1/*! p5.js v1.6.0 February 22, 2023 */ 2(function (f) { 3 if (typeof exports === 'object' && typeof module !== 'undefined') { 4 module.exports = f() 5 } else if (typeof define === 'function' && define.amd) { 6 define([], f) 7 } else { 8 var g; 9 if (typeof window !== 'undefined') { 10 g = window 11 } else if (typeof global !== 'undefined') { 12 g = global 13 } else if (typeof self !== 'undefined') { 14 g = self 15 } else { 16 g = this 17 } 18 g.p5 = f() 19 } 20}) (function () { 21 var define, 22 module, 23 exports; 24 return (function () { 25 function r(e, n, t) { 26 function o(i, f) { 27 if (!n[i]) { 28 if (!e[i]) { 29 var c = 'function' == typeof require && require; 30 if (!f && c) return c(i, !0); 31 if (u) return u(i, !0); 32 var a = new Error('Cannot find module \'' + i + '\''); 33 throw a.code = 'MODULE_NOT_FOUND', 34 a 35 } 36 var p = n[i] = { 37 exports: { 38 } 39 }; 40 e[i][0].call(p.exports, function (r) { 41 var n = e[i][1][r]; 42 return o(n || r) 43 }, p, p.exports, r, e, n, t) 44 } 45 return n[i].exports 46 } 47 for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++) o(t[i]); 48 return o 49 } 50 return r 51 }) () ({ 52 1: [ 53 function (_dereq_, module, exports) { 54 module.exports = { 55 'p5': { 56 'describe': { 57 'name': 'describe', 58 'params': [ 59 { 60 'name': 'text', 61 'description': '<p>description of the canvas</p>\n', 62 'type': 'String' 63 }, 64 { 65 'name': 'display', 66 'description': '<p>either LABEL or FALLBACK</p>\n', 67 'type': 'Constant', 68 'optional': true 69 } 70 ], 71 'class': 'p5', 72 'module': 'Environment' 73 }, 74 'describeElement': { 75 'name': 'describeElement', 76 'params': [ 77 { 78 'name': 'name', 79 'description': '<p>name of the element</p>\n', 80 'type': 'String' 81 }, 82 { 83 'name': 'text', 84 'description': '<p>description of the element</p>\n', 85 'type': 'String' 86 }, 87 { 88 'name': 'display', 89 'description': '<p>either LABEL or FALLBACK</p>\n', 90 'type': 'Constant', 91 'optional': true 92 } 93 ], 94 'class': 'p5', 95 'module': 'Environment' 96 }, 97 'textOutput': { 98 'name': 'textOutput', 99 'params': [ 100 { 101 'name': 'display', 102 'description': '<p>either FALLBACK or LABEL</p>\n', 103 'type': 'Constant', 104 'optional': true 105 } 106 ], 107 'class': 'p5', 108 'module': 'Environment' 109 }, 110 'gridOutput': { 111 'name': 'gridOutput', 112 'params': [ 113 { 114 'name': 'display', 115 'description': '<p>either FALLBACK or LABEL</p>\n', 116 'type': 'Constant', 117 'optional': true 118 } 119 ], 120 'class': 'p5', 121 'module': 'Environment' 122 }, 123 'alpha': { 124 'name': 'alpha', 125 'params': [ 126 { 127 'name': 'color', 128 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 129 'type': 'p5.Color|Number[]|String' 130 } 131 ], 132 'class': 'p5', 133 'module': 'Color' 134 }, 135 'blue': { 136 'name': 'blue', 137 'params': [ 138 { 139 'name': 'color', 140 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 141 'type': 'p5.Color|Number[]|String' 142 } 143 ], 144 'class': 'p5', 145 'module': 'Color' 146 }, 147 'brightness': { 148 'name': 'brightness', 149 'params': [ 150 { 151 'name': 'color', 152 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 153 'type': 'p5.Color|Number[]|String' 154 } 155 ], 156 'class': 'p5', 157 'module': 'Color' 158 }, 159 'color': { 160 'name': 'color', 161 'class': 'p5', 162 'module': 'Color', 163 'overloads': [ 164 { 165 'params': [ 166 { 167 'name': 'gray', 168 'description': '<p>number specifying value between white and black.</p>\n', 169 'type': 'Number' 170 }, 171 { 172 'name': 'alpha', 173 'description': '<p>alpha value relative to current color range\n (default is 0-255)</p>\n', 174 'type': 'Number', 175 'optional': true 176 } 177 ] 178 }, 179 { 180 'params': [ 181 { 182 'name': 'v1', 183 'description': '<p>red or hue value relative to\n the current color range</p>\n', 184 'type': 'Number' 185 }, 186 { 187 'name': 'v2', 188 'description': '<p>
188green or saturation value\n relative to the current color range</p>\n', 189 'type': 'Number' 190 }, 191 { 192 'name': 'v3', 193 'description': '<p>blue or brightness value\n relative to the current color range</p>\n', 194 'type': 'Number' 195 }, 196 { 197 'name': 'alpha', 198 'description': '', 199 'type': 'Number', 200 'optional': true 201 } 202 ] 203 }, 204 { 205 'params': [ 206 { 207 'name': 'value', 208 'description': '<p>a color string</p>\n', 209 'type': 'String' 210 } 211 ] 212 }, 213 { 214 'params': [ 215 { 216 'name': 'values', 217 'description': '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n', 218 'type': 'Number[]' 219 } 220 ] 221 }, 222 { 223 'params': [ 224 { 225 'name': 'color', 226 'description': '', 227 'type': 'p5.Color' 228 } 229 ] 230 } 231 ] 232 }, 233 'green': { 234 'name': 'green', 235 'params': [ 236 { 237 'name': 'color', 238 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 239 'type': 'p5.Color|Number[]|String' 240 } 241 ], 242 'class': 'p5', 243 'module': 'Color' 244 }, 245 'hue': { 246 'name': 'hue', 247 'params': [ 248 { 249 'name': 'color', 250 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 251 'type': 'p5.Color|Number[]|String' 252 } 253 ], 254 'class': 'p5', 255 'module': 'Color' 256 }, 257 'lerpColor': { 258 'name': 'lerpColor', 259 'params': [ 260 { 261 'name': 'c1', 262 'description': '<p>interpolate from this color</p>\n', 263 'type': 'p5.Color' 264 }, 265 { 266 'name': 'c2', 267 'description': '<p>interpolate to this color</p>\n', 268 'type': 'p5.Color' 269 }, 270 { 271 'name': 'amt', 272 'description': '<p>number between 0 and 1</p>\n', 273 'type': 'Number' 274 } 275 ], 276 'class': 'p5', 277 'module': 'Color' 278 }, 279 'lightness': { 280 'name': 'lightness', 281 'params': [ 282 { 283 'name': 'color', 284 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 285 'type': 'p5.Color|Number[]|String' 286 } 287 ], 288 'class': 'p5', 289 'module': 'Color' 290 }, 291 'red': { 292 'name': 'red', 293 'params': [ 294 { 295 'name': 'color', 296 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 297 'type': 'p5.Color|Number[]|String' 298 } 299 ], 300 'class': 'p5', 301 'module': 'Color' 302 },
303 'saturation': { 304 'name': 'saturation', 305 'params': [ 306 { 307 'name': 'color', 308 'description': '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n', 309 'type': 'p5.Color|Number[]|String' 310 } 311 ], 312 'class': 'p5', 313 'module': 'Color' 314 }, 315 'background': { 316 'name': 'background', 317 'class': 'p5', 318 'module': 'Color', 319 'overloads': [ 320 { 321 'params': [ 322 { 323 'name': 'color', 324 'description': '<p>any value created by the <a href="#/p5/color">color()</a> function</p>\n', 325 'type': 'p5.Color' 326 } 327 ], 328 'chainable': 1 329 }, 330 { 331 'params': [ 332 { 333 'name': 'colorstring', 334 'description': '<p>color string, possible formats include: integer\n rgb() or rgba(), percentage rgb() or rgba(),\n 3-digit hex, 6-digit hex</p>\n', 335 'type': 'String' 336 }, 337 { 338 'name': 'a', 339 'description': '<p>opacity of the background relative to current\n color range (default is 0-255)</p>\n', 340 'type': 'Number', 341 'optional': true 342 } 343 ], 344 'chainable': 1 345 }, 346 { 347 'params': [ 348 { 349 'name': 'gray', 350 'description': '<p>specifies a value between white and black</p>\n', 351 'type': 'Number' 352 }, 353 { 354 'name': 'a', 355 'description': '', 356 'type': 'Number', 357 'optional': true 358 } 359 ], 360 'chainable': 1 361 }, 362 { 363 'params': [ 364 { 365 'name': 'v1', 366 'description': '<p>red or hue value (depending on the current color\n mode)</p>\n', 367 'type': 'Number' 368 }, 369 { 370 'name': 'v2', 371 'description': '<p>green or saturation value (depending on the current\n color mode)</p>\n', 372 'type': 'Number' 373 }, 374 { 375 'name': 'v3', 376 'description': '<p>blue or brightness value (depending on the current\n color mode)</p>\n', 377 'type': 'Number' 378 }, 379 { 380 'name': 'a', 381 'description': '', 382 'type': 'Number', 383 'optional': true 384 } 385 ], 386 'chainable': 1 387 }, 388 { 389 'params': [ 390 { 391 'name': 'values', 392 'description': '<p>an array containing the red, green, blue\n and alpha components of the color</p>\n', 393 'type': 'Number[]' 394 } 395 ], 396 'chainable': 1 397 }, 398 { 399 'params': [ 400 { 401 'name': 'image', 402 'description': '<p>image created with <a href="#/p5/loadImage">loadImage()</a> or <a href="#/p5/createImage">createImage()</a>,\n to set as background\n (must be same size as the sketch window)</p>\n', 403 'type': 'p5.Image' 404 }, 405 { 406 'name': 'a', 407 'description': '', 408 'type': 'Number', 409 'optional': true 410 } 411 ], 412 'chainable': 1 413 } 414 ] 415 }, 416 'clear': { 417 'name': 'clear', 418 'params': [ 419 { 420 'name': 'r', 421 'description': '<p>normalized red val.</p>\n', 422 'type': 'Number' 423 }, 424 { 425 'name': 'g', 426 'description': '<p>normalized green val.</p>\n', 427 'type': 'Number' 428 }, 429 { 430 'name': 'b', 431 'description': '<p>normalized blue val.</p>\n', 432 'type': 'Number' 433 }, 434 { 435 'name': 'a', 436 'description': '<p>normalized alpha val.</p>\n', 437 'type': 'Number' 438 } 439 ], 440 'class': 'p5', 441 'module': 'Color' 442 }, 443 'colorMode': { 444 'name': 'colorMode', 445 'class': 'p5', 446 'module': 'Color', 447 'overloads': [ 448 { 449 'params': [ 450 { 451 'name': 'mode', 452 'description': '<p>either RGB, HSB or HSL, corresponding to\n Red/Green/Blue and Hue/Saturation/Brightness\n (or Lightness)</p>\n', 453 'type': 'Constant' 454 }, 455 { 456 'name': 'max', 457 'description': '<p>range for all values</p>\n', 458 'type': 'Number', 459 'optional': true 460 } 461 ], 462 'chainable': 1 463 }, 464 { 465 'params': [ 466 { 467 'name': 'mode', 468 'description': '', 469 'type': 'Constant' 470 }, 471 { 472 'name': 'max1', 473 'description': '<p>range for the red or hue depending on the\n current color mode</p>\n', 474 'type': 'Number' 475 }, 476 { 477 'name': 'max2', 478 'description': '<p>range for the green or saturation depending\n on the current color mode</p>\n', 479 'type': 'Number' 480 }, 481 { 482 'name': 'max3', 483 'description': '<p>range for the blue or brightness/lightness\n depending on the current color mode</p>\n', 484 'type': 'Number' 485 }, 486 { 487 'name': 'maxA', 488 'description': '<p>range for the alpha</p>\n', 489 'type': 'Number', 490 'optional': true 491 } 492 ], 493 'chainable': 1 494 } 495 ] 496 }, 497 'fill': { 498 'name': 'fill', 499 'class': 'p5', 500 'module': 'Color', 501 'overloads': [ 502 { 503 'params': [ 504 { 505 'name': 'v1', 506 'description': '<p>red or hue value relative to\n the current color range</p>\n', 507 'type': 'Number' 508 }, 509 { 510 'name': 'v2', 511 'description': '<p>
511green or saturation value\n relative to the current color range</p>\n', 512 'type': 'Number' 513 }, 514 { 515 'name': 'v3', 516 'description': '<p>blue or brightness value\n relative to the current color range</p>\n', 517 'type': 'Number' 518 }, 519 { 520 'name': 'alpha', 521 'description': '', 522 'type': 'Number', 523 'optional': true 524 } 525 ], 526 'chainable': 1 527 }, 528 { 529 'params': [ 530 { 531 'name': 'value', 532 'description': '<p>a color string</p>\n', 533 'type': 'String' 534 } 535 ], 536 'chainable': 1 537 }, 538 { 539 'params': [ 540 { 541 'name': 'gray', 542 'description': '<p>a gray value</p>\n', 543 'type': 'Number' 544 }, 545 { 546 'name': 'alpha', 547 'description': '', 548 'type': 'Number', 549 'optional': true 550 } 551 ], 552 'chainable': 1 553 }, 554 { 555 'params': [ 556 { 557 'name': 'values', 558 'description': '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n', 559 'type': 'Number[]' 560 } 561 ], 562 'chainable': 1 563 }, 564 { 565 'params': [ 566 { 567 'name': 'color', 568 'description': '<p>the fill color</p>\n', 569 'type': 'p5.Color' 570 } 571 ], 572 'chainable': 1 573 } 574 ] 575 }, 576 'noFill': { 577 'name': 'noFill', 578 'class': 'p5', 579 'module': 'Color' 580 }, 581 'noStroke': { 582 'name': 'noStroke', 583 'class': 'p5', 584 'module': 'Color' 585 }, 586 'stroke': { 587 'name': 'stroke', 588 'class': 'p5', 589 'module': 'Color', 590 'overloads': [ 591 { 592 'params': [ 593 { 594 'name': 'v1', 595 'description': '<p>red or hue value relative to\n the current color range</p>\n', 596 'type': 'Number' 597 }, 598 { 599 'name': 'v2', 600 'description': '<p>green or saturation value\n relative to the current color range</p>\n', 601 'type': 'Number' 602 }, 603 { 604 'name': 'v3', 605 'description': '<p>blue or brightness value\n relative to the current color range</p>\n', 606 'type': 'Number' 607 }, 608 { 609 'name': 'alpha', 610 'description': '', 611 'type': 'Number', 612 'optional': true 613 } 614 ], 615 'chainable': 1 616 }, 617 { 618 'params': [ 619 { 620 'name': 'value', 621 'description': '<p>a color string</p>\n', 622 'type': 'String' 623 } 624 ], 625 'chainable': 1 626 }, 627 { 628 'params': [ 629 { 630 'name': 'gray', 631 'description': '<p>a gray value</p>\n', 632 'type': 'Number' 633 }, 634 { 635 'name': 'alpha', 636 'description': '', 637 'type': 'Number', 638 'optional': true 639 } 640 ], 641 'chainable': 1 642 }, 643 { 644 'params': [ 645 { 646 'name': 'values', 647 'description': '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n', 648 'type': 'Number[]' 649 } 650 ], 651 'chainable': 1 652 }, 653 { 654 'params': [ 655 { 656 'name': 'color', 657 'description': '<p>the stroke color</p>\n', 658 'type': 'p5.Color' 659 } 660 ], 661 'chainable': 1 662 } 663 ] 664 }, 665 'erase': { 666 'name': 'erase', 667 'params': [ 668 { 669 'name': 'strengthFill', 670 'description': '<p>A number (0-255) for the strength of erasing for a shape\'s fill.\n This will default to 255 when no argument is given, which\n is full strength.</p>\n', 671 'type': 'Number', 672 'optional': true 673 }, 674 { 675 'name': 'strengthStroke', 676 'description': '<p>A number (0-255) for the strength of erasing for a shape\'s stroke.\n This will default to 255 when no argument is given, which\n is full strength.</p>\n', 677 'type': 'Number', 678 'optional': true 679 } 680 ], 681 'class': 'p5', 682 'module': 'Color' 683 }, 684 'noErase': { 685 'name': 'noErase', 686 'class': 'p5', 687 'module': 'Color' 688 }, 689 'arc': { 690 'name': 'arc', 691 'params': [ 692 { 693 'name': 'x', 694 'description': '<p>x-coordinate of the arc\'s ellipse</p>\n', 695 'type': 'Number' 696 }, 697 { 698 'name': 'y', 699 'description': '<p>y-coordinate of the arc\'s ellipse</p>\n', 700 'type': 'Number' 701 }, 702 { 703 'name': 'w', 704 'description': '<p>width of the arc\'s ellipse by default</p>\n', 705 'type': 'Number' 706 }, 707 { 708 'name': 'h', 709 'description': '<p>height of the arc\'s ellipse by default</p>\n', 710 'type': 'Number' 711 }, 712 { 713 'name': 'start', 714 'description': '<p>angle to start the arc, specified in radians</p>\n', 715 'type': 'Number' 716 }, 717 { 718 'name': 'stop', 719 'description': '<p>angle to stop the arc, specified in radians</p>\n', 720 'type': 'Number' 721 }, 722 { 723 'name': 'mode', 724 'description': '<p>optional parameter to determine the way of drawing\n the arc. either CHORD, PIE or OPEN</p>\n', 725 'type': 'Constant', 726 'optional': true 727 }, 728 { 729 'name': 'detail', 730 'description': '<p>optional parameter for WebGL mode only. This is to\n specify the number of vertices that makes up the\n perimeter of the arc. Default value is 25. Won\'t\n draw a stroke for a detail of more than 50.</p>\n', 731 'type': 'Integer', 732 'optional': true 733 } 734 ], 735 'class': 'p5', 736 'module': 'Shape' 737 }, 738 'ellipse': { 739 'name': 'ellipse', 740 'class': 'p5', 741 'module': 'Shape', 742 'overloads': [ 743 { 744 'params': [ 745 { 746 'name': 'x', 747 'description': '<p>x-coordinate of the center of the ellipse.</p>\n', 748 'type': 'Number' 749 }, 750 { 751 'name': 'y', 752 'description': '<p>y-coordinate of the center of the ellipse.</p>\n', 753 'type': 'Number' 754 }, 755 { 756 'name': 'w', 757 'description': '<p>width of the ellipse.</p>\n', 758 'type': 'Number' 759 }, 760 { 761 'name': 'h', 762 'description': '<p>height of the ellipse.</p>\n', 763 'type': 'Number', 764 'optional': true 765 } 766 ], 767 'chainable': 1 768 }, 769 { 770 'params': [ 771 { 772 'name': 'x', 773 'description': '', 774 'type': 'Number' 775 }, 776 { 777 'name': 'y', 778 'description': '', 779 'type': 'Number' 780 }, 781 { 782 'name': 'w', 783 'description': '', 784 'type': 'Number' 785 }, 786 { 787 'name': 'h', 788 'description': '', 789 'type': 'Number' 790 }, 791 { 792 'name': 'detail', 793 'description': '<p>optional parameter for WEBGL mode only. This is to\n specify the number of vertices that makes up the\n perimeter of the ellipse. Default value is 25. Won\'t\n draw a stroke for a detail of more than 50.</p>\n', 794 'type': 'Integer', 795 'optional': true 796 } 797 ] 798 } 799 ] 800 }, 801 'circle': { 802 'name': 'circle', 803 'params': [ 804 { 805 'name': 'x', 806 'description': '<p>x-coordinate of the center of the circle.</p>\n', 807 'type': 'Number' 808 }, 809 { 810 'name': 'y', 811 'description': '<p>y-coordinate of the center of the circle.</p>\n', 812 'type': 'Number' 813 }, 814 { 815 'name': 'd', 816 'description': '<p>diameter of the circle.</p>\n', 817 'type': 'Number' 818 } 819 ], 820 'class': 'p5', 821 'module': 'Shape' 822 }, 823 'line': { 824 'name': 'line', 825 'class': 'p5', 826 'module': 'Shape', 827 'overloads': [ 828 { 829 'params': [ 830 { 831 'name': 'x1', 832 'description': '<p>the x-coordinate of the first point</p>\n', 833 'type': 'Number' 834 }, 835 { 836 'name': 'y1', 837 'description': '<p>the y-coordinate of the first point</p>\n', 838 'type': 'Number' 839 }, 840 { 841 'name': 'x2', 842 'description': '<p>the x-coordinate of the second point</p>\n', 843 'type': 'Number' 844 }, 845 { 846 'name': 'y2', 847 'description': '<p>the y-coordinate of the second point</p>\n', 848 'type': 'Number' 849 } 850 ], 851 'chainable': 1 852 }, 853 { 854 'params': [ 855 { 856 'name': 'x1', 857 'description': '', 858 'type': 'Number' 859 }, 860 { 861 'name': 'y1', 862 'description': '', 863 'type': 'Number' 864 }, 865 { 866 'name': 'z1', 867 'description': '<p>the z-coordinate of the first point</p>\n', 868 'type': 'Number' 869 }, 870 { 871 'name': 'x2', 872 'description': '', 873 'type': 'Number' 874 }, 875 { 876 'name': 'y2', 877 'description': '', 878 'type': 'Number' 879 }, 880 { 881 'name': 'z2', 882 'description': '<p>the z-coordinate of the second point</p>\n', 883 'type': 'Number' 884 } 885 ], 886 'chainable': 1 887 } 888 ] 889 }, 890 'point': { 891 'name': 'point', 892 'class': 'p5', 893 'module': 'Shape', 894 'overloads': [ 895 { 896 'params': [ 897 { 898 'name': 'x', 899 'description': '<p>the x-coordinate</p>\n', 900 'type': 'Number' 901 }, 902 { 903 'name': 'y', 904 'description': '<p>the y-coordinate</p>\n', 905 'type': 'Number' 906 }, 907 { 908 'name': 'z', 909 'description': '<p>the z-coordinate (for WebGL mode)</p>\n', 910 'type': 'Number', 911 'optional': true 912 } 913 ], 914 'chainable': 1 915 }, 916 { 917 'params': [ 918 { 919 'name': 'coordinate_vector', 920 'description': '<p>the coordinate vector</p>\n', 921 'type': 'p5.Vector' 922 } 923 ], 924 'chainable': 1 925 } 926 ] 927 }, 928 'quad': { 929 'name': 'quad', 930 'class': 'p5', 931 'module': 'Shape', 932 'overloads': [ 933 { 934 'params': [ 935 { 936 'name': 'x1', 937 'description': '<p>the x-coordinate of the first point</p>\n', 938 'type': 'Number' 939 }, 940 { 941 'name': 'y1', 942 'description': '<p>the y-coordinate of the first point</p>\n', 943 'type': 'Number' 944 }, 945 { 946 'name': 'x2', 947 'description': '<p>the x-coordinate of the second point</p>\n', 948 'type': 'Number' 949 }, 950 { 951 'name': 'y2', 952 'description': '<p>the y-coordinate of the second point</p>\n', 953 'type': 'Number' 954 }, 955 { 956 'name': 'x3', 957 'description': '<p>the x-coordinate of the third point</p>\n', 958 'type': 'Number' 959 }, 960
960 { 961 'name': 'y3', 962 'description': '<p>the y-coordinate of the third point</p>\n', 963 'type': 'Number' 964 }, 965 { 966 'name': 'x4', 967 'description': '<p>the x-coordinate of the fourth point</p>\n', 968 'type': 'Number' 969 }, 970 { 971 'name': 'y4', 972 'description': '<p>the y-coordinate of the fourth point</p>\n', 973 'type': 'Number' 974 }, 975 { 976 'name': 'detailX', 977 'description': '<p>number of segments in the x-direction</p>\n', 978 'type': 'Integer', 979 'optional': true 980 }, 981 { 982 'name': 'detailY', 983 'description': '<p>number of segments in the y-direction</p>\n', 984 'type': 'Integer', 985 'optional': true 986 } 987 ], 988 'chainable': 1 989 }, 990 { 991 'params': [ 992 { 993 'name': 'x1', 994 'description': '', 995 'type': 'Number' 996 }, 997 { 998 'name': 'y1', 999 'description': '', 1000 'type': 'Number' 1001 }, 1002 { 1003 'name': 'z1', 1004 'description': '<p>the z-coordinate of the first point</p>\n', 1005 'type': 'Number' 1006 }, 1007 { 1008 'name': 'x2', 1009 'description': '', 1010 'type': 'Number' 1011 }, 1012 { 1013 'name': 'y2', 1014 'description': '', 1015 'type': 'Number' 1016 }, 1017 { 1018 'name': 'z2', 1019 'description': '<p>the z-coordinate of the second point</p>\n', 1020 'type': 'Number' 1021 }, 1022 { 1023 'name': 'x3', 1024 'description': '', 1025 'type': 'Number' 1026 }, 1027 { 1028 'name': 'y3', 1029 'description': '', 1030 'type': 'Number' 1031 }, 1032 { 1033 'name': 'z3', 1034 'description': '<p>the z-coordinate of the third point</p>\n', 1035 'type': 'Number' 1036 }, 1037 { 1038 'name': 'x4', 1039 'description': '', 1040 'type': 'Number' 1041 }, 1042 { 1043 'name': 'y4', 1044 'description': '', 1045 'type': 'Number' 1046 }, 1047 { 1048 'name': 'z4', 1049 'description': '<p>the z-coordinate of the fourth point</p>\n', 1050 'type': 'Number' 1051 }, 1052 { 1053 'name': 'detailX', 1054 'description': '', 1055 'type': 'Integer', 1056 'optional': true 1057 }, 1058 { 1059 'name': 'detailY', 1060 'description': '', 1061 'type': 'Integer', 1062 'optional': true 1063 } 1064 ], 1065 'chainable': 1 1066 } 1067 ] 1068 }, 1069 'rect': { 1070 'name': 'rect', 1071 'class': 'p5', 1072 'module': 'Shape', 1073 'overloads': [ 1074 { 1075 'params': [ 1076 { 1077 'name': 'x', 1078 'description': '<p>x-coordinate of the rectangle.</p>\n', 1079 'type': 'Number' 1080 }, 1081 { 1082 'name': 'y', 1083 'description': '<p>y-coordinate of the rectangle.</p>\n', 1084 'type': 'Number' 1085 }, 1086 { 1087 'name': 'w', 1088 'description': '<p>width of the rectangle.</p>\n', 1089 'type': 'Number' 1090 }, 1091 { 1092 'name': 'h', 1093 'description': '<p>height of the rectangle.</p>\n', 1094 'type': 'Number', 1095 'optional': true 1096 }, 1097 { 1098 'name': 'tl', 1099 'description': '<p>optional radius of top-left corner.</p>\n', 1100 'type': 'Number', 1101 'optional': true 1102 }, 1103 { 1104 'name': 'tr', 1105 'description': '<p>optional radius of top-right corner.</p>\n', 1106 'type': 'Number', 1107 'optional': true 1108 }, 1109 { 1110 'name': 'br', 1111 'description': '<p>optional radius of bottom-right corner.</p>\n', 1112 'type': 'Number', 1113 'optional': true 1114 }, 1115 { 1116 'name': 'bl', 1117 'description': '<p>optional radius of bottom-left corner.</p>\n', 1118 'type': 'Number', 1119 'optional': true 1120 } 1121 ], 1122 'chainable': 1 1123 }, 1124 { 1125 'params': [ 1126 { 1127 'name': 'x', 1128 'description': '', 1129 'type': 'Number' 1130 }, 1131 { 1132 'name': 'y', 1133 'description': '', 1134 'type': 'Number' 1135 }, 1136 { 1137 'name': 'w', 1138 'description': '', 1139 'type': 'Number' 1140 }, 1141 { 1142 'name': 'h', 1143 'description': '', 1144 'type': 'Number' 1145 }, 1146 { 1147 'name': 'detailX', 1148 'description': '<p>number of segments in the x-direction (for WebGL mode)</p>\n', 1149 'type': 'Integer', 1150 'optional': true 1151 }, 1152 { 1153 'name': 'detailY', 1154 'description': '<p>number of segments in the y-direction (for WebGL mode)</p>\n', 1155 'type': 'Integer', 1156 'optional': true 1157 } 1158 ], 1159 'chainable': 1 1160 } 1161 ] 1162 }, 1163 'square': { 1164 'name': 'square', 1165 'params': [ 1166 { 1167 'name': 'x', 1168 'description': '<p>x-coordinate of the square.</p>\n', 1169 'type': 'Number' 1170 }, 1171 { 1172 'name': 'y', 1173 'description': '<p>y-coordinate of the square.</p>\n', 1174 'type': 'Number' 1175 }, 1176 { 1177 'name': 's', 1178 'description': '<p>side size of the square.</p>\n', 1179 'type': 'Number' 1180 }, 1181 { 1182 'name': 'tl', 1183 'description': '<p>optional radius of top-left corner.</p>\n', 1184 'type': 'Number', 1185 'optional': true 1186 }, 1187 { 1188 'name': 'tr', 1189 'description': '<p>optional radius of top-right corner.</p>\n', 1190 'type': 'Number', 1191 'optional': true 1192 }, 1193 { 1194 'name': 'br', 1195 'description': '<p>optional radius of bottom-right corner.</p>\n', 1196 'type': 'Number', 1197 'optional': true 1198 }, 1199 { 1200 'name': 'bl', 1201 'description': '<p>optional radius of bottom-left corner.</p>\n', 1202 'type': 'Number', 1203 'optional': true 1204 } 1205 ], 1206 'class': 'p5', 1207 'module': 'Shape' 1208 }, 1209 'triangle': { 1210 'name': 'triangle', 1211 'params': [ 1212 { 1213 'name': 'x1', 1214 'description': '<p>x-coordinate of the first point</p>\n', 1215 'type': 'Number' 1216 }, 1217 { 1218 'name': 'y1', 1219 'description': '<p>y-coordinate of the first point</p>\n', 1220 'type': 'Number' 1221 }, 1222 { 1223 'name': 'x2', 1224 'description': '<p>x-coordinate of the second point</p>\n', 1225 'type': 'Number' 1226 }, 1227 { 1228 'name': 'y2', 1229 'description': '<p>y-coordinate of the second point</p>\n', 1230 'type': 'Number' 1231 }, 1232 { 1233 'name': 'x3', 1234 'description': '<p>x-coordinate of the third point</p>\n', 1235 'type': 'Number' 1236 }, 1237 { 1238 'name': 'y3', 1239 'description': '<p>y-coordinate of the third point</p>\n', 1240 'type': 'Number' 1241 } 1242 ], 1243 'class': 'p5', 1244 'module': 'Shape' 1245 }, 1246 'ellipseMode': { 1247 'name': 'ellipseMode', 1248 'params': [ 1249 { 1250 'name': 'mode', 1251 'description': '<p>either CENTER, RADIUS, CORNER, or CORNERS</p>\n', 1252 'type': 'Constant' 1253 } 1254 ], 1255 'class': 'p5', 1256 'module': 'Shape' 1257 }, 1258 'noSmooth': { 1259 'name': 'noSmooth', 1260 'class': 'p5', 1261 'module': 'Shape' 1262 }, 1263 'rectMode': { 1264 'name': 'rectMode', 1265 'params': [ 1266 { 1267 'name': 'mode', 1268 'description': '<p>either CORNER, CORNERS, CENTER, or RADIUS</p>\n', 1269 'type': 'Constant' 1270 } 1271 ], 1272 'class': 'p5', 1273 'module': 'Shape' 1274 }, 1275 'smooth': { 1276 'name': 'smooth', 1277 'class': 'p5', 1278 'module': 'Shape' 1279 }, 1280 'strokeCap': { 1281 'name': 'strokeCap', 1282 'params': [ 1283 { 1284 'name': 'cap', 1285 'description': '<p>either ROUND, SQUARE, or PROJECT</p>\n', 1286 'type': 'Constant' 1287 } 1288 ], 1289 'class': 'p5', 1290 'module': 'Shape' 1291 }, 1292 'strokeJoin': { 1293 'name': 'strokeJoin', 1294 'params': [ 1295 { 1296 'name': 'join', 1297 'description': '<p>either MITER, BEVEL, or ROUND</p>\n', 1298 'type': 'Constant' 1299 } 1300 ], 1301 'class': 'p5', 1302 'module': 'Shape' 1303 }, 1304 'strokeWeight': { 1305 'name': 'strokeWeight', 1306 'params': [ 1307 { 1308 'name': 'weight', 1309 'description': '<p>the weight of the stroke (in pixels)</p>\n', 1310 'type': 'Number' 1311 } 1312 ], 1313 'class': 'p5', 1314 'module': 'Shape' 1315 }, 1316 'bezier': { 1317 'name': 'bezier', 1318 'class': 'p5', 1319 'module': 'Shape', 1320 'overloads': [ 1321 { 1322 'params': [ 1323 { 1324 'name': 'x1', 1325 'description': '<p>x-coordinate for the first anchor point</p>\n', 1326 'type': 'Number' 1327 }, 1328 { 1329 'name': 'y1', 1330 'description': '<p>y-coordinate for the first anchor point</p>\n', 1331 'type': 'Number' 1332 }, 1333 { 1334 'name': 'x2', 1335 'description': '<p>x-coordinate for the first control point</p>\n', 1336 'type': 'Number' 1337 }, 1338 { 1339 'name': 'y2', 1340 'description': '<p>y-coordinate for the first control point</p>\n', 1341 'type': 'Number' 1342 }, 1343 { 1344 'name': 'x3', 1345 'description': '<p>x-coordinate for the second control point</p>\n', 1346 'type': 'Number' 1347 }, 1348 { 1349 'name': 'y3', 1350 'description': '<p>y-coordinate for the second control point</p>\n', 1351 'type': 'Number' 1352 }, 1353 { 1354 'name': 'x4', 1355 'description': '<p>x-coordinate for the second anchor point</p>\n', 1356 'type': 'Number' 1357 }, 1358 { 1359 'name': 'y4', 1360 'description': '<p>y-coordinate for the second anchor point</p>\n', 1361 'type': 'Number' 1362 } 1363 ], 1364 'chainable': 1 1365 }, 1366 { 1367 'params': [ 1368 { 1369 'name': 'x1', 1370 'description': '', 1371 'type': 'Number' 1372 }, 1373 { 1374 'name': 'y1', 1375 'description': '', 1376 'type': 'Number' 1377 }, 1378 { 1379 'name': 'z1', 1380 'description': '<p>z-coordinate for the first anchor point</p>\n', 1381 'type': 'Number' 1382 }, 1383 { 1384 'name': 'x2', 1385 'description': '', 1386 'type': 'Number' 1387 }, 1388 { 1389 'name': 'y2', 1390 'description': '', 1391 'type': 'Number' 1392 }, 1393 { 1394 'name': 'z2', 1395 'description': '<p>z-coordinate for the first control point</p>\n', 1396 'type': 'Number' 1397 }, 1398 { 1399 'name': 'x3', 1400 'description': '', 1401 'type': 'Number' 1402 }, 1403 { 1404 'name': 'y3', 1405 'description': '', 1406 'type': 'Number' 1407 }, 1408 { 1409 'name': 'z3', 1410 'description': '<p>z-coordinate for the second control point</p>\n', 1411 'type': 'Number' 1412 }, 1413 { 1414 'name': 'x4', 1415 'description': '', 1416 'type': 'Number' 1417 }, 1418 { 1419 'name': 'y4', 1420 'description': '', 1421 'type': 'Number' 1422 }, 1423 { 1424 'name': 'z4', 1425 'description': '<p>z-coordinate for the second anchor point</p>\n', 1426 'type': 'Number' 1427 } 1428 ],
1428 1429 'chainable': 1 1430 } 1431 ] 1432 }, 1433 'bezierDetail': { 1434 'name': 'bezierDetail', 1435 'params': [ 1436 { 1437 'name': 'detail', 1438 'description': '<p>resolution of the curves</p>\n', 1439 'type': 'Number' 1440 } 1441 ], 1442 'class': 'p5', 1443 'module': 'Shape' 1444 }, 1445 'bezierPoint': { 1446 'name': 'bezierPoint', 1447 'params': [ 1448 { 1449 'name': 'a', 1450 'description': '<p>coordinate of first point on the curve</p>\n', 1451 'type': 'Number' 1452 }, 1453 { 1454 'name': 'b', 1455 'description': '<p>coordinate of first control point</p>\n', 1456 'type': 'Number' 1457 }, 1458 { 1459 'name': 'c', 1460 'description': '<p>coordinate of second control point</p>\n', 1461 'type': 'Number' 1462 }, 1463 { 1464 'name': 'd', 1465 'description': '<p>coordinate of second point on the curve</p>\n', 1466 'type': 'Number' 1467 }, 1468 { 1469 'name': 't', 1470 'description': '<p>value between 0 and 1</p>\n', 1471 'type': 'Number' 1472 } 1473 ], 1474 'class': 'p5', 1475 'module': 'Shape' 1476 }, 1477 'bezierTangent': { 1478 'name': 'bezierTangent', 1479 'params': [ 1480 { 1481 'name': 'a', 1482 'description': '<p>coordinate of first point on the curve</p>\n', 1483 'type': 'Number' 1484 }, 1485 { 1486 'name': 'b', 1487 'description': '<p>coordinate of first control point</p>\n', 1488 'type': 'Number' 1489 }, 1490 { 1491 'name': 'c', 1492 'description': '<p>coordinate of second control point</p>\n', 1493 'type': 'Number' 1494 }, 1495 { 1496 'name': 'd', 1497 'description': '<p>coordinate of second point on the curve</p>\n', 1498 'type': 'Number' 1499 }, 1500 { 1501 'name': 't', 1502 'description': '<p>value between 0 and 1</p>\n', 1503 'type': 'Number' 1504 } 1505 ], 1506 'class': 'p5', 1507 'module': 'Shape' 1508 }, 1509 'curve': { 1510 'name': 'curve', 1511 'class': 'p5', 1512 'module': 'Shape', 1513 'overloads': [ 1514 { 1515 'params': [ 1516 { 1517 'name': 'x1', 1518 'description': '<p>x-coordinate for the beginning control point</p>\n', 1519 'type': 'Number' 1520 }, 1521 { 1522 'name': 'y1', 1523 'description': '<p>y-coordinate for the beginning control point</p>\n', 1524 'type': 'Number' 1525 }, 1526 { 1527 'name': 'x2', 1528 'description': '<p>x-coordinate for the first point</p>\n', 1529 'type': 'Number' 1530 }, 1531 { 1532 'name': 'y2', 1533 'description': '<p>y-coordinate for the first point</p>\n', 1534 'type': 'Number' 1535 }, 1536 { 1537 'name': 'x3', 1538 'description': '<p>x-coordinate for the second point</p>\n', 1539 'type': 'Number' 1540 }, 1541 { 1542 'name': 'y3', 1543 'description': '<p>y-coordinate for the second point</p>\n', 1544 'type': 'Number' 1545 }, 1546 { 1547 'name': 'x4', 1548 'description': '<p>x-coordinate for the ending control point</p>\n', 1549 'type': 'Number' 1550 }, 1551 { 1552 'name': 'y4', 1553 'description': '<p>y-coordinate for the ending control point</p>\n', 1554 'type': 'Number' 1555 } 1556 ], 1557 'chainable': 1 1558 }, 1559 { 1560 'params': [ 1561 { 1562 'name': 'x1', 1563 'description': '', 1564 'type': 'Number' 1565 }, 1566 { 1567 'name': 'y1', 1568 'description': '', 1569 'type': 'Number' 1570 }, 1571 { 1572 'name': 'z1', 1573 'description': '<p>z-coordinate for the beginning control point</p>\n', 1574 'type': 'Number' 1575 }, 1576 { 1577 'name': 'x2', 1578 'description': '', 1579 'type': 'Number' 1580 }, 1581 { 1582 'name': 'y2', 1583 'description': '', 1584 'type': 'Number' 1585 }, 1586 { 1587 'name': 'z2', 1588 'description': '<p>z-coordinate for the first point</p>\n', 1589 'type': 'Number' 1590 }, 1591 { 1592 'name': 'x3', 1593 'description': '', 1594 'type': 'Number' 1595 }, 1596 { 1597 'name': 'y3', 1598 'description': '', 1599 'type': 'Number' 1600 }, 1601 { 1602 'name': 'z3', 1603 'description': '<p>z-coordinate for the second point</p>\n', 1604 'type': 'Number' 1605 }, 1606 { 1607 'name': 'x4', 1608 'description': '', 1609 'type': 'Number' 1610 }, 1611 { 1612 'name': 'y4', 1613 'description': '', 1614 'type': 'Number' 1615 }, 1616 { 1617 'name': 'z4', 1618 'description': '<p>z-coordinate for the ending control point</p>\n', 1619 'type': 'Number' 1620 } 1621 ], 1622 'chainable': 1 1623 } 1624 ] 1625 }, 1626 'curveDetail': { 1627 'name': 'curveDetail', 1628 'params': [ 1629 { 1630 'name': 'resolution', 1631 'description': '<p>resolution of the curves</p>\n', 1632 'type': 'Number' 1633 } 1634 ], 1635 'class': 'p5', 1636 'module': 'Shape' 1637 }, 1638 'curveTightness': { 1639 'name': 'curveTightness', 1640 'params': [ 1641 { 1642 'name': 'amount', 1643 'description': '<p>amount of deformation from the original vertices</p>\n', 1644 'type': 'Number' 1645 } 1646 ], 1647 'class': 'p5', 1648 'module': 'Shape' 1649 }, 1650 'curvePoint': { 1651 'name': 'curvePoint', 1652 'params': [ 1653 { 1654 'name': 'a', 1655 'description': '<p>coordinate of first control point of the curve</p>\n', 1656 'type': 'Number' 1657 }, 1658 { 1659 'name': 'b', 1660 'description': '<p>coordinate of first point</p>\n', 1661 'type': 'Number' 1662 }, 1663 { 1664 'name': 'c', 1665 'description': '<p>coordinate of second point</p>\n', 1666 'type': 'Number' 1667 }, 1668 { 1669 'name': 'd', 1670 'description': '<p>coordinate of second control point</p>\n', 1671 'type': 'Number' 1672 }, 1673 { 1674 'name': 't', 1675 'description': '<p>value between 0 and 1</p>\n', 1676 'type': 'Number' 1677 } 1678 ], 1679 'class': 'p5', 1680 'module': 'Shape' 1681 }, 1682 'curveTangent': { 1683 'name': 'curveTangent', 1684 'params': [ 1685 { 1686 'name': 'a', 1687 'description': '<p>coordinate of first control point</p>\n', 1688 'type': 'Number' 1689 }, 1690 { 1691 'name': 'b', 1692 'description': '<p>coordinate of first point on the curve</p>\n', 1693 'type': 'Number' 1694 }, 1695 { 1696 'name': 'c', 1697 'description': '<p>coordinate of second point on the curve</p>\n', 1698 'type': 'Number' 1699 }, 1700 { 1701 'name': 'd', 1702 'description': '<p>coordinate of second conrol point</p>\n', 1703 'type': 'Number' 1704 }, 1705 { 1706 'name': 't', 1707 'description': '<p>value between 0 and 1</p>\n', 1708 'type': 'Number' 1709 } 1710 ], 1711 'class': 'p5', 1712 'module': 'Shape' 1713 }, 1714 'beginContour': { 1715 'name': 'beginContour', 1716 'class': 'p5', 1717 'module': 'Shape' 1718 }, 1719 'beginShape': { 1720 'name': 'beginShape', 1721 'params': [ 1722 { 1723 'name': 'kind', 1724 'description': '<p>either POINTS, LINES, TRIANGLES, TRIANGLE_FAN\n TRIANGLE_STRIP, QUADS, QUAD_STRIP or TESS</p>\n', 1725 'type': 'Constant', 1726 'optional': true 1727 } 1728 ], 1729 'class': 'p5', 1730 'module': 'Shape' 1731 }, 1732 'bezierVertex': { 1733 'name': 'bezierVertex', 1734 'class': 'p5', 1735 'module': 'Shape', 1736 'overloads': [ 1737 { 1738 'params': [ 1739 { 1740 'name': 'x2', 1741 'description': '<p>x-coordinate for the first control point</p>\n', 1742 'type': 'Number' 1743 }, 1744 { 1745 'name': 'y2', 1746 'description': '<p>y-coordinate for the first control point</p>\n', 1747 'type': 'Number' 1748 }, 1749 { 1750 'name': 'x3', 1751 'description': '<p>x-coordinate for the second control point</p>\n', 1752 'type': 'Number' 1753 }, 1754 { 1755 'name': 'y3', 1756 'description': '<p>y-coordinate for the second control point</p>\n', 1757 'type': 'Number' 1758 }, 1759 { 1760 'name': 'x4', 1761 'description': '<p>
1761x-coordinate for the anchor point</p>\n', 1762 'type': 'Number' 1763 }, 1764 { 1765 'name': 'y4', 1766 'description': '<p>y-coordinate for the anchor point</p>\n', 1767 'type': 'Number' 1768 } 1769 ], 1770 'chainable': 1 1771 }, 1772 { 1773 'params': [ 1774 { 1775 'name': 'x2', 1776 'description': '', 1777 'type': 'Number' 1778 }, 1779 { 1780 'name': 'y2', 1781 'description': '', 1782 'type': 'Number' 1783 }, 1784 { 1785 'name': 'z2', 1786 'description': '<p>z-coordinate for the first control point (for WebGL mode)</p>\n', 1787 'type': 'Number' 1788 }, 1789 { 1790 'name': 'x3', 1791 'description': '', 1792 'type': 'Number' 1793 }, 1794 { 1795 'name': 'y3', 1796 'description': '', 1797 'type': 'Number' 1798 }, 1799 { 1800 'name': 'z3', 1801 'description': '<p>z-coordinate for the second control point (for WebGL mode)</p>\n', 1802 'type': 'Number' 1803 }, 1804 { 1805 'name': 'x4', 1806 'description': '', 1807 'type': 'Number' 1808 }, 1809 { 1810 'name': 'y4', 1811 'description': '', 1812 'type': 'Number' 1813 }, 1814 { 1815 'name': 'z4', 1816 'description': '<p>z-coordinate for the anchor point (for WebGL mode)</p>\n', 1817 'type': 'Number' 1818 } 1819 ], 1820 'chainable': 1 1821 } 1822 ] 1823 }, 1824 'curveVertex': { 1825 'name': 'curveVertex', 1826 'class': 'p5', 1827 'module': 'Shape', 1828 'overloads': [ 1829 { 1830 'params': [ 1831 { 1832 'name': 'x', 1833 'description': '<p>x-coordinate of the vertex</p>\n', 1834 'type': 'Number' 1835 }, 1836 { 1837 'name': 'y', 1838 'description': '<p>y-coordinate of the vertex</p>\n', 1839 'type': 'Number' 1840 } 1841 ], 1842 'chainable': 1 1843 }, 1844 { 1845 'params': [ 1846 { 1847 'name': 'x', 1848 'description': '', 1849 'type': 'Number' 1850 }, 1851 { 1852 'name': 'y', 1853 'description': '', 1854 'type': 'Number' 1855 }, 1856 { 1857 'name': 'z', 1858 'description': '<p>z-coordinate of the vertex (for WebGL mode)</p>\n', 1859 'type': 'Number', 1860 'optional': true 1861 } 1862 ], 1863 'chainable': 1 1864 } 1865 ] 1866 }, 1867 'endContour': { 1868 'name': 'endContour', 1869 'class': 'p5', 1870 'module': 'Shape' 1871 }, 1872 'endShape': { 1873 'name': 'endShape', 1874 'params': [ 1875 { 1876 'name': 'mode', 1877 'description': '<p>use CLOSE to close the shape</p>\n', 1878 'type': 'Constant', 1879 'optional': true 1880 } 1881 ], 1882 'class': 'p5', 1883 'module': 'Shape' 1884 }, 1885 'quadraticVertex': { 1886 'name': 'quadraticVertex', 1887 'class': 'p5', 1888 'module': 'Shape', 1889 'overloads': [ 1890 { 1891 'params': [ 1892 { 1893 'name': 'cx', 1894 'description': '<p>x-coordinate for the control point</p>\n', 1895 'type': 'Number' 1896 }, 1897 { 1898 'name': 'cy', 1899 'description': '<p>y-coordinate for the control point</p>\n', 1900 'type': 'Number' 1901 }, 1902 { 1903 'name': 'x3', 1904 'description': '<p>
1904x-coordinate for the anchor point</p>\n', 1905 'type': 'Number' 1906 }, 1907 { 1908 'name': 'y3', 1909 'description': '<p>y-coordinate for the anchor point</p>\n', 1910 'type': 'Number' 1911 } 1912 ], 1913 'chainable': 1 1914 }, 1915 { 1916 'params': [ 1917 { 1918 'name': 'cx', 1919 'description': '', 1920 'type': 'Number' 1921 }, 1922 { 1923 'name': 'cy', 1924 'description': '', 1925 'type': 'Number' 1926 }, 1927 { 1928 'name': 'cz', 1929 'description': '<p>z-coordinate for the control point (for WebGL mode)</p>\n', 1930 'type': 'Number' 1931 }, 1932 { 1933 'name': 'x3', 1934 'description': '', 1935 'type': 'Number' 1936 }, 1937 { 1938 'name': 'y3', 1939 'description': '', 1940 'type': 'Number' 1941 }, 1942 { 1943 'name': 'z3', 1944 'description': '<p>z-coordinate for the anchor point (for WebGL mode)</p>\n', 1945 'type': 'Number' 1946 } 1947 ], 1948 'chainable': 1 1949 } 1950 ] 1951 }, 1952 'vertex': { 1953 'name': 'vertex', 1954 'class': 'p5', 1955 'module': 'Shape', 1956 'overloads': [ 1957 { 1958 'params': [ 1959 { 1960 'name': 'x', 1961 'description': '<p>x-coordinate of the vertex</p>\n', 1962 'type': 'Number' 1963 }, 1964 { 1965 'name': 'y', 1966 'description': '<p>y-coordinate of the vertex</p>\n', 1967 'type': 'Number' 1968 } 1969 ], 1970 'chainable': 1 1971 }, 1972 { 1973 'params': [ 1974 { 1975 'name': 'x', 1976 'description': '', 1977 'type': 'Number' 1978 }, 1979 { 1980 'name': 'y', 1981 'description': '', 1982 'type': 'Number' 1983 }, 1984 { 1985 'name': 'z', 1986 'description': '<p>z-coordinate of the vertex.\n Defaults to 0 if not specified.</p>\n', 1987 'type': 'Number', 1988 'optional': true 1989 } 1990 ], 1991 'chainable': 1 1992 }, 1993 { 1994 'params': [ 1995 { 1996 'name': 'x', 1997 'description': '', 1998 'type': 'Number' 1999 }, 2000 { 2001 'name': 'y', 2002 'description': '', 2003 'type': 'Number' 2004 }, 2005 { 2006 'name': 'z', 2007 'description': '', 2008 'type': 'Number', 2009 'optional': true 2010 }, 2011 { 2012 'name': 'u', 2013 'description': '<p>the vertex\'s texture u-coordinate</p>\n', 2014 'type': 'Number', 2015 'optional': true 2016 }, 2017 { 2018 'name': 'v', 2019 'description': '<p>the vertex\'s texture v-coordinate</p>\n', 2020 'type': 'Number', 2021 'optional': true 2022 } 2023 ], 2024 'chainable': 1 2025 } 2026 ] 2027 }, 2028 'normal': { 2029 'name': 'normal', 2030 'class': 'p5', 2031 'module': 'Shape', 2032 'overloads': [ 2033 { 2034 'params': [ 2035 { 2036 'name': 'vector', 2037 'description': '<p>A p5.Vector representing the vertex normal.</p>\n', 2038 'type': 'Vector' 2039 } 2040 ], 2041 'chainable': 1 2042 }, 2043 { 2044 'params': [ 2045 { 2046 'name': 'x', 2047 'description': '<p>The x component of the vertex normal.</p>\n', 2048 'type': 'Number' 2049 }, 2050 { 2051 'name': 'y', 2052 'description': '<p>The y component of the vertex normal.</p>\n', 2053 'type': 'Number' 2054 }, 2055 { 2056 'name': 'z', 2057 'description': '<p>The z component of the vertex normal.</p>\n', 2058 'type': 'Number' 2059 } 2060 ], 2061 'chainable': 1 2062 } 2063 ] 2064 }, 2065 'VERSION': { 2066 'name': 'VERSION', 2067 'class': 'p5', 2068 'module': 'Constants' 2069 }, 2070 'P2D': { 2071 'name': 'P2D', 2072 'class': 'p5', 2073 'module': 'Constants' 2074 }, 2075 'WEBGL': { 2076 'name': 'WEBGL', 2077 'class': 'p5', 2078 'module': 'Constants' 2079 }, 2080 'ARROW': { 2081 'name': 'ARROW', 2082 'class': 'p5', 2083 'module': 'Constants' 2084 }, 2085 'CROSS': { 2086 'name': 'CROSS', 2087 'class': 'p5', 2088 'module': 'Constants' 2089 }, 2090 'HAND': { 2091 'name': 'HAND', 2092 'class': 'p5', 2093 'module': 'Constants' 2094 }, 2095 'MOVE': { 2096 'name': 'MOVE', 2097 'class': 'p5', 2098 'module': 'Constants' 2099 }, 2100 'TEXT': { 2101 'name': 'TEXT', 2102 'class': 'p5', 2103 'module': 'Constants' 2104 }, 2105 'WAIT': { 2106 'name': 'WAIT', 2107 'class': 'p5', 2108 'module': 'Constants' 2109 }, 2110 'HALF_PI': { 2111 'name': 'HALF_PI', 2112 'class': 'p5', 2113 'module': 'Constants' 2114 }, 2115 'PI': { 2116 'name': 'PI', 2117 'class': 'p5', 2118 'module': 'Constants' 2119 },
2120 'QUARTER_PI': { 2121 'name': 'QUARTER_PI', 2122 'class': 'p5', 2123 'module': 'Constants' 2124 }, 2125 'TAU': { 2126 'name': 'TAU', 2127 'class': 'p5', 2128 'module': 'Constants' 2129 }, 2130 'TWO_PI': { 2131 'name': 'TWO_PI', 2132 'class': 'p5', 2133 'module': 'Constants' 2134 }, 2135 'DEGREES': { 2136 'name': 'DEGREES', 2137 'class': 'p5', 2138 'module': 'Constants' 2139 }, 2140 'RADIANS': { 2141 'name': 'RADIANS', 2142 'class': 'p5', 2143 'module': 'Constants' 2144 }, 2145 'CORNER': { 2146 'name': 'CORNER', 2147 'class': 'p5', 2148 'module': 'Constants' 2149 }, 2150 'CORNERS': { 2151 'name': 'CORNERS', 2152 'class': 'p5', 2153 'module': 'Constants' 2154 }, 2155 'RADIUS': { 2156 'name': 'RADIUS', 2157 'class': 'p5', 2158 'module': 'Constants' 2159 }, 2160 'RIGHT': { 2161 'name': 'RIGHT', 2162 'class': 'p5', 2163 'module': 'Constants' 2164 }, 2165 'LEFT': { 2166 'name': 'LEFT', 2167 'class': 'p5', 2168 'module': 'Constants' 2169 }, 2170 'CENTER': { 2171 'name': 'CENTER', 2172 'class': 'p5', 2173 'module': 'Constants' 2174 }, 2175 'TOP': { 2176 'name': 'TOP', 2177 'class': 'p5', 2178 'module': 'Constants' 2179 }, 2180 'BOTTOM': { 2181 'name': 'BOTTOM', 2182 'class': 'p5', 2183 'module': 'Constants' 2184 }, 2185 'BASELINE': { 2186 'name': 'BASELINE', 2187 'class': 'p5', 2188 'module': 'Constants' 2189 }, 2190 'POINTS': { 2191 'name': 'POINTS', 2192 'class': 'p5', 2193 'module': 'Constants' 2194 }, 2195 'LINES': { 2196 'name': 'LINES', 2197 'class': 'p5', 2198 'module': 'Constants' 2199 }, 2200 'LINE_STRIP': { 2201 'name': 'LINE_STRIP', 2202 'class': 'p5', 2203 'module': 'Constants' 2204 }, 2205 'LINE_LOOP': { 2206 'name': 'LINE_LOOP', 2207 'class': 'p5', 2208 'module': 'Constants' 2209 }, 2210 'TRIANGLES': { 2211 'name': 'TRIANGLES', 2212 'class': 'p5', 2213 'module': 'Constants' 2214 }, 2215 'TRIANGLE_FAN': { 2216 'name': 'TRIANGLE_FAN', 2217 'class': 'p5', 2218 'module': 'Constants' 2219 }, 2220 'TRIANGLE_STRIP': { 2221 'name': 'TRIANGLE_STRIP', 2222 'class': 'p5', 2223 'module': 'Constants' 2224 }, 2225 'QUADS': { 2226 'name': 'QUADS', 2227 'class': 'p5', 2228 'module': 'Constants' 2229 }, 2230 'QUAD_STRIP': { 2231 'name': 'QUAD_STRIP', 2232 'class': 'p5', 2233 'module': 'Constants' 2234 }, 2235 'TESS': { 2236 'name': 'TESS', 2237 'class': 'p5', 2238 'module': 'Constants' 2239 }, 2240 'CLOSE': { 2241 'name': 'CLOSE', 2242 'class': 'p5', 2243 'module': 'Constants' 2244 }, 2245 'OPEN': { 2246 'name': 'OPEN', 2247 'class': 'p5', 2248 'module': 'Constants' 2249 }, 2250 'CHORD': { 2251 'name': 'CHORD', 2252 'class': 'p5', 2253 'module': 'Constants' 2254 }, 2255 'PIE': { 2256 'name': 'PIE', 2257 'class': 'p5', 2258 'module': 'Constants' 2259 }, 2260 'PROJECT': { 2261 'name': 'PROJECT', 2262 'class': 'p5', 2263 'module': 'Constants' 2264 }, 2265 'SQUARE': { 2266 'name': 'SQUARE', 2267 'class': 'p5', 2268 'module': 'Constants' 2269 }, 2270 'ROUND': { 2271 'name': 'ROUND', 2272 'class': 'p5', 2273 'module': 'Constants' 2274 }, 2275 'BEVEL': { 2276 'name': 'BEVEL', 2277 'class': 'p5', 2278 'module': 'Constants' 2279 }, 2280 'MITER': { 2281 'name': 'MITER', 2282 'class': 'p5', 2283 'module': 'Constants' 2284 }, 2285 'RGB': { 2286 'name': 'RGB', 2287 'class': 'p5', 2288 'module': 'Constants' 2289 }, 2290 'HSB': { 2291 'name': 'HSB', 2292 'class': 'p5', 2293 'module': 'Constants' 2294 }, 2295 'HSL': { 2296 'name': 'HSL', 2297 'class': 'p5', 2298 'module': 'Constants' 2299 }, 2300 'AUTO': { 2301 'name': 'AUTO', 2302 'class': 'p5', 2303 'module': 'Constants' 2304 }, 2305 'ALT': { 2306 'name': 'ALT', 2307 'class': 'p5', 2308 'module': 'Constants' 2309 }, 2310 'BACKSPACE': { 2311 'name': 'BACKSPACE', 2312 'class': 'p5', 2313 'module': 'Constants' 2314 }, 2315 'CONTROL': { 2316 'name': 'CONTROL', 2317 'class': 'p5', 2318 'module': 'Constants' 2319 }, 2320 'DELETE': { 2321 'name': 'DELETE', 2322 'class': 'p5', 2323 'module': 'Constants' 2324 }, 2325 'DOWN_ARROW': { 2326 'name': 'DOWN_ARROW', 2327 'class': 'p5', 2328 'module': 'Constants' 2329 }, 2330 'ENTER': { 2331 'name': 'ENTER', 2332 'class': 'p5', 2333 'module': 'Constants' 2334 }, 2335 'ESCAPE': { 2336 'name': 'ESCAPE', 2337 'class': 'p5', 2338 'module': 'Constants' 2339 }, 2340 'LEFT_ARROW': { 2341 'name': 'LEFT_ARROW', 2342 'class': 'p5', 2343 'module': 'Constants' 2344 }, 2345 'OPTION': { 2346 'name': 'OPTION', 2347 'class': 'p5', 2348 'module': 'Constants' 2349 }, 2350 'RETURN': { 2351 'name': 'RETURN', 2352 'class': 'p5', 2353 'module': 'Constants' 2354 }, 2355 'RIGHT_ARROW': { 2356 'name': 'RIGHT_ARROW', 2357 'class': 'p5', 2358 'module': 'Constants' 2359 }, 2360 'SHIFT': { 2361 'name': 'SHIFT', 2362 'class': 'p5', 2363 'module': 'Constants' 2364 }, 2365 'TAB': { 2366 'name': 'TAB', 2367 'class': 'p5', 2368 'module': 'Constants' 2369 }, 2370 'UP_ARROW': { 2371 'name': 'UP_ARROW', 2372 'class': 'p5', 2373 'module': 'Constants' 2374 }, 2375 'BLEND': { 2376 'name': 'BLEND', 2377 'class': 'p5', 2378 'module': 'Constants' 2379 }, 2380 'REMOVE': { 2381 'name': 'REMOVE', 2382 'class': 'p5', 2383 'module': 'Constants' 2384 }, 2385 'ADD': { 2386 'name': 'ADD', 2387 'class': 'p5', 2388 'module': 'Constants' 2389 }, 2390 'DARKEST': { 2391 'name': 'DARKEST', 2392 'class': 'p5', 2393 'module': 'Constants' 2394 }, 2395 'LIGHTEST': { 2396 'name': 'LIGHTEST', 2397 'class': 'p5', 2398 'module': 'Constants' 2399 }, 2400 'DIFFERENCE': { 2401 'name': 'DIFFERENCE', 2402 'class': 'p5', 2403 'module': 'Constants' 2404 }, 2405 'SUBTRACT': { 2406 'name': 'SUBTRACT', 2407 'class': 'p5', 2408 'module': 'Constants' 2409 }, 2410 'EXCLUSION': { 2411 'name': 'EXCLUSION', 2412 'class': 'p5', 2413 'module': 'Constants' 2414 }, 2415 'MULTIPLY': { 2416 'name': 'MULTIPLY', 2417 'class': 'p5', 2418 'module': 'Constants' 2419 }, 2420 'SCREEN': { 2421 'name': 'SCREEN', 2422 'class': 'p5', 2423 'module': 'Constants' 2424 }, 2425 'REPLACE': { 2426 'name': 'REPLACE', 2427 'class': 'p5', 2428 'module': 'Constants' 2429 }, 2430 'OVERLAY': { 2431 'name': 'OVERLAY', 2432 'class': 'p5', 2433 'module': 'Constants' 2434 }, 2435 'HARD_LIGHT': { 2436 'name': 'HARD_LIGHT', 2437 'class': 'p5', 2438 'module': 'Constants' 2439 }, 2440 'SOFT_LIGHT': { 2441 'name': 'SOFT_LIGHT', 2442 'class': 'p5', 2443 'module': 'Constants' 2444 }, 2445 'DODGE': { 2446 'name': 'DODGE', 2447 'class': 'p5', 2448 'module': 'Constants' 2449 }, 2450 'BURN': { 2451 'name': 'BURN', 2452 'class': 'p5', 2453 'module': 'Constants' 2454 }, 2455 'THRESHOLD': { 2456 'name': 'THRESHOLD', 2457 'class': 'p5', 2458 'module': 'Constants' 2459 }, 2460 'GRAY': { 2461 'name': 'GRAY', 2462 'class': 'p5', 2463 'module': 'Constants' 2464 }, 2465 'OPAQUE': { 2466 'name': 'OPAQUE', 2467 'class': 'p5', 2468 'module': 'Constants' 2469 }, 2470 'INVERT': { 2471 'name': 'INVERT', 2472 'class': 'p5', 2473 'module': 'Constants' 2474 }, 2475 'POSTERIZE': { 2476 'name': 'POSTERIZE', 2477 'class': 'p5', 2478 'module': 'Constants' 2479 }, 2480 'DILATE': { 2481 'name': 'DILATE', 2482 'class': 'p5', 2483 'module': 'Constants' 2484 }, 2485 'ERODE': { 2486 'name': 'ERODE', 2487 'class': 'p5', 2488 'module': 'Constants' 2489 }, 2490 'BLUR': { 2491 'name': 'BLUR', 2492 'class': 'p5', 2493 'module': 'Constants' 2494 },
2495 'NORMAL': { 2496 'name': 'NORMAL', 2497 'class': 'p5', 2498 'module': 'Constants' 2499 }, 2500 'ITALIC': { 2501 'name': 'ITALIC', 2502 'class': 'p5', 2503 'module': 'Constants' 2504 }, 2505 'BOLD': { 2506 'name': 'BOLD', 2507 'class': 'p5', 2508 'module': 'Constants' 2509 }, 2510 'BOLDITALIC': { 2511 'name': 'BOLDITALIC', 2512 'class': 'p5', 2513 'module': 'Constants' 2514 }, 2515 'CHAR': { 2516 'name': 'CHAR', 2517 'class': 'p5', 2518 'module': 'Constants' 2519 }, 2520 'WORD': { 2521 'name': 'WORD', 2522 'class': 'p5', 2523 'module': 'Constants' 2524 }, 2525 'LINEAR': { 2526 'name': 'LINEAR', 2527 'class': 'p5', 2528 'module': 'Constants' 2529 }, 2530 'QUADRATIC': { 2531 'name': 'QUADRATIC', 2532 'class': 'p5', 2533 'module': 'Constants' 2534 }, 2535 'BEZIER': { 2536 'name': 'BEZIER', 2537 'class': 'p5', 2538 'module': 'Constants' 2539 }, 2540 'CURVE': { 2541 'name': 'CURVE', 2542 'class': 'p5', 2543 'module': 'Constants' 2544 }, 2545 'STROKE': { 2546 'name': 'STROKE', 2547 'class': 'p5', 2548 'module': 'Constants' 2549 }, 2550 'FILL': { 2551 'name': 'FILL', 2552 'class': 'p5', 2553 'module': 'Constants' 2554 }, 2555 'TEXTURE': { 2556 'name': 'TEXTURE', 2557 'class': 'p5', 2558 'module': 'Constants' 2559 }, 2560 'IMMEDIATE': { 2561 'name': 'IMMEDIATE', 2562 'class': 'p5', 2563 'module': 'Constants' 2564 }, 2565 'IMAGE': { 2566 'name': 'IMAGE', 2567 'class': 'p5', 2568 'module': 'Constants' 2569 }, 2570 'NEAREST': { 2571 'name': 'NEAREST', 2572 'class': 'p5', 2573 'module': 'Constants' 2574 }, 2575 'REPEAT': { 2576 'name': 'REPEAT', 2577 'class': 'p5', 2578 'module': 'Constants' 2579 }, 2580 'CLAMP': { 2581 'name': 'CLAMP', 2582 'class': 'p5', 2583 'module': 'Constants' 2584 }, 2585 'MIRROR': { 2586 'name': 'MIRROR', 2587 'class': 'p5', 2588 'module': 'Constants' 2589 }, 2590 'LANDSCAPE': { 2591 'name': 'LANDSCAPE', 2592 'class': 'p5', 2593 'module': 'Constants' 2594 }, 2595 'PORTRAIT': { 2596 'name': 'PORTRAIT', 2597 'class': 'p5', 2598 'module': 'Constants' 2599 }, 2600 'GRID': { 2601 'name': 'GRID', 2602 'class': 'p5', 2603 'module': 'Constants' 2604 }, 2605 'AXES': { 2606 'name': 'AXES', 2607 'class': 'p5', 2608 'module': 'Constants' 2609 }, 2610 'LABEL': { 2611 'name': 'LABEL', 2612 'class': 'p5', 2613 'module': 'Constants' 2614 }, 2615 'FALLBACK': { 2616 'name': 'FALLBACK', 2617 'class': 'p5', 2618 'module': 'Constants' 2619 }, 2620 'CONTAIN': { 2621 'name': 'CONTAIN', 2622 'class': 'p5', 2623 'module': 'Constants' 2624 }, 2625 'COVER': { 2626 'name': 'COVER', 2627 'class': 'p5', 2628 'module': 'Constants' 2629 }, 2630 'print': { 2631 'name': 'print', 2632 'params': [ 2633 { 2634 'name': 'contents', 2635 'description': '<p>any combination of Number, String, Object, Boolean,\n Array to print</p>\n', 2636 'type': 'Any' 2637 } 2638 ], 2639 'class': 'p5', 2640 'module': 'Environment' 2641 }, 2642 'frameCount': { 2643 'name': 'frameCount', 2644 'class': 'p5', 2645 'module': 'Environment' 2646 }, 2647 'deltaTime': { 2648 'name': 'deltaTime', 2649 'class': 'p5', 2650 'module': 'Environment' 2651 },
2652 'focused': { 2653 'name': 'focused', 2654 'class': 'p5', 2655 'module': 'Environment' 2656 }, 2657 'cursor': { 2658 'name': 'cursor', 2659 'params': [ 2660 { 2661 'name': 'type', 2662 'description': '<p>Built-In: either ARROW, CROSS, HAND, MOVE, TEXT and WAIT\n Native CSS properties: \'grab\', \'progress\', \'cell\' etc.\n External: path for cursor\'s images\n (Allowed File extensions: .cur, .gif, .jpg, .jpeg, .png)\n For more information on Native CSS cursors and url visit:\n <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/cursor">https://developer.mozilla.org/en-US/docs/Web/CSS/cursor</a></p>\n', 2663 'type': 'String|Constant' 2664 }, 2665 { 2666 'name': 'x', 2667 'description': '<p>the horizontal active spot of the cursor (must be less than 32)</p>\n', 2668 'type': 'Number', 2669 'optional': true 2670 }, 2671 { 2672 'name': 'y', 2673 'description': '<p>the vertical active spot of the cursor (must be less than 32)</p>\n', 2674 'type': 'Number', 2675 'optional': true 2676 } 2677 ], 2678 'class': 'p5', 2679 'module': 'Environment' 2680 }, 2681 'frameRate': { 2682 'name': 'frameRate', 2683 'class': 'p5', 2684 'module': 'Environment', 2685 'overloads': [ 2686 { 2687 'params': [ 2688 { 2689 'name': 'fps', 2690 'description': '<p>number of frames to be displayed every second</p>\n', 2691 'type': 'Number' 2692 } 2693 ], 2694 'chainable': 1 2695 }, 2696 { 2697 'params': [ 2698 ] 2699 } 2700 ] 2701 }, 2702 'getTargetFrameRate': { 2703 'name': 'getTargetFrameRate', 2704 'class': 'p5', 2705 'module': 'Environment' 2706 }, 2707 'noCursor': { 2708 'name': 'noCursor', 2709 'class': 'p5', 2710 'module': 'Environment' 2711 }, 2712 'displayWidth': { 2713 'name': 'displayWidth', 2714 'class': 'p5', 2715 'module': 'Environment' 2716 }, 2717 'displayHeight': { 2718 'name': 'displayHeight', 2719 'class': 'p5', 2720 'module': 'Environment' 2721 }, 2722 'windowWidth': { 2723 'name': 'windowWidth', 2724 'class': 'p5', 2725 'module': 'Environment' 2726 }, 2727 'windowHeight': { 2728 'name': 'windowHeight', 2729 'class': 'p5', 2730 'module': 'Environment' 2731 }, 2732 'windowResized': { 2733 'name': 'windowResized', 2734 'params': [ 2735 { 2736 'name': 'event', 2737 'description': '<p>optional Event callback argument.</p>\n', 2738 'type': 'Object', 2739 'optional': true 2740 } 2741 ], 2742 'class': 'p5', 2743 'module': 'Environment' 2744 }, 2745 'width': { 2746 'name': 'width', 2747 'class': 'p5', 2748 'module': 'Environment' 2749 }, 2750 'height': { 2751 'name': 'height', 2752 'class': 'p5', 2753 'module': 'Environment' 2754 }, 2755 'fullscreen': { 2756 'name': 'fullscreen', 2757 'params': [ 2758 { 2759 'name': 'val', 2760 'description': '<p>whether the sketch should be in fullscreen mode\nor not</p>\n', 2761 'type': 'Boolean', 2762 'optional': true 2763 } 2764 ], 2765 'class': 'p5', 2766 'module': 'Environment' 2767 }, 2768 'pixelDensity': { 2769 'name': 'pixelDensity', 2770 'class': 'p5', 2771 'module': 'Environment', 2772 'overloads': [ 2773 { 2774 'params': [ 2775 { 2776 'name': 'val', 2777 'description': '<p>whether or how much the sketch should scale</p>\n', 2778 'type': 'Number' 2779 } 2780 ], 2781 'chainable': 1 2782 }, 2783 { 2784 'params': [ 2785 ] 2786 } 2787 ] 2788 }, 2789 'displayDensity': { 2790 'name': 'displayDensity', 2791 'class': 'p5', 2792 'module': 'Environment' 2793 }, 2794 'getURL': { 2795 'name': 'getURL', 2796 'class': 'p5', 2797 'module': 'Environment' 2798 }, 2799 'getURLPath': { 2800 'name': 'getURLPath', 2801 'class': 'p5', 2802 'module': 'Environment' 2803 }, 2804 'getURLParams': { 2805 'name': 'getURLParams', 2806 'class': 'p5', 2807 'module': 'Environment' 2808 }, 2809 'preload': { 2810 'name': 'preload', 2811 'class': 'p5', 2812 'module': 'Structure' 2813 }, 2814 'setup': { 2815 'name': 'setup', 2816 'class': 'p5', 2817 'module': 'Structure' 2818 }, 2819 'draw': { 2820 'name': 'draw', 2821 'class': 'p5', 2822 'module': 'Structure' 2823 }, 2824 'remove': { 2825 'name': 'remove', 2826 'class': 'p5', 2827 'module': 'Structure' 2828 }, 2829 'disableFriendlyErrors': { 2830 'name': 'disableFriendlyErrors', 2831 'class': 'p5', 2832 'module': 'Structure' 2833 }, 2834 'let': { 2835 'name': 'let', 2836 'class': 'p5', 2837 'module': 'Foundation' 2838 }, 2839 'const': { 2840 'name': 'const', 2841 'class': 'p5', 2842 'module': 'Foundation' 2843 }, 2844 '===': {
2845 'name': '===', 2846 'class': 'p5', 2847 'module': 'Foundation' 2848 }, 2849 '>': { 2850 'name': '>', 2851 'class': 'p5', 2852 'module': 'Foundation' 2853 }, 2854 '>=': { 2855 'name': '>=', 2856 'class': 'p5', 2857 'module': 'Foundation' 2858 }, 2859 '<': { 2860 'name': '<', 2861 'class': 'p5', 2862 'module': 'Foundation' 2863 }, 2864 '<=': { 2865 'name': '<=', 2866 'class': 'p5', 2867 'module': 'Foundation' 2868 }, 2869 'if-else': { 2870 'name': 'if-else', 2871 'class': 'p5', 2872 'module': 'Foundation' 2873 }, 2874 'function': { 2875 'name': 'function', 2876 'class': 'p5', 2877 'module': 'Foundation' 2878 }, 2879 'return': { 2880 'name': 'return', 2881 'class': 'p5', 2882 'module': 'Foundation' 2883 }, 2884 'boolean': { 2885 'name': 'boolean', 2886 'params': [ 2887 { 2888 'name': 'n', 2889 'description': '<p>value to parse</p>\n', 2890 'type': 'String|Boolean|Number|Array' 2891 } 2892 ], 2893 'class': 'p5', 2894 'module': 'Data' 2895 }, 2896 'string': { 2897 'name': 'string', 2898 'class': 'p5', 2899 'module': 'Foundation' 2900 }, 2901 'number': { 2902 'name': 'number', 2903 'class': 'p5', 2904 'module': 'Foundation' 2905 }, 2906 'object': { 2907 'name': 'object', 2908 'class': 'p5', 2909 'module': 'Foundation' 2910 }, 2911 'class': { 2912 'name': 'class', 2913 'class': 'p5', 2914 'module': 'Foundation' 2915 }, 2916 'for': { 2917 'name': 'for', 2918 'class': 'p5', 2919 'module': 'Foundation' 2920 }, 2921 'while': { 2922 'name': 'while', 2923 'class': 'p5', 2924 'module': 'Foundation' 2925 }, 2926 'createCanvas': { 2927 'name': 'createCanvas', 2928 'params': [ 2929 { 2930 'name': 'w', 2931 'description': '<p>width of the canvas</p>\n', 2932 'type': 'Number' 2933 }, 2934 { 2935 'name': 'h', 2936 'description': '<p>height of the canvas</p>\n', 2937 'type': 'Number' 2938 }, 2939 { 2940 'name': 'renderer', 2941 'description': '<p>either P2D or WEBGL</p>\n', 2942 'type': 'Constant', 2943 'optional': true 2944 } 2945 ], 2946 'class': 'p5', 2947 'module': 'Rendering' 2948 }, 2949 'resizeCanvas': { 2950 'name': 'resizeCanvas', 2951 'params': [ 2952 { 2953 'name': 'w', 2954 'description': '<p>width of the canvas</p>\n', 2955 'type': 'Number' 2956 }, 2957 { 2958 'name': 'h', 2959 'description': '<p>height of the canvas</p>\n', 2960 'type': 'Number' 2961 }, 2962 { 2963 'name': 'noRedraw', 2964 'description': '<p>don\'t redraw the canvas immediately</p>\n', 2965 'type': 'Boolean', 2966 'optional': true 2967 } 2968 ], 2969 'class': 'p5', 2970 'module': 'Rendering' 2971 }, 2972 'noCanvas': { 2973 'name': 'noCanvas', 2974 'class': 'p5', 2975 'module': 'Rendering' 2976 }, 2977 'createGraphics': { 2978 'name': 'createGraphics', 2979 'params': [ 2980 { 2981 'name': 'w', 2982 'description': '<p>width of the offscreen graphics buffer</p>\n', 2983 'type': 'Number' 2984 }, 2985 { 2986 'name': 'h', 2987 'description': '<p>height of the offscreen graphics buffer</p>\n', 2988 'type': 'Number' 2989 }, 2990 { 2991 'name': 'renderer', 2992 'description': '<p>either P2D or WEBGL\n undefined defaults to p2d</p>\n', 2993 'type': 'Constant', 2994 'optional': true 2995 } 2996 ], 2997 'class': 'p5', 2998 'module': 'Rendering' 2999 }, 3000 'blendMode': { 3001 'name': 'blendMode', 3002 'params': [ 3003 { 3004 'name': 'mode', 3005 'description': '<p>blend mode to set for canvas.\n either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY,\n EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT</p>\n', 3006 'type': 'Constant' 3007 } 3008 ], 3009 'class': 'p5', 3010 'module': 'Rendering' 3011 }, 3012 'drawingContext': { 3013 'name': 'drawingContext', 3014 'class': 'p5', 3015 'module': 'Rendering' 3016 }, 3017 'noLoop': { 3018 'name': 'noLoop', 3019 'class': 'p5', 3020 'module': 'Structure' 3021 }, 3022 'loop': { 3023 'name': 'loop', 3024 'class': 'p5', 3025 'module': 'Structure' 3026 }, 3027 'isLooping': { 3028 'name': 'isLooping', 3029 'class': 'p5', 3030 'module': 'Structure' 3031 }, 3032 'push': { 3033 'name': 'push', 3034 'class': 'p5', 3035 'module': 'Structure' 3036 }, 3037 'pop': { 3038 'name': 'pop', 3039 'class': 'p5', 3040 'module': 'Structure' 3041 }, 3042 'redraw': { 3043 'name': 'redraw', 3044 'params': [ 3045 { 3046 'name': 'n', 3047 'description': '<p>Redraw for n-times. The default value is 1.</p>\n', 3048 'type': 'Integer', 3049 'optional': true 3050 } 3051 ], 3052 'class': 'p5', 3053 'module': 'Structure' 3054 }, 3055 'p5': { 3056 'name': 'p5', 3057 'params': [ 3058 { 3059 'name': 'sketch', 3060 'description': '<p>a function containing a p5.js sketch</p>\n', 3061 'type': 'Object' 3062 }, 3063 { 3064 'name': 'node', 3065 'description': '<p>ID or pointer to HTML DOM node to contain sketch in</p>\n', 3066 'type': 'String|Object' 3067 } 3068 ], 3069 'class': 'p5', 3070 'module': 'Structure' 3071 },
3072 'applyMatrix': { 3073 'name': 'applyMatrix', 3074 'class': 'p5', 3075 'module': 'Transform', 3076 'overloads': [ 3077 { 3078 'params': [ 3079 { 3080 'name': 'arr', 3081 'description': '<p>an array of numbers - should be 6 or 16 length (2<em>3 or 4</em>4 matrix values)</p>\n', 3082 'type': 'Array' 3083 } 3084 ], 3085 'chainable': 1 3086 }, 3087 { 3088 'params': [ 3089 { 3090 'name': 'a', 3091 'description': '<p>numbers which define the 2Ã3 or 4x4 matrix to be multiplied</p>\n', 3092 'type': 'Number' 3093 }, 3094 { 3095 'name': 'b', 3096 'description': '<p>numbers which define the 2Ã3 or 4x4 matrix to be multiplied</p>\n', 3097 'type': 'Number' 3098 }, 3099 { 3100 'name': 'c', 3101 'description': '<p>numbers which define the 2Ã3 or 4x4 matrix to be multiplied</p>\n', 3102 'type': 'Number' 3103 }, 3104 { 3105 'name': 'd', 3106 'description': '<p>numbers which define the 2Ã3 or 4x4 matrix to be multiplied</p>\n', 3107 'type': 'Number' 3108 }, 3109 { 3110 'name': 'e', 3111 'description': '<p>numbers which define the 2Ã3 or 4x4 matrix to be multiplied</p>\n', 3112 'type': 'Number' 3113 }, 3114 { 3115 'name': 'f', 3116 'description': '<p>numbers which define the 2Ã3 or 4x4 matrix to be multiplied</p>\n', 3117 'type': 'Number' 3118 } 3119 ], 3120 'chainable': 1 3121 }, 3122 { 3123 'params': [ 3124 { 3125 'name': 'a', 3126 'description': '', 3127 'type': 'Number' 3128 }, 3129 { 3130 'name': 'b', 3131 'description': '', 3132 'type': 'Number' 3133 }, 3134 { 3135 'name': 'c', 3136 'description': '', 3137 'type': 'Number' 3138 }, 3139 { 3140 'name': 'd', 3141 'description': '', 3142 'type': 'Number' 3143 }, 3144 { 3145 'name': 'e', 3146 'description': '', 3147 'type': 'Number' 3148 }, 3149 { 3150 'name': 'f', 3151 'description': '', 3152 'type': 'Number' 3153 }, 3154 { 3155 'name': 'g', 3156 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3157 'type': 'Number' 3158 }, 3159 { 3160 'name': 'h', 3161 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3162 'type': 'Number' 3163 }, 3164 { 3165 'name': 'i', 3166 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3167 'type': 'Number' 3168 }, 3169 { 3170 'name': 'j', 3171 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3172 'type': 'Number' 3173 }, 3174 { 3175 'name': 'k', 3176 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3177 'type': 'Number' 3178 }, 3179 { 3180 'name': 'l', 3181 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3182 'type': 'Number' 3183 }, 3184 { 3185 'name': 'm', 3186 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3187 'type': 'Number' 3188 }, 3189 { 3190 'name': 'n', 3191 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3192 'type': 'Number' 3193 }, 3194 { 3195 'name': 'o', 3196 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3197 'type': 'Number' 3198 }, 3199 { 3200 'name': 'p', 3201 'description': '<p>numbers which define the 4x4 matrix to be multiplied</p>\n', 3202 'type': 'Number' 3203 } 3204 ], 3205 'chainable': 1 3206 } 3207 ] 3208 }, 3209 'resetMatrix': { 3210 'name': 'resetMatrix', 3211 'class': 'p5', 3212 'module': 'Transform' 3213 }, 3214 'rotate': { 3215 'name': 'rotate', 3216 'params': [ 3217 { 3218 'name': 'angle', 3219 'description': '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n', 3220 'type': 'Number' 3221 }, 3222 { 3223 'name': 'axis', 3224 'description': '<p>(in 3d) the axis to rotate around</p>\n', 3225 'type': 'p5.Vector|Number[]', 3226 'optional': true 3227 } 3228 ], 3229 'class': 'p5', 3230 'module': 'Transform' 3231 }, 3232 'rotateX': { 3233 'name': 'rotateX', 3234 'params': [ 3235 { 3236 'name': 'angle', 3237 'description': '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n', 3238 'type': 'Number' 3239 } 3240 ], 3241 'class': 'p5', 3242 'module': 'Transform' 3243 }, 3244 'rotateY': { 3245 'name': 'rotateY', 3246 'params': [ 3247 { 3248 'name': 'angle', 3249 'description': '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n', 3250 'type': 'Number' 3251 } 3252 ], 3253 'class': 'p5', 3254 'module': 'Transform' 3255 }, 3256 'rotateZ': { 3257 'name': 'rotateZ', 3258 'params': [ 3259 { 3260 'name': 'angle', 3261 'description': '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n', 3262 'type': 'Number' 3263 } 3264 ], 3265 'class': 'p5', 3266 'module': 'Transform' 3267 }, 3268 'scale': { 3269 'name': 'scale', 3270 'class': 'p5', 3271 'module': 'Transform', 3272 'overloads': [ 3273 { 3274 'params': [ 3275 { 3276 'name': 's', 3277 'description': '<p>percent to scale the object, or percentage to\n scale the object in the x-axis if multiple arguments\n are given</p>\n', 3278 'type': 'Number|p5.Vector|Number[]' 3279 }, 3280 { 3281 'name': 'y', 3282 'description': '<p>percent to scale the object in the y-axis</p>\n', 3283 'type': 'Number', 3284 'optional': true 3285 }, 3286 { 3287 'name': 'z', 3288 'description': '<p>percent to scale the object in the z-axis (webgl only)</p>\n', 3289 'type': 'Number', 3290 'optional': true 3291 } 3292 ], 3293 'chainable': 1 3294 }, 3295 { 3296 'params': [ 3297 { 3298 'name': 'scales', 3299 'description': '<p>per-axis percents to scale the object</p>\n', 3300 'type': 'p5.Vector|Number[]' 3301 } 3302 ], 3303 'chainable': 1 3304 } 3305 ] 3306 }, 3307 'shearX': { 3308 'name': 'shearX', 3309 'params': [ 3310 { 3311 'name': 'angle', 3312 'description': '<p>angle of shear specified in radians or degrees,\n depending on current angleMode</p>\n', 3313 'type': 'Number' 3314 } 3315 ], 3316 'class': 'p5', 3317 'module': 'Transform' 3318 }, 3319 'shearY': { 3320 'name': 'shearY', 3321 'params': [ 3322 { 3323 'name': 'angle', 3324 'description': '<p>angle of shear specified in radians or degrees,\n depending on current angleMode</p>\n', 3325 'type': 'Number' 3326 } 3327 ], 3328 'class': 'p5', 3329 'module': 'Transform' 3330 }, 3331 'translate': { 3332 'name': 'translate', 3333 'class': 'p5', 3334 'module': 'Transform', 3335 'overloads': [ 3336 { 3337 'params': [ 3338 { 3339 'name': 'x', 3340 'description': '<p>left/right translation</p>\n', 3341 'type': 'Number' 3342 }, 3343 { 3344 'name': 'y', 3345 'description': '<p>up/down translation</p>\n', 3346 'type': 'Number' 3347 }, 3348 { 3349 'name': 'z', 3350 'description': '<p>forward/backward translation (WEBGL only)</p>\n', 3351 'type': 'Number', 3352 'optional': true 3353 } 3354 ], 3355 'chainable': 1 3356 }, 3357 { 3358 'params': [ 3359 { 3360 'name': 'vector', 3361 'description': '<p>the vector to translate by</p>\n', 3362 'type': 'p5.Vector' 3363 } 3364 ], 3365 'chainable': 1 3366 } 3367 ] 3368 }, 3369 'storeItem': { 3370 'name': 'storeItem', 3371 'params': [ 3372 { 3373 'name': 'key', 3374 'description': '', 3375 'type': 'String' 3376 }, 3377 { 3378 'name': 'value', 3379 'description': '', 3380 'type': 'String|Number|Object|Boolean|p5.Color|p5.Vector' 3381 } 3382 ], 3383 'class': 'p5', 3384 'module': 'Data' 3385 }, 3386 'getItem': { 3387 'name': 'getItem', 3388 'params': [ 3389 { 3390 'name': 'key', 3391 'description': '<p>name that you wish to use to store in local storage</p>\n', 3392 'type': 'String' 3393 } 3394 ], 3395 'class': 'p5', 3396 'module': 'Data' 3397 }, 3398 'clearStorage': { 3399 'name': 'clearStorage', 3400 'class': 'p5', 3401 'module': 'Data' 3402 }, 3403 'removeItem': { 3404 'name': 'removeItem', 3405 'params': [ 3406 { 3407 'name': 'key', 3408 'description': '', 3409 'type': 'String' 3410 } 3411 ], 3412 'class': 'p5', 3413 'module': 'Data' 3414 }, 3415 'createStringDict': { 3416 'name': 'createStringDict', 3417 'class': 'p5', 3418 'module': 'Data', 3419 'overloads': [ 3420 { 3421 'params': [ 3422 { 3423 'name': 'key', 3424 'description': '', 3425 'type': 'String' 3426 }, 3427 { 3428 'name': 'value', 3429 'description': '', 3430 'type': 'String' 3431 } 3432 ] 3433 }, 3434 { 3435 'params': [ 3436 { 3437 'name': 'object', 3438 'description': '<p>object</p>\n', 3439 'type': 'Object' 3440 } 3441 ] 3442 } 3443 ] 3444 }, 3445 'createNumberDict': { 3446 'name': 'createNumberDict', 3447 'class': 'p5', 3448 'module': 'Data', 3449 'overloads': [ 3450 { 3451 'params': [ 3452 { 3453 'name': 'key', 3454 'description': '', 3455 'type': 'Number' 3456 }, 3457 { 3458 'name': 'value', 3459 'description': '', 3460 'type': 'Number' 3461 } 3462 ] 3463 }, 3464 { 3465 'params': [ 3466 { 3467 'name': 'object', 3468 'description': '<p>object</p>\n', 3469 'type': 'Object' 3470 } 3471 ] 3472 } 3473 ] 3474 }, 3475 'select': { 3476 'name': 'select', 3477 'params': [ 3478 { 3479 'name': 'selectors', 3480 'description': '<p>CSS selector string of element to search for</p>\n', 3481 'type': 'String' 3482 }, 3483 { 3484 'name': 'container', 3485 'description': '<p>CSS selector string, <a href="#/p5.Element">p5.Element</a>, or\n HTML element to search within</p>\n', 3486 'type': 'String|p5.Element|HTMLElement', 3487 'optional': true 3488 } 3489 ], 3490 'class': 'p5', 3491 'module': 'DOM' 3492 }, 3493 'selectAll': { 3494 'name': 'selectAll', 3495 'params': [ 3496 { 3497 'name': 'selectors', 3498 'description': '<p>CSS selector string of elements to search for</p>\n', 3499 'type': 'String' 3500 }, 3501 { 3502 'name': 'container', 3503 'description': '<p>CSS selector string, <a href="#/p5.Element">p5.Element</a>\n , or HTML element to search within</p>\n', 3504 'type': 'String|p5.Element|HTMLElement', 3505 'optional': true 3506 } 3507 ], 3508 'class': 'p5', 3509 'module': 'DOM' 3510 }, 3511 'removeElements': { 3512 'name': 'removeElements', 3513 'class': 'p5', 3514 'module': 'DOM' 3515 }, 3516 'changed': { 3517 'name': 'changed', 3518 'params': [ 3519 { 3520 'name': 'fxn', 3521 'description': '<p>function to be fired when the value of\n an element changes.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 3522 'type': 'Function|Boolean' 3523 } 3524 ], 3525 'class': 'p5', 3526 'module': 'DOM'
3527 }, 3528 'input': { 3529 'name': 'input', 3530 'params': [ 3531 { 3532 'name': 'fxn', 3533 'description': '<p>function to be fired when any user input is\n detected within the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 3534 'type': 'Function|Boolean' 3535 } 3536 ], 3537 'class': 'p5', 3538 'module': 'DOM' 3539 }, 3540 'createDiv': { 3541 'name': 'createDiv', 3542 'params': [ 3543 { 3544 'name': 'html', 3545 'description': '<p>inner HTML for element created</p>\n', 3546 'type': 'String', 3547 'optional': true 3548 } 3549 ], 3550 'class': 'p5', 3551 'module': 'DOM' 3552 }, 3553 'createP': { 3554 'name': 'createP', 3555 'params': [ 3556 { 3557 'name': 'html', 3558 'description': '<p>inner HTML for element created</p>\n', 3559 'type': 'String', 3560 'optional': true 3561 } 3562 ], 3563 'class': 'p5', 3564 'module': 'DOM' 3565 }, 3566 'createSpan': { 3567 'name': 'createSpan', 3568 'params': [ 3569 { 3570 'name': 'html', 3571 'description': '<p>inner HTML for element created</p>\n', 3572 'type': 'String', 3573 'optional': true 3574 } 3575 ], 3576 'class': 'p5', 3577 'module': 'DOM' 3578 }, 3579 'createImg': { 3580 'name': 'createImg', 3581 'class': 'p5', 3582 'module': 'DOM', 3583 'overloads': [ 3584 { 3585 'params': [ 3586 { 3587 'name': 'src', 3588 'description': '<p>src path or url for image</p>\n', 3589 'type': 'String' 3590 }, 3591 { 3592 'name': 'alt', 3593 'description': '<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img#Attributes">alternate text</a> to be used if image does not load. You can use also an empty string (<code>""</code>) if that an image is not intended to be viewed.</p>\n', 3594 'type': 'String' 3595 } 3596 ] 3597 }, 3598 { 3599 'params': [ 3600 { 3601 'name': 'src', 3602 'description': '', 3603 'type': 'String' 3604 }, 3605 { 3606 'name': 'alt', 3607 'description': '', 3608 'type': 'String' 3609 }, 3610 { 3611 'name': 'crossOrigin', 3612 'description': '<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes">crossOrigin property</a> of the <code>img</code> element; use either \'anonymous\' or \'use-credentials\' to retrieve the image with cross-origin access (for later use with <code>canvas</code>. if an empty string(<code>""</code>) is passed, CORS is not used</p>\n', 3613 'type': 'String' 3614 }, 3615 { 3616 'name': 'successCallback', 3617 'description': '<p>callback to be called once image data is loaded with the <a href="#/p5.Element">p5.Element</a> as argument</p>\n', 3618 'type': 'Function', 3619 'optional': true 3620 } 3621 ] 3622 } 3623 ] 3624 }, 3625 'createA': { 3626 'name': 'createA', 3627 'params': [ 3628 { 3629 'name': 'href', 3630 'description': '<p>url of page to link to</p>\n', 3631 'type': 'String' 3632 }, 3633 { 3634 'name': 'html', 3635 'description': '<p>inner html of link element to display</p>\n', 3636 'type': 'String' 3637 }, 3638 { 3639 'name': 'target', 3640 'description': '<p>target where new link should open,\n could be _blank, _self, _parent, _top.</p>\n', 3641 'type': 'String', 3642 'optional': true 3643 } 3644 ], 3645 'class': 'p5', 3646 'module': 'DOM' 3647 }, 3648 'createSlider': { 3649 'name': 'createSlider', 3650 'params': [ 3651 { 3652 'name': 'min', 3653 'description': '<p>minimum value of the slider</p>\n', 3654 'type': 'Number' 3655 }, 3656 { 3657 'name': 'max', 3658 'description': '<p>maximum value of the slider</p>\n', 3659 'type': 'Number' 3660 }, 3661 { 3662 'name': 'value', 3663 'description': '<p>default value of the slider</p>\n', 3664 'type': 'Number', 3665 'optional': true 3666 }, 3667 { 3668 'name': 'step', 3669 'description': '<p>step size for each tick of the slider (if step is set to 0, the slider will move continuously from the minimum to the maximum value)</p>\n', 3670 'type': 'Number', 3671 'optional': true 3672 } 3673 ], 3674 'class': 'p5', 3675 'module': 'DOM' 3676 }, 3677 'createButton': { 3678 'name': 'createButton', 3679 'params': [ 3680 { 3681 'name': 'label', 3682 'description': '<p>label displayed on the button</p>\n', 3683 'type': 'String' 3684 }, 3685 { 3686 'name': 'value', 3687 'description': '<p>value of the button</p>\n', 3688 'type': 'String', 3689 'optional': true 3690 } 3691 ], 3692 'class': 'p5', 3693 'module': 'DOM' 3694 }, 3695 'createCheckbox': { 3696 'name': 'createCheckbox', 3697 'params': [ 3698 { 3699 'name': 'label', 3700 'description': '<p>label displayed after checkbox</p>\n', 3701 'type': 'String', 3702 'optional': true 3703 }, 3704 { 3705 'name': 'value', 3706 'description': '<p>value of the checkbox; checked is true, unchecked is false</p>\n', 3707 'type': 'Boolean', 3708 'optional': true 3709 } 3710 ], 3711 'class': 'p5', 3712 'module': 'DOM' 3713 }, 3714 'createSelect': { 3715 'name': 'createSelect', 3716 'class': 'p5', 3717 'module': 'DOM', 3718 'overloads': [ 3719 { 3720 'params': [ 3721 { 3722 'name': 'multiple', 3723 'description': '<p>true if dropdown should support multiple selections</p>\n', 3724 'type': 'Boolean', 3725 'optional': true 3726 } 3727 ] 3728 }, 3729 { 3730 'params': [ 3731 { 3732 'name': 'existing', 3733 'description': '<p>DOM select element</p>\n', 3734 'type': 'Object' 3735 } 3736 ] 3737 } 3738 ] 3739 }, 3740 'createRadio': { 3741 'name': 'createRadio', 3742 'class': 'p5', 3743 'module': 'DOM', 3744 'overloads': [ 3745 { 3746 'params': [ 3747 { 3748 'name': 'containerElement', 3749 'description': '<p>A container HTML Element, either a div\nor span, inside which all existing radio inputs will be considered as options.
3749</p>\n', 3750 'type': 'Object' 3751 }, 3752 { 3753 'name': 'name', 3754 'description': '<p>A name parameter for each Input Element.</p>\n', 3755 'type': 'String', 3756 'optional': true 3757 } 3758 ] 3759 }, 3760 { 3761 'params': [ 3762 { 3763 'name': 'name', 3764 'description': '', 3765 'type': 'String' 3766 } 3767 ] 3768 }, 3769 { 3770 'params': [ 3771 ] 3772 } 3773 ] 3774 }, 3775 'createColorPicker': { 3776 'name': 'createColorPicker', 3777 'params': [ 3778 { 3779 'name': 'value', 3780 'description': '<p>default color of element</p>\n', 3781 'type': 'String|p5.Color', 3782 'optional': true 3783 } 3784 ], 3785 'class': 'p5', 3786 'module': 'DOM' 3787 }, 3788 'createInput': { 3789 'name': 'createInput', 3790 'class': 'p5', 3791 'module': 'DOM', 3792 'overloads': [ 3793 { 3794 'params': [ 3795 { 3796 'name': 'value', 3797 'description': '<p>default value of the input box</p>\n', 3798 'type': 'String' 3799 }, 3800 { 3801 'name': 'type', 3802 'description': '<p>type of text, ie text, password etc. Defaults to text.\n Needs a value to be specified first.</p>\n', 3803 'type': 'String', 3804 'optional': true 3805 } 3806 ] 3807 }, 3808 { 3809 'params': [ 3810 { 3811 'name': 'value', 3812 'description': '', 3813 'type': 'String', 3814 'optional': true 3815 } 3816 ] 3817 } 3818 ] 3819 }, 3820 'createFileInput': { 3821 'name': 'createFileInput', 3822 'params': [ 3823 { 3824 'name': 'callback', 3825 'description': '<p>callback function for when a file is loaded</p>\n', 3826 'type': 'Function' 3827 }, 3828 { 3829 'name': 'multiple', 3830 'description': '<p>optional, to allow multiple files to be selected</p>\n', 3831 'type': 'Boolean', 3832 'optional': true 3833 } 3834 ], 3835 'class': 'p5', 3836 'module': 'DOM' 3837 }, 3838 'createVideo': { 3839 'name': 'createVideo', 3840 'params': [ 3841 { 3842 'name': 'src', 3843 'description': '<p>path to a video file, or array of paths for\n supporting different browsers</p>\n', 3844 'type': 'String|String[]' 3845 }, 3846 { 3847 'name': 'callback', 3848 'description': '<p>callback function to be called upon\n \'canplaythrough\' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content</p>\n', 3849 'type': 'Function', 3850 'optional': true 3851 } 3852 ], 3853 'class': 'p5', 3854 'module': 'DOM' 3855 }, 3856 'createAudio': { 3857 'name': 'createAudio', 3858 'params': [ 3859 { 3860 'name': 'src', 3861 'description': '<p>path to an audio file, or array of paths\n for supporting different browsers</p>\n', 3862 'type': 'String|String[]', 3863 'optional': true 3864 }, 3865 { 3866 'name': 'callback', 3867 'description': '<p>callback function to be called upon\n \'canplaythrough\' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content</p>\n', 3868 'type': 'Function', 3869 'optional': true 3870 } 3871 ], 3872 'class': 'p5', 3873 'module': 'DOM' 3874 }, 3875 'createCapture': { 3876 'name': 'createCapture', 3877 'params': [ 3878 { 3879 'name': 'type', 3880 'description': '<p>type of capture, either VIDEO or\n AUDIO if none specified, default both,\n or a Constraints object</p>\n', 3881 'type': 'String|Constant|Object' 3882 }, 3883 { 3884 'name': 'callback', 3885 'description': '<p>function to be called once\n stream has loaded</p>\n', 3886 'type': 'Function', 3887 'optional': true 3888 } 3889 ], 3890 'class': 'p5', 3891 'module': 'DOM' 3892 }, 3893 'createElement': { 3894 'name': 'createElement', 3895 'params': [ 3896 { 3897 'name': 'tag', 3898 'description': '<p>tag for the new element</p>\n', 3899 'type': 'String' 3900 }, 3901 { 3902 'name': 'content', 3903 'description': '<p>html content to be inserted into the element</p>\n', 3904 'type': 'String', 3905 'optional': true 3906 } 3907 ], 3908 'class': 'p5', 3909 'module': 'DOM' 3910 }, 3911 'deviceOrientation': { 3912 'name': 'deviceOrientation', 3913 'class': 'p5', 3914 'module': 'Events' 3915 }, 3916 'accelerationX': { 3917 'name': 'accelerationX', 3918 'class': 'p5', 3919 'module': 'Events' 3920 }, 3921 'accelerationY': { 3922 'name': 'accelerationY', 3923 'class': 'p5', 3924 'module': 'Events' 3925 }, 3926 'accelerationZ': { 3927 'name': 'accelerationZ', 3928 'class': 'p5', 3929 'module': 'Events' 3930 }, 3931 'pAccelerationX': { 3932 'name': 'pAccelerationX', 3933 'class': 'p5', 3934 'module': 'Events' 3935 }, 3936 'pAccelerationY': { 3937 'name': 'pAccelerationY', 3938 'class': 'p5', 3939 'module': 'Events' 3940 }, 3941 'pAccelerationZ': { 3942 'name': 'pAccelerationZ', 3943 'class': 'p5', 3944 'module': 'Events' 3945 }, 3946 'rotationX': { 3947 'name': 'rotationX', 3948 'class': 'p5', 3949 'module': 'Events' 3950 }, 3951 'rotationY': { 3952 'name': 'rotationY', 3953 'class': 'p5', 3954 'module': 'Events' 3955 }, 3956 'rotationZ': { 3957 'name': 'rotationZ', 3958 'class': 'p5', 3959 'module': 'Events' 3960 }, 3961 'pRotationX': { 3962 'name': 'pRotationX', 3963 'class': 'p5', 3964 'module': 'Events' 3965 }, 3966 'pRotationY': { 3967 'name': 'pRotationY', 3968 'class': 'p5', 3969 'module': 'Events' 3970 }, 3971 'pRotationZ': { 3972 'name': 'pRotationZ', 3973 'class': 'p5', 3974 'module': 'Events' 3975 }, 3976 'turnAxis': { 3977 'name': 'turnAxis', 3978 'class': 'p5', 3979 'module': 'Events' 3980 }, 3981 'setMoveThreshold': { 3982 'name': 'setMoveThreshold', 3983 'params': [ 3984 { 3985 'name': 'value', 3986 'description': '<p>The threshold value</p>\n', 3987 'type': 'Number' 3988 } 3989 ], 3990 'class': 'p5', 3991 'module': 'Events' 3992 }, 3993 'setShakeThreshold': { 3994 'name': 'setShakeThreshold', 3995 'params': [ 3996 { 3997 'name': 'value', 3998 'description': '<p>The threshold value</p>\n', 3999 'type': 'Number' 4000 } 4001 ], 4002 'class': 'p5', 4003 'module': 'Events' 4004 }, 4005 'deviceMoved': { 4006 'name': 'deviceMoved', 4007 'class': 'p5', 4008 'module': 'Events' 4009 }, 4010 'deviceTurned': { 4011 'name': 'deviceTurned', 4012 'class': 'p5', 4013 'module': 'Events' 4014 }, 4015 'deviceShaken': { 4016 'name': 'deviceShaken', 4017 'class': 'p5', 4018 'module': 'Events' 4019 }, 4020 'keyIsPressed': { 4021 'name': 'keyIsPressed', 4022 'class': 'p5', 4023 'module': 'Events' 4024 }, 4025 'key': { 4026 'name': 'key', 4027 'class': 'p5', 4028 'module': 'Events' 4029 }, 4030 'keyCode': { 4031 'name': 'keyCode', 4032 'class': 'p5', 4033 'module': 'Events' 4034 }, 4035 'keyPressed': { 4036 'name': 'keyPressed', 4037 'params': [ 4038 { 4039 'name': 'event', 4040 'description': '<p>optional KeyboardEvent callback argument.</p>\n', 4041 'type': 'Object', 4042 'optional': true 4043 } 4044 ], 4045 'class': 'p5', 4046 'module': 'Events' 4047 }, 4048 'keyReleased': { 4049 'name': 'keyReleased', 4050 'params': [ 4051 { 4052 'name': 'event', 4053 'description': '<p>optional KeyboardEvent callback argument.</p>\n', 4054 'type': 'Object', 4055 'optional': true 4056 } 4057 ], 4058 'class': 'p5', 4059 'module': 'Events' 4060 }, 4061 'keyTyped': { 4062 'name': 'keyTyped', 4063 'params': [ 4064 { 4065 'name': 'event', 4066 'description': '<p>optional KeyboardEvent callback argument.</p>\n', 4067 'type': 'Object', 4068 'optional': true 4069 } 4070 ], 4071 'class': 'p5', 4072 'module': 'Events' 4073 }, 4074 'keyIsDown': { 4075 'name': 'keyIsDown', 4076 'params': [ 4077 { 4078 'name': 'code', 4079 'description': '<p>The key to check for.</p>\n', 4080 'type': 'Number' 4081 } 4082 ], 4083 'class': 'p5', 4084 'module': 'Events' 4085 }, 4086 'movedX': { 4087 'name': 'movedX', 4088 'class': 'p5', 4089 'module': 'Events' 4090 }, 4091 'movedY': { 4092 'name': 'movedY', 4093 'class': 'p5', 4094 'module': 'Events' 4095 }, 4096 'mouseX': { 4097 'name': 'mouseX', 4098 'class': 'p5', 4099 'module': 'Events' 4100 }, 4101 'mouseY': { 4102 'name': 'mouseY', 4103 'class': 'p5', 4104 'module': 'Events' 4105 }, 4106 'pmouseX': { 4107 'name': 'pmouseX', 4108 'class': 'p5', 4109 'module': 'Events' 4110 }, 4111 'pmouseY': { 4112 'name': 'pmouseY', 4113 'class': 'p5', 4114 'module': 'Events' 4115 }, 4116 'winMouseX': { 4117 'name': 'winMouseX', 4118 'class': 'p5', 4119 'module': 'Events' 4120 }, 4121 'winMouseY': { 4122 'name': 'winMouseY', 4123 'class': 'p5', 4124 'module': 'Events' 4125 }, 4126 'pwinMouseX': { 4127 'name': 'pwinMouseX', 4128 'class': 'p5', 4129 'module': 'Events' 4130 }, 4131 'pwinMouseY': { 4132 'name': 'pwinMouseY', 4133 'class': 'p5', 4134 'module': 'Events' 4135 }, 4136 'mouseButton': { 4137 'name': 'mouseButton', 4138 'class': 'p5', 4139 'module': 'Events' 4140 }, 4141 'mouseIsPressed': { 4142 'name': 'mouseIsPressed', 4143 'class': 'p5', 4144 'module': 'Events' 4145 }, 4146 'mouseMoved': { 4147 'name': 'mouseMoved', 4148 'params': [ 4149 { 4150 'name': 'event', 4151 'description': '<p>optional MouseEvent callback argument.</p>\n', 4152 'type': 'Object', 4153 'optional': true 4154 } 4155 ], 4156 'class': 'p5', 4157 'module': 'Events' 4158 }, 4159 'mouseDragged': { 4160 'name': 'mouseDragged', 4161 'params': [ 4162 { 4163 'name': 'event', 4164 'description': '<p>optional MouseEvent callback argument.</p>\n', 4165 'type': 'Object', 4166 'optional': true 4167 } 4168 ], 4169 'class': 'p5', 4170 'module': 'Events' 4171 }, 4172 'mousePressed': { 4173 'name': 'mousePressed', 4174 'params': [ 4175 { 4176 'name': 'event', 4177 'description': '<p>optional MouseEvent callback argument.</p>\n', 4178 'type': 'Object', 4179 'optional': true 4180 } 4181 ], 4182 'class': 'p5', 4183 'module': 'Events' 4184 }, 4185 'mouseReleased': { 4186 'name': 'mouseReleased', 4187 'params': [ 4188 { 4189 'name': 'event', 4190 'description': '<p>optional MouseEvent callback argument.</p>\n', 4191 'type': 'Object', 4192 'optional': true 4193 } 4194 ], 4195 'class': 'p5', 4196 'module': 'Events' 4197 }, 4198 'mouseClicked': { 4199 'name': 'mouseClicked', 4200 'params': [ 4201 { 4202 'name': 'event', 4203 'description': '<p>optional MouseEvent callback argument.</p>\n', 4204 'type': 'Object', 4205 'optional': true 4206 } 4207 ], 4208 'class': 'p5', 4209 'module': 'Events' 4210 }, 4211 'doubleClicked': { 4212 'name': 'doubleClicked', 4213 'params': [ 4214 { 4215 'name': 'event', 4216 'description': '<p>optional MouseEvent callback argument.</p>\n', 4217 'type': 'Object', 4218 'optional': true 4219 } 4220 ], 4221 'class': 'p5', 4222 'module': 'Events' 4223 }, 4224 'mouseWheel': { 4225 'name': 'mouseWheel', 4226 'params': [ 4227 { 4228 'name': 'event', 4229 'description': '<p>optional WheelEvent callback argument.</p>\n', 4230 'type': 'Object', 4231 'optional': true 4232 } 4233 ], 4234 'class': 'p5', 4235 'module': 'Events' 4236 }, 4237 'requestPointerLock': { 4238 'name': 'requestPointerLock', 4239 'class': 'p5', 4240 'module': 'Events' 4241 }, 4242 'exitPointerLock': { 4243 'name': 'exitPointerLock', 4244 'class': 'p5', 4245 'module': 'Events' 4246 }, 4247
4247'touches': { 4248 'name': 'touches', 4249 'class': 'p5', 4250 'module': 'Events' 4251 }, 4252 'touchStarted': { 4253 'name': 'touchStarted', 4254 'params': [ 4255 { 4256 'name': 'event', 4257 'description': '<p>optional TouchEvent callback argument.</p>\n', 4258 'type': 'Object', 4259 'optional': true 4260 } 4261 ], 4262 'class': 'p5', 4263 'module': 'Events' 4264 }, 4265 'touchMoved': { 4266 'name': 'touchMoved', 4267 'params': [ 4268 { 4269 'name': 'event', 4270 'description': '<p>optional TouchEvent callback argument.</p>\n', 4271 'type': 'Object', 4272 'optional': true 4273 } 4274 ], 4275 'class': 'p5', 4276 'module': 'Events' 4277 }, 4278 'touchEnded': { 4279 'name': 'touchEnded', 4280 'params': [ 4281 { 4282 'name': 'event', 4283 'description': '<p>optional TouchEvent callback argument.</p>\n', 4284 'type': 'Object', 4285 'optional': true 4286 } 4287 ], 4288 'class': 'p5', 4289 'module': 'Events' 4290 }, 4291 'createImage': { 4292 'name': 'createImage', 4293 'params': [ 4294 { 4295 'name': 'width', 4296 'description': '<p>width in pixels</p>\n', 4297 'type': 'Integer' 4298 }, 4299 { 4300 'name': 'height', 4301 'description': '<p>height in pixels</p>\n', 4302 'type': 'Integer' 4303 } 4304 ], 4305 'class': 'p5', 4306 'module': 'Image' 4307 }, 4308 'saveCanvas': { 4309 'name': 'saveCanvas', 4310 'class': 'p5', 4311 'module': 'Image', 4312 'overloads': [ 4313 { 4314 'params': [ 4315 { 4316 'name': 'selectedCanvas', 4317 'description': '<p>a variable\n representing a specific html5 canvas (optional)</p>\n', 4318 'type': 'p5.Element|HTMLCanvasElement' 4319 }, 4320 { 4321 'name': 'filename', 4322 'description': '', 4323 'type': 'String', 4324 'optional': true 4325 }, 4326 { 4327 'name': 'extension', 4328 'description': '<p>\'jpg\' or \'png\'</p>\n', 4329 'type': 'String', 4330 'optional': true 4331 } 4332 ] 4333 }, 4334 { 4335 'params': [ 4336 { 4337 'name': 'filename', 4338 'description': '', 4339 'type': 'String', 4340 'optional': true 4341 }, 4342 { 4343 'name': 'extension', 4344 'description': '', 4345 'type': 'String', 4346 'optional': true 4347 } 4348 ] 4349 } 4350 ] 4351 }, 4352 'saveFrames': { 4353 'name': 'saveFrames', 4354 'params': [ 4355 { 4356 'name': 'filename', 4357 'description': '', 4358 'type': 'String' 4359 }, 4360 { 4361 'name': 'extension', 4362 'description': '<p>\'jpg\' or \'png\'</p>\n', 4363 'type': 'String' 4364 }, 4365 { 4366 'name': 'duration', 4367 'description': '<p>Duration in seconds to save the frames for. This parameter will be constrained to be less or equal to 15.</p>\n', 4368 'type': 'Number' 4369 }, 4370 { 4371 'name': 'framerate', 4372 'description': '<p>Framerate to save the frames in. This parameter will be constrained to be less or equal to 22.</p>\n', 4373 'type': 'Number' 4374 }, 4375 { 4376 'name': 'callback', 4377 'description': '<p>A callback function that will be executed\n to handle the image data. This function\n should accept an array as argument. The\n array will contain the specified number of\n frames of objects. Each object has three\n properties: imageData - an\n image/octet-stream, filename and extension.</p>\n', 4378 'type': 'Function(Array)', 4379 'optional': true 4380 } 4381 ], 4382 'class': 'p5', 4383 'module': 'Image' 4384 }, 4385 'loadImage': { 4386 'name': 'loadImage', 4387 'params': [ 4388 { 4389 'name': 'path', 4390 'description': '<p>Path of the image to be loaded</p>\n', 4391 'type': 'String' 4392 }, 4393 { 4394 'name': 'successCallback', 4395 'description': '<p>Function to be called once\n the image is loaded. Will be passed the\n <a href="#/p5.Image">p5.Image</a>.</p>\n', 4396 'type': 'function(p5.Image)', 4397 'optional': true 4398 }, 4399 { 4400 'name': 'failureCallback', 4401 'description': '<p>called with event error if\n the image fails to load.</p>\n', 4402 'type': 'Function(Event)', 4403 'optional': true 4404 } 4405 ], 4406 'class': 'p5', 4407 'module': 'Image' 4408 },
4409 'saveGif': { 4410 'name': 'saveGif', 4411 'params': [ 4412 { 4413 'name': 'filename', 4414 'description': '<p>File name of your gif</p>\n', 4415 'type': 'String' 4416 }, 4417 { 4418 'name': 'duration', 4419 'description': '<p>Duration in seconds that you wish to capture from your sketch</p>\n', 4420 'type': 'Number' 4421 }, 4422 { 4423 'name': 'options', 4424 'description': '<p>An optional object that can contain two more arguments: delay, specifying\nhow much time we should wait before recording, and units, a string that can be either \'seconds\' or\n\'frames\'. By default it\'s \'seconds\'.</p>\n', 4425 'type': 'Object' 4426 } 4427 ], 4428 'class': 'p5', 4429 'module': 'Image' 4430 }, 4431 'image': { 4432 'name': 'image', 4433 'class': 'p5', 4434 'module': 'Image', 4435 'overloads': [ 4436 { 4437 'params': [ 4438 { 4439 'name': 'img', 4440 'description': '<p>the image to display</p>\n', 4441 'type': 'p5.Image|p5.Element|p5.Texture' 4442 }, 4443 { 4444 'name': 'x', 4445 'description': '<p>the x-coordinate of the top-left corner of the image</p>\n', 4446 'type': 'Number' 4447 }, 4448 { 4449 'name': 'y', 4450 'description': '<p>the y-coordinate of the top-left corner of the image</p>\n', 4451 'type': 'Number' 4452 }, 4453 { 4454 'name': 'width', 4455 'description': '<p>the width to draw the image</p>\n', 4456 'type': 'Number', 4457 'optional': true 4458 }, 4459 { 4460 'name': 'height', 4461 'description': '<p>the height to draw the image</p>\n', 4462 'type': 'Number', 4463 'optional': true 4464 } 4465 ] 4466 }, 4467 { 4468 'params': [ 4469 { 4470 'name': 'img', 4471 'description': '', 4472 'type': 'p5.Image|p5.Element|p5.Texture' 4473 }, 4474 { 4475 'name': 'dx', 4476 'description': '<p>the x-coordinate of the destination\n rectangle in which to draw the source image</p>\n', 4477 'type': 'Number' 4478 }, 4479 { 4480 'name': 'dy', 4481 'description': '<p>the y-coordinate of the destination\n rectangle in which to draw the source image</p>\n', 4482 'type': 'Number' 4483 }, 4484 { 4485 'name': 'dWidth', 4486 'description': '<p>the width of the destination rectangle</p>\n', 4487 'type': 'Number' 4488 }, 4489 { 4490 'name': 'dHeight', 4491 'description': '<p>the height of the destination rectangle</p>\n', 4492 'type': 'Number' 4493 }, 4494 { 4495 'name': 'sx', 4496 'description': '<p>the x-coordinate of the subsection of the source\nimage to draw into the destination rectangle</p>\n', 4497 'type': 'Number' 4498 }, 4499 { 4500 'name': 'sy', 4501 'description': '<p>the y-coordinate of the subsection of the source\nimage to draw into the destination rectangle</p>\n', 4502 'type': 'Number' 4503 }, 4504 { 4505 'name': 'sWidth', 4506 'description': '<p>the width of the subsection of the\n source image to draw into the destination\n rectangle</p>\n', 4507 'type': 'Number', 4508 'optional': true 4509 }, 4510 { 4511 'name': 'sHeight', 4512 'description': '<p>the height of the subsection of the\n source image to draw into the destination rectangle</p>\n', 4513 'type': 'Number', 4514 'optional': true 4515 }, 4516 { 4517 'name': 'fit', 4518 'description': '<p>either CONTAIN or COVER</p>\n', 4519 'type': 'Constant', 4520 'optional': true 4521 }, 4522 { 4523 'name': 'xAlign', 4524 'description': '<p>either LEFT, RIGHT or CENTER default is CENTER</p>\n', 4525 'type': 'Constant', 4526 'optional': true 4527 }, 4528 { 4529 'name': 'yAlign', 4530 'description': '<p>either TOP, BOTTOM or CENTER default is CENTER</p>\n', 4531 'type': 'Constant', 4532 'optional': true 4533 } 4534 ] 4535 } 4536 ] 4537 }, 4538 'tint': { 4539 'name': 'tint', 4540 'class': 'p5', 4541 'module': 'Image', 4542 'overloads': [ 4543 { 4544 'params': [ 4545 { 4546 'name': 'v1', 4547 'description': '<p>red or hue value relative to\n the current color range</p>\n', 4548 'type': 'Number' 4549 }, 4550 { 4551 'name': 'v2', 4552 'description': '<p>
4552green or saturation value\n relative to the current color range</p>\n', 4553 'type': 'Number' 4554 }, 4555 { 4556 'name': 'v3', 4557 'description': '<p>blue or brightness value\n relative to the current color range</p>\n', 4558 'type': 'Number' 4559 }, 4560 { 4561 'name': 'alpha', 4562 'description': '', 4563 'type': 'Number', 4564 'optional': true 4565 } 4566 ] 4567 }, 4568 { 4569 'params': [ 4570 { 4571 'name': 'value', 4572 'description': '<p>a color string</p>\n', 4573 'type': 'String' 4574 } 4575 ] 4576 }, 4577 { 4578 'params': [ 4579 { 4580 'name': 'gray', 4581 'description': '<p>a gray value</p>\n', 4582 'type': 'Number' 4583 }, 4584 { 4585 'name': 'alpha', 4586 'description': '', 4587 'type': 'Number', 4588 'optional': true 4589 } 4590 ] 4591 }, 4592 { 4593 'params': [ 4594 { 4595 'name': 'values', 4596 'description': '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n', 4597 'type': 'Number[]' 4598 } 4599 ] 4600 }, 4601 { 4602 'params': [ 4603 { 4604 'name': 'color', 4605 'description': '<p>the tint color</p>\n', 4606 'type': 'p5.Color' 4607 } 4608 ] 4609 } 4610 ] 4611 }, 4612 'noTint': { 4613 'name': 'noTint', 4614 'class': 'p5', 4615 'module': 'Image' 4616 }, 4617 'imageMode': { 4618 'name': 'imageMode', 4619 'params': [ 4620 { 4621 'name': 'mode', 4622 'description': '<p>either CORNER, CORNERS, or CENTER</p>\n', 4623 'type': 'Constant' 4624 } 4625 ], 4626 'class': 'p5', 4627 'module': 'Image' 4628 }, 4629 'pixels': { 4630 'name': 'pixels', 4631 'class': 'p5', 4632 'module': 'Image' 4633 }, 4634 'blend': { 4635 'name': 'blend', 4636 'class': 'p5', 4637 'module': 'Image', 4638 'overloads': [ 4639 { 4640 'params': [ 4641 { 4642 'name': 'srcImage', 4643 'description': '<p>source image</p>\n', 4644 'type': 'p5.Image' 4645 }, 4646 { 4647 'name': 'sx', 4648 'description': '<p>X coordinate of the source\'s upper left corner</p>\n', 4649 'type': 'Integer' 4650 }, 4651 { 4652 'name': 'sy', 4653 'description': '<p>Y coordinate of the source\'s upper left corner</p>\n', 4654 'type': 'Integer' 4655 }, 4656 { 4657 'name': 'sw', 4658 'description': '<p>source image width</p>\n', 4659 'type': 'Integer' 4660 }, 4661 { 4662 'name': 'sh', 4663 'description': '<p>source image height</p>\n', 4664 'type': 'Integer' 4665 }, 4666 { 4667 'name': 'dx', 4668 'description': '<p>X coordinate of the destination\'s upper left corner</p>\n', 4669 'type': 'Integer' 4670 }, 4671 { 4672 'name': 'dy', 4673 'description': '<p>Y coordinate of the destination\'s upper left corner</p>\n', 4674 'type': 'Integer' 4675 }, 4676 { 4677 'name': 'dw', 4678 'description': '<p>destination image width</p>\n', 4679 'type': 'Integer' 4680 }, 4681 { 4682 'name': 'dh', 4683 'description': '<p>destination image height</p>\n', 4684 'type': 'Integer' 4685 }, 4686 { 4687 'name': 'blendMode', 4688 'description': '<p>the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.</p>\n', 4689 'type': 'Constant' 4690 } 4691 ] 4692 }, 4693 { 4694 'params': [ 4695 { 4696 'name': 'sx', 4697 'description': '', 4698 'type': 'Integer' 4699 }, 4700 { 4701 'name': 'sy', 4702 'description': '', 4703 'type': 'Integer' 4704 }, 4705 { 4706 'name': 'sw', 4707 'description': '', 4708 'type': 'Integer' 4709 }, 4710 { 4711 'name': 'sh', 4712 'description': '', 4713 'type': 'Integer' 4714 }, 4715 { 4716 'name': 'dx', 4717 'description': '', 4718 'type': 'Integer' 4719 }, 4720 { 4721 'name': 'dy', 4722 'description': '', 4723 'type': 'Integer' 4724 }, 4725 { 4726 'name': 'dw', 4727 'description': '', 4728 'type': 'Integer' 4729 }, 4730 { 4731 'name': 'dh', 4732 'description': '', 4733 'type': 'Integer' 4734 }, 4735 { 4736 'name': 'blendMode', 4737 'description': '', 4738 'type': 'Constant' 4739 } 4740 ] 4741 } 4742 ] 4743 }, 4744 'copy': { 4745 'name': 'copy', 4746 'class': 'p5', 4747 'module': 'Image', 4748 'overloads': [ 4749 { 4750 'params': [ 4751 { 4752 'name': 'srcImage', 4753 'description': '<p>source image</p>\n', 4754 'type': 'p5.Image|p5.Element' 4755 }, 4756 { 4757 'name': 'sx', 4758 'description': '<p>X coordinate of the source\'s upper left corner</p>\n', 4759 'type': 'Integer' 4760 }, 4761 { 4762 'name': 'sy', 4763 'description': '<p>Y coordinate of the source\'s upper left corner</p>\n', 4764 'type': 'Integer' 4765 }, 4766 { 4767 'name': 'sw', 4768 'description': '<p>source image width</p>\n', 4769 'type': 'Integer' 4770 }, 4771 { 4772 'name': 'sh', 4773 'description': '<p>source image height</p>\n', 4774 'type': 'Integer' 4775 }, 4776 { 4777 'name': 'dx', 4778 'description': '<p>X coordinate of the destination\'s upper left corner</p>\n', 4779 'type': 'Integer' 4780 }, 4781 { 4782 'name': 'dy', 4783 'description': '<p>Y coordinate of the destination\'s upper left corner</p>\n', 4784 'type': 'Integer' 4785 }, 4786 { 4787 'name': 'dw', 4788 'description': '<p>destination image width</p>\n', 4789 'type': 'Integer' 4790 }, 4791 { 4792 'name': 'dh', 4793 'description': '<p>destination image height</p>\n', 4794 'type': 'Integer' 4795 } 4796 ] 4797 }, 4798 { 4799 'params': [ 4800 { 4801 'name': 'sx', 4802 'description': '', 4803 'type': 'Integer' 4804 }, 4805 { 4806 'name': 'sy', 4807 'description': '', 4808 'type': 'Integer' 4809 }, 4810 { 4811 'name': 'sw', 4812 'description': '', 4813 'type': 'Integer' 4814 }, 4815 { 4816 'name': 'sh', 4817 'description': '', 4818 'type': 'Integer' 4819 }, 4820 { 4821 'name': 'dx', 4822 'description': '', 4823 'type': 'Integer' 4824 }, 4825 { 4826 'name': 'dy', 4827 'description': '', 4828 'type': 'Integer' 4829 }, 4830 { 4831 'name': 'dw', 4832 'description': '', 4833 'type': 'Integer' 4834 }, 4835 { 4836 'name': 'dh', 4837 'description': '', 4838 'type': 'Integer' 4839 } 4840 ] 4841 } 4842 ] 4843 }, 4844 'filter': { 4845 'name': 'filter', 4846 'params': [ 4847 { 4848 'name': 'filterType', 4849 'description': '<p>either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, BLUR, ERODE, DILATE or BLUR.\
4849n See Filters.js for docs on\n each available filter</p>\n', 4850 'type': 'Constant' 4851 }, 4852 { 4853 'name': 'filterParam', 4854 'description': '<p>an optional parameter unique\n to each filter, see above</p>\n', 4855 'type': 'Number', 4856 'optional': true 4857 } 4858 ], 4859 'class': 'p5', 4860 'module': 'Image' 4861 }, 4862 'get': { 4863 'name': 'get', 4864 'class': 'p5', 4865 'module': 'Image', 4866 'overloads': [ 4867 { 4868 'params': [ 4869 { 4870 'name': 'x', 4871 'description': '<p>x-coordinate of the pixel</p>\n', 4872 'type': 'Number' 4873 }, 4874 { 4875 'name': 'y', 4876 'description': '<p>y-coordinate of the pixel</p>\n', 4877 'type': 'Number' 4878 }, 4879 { 4880 'name': 'w', 4881 'description': '<p>width</p>\n', 4882 'type': 'Number' 4883 }, 4884 { 4885 'name': 'h', 4886 'description': '<p>height</p>\n', 4887 'type': 'Number' 4888 } 4889 ] 4890 }, 4891 { 4892 'params': [ 4893 ] 4894 }, 4895 { 4896 'params': [ 4897 { 4898 'name': 'x', 4899 'description': '', 4900 'type': 'Number' 4901 }, 4902 { 4903 'name': 'y', 4904 'description': '', 4905 'type': 'Number' 4906 } 4907 ] 4908 } 4909 ] 4910 }, 4911 'loadPixels': { 4912 'name': 'loadPixels', 4913 'class': 'p5', 4914 'module': 'Image' 4915 }, 4916 'set': { 4917 'name': 'set', 4918 'params': [ 4919 { 4920 'name': 'x', 4921 'description': '<p>x-coordinate of the pixel</p>\n', 4922 'type': 'Number' 4923 }, 4924 { 4925 'name': 'y', 4926 'description': '<p>y-coordinate of the pixel</p>\n', 4927 'type': 'Number' 4928 }, 4929 { 4930 'name': 'c', 4931 'description': '<p>insert a grayscale value | a pixel array |\n a <a href="#/p5.Color">p5.Color</a> object | a <a href="#/p5.Image">p5.Image</a> to copy</p>\n', 4932 'type': 'Number|Number[]|Object' 4933 } 4934 ], 4935 'class': 'p5', 4936 'module': 'Image' 4937 }, 4938 'updatePixels': { 4939 'name': 'updatePixels', 4940 'params': [ 4941 { 4942 'name': 'x', 4943 'description': '<p>x-coordinate of the upper-left corner of region\n to update</p>\n', 4944 'type': 'Number', 4945 'optional': true 4946 }, 4947 { 4948 'name': 'y', 4949 'description': '<p>y-coordinate of the upper-left corner of region\n to update</p>\n', 4950 'type': 'Number', 4951 'optional': true 4952 }, 4953 { 4954 'name': 'w', 4955 'description': '<p>width of region to update</p>\n', 4956 'type': 'Number', 4957 'optional': true 4958 }, 4959 { 4960 'name': 'h', 4961 'description': '<p>height of region to update</p>\n', 4962 'type': 'Number', 4963 'optional': true 4964 } 4965 ], 4966 'class': 'p5', 4967 'module': 'Image' 4968 }, 4969 'loadJSON': { 4970 'name': 'loadJSON', 4971 'class': 'p5', 4972 'module': 'IO', 4973 'overloads': [ 4974 { 4975 'params': [ 4976 { 4977 'name': 'path', 4978 'description': '<p>name of the file or url to load</p>\n', 4979 'type': 'String' 4980 }, 4981 { 4982 'name': 'jsonpOptions', 4983 'description': '<p>options object for jsonp related settings</p>\n', 4984 'type': 'Object', 4985 'optional': true 4986 }, 4987 { 4988 'name': 'datatype', 4989 'description': '<p>"json" or "jsonp"</p>\n', 4990 'type': 'String', 4991 'optional': true 4992 }, 4993 { 4994 'name': 'callback', 4995 'description': '<p>function to be executed after\n <a href="#/p5/loadJSON">loadJSON()</a> completes, data is passed\n in as first argument</p>\n', 4996 'type': 'Function', 4997 'optional': true 4998 }, 4999 { 5000 'name': 'errorCallback', 5001 'description': '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n', 5002 'type': 'Function', 5003 'optional': true 5004 } 5005 ] 5006 }, 5007 { 5008 'params': [ 5009 { 5010 'name': 'path', 5011 'description': '', 5012 'type': 'String' 5013 }, 5014 { 5015 'name': 'datatype', 5016 'description': '', 5017 'type': 'String' 5018 }, 5019 { 5020 'name': 'callback', 5021 'description': '', 5022 'type': 'Function', 5023 'optional': true 5024 }, 5025 { 5026 'name': 'errorCallback', 5027 'description': '', 5028 'type': 'Function', 5029 'optional': true 5030 } 5031 ] 5032 }, 5033 { 5034 'params': [ 5035 { 5036 'name': 'path', 5037 'description': '', 5038 'type': 'String' 5039 }, 5040 { 5041 'name': 'callback', 5042 'description': '', 5043 'type': 'Function' 5044 }, 5045 { 5046 'name': 'errorCallback', 5047 'description': '', 5048 'type': 'Function', 5049 'optional': true 5050 } 5051 ] 5052 } 5053 ] 5054 }, 5055 'loadStrings': { 5056 'name': 'loadStrings', 5057 'params': [ 5058 { 5059 'name': 'filename', 5060 'description': '<p>name of the file or url to load</p>\n', 5061 'type': 'String' 5062 }, 5063 { 5064 'name': 'callback', 5065 'description': '<p>function to be executed after <a href="#/p5/loadStrings">loadStrings()</a>\n completes, Array is passed in as first\n argument</p>\n', 5066 'type': 'Function', 5067 'optional': true 5068 }, 5069 { 5070 'name': 'errorCallback', 5071 'description': '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n', 5072 'type': 'Function', 5073 'optional': true 5074 } 5075 ], 5076 'class': 'p5', 5077 'module': 'IO' 5078 }, 5079 'loadTable': { 5080 'name': 'loadTable', 5081 'params': [ 5082 { 5083 'name': 'filename', 5084 'description': '<p>name of the file or URL to load</p>\n', 5085 'type': 'String' 5086 }, 5087 { 5088 'name': 'extension', 5089 'description': '<p>parse the table by comma-separated values "csv", semicolon-separated\n values "ssv", or tab-separated values "tsv"</p>\n', 5090 'type': 'String', 5091 'optional': true 5092 }, 5093 { 5094 'name': 'header', 5095 'description': '<p>"header" to indicate table has header row</p>\n', 5096 'type': 'String', 5097 'optional': true 5098 }, 5099 { 5100 'name': 'callback', 5101 'description': '<p>function to be executed after\n <a href="#/p5/loadTable">loadTable()</a> completes. On success, the\n <a href="#/p5.Table">Table</a> object is passed in as the\n first argument.</p>\n', 5102 'type': 'Function', 5103 'optional': true 5104 }, 5105 { 5106 'name': 'errorCallback', 5107 'description': '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n', 5108 'type': 'Function', 5109 'optional': true 5110 } 5111 ], 5112 'class': 'p5', 5113 'module': 'IO' 5114 }, 5115 'loadXML': { 5116 'name': 'loadXML', 5117 'params': [ 5118 { 5119 'name': 'filename', 5120 'description': '<p>name of the file or URL to load</p>\n', 5121 'type': 'String' 5122 }, 5123 { 5124 'name': 'callback', 5125 'description': '<p>function to be executed after <a href="#/p5/loadXML">loadXML()</a>\n completes, XML object is passed in as\n first argument</p>\n', 5126 'type': 'Function', 5127 'optional': true 5128 }, 5129 { 5130 'name': 'errorCallback', 5131 'description': '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n', 5132 'type': 'Function', 5133 'optional': true 5134 } 5135 ], 5136 'class': 'p5', 5137 'module': 'IO' 5138 }, 5139 'loadBytes': { 5140 'name': 'loadBytes', 5141 'params': [ 5142 { 5143 'name': 'file', 5144 'description': '<p>name of the file or URL to load</p>\n', 5145 'type': 'String' 5146 }, 5147 { 5148 'name': 'callback', 5149 'description': '<p>function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>\n completes</p>\n', 5150 'type': 'Function', 5151 'optional': true 5152 }, 5153 { 5154 'name': 'errorCallback', 5155 'description': '<p>function to be executed if there\n is an error</p>\n', 5156 'type': 'Function', 5157 'optional': true 5158 } 5159 ], 5160 'class': 'p5', 5161 'module': 'IO' 5162 }, 5163 'httpGet': { 5164 'name': 'httpGet', 5165 'class': 'p5', 5166 'module': 'IO', 5167 'overloads': [ 5168 { 5169 'params': [ 5170 { 5171 'name': 'path', 5172 'description': '<p>name of the file or url to load</p>\n', 5173 'type': 'String' 5174 }, 5175 { 5176 'name': 'datatype', 5177 'description': '<p>"json", "jsonp", "binary", "arrayBuffer",\n "xml", or "text"</p>\n', 5178 'type': 'String', 5179 'optional': true 5180 }, 5181 { 5182 'name': 'data', 5183 'description': '<p>param data passed sent with request</p>\n', 5184 'type': 'Object|Boolean', 5185 'optional': true 5186 }, 5187 { 5188 'name': 'callback', 5189 'description': '<p>function to be executed after\n <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in\n as first argument</p>\n', 5190 'type': 'Function', 5191 'optional': true 5192 }, 5193 { 5194 'name': 'errorCallback', 5195 'description': '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n', 5196 'type': 'Function', 5197 'optional': true 5198 } 5199 ] 5200 }, 5201 { 5202 'params': [ 5203 { 5204 'name': 'path', 5205 'description': '', 5206 'type': 'String' 5207 }, 5208 { 5209 'name': 'data', 5210 'description': '', 5211 'type': 'Object|Boolean' 5212 }, 5213 { 5214 'name': 'callback', 5215 'description': '', 5216 'type': 'Function', 5217 'optional': true 5218 }, 5219 { 5220 'name': 'errorCallback', 5221 'description': '', 5222 'type': 'Function', 5223 'optional': true 5224 } 5225 ] 5226 }, 5227 { 5228 'params': [ 5229 { 5230 'name': 'path', 5231 'description': '', 5232 'type': 'String' 5233 }, 5234 { 5235 'name': 'callback', 5236 'description': '', 5237 'type': 'Function' 5238 }, 5239 { 5240 'name': 'errorCallback', 5241 'description': '', 5242 'type': 'Function', 5243 'optional': true 5244 } 5245 ] 5246 } 5247 ] 5248 }, 5249 'httpPost': { 5250 'name': 'httpPost', 5251 'class': 'p5', 5252 'module': 'IO', 5253 'overloads': [ 5254 { 5255 'params': [ 5256 { 5257 'name': 'path', 5258 'description': '<p>name of the file or url to load</p>\n', 5259 'type': 'String' 5260 }, 5261 { 5262 'name': 'datatype', 5263 'description': '<p>"json", "jsonp", "xml", or "text".\n If omitted, <a href="#/p5/httpPost">httpPost()</a> will guess.</p>\n', 5264 'type': 'String', 5265 'optional': true 5266 }, 5267 { 5268 'name': 'data', 5269
5269 'description': '<p>param data passed sent with request</p>\n', 5270 'type': 'Object|Boolean', 5271 'optional': true 5272 }, 5273 { 5274 'name': 'callback', 5275 'description': '<p>function to be executed after\n <a href="#/p5/httpPost">httpPost()</a> completes, data is passed in\n as first argument</p>\n', 5276 'type': 'Function', 5277 'optional': true 5278 }, 5279 { 5280 'name': 'errorCallback', 5281 'description': '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n', 5282 'type': 'Function', 5283 'optional': true 5284 } 5285 ] 5286 }, 5287 { 5288 'params': [ 5289 { 5290 'name': 'path', 5291 'description': '', 5292 'type': 'String' 5293 }, 5294 { 5295 'name': 'data', 5296 'description': '', 5297 'type': 'Object|Boolean' 5298 }, 5299 { 5300 'name': 'callback', 5301 'description': '', 5302 'type': 'Function', 5303 'optional': true 5304 }, 5305 { 5306 'name': 'errorCallback', 5307 'description': '', 5308 'type': 'Function', 5309 'optional': true 5310 } 5311 ] 5312 }, 5313 { 5314 'params': [ 5315 { 5316 'name': 'path', 5317 'description': '', 5318 'type': 'String' 5319 }, 5320 { 5321 'name': 'callback', 5322 'description': '', 5323 'type': 'Function' 5324 }, 5325 { 5326 'name': 'errorCallback', 5327 'description': '', 5328 'type': 'Function', 5329 'optional': true 5330 } 5331 ] 5332 } 5333 ] 5334 }, 5335 'httpDo': { 5336 'name': 'httpDo', 5337 'class': 'p5', 5338 'module': 'IO', 5339 'overloads': [ 5340 { 5341 'params': [ 5342 { 5343 'name': 'path', 5344 'description': '<p>name of the file or url to load</p>\n', 5345 'type': 'String' 5346 }, 5347 { 5348 'name': 'method', 5349 'description': '<p>either "GET", "POST", or "PUT",\n defaults to "GET"</p>\n', 5350 'type': 'String', 5351 'optional': true 5352 }, 5353 { 5354 'name': 'datatype', 5355 'description': '<p>"json", "jsonp", "xml", or "text"</p>\n', 5356 'type': 'String', 5357 'optional': true 5358 }, 5359 { 5360 'name': 'data', 5361 'description': '<p>param data passed sent with request</p>\n', 5362 'type': 'Object', 5363 'optional': true 5364 }, 5365 { 5366 'name': 'callback', 5367 'description': '<p>function to be executed after\n <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in\n as first argument</p>\n', 5368 'type': 'Function', 5369 'optional': true 5370 }, 5371 { 5372 'name': 'errorCallback', 5373 'description': '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n', 5374 'type': 'Function', 5375 'optional': true 5376 } 5377 ] 5378 }, 5379 { 5380 'params': [ 5381 { 5382 'name': 'path', 5383 'description': '', 5384 'type': 'String' 5385 }, 5386 { 5387 'name': 'options', 5388 'description': '<p>Request object options as documented in the\n "fetch" API\n<a href="https://developer.mozilla.org/en/docs/Web/API/Fetch_API">reference</a></p>\n', 5389 'type': 'Object' 5390 }, 5391 { 5392 'name': 'callback', 5393 'description': '', 5394 'type': 'Function', 5395 'optional': true 5396 }, 5397 { 5398 'name': 'errorCallback', 5399 'description': '', 5400 'type': 'Function', 5401 'optional': true 5402 } 5403 ] 5404 } 5405 ] 5406 }, 5407 'createWriter': { 5408 'name': 'createWriter', 5409 'params': [ 5410 { 5411 'name': 'name', 5412 'description': '<p>name of the file to be created</p>\n', 5413 'type': 'String' 5414 }, 5415 { 5416 'name': 'extension', 5417 'description': '', 5418 'type': 'String', 5419 'optional': true 5420 } 5421 ], 5422 'class': 'p5', 5423 'module': 'IO' 5424 },
5425 'save': { 5426 'name': 'save', 5427 'params': [ 5428 { 5429 'name': 'objectOrFilename', 5430 'description': '<p>If filename is provided, will\n save canvas as an image with\n either png or jpg extension\n depending on the filename.\n If object is provided, will\n save depending on the object\n and filename (see examples\n above).</p>\n', 5431 'type': 'Object|String', 5432 'optional': true 5433 }, 5434 { 5435 'name': 'filename', 5436 'description': '<p>If an object is provided as the first\n parameter, then the second parameter\n indicates the filename,\n and should include an appropriate\n file extension (see examples above).</p>\n', 5437 'type': 'String', 5438 'optional': true 5439 }, 5440 { 5441 'name': 'options', 5442 'description': '<p>Additional options depend on\n filetype. For example, when saving JSON,\n <code>true</code> indicates that the\n output will be optimized for filesize,\n rather than readability.</p>\n', 5443 'type': 'Boolean|String', 5444 'optional': true 5445 } 5446 ], 5447 'class': 'p5', 5448 'module': 'IO' 5449 }, 5450 'saveJSON': { 5451 'name': 'saveJSON', 5452 'params': [ 5453 { 5454 'name': 'json', 5455 'description': '', 5456 'type': 'Array|Object' 5457 }, 5458 { 5459 'name': 'filename', 5460 'description': '', 5461 'type': 'String' 5462 }, 5463 { 5464 'name': 'optimize', 5465 'description': '<p>If true, removes line breaks\n and spaces from the output\n file to optimize filesize\n (but not readability).</p>\n', 5466 'type': 'Boolean', 5467 'optional': true 5468 } 5469 ], 5470 'class': 'p5', 5471 'module': 'IO' 5472 }, 5473 'saveStrings': { 5474 'name': 'saveStrings', 5475 'params': [ 5476 { 5477 'name': 'list', 5478 'description': '<p>string array to be written</p>\n', 5479 'type': 'String[]' 5480 }, 5481 { 5482 'name': 'filename', 5483 'description': '<p>filename for output</p>\n', 5484 'type': 'String' 5485 }, 5486 { 5487 'name': 'extension', 5488 'description': '<p>the filename\'s extension</p>\n', 5489 'type': 'String', 5490 'optional': true 5491 }, 5492 { 5493 'name': 'isCRLF', 5494 'description': '<p>if true, change line-break to CRLF</p>\n', 5495 'type': 'Boolean', 5496 'optional': true 5497 } 5498 ], 5499 'class': 'p5', 5500 'module': 'IO' 5501 }, 5502 'saveTable': { 5503 'name': 'saveTable', 5504 'params': [ 5505 { 5506 'name': 'Table', 5507 'description': '<p>the <a href="#/p5.Table">Table</a> object to save to a file</p>\n', 5508 'type': 'p5.Table' 5509 }, 5510 { 5511 'name': 'filename', 5512 'description': '<p>the filename to which the Table should be saved</p>\n', 5513 'type': 'String' 5514 }, 5515 { 5516 'name': 'options', 5517 'description': '<p>can be one of "tsv", "csv", or "html"</p>\n', 5518 'type': 'String', 5519 'optional': true 5520 } 5521 ], 5522 'class': 'p5', 5523 'module': 'IO' 5524 }, 5525 'abs': { 5526 'name': 'abs', 5527 'params': [ 5528 { 5529 'name': 'n', 5530 'description': '<p>number to compute</p>\n', 5531 'type': 'Number' 5532 } 5533 ], 5534 'class': 'p5', 5535 'module': 'Math' 5536 }, 5537 'ceil': { 5538 'name': 'ceil', 5539 'params': [ 5540 { 5541 'name': 'n', 5542 'description': '<p>number to round up</p>\n', 5543 'type': 'Number' 5544 } 5545 ], 5546 'class': 'p5', 5547 'module': 'Math' 5548 }, 5549 'constrain': { 5550 'name': 'constrain', 5551 'params': [ 5552 { 5553 'name': 'n', 5554 'description': '<p>number to constrain</p>\n', 5555 'type': 'Number' 5556 }, 5557 { 5558 'name': 'low', 5559 'description': '<p>minimum limit</p>\n', 5560 'type': 'Number' 5561 }, 5562 { 5563 'name': 'high', 5564 'description': '<p>maximum limit</p>\n', 5565 'type': 'Number' 5566 } 5567 ], 5568 'class': 'p5', 5569 'module': 'Math' 5570 }, 5571 'dist': { 5572 'name': 'dist', 5573 'class': 'p5', 5574 'module': 'Math', 5575 'overloads': [ 5576 { 5577 'params': [ 5578 { 5579 'name': 'x1', 5580 'description': '<p>x-coordinate of the first point</p>\n', 5581 'type': 'Number' 5582 }, 5583 { 5584 'name': 'y1', 5585 'description': '<p>y-coordinate of the first point</p>\n', 5586 'type': 'Number' 5587 }, 5588 { 5589 'name': 'x2', 5590 'description': '<p>x-coordinate of the second point</p>\n', 5591 'type': 'Number' 5592 }, 5593 { 5594 'name': 'y2', 5595 'description': '<p>y-coordinate of the second point</p>\n', 5596 'type': 'Number' 5597 } 5598 ] 5599 }, 5600 { 5601 'params': [ 5602 { 5603 'name': 'x1', 5604 'description': '', 5605 'type': 'Number' 5606 }, 5607 { 5608 'name': 'y1', 5609 'description': '', 5610 'type': 'Number' 5611 }, 5612 { 5613 'name': 'z1', 5614 'description': '<p>z-coordinate of the first point</p>\n', 5615 'type': 'Number' 5616 }, 5617 { 5618 'name': 'x2', 5619 'description': '', 5620 'type': 'Number' 5621 }, 5622 { 5623 'name': 'y2', 5624 'description': '', 5625 'type': 'Number' 5626 }, 5627 { 5628 'name': 'z2', 5629 'description': '<p>z-coordinate of the second point</p>\n', 5630 'type': 'Number' 5631 } 5632 ] 5633 } 5634 ] 5635 }, 5636 'exp': { 5637 'name': 'exp', 5638 'params': [ 5639 { 5640 'name': 'n', 5641 'description': '<p>exponent to raise</p>\n', 5642 'type': 'Number' 5643 } 5644 ], 5645 'class': 'p5', 5646 'module': 'Math' 5647 }, 5648 'floor': { 5649 'name': 'floor', 5650 'params': [ 5651 { 5652 'name': 'n', 5653 'description': '<p>number to round down</p>\n', 5654 'type': 'Number' 5655 } 5656 ], 5657 'class': 'p5', 5658 'module': 'Math' 5659 }, 5660 'lerp': { 5661 'name': 'lerp', 5662 'params': [ 5663 { 5664 'name': 'start', 5665 'description': '<p>first value</p>\n', 5666 'type': 'Number' 5667 }, 5668 { 5669 'name': 'stop', 5670 'description': '<p>second value</p>\n', 5671 'type': 'Number' 5672 }, 5673 { 5674 'name': 'amt', 5675 'description': '<p>number</p>\n', 5676 'type': 'Number' 5677 } 5678 ], 5679 'class': 'p5', 5680 'module': 'Math' 5681 }, 5682 'log': { 5683 'name': 'log', 5684 'params': [ 5685 { 5686 'name': 'n', 5687 'description': '<p>number greater than 0</p>\n', 5688 'type': 'Number' 5689 } 5690 ], 5691 'class': 'p5', 5692 'module': 'Math' 5693 }, 5694 'mag': { 5695 'name': 'mag', 5696 'params': [ 5697 { 5698 'name': 'a', 5699 'description': '<p>first value</p>\n', 5700 'type': 'Number' 5701 }, 5702 { 5703 'name': 'b', 5704 'description': '<p>second value</p>\n', 5705 'type': 'Number' 5706 } 5707 ], 5708 'class': 'p5', 5709 'module': 'Math' 5710 }, 5711 'map': { 5712 'name': 'map', 5713 'params': [ 5714 { 5715 'name': 'value', 5716 'description': '<p>the incoming value to be converted</p>\n', 5717 'type': 'Number' 5718 }, 5719 { 5720 'name': 'start1', 5721 'description': '<p>lower bound of the value\'s current range</p>\n', 5722 'type': 'Number' 5723 }, 5724 { 5725 'name': 'stop1', 5726 'description': '<p>upper bound of the value\'s current range</p>\n', 5727 'type': 'Number' 5728 }, 5729 { 5730 'name': 'start2', 5731 'description': '<p>lower bound of the value\'s target range</p>\n', 5732 'type': 'Number' 5733 }, 5734 { 5735 'name': 'stop2', 5736 'description': '<p>upper bound of the value\'s target range</p>\n', 5737 'type': 'Number' 5738 }, 5739 { 5740 'name': 'withinBounds', 5741 'description': '<p>constrain the value to the newly mapped range</p>\n', 5742 'type': 'Boolean', 5743 'optional': true 5744 } 5745 ], 5746 'class': 'p5', 5747 'module': 'Math' 5748 }, 5749 'max': { 5750 'name': 'max', 5751 'class': 'p5', 5752 'module': 'Math', 5753 'overloads': [ 5754 { 5755 'params': [ 5756 { 5757 'name': 'n0', 5758 'description': '<p>Number to compare</p>\n', 5759 'type': 'Number' 5760 }, 5761 { 5762 'name': 'n1', 5763 'description': '<p>Number to compare</p>\n', 5764 'type': 'Number' 5765 } 5766 ] 5767 }, 5768 { 5769 'params': [ 5770 { 5771 'name': 'nums', 5772 'description': '<p>Numbers to compare</p>\n', 5773 'type': 'Number[]' 5774 } 5775 ] 5776 } 5777 ] 5778 }, 5779 'min': { 5780 'name': 'min', 5781 'class': 'p5', 5782 'module': 'Math', 5783 'overloads': [ 5784 { 5785 'params': [ 5786 { 5787 'name': 'n0', 5788 'description': '<p>Number to compare</p>\n', 5789 'type': 'Number' 5790 }, 5791 { 5792 'name': 'n1', 5793 'description': '<p>Number to compare</p>\n', 5794 'type': 'Number' 5795 } 5796 ] 5797 }, 5798 { 5799 'params': [ 5800 { 5801 'name': 'nums', 5802 'description': '<p>Numbers to compare</p>\n', 5803 'type': 'Number[]' 5804 } 5805 ] 5806 } 5807 ] 5808 }, 5809 'norm': { 5810 'name': 'norm', 5811 'params': [ 5812 { 5813 'name': 'value', 5814 'description': '<p>incoming value to be normalized</p>\n', 5815 'type': 'Number' 5816 }, 5817 { 5818 'name': 'start', 5819 'description': '<p>lower bound of the value\'s current range</p>\n', 5820 'type': 'Number' 5821 }, 5822 { 5823 'name': 'stop', 5824 'description': '<p>upper bound of the value\'s current range</p>\n', 5825 'type': 'Number' 5826 } 5827 ], 5828 'class': 'p5', 5829 'module': 'Math' 5830 }, 5831 'pow': { 5832 'name': 'pow', 5833 'params': [ 5834 { 5835 'name': 'n', 5836 'description': '<p>base of the exponential expression</p>\n', 5837 'type': 'Number' 5838 }, 5839 { 5840 'name': 'e', 5841 'description': '<p>power by which to raise the base</p>\n', 5842 'type': 'Number' 5843 } 5844 ], 5845 'class': 'p5', 5846 'module': 'Math' 5847 }, 5848 'round': { 5849 'name': 'round', 5850 'params': [ 5851 { 5852 'name': 'n', 5853 'description': '<p>number to round</p>\n', 5854 'type': 'Number' 5855 }, 5856 { 5857 'name': 'decimals', 5858 'description': '<p>number of decimal places to round to, default is 0</p>\n', 5859 'type': 'Number', 5860 'optional': true 5861 } 5862 ], 5863 'class': 'p5', 5864 'module': 'Math' 5865 }, 5866 'sq': { 5867 'name': 'sq', 5868 'params': [ 5869 { 5870 'name': 'n', 5871 'description': '<p>number to square</p>\n', 5872 'type': 'Number' 5873 } 5874 ], 5875 'class': 'p5', 5876 'module': 'Math' 5877 }, 5878 'sqrt': { 5879 'name': 'sqrt', 5880 'params': [ 5881 { 5882 'name': 'n', 5883 'description': '<p>non-negative number to square root</p>\n', 5884 'type': 'Number' 5885 } 5886 ], 5887 'class': 'p5', 5888 'module': 'Math' 5889 }, 5890 'fract': { 5891 'name': 'fract', 5892 'params': [ 5893 { 5894 'name': 'num', 5895 'description': '<p>Number whose fractional part needs to be found out</p>\n', 5896 'type': 'Number' 5897 } 5898 ], 5899 'class': 'p5', 5900 'module': 'Math' 5901 }, 5902 'createVector': { 5903 'name': 'createVector', 5904 'params'
5904: [ 5905 { 5906 'name': 'x', 5907 'description': '<p>x component of the vector</p>\n', 5908 'type': 'Number', 5909 'optional': true 5910 }, 5911 { 5912 'name': 'y', 5913 'description': '<p>y component of the vector</p>\n', 5914 'type': 'Number', 5915 'optional': true 5916 }, 5917 { 5918 'name': 'z', 5919 'description': '<p>z component of the vector</p>\n', 5920 'type': 'Number', 5921 'optional': true 5922 } 5923 ], 5924 'class': 'p5', 5925 'module': 'Math' 5926 }, 5927 'noise': { 5928 'name': 'noise', 5929 'params': [ 5930 { 5931 'name': 'x', 5932 'description': '<p>x-coordinate in noise space</p>\n', 5933 'type': 'Number' 5934 }, 5935 { 5936 'name': 'y', 5937 'description': '<p>y-coordinate in noise space</p>\n', 5938 'type': 'Number', 5939 'optional': true 5940 }, 5941 { 5942 'name': 'z', 5943 'description': '<p>z-coordinate in noise space</p>\n', 5944 'type': 'Number', 5945 'optional': true 5946 } 5947 ], 5948 'class': 'p5', 5949 'module': 'Math' 5950 }, 5951 'noiseDetail': { 5952 'name': 'noiseDetail', 5953 'params': [ 5954 { 5955 'name': 'lod', 5956 'description': '<p>number of octaves to be used by the noise</p>\n', 5957 'type': 'Number' 5958 }, 5959 { 5960 'name': 'falloff', 5961 'description': '<p>falloff factor for each octave</p>\n', 5962 'type': 'Number' 5963 } 5964 ], 5965 'class': 'p5', 5966 'module': 'Math' 5967 }, 5968 'noiseSeed': { 5969 'name': 'noiseSeed', 5970 'params': [ 5971 { 5972 'name': 'seed', 5973 'description': '<p>the seed value</p>\n', 5974 'type': 'Number' 5975 } 5976 ], 5977 'class': 'p5', 5978 'module': 'Math' 5979 }, 5980 'randomSeed': { 5981 'name': 'randomSeed', 5982 'params': [ 5983 { 5984 'name': 'seed', 5985 'description': '<p>the seed value</p>\n', 5986 'type': 'Number' 5987 } 5988 ], 5989 'class': 'p5', 5990 'module': 'Math' 5991 }, 5992 'random': { 5993 'name': 'random', 5994 'class': 'p5', 5995 'module': 'Math', 5996 'overloads': [ 5997 { 5998 'params': [ 5999 { 6000 'name': 'min', 6001 'description': '<p>the lower bound (inclusive)</p>\n', 6002 'type': 'Number', 6003 'optional': true 6004 }, 6005 { 6006 'name': 'max', 6007 'description': '<p>the upper bound (exclusive)</p>\n', 6008 'type': 'Number', 6009 'optional': true 6010 } 6011 ] 6012 }, 6013 { 6014 'params': [ 6015 { 6016 'name': 'choices', 6017 'description': '<p>the array to choose from</p>\n', 6018 'type': 'Array' 6019 } 6020 ] 6021 } 6022 ] 6023 }, 6024 'randomGaussian': { 6025 'name': 'randomGaussian', 6026 'params': [ 6027 { 6028 'name': 'mean', 6029 'description': '<p>the mean</p>\n', 6030 'type': 'Number', 6031 'optional': true 6032 }, 6033 { 6034 'name': 'sd', 6035 'description': '<p>the standard deviation</p>\n', 6036 'type': 'Number', 6037 'optional': true 6038 } 6039 ], 6040 'class': 'p5', 6041 'module': 'Math' 6042 }, 6043 'acos': { 6044 'name': 'acos', 6045 'params': [ 6046 { 6047 'name': 'value', 6048 'description': '<p>the value whose arc cosine is to be returned</p>\n', 6049 'type': 'Number' 6050 } 6051 ], 6052 'class': 'p5', 6053 'module': 'Math' 6054 }, 6055 'asin': { 6056 'name': 'asin', 6057 'params': [ 6058 { 6059 'name': 'value', 6060 'description': '<p>the value whose arc sine is to be returned</p>\n', 6061 'type': 'Number' 6062 } 6063 ], 6064 'class': 'p5', 6065 'module': 'Math' 6066 }, 6067 'atan': { 6068 'name': 'atan', 6069 'params': [ 6070 { 6071 'name': 'value', 6072 'description': '<p>the value whose arc tangent is to be returned</p>\n', 6073 'type': 'Number' 6074 } 6075 ], 6076 'class': 'p5', 6077 'module': 'Math' 6078 }, 6079 'atan2': { 6080 'name': 'atan2', 6081 'params': [ 6082 { 6083 'name': 'y', 6084 'description': '<p>y-coordinate of the point</p>\n', 6085 'type': 'Number' 6086 }, 6087 { 6088 'name': 'x', 6089 'description': '<p>x-coordinate of the point</p>\n', 6090 'type': 'Number' 6091 } 6092 ], 6093 'class': 'p5', 6094 'module': 'Math' 6095 }, 6096 'cos': { 6097 'name': 'cos', 6098 'params': [ 6099 { 6100 'name': 'angle', 6101 'description': '<p>the angle</p>\n', 6102 'type': 'Number' 6103 } 6104 ], 6105 'class': 'p5', 6106 'module': 'Math' 6107 }, 6108 'sin': { 6109 'name': 'sin', 6110 'params': [ 6111 { 6112 'name': 'angle', 6113 'description': '<p>the angle</p>\n', 6114 'type': 'Number' 6115 } 6116 ], 6117 'class': 'p5', 6118 'module': 'Math' 6119 }, 6120 'tan': { 6121 'name': 'tan', 6122 'params': [ 6123 { 6124 'name': 'angle', 6125 'description': '<p>the angle</p>\n', 6126 'type': 'Number' 6127 } 6128 ], 6129 'class': 'p5', 6130 'module': 'Math' 6131 }, 6132 'degrees': { 6133 'name': 'degrees', 6134 'params': [ 6135 { 6136 'name': 'radians', 6137 'description': '<p>the radians value to convert to degrees</p>\n', 6138 'type': 'Number' 6139 } 6140 ], 6141 'class': 'p5', 6142 'module': 'Math' 6143 }, 6144 'radians': { 6145 'name': 'radians', 6146 'params': [ 6147 { 6148 'name': 'degrees', 6149 'description': '<p>the degree value to convert to radians</p>\n', 6150 'type': 'Number' 6151 } 6152 ], 6153 'class': 'p5', 6154 'module': 'Math' 6155 }, 6156 'angleMode': { 6157 'name': 'angleMode', 6158 'class': 'p5', 6159 'module': 'Math', 6160 'overloads': [ 6161 { 6162 'params': [ 6163 { 6164 'name': 'mode', 6165 'description': '<p>either RADIANS or DEGREES</p>\n', 6166 'type': 'Constant' 6167 } 6168 ] 6169 }, 6170 { 6171 'params': [ 6172 ] 6173 } 6174 ] 6175 }, 6176 'textAlign': { 6177 'name': 'textAlign', 6178 'class': 'p5', 6179 'module': 'Typography', 6180 'overloads': [ 6181 { 6182 'params': [ 6183 { 6184 'name': 'horizAlign', 6185 'description': '<p>horizontal alignment, either LEFT,\n CENTER, or RIGHT</p>\n', 6186 'type': 'Constant' 6187 }, 6188 { 6189 'name': 'vertAlign', 6190 'description': '<p>vertical alignment, either TOP,\n BOTTOM, CENTER, or BASELINE</p>\n', 6191 'type': 'Constant', 6192 'optional': true 6193 } 6194 ], 6195 'chainable': 1 6196 }, 6197 { 6198 'params': [ 6199 ] 6200 } 6201 ] 6202 }, 6203 'textLeading': { 6204 'name': 'textLeading', 6205 'class': 'p5', 6206 'module': 'Typography', 6207 'overloads': [ 6208 { 6209 'params': [ 6210 { 6211 'name': 'leading', 6212 'description': '<p>the size in pixels for spacing between lines</p>\n', 6213 'type': 'Number' 6214 } 6215 ], 6216 'chainable': 1 6217 }, 6218 { 6219 'params': [ 6220 ] 6221 } 6222 ] 6223 }, 6224 'textSize': { 6225 'name': 'textSize', 6226 'class': 'p5', 6227 'module': 'Typography', 6228 'overloads': [ 6229 { 6230 'params': [ 6231 { 6232 'name': 'theSize', 6233 'description': '<p>the size of the letters in units of pixels</p>\n', 6234 'type': 'Number' 6235 } 6236 ], 6237 'chainable': 1 6238 }, 6239 { 6240 'params': [ 6241 ] 6242 } 6243 ] 6244 }, 6245 'textStyle': { 6246 'name': 'textStyle', 6247 'class': 'p5', 6248 'module': 'Typography', 6249 'overloads': [ 6250 { 6251 'params': [ 6252 { 6253 'name': 'theStyle', 6254 'description': '<p>styling for text, either NORMAL,\n ITALIC, BOLD or BOLDITALIC</p>\n', 6255 'type': 'Constant' 6256 } 6257 ], 6258 'chainable': 1 6259 }, 6260 { 6261 'params': [ 6262 ] 6263 } 6264 ] 6265 }, 6266 'textWidth': { 6267 'name': 'textWidth', 6268 'params': [ 6269 { 6270 'name': 'theText', 6271 'description': '<p>
6271the String of characters to measure</p>\n', 6272 'type': 'String' 6273 } 6274 ], 6275 'class': 'p5', 6276 'module': 'Typography' 6277 }, 6278 'textAscent': { 6279 'name': 'textAscent', 6280 'class': 'p5', 6281 'module': 'Typography' 6282 }, 6283 'textDescent': { 6284 'name': 'textDescent', 6285 'class': 'p5', 6286 'module': 'Typography' 6287 }, 6288 'textWrap': { 6289 'name': 'textWrap', 6290 'params': [ 6291 { 6292 'name': 'wrapStyle', 6293 'description': '<p>text wrapping style, either WORD or CHAR</p>\n', 6294 'type': 'Constant' 6295 } 6296 ], 6297 'class': 'p5', 6298 'module': 'Typography' 6299 }, 6300 'loadFont': { 6301 'name': 'loadFont', 6302 'params': [ 6303 { 6304 'name': 'path', 6305 'description': '<p>name of the file or url to load</p>\n', 6306 'type': 'String' 6307 }, 6308 { 6309 'name': 'callback', 6310 'description': '<p>function to be executed after\n <a href="#/p5/loadFont">loadFont()</a> completes</p>\n', 6311 'type': 'Function', 6312 'optional': true 6313 }, 6314 { 6315 'name': 'onError', 6316 'description': '<p>function to be executed if\n an error occurs</p>\n', 6317 'type': 'Function', 6318 'optional': true 6319 } 6320 ], 6321 'class': 'p5', 6322 'module': 'Typography' 6323 }, 6324 'text': { 6325 'name': 'text', 6326 'params': [ 6327 { 6328 'name': 'str', 6329 'description': '<p>the alphanumeric\n symbols to be displayed</p>\n', 6330 'type': 'String|Object|Array|Number|Boolean' 6331 }, 6332 { 6333 'name': 'x', 6334 'description': '<p>x-coordinate of text</p>\n', 6335 'type': 'Number' 6336 }, 6337 { 6338 'name': 'y', 6339 'description': '<p>y-coordinate of text</p>\n', 6340 'type': 'Number' 6341 }, 6342 { 6343 'name': 'x2', 6344 'description': '<p>by default, the width of the text box,\n see <a href="#/p5/rectMode">rectMode()</a> for more info</p>\n', 6345 'type': 'Number', 6346 'optional': true 6347 }, 6348 { 6349 'name': 'y2', 6350 'description': '<p>by default, the height of the text box,\n see <a href="#/p5/rectMode">rectMode()</a> for more info</p>\n', 6351 'type': 'Number', 6352 'optional': true 6353 } 6354 ], 6355 'class': 'p5', 6356 'module': 'Typography' 6357 }, 6358 'textFont': { 6359 'name': 'textFont', 6360 'class': 'p5', 6361 'module': 'Typography', 6362 'overloads': [ 6363 { 6364 'params': [ 6365 ] 6366 }, 6367 { 6368 'params': [ 6369 { 6370 'name': 'font', 6371 'description': '<p>a font loaded via <a href="#/p5/loadFont">loadFont()</a>,\nor a String representing a <a href="https://mzl.la/2dOw8WD">web safe font</a>\n(a font that is generally available across all systems)</p>\n', 6372 'type': 'Object|String' 6373 }, 6374 { 6375 'name': 'size', 6376 'description': '<p>the font size to use</p>\n', 6377 'type': 'Number', 6378 'optional': true 6379 } 6380 ], 6381 'chainable': 1 6382 } 6383 ] 6384 }, 6385 'append': { 6386 'name': 'append', 6387 'params': [ 6388 { 6389 'name': 'array', 6390 'description': '<p>Array to append</p>\n', 6391 'type': 'Array' 6392 }, 6393 { 6394 'name': 'value', 6395 'description': '<p>to be added to the Array</p>\n', 6396 'type': 'Any' 6397 } 6398 ], 6399 'class': 'p5', 6400 'module': 'Data' 6401 }, 6402 'arrayCopy': { 6403 'name': 'arrayCopy', 6404 'class': 'p5', 6405 'module': 'Data', 6406 'overloads': [ 6407 { 6408 'params': [ 6409 { 6410 'name': 'src', 6411 'description': '<p>the source Array</p>\n', 6412 'type': 'Array' 6413 }, 6414 { 6415 'name': 'srcPosition', 6416 'description': '<p>starting position in the source Array</p>\n', 6417 'type': 'Integer' 6418 }, 6419 { 6420 'name': 'dst', 6421 'description': '<p>the destination Array</p>\n', 6422 'type': 'Array' 6423 }, 6424 { 6425 'name': 'dstPosition', 6426 'description': '<p>starting position in the destination Array</p>\n', 6427 'type': 'Integer' 6428 }, 6429 { 6430 'name': 'length', 6431 'description': '<p>number of Array elements to be copied</p>\n', 6432 'type': 'Integer' 6433 } 6434 ] 6435 }, 6436 { 6437 'params': [ 6438 { 6439 'name': 'src', 6440 'description': '', 6441 'type': 'Array' 6442 }, 6443 { 6444 'name': 'dst', 6445 'description': '', 6446 'type': 'Array' 6447 }, 6448 { 6449 'name': 'length', 6450 'description': '', 6451 'type': 'Integer', 6452 'optional': true 6453 } 6454 ] 6455 } 6456 ] 6457 }, 6458 'concat': { 6459 'name': 'concat', 6460 'params': [ 6461 { 6462 'name': 'a', 6463 'description': '<p>first Array to concatenate</p>\n', 6464 'type': 'Array' 6465 }, 6466 { 6467 'name': 'b', 6468 'description': '<p>second Array to concatenate</p>\n', 6469 'type': 'Array' 6470 } 6471 ], 6472 'class': 'p5', 6473 'module': 'Data' 6474 }, 6475 'reverse': { 6476 'name': 'reverse', 6477 'params': [ 6478 { 6479 'name': 'list', 6480 'description': '<p>Array to reverse</p>\n', 6481 'type': 'Array' 6482 } 6483 ], 6484 'class': 'p5', 6485 'module': 'Data' 6486 }, 6487 'shorten': { 6488 'name': 'shorten', 6489 'params': [ 6490 { 6491 'name': 'list', 6492 'description': '<p>Array to shorten</p>\n', 6493 'type': 'Array' 6494 } 6495 ], 6496 'class': 'p5', 6497 'module': 'Data' 6498 }, 6499 'shuffle': { 6500 'name': 'shuffle', 6501 'params': [ 6502 { 6503 'name': 'array', 6504 'description': '<p>Array to shuffle</p>\n', 6505 'type': 'Array' 6506 }, 6507 { 6508 'name': 'bool', 6509 'description': '<p>modify passed array</p>\n', 6510 'type': 'Boolean', 6511 'optional': true 6512 } 6513 ], 6514 'class': 'p5', 6515 'module': 'Data' 6516 }, 6517 'sort': { 6518 'name': 'sort', 6519 'params': [ 6520 { 6521 'name': 'list', 6522 'description': '<p>Array to sort</p>\n', 6523 'type': 'Array' 6524 }, 6525 { 6526 'name': 'count', 6527 'description': '<p>number of elements to sort, starting from 0</p>\n', 6528 'type': 'Integer', 6529 'optional': true 6530 } 6531 ], 6532 'class': 'p5', 6533 'module': 'Data' 6534 }, 6535 'splice': { 6536 'name': 'splice', 6537 'params': [ 6538 { 6539 'name': 'list', 6540 'description': '<p>Array to splice into</p>\n', 6541 'type': 'Array' 6542 }, 6543 { 6544 'name': 'value', 6545 'description': '<p>value to be spliced in</p>\n', 6546 'type': 'Any' 6547 }, 6548 { 6549 'name': 'position', 6550 'description': '<p>in the array from which to insert data</p>\n', 6551 'type': 'Integer' 6552 } 6553 ], 6554 'class': 'p5', 6555 'module': 'Data' 6556 }, 6557 'subset': { 6558 'name': 'subset', 6559 'params': [ 6560 { 6561 'name': 'list', 6562 'description': '<p>Array to extract from</p>\n', 6563 'type': 'Array' 6564 }, 6565 { 6566 'name': 'start', 6567 'description': '<p>position to begin</p>\n', 6568 'type': 'Integer' 6569 }, 6570 { 6571 'name': 'count', 6572 'description': '<p>number of values to extract</p>\n', 6573 'type': 'Integer', 6574 'optional': true 6575 } 6576 ], 6577 'class': 'p5', 6578 'module': 'Data' 6579 }, 6580 'float': { 6581 'name': 'float', 6582 'params': [ 6583 { 6584 'name': 'str', 6585 'description': '<p>float string to parse</p>\n', 6586 'type': 'String' 6587 } 6588 ], 6589 'class': 'p5', 6590 'module': 'Data' 6591 }, 6592 'int': { 6593 'name': 'int', 6594 'class': 'p5', 6595 'module': 'Data', 6596 'overloads': [ 6597 { 6598 'params': [ 6599 { 6600 'name': 'n', 6601 'description': '<p>value to parse</p>\n', 6602 'type': 'String|Boolean|Number' 6603 }, 6604 { 6605 'name': 'radix', 6606 'description': '<p>the radix to convert to (default: 10)</p>\n', 6607 'type': 'Integer', 6608 'optional': true 6609 } 6610 ] 6611 }, 6612 { 6613 'params': [ 6614 { 6615 'name': 'ns', 6616 'description': '<p>values to parse</p>\n', 6617 'type': 'Array' 6618 }, 6619 { 6620 'name': 'radix', 6621 'description': '', 6622 'type': 'Integer', 6623 'optional': true 6624 } 6625 ] 6626 } 6627 ] 6628 }, 6629 'str': { 6630 'name': 'str', 6631 'params': [ 6632 { 6633 'name': 'n', 6634 'description': '<p>value to parse</p>\n', 6635 'type': 'String|Boolean|Number|Array' 6636 } 6637 ], 6638 'class': 'p5', 6639 'module': 'Data' 6640 }, 6641 'byte': { 6642 'name': 'byte', 6643 'class': 'p5', 6644 'module': 'Data', 6645 'overloads': [ 6646 { 6647 'params': [ 6648 { 6649 'name': 'n', 6650 'description': '<p>value to parse</p>\n', 6651 'type': 'String|Boolean|Number' 6652 } 6653 ] 6654 }, 6655 { 6656 'params': [ 6657 { 6658 'name': 'ns', 6659 'description': '<p>values to parse</p>\n', 6660 'type': 'Array' 6661 } 6662 ] 6663 } 6664 ] 6665 }, 6666 'char': { 6667 'name': 'char', 6668 'class': 'p5', 6669 'module': 'Data', 6670 'overloads': [ 6671 { 6672 'params': [ 6673 { 6674 'name': 'n', 6675 'description': '<p>value to parse</p>\n', 6676 'type': 'String|Number' 6677 } 6678 ] 6679 }, 6680 { 6681 'params': [ 6682 { 6683 'name': 'ns', 6684 'description': '<p>values to parse</p>\n', 6685 'type': 'Array' 6686 } 6687 ] 6688 } 6689 ] 6690 }, 6691 'unchar': { 6692 'name': 'unchar', 6693 'class': 'p5', 6694 'module': 'Data', 6695 'overloads': [ 6696 { 6697 'params': [ 6698 { 6699 'name': 'n', 6700 'description': '<p>value to parse</p>\n', 6701 'type': 'String' 6702 } 6703 ] 6704 }, 6705 { 6706 'params': [ 6707 { 6708 'name': 'ns', 6709 'description': '<p>values to parse</p>\n', 6710 'type': 'Array' 6711 } 6712 ] 6713 } 6714 ] 6715 }, 6716 'hex': { 6717 'name': 'hex', 6718 'class': 'p5', 6719 'module': 'Data', 6720 'overloads': [ 6721 { 6722 'params': [ 6723 { 6724 'name': 'n', 6725 'description': '<p>value to parse</p>\n', 6726 'type': 'Number' 6727 }, 6728 { 6729 'name': 'digits', 6730 'description': '', 6731 'type': 'Number', 6732 'optional': true 6733 } 6734 ] 6735 }, 6736 { 6737 'params': [ 6738 { 6739 'name': 'ns', 6740 'description': '<p>array of values to parse</p>\n', 6741 'type': 'Number[]' 6742 }, 6743 { 6744 'name': 'digits', 6745 'description': '', 6746 'type': 'Number', 6747 'optional': true 6748 } 6749 ] 6750 } 6751 ] 6752 }, 6753 'unhex': { 6754 'name': 'unhex', 6755 'class': 'p5', 6756 'module': 'Data', 6757 'overloads': [ 6758 { 6759 'params': [ 6760 { 6761 'name': 'n', 6762 'description': '<p>value to parse</p>\n', 6763 'type': 'String' 6764 } 6765 ] 6766 }, 6767 { 6768 'params': [ 6769 { 6770 'name': 'ns', 6771 'description': '<p>values to parse</p>\n', 6772 'type': 'Array' 6773 } 6774 ] 6775 } 6776 ] 6777 }, 6778 'join': { 6779 'name': 'join', 6780 'params': [ 6781 { 6782 'name': '
6782list', 6783 'description': '<p>array of Strings to be joined</p>\n', 6784 'type': 'Array' 6785 }, 6786 { 6787 'name': 'separator', 6788 'description': '<p>String to be placed between each item</p>\n', 6789 'type': 'String' 6790 } 6791 ], 6792 'class': 'p5', 6793 'module': 'Data' 6794 }, 6795 'match': { 6796 'name': 'match', 6797 'params': [ 6798 { 6799 'name': 'str', 6800 'description': '<p>the String to be searched</p>\n', 6801 'type': 'String' 6802 }, 6803 { 6804 'name': 'regexp', 6805 'description': '<p>the regexp to be used for matching</p>\n', 6806 'type': 'String' 6807 } 6808 ], 6809 'class': 'p5', 6810 'module': 'Data' 6811 }, 6812 'matchAll': { 6813 'name': 'matchAll', 6814 'params': [ 6815 { 6816 'name': 'str', 6817 'description': '<p>the String to be searched</p>\n', 6818 'type': 'String' 6819 }, 6820 { 6821 'name': 'regexp', 6822 'description': '<p>the regexp to be used for matching</p>\n', 6823 'type': 'String' 6824 } 6825 ], 6826 'class': 'p5', 6827 'module': 'Data' 6828 }, 6829 'nf': { 6830 'name': 'nf', 6831 'class': 'p5', 6832 'module': 'Data', 6833 'overloads': [ 6834 { 6835 'params': [ 6836 { 6837 'name': 'num', 6838 'description': '<p>the Number to format</p>\n', 6839 'type': 'Number|String' 6840 }, 6841 { 6842 'name': 'left', 6843 'description': '<p>number of digits to the left of the\n decimal point</p>\n', 6844 'type': 'Integer|String', 6845 'optional': true 6846 }, 6847 { 6848 'name': 'right', 6849 'description': '<p>number of digits to the right of the\n decimal point</p>\n', 6850 'type': 'Integer|String', 6851 'optional': true 6852 } 6853 ] 6854 }, 6855 { 6856 'params': [ 6857 { 6858 'name': 'nums', 6859 'description': '<p>the Numbers to format</p>\n', 6860 'type': 'Array' 6861 }, 6862 { 6863 'name': 'left', 6864 'description': '', 6865 'type': 'Integer|String', 6866 'optional': true 6867 }, 6868 { 6869 'name': 'right', 6870 'description': '', 6871 'type': 'Integer|String', 6872 'optional': true 6873 } 6874 ] 6875 } 6876 ] 6877 }, 6878 'nfc': { 6879 'name': 'nfc', 6880 'class': 'p5', 6881 'module': 'Data', 6882 'overloads': [ 6883 { 6884 'params': [ 6885 { 6886 'name': 'num', 6887 'description': '<p>the Number to format</p>\n', 6888 'type': 'Number|String' 6889 }, 6890 { 6891 'name': 'right', 6892 'description': '<p>number of digits to the right of the\n decimal point</p>\n', 6893 'type': 'Integer|String', 6894 'optional': true 6895 } 6896 ] 6897 }, 6898 { 6899 'params': [ 6900 { 6901 'name': 'nums', 6902 'description': '<p>the Numbers to format</p>\n', 6903 'type': 'Array' 6904 }, 6905 { 6906 'name': 'right', 6907 'description': '', 6908 'type': 'Integer|String', 6909 'optional': true 6910 } 6911 ] 6912 } 6913 ] 6914 }, 6915 'nfp': { 6916 'name': 'nfp', 6917 'class': 'p5', 6918 'module': 'Data', 6919 'overloads': [ 6920 { 6921 'params': [ 6922 { 6923 'name': 'num', 6924 'description': '<p>the Number to format</p>\n', 6925 'type': 'Number' 6926 }, 6927 { 6928 'name': 'left', 6929 'description': '<p>number of digits to the left of the decimal\n point</p>\n', 6930 'type': 'Integer', 6931 'optional': true 6932 }, 6933 { 6934 'name': 'right', 6935 'description': '<p>number of digits to the right of the\n decimal point</p>\n', 6936 'type': 'Integer', 6937 'optional': true 6938 } 6939 ] 6940 }, 6941 { 6942 'params': [ 6943 { 6944 'name': 'nums', 6945 'description': '<p>the Numbers to format</p>\n', 6946 'type': 'Number[]' 6947 }, 6948 { 6949 'name': 'left', 6950 'description': '', 6951 'type': 'Integer', 6952 'optional': true 6953 }, 6954 { 6955 'name': 'right', 6956 'description': '', 6957 'type': 'Integer', 6958 'optional': true 6959 } 6960 ] 6961 } 6962 ] 6963 }, 6964 'nfs': { 6965 'name': 'nfs', 6966 'class': 'p5', 6967 'module': 'Data', 6968 'overloads': [ 6969 { 6970 'params': [ 6971 { 6972 'name': 'num', 6973 'description': '<p>the Number to format</p>\n', 6974 'type': 'Number' 6975 }, 6976 { 6977 'name': 'left', 6978 'description': '<p>number of digits to the left of the decimal\n point</p>\n', 6979 'type': 'Integer', 6980 'optional': true 6981 }, 6982 { 6983 'name': 'right', 6984 'description': '<p>number of digits to the right of the\n decimal point</p>\n', 6985 'type': 'Integer', 6986 'optional': true 6987 } 6988 ] 6989 }, 6990 { 6991 'params': [ 6992 { 6993 'name': 'nums', 6994 'description': '<p>the Numbers to format</p>\n', 6995 'type': 'Array' 6996 }, 6997 { 6998 'name': 'left', 6999 'description': '', 7000 'type': 'Integer', 7001 'optional': true 7002 }, 7003 { 7004 'name': 'right', 7005 'description': '', 7006 'type': 'Integer', 7007 'optional': true 7008 } 7009 ] 7010 } 7011 ] 7012 }, 7013 'split': { 7014 'name': 'split', 7015 'params': [ 7016 { 7017 'name': 'value', 7018 'description': '<p>the String to be split</p>\n', 7019 'type': 'String' 7020 }, 7021 { 7022 'name': 'delim', 7023 'description': '<p>the String used to separate the data</p>\n', 7024 'type': 'String' 7025 } 7026 ], 7027 'class': 'p5', 7028 'module': 'Data' 7029 }, 7030 'splitTokens': { 7031 'name': 'splitTokens', 7032 'params': [ 7033 { 7034 'name': 'value', 7035 'description': '<p>the String to be split</p>\n', 7036 'type': 'String' 7037 }, 7038 { 7039 'name': 'delim', 7040 'description': '<p>list of individual Strings that will be used as\n separators</p>\n', 7041 'type': 'String', 7042 'optional': true 7043 } 7044 ], 7045 'class': 'p5', 7046 'module': 'Data' 7047 }, 7048 'trim': { 7049 'name': 'trim', 7050 'class': 'p5', 7051 'module': 'Data', 7052 'overloads': [ 7053 { 7054 'params': [ 7055 { 7056 'name': 'str', 7057 'description': '<p>a String to be trimmed</p>\n', 7058 'type': 'String' 7059 } 7060 ] 7061 }, 7062 { 7063 'params': [ 7064 { 7065 'name': 'strs', 7066 'description': '<p>an Array of Strings to be trimmed</p>\n', 7067 'type': 'Array' 7068 } 7069 ] 7070 } 7071 ] 7072 }, 7073 'day': { 7074 'name': 'day', 7075 'class': 'p5', 7076 'module': 'IO' 7077 }, 7078 'hour': { 7079 'name': 'hour', 7080 'class': 'p5', 7081 'module': 'IO' 7082 }, 7083 'minute': { 7084 'name': 'minute', 7085 'class': 'p5', 7086 'module': 'IO' 7087 }, 7088 'millis': { 7089 'name': 'millis', 7090 'class': 'p5', 7091 'module': 'IO' 7092 }, 7093 'month': { 7094 'name': 'month', 7095 'class': 'p5', 7096 'module': 'IO' 7097 }, 7098 'second': { 7099 'name': 'second', 7100 'class': 'p5', 7101 'module': 'IO' 7102 }, 7103 'year': { 7104 'name': 'year', 7105 'class': 'p5', 7106 'module': 'IO' 7107 }, 7108 'plane': { 7109 'name': 'plane', 7110 'params': [ 7111 { 7112 'name': 'width', 7113 'description': '<p>width of the plane</p>\n', 7114 'type': 'Number', 7115 'optional': true 7116 }, 7117 { 7118 'name': 'height', 7119 'description': '<p>height of the plane</p>\n', 7120 'type': 'Number', 7121 'optional': true 7122 }, 7123 { 7124 'name': 'detailX', 7125 'description': '<p>Optional number of triangle\n subdivisions in x-dimension</p>\n', 7126 'type': 'Integer', 7127 'optional': true 7128 }, 7129 { 7130 'name': 'detailY', 7131 'description': '<p>Optional number of triangle\n subdivisions in y-dimension</p>\n', 7132 'type': 'Integer', 7133 'optional': true 7134 } 7135 ], 7136 'class': 'p5', 7137 'module': 'Shape' 7138 }, 7139 'box': { 7140 'name': 'box', 7141 'params': [ 7142 { 7143 'name': 'width', 7144 'description': '<p>width of the box</p>\n', 7145 'type': 'Number', 7146 'optional': true 7147 }, 7148 { 7149 'name': 'height', 7150 'description': '<p>height of the box</p>\n', 7151 'type': 'Number', 7152 'optional': true 7153 }, 7154 { 7155 'name': 'depth', 7156 'description': '<p>depth of the box</p>\n', 7157 'type': 'Number', 7158 'optional': true 7159 }, 7160 { 7161 'name': 'detailX', 7162 'description': '<p>Optional number of triangle\n subdivisions in x-dimension</p>\n', 7163 'type': 'Integer', 7164 'optional': true 7165 }, 7166 { 7167 'name': 'detailY', 7168 'description': '<p>Optional number of triangle\n subdivisions in y-dimension</p>\n', 7169 'type': 'Integer', 7170 'optional': true 7171 } 7172 ], 7173 'class': 'p5', 7174 'module': 'Shape' 7175 }, 7176 'sphere': { 7177 'name': 'sphere', 7178 'params': [ 7179 { 7180 'name': 'radius', 7181 'description': '<p>
7181radius of circle</p>\n', 7182 'type': 'Number', 7183 'optional': true 7184 }, 7185 { 7186 'name': 'detailX', 7187 'description': '<p>optional number of subdivisions in x-dimension</p>\n', 7188 'type': 'Integer', 7189 'optional': true 7190 }, 7191 { 7192 'name': 'detailY', 7193 'description': '<p>optional number of subdivisions in y-dimension</p>\n', 7194 'type': 'Integer', 7195 'optional': true 7196 } 7197 ], 7198 'class': 'p5', 7199 'module': 'Shape' 7200 }, 7201 'cylinder': { 7202 'name': 'cylinder', 7203 'params': [ 7204 { 7205 'name': 'radius', 7206 'description': '<p>radius of the surface</p>\n', 7207 'type': 'Number', 7208 'optional': true 7209 }, 7210 { 7211 'name': 'height', 7212 'description': '<p>height of the cylinder</p>\n', 7213 'type': 'Number', 7214 'optional': true 7215 }, 7216 { 7217 'name': 'detailX', 7218 'description': '<p>number of subdivisions in x-dimension;\n default is 24</p>\n', 7219 'type': 'Integer', 7220 'optional': true 7221 }, 7222 { 7223 'name': 'detailY', 7224 'description': '<p>number of subdivisions in y-dimension;\n default is 1</p>\n', 7225 'type': 'Integer', 7226 'optional': true 7227 }, 7228 { 7229 'name': 'bottomCap', 7230 'description': '<p>whether to draw the bottom of the cylinder</p>\n', 7231 'type': 'Boolean', 7232 'optional': true 7233 }, 7234 { 7235 'name': 'topCap', 7236 'description': '<p>whether to draw the top of the cylinder</p>\n', 7237 'type': 'Boolean', 7238 'optional': true 7239 } 7240 ], 7241 'class': 'p5', 7242 'module': 'Shape' 7243 }, 7244 'cone': { 7245 'name': 'cone', 7246 'params': [ 7247 { 7248 'name': 'radius', 7249 'description': '<p>radius of the bottom surface</p>\n', 7250 'type': 'Number', 7251 'optional': true 7252 }, 7253 { 7254 'name': 'height', 7255 'description': '<p>height of the cone</p>\n', 7256 'type': 'Number', 7257 'optional': true 7258 }, 7259 { 7260 'name': 'detailX', 7261 'description': '<p>number of segments,\n the more segments the smoother geometry\n default is 24</p>\n', 7262 'type': 'Integer', 7263 'optional': true 7264 }, 7265 { 7266 'name': 'detailY', 7267 'description': '<p>number of segments,\n the more segments the smoother geometry\n default is 1</p>\n', 7268 'type': 'Integer', 7269 'optional': true 7270 }, 7271 { 7272 'name': 'cap', 7273 'description': '<p>whether to draw the base of the cone</p>\n', 7274 'type': 'Boolean', 7275 'optional': true 7276 } 7277 ], 7278 'class': 'p5', 7279 'module': 'Shape' 7280 }, 7281 'ellipsoid': { 7282 'name': 'ellipsoid', 7283 'params': [ 7284 { 7285 'name': 'radiusx', 7286 'description': '<p>x-radius of ellipsoid</p>\n', 7287 'type': 'Number', 7288 'optional': true 7289 }, 7290 { 7291 'name': 'radiusy', 7292 'description': '<p>y-radius of ellipsoid</p>\n', 7293 'type': 'Number', 7294 'optional': true 7295 }, 7296 { 7297 'name': 'radiusz', 7298 'description': '<p>z-radius of ellipsoid</p>\n', 7299 'type': 'Number', 7300 'optional': true 7301 }, 7302 { 7303 'name': 'detailX', 7304 'description': '<p>number of segments,\n the more segments the smoother geometry\n default is 24. Avoid detail number above\n 150, it may crash the browser.</p>\n', 7305 'type': 'Integer', 7306 'optional': true 7307 }, 7308 { 7309 'name': 'detailY', 7310 'description': '<p>number of segments,\n the more segments the smoother geometry\n default is 16. Avoid detail number above\n 150, it may crash the browser.</p>\n', 7311 'type': 'Integer', 7312 'optional': true 7313 } 7314 ], 7315 'class': 'p5', 7316 'module': 'Shape' 7317 }, 7318 'torus': { 7319 'name': 'torus', 7320 'params': [ 7321 { 7322 'name': 'radius', 7323 'description': '<p>radius of the whole ring</p>\n', 7324 'type': 'Number', 7325 'optional': true 7326 }, 7327 { 7328 'name': 'tubeRadius', 7329 'description': '<p>radius of the tube</p>\n', 7330 'type': 'Number', 7331 'optional': true 7332 }, 7333 { 7334 'name': 'detailX', 7335 'description': '<p>number of segments in x-dimension,\n the more segments the smoother geometry\n default is 24</p>\n', 7336 'type': 'Integer', 7337 'optional': true 7338 }, 7339 { 7340 'name': 'detailY', 7341 'description': '<p>number of segments in y-dimension,\n the more segments the smoother geometry\n default is 16</p>\n', 7342 'type': 'Integer', 7343 'optional': true 7344 } 7345 ], 7346 'class': 'p5', 7347 'module': 'Shape' 7348 }, 7349 'orbitControl': { 7350 'name': 'orbitControl', 7351 'params': [ 7352 { 7353 'name': 'sensitivityX', 7354 'description': '<p>sensitivity to mouse movement along X axis</p>\n', 7355 'type': 'Number', 7356 'optional': true 7357 }, 7358 { 7359 'name': 'sensitivityY', 7360 'description': '<p>sensitivity to mouse movement along Y axis</p>\n', 7361 'type': 'Number', 7362 'optional': true 7363 }, 7364 { 7365 'name': 'sensitivityZ', 7366 'description': '<p>sensitivity to scroll movement along Z axis</p>\n', 7367 'type': 'Number', 7368 'optional': true 7369 } 7370 ], 7371 'class': 'p5', 7372 'module': '3D' 7373 },
7374 'debugMode': { 7375 'name': 'debugMode', 7376 'class': 'p5', 7377 'module': '3D', 7378 'overloads': [ 7379 { 7380 'params': [ 7381 ] 7382 }, 7383 { 7384 'params': [ 7385 { 7386 'name': 'mode', 7387 'description': '<p>either GRID or AXES</p>\n', 7388 'type': 'Constant' 7389 } 7390 ] 7391 }, 7392 { 7393 'params': [ 7394 { 7395 'name': 'mode', 7396 'description': '', 7397 'type': 'Constant' 7398 }, 7399 { 7400 'name': 'gridSize', 7401 'description': '<p>size of one side of the grid</p>\n', 7402 'type': 'Number', 7403 'optional': true 7404 }, 7405 { 7406 'name': 'gridDivisions', 7407 'description': '<p>number of divisions in the grid</p>\n', 7408 'type': 'Number', 7409 'optional': true 7410 }, 7411 { 7412 'name': 'xOff', 7413 'description': '<p>X axis offset from origin (0,0,0)</p>\n', 7414 'type': 'Number', 7415 'optional': true 7416 }, 7417 { 7418 'name': 'yOff', 7419 'description': '<p>Y axis offset from origin (0,0,0)</p>\n', 7420 'type': 'Number', 7421 'optional': true 7422 }, 7423 { 7424 'name': 'zOff', 7425 'description': '<p>Z axis offset from origin (0,0,0)</p>\n', 7426 'type': 'Number', 7427 'optional': true 7428 } 7429 ] 7430 }, 7431 { 7432 'params': [ 7433 { 7434 'name': 'mode', 7435 'description': '', 7436 'type': 'Constant' 7437 }, 7438 { 7439 'name': 'axesSize', 7440 'description': '<p>size of axes icon</p>\n', 7441 'type': 'Number', 7442 'optional': true 7443 }, 7444 { 7445 'name': 'xOff', 7446 'description': '', 7447 'type': 'Number', 7448 'optional': true 7449 }, 7450 { 7451 'name': 'yOff', 7452 'description': '', 7453 'type': 'Number', 7454 'optional': true 7455 }, 7456 { 7457 'name': 'zOff', 7458 'description': '', 7459 'type': 'Number', 7460 'optional': true 7461 } 7462 ] 7463 }, 7464 { 7465 'params': [ 7466 { 7467 'name': 'gridSize', 7468 'description': '', 7469 'type': 'Number', 7470 'optional': true 7471 }, 7472 { 7473 'name': 'gridDivisions', 7474 'description': '', 7475 'type': 'Number', 7476 'optional': true 7477 }, 7478 { 7479 'name': 'gridXOff', 7480 'description': '', 7481 'type': 'Number', 7482 'optional': true 7483 }, 7484 { 7485 'name': 'gridYOff', 7486 'description': '', 7487 'type': 'Number', 7488 'optional': true 7489 }, 7490 { 7491 'name': 'gridZOff', 7492 'description': '', 7493 'type': 'Number', 7494 'optional': true 7495 }, 7496 { 7497 'name': 'axesSize', 7498 'description': '', 7499 'type': 'Number', 7500 'optional': true 7501 }, 7502 { 7503 'name': 'axesXOff', 7504 'description': '', 7505 'type': 'Number', 7506 'optional': true 7507 }, 7508 { 7509 'name': 'axesYOff', 7510 'description': '', 7511 'type': 'Number', 7512 'optional': true 7513 }, 7514 { 7515 'name': 'axesZOff', 7516 'description': '', 7517 'type': 'Number', 7518 'optional': true 7519 } 7520 ] 7521 } 7522 ] 7523 },
7524 'noDebugMode': { 7525 'name': 'noDebugMode', 7526 'class': 'p5', 7527 'module': '3D' 7528 }, 7529 'ambientLight': { 7530 'name': 'ambientLight', 7531 'class': 'p5', 7532 'module': '3D', 7533 'overloads': [ 7534 { 7535 'params': [ 7536 { 7537 'name': 'v1', 7538 'description': '<p>red or hue value relative to\n the current color range</p>\n', 7539 'type': 'Number' 7540 }, 7541 { 7542 'name': 'v2', 7543 'description': '<p>green or saturation value\n relative to the current color range</p>\n', 7544 'type': 'Number' 7545 }, 7546 { 7547 'name': 'v3', 7548 'description': '<p>blue or brightness value\n relative to the current color range</p>\n', 7549 'type': 'Number' 7550 }, 7551 { 7552 'name': 'alpha', 7553 'description': '<p>alpha value relative to current\n color range (default is 0-255)</p>\n', 7554 'type': 'Number', 7555 'optional': true 7556 } 7557 ], 7558 'chainable': 1 7559 }, 7560 { 7561 'params': [ 7562 { 7563 'name': 'gray', 7564 'description': '<p>number specifying value between\n white and black</p>\n', 7565 'type': 'Number' 7566 }, 7567 { 7568 'name': 'alpha', 7569 'description': '', 7570 'type': 'Number', 7571 'optional': true 7572 } 7573 ], 7574 'chainable': 1 7575 }, 7576 { 7577 'params': [ 7578 { 7579 'name': 'value', 7580 'description': '<p>a color string</p>\n', 7581 'type': 'String' 7582 } 7583 ], 7584 'chainable': 1 7585 }, 7586 { 7587 'params': [ 7588 { 7589 'name': 'values', 7590 'description': '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n', 7591 'type': 'Number[]' 7592 } 7593 ], 7594 'chainable': 1 7595 }, 7596 { 7597 'params': [ 7598 { 7599 'name': 'color', 7600 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a></p>\n', 7601 'type': 'p5.Color' 7602 } 7603 ], 7604 'chainable': 1 7605 } 7606 ] 7607 }, 7608 'specularColor': { 7609 'name': 'specularColor', 7610 'class': 'p5', 7611 'module': '3D', 7612 'overloads': [ 7613 { 7614 'params': [ 7615 { 7616 'name': 'v1', 7617 'description': '<p>red or hue value relative to\n the current color range</p>\n', 7618 'type': 'Number' 7619 }, 7620 { 7621 'name': 'v2', 7622 'description': '<p>green or saturation value\n relative to the current color range</p>\n', 7623 'type': 'Number' 7624 }, 7625 { 7626 'name': 'v3', 7627 'description': '<p>blue or brightness value\n relative to the current color range</p>\n', 7628 'type': 'Number' 7629 } 7630 ], 7631 'chainable': 1 7632 }, 7633 { 7634 'params': [ 7635 { 7636 'name': 'gray', 7637 'description': '<p>number specifying value between\n white and black</p>\n', 7638 'type': 'Number' 7639 } 7640 ], 7641 'chainable': 1 7642 }, 7643 { 7644 'params': [ 7645 { 7646 'name': 'value', 7647 'description': '<p>color as a CSS string</p>\n', 7648 'type': 'String' 7649 } 7650 ], 7651 'chainable': 1 7652 }, 7653 { 7654 'params': [ 7655 { 7656 'name': 'values', 7657 'description': '<p>color as an array containing the\n red, green, and blue components</p>\n', 7658 'type': 'Number[]' 7659 } 7660 ], 7661 'chainable': 1 7662 }, 7663 { 7664 'params': [ 7665 { 7666 'name': 'color', 7667 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a></p>\n', 7668 'type': 'p5.Color' 7669 } 7670 ], 7671 'chainable': 1 7672 } 7673 ] 7674 }, 7675 'directionalLight': { 7676 'name': 'directionalLight', 7677 'class': 'p5', 7678 'module': '3D', 7679 'overloads': [ 7680 { 7681 'params': [ 7682 { 7683 'name': 'v1', 7684 'description': '<p>red or hue value relative to the current\n color range</p>\n', 7685 'type': 'Number' 7686 }, 7687 { 7688 'name': 'v2', 7689 'description': '<p>green or saturation value relative to the\n current color range</p>\n', 7690 'type': 'Number' 7691 }, 7692 { 7693 'name': 'v3', 7694 'description': '<p>blue or brightness value relative to the\n current color range</p>\n', 7695 'type': 'Number' 7696 }, 7697 { 7698 'name': 'x', 7699 'description': '<p>x component of direction (inclusive range of -1 to 1)</p>\n', 7700 'type': 'Number' 7701 }, 7702 { 7703 'name': 'y', 7704 'description': '<p>y component of direction (inclusive range of -1 to 1)</p>\n', 7705 'type': 'Number' 7706 }, 7707 { 7708 'name': 'z', 7709 'description': '<p>z component of direction (inclusive range of -1 to 1)</p>\n', 7710 'type': 'Number' 7711 } 7712 ], 7713 'chainable': 1 7714 }, 7715 { 7716 'params': [ 7717 { 7718 'name': 'v1', 7719 'description': '', 7720 'type': 'Number' 7721 }, 7722 { 7723 'name': 'v2', 7724 'description': '', 7725 'type': 'Number' 7726 }, 7727 { 7728 'name': 'v3', 7729 'description': '', 7730 'type': 'Number' 7731 }, 7732 { 7733 'name': 'direction', 7734 'description': '<p>direction of light as a\n <a href="#/p5.Vector">p5.Vector</a></p>\n', 7735 'type': 'p5.Vector' 7736 } 7737 ], 7738 'chainable': 1 7739 }, 7740 { 7741 'params': [ 7742 { 7743 'name': 'color', 7744 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a>,\n as an array, or as a CSS string</p>\n', 7745 'type': 'p5.Color|Number[]|String' 7746 }, 7747 { 7748 'name': 'x', 7749 'description': '', 7750 'type': 'Number' 7751 }, 7752 { 7753 'name': 'y', 7754 'description': '', 7755 'type': 'Number' 7756 }, 7757 { 7758 'name': 'z', 7759 'description': '', 7760 'type': 'Number' 7761 } 7762 ], 7763 'chainable': 1 7764 }, 7765 { 7766 'params': [ 7767 { 7768 'name': 'color', 7769 'description': '', 7770 'type': 'p5.Color|Number[]|String' 7771 }, 7772 { 7773 'name': 'direction', 7774 'description': '', 7775 'type': 'p5.Vector' 7776 } 7777 ], 7778 'chainable': 1 7779 } 7780 ] 7781 }, 7782 'pointLight': { 7783 'name': 'pointLight', 7784 'class': 'p5', 7785 'module': '3D', 7786 'overloads': [ 7787 { 7788 'params': [ 7789 { 7790 'name': 'v1', 7791 'description': '<p>red or hue value relative to the current\n color range</p>\n', 7792 'type': 'Number' 7793 }, 7794 { 7795 'name': 'v2', 7796 'description': '<p>green or saturation value relative to the\n current color range</p>\n', 7797 'type': 'Number' 7798 }, 7799 { 7800 'name': 'v3', 7801 'description': '<p>blue or brightness value relative to the\n current color range</p>\n', 7802 'type': 'Number' 7803 }, 7804 { 7805 'name': 'x', 7806 'description': '<p>x component of position</p>\n', 7807 'type': 'Number' 7808 }, 7809 { 7810 'name': 'y', 7811 'description': '<p>y component of position</p>\n', 7812 'type': 'Number' 7813 }, 7814 { 7815 'name': 'z', 7816 'description': '<p>z component of position</p>\n', 7817 'type': 'Number' 7818 } 7819 ], 7820 'chainable': 1 7821 }, 7822 { 7823 'params': [ 7824 { 7825 'name': 'v1', 7826 'description': '', 7827 'type': 'Number' 7828 }, 7829 { 7830 'name': 'v2', 7831 'description': '', 7832 'type': 'Number' 7833 }, 7834 { 7835 'name': 'v3', 7836 'description': '', 7837 'type': 'Number' 7838 }, 7839 { 7840 'name': 'position', 7841 'description': '<p>of light as a <a href="#/p5.Vector">p5.Vector</a></p>\n', 7842 'type': 'p5.Vector' 7843 } 7844 ], 7845 'chainable': 1 7846 }, 7847 { 7848 'params': [ 7849 { 7850 'name': 'color', 7851 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a>,\n as an array, or as a CSS string</p>\n', 7852 'type': 'p5.Color|Number[]|String' 7853 }, 7854 { 7855 'name': 'x', 7856 'description': '', 7857 'type': 'Number' 7858 }, 7859 { 7860 'name': 'y', 7861 'description': '', 7862 'type': 'Number' 7863 }, 7864 { 7865 'name': 'z', 7866 'description': '', 7867 'type': 'Number' 7868 } 7869 ], 7870 'chainable': 1 7871 }, 7872 { 7873 'params': [ 7874 { 7875 'name': 'color', 7876 'description': '', 7877 'type': 'p5.Color|Number[]|String' 7878 }, 7879 { 7880 'name': 'position', 7881 'description': '', 7882 'type': 'p5.Vector' 7883 } 7884 ], 7885 'chainable': 1 7886 } 7887 ] 7888 }, 7889 'lights': { 7890 'name': 'lights', 7891 'class': 'p5', 7892 'module': '3D' 7893 }, 7894 'lightFalloff': { 7895 'name': 'lightFalloff', 7896 'params': [ 7897 { 7898 'name': 'constant', 7899 'description': '<p>CONSTANT value for determining falloff</p>\n', 7900 'type': 'Number' 7901 }, 7902 { 7903 'name': 'linear', 7904 'description': '<p>LINEAR value for determining falloff</p>\n', 7905 'type': 'Number' 7906 }, 7907 { 7908 'name': 'quadratic', 7909 'description': '<p>QUADRATIC value for determining falloff</p>\n', 7910 'type': 'Number' 7911 } 7912 ], 7913 'class': 'p5', 7914 'module': '3D' 7915 }, 7916 'spotLight': { 7917 'name': 'spotLight', 7918 'class': 'p5', 7919 'module': '3D', 7920 'overloads': [ 7921 { 7922 'params': [ 7923 { 7924 'name': 'v1', 7925 'description': '<p>red or hue value relative to the current color range</p>\n', 7926 'type': 'Number' 7927 }, 7928 { 7929 'name': 'v2', 7930 'description': '<p>green or saturation value relative to the current color range</p>\n', 7931 'type': 'Number' 7932 }, 7933 { 7934 'name': 'v3', 7935 'description': '<p>blue or brightness value relative to the current color range</p>\n', 7936 'type': 'Number' 7937 }, 7938 { 7939 'name': 'x', 7940 'description': '<p>x component of position</p>\n', 7941 'type': 'Number' 7942 }, 7943 { 7944 'name': 'y', 7945 'description': '<p>y component of position</p>\n', 7946 'type': 'Number' 7947 }, 7948 { 7949 'name': 'z', 7950 'description': '<p>z component of position</p>\n', 7951 'type': 'Number' 7952 }, 7953 { 7954 'name': 'rx', 7955 'description': '<p>x component of light direction (inclusive range of -1 to 1)</p>\n', 7956 'type': 'Number' 7957 }, 7958 { 7959 'name': 'ry', 7960 'description': '<p>y component of light direction (inclusive range of -1 to 1)</p>\n', 7961 'type': 'Number' 7962 }, 7963
7963 { 7964 'name': 'rz', 7965 'description': '<p>z component of light direction (inclusive range of -1 to 1)</p>\n', 7966 'type': 'Number' 7967 }, 7968 { 7969 'name': 'angle', 7970 'description': '<p>angle of cone. Defaults to PI/3</p>\n', 7971 'type': 'Number', 7972 'optional': true 7973 }, 7974 { 7975 'name': 'concentration', 7976 'description': '<p>concentration of cone. Defaults to 100</p>\n', 7977 'type': 'Number', 7978 'optional': true 7979 } 7980 ], 7981 'chainable': 1 7982 }, 7983 { 7984 'params': [ 7985 { 7986 'name': 'color', 7987 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a>,\n as an array, or as a CSS string</p>\n', 7988 'type': 'p5.Color|Number[]|String' 7989 }, 7990 { 7991 'name': 'position', 7992 'description': '<p>position of light as a <a href="#/p5.Vector">p5.Vector</a></p>\n', 7993 'type': 'p5.Vector' 7994 }, 7995 { 7996 'name': 'direction', 7997 'description': '<p>direction of light as a <a href="#/p5.Vector">p5.Vector</a></p>\n', 7998 'type': 'p5.Vector' 7999 }, 8000 { 8001 'name': 'angle', 8002 'description': '', 8003 'type': 'Number', 8004 'optional': true 8005 }, 8006 { 8007 'name': 'concentration', 8008 'description': '', 8009 'type': 'Number', 8010 'optional': true 8011 } 8012 ] 8013 }, 8014 { 8015 'params': [ 8016 { 8017 'name': 'v1', 8018 'description': '', 8019 'type': 'Number' 8020 }, 8021 { 8022 'name': 'v2', 8023 'description': '', 8024 'type': 'Number' 8025 }, 8026 { 8027 'name': 'v3', 8028 'description': '', 8029 'type': 'Number' 8030 }, 8031 { 8032 'name': 'position', 8033 'description': '', 8034 'type': 'p5.Vector' 8035 }, 8036 { 8037 'name': 'direction', 8038 'description': '', 8039 'type': 'p5.Vector' 8040 }, 8041 { 8042 'name': 'angle', 8043 'description': '', 8044 'type': 'Number', 8045 'optional': true 8046 }, 8047 { 8048 'name': 'concentration', 8049 'description': '', 8050 'type': 'Number', 8051 'optional': true 8052 } 8053 ] 8054 }, 8055 { 8056 'params': [ 8057 { 8058 'name': 'color', 8059 'description': '', 8060 'type': 'p5.Color|Number[]|String' 8061 }, 8062 { 8063 'name': 'x', 8064 'description': '', 8065 'type': 'Number' 8066 }, 8067 { 8068 'name': 'y', 8069 'description': '', 8070 'type': 'Number' 8071 }, 8072 { 8073 'name': 'z', 8074 'description': '', 8075 'type': 'Number' 8076 }, 8077 { 8078 'name': 'direction', 8079 'description': '', 8080 'type': 'p5.Vector' 8081 }, 8082 { 8083 'name': 'angle', 8084 'description': '', 8085 'type': 'Number', 8086 'optional': true 8087 }, 8088 { 8089 'name': 'concentration', 8090 'description': '', 8091 'type': 'Number', 8092 'optional': true 8093 } 8094 ] 8095 }, 8096 { 8097 'params': [ 8098 { 8099 'name': 'color', 8100 'description': '', 8101 'type': 'p5.Color|Number[]|String' 8102 }, 8103 { 8104 'name': 'position', 8105 'description': '', 8106 'type': 'p5.Vector' 8107 }, 8108 { 8109 'name': 'rx', 8110 'description': '', 8111 'type': 'Number' 8112 }, 8113 { 8114 'name': 'ry', 8115 'description': '', 8116 'type': 'Number' 8117 }, 8118 { 8119 'name': 'rz', 8120 'description': '', 8121 'type': 'Number' 8122 }, 8123 { 8124 'name': 'angle', 8125 'description': '', 8126 'type': 'Number', 8127 'optional': true 8128 }, 8129 { 8130 'name': 'concentration', 8131 'description': '', 8132 'type': 'Number', 8133 'optional': true 8134 } 8135 ] 8136 }, 8137 { 8138 'params': [ 8139 { 8140 'name': 'v1', 8141 'description': '', 8142 'type': 'Number' 8143 }, 8144 { 8145 'name': 'v2', 8146 'description': '', 8147 'type': 'Number' 8148 }, 8149 { 8150 'name': 'v3', 8151 'description': '', 8152 'type': 'Number' 8153 }, 8154 { 8155 'name': 'x', 8156 'description': '', 8157 'type': 'Number' 8158 }, 8159 { 8160 'name': 'y', 8161 'description': '', 8162 'type': 'Number' 8163 }, 8164 { 8165 'name': 'z', 8166 'description': '', 8167 'type': 'Number' 8168 }, 8169 { 8170 'name': 'direction', 8171 'description': '', 8172 'type': 'p5.Vector' 8173 }, 8174 { 8175 'name': 'angle', 8176 'description': '', 8177 'type': 'Number', 8178 'optional': true 8179 }, 8180 { 8181 'name': 'concentration', 8182 'description': '', 8183 'type': 'Number', 8184 'optional': true 8185 } 8186 ] 8187 }, 8188 { 8189 'params': [ 8190 { 8191 'name': 'v1', 8192 'description': '', 8193 'type': 'Number' 8194 }, 8195 { 8196 'name': 'v2', 8197 'description': '', 8198 'type': 'Number' 8199 }, 8200 { 8201 'name': 'v3', 8202 'description': '', 8203 'type': 'Number' 8204 }, 8205 { 8206 'name': 'position', 8207 'description': '', 8208 'type': 'p5.Vector' 8209 }, 8210 { 8211 'name': 'rx', 8212 'description': '', 8213 'type': 'Number' 8214 }, 8215 { 8216 'name': 'ry', 8217 'description': '', 8218 'type': 'Number' 8219 }, 8220 { 8221 'name': 'rz', 8222 'description': '', 8223 'type': 'Number' 8224 }, 8225 { 8226 'name': 'angle', 8227 'description': '', 8228 'type': 'Number', 8229 'optional': true 8230 }, 8231 { 8232 'name': 'concentration', 8233 'description': '', 8234 'type': 'Number', 8235 'optional': true 8236 } 8237 ] 8238 }, 8239 { 8240 'params': [ 8241 { 8242 'name': 'color', 8243 'description': '', 8244 'type': 'p5.Color|Number[]|String' 8245 }, 8246 { 8247 'name': 'x', 8248 'description': '', 8249 'type': 'Number' 8250 }, 8251 { 8252 'name': 'y', 8253 'description': '', 8254 'type': 'Number' 8255 }, 8256 { 8257 'name': 'z', 8258 'description': '', 8259 'type': 'Number' 8260 }, 8261 { 8262 'name': 'rx', 8263 'description': '', 8264 'type': 'Number' 8265 }, 8266 { 8267 'name': 'ry', 8268 'description': '', 8269 'type': 'Number' 8270 }, 8271 { 8272 'name': 'rz', 8273 'description': '', 8274 'type': 'Number' 8275 }, 8276 { 8277 'name': 'angle', 8278 'description': '', 8279 'type': 'Number', 8280 'optional': true 8281 }, 8282 { 8283 'name': 'concentration', 8284 'description': '', 8285 'type': 'Number', 8286 'optional': true 8287 } 8288 ] 8289 } 8290 ] 8291 }, 8292 'noLights': { 8293 'name': 'noLights', 8294 'class': 'p5', 8295 'module': '3D' 8296 }, 8297 'loadModel': { 8298 'name': 'loadModel', 8299 'class': 'p5', 8300 'module': 'Shape', 8301 'overloads': [ 8302 { 8303 'params': [ 8304 { 8305 'name': 'path', 8306 'description': '<p>Path of the model to be loaded</p>\n', 8307 'type': 'String' 8308 }, 8309 { 8310 'name': 'normalize', 8311 'description': '<p>If true, scale the model to a\n standardized size when loading</p>\n', 8312 'type': 'Boolean' 8313 }, 8314 { 8315 'name': 'successCallback', 8316 'description': '<p>Function to be called\n once the model is loaded. Will be passed\n the 3D model object.</p>\n', 8317 'type': 'function(p5.Geometry)', 8318 'optional': true 8319 }, 8320 { 8321 'name': 'failureCallback', 8322 'description': '<p>called with event error if\n the model fails to load.</p>\n', 8323 'type': 'Function(Event)', 8324 'optional': true 8325 }, 8326 { 8327 'name': 'fileType', 8328 'description': '<p>The file extension of the model\n (<code>.stl</code>, <code>.obj</code>).</p>\n', 8329 'type': 'String', 8330 'optional': true 8331 } 8332 ] 8333 }, 8334 { 8335 'params': [ 8336 { 8337 'name': 'path', 8338 'description': '', 8339 'type': 'String' 8340 }, 8341 { 8342 'name': 'successCallback', 8343 'description': '', 8344 'type': 'function(p5.Geometry)', 8345 'optional': true 8346 }, 8347 { 8348 'name': 'failureCallback', 8349 'description': '', 8350 'type': 'Function(Event)', 8351 'optional': true 8352 }, 8353 { 8354 'name': 'fileType', 8355 'description': '', 8356 'type': 'String', 8357 'optional': true 8358 } 8359 ] 8360 } 8361 ] 8362 }, 8363 'model': { 8364 'name': 'model', 8365 'params': [ 8366 { 8367 'name': 'model', 8368 'description': '<p>Loaded 3d model to be rendered</p>\n', 8369 'type': 'p5.Geometry' 8370 } 8371 ], 8372 'class': 'p5', 8373 'module': 'Shape' 8374 }, 8375 'loadShader': { 8376 'name': 'loadShader', 8377 'params': [ 8378 { 8379 'name': 'vertFilename', 8380 'description': '<p>path to file containing vertex shader\nsource code</p>\n', 8381 'type': 'String' 8382 }, 8383 { 8384 'name': 'fragFilename', 8385 'description': '<p>path to file containing fragment shader\nsource code</p>\n', 8386 'type': 'String' 8387 }, 8388 { 8389 'name': 'callback', 8390 'description': '<p>callback to be executed after loadShader\ncompletes. On success, the p5.Shader object is passed as the first argument.</p>\n', 8391 'type': 'Function', 8392 'optional': true 8393 }, 8394 { 8395 'name': 'errorCallback', 8396 'description': '<p>callback to be executed when an error\noccurs inside loadShader. On error, the error is passed as the first\nargument.</p>\n', 8397 'type': 'Function', 8398 'optional': true 8399 } 8400 ], 8401 'class': 'p5', 8402 'module': '3D' 8403 }, 8404 'createShader': { 8405 'name': 'createShader', 8406 'params': [ 8407 { 8408 'name': 'vertSrc', 8409 'description': '<p>source code for the vertex shader</p>\n', 8410 'type': 'String' 8411 }, 8412 { 8413 'name': 'fragSrc', 8414 'description': '<p>source code for the fragment shader</p>\n', 8415 'type': 'String' 8416 } 8417 ], 8418 'class': 'p5', 8419 'module': '3D' 8420 }, 8421 'shader': { 8422 'name': 'shader', 8423 'params': [ 8424 { 8425 'name': 's', 8426 'description': '<p>the <a href="#/p5.Shader">p5.Shader</a> object\nto use for rendering shapes.</p>\n', 8427 'type': 'p5.Shader' 8428 } 8429 ], 8430 'class': 'p5', 8431
8431 'module': '3D' 8432 }, 8433 'resetShader': { 8434 'name': 'resetShader', 8435 'class': 'p5', 8436 'module': '3D' 8437 }, 8438 'texture': { 8439 'name': 'texture', 8440 'params': [ 8441 { 8442 'name': 'tex', 8443 'description': '<p>image to use as texture</p>\n', 8444 'type': 'p5.Image|p5.MediaElement|p5.Graphics|p5.Texture' 8445 } 8446 ], 8447 'class': 'p5', 8448 'module': '3D' 8449 }, 8450 'textureMode': { 8451 'name': 'textureMode', 8452 'params': [ 8453 { 8454 'name': 'mode', 8455 'description': '<p>either IMAGE or NORMAL</p>\n', 8456 'type': 'Constant' 8457 } 8458 ], 8459 'class': 'p5', 8460 'module': '3D' 8461 }, 8462 'textureWrap': { 8463 'name': 'textureWrap', 8464 'params': [ 8465 { 8466 'name': 'wrapX', 8467 'description': '<p>either CLAMP, REPEAT, or MIRROR</p>\n', 8468 'type': 'Constant' 8469 }, 8470 { 8471 'name': 'wrapY', 8472 'description': '<p>either CLAMP, REPEAT, or MIRROR</p>\n', 8473 'type': 'Constant', 8474 'optional': true 8475 } 8476 ], 8477 'class': 'p5', 8478 'module': '3D' 8479 }, 8480 'normalMaterial': { 8481 'name': 'normalMaterial', 8482 'class': 'p5', 8483 'module': '3D' 8484 }, 8485 'ambientMaterial': { 8486 'name': 'ambientMaterial', 8487 'class': 'p5', 8488 'module': '3D', 8489 'overloads': [ 8490 { 8491 'params': [ 8492 { 8493 'name': 'v1', 8494 'description': '<p>red or hue value relative to the current\n color range</p>\n', 8495 'type': 'Number' 8496 }, 8497 { 8498 'name': 'v2', 8499 'description': '<p>green or saturation value relative to the\n current color range</p>\n', 8500 'type': 'Number' 8501 }, 8502 { 8503 'name': 'v3', 8504 'description': '<p>blue or brightness value relative to the\n current color range</p>\n', 8505 'type': 'Number' 8506 } 8507 ], 8508 'chainable': 1 8509 }, 8510 { 8511 'params': [ 8512 { 8513 'name': 'gray', 8514 'description': '<p>number specifying value between\n white and black</p>\n', 8515 'type': 'Number' 8516 } 8517 ], 8518 'chainable': 1 8519 }, 8520 { 8521 'params': [ 8522 { 8523 'name': 'color', 8524 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a>,\n as an array, or as a CSS string</p>\n', 8525 'type': 'p5.Color|Number[]|String' 8526 } 8527 ], 8528 'chainable': 1 8529 } 8530 ] 8531 }, 8532 'emissiveMaterial': { 8533 'name': 'emissiveMaterial', 8534 'class': 'p5', 8535 'module': '3D', 8536 'overloads': [ 8537 { 8538 'params': [ 8539 { 8540 'name': 'v1', 8541 'description': '<p>red or hue value relative to the current\n color range</p>\n', 8542 'type': 'Number' 8543 }, 8544 { 8545 'name': 'v2', 8546 'description': '<p>green or saturation value relative to the\n current color range</p>\n', 8547 'type': 'Number' 8548 }, 8549 { 8550 'name': 'v3', 8551 'description': '<p>blue or brightness value relative to the\n current color range</p>\n', 8552 'type': 'Number' 8553 }, 8554 { 8555 'name': 'alpha', 8556 'description': '<p>alpha value relative to current color\n range (default is 0-255)</p>\n', 8557 'type': 'Number', 8558 'optional': true 8559 } 8560 ], 8561 'chainable': 1 8562 }, 8563 { 8564 'params': [ 8565 { 8566 'name': 'gray', 8567 'description': '<p>number specifying value between\n white and black</p>\n', 8568 'type': 'Number' 8569 } 8570 ], 8571 'chainable': 1 8572 }, 8573 { 8574 'params': [ 8575 { 8576 'name': 'color', 8577 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a>,\n as an array, or as a CSS string</p>\n', 8578 'type': 'p5.Color|Number[]|String' 8579 } 8580 ], 8581 'chainable': 1 8582 } 8583 ] 8584 }, 8585 'specularMaterial': { 8586 'name': 'specularMaterial', 8587 'class': 'p5', 8588 'module': '3D', 8589 'overloads': [ 8590 { 8591 'params': [ 8592 { 8593 'name': 'gray', 8594 'description': '<p>number specifying value between white and black.</p>\n', 8595 'type': 'Number' 8596 }, 8597 { 8598 'name': 'alpha', 8599 'description': '<p>alpha value relative to current color range\n (default is 0-255)</p>\n', 8600 'type': 'Number', 8601 'optional': true 8602 } 8603 ], 8604 'chainable': 1 8605 }, 8606 { 8607 'params': [ 8608 { 8609 'name': 'v1', 8610 'description': '<p>red or hue value relative to\n the current color range</p>\n', 8611 'type': 'Number' 8612 }, 8613 { 8614 'name': 'v2', 8615 'description': '<p>
8615green or saturation value\n relative to the current color range</p>\n', 8616 'type': 'Number' 8617 }, 8618 { 8619 'name': 'v3', 8620 'description': '<p>blue or brightness value\n relative to the current color range</p>\n', 8621 'type': 'Number' 8622 }, 8623 { 8624 'name': 'alpha', 8625 'description': '', 8626 'type': 'Number', 8627 'optional': true 8628 } 8629 ], 8630 'chainable': 1 8631 }, 8632 { 8633 'params': [ 8634 { 8635 'name': 'color', 8636 'description': '<p>color as a <a href="#/p5.Color">p5.Color</a>,\n as an array, or as a CSS string</p>\n', 8637 'type': 'p5.Color|Number[]|String' 8638 } 8639 ], 8640 'chainable': 1 8641 } 8642 ] 8643 }, 8644 'shininess': { 8645 'name': 'shininess', 8646 'params': [ 8647 { 8648 'name': 'shine', 8649 'description': '<p>degree of shininess</p>\n', 8650 'type': 'Number' 8651 } 8652 ], 8653 'class': 'p5', 8654 'module': '3D' 8655 }, 8656 'camera': { 8657 'name': 'camera', 8658 'params': [ 8659 { 8660 'name': 'x', 8661 'description': '<p>camera position value on x axis</p>\n', 8662 'type': 'Number', 8663 'optional': true 8664 }, 8665 { 8666 'name': 'y', 8667 'description': '<p>camera position value on y axis</p>\n', 8668 'type': 'Number', 8669 'optional': true 8670 }, 8671 { 8672 'name': 'z', 8673 'description': '<p>camera position value on z axis</p>\n', 8674 'type': 'Number', 8675 'optional': true 8676 }, 8677 { 8678 'name': 'centerX', 8679 'description': '<p>x coordinate representing center of the sketch</p>\n', 8680 'type': 'Number', 8681 'optional': true 8682 }, 8683 { 8684 'name': 'centerY', 8685 'description': '<p>y coordinate representing center of the sketch</p>\n', 8686 'type': 'Number', 8687 'optional': true 8688 }, 8689 { 8690 'name': 'centerZ', 8691 'description': '<p>z coordinate representing center of the sketch</p>\n', 8692 'type': 'Number', 8693 'optional': true 8694 }, 8695 { 8696 'name': 'upX', 8697 'description': '<p>x component of direction \'up\' from camera</p>\n', 8698 'type': 'Number', 8699 'optional': true 8700 }, 8701 { 8702 'name': 'upY', 8703 'description': '<p>y component of direction \'up\' from camera</p>\n', 8704 'type': 'Number', 8705 'optional': true 8706 }, 8707 { 8708 'name': 'upZ', 8709 'description': '<p>z component of direction \'up\' from camera</p>\n', 8710 'type': 'Number', 8711 'optional': true 8712 } 8713 ], 8714 'class': 'p5', 8715 'module': '3D' 8716 }, 8717 'perspective': { 8718 'name': 'perspective', 8719 'params': [ 8720 { 8721 'name': 'fovy', 8722 'description': '<p>camera frustum vertical field of view,\n from bottom to top of view, in <a href="#/p5/angleMode">angleMode</a> units</p>\n', 8723 'type': 'Number', 8724 'optional': true 8725 }, 8726 { 8727 'name': 'aspect', 8728 'description': '<p>camera frustum aspect ratio</p>\n', 8729 'type': 'Number', 8730 'optional': true 8731 }, 8732 { 8733 'name': 'near', 8734 'description': '<p>frustum near plane length</p>\n', 8735 'type': 'Number', 8736 'optional': true 8737 }, 8738 { 8739 'name': 'far', 8740 'description': '<p>frustum far plane length</p>\n', 8741 'type': 'Number', 8742 'optional': true 8743 } 8744 ], 8745 'class': 'p5', 8746 'module': '3D' 8747 }, 8748 'ortho': { 8749 'name': 'ortho', 8750 'params': [ 8751 { 8752 'name': 'left', 8753 'description': '<p>camera frustum left plane</p>\n', 8754 'type': 'Number', 8755 'optional': true 8756 }, 8757 { 8758 'name': 'right', 8759 'description': '<p>camera frustum right plane</p>\n', 8760 'type': 'Number', 8761 'optional': true 8762 }, 8763 { 8764 'name': 'bottom', 8765 'description': '<p>camera frustum bottom plane</p>\n', 8766 'type': 'Number', 8767 'optional': true 8768 }, 8769 { 8770 'name': 'top', 8771 'description': '<p>camera frustum top plane</p>\n', 8772 'type': 'Number', 8773 'optional': true 8774 }, 8775 { 8776 'name': 'near', 8777 'description': '<p>camera frustum near plane</p>\n', 8778 'type': 'Number', 8779 'optional': true 8780 }, 8781 { 8782 'name': 'far', 8783 'description': '<p>camera frustum far plane</p>\n', 8784 'type': 'Number', 8785 'optional': true 8786 } 8787 ], 8788 'class': 'p5', 8789 'module': '3D' 8790 }, 8791 'frustum': { 8792 'name': 'frustum', 8793 'params': [ 8794 { 8795 'name': 'left', 8796 'description': '<p>camera frustum left plane</p>\n', 8797 'type': 'Number', 8798 'optional': true 8799 }, 8800 { 8801 'name': 'right', 8802 'description': '<p>camera frustum right plane</p>\n', 8803 'type': 'Number', 8804 'optional': true 8805 }, 8806 { 8807 'name': 'bottom', 8808 'description': '<p>camera frustum bottom plane</p>\n', 8809 'type': 'Number', 8810 'optional': true 8811 }, 8812 { 8813 'name': 'top', 8814 'description': '<p>camera frustum top plane</p>\n', 8815 'type': 'Number', 8816 'optional': true 8817 }, 8818 { 8819 'name': 'near', 8820 'description': '<p>camera frustum near plane</p>\n', 8821 'type': 'Number', 8822 'optional': true 8823 }, 8824 { 8825 'name': 'far', 8826 'description': '<p>camera frustum far plane</p>\n', 8827 'type': 'Number', 8828 'optional': true 8829 } 8830 ], 8831 'class': 'p5', 8832 'module': '3D' 8833 }, 8834 'createCamera': { 8835 'name': 'createCamera', 8836 'class': 'p5', 8837 'module': '3D' 8838 }, 8839 'setCamera': { 8840 'name': 'setCamera', 8841 'params': [ 8842 { 8843 'name': 'cam', 8844 'description': '<p>p5.Camera object</p>\n', 8845 'type': 'p5.Camera' 8846 } 8847 ], 8848 'class': 'p5', 8849 'module': '3D' 8850 }, 8851 'setAttributes': { 8852 'name': 'setAttributes', 8853 'class': 'p5', 8854 'module': 'Rendering', 8855 'overloads': [ 8856 { 8857 'params': [ 8858 { 8859 'name': 'key', 8860 'description': '<p>Name of attribute</p>\n', 8861 'type': 'String' 8862 }, 8863 { 8864 'name': 'value', 8865 'description': '<p>New value of named attribute</p>\n', 8866 'type': 'Boolean' 8867 } 8868 ] 8869 }, 8870 { 8871 'params': [ 8872 { 8873 'name': 'obj', 8874 'description': '<p>object with key-value pairs</p>\n', 8875 'type': 'Object' 8876 } 8877 ] 8878 } 8879 ] 8880 }, 8881 'getAudioContext': { 8882 'name': 'getAudioContext', 8883 'class': 'p5', 8884 'module': 'p5.sound' 8885 }, 8886 'userStartAudio': { 8887 'params': [ 8888 { 8889 'name': 'elements', 8890 'description': '<p>This argument can be an Element,\n Selector String, NodeList, p5.Element,\n jQuery Element, or an Array of any of those.</p>\n', 8891 'type': 'Element|Array', 8892 'optional': true 8893 }, 8894 { 8895 'name': 'callback', 8896 'description': '<p>Callback to invoke when the AudioContext\n has started</p>\n', 8897 'type': 'Function', 8898 'optional': true 8899 } 8900 ], 8901 'name': 'userStartAudio', 8902 'class': 'p5', 8903 'module': 'p5.sound' 8904 }, 8905 'getOutputVolume': { 8906 'name': 'getOutputVolume', 8907 'class': 'p5', 8908 'module': 'p5.sound' 8909 }, 8910 'outputVolume': { 8911 'name': 'outputVolume', 8912 'params': [ 8913 { 8914 'name': 'volume', 8915 'description': '<p>Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator</p>\n', 8916 'type': 'Number|Object' 8917 }, 8918 { 8919 'name': 'rampTime', 8920 'description': '<p>Fade for t seconds</p>\n', 8921 'type': 'Number', 8922 'optional': true 8923 }, 8924 { 8925 'name': 'timeFromNow', 8926 'description': '<p>Schedule this event to happen at\n t seconds
8926in the future</p>\n', 8927 'type': 'Number', 8928 'optional': true 8929 } 8930 ], 8931 'class': 'p5', 8932 'module': 'p5.sound' 8933 }, 8934 'soundOut': { 8935 'name': 'soundOut', 8936 'class': 'p5', 8937 'module': 'p5.sound' 8938 }, 8939 'sampleRate': { 8940 'name': 'sampleRate', 8941 'class': 'p5', 8942 'module': 'p5.sound' 8943 }, 8944 'freqToMidi': { 8945 'name': 'freqToMidi', 8946 'params': [ 8947 { 8948 'name': 'frequency', 8949 'description': '<p>A freqeuncy, for example, the "A"\n above Middle C is 440Hz</p>\n', 8950 'type': 'Number' 8951 } 8952 ], 8953 'class': 'p5', 8954 'module': 'p5.sound' 8955 }, 8956 'midiToFreq': { 8957 'name': 'midiToFreq', 8958 'params': [ 8959 { 8960 'name': 'midiNote', 8961 'description': '<p>The number of a MIDI note</p>\n', 8962 'type': 'Number' 8963 } 8964 ], 8965 'class': 'p5', 8966 'module': 'p5.sound' 8967 }, 8968 'soundFormats': { 8969 'name': 'soundFormats', 8970 'params': [ 8971 { 8972 'name': 'formats', 8973 'description': '<p>i.e. \'mp3\', \'wav\', \'ogg\'</p>\n', 8974 'type': 'String', 8975 'optional': true, 8976 'multiple': true 8977 } 8978 ], 8979 'class': 'p5', 8980 'module': 'p5.sound' 8981 }, 8982 'saveSound': { 8983 'name': 'saveSound', 8984 'params': [ 8985 { 8986 'name': 'soundFile', 8987 'description': '<p>p5.SoundFile that you wish to save</p>\n', 8988 'type': 'p5.SoundFile' 8989 }, 8990 { 8991 'name': 'fileName', 8992 'description': '<p>name of the resulting .wav file.</p>\n', 8993 'type': 'String' 8994 } 8995 ], 8996 'class': 'p5', 8997 'module': 'p5.sound' 8998 }, 8999 'loadSound': { 9000 'name': 'loadSound', 9001 'params': [ 9002 { 9003 'name': 'path', 9004 'description': '<p>Path to the sound file, or an array with\n paths to soundfiles in multiple formats\n i.e. [\'sound.ogg\', \'sound.mp3\'].\n Alternately, accepts an object: either\n from the HTML5 File API, or a p5.File.</p>\n', 9005 'type': 'String|Array' 9006 }, 9007 { 9008 'name': 'successCallback', 9009 'description': '<p>Name of a function to call once file loads</p>\n', 9010 'type': 'Function', 9011 'optional': true 9012 }, 9013 { 9014 'name': 'errorCallback', 9015 'description': '<p>Name of a function to call if there is\n an error loading the file.</p>\n', 9016 'type': 'Function', 9017 'optional': true 9018 }, 9019 { 9020 'name': 'whileLoading', 9021 'description': '<p>Name of a function to call while file is loading.\n This function will receive the percentage loaded\n so far, from 0.0 to 1.0.</p>\n', 9022 'type': 'Function', 9023 'optional': true 9024 } 9025 ], 9026 'class': 'p5', 9027 'module': 'p5.sound' 9028 }, 9029 'createConvolver': { 9030 'name': 'createConvolver', 9031 'params': [ 9032 { 9033 'name': 'path', 9034 'description': '<p>
9034path to a sound file</p>\n', 9035 'type': 'String' 9036 }, 9037 { 9038 'name': 'callback', 9039 'description': '<p>function to call if loading is successful.\n The object will be passed in as the argument\n to the callback function.</p>\n', 9040 'type': 'Function', 9041 'optional': true 9042 }, 9043 { 9044 'name': 'errorCallback', 9045 'description': '<p>function to call if loading is not successful.\n A custom error will be passed in as the argument\n to the callback function.</p>\n', 9046 'type': 'Function', 9047 'optional': true 9048 } 9049 ], 9050 'class': 'p5', 9051 'module': 'p5.sound' 9052 }, 9053 'setBPM': { 9054 'name': 'setBPM', 9055 'params': [ 9056 { 9057 'name': 'BPM', 9058 'description': '<p>Beats Per Minute</p>\n', 9059 'type': 'Number' 9060 }, 9061 { 9062 'name': 'rampTime', 9063 'description': '<p>Seconds from now</p>\n', 9064 'type': 'Number' 9065 } 9066 ], 9067 'class': 'p5', 9068 'module': 'p5.sound' 9069 } 9070 }, 9071 'p5.Color': { 9072 'toString': { 9073 'name': 'toString', 9074 'params': [ 9075 { 9076 'name': 'format', 9077 'description': '<p>How the color string will be formatted.\nLeaving this empty formats the string as rgba(r, g, b, a).\n\'#rgb\' \'#rgba\' \'#rrggbb\' and \'#rrggbbaa\' format as hexadecimal color codes.\n\'rgb\' \'hsb\' and \'hsl\' return the color formatted in the specified color mode.\n\'rgba\' \'hsba\' and \'hsla\' are the same as above but with alpha channels.\n\'rgb%\' \'hsb%\' \'hsl%\' \'rgba%\' \'hsba%\' and \'hsla%\' format as percentages.</p>\n', 9078 'type': 'String', 9079 'optional': true 9080 } 9081 ], 9082 'class': 'p5.Color', 9083 'module': 'Color' 9084 }, 9085 'setRed': { 9086 'name': 'setRed', 9087 'params': [ 9088 { 9089 'name': 'red', 9090 'description': '<p>the new red value</p>\n', 9091 'type': 'Number' 9092 } 9093 ], 9094 'class': 'p5.Color', 9095 'module': 'Color' 9096 }, 9097 'setGreen': { 9098 'name': 'setGreen', 9099 'params': [ 9100 { 9101 'name': 'green', 9102 'description': '<p>the new green value</p>\n', 9103 'type': 'Number' 9104 } 9105 ], 9106 'class': 'p5.Color', 9107 'module': 'Color' 9108 }, 9109 'setBlue': { 9110 'name': 'setBlue', 9111 'params': [ 9112 { 9113 'name': 'blue', 9114 'description': '<p>the new blue value</p>\n', 9115 'type': 'Number' 9116 } 9117 ], 9118 'class': 'p5.Color', 9119 'module': 'Color' 9120 }, 9121 'setAlpha': { 9122 'name': 'setAlpha', 9123 'params': [ 9124 { 9125 'name': 'alpha', 9126 'description': '<p>the new alpha value</p>\n', 9127 'type': 'Number' 9128 } 9129 ], 9130 'class': 'p5.Color', 9131 'module': 'Color' 9132 } 9133 }, 9134 'p5.Element': { 9135 'elt': { 9136 'name': 'elt', 9137 'class': 'p5.Element', 9138 'module': 'DOM' 9139 }, 9140 'parent': { 9141 'name': 'parent', 9142 'class': 'p5.Element', 9143 'module': 'DOM', 9144 'overloads': [ 9145 { 9146 'params': [ 9147 { 9148 'name': 'parent', 9149 'description': '<p>the ID, DOM node, or <a href="#/p5.Element">p5.Element</a>\n of desired parent element</p>\n',
9150 'type': 'String|p5.Element|Object' 9151 } 9152 ], 9153 'chainable': 1 9154 }, 9155 { 9156 'params': [ 9157 ] 9158 } 9159 ] 9160 }, 9161 'id': { 9162 'name': 'id', 9163 'class': 'p5.Element', 9164 'module': 'DOM', 9165 'overloads': [ 9166 { 9167 'params': [ 9168 { 9169 'name': 'id', 9170 'description': '<p>ID of the element</p>\n', 9171 'type': 'String' 9172 } 9173 ], 9174 'chainable': 1 9175 }, 9176 { 9177 'params': [ 9178 ] 9179 } 9180 ] 9181 }, 9182 'class': { 9183 'name': 'class', 9184 'class': 'p5.Element', 9185 'module': 'DOM', 9186 'overloads': [ 9187 { 9188 'params': [ 9189 { 9190 'name': 'class', 9191 'description': '<p>class to add</p>\n', 9192 'type': 'String' 9193 } 9194 ], 9195 'chainable': 1 9196 }, 9197 { 9198 'params': [ 9199 ] 9200 } 9201 ] 9202 }, 9203 'mousePressed': { 9204 'name': 'mousePressed', 9205 'params': [ 9206 { 9207 'name': 'fxn', 9208 'description': '<p>function to be fired when mouse is\n pressed over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9209 'type': 'Function|Boolean' 9210 } 9211 ], 9212 'class': 'p5.Element', 9213 'module': 'DOM' 9214 }, 9215 'doubleClicked': { 9216 'name': 'doubleClicked', 9217 'params': [ 9218 { 9219 'name': 'fxn', 9220 'description': '<p>function to be fired when mouse is\n double clicked over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9221 'type': 'Function|Boolean' 9222 } 9223 ], 9224 'class': 'p5.Element', 9225 'module': 'DOM' 9226 }, 9227 'mouseWheel': { 9228 'name': 'mouseWheel', 9229 'params': [ 9230 { 9231 'name': 'fxn', 9232 'description': '<p>function to be fired when mouse is\n scrolled over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9233 'type': 'Function|Boolean' 9234 } 9235 ], 9236 'class': 'p5.Element', 9237 'module': 'DOM' 9238 }, 9239 'mouseReleased': { 9240 'name': 'mouseReleased', 9241 'params': [ 9242 { 9243 'name': 'fxn', 9244 'description': '<p>function to be fired when mouse is\n released over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9245 'type': 'Function|Boolean' 9246 } 9247 ], 9248 'class': 'p5.Element', 9249 'module': 'DOM' 9250 }, 9251 'mouseClicked': { 9252 'name': 'mouseClicked', 9253 'params': [ 9254 { 9255 'name': 'fxn', 9256 'description': '<p>function to be fired when mouse is\n clicked over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9257 'type': 'Function|Boolean' 9258 } 9259 ], 9260 'class': 'p5.Element', 9261 'module': 'DOM' 9262 }, 9263 'mouseMoved': { 9264 'name': 'mouseMoved', 9265 'params': [ 9266 { 9267 'name': 'fxn', 9268 'description': '<p>function to be fired when a mouse moves\n over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9269 'type': 'Function|Boolean' 9270 } 9271 ], 9272 'class': 'p5.Element', 9273 'module': 'DOM' 9274 }, 9275 'mouseOver': { 9276 'name': 'mouseOver', 9277 'params': [ 9278 { 9279 'name': 'fxn', 9280 'description': '<p>function to be fired when a mouse moves\n onto the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9281 'type': 'Function|Boolean' 9282 } 9283 ], 9284 'class': 'p5.Element', 9285 'module': 'DOM' 9286 }, 9287 'mouseOut': { 9288 'name': 'mouseOut', 9289 'params': [ 9290 { 9291 'name': 'fxn', 9292 'description': '<p>function to be fired when a mouse\n moves off of an element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9293 'type': 'Function|Boolean' 9294 } 9295 ], 9296 'class': 'p5.Element', 9297 'module': 'DOM' 9298 }, 9299 'touchStarted': { 9300 'name': 'touchStarted', 9301 'params': [ 9302 { 9303 'name': 'fxn', 9304 'description': '<p>function to be fired when a touch\n starts over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9305 'type': 'Function|Boolean' 9306 } 9307 ], 9308 'class': 'p5.Element', 9309 'module': 'DOM' 9310 }, 9311 'touchMoved': { 9312 'name': 'touchMoved', 9313 'params': [ 9314 { 9315 'name': 'fxn', 9316 'description': '<p>function to be fired when a touch moves over\n the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9317 'type': 'Function|Boolean' 9318 } 9319 ], 9320 'class': 'p5.Element', 9321 'module': 'DOM' 9322 }, 9323 'touchEnded': { 9324 'name': 'touchEnded', 9325 'params': [ 9326 { 9327 'name': 'fxn', 9328 'description': '<p>function to be fired when a touch ends\n over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9329 'type': 'Function|Boolean' 9330 } 9331 ], 9332 'class': 'p5.Element', 9333 'module': 'DOM' 9334 }, 9335 'dragOver': { 9336 'name': 'dragOver', 9337 'params': [ 9338 { 9339 'name': 'fxn', 9340 'description': '<p>function to be fired when a file is\n dragged over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9341 'type': 'Function|Boolean' 9342 } 9343 ], 9344 'class': 'p5.Element', 9345 'module': 'DOM' 9346 }, 9347 'dragLeave': { 9348 'name': 'dragLeave', 9349 'params': [ 9350 { 9351 'name': 'fxn', 9352 'description': '<p>function to be fired when a file is\n dragged off the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n', 9353 'type': 'Function|Boolean' 9354 } 9355 ], 9356 'class': 'p5.Element', 9357 'module': 'DOM' 9358 }, 9359 'addClass': { 9360 'name': 'addClass', 9361 'params': [ 9362 { 9363 'name': 'class', 9364 'description': '<p>name of class to add</p>\n', 9365 'type': 'String' 9366 } 9367 ], 9368 'class': 'p5.Element', 9369 'module': 'DOM' 9370 }, 9371 'removeClass': { 9372 'name': 'removeClass', 9373 'params': [ 9374 { 9375 'name': 'class', 9376 'description': '<p>name of class to remove</p>\n', 9377 'type': 'String' 9378 } 9379 ], 9380 'class': 'p5.Element', 9381 'module': 'DOM' 9382 }, 9383 'hasClass': { 9384 'name': 'hasClass', 9385 'params': [ 9386 { 9387 'name': 'c', 9388 'description': '<p>class name of class to check</p>\n', 9389 'type': 'String' 9390 } 9391 ], 9392 'class': 'p5.Element', 9393 'module': 'DOM' 9394 }, 9395 'toggleClass': { 9396 'name': 'toggleClass', 9397 'params': [ 9398 { 9399 'name': 'c', 9400 'description': '<p>class name to toggle</p>\n', 9401 'type': 'String' 9402 } 9403 ], 9404 'class': 'p5.Element', 9405 'module': 'DOM' 9406 }, 9407 'child': { 9408 'name': 'child', 9409 'class': 'p5.Element', 9410 'module': 'DOM', 9411 'overloads': [ 9412 { 9413 'params': [ 9414 ] 9415 }, 9416 { 9417 'params': [ 9418 { 9419 'name': 'child', 9420 'description': '<p>the ID, DOM node, or <a href="#/p5.Element">p5.Element</a>\n to add to the current element</p>\n', 9421 'type': 'String|p5.Element', 9422 'optional': true 9423 } 9424 ], 9425 'chainable': 1 9426 } 9427 ] 9428 }, 9429 'center': { 9430 'name': 'center', 9431 'params': [ 9432 { 9433 'name': 'align', 9434 'description': '<p>passing \'vertical\', \'horizontal\' aligns element accordingly</p>\n', 9435 'type': 'String', 9436 'optional': true 9437 } 9438 ], 9439 'class': 'p5.Element', 9440 'module': 'DOM' 9441 }, 9442 'html': { 9443 'name': 'html', 9444 'class': 'p5.Element', 9445 'module': 'DOM', 9446 'overloads': [ 9447 { 9448 'params': [ 9449 ] 9450 }, 9451 { 9452 'params': [ 9453 { 9454 'name': 'html', 9455 'description': '<p>the HTML to be placed inside the element</p>\n', 9456 'type': 'String', 9457 'optional': true 9458 }, 9459 { 9460 'name': 'append', 9461 'description': '<p>whether to append HTML to existing</p>\n', 9462 'type': 'Boolean', 9463 'optional': true 9464 } 9465 ], 9466 'chainable': 1 9467 } 9468 ] 9469 }, 9470 'position': { 9471 'name': 'position', 9472 'class': 'p5.Element', 9473 'module': 'DOM', 9474 'overloads': [ 9475 { 9476 'params': [ 9477 ] 9478 }, 9479 { 9480 'params': [ 9481 { 9482 'name': 'x', 9483 'description': '<p>x-position relative to upper left of window (optional)</p>\n', 9484 'type': 'Number', 9485 'optional': true 9486 }, 9487 { 9488 'name': 'y', 9489 'description': '<p>y-position relative to upper left of window (optional)</p>\n', 9490 'type': 'Number', 9491 'optional': true 9492 }, 9493 { 9494 'name': 'positionType', 9495 'description': '<p>it can be static, fixed, relative, sticky, initial or inherit (optional)</p>\n', 9496 'type': 'String', 9497 'optional': true 9498 } 9499 ], 9500 'chainable': 1 9501 } 9502 ] 9503 }, 9504 'style': { 9505 'name': 'style', 9506 'class': 'p5.Element', 9507 'module': 'DOM', 9508 'overloads': [ 9509 { 9510 'params': [ 9511 { 9512 'name': 'property', 9513 'description': '<p>property to be set</p>\n', 9514 'type': 'String' 9515 } 9516 ] 9517 }, 9518 { 9519 'params': [ 9520 { 9521 'name': 'property', 9522 'description': '', 9523 'type': 'String' 9524 }, 9525 { 9526 'name': 'value', 9527 'description': '<p>value to assign to property</p>\n', 9528 'type': 'String|p5.Color' 9529 } 9530 ], 9531 'chainable': 1 9532 } 9533 ] 9534 }, 9535 'attribute': { 9536 'name': 'attribute', 9537 'class': 'p5.Element', 9538 'module': 'DOM', 9539 'overloads': [ 9540 { 9541 'params': [ 9542 ] 9543 }, 9544 { 9545 'params': [ 9546 { 9547 'name': 'attr', 9548 'description': '<p>attribute to set</p>\n', 9549 'type': 'String' 9550 }, 9551 { 9552 'name': 'value', 9553 'description': '<p>value to assign to attribute</p>\n', 9554 'type': 'String' 9555 } 9556 ], 9557 'chainable': 1 9558 } 9559 ] 9560 }, 9561 'removeAttribute': { 9562 'name': 'removeAttribute', 9563 'params': [ 9564 { 9565 'name': 'attr', 9566 'description': '<p>attribute to remove</p>\n', 9567 'type': 'String' 9568 } 9569 ], 9570 'class': 'p5.Element', 9571 'module': 'DOM' 9572 }, 9573 'value': { 9574 'name': 'value', 9575 'class': 'p5.Element', 9576 'module': 'DOM', 9577 'overloads': [ 9578 { 9579 'params': [ 9580 ] 9581 }, 9582 { 9583 'params': [ 9584 { 9585 'name': 'value', 9586 'description':
9586'', 9587 'type': 'String|Number' 9588 } 9589 ], 9590 'chainable': 1 9591 } 9592 ] 9593 }, 9594 'show': { 9595 'name': 'show', 9596 'class': 'p5.Element', 9597 'module': 'DOM' 9598 }, 9599 'hide': { 9600 'name': 'hide', 9601 'class': 'p5.Element', 9602 'module': 'DOM' 9603 }, 9604 'size': { 9605 'name': 'size', 9606 'class': 'p5.Element', 9607 'module': 'DOM', 9608 'overloads': [ 9609 { 9610 'params': [ 9611 ] 9612 }, 9613 { 9614 'params': [ 9615 { 9616 'name': 'w', 9617 'description': '<p>width of the element, either AUTO, or a number</p>\n', 9618 'type': 'Number|Constant' 9619 }, 9620 { 9621 'name': 'h', 9622 'description': '<p>height of the element, either AUTO, or a number</p>\n', 9623 'type': 'Number|Constant', 9624 'optional': true 9625 } 9626 ], 9627 'chainable': 1 9628 } 9629 ] 9630 }, 9631 'remove': { 9632 'name': 'remove', 9633 'class': 'p5.Element', 9634 'module': 'DOM' 9635 }, 9636 'drop': { 9637 'name': 'drop', 9638 'params': [ 9639 { 9640 'name': 'callback', 9641 'description': '<p>callback to receive loaded file, called for each file dropped.</p>\n', 9642 'type': 'Function' 9643 }, 9644 { 9645 'name': 'fxn', 9646 'description': '<p>callback triggered once when files are dropped with the drop event.</p>\n', 9647 'type': 'Function', 9648 'optional': true 9649 } 9650 ], 9651 'class': 'p5.Element', 9652 'module': 'DOM' 9653 } 9654 }, 9655 'p5.Graphics': { 9656 'reset': { 9657 'name': 'reset', 9658 'class': 'p5.Graphics', 9659 'module': 'Rendering' 9660 }, 9661 'remove': { 9662 'name': 'remove', 9663 'class': 'p5.Graphics', 9664 'module': 'Rendering' 9665 } 9666 }, 9667 'JSON': { 9668 'stringify': { 9669 'name': 'stringify', 9670 'params': [ 9671 { 9672 'name': 'object', 9673 'description': '<p>:Javascript object that you would like to convert to JSON</p>\n', 9674 'type': 'Object' 9675 } 9676 ], 9677 'class': 'JSON', 9678 'module': 'Foundation' 9679 } 9680 }, 9681 'console': { 9682 'log': { 9683 'name': 'log', 9684 'params': [ 9685 { 9686 'name': 'message', 9687 'description': '<p>:Message that you would like to print to the console</p>\n', 9688 'type': 'String|Expression|Object' 9689 } 9690 ], 9691 'class': 'console', 9692 'module': 'Foundation' 9693 } 9694 }, 9695 'p5.TypedDict': { 9696 'size': { 9697 'name': 'size', 9698 'class': 'p5.TypedDict', 9699 'module': 'Data' 9700 }, 9701 'hasKey': { 9702 'name': 'hasKey', 9703 'params': [ 9704 { 9705 'name': 'key', 9706 'description': '<p>that you want to look up</p>\n', 9707 'type': 'Number|String' 9708 } 9709 ], 9710 'class': 'p5.TypedDict', 9711 'module': 'Data' 9712 }, 9713 'get': { 9714 'name': 'get', 9715 'params': [ 9716 { 9717 'name': 'the', 9718 'description': '<p>key you want to access</p>\n', 9719 'type': 'Number|String' 9720 } 9721 ], 9722 'class': 'p5.TypedDict', 9723 'module': 'Data' 9724 }, 9725 'set': { 9726 'name': 'set', 9727 'params': [ 9728 { 9729 'name': 'key', 9730 'description': '', 9731 'type': 'Number|String' 9732 }, 9733 { 9734 'name': 'value', 9735 'description': '', 9736 'type': 'Number|String' 9737 } 9738 ], 9739 'class': 'p5.TypedDict', 9740 'module': 'Data' 9741 }, 9742 'create': { 9743 'name': 'create', 9744 'class': 'p5.TypedDict', 9745 'module': 'Data', 9746 'overloads': [ 9747 { 9748 'params': [ 9749 { 9750 'name': 'key', 9751 'description': '', 9752 'type': 'Number|String' 9753 }, 9754 { 9755 'name': 'value', 9756 'description': '', 9757 'type': 'Number|String' 9758 } 9759 ] 9760 }, 9761 { 9762 'params': [ 9763 { 9764 'name': 'obj', 9765 'description': '<p>key/value pair</p>\n', 9766 'type': 'Object' 9767 } 9768 ] 9769 } 9770 ] 9771 }, 9772 'clear': { 9773 'name': 'clear', 9774 'class': 'p5.TypedDict', 9775 'module': 'Data' 9776 }, 9777 'remove': { 9778 'name': 'remove', 9779 'params': [ 9780 { 9781 'name': 'key', 9782 'description': '<p>for the pair to remove</p>\n', 9783 'type': 'Number|String' 9784 } 9785 ], 9786 'class': 'p5.TypedDict', 9787 'module': 'Data' 9788 }, 9789 'print': { 9790 'name': 'print', 9791 'class': 'p5.TypedDict', 9792 'module': 'Data' 9793 },
9794 'saveTable': { 9795 'name': 'saveTable', 9796 'class': 'p5.TypedDict', 9797 'module': 'Data' 9798 }, 9799 'saveJSON': { 9800 'name': 'saveJSON', 9801 'class': 'p5.TypedDict', 9802 'module': 'Data' 9803 } 9804 }, 9805 'p5.NumberDict': { 9806 'add': { 9807 'name': 'add', 9808 'params': [ 9809 { 9810 'name': 'Key', 9811 'description': '<p>for the value you wish to add to</p>\n', 9812 'type': 'Number' 9813 }, 9814 { 9815 'name': 'Number', 9816 'description': '<p>to add to the value</p>\n', 9817 'type': 'Number' 9818 } 9819 ], 9820 'class': 'p5.NumberDict', 9821 'module': 'Data' 9822 }, 9823 'sub': { 9824 'name': 'sub', 9825 'params': [ 9826 { 9827 'name': 'Key', 9828 'description': '<p>for the value you wish to subtract from</p>\n', 9829 'type': 'Number' 9830 }, 9831 { 9832 'name': 'Number', 9833 'description': '<p>to subtract from the value</p>\n', 9834 'type': 'Number' 9835 } 9836 ], 9837 'class': 'p5.NumberDict', 9838 'module': 'Data' 9839 }, 9840 'mult': { 9841 'name': 'mult', 9842 'params': [ 9843 { 9844 'name': 'Key', 9845 'description': '<p>for value you wish to multiply</p>\n', 9846 'type': 'Number' 9847 }, 9848 { 9849 'name': 'Amount', 9850 'description': '<p>to multiply the value by</p>\n', 9851 'type': 'Number' 9852 } 9853 ], 9854 'class': 'p5.NumberDict', 9855 'module': 'Data' 9856 }, 9857 'div': { 9858 'name': 'div', 9859 'params': [ 9860 { 9861 'name': 'Key', 9862 'description': '<p>for value you wish to divide</p>\n', 9863 'type': 'Number' 9864 }, 9865 { 9866 'name': 'Amount', 9867 'description': '<p>to divide the value by</p>\n', 9868 'type': 'Number' 9869 } 9870 ], 9871 'class': 'p5.NumberDict', 9872 'module': 'Data' 9873 }, 9874 'minValue': { 9875 'name': 'minValue', 9876 'class': 'p5.NumberDict', 9877 'module': 'Data' 9878 }, 9879 'maxValue': { 9880 'name': 'maxValue', 9881 'class': 'p5.NumberDict', 9882 'module': 'Data' 9883 }, 9884 'minKey': { 9885 'name': 'minKey', 9886 'class': 'p5.NumberDict', 9887 'module': 'Data' 9888 }, 9889 'maxKey': { 9890 'name': 'maxKey', 9891 'class': 'p5.NumberDict', 9892 'module': 'Data' 9893 } 9894 }, 9895 'p5.MediaElement': { 9896 'src': { 9897 'name': 'src', 9898 'class': 'p5.MediaElement', 9899 'module': 'DOM' 9900 }, 9901 'play': { 9902 'name': 'play', 9903 'class': 'p5.MediaElement', 9904 'module': 'DOM' 9905 }, 9906 'stop': { 9907 'name': 'stop', 9908 'class': 'p5.MediaElement', 9909 'module': 'DOM' 9910 }, 9911 'pause': { 9912 'name': 'pause', 9913 'class': 'p5.MediaElement', 9914 'module': 'DOM' 9915 }, 9916 'loop': { 9917 'name': 'loop', 9918 'class': 'p5.MediaElement', 9919 'module': 'DOM' 9920 }, 9921 'noLoop': { 9922 'name': 'noLoop', 9923 'class': 'p5.MediaElement', 9924 'module': 'DOM' 9925 }, 9926 'autoplay': { 9927 'name': 'autoplay', 9928 'params': [ 9929 { 9930 'name': 'shouldAutoplay', 9931 'description': '<p>whether the element should autoplay</p>\n', 9932 'type': 'Boolean' 9933 } 9934 ], 9935 'class': 'p5.MediaElement', 9936 'module': 'DOM' 9937 }, 9938 'volume': { 9939 'name': 'volume', 9940 'class': 'p5.MediaElement', 9941 'module': 'DOM', 9942 'overloads': [ 9943 { 9944 'params': [ 9945 ] 9946 }, 9947 { 9948 'params': [ 9949 { 9950 'name': 'val', 9951 'description': '<p>volume between 0.0 and 1.0</p>\n', 9952 'type': 'Number' 9953 } 9954 ], 9955 'chainable': 1 9956 } 9957 ] 9958 }, 9959 'speed': { 9960 'name': 'speed', 9961 'class': 'p5.MediaElement', 9962 'module': 'DOM', 9963 'overloads': [ 9964 { 9965 'params': [ 9966 ] 9967 }, 9968 { 9969 'params': [ 9970 { 9971 'name': 'speed', 9972 'description': '<p>speed multiplier for element playback</p>\n', 9973 'type': 'Number' 9974 } 9975 ], 9976 'chainable': 1 9977 } 9978 ] 9979 }, 9980 'time': { 9981 'name': 'time', 9982 'class': 'p5.MediaElement', 9983 'module': 'DOM', 9984 'overloads': [ 9985 { 9986 'params': [ 9987 ] 9988 }, 9989 { 9990 'params': [ 9991 { 9992 'name': 'time', 9993 'description': '<p>time to jump to (in seconds)</p>\n', 9994 'type': 'Number' 9995 } 9996 ], 9997 'chainable': 1 9998 } 9999 ] 10000 }, 10001 'duration': { 10002 'name': 'duration', 10003 'class': 'p5.MediaElement', 10004 'module': 'DOM' 10005 }, 10006 'onended': { 10007 'name': 'onended', 10008 'params': [ 10009 { 10010 'name': 'callback', 10011 'description': '<p>function to call when the\n soundfile has ended. The\n media element will be passed\n in as the argument to the\n callback.</p>\n', 10012 'type': 'Function' 10013 } 10014 ], 10015 'class': 'p5.MediaElement', 10016 'module': 'DOM' 10017 }, 10018 'connect': { 10019 'name': 'connect', 10020 'params': [ 10021 { 10022 'name': 'audioNode', 10023 'description': '<p>AudioNode from the Web Audio API,\nor an object from the p5.sound library</p>\n', 10024 'type': 'AudioNode|Object' 10025 } 10026 ], 10027 'class': 'p5.MediaElement', 10028 'module': 'DOM' 10029 }, 10030 'disconnect': { 10031 'name': 'disconnect', 10032 'class': 'p5.MediaElement', 10033 'module': 'DOM' 10034 }, 10035 'showControls': { 10036 'name': 'showControls', 10037 'class': 'p5.MediaElement', 10038 'module': 'DOM' 10039 }, 10040 'hideControls': { 10041 'name': 'hideControls', 10042 'class': 'p5.MediaElement', 10043 'module': 'DOM' 10044 }, 10045 'addCue': { 10046 'name': 'addCue', 10047 'params': [ 10048 { 10049 'name': 'time', 10050 'description': '<p>Time in seconds, relative to this media\n element\'s playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.</p>\n', 10051 'type': 'Number' 10052 }, 10053 { 10054 'name': 'callback', 10055 'description': '<p>Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.</p>\n', 10056 'type': 'Function' 10057 }, 10058 { 10059 'name': 'value', 10060 'description': '<p>An object to be passed as the\n second parameter to the\n callback function.</p>\n', 10061 'type': 'Object', 10062 'optional': true 10063 } 10064 ], 10065 'class': 'p5.MediaElement', 10066 'module': 'DOM' 10067 }, 10068 'removeCue': { 10069 'name': 'removeCue', 10070 'params': [ 10071 { 10072 'name': 'id', 10073 'description': '<p>ID of the cue, as returned by addCue</p>\n', 10074 'type': 'Number' 10075 } 10076 ], 10077 'class': 'p5.MediaElement', 10078 'module': 'DOM' 10079 }, 10080 'clearCues': { 10081 'name': 'clearCues', 10082 'params': [ 10083 { 10084 'name': 'id', 10085 'description': '<p>ID of the cue, as returned by addCue</p>\n', 10086 'type': 'Number' 10087 } 10088 ], 10089 'class': 'p5.MediaElement', 10090 'module': 'DOM' 10091 } 10092 }, 10093 'p5.File': { 10094 'file': { 10095 'name': 'file', 10096 'class': 'p5.File', 10097 'module': 'DOM' 10098 }, 10099 'type': { 10100 'name': 'type', 10101 'class': 'p5.File', 10102 'module': 'DOM' 10103 }, 10104 'subtype': { 10105 'name': 'subtype', 10106 'class': 'p5.File', 10107 'module': 'DOM' 10108 }, 10109 'name': { 10110 'name': 'name', 10111 'class': 'p5.File', 10112 'module': 'DOM' 10113 }, 10114 'size': { 10115 'name': 'size', 10116 'class': 'p5.File', 10117 'module': 'DOM' 10118 }, 10119 'data': { 10120 'name': 'data', 10121 'class': 'p5.File', 10122 'module': 'DOM' 10123 } 10124 }, 10125 'p5.Image': { 10126 'width': { 10127 'name': 'width', 10128 'class': 'p5.Image', 10129 'module': 'Image' 10130 }, 10131 'height': { 10132 'name': 'height', 10133 'class': 'p5.Image', 10134 'module': 'Image' 10135 }, 10136 'pixels': { 10137 'name': 'pixels', 10138 'class': 'p5.Image', 10139 'module': 'Image' 10140 }, 10141 'loadPixels': { 10142 'name': 'loadPixels', 10143 'class': 'p5.Image', 10144 'module': 'Image' 10145 }, 10146 'updatePixels': { 10147 'name': 'updatePixels', 10148 'class': 'p5.Image', 10149 'module': 'Image', 10150 'overloads': [ 10151 { 10152 'params': [ 10153 { 10154 'name': 'x', 10155 'description': '<p>x-offset of the target update area for the\n underlying canvas</p>\n', 10156 'type': 'Integer' 10157 }, 10158 { 10159 'name': 'y', 10160 'description': '<p>y-offset of the target update area for the\n underlying canvas</p>\n', 10161 'type': 'Integer' 10162 }, 10163 { 10164 'name': 'w', 10165 'description': '<p>width of the target update area for the\n underlying canvas</p>\n', 10166 'type': 'Integer' 10167 }, 10168 { 10169 'name': 'h', 10170 'description': '<p>height of the target update area for the\n underlying canvas</p>\n', 10171 'type': 'Integer' 10172 } 10173 ] 10174 }, 10175 { 10176 'params': [ 10177 ] 10178 } 10179 ] 10180 }, 10181 'get': { 10182 'name': 'get', 10183 'class': 'p5.Image', 10184 'module': 'Image', 10185 'overloads': [ 10186 { 10187 'params': [ 10188 { 10189 'name': 'x', 10190 'description': '<p>x-coordinate of the pixel</p>\n', 10191 'type': 'Number' 10192 }, 10193 { 10194 'name': 'y', 10195 'description': '<p>y-coordinate of the pixel</p>\n', 10196 'type': 'Number' 10197 }, 10198 { 10199 'name': 'w', 10200 'description': '<p>width</p>\n', 10201 'type': 'Number' 10202 }, 10203 { 10204 'name': 'h', 10205 'description': '<p>height</p>\n', 10206 'type': 'Number' 10207 } 10208 ] 10209 }, 10210 { 10211 'params': [ 10212 ] 10213 }, 10214 { 10215 'params': [ 10216 { 10217 'name': 'x', 10218 'description': '', 10219 'type': 'Number' 10220 }, 10221 { 10222 'name': 'y', 10223 'description': '', 10224 'type': 'Number' 10225 } 10226 ] 10227 } 10228 ] 10229 }, 10230 'set': { 10231 'name': 'set', 10232 'params': [ 10233 { 10234 'name': 'x', 10235 'description': '<p>x-coordinate of the pixel</p>\n', 10236 'type': 'Number' 10237 }, 10238 { 10239 'name': 'y', 10240 'description': '<p>y-coordinate of the pixel</p>\n', 10241 'type': 'Number' 10242 }, 10243 { 10244 'name': 'a', 10245 'description': '<p>grayscale value | pixel array |\n a <a href="#/p5.Color">p5.Color</a> | image to copy</p>\n', 10246 'type': 'Number|Number[]|Object' 10247 } 10248 ], 10249 'class': 'p5.Image', 10250 'module': 'Image' 10251 }, 10252 'resize': { 10253 'name': 'resize', 10254 'params': [ 10255 { 10256 'name': 'width', 10257 'description': '<p>the resized image width</p>\n', 10258 'type': 'Number' 10259 }, 10260 { 10261 'name': 'height', 10262 'description': '<p>the resized image height</p>\n', 10263 'type': 'Number' 10264 } 10265 ], 10266 'class': 'p5.Image', 10267 'module': 'Image' 10268 }, 10269 'copy': { 10270 'name': 'copy', 10271 'class': 'p5.Image', 10272 'module': 'Image', 10273 'overloads': [ 10274 { 10275 'params': [ 10276 { 10277 'name': 'srcImage', 10278 'description': '<p>source image</p>\n', 10279 'type': 'p5.Image|p5.Element' 10280 }, 10281 { 10282 'name': 'sx', 10283 'description': '<p>X coordinate of the source\'s upper left corner</p>\n', 10284 'type': 'Integer' 10285 }, 10286 { 10287 'name': 'sy', 10288 'description': '<p>Y coordinate of the source\'s upper left corner</p>\n', 10289 'type': 'Integer' 10290 }, 10291
10291 { 10292 'name': 'sw', 10293 'description': '<p>source image width</p>\n', 10294 'type': 'Integer' 10295 }, 10296 { 10297 'name': 'sh', 10298 'description': '<p>source image height</p>\n', 10299 'type': 'Integer' 10300 }, 10301 { 10302 'name': 'dx', 10303 'description': '<p>X coordinate of the destination\'s upper left corner</p>\n', 10304 'type': 'Integer' 10305 }, 10306 { 10307 'name': 'dy', 10308 'description': '<p>Y coordinate of the destination\'s upper left corner</p>\n', 10309 'type': 'Integer' 10310 }, 10311 { 10312 'name': 'dw', 10313 'description': '<p>destination image width</p>\n', 10314 'type': 'Integer' 10315 }, 10316 { 10317 'name': 'dh', 10318 'description': '<p>destination image height</p>\n', 10319 'type': 'Integer' 10320 } 10321 ] 10322 }, 10323 { 10324 'params': [ 10325 { 10326 'name': 'sx', 10327 'description': '', 10328 'type': 'Integer' 10329 }, 10330 { 10331 'name': 'sy', 10332 'description': '', 10333 'type': 'Integer' 10334 }, 10335 { 10336 'name': 'sw', 10337 'description': '', 10338 'type': 'Integer' 10339 }, 10340 { 10341 'name': 'sh', 10342 'description': '', 10343 'type': 'Integer' 10344 }, 10345 { 10346 'name': 'dx', 10347 'description': '', 10348 'type': 'Integer' 10349 }, 10350 { 10351 'name': 'dy', 10352 'description': '', 10353 'type': 'Integer' 10354 }, 10355 { 10356 'name': 'dw', 10357 'description': '', 10358 'type': 'Integer' 10359 }, 10360 { 10361 'name': 'dh', 10362 'description': '', 10363 'type': 'Integer' 10364 } 10365 ] 10366 } 10367 ] 10368 }, 10369 'mask': { 10370 'name': 'mask', 10371 'params': [ 10372 { 10373 'name': 'srcImage', 10374 'description': '<p>source image</p>\n', 10375 'type': 'p5.Image' 10376 } 10377 ], 10378 'class': 'p5.Image', 10379 'module': 'Image' 10380 }, 10381 'filter': { 10382 'name': 'filter', 10383 'params': [ 10384 { 10385 'name': 'filterType', 10386 'description': '<p>either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, ERODE, DILATE or BLUR.\n See Filters.js for docs on\n each available filter</p>\n', 10387 'type': 'Constant' 10388 }, 10389 { 10390 'name': 'filterParam', 10391 'description': '<p>an optional parameter unique\n to each filter, see above</p>\n', 10392 'type': 'Number', 10393 'optional': true 10394 } 10395 ], 10396 'class': 'p5.Image', 10397 'module': 'Image' 10398 }, 10399 'blend': { 10400 'name': 'blend', 10401 'class': 'p5.Image', 10402 'module': 'Image', 10403 'overloads': [ 10404 { 10405 'params': [ 10406 { 10407 'name': 'srcImage', 10408 'description': '<p>source image</p>\n', 10409 'type': 'p5.Image' 10410 }, 10411 { 10412 'name': 'sx', 10413 'description': '<p>X coordinate of the source\'s upper left corner</p>\n', 10414 'type': 'Integer' 10415 }, 10416 { 10417 'name': 'sy', 10418 'description': '<p>Y coordinate of the source\'s upper left corner</p>\n', 10419 'type': 'Integer' 10420 }, 10421 { 10422 'name': 'sw', 10423 'description': '<p>source image width</p>\n', 10424 'type': 'Integer' 10425 }, 10426 { 10427 'name': 'sh', 10428 'description': '<p>source image height</p>\n', 10429 'type': 'Integer' 10430 }, 10431 { 10432 'name': 'dx', 10433 'description': '<p>X coordinate of the destination\'s upper left corner</p>\n', 10434 'type': 'Integer' 10435 }, 10436 { 10437 'name': 'dy', 10438 'description': '<p>Y coordinate of the destination\'s upper left corner</p>\n', 10439 'type': 'Integer' 10440 }, 10441 { 10442 'name': 'dw', 10443 'description': '<p>destination image width</p>\n', 10444 'type': 'Integer' 10445 }, 10446 { 10447 'name': 'dh', 10448 'description': '<p>destination image height</p>\n', 10449 'type': 'Integer' 10450 }, 10451 { 10452 'name': 'blendMode', 10453 'description': '<p>the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.</p>\n<p>Available blend modes are: normal | multiply | screen | overlay |\n darken | lighten | color-dodge | color-burn | hard-light |\n soft-light | difference | exclusion | hue | saturation |\n color | luminosity</p>\n<p><a href="http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/">http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/</a></p>\n', 10454 'type': 'Constant' 10455 } 10456 ] 10457 }, 10458 { 10459 'params': [ 10460 { 10461 'name': 'sx', 10462 'description': '', 10463 'type': 'Integer' 10464 }, 10465 { 10466 'name': 'sy', 10467 'description': '', 10468 'type': 'Integer' 10469 }, 10470 { 10471 'name': 'sw', 10472 'description': '', 10473 'type': 'Integer' 10474 }, 10475 { 10476 'name': 'sh', 10477 'description': '', 10478 'type': 'Integer' 10479 }, 10480 { 10481 'name': 'dx', 10482 'description': '', 10483 'type': 'Integer' 10484 }, 10485 { 10486 'name': 'dy', 10487 'description': '', 10488 'type': 'Integer' 10489 }, 10490 { 10491 'name': 'dw', 10492 'description': '', 10493 'type': 'Integer' 10494 }, 10495 { 10496 'name': 'dh', 10497 'description': '', 10498 'type': 'Integer' 10499 }, 10500 { 10501 'name': 'blendMode', 10502 'description': '', 10503 'type': 'Constant' 10504 } 10505 ] 10506 } 10507 ] 10508 },
10509 'save': { 10510 'name': 'save', 10511 'params': [ 10512 { 10513 'name': 'filename', 10514 'description': '<p>give your file a name</p>\n', 10515 'type': 'String' 10516 }, 10517 { 10518 'name': 'extension', 10519 'description': '<p>\'png\' or \'jpg\'</p>\n', 10520 'type': 'String' 10521 } 10522 ], 10523 'class': 'p5.Image', 10524 'module': 'Image' 10525 }, 10526 'reset': { 10527 'name': 'reset', 10528 'class': 'p5.Image', 10529 'module': 'Image' 10530 }, 10531 'getCurrentFrame': { 10532 'name': 'getCurrentFrame', 10533 'class': 'p5.Image', 10534 'module': 'Image' 10535 }, 10536 'setFrame': { 10537 'name': 'setFrame', 10538 'params': [ 10539 { 10540 'name': 'index', 10541 'description': '<p>the index for the frame that should be displayed</p>\n', 10542 'type': 'Number' 10543 } 10544 ], 10545 'class': 'p5.Image', 10546 'module': 'Image' 10547 }, 10548 'numFrames': { 10549 'name': 'numFrames', 10550 'class': 'p5.Image', 10551 'module': 'Image' 10552 }, 10553 'play': { 10554 'name': 'play', 10555 'class': 'p5.Image', 10556 'module': 'Image' 10557 }, 10558 'pause': { 10559 'name': 'pause', 10560 'class': 'p5.Image', 10561 'module': 'Image' 10562 }, 10563 'delay': { 10564 'name': 'delay', 10565 'params': [ 10566 { 10567 'name': 'd', 10568 'description': '<p>the amount in milliseconds to delay between switching frames</p>\n', 10569 'type': 'Number' 10570 }, 10571 { 10572 'name': 'index', 10573 'description': '<p>the index of the frame that should have the new delay value {optional}</p>\n', 10574 'type': 'Number', 10575 'optional': true 10576 } 10577 ], 10578 'class': 'p5.Image', 10579 'module': 'Image' 10580 } 10581 }, 10582 'p5.PrintWriter': { 10583 'write': { 10584 'name': 'write', 10585 'params': [ 10586 { 10587 'name': 'data', 10588 'description': '<p>all data to be written by the PrintWriter</p>\n', 10589 'type': 'Array' 10590 } 10591 ], 10592 'class': 'p5.PrintWriter', 10593 'module': 'IO' 10594 }, 10595 'print': { 10596 'name': 'print', 10597 'params': [ 10598 { 10599 'name': 'data', 10600 'description': '<p>all data to be printed by the PrintWriter</p>\n', 10601 'type': 'Array' 10602 } 10603 ], 10604 'class': 'p5.PrintWriter', 10605 'module': 'IO' 10606 }, 10607 'clear': { 10608 'name': 'clear', 10609 'class': 'p5.PrintWriter', 10610 'module': 'IO' 10611 }, 10612 'close': { 10613 'name': 'close', 10614 'class': 'p5.PrintWriter', 10615 'module': 'IO' 10616 } 10617 }, 10618 'p5.Table': { 10619 'columns': { 10620 'name': 'columns', 10621 'class': 'p5.Table', 10622 'module': 'IO' 10623 }, 10624 'rows': { 10625 'name': 'rows', 10626 'class': 'p5.Table', 10627 'module': 'IO' 10628 }, 10629 'addRow': { 10630 'name': 'addRow', 10631 'params': [ 10632 { 10633 'name': 'row', 10634 'description': '<p>row to be added to the table</p>\n', 10635 'type': 'p5.TableRow', 10636 'optional': true 10637 } 10638 ], 10639 'class': 'p5.Table', 10640 'module': 'IO' 10641 }, 10642 'removeRow': { 10643 'name': 'removeRow', 10644 'params': [ 10645 { 10646 'name': 'id', 10647 'description': '<p>ID number of the row to remove</p>\n', 10648 'type': 'Integer' 10649 } 10650 ], 10651 'class': 'p5.Table', 10652 'module': 'IO' 10653 }, 10654 'getRow': { 10655 'name': 'getRow', 10656 'params': [ 10657 { 10658 'name': 'rowID', 10659 'description': '<p>ID number of the row to get</p>\n', 10660 'type': 'Integer' 10661 } 10662 ], 10663 'class': 'p5.Table', 10664 'module': 'IO' 10665 }, 10666 'getRows': { 10667 'name': 'getRows', 10668 'class': 'p5.Table', 10669 'module': 'IO' 10670 }, 10671 'findRow': { 10672 'name': 'findRow', 10673 'params': [ 10674 { 10675 'name': 'value', 10676 'description': '<p>The value to match</p>\n', 10677 'type': 'String' 10678 }, 10679 { 10680 'name': 'column', 10681 'description': '<p>ID number or title of the\n column to search</p>\n', 10682 'type': 'Integer|String' 10683 } 10684 ], 10685 'class': 'p5.Table', 10686 'module': 'IO' 10687 }, 10688 'findRows': { 10689 'name': 'findRows', 10690 'params': [ 10691 { 10692 'name': 'value', 10693 'description': '<p>The value to match</p>\n', 10694 'type': 'String' 10695 }, 10696 { 10697 'name': 'column', 10698 'description': '<p>ID number or title of the\n column to search</p>\n', 10699 'type': 'Integer|String' 10700 } 10701 ], 10702 'class': 'p5.Table', 10703 'module': 'IO' 10704 }, 10705 'matchRow': { 10706 'name': 'matchRow', 10707 'params': [ 10708 { 10709 'name': 'regexp', 10710 'description': '<p>The regular expression to match</p>\n', 10711 'type': 'String|RegExp' 10712 }, 10713 { 10714 'name': 'column', 10715 'description': '<p>The column ID (number) or\n title (string)</p>\n', 10716 'type': 'String|Integer' 10717 } 10718 ], 10719 'class': 'p5.Table', 10720 'module': 'IO' 10721 }, 10722 'matchRows': { 10723 'name': 'matchRows', 10724 'params': [ 10725 { 10726 'name': 'regexp', 10727 'description': '<p>The regular expression to match</p>\n', 10728 'type': 'String' 10729 }, 10730 { 10731 'name': 'column', 10732 'description': '<p>The column ID (number) or\n title (string)</p>\n', 10733 'type': 'String|Integer', 10734 'optional': true 10735 } 10736 ], 10737 'class': 'p5.Table', 10738 'module': 'IO' 10739 }, 10740 'getColumn': { 10741 'name': 'getColumn', 10742 'params': [ 10743 { 10744 'name': 'column', 10745 'description': '<p>String or Number of the column to return</p>\n', 10746 'type': 'String|Number' 10747 } 10748 ], 10749 'class': 'p5.Table', 10750 'module': 'IO' 10751 }, 10752 'clearRows': { 10753 'name': 'clearRows', 10754 'class': 'p5.Table', 10755 'module': 'IO' 10756 }, 10757 'addColumn': { 10758 'name': 'addColumn', 10759 'params': [ 10760 { 10761 'name': 'title', 10762 'description': '<p>title of the given column</p>\n', 10763 'type': 'String', 10764 'optional': true 10765 } 10766 ], 10767 'class': 'p5.Table', 10768 'module': 'IO' 10769 }, 10770 'getColumnCount': { 10771 'name': 'getColumnCount', 10772 'class': 'p5.Table', 10773 'module': 'IO' 10774 }, 10775 'getRowCount': { 10776 'name': 'getRowCount', 10777 'class': 'p5.Table', 10778 'module': 'IO' 10779 }, 10780 'removeTokens': { 10781 'name': 'removeTokens', 10782 'params': [ 10783 { 10784 'name': 'chars', 10785 'description': '<p>String listing characters to be removed</p>\n', 10786 'type': 'String' 10787 }, 10788 { 10789 'name': 'column', 10790 'description': '<p>Column ID (number)\n or name (string)</p>\n', 10791 'type': 'String|Integer', 10792 'optional': true 10793 } 10794 ], 10795 'class': 'p5.Table', 10796 'module': 'IO' 10797 }, 10798 'trim': { 10799 'name': 'trim', 10800 'params': [ 10801 { 10802 'name': 'column', 10803 'description': '<p>Column ID (number)\n or name (string)</p>\n', 10804 'type': 'String|Integer', 10805 'optional': true 10806 } 10807 ], 10808 'class': 'p5.Table', 10809 'module': 'IO' 10810 }, 10811 'removeColumn': { 10812 'name': 'removeColumn', 10813 'params': [ 10814 { 10815 'name': 'column', 10816 'description': '<p>columnName (string) or ID (number)</p>\n', 10817 'type': 'String|Integer' 10818 } 10819 ], 10820 'class': 'p5.Table', 10821 'module': 'IO' 10822 }, 10823 'set': { 10824 'name': 'set', 10825 'params': [ 10826 { 10827 'name': 'row', 10828 'description': '<p>row ID</p>\n', 10829 'type': 'Integer' 10830 }, 10831 { 10832 'name': 'column', 10833 'description': '<p>column ID (Number)\n or title (String)</p>\n', 10834 'type': 'String|Integer' 10835 }, 10836 { 10837 'name': 'value', 10838 'description': '<p>value to assign</p>\n', 10839 'type': 'String|Number' 10840 } 10841 ], 10842 'class': 'p5.Table', 10843 'module': 'IO' 10844 }, 10845 'setNum': { 10846 'name': 'setNum', 10847 'params': [ 10848 { 10849 'name': 'row', 10850 'description': '<p>row ID</p>\n', 10851 'type': 'Integer' 10852 }, 10853 { 10854 'name': 'column', 10855 'description': '<p>column ID (Number)\n or title (String)</p>\n', 10856 'type': 'String|Integer' 10857 }, 10858 { 10859 'name': 'value', 10860 'description': '<p>value to assign</p>\n', 10861 'type': 'Number' 10862 } 10863 ], 10864 'class': 'p5.Table', 10865 'module': 'IO' 10866 }, 10867 'setString': { 10868 'name': 'setString', 10869 'params': [ 10870 { 10871 'name': 'row', 10872 'description': '<p>row ID</p>\n', 10873 'type': 'Integer' 10874 }, 10875 { 10876 'name': 'column', 10877 'description': '<p>column ID (Number)\n or title (String)</p>\n', 10878 'type': 'String|Integer' 10879 }, 10880 { 10881 'name': 'value', 10882 'description': '<p>value to assign</p>\n', 10883 'type': 'String' 10884 } 10885 ], 10886 'class': 'p5.Table', 10887 'module': 'IO' 10888 }, 10889 'get': { 10890 'name': 'get', 10891 'params': [ 10892 { 10893 'name': 'row', 10894 'description': '<p>row ID</p>\n', 10895 'type': 'Integer' 10896 }, 10897 { 10898 'name': 'column', 10899 'description': '<p>columnName (string) or\n ID (number)</p>\n', 10900 'type': 'String|Integer' 10901 } 10902 ], 10903 'class': 'p5.Table', 10904 'module': 'IO' 10905 }, 10906 'getNum': { 10907 'name': 'getNum', 10908 'params': [ 10909 { 10910 'name': 'row', 10911 'description': '<p>row ID</p>\n', 10912 'type': 'Integer' 10913 }, 10914 { 10915 'name': 'column', 10916 'description': '<p>columnName (string) or\n ID (number)</p>\n', 10917 'type': 'String|Integer' 10918 } 10919 ], 10920 'class': 'p5.Table', 10921 'module': 'IO' 10922 }, 10923 'getString': { 10924 'name': 'getString', 10925 'params': [ 10926 { 10927 'name': 'row', 10928 'description': '<p>row ID</p>\n', 10929 'type': 'Integer' 10930 }, 10931 { 10932 'name': 'column', 10933 'description': '<p>columnName (string) or\n ID (number)</p>\n', 10934 'type': 'String|Integer' 10935 } 10936 ], 10937 'class': 'p5.Table', 10938 'module': 'IO' 10939 }, 10940 'getObject': { 10941 'name': 'getObject', 10942 'params': [ 10943 { 10944 'name': 'headerColumn', 10945 'description': '<p>Name of the column which should be used to\n title each row object (optional)</p>\n', 10946 'type': 'String', 10947 'optional': true 10948 } 10949 ], 10950 'class': 'p5.Table', 10951 'module': 'IO' 10952 }, 10953 'getArray': { 10954 'name': 'getArray', 10955 'class': 'p5.Table', 10956 'module': 'IO' 10957 } 10958 }, 10959 'p5.TableRow': { 10960 'set': { 10961 'name': 'set', 10962 'params': [ 10963 { 10964 'name': 'column', 10965 'description': '<p>Column ID (Number)\n or Title (String)</p>\n', 10966 'type': 'String|Integer' 10967 }, 10968 { 10969 'name': 'value', 10970 'description': '<p>The value to be stored</p>\n', 10971 'type': 'String|Number' 10972 } 10973 ], 10974 'class': 'p5.TableRow', 10975 'module': 'IO' 10976 }, 10977 'setNum': { 10978 'name': 'setNum', 10979 'params': [ 10980 { 10981 'name': 'column', 10982 'description': '<p>Column ID (Number)\n or Title (String)</p>\n', 10983 'type': 'String|Integer' 10984 }, 10985 { 10986 'name': 'value', 10987 'description': '<p>The value to be stored\n as a Float</p>\n', 10988 'type': 'Number|String' 10989 } 10990 ], 10991 'class': 'p5.TableRow', 10992 'module': 'IO' 10993 }, 10994 'setString': { 10995 'name': 'setString', 10996 'params': [ 10997 { 10998 'name': 'column', 10999 'description': '<p>Column ID (Number)\n or Title (String)</p>\n', 11000 'type': 'String|Integer' 11001 }, 11002 { 11003 'name': 'value', 11004 'description': '<p>The value to be stored\n as a String</p>\n', 11005 'type': 'String|Number|Boolean|Object' 11006 } 11007 ], 11008 'class': 'p
110085.TableRow', 11009 'module': 'IO' 11010 }, 11011 'get': { 11012 'name': 'get', 11013 'params': [ 11014 { 11015 'name': 'column', 11016 'description': '<p>columnName (string) or\n ID (number)</p>\n', 11017 'type': 'String|Integer' 11018 } 11019 ], 11020 'class': 'p5.TableRow', 11021 'module': 'IO' 11022 }, 11023 'getNum': { 11024 'name': 'getNum', 11025 'params': [ 11026 { 11027 'name': 'column', 11028 'description': '<p>columnName (string) or\n ID (number)</p>\n', 11029 'type': 'String|Integer' 11030 } 11031 ], 11032 'class': 'p5.TableRow', 11033 'module': 'IO' 11034 }, 11035 'getString': { 11036 'name': 'getString', 11037 'params': [ 11038 { 11039 'name': 'column', 11040 'description': '<p>columnName (string) or\n ID (number)</p>\n', 11041 'type': 'String|Integer' 11042 } 11043 ], 11044 'class': 'p5.TableRow', 11045 'module': 'IO' 11046 } 11047 }, 11048 'p5.XML': { 11049 'getParent': { 11050 'name': 'getParent', 11051 'class': 'p5.XML', 11052 'module': 'IO' 11053 }, 11054 'getName': { 11055 'name': 'getName', 11056 'class': 'p5.XML', 11057 'module': 'IO' 11058 }, 11059 'setName': { 11060 'name': 'setName', 11061 'params': [ 11062 { 11063 'name': 'the', 11064 'description': '<p>new name of the node</p>\n', 11065 'type': 'String' 11066 } 11067 ], 11068 'class': 'p5.XML', 11069 'module': 'IO' 11070 }, 11071 'hasChildren': { 11072 'name': 'hasChildren', 11073 'class': 'p5.XML', 11074 'module': 'IO' 11075 }, 11076 'listChildren': { 11077 'name': 'listChildren', 11078 'class': 'p5.XML', 11079 'module': 'IO' 11080 }, 11081 'getChildren': { 11082 'name': 'getChildren', 11083 'params': [ 11084 { 11085 'name': 'name', 11086 'description': '<p>element name</p>\n', 11087 'type': 'String', 11088 'optional': true 11089 } 11090 ], 11091 'class': 'p5.XML', 11092 'module': 'IO' 11093 }, 11094 'getChild': { 11095 'name': 'getChild', 11096 'params': [ 11097 { 11098 'name': 'name', 11099 'description': '<p>element name or index</p>\n', 11100 'type': 'String|Integer' 11101 } 11102 ], 11103 'class': 'p5.XML', 11104 'module': 'IO' 11105 }, 11106 'addChild': { 11107 'name': 'addChild', 11108 'params': [ 11109 { 11110 'name': 'node', 11111 'description': '<p>a <a href="#/p5.XML">p5.XML</a> Object which will be the child to be added</p>\n', 11112 'type': 'p5.XML' 11113 } 11114 ], 11115 'class': 'p5.XML', 11116 'module': 'IO' 11117 }, 11118 'removeChild': { 11119 'name': 'removeChild', 11120 'params': [ 11121 { 11122 'name': 'name', 11123 'description': '<p>element name or index</p>\n', 11124 'type': 'String|Integer' 11125 } 11126 ], 11127 'class': 'p5.XML', 11128 'module': 'IO' 11129 }, 11130 'getAttributeCount': { 11131 'name': 'getAttributeCount', 11132 'class': 'p5.XML', 11133 'module': 'IO' 11134 }, 11135 'listAttributes': { 11136 'name': 'listAttributes', 11137 'class': 'p5.XML', 11138 'module': 'IO' 11139 }, 11140 'hasAttribute': { 11141 'name': 'hasAttribute', 11142 'params': [ 11143 { 11144 'name': 'the', 11145 'description': '<p>attribute to be checked</p>\n', 11146 'type': 'String' 11147 } 11148 ], 11149 'class': 'p5.XML', 11150 'module': 'IO' 11151 }, 11152 'getNum': { 11153 'name': 'getNum', 11154 'params': [ 11155 { 11156 'name': 'name', 11157 'description': '<p>the non-null full name of the attribute</p>\n', 11158 'type': 'String' 11159 }, 11160 { 11161 'name': 'defaultValue', 11162 'description': '<p>the default value of the attribute</p>\n', 11163 'type': 'Number', 11164 'optional': true 11165 } 11166 ], 11167 'class': 'p5.XML', 11168 'module': 'IO' 11169 }, 11170 'getString': { 11171 'name': 'getString', 11172 'params': [ 11173 { 11174 'name': 'name', 11175 'description': '<p>the non-null full name of the attribute</p>\n', 11176 'type': 'String' 11177 }, 11178 { 11179 'name': 'defaultValue', 11180 'description': '<p>the default value of the attribute</p>\n', 11181 'type': 'Number', 11182 'optional': true 11183 } 11184 ], 11185 'class': 'p5.XML', 11186 'module': 'IO' 11187 }, 11188 'setAttribute': { 11189 'name': 'setAttribute', 11190 'params': [ 11191 { 11192 'name': 'name', 11193 'description': '<p>the full name of the attribute</p>\n', 11194 'type': 'String' 11195 }, 11196 { 11197 'name': 'value', 11198 'description': '<p>the value of the attribute</p>\n', 11199 'type': 'Number|String|Boolean' 11200 } 11201 ], 11202 'class': 'p5.XML', 11203 'module': 'IO' 11204 }, 11205 'getContent': { 11206 'name': 'getContent', 11207 'params': [ 11208 { 11209 'name': 'defaultValue', 11210 'description': '<p>value returned if no content is found</p>\n', 11211 'type': 'String', 11212 'optional': true 11213 } 11214 ], 11215 'class': 'p5.XML', 11216 'module': 'IO' 11217 }, 11218 'setContent': { 11219 'name': 'setContent', 11220 'params': [ 11221 { 11222 'name': 'text', 11223 'description': '<p>the new content</p>\n', 11224 'type': 'String' 11225 } 11226 ], 11227 'class': 'p5.XML', 11228 'module': 'IO' 11229 }, 11230 'serialize': { 11231 'name': 'serialize', 11232 'class': 'p5.XML', 11233 'module': 'IO' 11234 } 11235 }, 11236 'p5.Vector': { 11237 'x': { 11238 'name': 'x', 11239 'class': 'p5.Vector', 11240 'module': 'Math' 11241 }, 11242 'y': { 11243 'name': 'y', 11244 'class': 'p5.Vector', 11245 'module': 'Math' 11246 }, 11247 'z': { 11248 'name': 'z', 11249 'class': 'p5.Vector', 11250 'module': 'Math' 11251 }, 11252 'toString': { 11253 'name': 'toString', 11254 'class': 'p5.Vector', 11255 'module': 'Math' 11256 }, 11257 'set': { 11258 'name': 'set', 11259 'class': 'p5.Vector', 11260 'module': 'Math', 11261 'overloads': [ 11262 { 11263 'params': [ 11264 { 11265 'name': 'x', 11266 'description': '<p>The x component of the vector</p>\n', 11267 'type': 'Number', 11268 'optional': true 11269 }, 11270 { 11271 'name': 'y', 11272 'description': '<p>The y component of the vector</p>\n', 11273 'type': 'Number', 11274 'optional': true 11275 }, 11276 { 11277 'name': 'z', 11278 'description': '<p>The z component of the vector</p>\n', 11279 'type': 'Number', 11280 'optional': true 11281 } 11282 ], 11283 'chainable': 1 11284 }, 11285 { 11286 'params': [ 11287 { 11288 'name': 'value', 11289 'description': '<p>The vector to set</p>\n', 11290 'type': 'p5.Vector|Number[]' 11291 } 11292 ], 11293 'chainable': 1 11294 } 11295 ] 11296 }, 11297 'copy': { 11298 'name': 'copy', 11299 'class': 'p5.Vector', 11300 'module': 'Math', 11301 'overloads': [ 11302 { 11303 'params': [ 11304 ] 11305 }, 11306 { 11307 'params': [ 11308 { 11309 'name': 'v', 11310 'description': '<p>the <a href="#/p5.Vector">p5.Vector</a> to create a copy of</p>\n', 11311 'type': 'p5.Vector' 11312 } 11313 ], 11314 'static': 1 11315 } 11316 ] 11317 }, 11318 'add': { 11319 'name': 'add', 11320 'class': 'p5.Vector', 11321 'module': 'Math', 11322 'overloads': [ 11323 { 11324 'params': [ 11325 { 11326 'name': 'x', 11327 'description': '<p>The x component of the vector to be added</p>\n', 11328 'type': 'Number' 11329 }, 11330 { 11331 'name': 'y', 11332 'description': '<p>The y component of the vector to be added</p>\n', 11333 'type': 'Number', 11334 'optional': true 11335 }, 11336 { 11337 'name': 'z', 11338 'description': '<p>The z component of the vector to be added</p>\n', 11339 'type': 'Number', 11340 'optional': true 11341 } 11342 ], 11343 'chainable': 1 11344 }, 11345 { 11346 'params': [ 11347 { 11348 'name': 'value', 11349 'description': '<p>The vector to add</p>\n', 11350 'type': 'p5.Vector|Number[]' 11351 } 11352 ], 11353 'chainable': 1 11354 }, 11355 { 11356 'params': [ 11357 { 11358 'name': 'v1', 11359 'description': '<p>A <a href="#/p5.Vector">p5.Vector</a> to add</p>\n', 11360 'type': 'p5.Vector' 11361 }, 11362 { 11363 'name': 'v2', 11364 'description': '<p>A <a href="#/p5.Vector">p5.Vector</a> to add</p>\n', 11365 'type': 'p5.Vector' 11366 }, 11367 { 11368 'name': 'target', 11369 'description': '<p>The vector to receive the result</p>\n', 11370 'type': 'p5.Vector', 11371 'optional': true 11372 } 11373 ], 11374 'static': 1 11375 } 11376 ] 11377 }, 11378 'rem': { 11379 'name': 'rem', 11380 'class': 'p5.Vector', 11381 'module': 'Math', 11382 'overloads': [ 11383 { 11384 'params': [ 11385 { 11386 'name': 'x', 11387 'description': '<p>The x component of divisor vector</p>\n', 11388 'type': 'Number' 11389 }, 11390 { 11391 'name': 'y', 11392 'description': '<p>The y component of divisor vector</p>\n', 11393 'type': 'Number' 11394 }, 11395 { 11396 'name': 'z', 11397 'description': '<p>The z component of divisor vector</p>\n', 11398 'type': 'Number' 11399 } 11400 ], 11401 'chainable': 1 11402 }, 11403 { 11404 'params': [ 11405 { 11406 'name': 'value', 11407 'description': '<p>The divisor vector</p>\n', 11408 'type': 'p5.Vector | Number[]' 11409 } 11410 ], 11411 'chainable': 1 11412 }, 11413 { 11414 'params': [ 11415 { 11416 'name': 'v1', 11417 'description': '<p>The dividend <a href="#/p5.Vector">p5.Vector</a></p>\n', 11418 'type': 'p5.Vector' 11419 }, 11420 { 11421 'name': 'v2', 11422 'description': '<p>The divisor <a href="#/p5.Vector">p5.Vector</a></p>\n', 11423 'type': 'p5.Vector' 11424 } 11425 ], 11426 'static': 1 11427 }, 11428 { 11429 'params': [ 11430 { 11431 'name': 'v1', 11432 'description': '', 11433 'type': 'p5.Vector' 11434 }, 11435 { 11436 'name': 'v2', 11437 'description': '', 11438 'type': 'p5.Vector' 11439 } 11440 ], 11441 'static': 1 11442 } 11443 ] 11444 }, 11445 'sub': { 11446 'name': 'sub', 11447 'class': 'p5.Vector', 11448 'module': 'Math', 11449 'overloads': [ 11450 { 11451 'params': [ 11452 { 11453 'name': 'x', 11454 'description': '<p>The x component of the vector to subtract</p>\n', 11455 'type': 'Number' 11456 }, 11457 { 11458 'name': 'y', 11459 'description': '<p>The y component of the vector to subtract</p>\n', 11460 'type': 'Number', 11461 'optional': true 11462 }, 11463 { 11464 'name': 'z', 11465 'description': '<p>The z component of the vector to subtract</p>\n', 11466 'type': 'Number', 11467 'optional': true 11468 } 11469 ], 11470 'chainable': 1 11471 }, 11472 { 11473 'params': [ 11474 { 11475 'name': 'value', 11476 'description': '<p>the vector to subtract</p>\n', 11477 'type': 'p5.Vector|Number[]' 11478 } 11479 ], 11480 'chainable': 1 11481 }, 11482 { 11483 'params': [ 11484 { 11485 'name': 'v1', 11486 'description': '<p>A <a href="#/p5.Vector">p5.Vector</a> to subtract from</p>\n', 11487 'type': 'p5.Vector' 11488 }, 11489 { 11490 'name': 'v2', 11491 'description': '<p>A <a href="#/p5.Vector">p5.Vector</a> to subtract</p>\n', 11492 'type': 'p5.Vector' 11493 }, 11494 { 11495 'name': 'target', 11496 'description': '<p>The vector to receive the result</p>\n', 11497 'type': 'p5.Vector', 11498 'optional': true 11499 } 11500 ], 11501 'static': 1 11502 } 11503 ] 11504 }, 11505 'mult': { 11506 'name': 'mult', 11507 'class': 'p5.Vector', 11508 'module': 'Math', 11509 'overloads': [ 11510 { 11511 'params': [ 11512 { 11513 'name': 'n', 11514 'descriptio
11514n': '<p>The number to multiply with the vector</p>\n', 11515 'type': 'Number' 11516 } 11517 ], 11518 'chainable': 1 11519 }, 11520 { 11521 'params': [ 11522 { 11523 'name': 'x', 11524 'description': '<p>The number to multiply with the x component of the vector</p>\n', 11525 'type': 'Number' 11526 }, 11527 { 11528 'name': 'y', 11529 'description': '<p>The number to multiply with the y component of the vector</p>\n', 11530 'type': 'Number' 11531 }, 11532 { 11533 'name': 'z', 11534 'description': '<p>The number to multiply with the z component of the vector</p>\n', 11535 'type': 'Number', 11536 'optional': true 11537 } 11538 ], 11539 'chainable': 1 11540 }, 11541 { 11542 'params': [ 11543 { 11544 'name': 'arr', 11545 'description': '<p>The array to multiply with the components of the vector</p>\n', 11546 'type': 'Number[]' 11547 } 11548 ], 11549 'chainable': 1 11550 }, 11551 { 11552 'params': [ 11553 { 11554 'name': 'v', 11555 'description': '<p>The vector to multiply with the components of the original vector</p>\n', 11556 'type': 'p5.Vector' 11557 } 11558 ], 11559 'chainable': 1 11560 }, 11561 { 11562 'params': [ 11563 { 11564 'name': 'x', 11565 'description': '', 11566 'type': 'Number' 11567 }, 11568 { 11569 'name': 'y', 11570 'description': '', 11571 'type': 'Number' 11572 }, 11573 { 11574 'name': 'z', 11575 'description': '', 11576 'type': 'Number', 11577 'optional': true 11578 } 11579 ], 11580 'static': 1 11581 }, 11582 { 11583 'params': [ 11584 { 11585 'name': 'v', 11586 'description': '', 11587 'type': 'p5.Vector' 11588 }, 11589 { 11590 'name': 'n', 11591 'description': '', 11592 'type': 'Number' 11593 }, 11594 { 11595 'name': 'target', 11596 'description': '<p>the vector to receive the result</p>\n', 11597 'type': 'p5.Vector', 11598 'optional': true 11599 } 11600 ], 11601 'static': 1 11602 }, 11603 { 11604 'params': [ 11605 { 11606 'name': 'v0', 11607 'description': '', 11608 'type': 'p5.Vector' 11609 }, 11610 { 11611 'name': 'v1', 11612 'description': '', 11613 'type': 'p5.Vector' 11614 }, 11615 { 11616 'name': 'target', 11617 'description': '', 11618 'type': 'p5.Vector', 11619 'optional': true 11620 } 11621 ], 11622 'static': 1 11623 }, 11624 { 11625 'params': [ 11626 { 11627 'name': 'v0', 11628 'description': '', 11629 'type': 'p5.Vector' 11630 }, 11631 { 11632 'name': 'arr', 11633 'description': '', 11634 'type': 'Number[]' 11635 }, 11636 { 11637 'name': 'target', 11638 'description': '', 11639 'type': 'p5.Vector', 11640 'optional': true 11641 } 11642 ], 11643 'static': 1 11644 } 11645 ] 11646 }, 11647 'div': { 11648 'name': 'div', 11649 'class': 'p5.Vector', 11650 'module': 'Math', 11651 'overloads': [ 11652 { 11653 'params': [ 11654 { 11655 'name': 'n', 11656 'description': '<p>The number to divide the vector by</p>\n', 11657 'type': 'Number' 11658 } 11659 ], 11660 'chainable': 1 11661 }, 11662 { 11663 'params': [ 11664 { 11665 'name': 'x', 11666 'description': '<p>The number to divide with the x component of the vector</p>\n', 11667 'type': 'Number' 11668 }, 11669 { 11670 'name': 'y', 11671 'description': '<p>The number to divide with the y component of the vector</p>\n', 11672 'type': 'Number' 11673 }, 11674 { 11675 'name': 'z', 11676 'description': '<p>The number to divide with the z component of the vector</p>\n', 11677 'type': 'Number', 11678 'optional': true 11679 } 11680 ], 11681 'chainable': 1 11682 }, 11683 { 11684 'params': [ 11685 { 11686 'name': 'arr', 11687 'description': '<p>The array to divide the components of the vector by</p>\n', 11688 'type': 'Number[]' 11689 } 11690 ], 11691 'chainable': 1 11692 }, 11693 { 11694 'params': [ 11695 { 11696 'name': 'v', 11697 'description': '<p>The vector to divide the components of the original vector by</p>\n', 11698 'type': 'p5.Vector' 11699 } 11700 ], 11701 'chainable': 1 11702 }, 11703 { 11704 'params': [ 11705 { 11706 'name': 'x', 11707 'description': '', 11708 'type': 'Number' 11709 }, 11710 { 11711 'name': 'y', 11712 'description': '', 11713 'type': 'Number' 11714 }, 11715 { 11716 'name': 'z', 11717 'description': '', 11718 'type': 'Number', 11719 'optional': true 11720 } 11721 ], 11722 'static': 1 11723 }, 11724 { 11725 'params': [ 11726 { 11727 'name': 'v', 11728 'description': '', 11729 'type': 'p5.Vector' 11730 }, 11731 { 11732 'name': 'n', 11733 'description': '', 11734 'type': 'Number' 11735 }, 11736 { 11737 'name': 'target', 11738 'description': '<p>The vector to receive the result</p>\n', 11739 'type': 'p5.Vector', 11740 'optional': true 11741 } 11742 ], 11743 'static': 1 11744 }, 11745 { 11746 'params': [ 11747 { 11748 'name': 'v0', 11749 'description': '', 11750 'type': 'p5.Vector' 11751 }, 11752 { 11753 'name': 'v1', 11754 'description': '', 11755 'type': 'p5.Vector' 11756 }, 11757 { 11758 'name': 'target', 11759 'description': '', 11760 'type': 'p5.Vector', 11761 'optional': true 11762 } 11763 ], 11764 'static': 1 11765 }, 11766 { 11767 'params': [ 11768 { 11769 'name': 'v0', 11770 'description': '', 11771 'type': 'p5.Vector' 11772 }, 11773 { 11774 'name': 'arr', 11775 'description': '', 11776 'type': 'Number[]' 11777 }, 11778 { 11779 'name': 'target', 11780 'description': '', 11781 'type': 'p5.Vector', 11782 'optional': true 11783 } 11784 ], 11785 'static': 1 11786 } 11787 ] 11788 }, 11789 'mag': { 11790 'name': 'mag', 11791 'class': 'p5.Vector', 11792 'module': 'Math', 11793 'overloads': [ 11794 { 11795 'params': [ 11796 ] 11797 }, 11798 { 11799 'params': [ 11800 { 11801 'name': 'vecT', 11802 'description': '<p>The vector to return the magnitude of</p>\n', 11803 'type': 'p5.Vector' 11804 } 11805 ], 11806 'static': 1 11807 } 11808 ] 11809 }, 11810 'magSq': { 11811 'name': 'magSq', 11812 'class': 'p5.Vector', 11813 'module': 'Math', 11814 'overloads': [ 11815 { 11816 'params': [ 11817 ] 11818 }, 11819 { 11820 'params': [ 11821 { 11822 'name': 'vecT', 11823 'description': '<p>the vector to return the squared magnitude of</p>\n', 11824 'type': 'p5.Vector' 11825 } 11826 ], 11827 'static': 1 11828 } 11829 ] 11830 }, 11831 'dot': { 11832 'name': 'dot', 11833 'class': 'p5.Vector', 11834 'module': 'Math', 11835 'overloads': [ 11836 { 11837 'params': [ 11838 { 11839 'name': 'x', 11840 'description': '<p>The x component of the vector</p>\n', 11841 'type': 'Number' 11842 }, 11843 { 11844 'name': 'y', 11845 'description': '<p>The y component of the vector</p>\n', 11846 'type': 'Number', 11847 'optional': true 11848 }, 11849 { 11850 'name': 'z', 11851 'description': '<p>The z component of the vector</p>\n', 11852 'type': 'Number', 11853 'optional': true 11854 } 11855 ] 11856 }, 11857 { 11858 'params': [ 11859 { 11860 'name': 'value', 11861 'description': '<p>value component of the vector or a <a href="#/p5.Vector">p5.Vector</a></p>\n', 11862 'type': 'p5.Vector' 11863 } 11864 ] 11865 }, 11866 { 11867 'params': [ 11868 { 11869 'name': 'v1', 11870 'description': '<p>The first <a href="#/p5.Vector">p5.Vector</a></p>\n', 11871 'type': 'p5.Vector' 11872 }, 11873 { 11874 'name': 'v2', 11875 'description': '<p>The second <a href="#/p5.Vector">p5.Vector</a></p>\n', 11876 'type': 'p5.Vector' 11877 } 11878 ], 11879 'static': 1 11880 } 11881 ] 11882 }, 11883 'cross': { 11884 'name': 'cross', 11885 'class': 'p5.Vector', 11886 'module': 'Math', 11887 'overloads': [ 11888 { 11889 'params': [ 11890 { 11891 'name': 'v', 11892 'description': '<p><a href="#/p5.Vector">p5.Vector</a> to be crossed</p>\n', 11893 'type': 'p5.Vector' 11894 } 11895 ] 11896 }, 11897 { 11898 'params': [ 11899 { 11900 'name': 'v1', 11901 'description': '<p>The first <a href="#/p5.Vector">p5.Vector</a></p>\n', 11902 'type': 'p5.Vector' 11903 }, 11904 { 11905 'name': 'v2', 11906 'description': '<p>The second <a href="#/p5.Vector">p5.Vector</a></p>\n', 11907 'type': 'p5.Vector' 11908 } 11909 ], 11910 'static': 1 11911 } 11912 ] 11913 }, 11914 'dist': { 11915 'name': 'dist', 11916 'class': 'p5.Vector', 11917 'module': 'Math', 11918 'overloads': [ 11919 { 11920 'params': [ 11921 { 11922 'name': 'v', 11923 'description': '<p>The x, y, and z coordinates of a <a href="#/p5.Vector">p5.Vector</a></p>\n', 11924 'type': 'p5.Vector' 11925 } 11926 ] 11927 }, 11928 { 11929 'params': [ 11930 { 11931 'name': 'v1', 11932 'description': '<p>The first <a href="#/p5.Vector">p5.Vector</a></p>\n', 11933 'type': 'p5.Vector' 11934 }, 11935 { 11936 'name': 'v2', 11937 'description': '<p>The second <a href="#/p5.Vector">p5.Vector</a></p>\n', 11938 'type': 'p5.Vector' 11939 } 11940 ], 11941 'static': 1 11942 } 11943 ] 11944 }, 11945 'normalize': { 11946 'name': 'normalize', 11947 'class': 'p5.Vector', 11948 'module': 'Math', 11949 'overloads': [ 11950 { 11951 'params': [ 11952 ] 11953 }, 11954 { 11955 'params': [ 11956 { 11957 'name': 'v', 11958 'description': '<p>The vector to normalize</p>\n', 11959 'type': 'p5.Vector' 11960 }, 11961 { 11962 'name': 'target', 11963 'description': '<p>The vector to receive the result</p>\n', 11964 'type': 'p5.Vector', 11965 'optional': true 11966 } 11967 ], 11968 'static': 1 11969 } 11970 ] 11971 }, 11972 'limit': { 11973 'name': 'limit', 11974 'class': 'p5.Vector', 11975 'module': 'Math', 11976 'overloads': [ 11977 { 11978 'params': [ 11979 { 11980 'name': 'max', 11981 'description': '<p>The maximum magnitude for the vector</p>\n', 11982 'type': 'Number' 11983 } 11984 ], 11985 'chainable': 1 11986 }, 11987 { 11988 'params': [ 11989 { 11990 'name': 'v', 11991 'description': '<p>the vector to limit</p>\n', 11992 'type': 'p5.Vector' 11993 }, 11994 { 11995 'name': 'max', 11996 'description': '', 11997 'type': 'Number' 11998 }, 11999 { 12000 'name': 'target', 12001 'description': '<p>the vector to receive the result (Optional)</p>\n', 12002 'type': 'p5.Vector', 12003 'optional': true 12004 } 12005 ], 12006 'static': 1 12007 } 12008 ] 12009 }, 12010 'setMag': { 12011 'name': 'setMag', 12012 'class': 'p5.Vector', 12013 'module': 'Math', 12014
12014 'overloads': [ 12015 { 12016 'params': [ 12017 { 12018 'name': 'len', 12019 'description': '<p>The new length for this vector</p>\n', 12020 'type': 'Number' 12021 } 12022 ], 12023 'chainable': 1 12024 }, 12025 { 12026 'params': [ 12027 { 12028 'name': 'v', 12029 'description': '<p>the vector to set the magnitude of</p>\n', 12030 'type': 'p5.Vector' 12031 }, 12032 { 12033 'name': 'len', 12034 'description': '', 12035 'type': 'Number' 12036 }, 12037 { 12038 'name': 'target', 12039 'description': '<p>the vector to receive the result (Optional)</p>\n', 12040 'type': 'p5.Vector', 12041 'optional': true 12042 } 12043 ], 12044 'static': 1 12045 } 12046 ] 12047 }, 12048 'heading': { 12049 'name': 'heading', 12050 'class': 'p5.Vector', 12051 'module': 'Math', 12052 'overloads': [ 12053 { 12054 'params': [ 12055 ] 12056 }, 12057 { 12058 'params': [ 12059 { 12060 'name': 'v', 12061 'description': '<p>the vector to find the angle of</p>\n', 12062 'type': 'p5.Vector' 12063 } 12064 ], 12065 'static': 1 12066 } 12067 ] 12068 }, 12069 'setHeading': { 12070 'name': 'setHeading', 12071 'params': [ 12072 { 12073 'name': 'angle', 12074 'description': '<p>The angle of rotation</p>\n', 12075 'type': 'Number' 12076 } 12077 ], 12078 'class': 'p5.Vector', 12079 'module': 'Math' 12080 }, 12081 'rotate': { 12082 'name': 'rotate', 12083 'class': 'p5.Vector', 12084 'module': 'Math', 12085 'overloads': [ 12086 { 12087 'params': [ 12088 { 12089 'name': 'angle', 12090 'description': '<p>The angle of rotation</p>\n', 12091 'type': 'Number' 12092 } 12093 ], 12094 'chainable': 1 12095 }, 12096 { 12097 'params': [ 12098 { 12099 'name': 'v', 12100 'description': '', 12101 'type': 'p5.Vector' 12102 }, 12103 { 12104 'name': 'angle', 12105 'description': '', 12106 'type': 'Number' 12107 }, 12108 { 12109 'name': 'target', 12110 'description': '<p>The vector to receive the result</p>\n', 12111 'type': 'p5.Vector', 12112 'optional': true 12113 } 12114 ], 12115 'static': 1 12116 } 12117 ] 12118 }, 12119 'angleBetween': { 12120 'name': 'angleBetween', 12121 'class': 'p5.Vector', 12122 'module': 'Math', 12123 'overloads': [ 12124 { 12125 'params': [ 12126 { 12127 'name': 'value', 12128 'description': '<p>The x, y, and z components of a <a href="#/p5.Vector">p5.Vector</a></p>\n', 12129 'type': 'p5.Vector' 12130 } 12131 ] 12132 }, 12133 { 12134 'params': [ 12135 { 12136 'name': 'v1', 12137 'description': '<p>the first vector</p>\n', 12138 'type': 'p5.Vector' 12139 }, 12140 { 12141 'name': 'v2', 12142 'description': '<p>the second vector</p>\n', 12143 'type': 'p5.Vector' 12144 } 12145 ], 12146 'static': 1 12147 } 12148 ] 12149 }, 12150 'lerp': { 12151 'name': 'lerp', 12152 'class': 'p5.Vector', 12153 'module': 'Math', 12154 'overloads': [ 12155 { 12156 'params': [ 12157 { 12158 'name': 'x', 12159 'description': '<p>The x component</p>\n', 12160 'type': 'Number' 12161 }, 12162 { 12163 'name': 'y', 12164 'description': '<p>The y component</p>\n', 12165 'type': 'Number' 12166 }, 12167 { 12168 'name': 'z', 12169 'description': '<p>The z component</p>\n', 12170 'type': 'Number' 12171 }, 12172 { 12173 'name': 'amt', 12174 'description': '<p>The amount of interpolation; some value between 0.0\n (old vector) and 1.0 (new vector). 0.9 is very near\n the new vector. 0.5 is halfway in between.</p>\n', 12175 'type': 'Number' 12176 } 12177 ], 12178 'chainable': 1 12179 }, 12180 { 12181 'params': [ 12182 { 12183 'name': 'v', 12184 'description': '<p>The <a href="#/p5.Vector">p5.Vector</a> to lerp to</p>\n', 12185 'type': 'p5.Vector' 12186 }, 12187 { 12188 'name': 'amt', 12189 'description': '', 12190 'type': 'Number' 12191 } 12192 ], 12193 'chainable': 1 12194 }, 12195 { 12196 'params': [ 12197 { 12198 'name': 'v1', 12199 'description': '', 12200 'type': 'p5.Vector' 12201 }, 12202 { 12203 'name': 'v2', 12204 'description': '', 12205 'type': 'p5.Vector' 12206 }, 12207 { 12208 'name': 'amt', 12209 'description': '', 12210 'type': 'Number' 12211 }, 12212 { 12213 'name': 'target', 12214 'description': '<p>The vector to receive the result</p>\n', 12215 'type': 'p5.Vector', 12216 'optional': true 12217 } 12218 ], 12219 'static': 1 12220 } 12221 ] 12222 }, 12223 'reflect': { 12224 'name': 'reflect', 12225 'class': 'p5.Vector', 12226 'module': 'Math', 12227 'overloads': [ 12228 { 12229 'params': [ 12230 { 12231 'name': 'surfaceNormal', 12232 'description': '<p>the <a href="#/p5.Vector">p5.Vector</a>\n to reflect about.</p>\n', 12233 'type': 'p5.Vector' 12234 } 12235 ], 12236 'chainable': 1 12237 }, 12238 { 12239 'params': [ 12240 { 12241 'name': 'incidentVector', 12242 'description': '<p>vector to be reflected</p>\n', 12243 'type': 'p5.Vector' 12244 }, 12245 { 12246 'name': 'surfaceNormal', 12247 'description': '', 12248 'type': 'p5.Vector' 12249 }, 12250 { 12251 'name': 'target', 12252 'description': '<p>the vector to receive the result (Optional)</p>\n', 12253 'type': 'p5.Vector', 12254 'optional': true 12255 } 12256 ], 12257 'static': 1 12258 } 12259 ] 12260 }, 12261 'array': { 12262 'name': 'array', 12263 'class': 'p5.Vector', 12264 'module': 'Math', 12265 'overloads': [ 12266 { 12267 'params': [ 12268 ] 12269 }, 12270 { 12271 'params': [ 12272 { 12273 'name': 'v', 12274 'description': '<p>the vector to convert to an array</p>\n', 12275 'type': 'p5.Vector' 12276 } 12277 ], 12278 'static': 1 12279 } 12280 ] 12281 }, 12282 'equals': { 12283 'name': 'equals', 12284 'class': 'p5.Vector', 12285 'module': 'Math', 12286 'overloads': [ 12287 { 12288 'params': [ 12289 { 12290 'name': 'x', 12291 'description': '<p>The x component of the vector</p>\n', 12292 'type': 'Number', 12293 'optional': true 12294 }, 12295 { 12296 'name': 'y', 12297 'description': '<p>The y component of the vector</p>\n', 12298 'type': 'Number', 12299 'optional': true 12300 }, 12301 { 12302 'name': 'z', 12303 'description': '<p>The z component of the vector</p>\n', 12304 'type': 'Number', 12305 'optional': true 12306 } 12307 ] 12308 }, 12309 { 12310 'params': [ 12311 { 12312 'name': 'value', 12313 'description': '<p>The vector to compare</p>\n', 12314 'type': 'p5.Vector|Array' 12315 } 12316 ] 12317 }, 12318 { 12319 'params': [ 12320 { 12321 'name': 'v1', 12322 'description': '<p>the first vector to compare</p>\n', 12323 'type': 'p5.Vector|Array' 12324 }, 12325 { 12326 'name': 'v2', 12327 'description': '<p>the second vector to compare</p>\n', 12328 'type': 'p5.Vector|Array' 12329 } 12330 ], 12331 'static': 1 12332 } 12333 ] 12334 }, 12335 'fromAngle': { 12336 'name': 'fromAngle', 12337 'params': [ 12338 { 12339 'name': 'angle', 12340 'description': '<p>The desired angle, in radians (unaffected by <a href="#/p5/angleMode">angleMode</a>)</p>\n', 12341 'type': 'Number' 12342 }, 12343 { 12344 'name': 'length', 12345 'description': '<p>The length of the new vector (defaults to 1)</p>\n', 12346 'type': 'Number', 12347 'optional': true 12348 } 12349 ], 12350 'class': 'p5.Vector', 12351 'module': 'Math' 12352 }, 12353 'fromAngles': { 12354 'name': 'fromAngles', 12355 'params': [ 12356 { 12357 'name': 'theta', 12358 'description': '<p>The polar angle, in radians (zero is up)</p>\n', 12359 'type': 'Number' 12360 }, 12361 { 12362 'name': 'phi', 12363 'description': '<p>The azimuthal angle, in radians\n (zero is out of the screen)</p>\n', 12364 'type': 'Number' 12365 }, 12366 { 12367 'name': 'length', 12368 'description': '<p>The length of the new vector (defaults to 1)</p>\n', 12369 'type': 'Number', 12370 'optional': true 12371 } 12372 ], 12373 'class': 'p5.Vector', 12374 'module': 'Math' 12375 }, 12376 'random2D': { 12377 'name': 'random2D', 12378 'class': 'p5.Vector', 12379 'module': 'Math' 12380 }, 12381 'random3D': { 12382 'name': 'random3D', 12383 'class': 'p5.Vector', 12384 'module': 'Math' 12385 } 12386 }, 12387 'p5.Font': { 12388 'font': { 12389 'name': 'font', 12390 'class': 'p5.Font', 12391 'module': 'Typography' 12392 }, 12393 'textBounds': { 12394 'name': 'textBounds', 12395 'params': [ 12396 { 12397 'name': 'line', 12398 'description': '<p>a line of text</p>\n', 12399 'type': 'String' 12400 }, 12401 { 12402 'name': 'x', 12403 'description': '<p>x-position</p>\n', 12404 'type': 'Number' 12405 }, 12406 { 12407 'name': 'y', 12408 'description': '<p>y-position</p>\n', 12409 'type': 'Number' 12410 }, 12411 { 12412 'name': 'fontSize', 12413 'description': '<p>font size to use (optional) Default is 12.</p>\n', 12414 'type': 'Number', 12415 'optional': true 12416 }, 12417 { 12418 'name': 'options', 12419 'description': '<p>opentype options (optional)\n opentype fonts contains alignment and baseline options.\n Default is \'LEFT\' and \'alphabetic\'</p>\n', 12420 'type': 'Object', 12421 'optional': true 12422 } 12423 ], 12424 'class': 'p5.Font', 12425 'module': 'Typography' 12426 }, 12427 'textToPoints': { 12428 'name': 'textToPoints', 12429 'params': [ 12430 { 12431 'name': 'txt', 12432 'description': '<p>a line of text</p>\n', 12433 'type': 'String' 12434 }, 12435 { 12436 'name': 'x', 12437 'description': '<p>x-position</p>\n', 12438 'type': 'Number' 12439 }, 12440 { 12441 'name': 'y', 12442 'description': '<p>y-position</p>\n', 12443 'type': 'Number' 12444 }, 12445 { 12446 'name': 'fontSize', 12447 'description': '<p>font size to use (optional)</p>\n', 12448 'type': 'Number' 12449 }, 12450 { 12451 'name': 'options', 12452 'description': '<p>an (optional) object that can contain:</p>\n<p><br>sampleFactor - the ratio of path-length to number of samples\n(default=.1); higher values yield more points and are therefore\nmore precise</p>\n<p><br>simplifyThreshold - if set to a non-zero value, collinear points will be\nbe removed from the polygon; the value represents the threshold angle to use\nwhen determining whether two edges are collinear</p>\n', 12453 'type': 'Object', 12454 'optional': true 12455 } 12456 ], 12457 'class': 'p5.Font', 12458 'module': 'Typography' 12459 } 12460 }, 12461 'p5.Camera': { 12462 'eyeX': { 12463 'name': 'eyeX', 12464 'class': 'p5.Camera', 12465 'module': '3D' 12466 }, 12467 'eyeY': { 12468 'name': 'eyeY', 12469 'class': 'p5.Camera', 12470 'module': '3D' 12471 }, 12472 'eyeZ': { 12473 'name': 'eyeZ', 12474 'class': 'p5.Camera', 12475 'module': '3D' 12476 }, 12477 'centerX': { 12478 'name': 'centerX', 12479 'class': 'p5.Camera', 12480 'module': '3D' 12481 }, 12482 'centerY': { 12483 'name': 'centerY', 12484 'class': 'p5.Camera', 12485 'module': '3D' 12486 }, 12487 'centerZ': { 12488 'name': 'centerZ', 12489 'class': 'p5.Camera', 12490 'module': '3D' 12491 }, 12492 'upX': { 12493 'name': 'upX', 12494 'class': 'p5.Camera', 12495 'module': '3D' 12496 }, 12497 'upY': { 12498 'name': 'upY', 12499 'class': 'p5.Camera', 12500 'module':
12500'3D' 12501 }, 12502 'upZ': { 12503 'name': 'upZ', 12504 'class': 'p5.Camera', 12505 'module': '3D' 12506 }, 12507 'perspective': { 12508 'name': 'perspective', 12509 'class': 'p5.Camera', 12510 'module': '3D' 12511 }, 12512 'ortho': { 12513 'name': 'ortho', 12514 'class': 'p5.Camera', 12515 'module': '3D' 12516 }, 12517 'frustum': { 12518 'name': 'frustum', 12519 'class': 'p5.Camera', 12520 'module': '3D' 12521 }, 12522 'pan': { 12523 'name': 'pan', 12524 'params': [ 12525 { 12526 'name': 'angle', 12527 'description': '<p>amount to rotate camera in current\n<a href="#/p5/angleMode">angleMode</a> units.\nGreater than 0 values rotate counterclockwise (to the left).</p>\n', 12528 'type': 'Number' 12529 } 12530 ], 12531 'class': 'p5.Camera', 12532 'module': '3D' 12533 }, 12534 'tilt': { 12535 'name': 'tilt', 12536 'params': [ 12537 { 12538 'name': 'angle', 12539 'description': '<p>amount to rotate camera in current\n<a href="#/p5/angleMode">angleMode</a> units.\nGreater than 0 values rotate counterclockwise (to the left).</p>\n', 12540 'type': 'Number' 12541 } 12542 ], 12543 'class': 'p5.Camera', 12544 'module': '3D' 12545 }, 12546 'lookAt': { 12547 'name': 'lookAt', 12548 'params': [ 12549 { 12550 'name': 'x', 12551 'description': '<p>x position of a point in world space</p>\n', 12552 'type': 'Number' 12553 }, 12554 { 12555 'name': 'y', 12556 'description': '<p>y position of a point in world space</p>\n', 12557 'type': 'Number' 12558 }, 12559 { 12560 'name': 'z', 12561 'description': '<p>z position of a point in world space</p>\n', 12562 'type': 'Number' 12563 } 12564 ], 12565 'class': 'p5.Camera', 12566 'module': '3D' 12567 }, 12568 'camera': { 12569 'name': 'camera', 12570 'class': 'p5.Camera', 12571 'module': '3D' 12572 }, 12573 'move': { 12574 'name': 'move', 12575 'params': [ 12576 { 12577 'name': 'x', 12578 'description': '<p>amount to move along camera\'s left-right axis</p>\n', 12579 'type': 'Number' 12580 }, 12581 { 12582 'name': 'y', 12583 'description': '<p>amount to move along camera\'s up-down axis</p>\n', 12584 'type': 'Number' 12585 }, 12586 { 12587 'name': 'z', 12588 'description': '<p>amount to move along camera\'s forward-backward axis</p>\n', 12589 'type': 'Number' 12590 } 12591 ], 12592 'class': 'p5.Camera', 12593 'module': '3D' 12594 }, 12595 'setPosition': { 12596 'name': 'setPosition', 12597 'params': [ 12598 { 12599 'name': 'x', 12600 'description': '<p>x position of a point in world space</p>\n', 12601 'type': 'Number' 12602 }, 12603 { 12604 'name': 'y', 12605 'description': '<p>y position of a point in world space</p>\n', 12606 'type': 'Number' 12607 }, 12608 { 12609 'name': 'z', 12610 'description': '<p>z position of a point in world space</p>\n', 12611 'type': 'Number' 12612 } 12613 ], 12614 'class': 'p5.Camera', 12615 'module': '3D' 12616 } 12617 }, 12618 'p5.Geometry': { 12619 'computeFaces': { 12620 'name': 'computeFaces', 12621 'class': 'p5.Geometry', 12622 'module': 'Shape' 12623 }, 12624 'computeNormals': { 12625 'name': 'computeNormals', 12626 'class': 'p5.Geometry', 12627 'module': 'Shape' 12628 }, 12629 'averageNormals': { 12630 'name': 'averageNormals', 12631 'class': 'p5.Geometry', 12632 'module': 'Shape' 12633 }, 12634 'averagePoleNormals': { 12635 'name': 'averagePoleNormals', 12636 'class': 'p5.Geometry', 12637 'module': 'Shape' 12638 }, 12639 'normalize': { 12640 'name': 'normalize', 12641 'class': 'p5.Geometry', 12642 'module': 'Shape' 12643 } 12644 }, 12645 'p5.Shader': { 12646 'setUniform': { 12647 'name': 'setUniform', 12648 'params': [ 12649 { 12650 'name': 'uniformName', 12651 'description': '<p>the name of the uniform.\nMust correspond to the name used in the vertex and fragment shaders</p>\n', 12652 'type': 'String' 12653 }, 12654 { 12655 'name': 'data', 12656 'description': '<p>the data to associate with the uniform. The type can be\na boolean (true/false), a number, an array of numbers, or\nan image (p5.Image, p5.Graphics, p5.MediaElement, p5.Texture)</p>\n', 12657 'type': 'Boolean|Number|Number[]|p5.Image|p5.Graphics|p5.MediaElement|p5.Texture' 12658 } 12659 ], 12660 'class': 'p5.Shader', 12661 'module': '3D' 12662 } 12663 }, 12664 'p5.SoundFile': { 12665 'isLoaded': { 12666 'name': 'isLoaded', 12667 'class': 'p5.SoundFile', 12668 'module': 'p5.sound' 12669 }, 12670 'play': { 12671 'name': 'play', 12672 'params': [ 12673 { 12674 'name': 'startTime', 12675 'description': '<p>(optional) schedule playback to start (in seconds from now).</p>\n', 12676 'type': 'Number', 12677 'optional': true 12678 }, 12679 { 12680 'name': 'rate', 12681 'description': '<p>(optional) playback rate</p>\n', 12682 'type': 'Number', 12683 'optional': true 12684 }, 12685 { 12686 'name': 'amp', 12687 'description': '<p>(optional) amplitude (volume)\n of playback</p>\n', 12688 'type': 'Number', 12689 'optional': true 12690 }, 12691 { 12692 'name': 'cueStart', 12693 'description': '<p>(optional) cue start time in seconds</p>\n', 12694 'type': 'Number', 12695 'optional': true 12696 }, 12697 { 12698 'name': 'duration', 12699 'description': '<p>(optional) duration of playback in seconds</p>\n', 12700 'type': 'Number', 12701 'optional': true 12702 } 12703 ], 12704 'class': 'p5.SoundFile', 12705 'module': 'p5.sound' 12706 }, 12707 'playMode': { 12708 'name': 'playMode', 12709 'params': [ 12710 { 12711 'name': 'str', 12712 'description': '<p>\'restart\' or \'sustain\' or \'untilDone\'</p>\n', 12713 'type': 'String' 12714 } 12715 ], 12716 'class': 'p5.SoundFile', 12717 'module': 'p5.sound' 12718 }, 12719 'pause': { 12720 'name': 'pause', 12721 'params': [ 12722 { 12723 'name': 'startTime', 12724 'description': '<p>(optional) schedule event to occur\n seconds from now</p>\n', 12725 'type': 'Number', 12726 'optional': true 12727 } 12728 ], 12729 'class': 'p5.SoundFile', 12730 'module': 'p5.sound' 12731 }, 12732 'loop': { 12733 'name': 'loop', 12734 'params': [ 12735 { 12736 'name': 'startTime', 12737 'description': '<p>(optional) schedule event to occur\n seconds from now</p>\n', 12738 'type': 'Number', 12739 'optional': true 12740 }, 12741 { 12742 'name': 'rate', 12743 'description': '<p>(optional) playback rate</p>\n', 12744 'type': 'Number', 12745 'optional': true 12746 }, 12747 { 12748 'name': 'amp', 12749 'description': '<p>(optional) playback volume</p>\n', 12750 'type': 'Number', 12751 'optional': true 12752 }, 12753 { 12754 'name': 'cueLoopStart', 12755 'description': '<p>(optional) startTime in seconds</p>\n', 12756 'type': 'Number', 12757 'optional': true 12758 }, 12759 { 12760 'name': 'duration', 12761 'description': '<p>(optional) loop duration in seconds</p>\n', 12762 'type': 'Number', 12763 'optional': true 12764 } 12765 ], 12766 'class': 'p5.SoundFile', 12767 'module': 'p5.sound' 12768 }, 12769 'setLoop': { 12770 'name': 'setLoop', 12771 'params': [ 12772 { 12773 'name': 'Boolean', 12774 'description': '<p>set looping to true or false</p>\n', 12775 'type': 'Boolean' 12776 } 12777 ], 12778 'class': 'p5.SoundFile', 12779 'module': 'p5.sound' 12780 }, 12781 'isLooping': { 12782 'name': 'isLooping', 12783 'class': 'p5.SoundFile', 12784 'module': 'p5.sound' 12785 }, 12786 'isPlaying': { 12787 'name': 'isPlaying', 12788 'class': 'p5.SoundFile', 12789 'module': 'p5.sound' 12790 }, 12791 'isPaused': { 12792 'name': 'isPaused', 12793 'class': 'p5.SoundFile', 12794 'module': 'p5.sound' 12795 }, 12796 'stop': { 12797 'name': 'stop', 12798 'params': [ 12799 { 12800 'name': 'startTime', 12801 'description': '<p>(optional) schedule event to occur\n in seconds from now</p>\n', 12802 'type': 'Number', 12803 'optional': true 12804 } 12805 ], 12806 'class': 'p5.SoundFile', 12807 'module': 'p5.sound' 12808 }, 12809 'pan': { 12810 'name': 'pan', 12811 'params': [ 12812 { 12813 'name': 'panValue', 12814 'description': '<p>Set the stereo panner</p>\n', 12815 'type': 'Number', 12816 'optional': true 12817 }, 12818 { 12819 'name': 'timeFromNow', 12820 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 12821 'type': 'Number', 12822 'optional': true 12823 } 12824 ], 12825 'class': 'p5.SoundFile', 12826 'module': 'p5.sound' 12827 }, 12828 'getPan': { 12829 'name': 'getPan', 12830 'class': 'p5.SoundFile', 12831 'module': 'p5.sound' 12832 }, 12833 'rate': { 12834 'name': 'rate', 12835 'params': [ 12836 { 12837 'name': 'playbackRate', 12838 'description': '<p>Set the playback rate. 1.0 is normal,\n .5 is half-speed, 2.0 is twice as fast.\n Values less than zero play backwards.</p>\n', 12839 'type': 'Number', 12840 'optional': true 12841 } 12842 ], 12843 'class': 'p5.SoundFile', 12844 'module': 'p5.sound' 12845 }, 12846 'setVolume': { 12847 'name': 'setVolume', 12848 'params': [ 12849 { 12850 'name': 'volume', 12851 'description': '<p>Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator</p>\n', 12852 'type': 'Number|Object' 12853 }, 12854 { 12855 'name': 'rampTime', 12856 'description': '<p>Fade for t seconds</p>\n', 12857 'type': 'Number', 12858 'optional': true 12859 }, 12860 { 12861 'name': 'timeFromNow', 12862 'description': '<p>Schedule this event to happen at\n t seconds
12862in the future</p>\n', 12863 'type': 'Number', 12864 'optional': true 12865 } 12866 ], 12867 'class': 'p5.SoundFile', 12868 'module': 'p5.sound' 12869 }, 12870 'duration': { 12871 'name': 'duration', 12872 'class': 'p5.SoundFile', 12873 'module': 'p5.sound' 12874 }, 12875 'currentTime': { 12876 'name': 'currentTime', 12877 'class': 'p5.SoundFile', 12878 'module': 'p5.sound' 12879 }, 12880 'jump': { 12881 'name': 'jump', 12882 'params': [ 12883 { 12884 'name': 'cueTime', 12885 'description': '<p>cueTime of the soundFile in seconds.</p>\n', 12886 'type': 'Number' 12887 }, 12888 { 12889 'name': 'duration', 12890 'description': '<p>duration in seconds.</p>\n', 12891 'type': 'Number' 12892 } 12893 ], 12894 'class': 'p5.SoundFile', 12895 'module': 'p5.sound' 12896 }, 12897 'channels': { 12898 'name': 'channels', 12899 'class': 'p5.SoundFile', 12900 'module': 'p5.sound' 12901 }, 12902 'sampleRate': { 12903 'name': 'sampleRate', 12904 'class': 'p5.SoundFile', 12905 'module': 'p5.sound' 12906 }, 12907 'frames': { 12908 'name': 'frames', 12909 'class': 'p5.SoundFile', 12910 'module': 'p5.sound' 12911 }, 12912 'getPeaks': { 12913 'name': 'getPeaks', 12914 'params': [ 12915 { 12916 'name': 'length', 12917 'description': '<p>length is the size of the returned array.\n Larger length results in more precision.\n Defaults to 5*width of the browser window.</p>\n', 12918 'type': 'Number', 12919 'optional': true 12920 } 12921 ], 12922 'class': 'p5.SoundFile', 12923 'module': 'p5.sound' 12924 }, 12925 'reverseBuffer': { 12926 'name': 'reverseBuffer', 12927 'class': 'p5.SoundFile', 12928 'module': 'p5.sound' 12929 }, 12930 'onended': { 12931 'name': 'onended', 12932 'params': [ 12933 { 12934 'name': 'callback', 12935 'description': '<p>function to call when the\n soundfile has ended.</p>\n', 12936 'type': 'Function' 12937 } 12938 ], 12939 'class': 'p5.SoundFile', 12940 'module': 'p5.sound' 12941 }, 12942 'connect': { 12943 'name': 'connect', 12944 'params': [ 12945 { 12946 'name': 'object', 12947 'description': '<p>Audio object that accepts an input</p>\n', 12948 'type': 'Object', 12949 'optional': true 12950 } 12951 ], 12952 'class': 'p5.SoundFile', 12953 'module': 'p5.sound' 12954 }, 12955 'disconnect': { 12956 'name': 'disconnect', 12957 'class': 'p5.SoundFile', 12958 'module': 'p5.sound' 12959 }, 12960 'setPath': { 12961 'name': 'setPath', 12962 'params': [ 12963 { 12964 'name': 'path', 12965 'description': '<p>path to audio file</p>\n', 12966 'type': 'String' 12967 }, 12968 { 12969 'name': 'callback', 12970 'description': '<p>Callback</p>\n', 12971 'type': 'Function' 12972 } 12973 ], 12974 'class': 'p5.SoundFile', 12975 'module': 'p5.sound' 12976 }, 12977 'setBuffer': { 12978 'name': 'setBuffer', 12979 'params': [ 12980 { 12981 'name': 'buf', 12982 'description': '<p>Array of Float32 Array(s). 2 Float32 Arrays\n will create a stereo source. 1 will create\n a mono source.</p>\n', 12983 'type': 'Array' 12984 } 12985 ], 12986 'class': 'p5.SoundFile', 12987 'module': 'p5.sound' 12988 }, 12989 'addCue': { 12990 'name': 'addCue', 12991 'params': [ 12992 { 12993 'name': 'time', 12994 'description': '<p>Time in seconds, relative to this media\n element\'s playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.</p>\n', 12995 'type': 'Number' 12996 }, 12997 { 12998 'name': 'callback', 12999 'description': '<p>Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.</p>\n', 13000 'type': 'Function' 13001 }, 13002 { 13003 'name': 'value', 13004 'description': '<p>An object to be passed as the\n second parameter to the\n callback function.</p>\n', 13005 'type': 'Object', 13006 'optional': true 13007 } 13008 ], 13009 'class': 'p5.SoundFile', 13010 'module': 'p5.sound' 13011 }, 13012 'removeCue': { 13013 'name': 'removeCue', 13014 'params': [ 13015 { 13016 'name': 'id', 13017 'description': '<p>ID of the cue, as returned by addCue</p>\n', 13018 'type': 'Number' 13019 } 13020 ], 13021 'class': 'p5.SoundFile', 13022 'module': 'p5.sound' 13023 }, 13024 'clearCues': { 13025 'name': 'clearCues', 13026 'class': 'p5.SoundFile', 13027 'module': 'p5.sound' 13028 },
13029 'save': { 13030 'name': 'save', 13031 'params': [ 13032 { 13033 'name': 'fileName', 13034 'description': '<p>name of the resulting .wav file.</p>\n', 13035 'type': 'String', 13036 'optional': true 13037 } 13038 ], 13039 'class': 'p5.SoundFile', 13040 'module': 'p5.sound' 13041 }, 13042 'getBlob': { 13043 'name': 'getBlob', 13044 'class': 'p5.SoundFile', 13045 'module': 'p5.sound' 13046 } 13047 }, 13048 'p5.Amplitude': { 13049 'setInput': { 13050 'name': 'setInput', 13051 'params': [ 13052 { 13053 'name': 'snd', 13054 'description': '<p>set the sound source\n (optional, defaults to\n main output)</p>\n', 13055 'type': 'SoundObject|undefined', 13056 'optional': true 13057 }, 13058 { 13059 'name': 'smoothing', 13060 'description': '<p>a range between 0.0 and 1.0\n to smooth amplitude readings</p>\n', 13061 'type': 'Number|undefined', 13062 'optional': true 13063 } 13064 ], 13065 'class': 'p5.Amplitude', 13066 'module': 'p5.sound' 13067 }, 13068 'getLevel': { 13069 'name': 'getLevel', 13070 'params': [ 13071 { 13072 'name': 'channel', 13073 'description': '<p>Optionally return only channel 0 (left) or 1 (right)</p>\n', 13074 'type': 'Number', 13075 'optional': true 13076 } 13077 ], 13078 'class': 'p5.Amplitude', 13079 'module': 'p5.sound' 13080 }, 13081 'toggleNormalize': { 13082 'name': 'toggleNormalize', 13083 'params': [ 13084 { 13085 'name': 'boolean', 13086 'description': '<p>set normalize to true (1) or false (0)</p>\n', 13087 'type': 'Boolean', 13088 'optional': true 13089 } 13090 ], 13091 'class': 'p5.Amplitude', 13092 'module': 'p5.sound' 13093 }, 13094 'smooth': { 13095 'name': 'smooth', 13096 'params': [ 13097 { 13098 'name': 'set', 13099 'description': '<p>smoothing from 0.0 <= 1</p>\n', 13100 'type': 'Number' 13101 } 13102 ], 13103 'class': 'p5.Amplitude', 13104 'module': 'p5.sound' 13105 } 13106 }, 13107 'p5.FFT': { 13108 'setInput': { 13109 'name': 'setInput', 13110 'params': [ 13111 { 13112 'name': 'source', 13113 'description': '<p>p5.sound object (or web audio API source node)</p>\n', 13114 'type': 'Object', 13115 'optional': true 13116 } 13117 ], 13118 'class': 'p5.FFT', 13119 'module': 'p5.sound' 13120 }, 13121 'waveform': { 13122 'name': 'waveform', 13123 'params': [ 13124 { 13125 'name': 'bins', 13126 'description': '<p>Must be a power of two between\n 16 and 1024. Defaults to 1024.</p>\n', 13127 'type': 'Number', 13128 'optional': true 13129 }, 13130 { 13131 'name': 'precision', 13132 'description': '<p>If any value is provided, will return results\n in a Float32 Array which is more precise\n than a regular array.</p>\n', 13133 'type': 'String', 13134 'optional': true 13135 } 13136 ], 13137 'class': 'p5.FFT', 13138 'module': 'p5.sound' 13139 }, 13140 'analyze': { 13141 'name': 'analyze', 13142 'params': [ 13143 { 13144 'name': 'bins', 13145 'description': '<p>Must be a power of two between\n 16 and 1024. Defaults to 1024.</p>\n', 13146 'type': 'Number', 13147 'optional': true 13148 }, 13149 { 13150 'name': 'scale', 13151 'description': '<p>If "dB," returns decibel\n float measurements between\n -14
131510 and 0 (max).\n Otherwise returns integers from 0-255.</p>\n', 13152 'type': 'Number', 13153 'optional': true 13154 } 13155 ], 13156 'class': 'p5.FFT', 13157 'module': 'p5.sound' 13158 }, 13159 'getEnergy': { 13160 'name': 'getEnergy', 13161 'params': [ 13162 { 13163 'name': 'frequency1', 13164 'description': '<p>Will return a value representing\n energy at this frequency. Alternately,\n the strings "bass", "lowMid" "mid",\n "highMid", and "treble" will return\n predefined frequency ranges.</p>\n', 13165 'type': 'Number|String' 13166 }, 13167 { 13168 'name': 'frequency2', 13169 'description': '<p>If a second frequency is given,\n will return average amount of\n energy that exists between the\n two frequencies.</p>\n', 13170 'type': 'Number', 13171 'optional': true 13172 } 13173 ], 13174 'class': 'p5.FFT', 13175 'module': 'p5.sound' 13176 }, 13177 'getCentroid': { 13178 'name': 'getCentroid', 13179 'class': 'p5.FFT', 13180 'module': 'p5.sound' 13181 }, 13182 'smooth': { 13183 'name': 'smooth', 13184 'params': [ 13185 { 13186 'name': 'smoothing', 13187 'description': '<p>0.0 < smoothing < 1.0.\n Defaults to 0.8.</p>\n', 13188 'type': 'Number' 13189 } 13190 ], 13191 'class': 'p5.FFT', 13192 'module': 'p5.sound' 13193 }, 13194 'linAverages': { 13195 'name': 'linAverages', 13196 'params': [ 13197 { 13198 'name': 'N', 13199 'description': '<p>Number of returned frequency groups</p>\n', 13200 'type': 'Number' 13201 } 13202 ], 13203 'class': 'p5.FFT', 13204 'module': 'p5.sound' 13205 }, 13206 'logAverages': { 13207 'name': 'logAverages', 13208 'params': [ 13209 { 13210 'name': 'octaveBands', 13211 'description': '<p>Array of Octave Bands objects for grouping</p>\n', 13212 'type': 'Array' 13213 } 13214 ], 13215 'class': 'p5.FFT', 13216 'module': 'p5.sound' 13217 }, 13218 'getOctaveBands': { 13219 'name': 'getOctaveBands', 13220 'params': [ 13221 { 13222 'name': 'N', 13223 'description': '<p>Specifies the 1/N type of generated octave bands</p>\n', 13224 'type': 'Number' 13225 }, 13226 { 13227 'name': 'fCtr0', 13228 'description': '<p>Minimum central frequency for the lowest band</p>\n', 13229 'type': 'Number' 13230 } 13231 ], 13232 'class': 'p5.FFT', 13233 'module': 'p5.sound' 13234 } 13235 }, 13236 'p5.Oscillator': { 13237 'start': { 13238 'name': 'start', 13239 'params': [ 13240 { 13241 'name': 'time', 13242 'description': '<p>startTime in seconds from now.</p>\n', 13243 'type': 'Number', 13244 'optional': true 13245 }, 13246 { 13247 'name': 'frequency', 13248 'description': '<p>frequency in Hz.</p>\n', 13249 'type': 'Number', 13250 'optional': true 13251 } 13252 ], 13253 'class': 'p5.Oscillator', 13254 'module': 'p5.sound' 13255 }, 13256 'stop': { 13257 'name': 'stop', 13258 'params': [ 13259 { 13260 'name': 'secondsFromNow', 13261 'description': '<p>Time, in seconds from now.</p>\n', 13262 'type': 'Number' 13263 } 13264 ], 13265 'class': 'p5.Oscillator', 13266 'module': 'p5.sound' 13267 }, 13268 'amp': { 13269 'name': 'amp', 13270 'params': [ 13271 { 13272 'name': 'vol', 13273 'description': '<p>between 0 and 1.0\n or a modulating signal/oscillator</p>\n', 13274 'type': 'Number|Object' 13275 }, 13276 { 13277 'name': 'rampTime', 13278 'description': '<p>create a fade that lasts rampTime</p>\n', 13279 'type': 'Number', 13280 'optional': true 13281 }, 13282 { 13283 'name': 'timeFromNow', 13284 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 13285 'type': 'Number', 13286 'optional': true 13287 } 13288 ], 13289 'class': 'p5.Oscillator', 13290 'module': 'p5.sound' 13291 }, 13292 'getAmp': { 13293 'name': 'getAmp', 13294 'class': 'p5.Oscillator', 13295 'module': 'p5.sound' 13296 }, 13297 'freq': { 13298 'name': 'freq', 13299 'params': [ 13300 { 13301 'name': 'Frequency', 13302 'description': '<p>Frequency in Hz\n or modulating signal/oscillator</p>\n', 13303 'type': 'Number|Object' 13304 }, 13305 { 13306 'name': 'rampTime', 13307 'description': '<p>Ramp time (in seconds)</p>\n', 13308 'type': 'Number', 13309 'optional': true 13310 }, 13311 { 13312 'name': 'timeFromNow', 13313 'description': '<p>Schedule this event to happen\n at x seconds from now</p>\n', 13314 'type': 'Number', 13315 'optional': true 13316 } 13317 ], 13318 'class': 'p5.Oscillator', 13319 'module': 'p5.sound' 13320 }, 13321 'getFreq': { 13322 'name': 'getFreq', 13323 'class': 'p5.Oscillator', 13324 'module': 'p5.sound' 13325 }, 13326 'setType': { 13327 'name': 'setType', 13328 'params': [ 13329 { 13330 'name': 'type', 13331 'description': '<p>\'sine\', \'triangle\', \'sawtooth\' or \'square\'.</p>\n', 13332 'type': 'String' 13333 } 13334 ], 13335 'class': 'p5.Oscillator', 13336 'module': 'p5.sound' 13337 }, 13338 'getType': { 13339 'name': 'getType', 13340 'class': 'p5.Oscillator', 13341 'module': 'p5.sound' 13342 }, 13343 'connect': { 13344 'name': 'connect', 13345 'params': [ 13346 { 13347 'name': 'unit', 13348 'description': '<p>A p5.sound or Web Audio object</p>\n', 13349 'type': 'Object' 13350 } 13351 ], 13352 'class': 'p5.Oscillator', 13353 'module': 'p5.sound' 13354 }, 13355 'disconnect': { 13356 'name': 'disconnect', 13357 'class': 'p5.Oscillator', 13358 'module': 'p5.sound' 13359 }, 13360 'pan': { 13361 'name': 'pan', 13362 'params': [ 13363 { 13364 'name': 'panning', 13365 'description': '<p>Number between -1 and 1</p>\n', 13366 'type': 'Number' 13367 }, 13368 { 13369 'name': 'timeFromNow', 13370 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 13371 'type': 'Number' 13372 } 13373 ], 13374 'class': 'p5.Oscillator', 13375 'module': 'p5.sound' 13376 }, 13377 'getPan': { 13378 'name': 'getPan', 13379 'class': 'p5.Oscillator', 13380 'module': 'p5.sound' 13381 }, 13382 'phase': { 13383 'name': 'phase', 13384 'params': [ 13385 { 13386 'name': 'phase', 13387 'description': '<p>float between 0.0 and 1.0</p>\n', 13388 'type': 'Number' 13389 } 13390 ], 13391 'class': 'p5.Oscillator', 13392 'module': 'p5.sound' 13393 }, 13394 'add': { 13395 'name': 'add', 13396 'params': [ 13397 { 13398 'name': 'number', 13399 'description': '<p>Constant number to add</p>\n', 13400 'type': 'Number' 13401 } 13402 ], 13403 'class': 'p5.Oscillator', 13404 'module': 'p5.sound' 13405 }, 13406 'mult': { 13407 'name': 'mult', 13408 'params': [ 13409 { 13410 'name': 'number', 13411 'description': '<p>Constant number to multiply</p>\n', 13412 'type': 'Number' 13413 } 13414 ], 13415 'class': 'p5.Oscillator', 13416 'module': 'p5.sound' 13417 }, 13418 'scale': { 13419 'name': 'scale', 13420 'params': [ 13421 { 13422 'name': 'inMin', 13423 'description': '<p>input range minumum</p>\n', 13424 'type': 'Number' 13425 }, 13426 { 13427 'name': 'inMax', 13428 'description': '<p>input range maximum</p>\n', 13429 'type': 'Number' 13430 }, 13431 { 13432 'name': 'outMin', 13433 'description': '<p>input range minumum</p>\n', 13434 'type': 'Number' 13435 }, 13436 { 13437 'name': 'outMax', 13438 'description': '<p>input range maximum</p>\n', 13439 'type': 'Number' 13440 } 13441 ], 13442 'class': 'p5.Oscillator', 13443 'module': 'p5.sound' 13444 } 13445 },
13446 'p5.Envelope': { 13447 'attackTime': { 13448 'name': 'attackTime', 13449 'class': 'p5.Envelope', 13450 'module': 'p5.sound' 13451 }, 13452 'attackLevel': { 13453 'name': 'attackLevel', 13454 'class': 'p5.Envelope', 13455 'module': 'p5.sound' 13456 }, 13457 'decayTime': { 13458 'name': 'decayTime', 13459 'class': 'p5.Envelope', 13460 'module': 'p5.sound' 13461 }, 13462 'decayLevel': { 13463 'name': 'decayLevel', 13464 'class': 'p5.Envelope', 13465 'module': 'p5.sound' 13466 }, 13467 'releaseTime': { 13468 'name': 'releaseTime', 13469 'class': 'p5.Envelope', 13470 'module': 'p5.sound' 13471 }, 13472 'releaseLevel': { 13473 'name': 'releaseLevel', 13474 'class': 'p5.Envelope', 13475 'module': 'p5.sound' 13476 }, 13477 'set': { 13478 'name': 'set', 13479 'params': [ 13480 { 13481 'name': 'attackTime', 13482 'description': '<p>Time (in seconds) before level\n reaches attackLevel</p>\n', 13483 'type': 'Number' 13484 }, 13485 { 13486 'name': 'attackLevel', 13487 'description': '<p>Typically an amplitude between\n 0.0 and 1.0</p>\n', 13488 'type': 'Number' 13489 }, 13490 { 13491 'name': 'decayTime', 13492 'description': '<p>Time</p>\n', 13493 'type': 'Number' 13494 }, 13495 { 13496 'name': 'decayLevel', 13497 'description': '<p>Amplitude (In a standard ADSR envelope,\n decayLevel = sustainLevel)</p>\n', 13498 'type': 'Number' 13499 }, 13500 { 13501 'name': 'releaseTime', 13502 'description': '<p>Release Time (in seconds)</p>\n', 13503 'type': 'Number' 13504 }, 13505 { 13506 'name': 'releaseLevel', 13507 'description': '<p>Amplitude</p>\n', 13508 'type': 'Number' 13509 } 13510 ], 13511 'class': 'p5.Envelope', 13512 'module': 'p5.sound' 13513 }, 13514 'setADSR': { 13515 'name': 'setADSR', 13516 'params': [ 13517 { 13518 'name': 'attackTime', 13519 'description': '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n', 13520 'type': 'Number' 13521 }, 13522 { 13523 'name': 'decayTime', 13524 'description': '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n', 13525 'type': 'Number', 13526 'optional': true 13527 }, 13528 { 13529 'name': 'susRatio', 13530 'description': '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n', 13531 'type': 'Number', 13532 'optional': true 13533 }, 13534 { 13535 'name': 'releaseTime', 13536 'description': '<p>Time in seconds from now (defaults to 0)</p>\n', 13537 'type': 'Number', 13538 'optional': true 13539 } 13540 ], 13541 'class': 'p5.Envelope', 13542 'module': 'p5.sound' 13543 }, 13544 'setRange': { 13545 'name': 'setRange', 13546 'params': [ 13547 { 13548 'name': 'aLevel', 13549 'description': '<p>attack level (defaults to 1)</p>\n', 13550 'type': 'Number' 13551 }, 13552 { 13553 'name': 'rLevel', 13554 'description': '<p>release level (defaults to 0)</p>\n', 13555 'type': 'Number' 13556 } 13557 ], 13558 'class': 'p5.Envelope', 13559 'module': 'p5.sound' 13560 }, 13561 'setInput': { 13562 'name': 'setInput', 13563 'params': [ 13564 { 13565 'name': 'inputs', 13566 'description': '<p>A p5.sound object or\n Web Audio Param.</p>\n', 13567 'type': 'Object', 13568 'optional': true, 13569 'multiple': true 13570 } 13571 ], 13572 'class': 'p5.Envelope', 13573 'module': 'p5.sound' 13574 }, 13575 'setExp': { 13576 'name': 'setExp', 13577 'params': [ 13578 { 13579 'name': 'isExp', 13580 'description': '<p>true is exponential, false is linear</p>\n', 13581 'type': 'Boolean' 13582 } 13583 ], 13584 'class': 'p5.Envelope', 13585 'module': 'p5.sound' 13586 }, 13587 'play': { 13588 'name': 'play', 13589 'params': [ 13590 { 13591 'name': 'unit', 13592 'description': '<p>A p5.sound object or\n Web Audio Param.</p>\n', 13593 'type': 'Object' 13594 }, 13595 { 13596 'name': 'startTime', 13597 'description': '<p>time from now (in seconds) at which to play</p>\n', 13598 'type': 'Number', 13599 'optional': true 13600 }, 13601 { 13602 'name': 'sustainTime', 13603 'description': '<p>time to sustain before releasing the envelope</p>\n', 13604 'type': 'Number', 13605 'optional': true 13606 } 13607 ], 13608 'class': 'p5.Envelope', 13609 'module': 'p5.sound' 13610 }, 13611 'triggerAttack': { 13612 'name': 'triggerAttack', 13613 'params': [ 13614 { 13615 'name': 'unit', 13616 'description': '<p>p5.sound Object or Web Audio Param</p>\n', 13617 'type': 'Object' 13618 }, 13619 { 13620 'name': 'secondsFromNow', 13621 'description': '<p>time from now (in seconds)</p>\n', 13622 'type': 'Number' 13623 } 13624 ], 13625 'class': 'p5.Envelope', 13626 'module': 'p5.sound' 13627 }, 13628 'triggerRelease': { 13629 'name': 'triggerRelease', 13630 'params': [ 13631 { 13632 'name': 'unit', 13633 'description': '<p>p5.sound Object or Web Audio Param</p>\n', 13634 'type': 'Object' 13635 }, 13636 { 13637 'name': 'secondsFromNow', 13638 'description': '<p>time to trigger the release</p>\n', 13639 'type': 'Number' 13640 } 13641 ], 13642 'class': 'p5.Envelope', 13643 'module': 'p5.sound' 13644 }, 13645 'ramp': { 13646 'name': 'ramp', 13647 'params': [ 13648 { 13649 'name': 'unit', 13650 'description': '<p>p5.sound Object or Web Audio Param</p>\n', 13651 'type': 'Object' 13652 }, 13653 { 13654 'name': 'secondsFromNow', 13655 'description': '<p>When to trigger the ramp</p>\n', 13656 'type': 'Number' 13657 }, 13658 { 13659 'name': 'v', 13660 'description': '<p>Target value</p>\n', 13661 'type': 'Number' 13662 }, 13663 { 13664 'name': 'v2', 13665 'description': '<p>Second target value</p>\n', 13666 'type': 'Number', 13667 'optional': true 13668 } 13669 ], 13670 'class': 'p5.Envelope', 13671 'module': 'p5.sound' 13672 }, 13673 'add': { 13674 'name': 'add', 13675 'params': [ 13676 { 13677 'name': 'number', 13678 'description': '<p>Constant number to add</p>\n', 13679 'type': 'Number' 13680 } 13681 ], 13682 'class': 'p5.Envelope', 13683 'module': 'p5.sound' 13684 }, 13685 'mult': { 13686 'name': 'mult', 13687 'params': [ 13688 { 13689 'name': 'number', 13690 'description': '<p>Constant number to multiply</p>\n', 13691 'type': 'Number' 13692 } 13693 ], 13694 'class': 'p5.Envelope', 13695 'module': 'p5.sound' 13696 }, 13697 'scale': { 13698 'name': 'scale', 13699 'params': [ 13700 { 13701 'name': 'inMin', 13702 'description': '<p>input range minumum</p>\n', 13703 'type': 'Number' 13704 }, 13705 { 13706 'name': 'inMax', 13707 'description': '<p>input range maximum</p>\n', 13708 'type': 'Number' 13709 }, 13710 { 13711 'name': 'outMin', 13712 'description': '<p>input range minumum</p>\n', 13713 'type': 'Number' 13714 }, 13715 { 13716 'name': 'outMax', 13717 'description': '<p>input range maximum</p>\n', 13718 'type': 'Number' 13719 } 13720 ], 13721 'class': 'p5.Envelope', 13722 'module': 'p5.sound' 13723 } 13724 }, 13725 'p5.Noise': { 13726 'setType': { 13727 'name': 'setType', 13728 'params': [ 13729 { 13730 'name': 'type', 13731 'description': '<p>\'white\', \'pink\' or \'brown\'</p>\n', 13732 'type': 'String', 13733 'optional': true 13734 } 13735 ], 13736 'class': 'p5.Noise', 13737 'module': 'p5.sound' 13738 } 13739 }, 13740 'p5.Pulse': { 13741 'width': { 13742 'name': 'width', 13743 'params': [ 13744 { 13745 'name': 'width', 13746 'description': '<p>Width between the pulses (0 to 1.0,\n defaults to 0)</p>\n', 13747 'type': 'Number', 13748 'optional': true 13749 } 13750 ], 13751 'class': 'p5.Pulse', 13752 'module': 'p5.sound' 13753 } 13754 }, 13755 'p5.AudioIn': { 13756 'input': { 13757 'name': 'input', 13758 'class': 'p5.AudioIn', 13759 'module': 'p5.sound' 13760 }, 13761 'output': { 13762 'name': 'output', 13763 'class': 'p5.AudioIn', 13764 'module': 'p5.sound' 13765 }, 13766 'stream': { 13767 'name': 'stream', 13768 'class': 'p5.AudioIn', 13769 'module': 'p5.sound' 13770 }, 13771 'mediaStream': { 13772 'name': 'mediaStream', 13773 'class': 'p5.AudioIn', 13774 'module': 'p5.sound' 13775 }, 13776 'currentSource': { 13777 'name': 'currentSource', 13778 'class': 'p5.AudioIn', 13779 'module': 'p5.sound' 13780 }, 13781 'enabled': { 13782 'name': 'enabled', 13783 'class': 'p5.AudioIn', 13784 'module': 'p5.sound' 13785 }, 13786 'amplitude': { 13787 'name': 'amplitude', 13788 'class': 'p5.AudioIn', 13789 'module': 'p5.sound' 13790 }, 13791 'start': { 13792 'name': 'start', 13793 'params': [ 13794 { 13795 'name': 'successCallback', 13796 'description': '<p>Name of a function to call on\n success.</p>\n', 13797 'type': 'Function', 13798 'optional': true 13799 }, 13800 { 13801 'name': 'errorCallback', 13802 'description': '<p>Name of a function to call if\n there was an error. For example,\n some browsers do not support\n getUserMedia.</p>\n', 13803 'type': 'Function', 13804 'optional': true 13805 } 13806 ], 13807 'class': 'p5.AudioIn', 13808 'module': 'p5.sound' 13809 }, 13810 'stop': { 13811 'name': 'stop', 13812 'class': 'p5.AudioIn', 13813 'module': 'p5.sound' 13814 }, 13815 'connect': { 13816 'name': 'connect', 13817 'params': [ 13818 { 13819 'name': 'unit', 13820 'description': '<p>An object that accepts audio input,\n such as an FFT</p>\n', 13821 'type': 'Object', 13822 'optional': true 13823 } 13824 ], 13825 'class': 'p5.AudioIn', 13826 'module': 'p5.sound' 13827 }, 13828 'disconnect': { 13829 'name': 'disconnect', 13830 'class': 'p5.AudioIn', 13831 'module': 'p5.sound' 13832 }, 13833 'getLevel': { 13834 'name': 'getLevel', 13835 'params': [ 13836 { 13837 'name': 'smoothing', 13838 'description': '<p>Smoothing is 0.0 by default.\n Smooths values based on previous values.</p>\n', 13839 'type': 'Number', 13840 'optional': true 13841 } 13842 ], 13843 'class': 'p5.AudioIn', 13844 'module': 'p5.sound' 13845 }, 13846 'amp': { 13847 'name': 'amp', 13848 'params': [ 13849 { 13850 'name': 'vol', 13851 'description': '<p>between 0 and 1.0</p>\n', 13852 'type': 'Number' 13853 }, 13854 { 13855 'name': 'time', 13856 'description': '<p>ramp time (optional)</p>\n', 13857 'type': 'Number', 13858 'optional': true 13859 } 13860 ], 13861 'class': 'p5.AudioIn', 13862 'module': 'p5.sound' 13863 }, 13864 'getSources': { 13865 'name': 'getSources', 13866 'params': [ 13867 { 13868 'name': 'successCallback', 13869 'description': '<p>This callback function handles the sources when they\n have been enumerated. The callback function\n receives the deviceList array as its only argument</p>\n', 13870 'type': 'Function', 13871 'optional': true 13872 }, 13873 { 13874 'name': 'errorCallback', 13875 'description': '<p>This optional callback receives the error\n message as its argument.</p>\n', 13876 'type': 'Function', 13877 'optional': true 13878 } 13879 ], 13880 'class': 'p5.AudioIn', 13881 'module': 'p5.sound' 13882 }, 13883 'setSource': { 13884 'name': 'setSource', 13885 'params': [ 13886 { 13887 'name': 'num', 13888 'description': '<p>position of input source in the array</p>\n', 13889 'type': 'Number' 13890 } 13891 ], 13892 'class': 'p5.AudioIn', 13893 'module': 'p5.sound' 13894 } 13895 },
13896 'p5.Effect': { 13897 'amp': { 13898 'name': 'amp', 13899 'params': [ 13900 { 13901 'name': 'vol', 13902 'description': '<p>amplitude between 0 and 1.0</p>\n', 13903 'type': 'Number', 13904 'optional': true 13905 }, 13906 { 13907 'name': 'rampTime', 13908 'description': '<p>create a fade that lasts until rampTime</p>\n', 13909 'type': 'Number', 13910 'optional': true 13911 }, 13912 { 13913 'name': 'tFromNow', 13914 'description': '<p>schedule this event to happen in tFromNow seconds</p>\n', 13915 'type': 'Number', 13916 'optional': true 13917 } 13918 ], 13919 'class': 'p5.Effect', 13920 'module': 'p5.sound' 13921 }, 13922 'chain': { 13923 'name': 'chain', 13924 'params': [ 13925 { 13926 'name': 'arguments', 13927 'description': '<p>Chain together multiple sound objects</p>\n', 13928 'type': 'Object', 13929 'optional': true 13930 } 13931 ], 13932 'class': 'p5.Effect', 13933 'module': 'p5.sound' 13934 }, 13935 'drywet': { 13936 'name': 'drywet', 13937 'params': [ 13938 { 13939 'name': 'fade', 13940 'description': '<p>The desired drywet value (0 - 1.0)</p>\n', 13941 'type': 'Number', 13942 'optional': true 13943 } 13944 ], 13945 'class': 'p5.Effect', 13946 'module': 'p5.sound' 13947 }, 13948 'connect': { 13949 'name': 'connect', 13950 'params': [ 13951 { 13952 'name': 'unit', 13953 'description': '', 13954 'type': 'Object' 13955 } 13956 ], 13957 'class': 'p5.Effect', 13958 'module': 'p5.sound' 13959 }, 13960 'disconnect': { 13961 'name': 'disconnect', 13962 'class': 'p5.Effect', 13963 'module': 'p5.sound' 13964 } 13965 }, 13966 'p5.Filter': { 13967 'biquadFilter': { 13968 'name': 'biquadFilter', 13969 'class': 'p5.Filter', 13970 'module': 'p5.sound' 13971 }, 13972 'process': { 13973 'name': 'process', 13974 'params': [ 13975 { 13976 'name': 'Signal', 13977 'description': '<p>An object that outputs audio</p>\n', 13978 'type': 'Object' 13979 }, 13980 { 13981 'name': 'freq', 13982 'description': '<p>Frequency in Hz, from 10 to 22050</p>\n', 13983 'type': 'Number', 13984 'optional': true 13985 }, 13986 { 13987 'name': 'res', 13988 'description': '<p>Resonance/Width of the filter frequency\n from 0.001 to 1000</p>\n', 13989 'type': 'Number', 13990 'optional': true 13991 } 13992 ], 13993 'class': 'p5.Filter', 13994 'module': 'p5.sound' 13995 }, 13996 'set': { 13997 'name': 'set', 13998 'params': [ 13999 { 14000 'name': 'freq', 14001 'description': '<p>Frequency in Hz, from 10 to 22050</p>\n', 14002 'type': 'Number', 14003 'optional': true 14004 }, 14005 { 14006 'name': 'res', 14007 'description': '<p>Resonance (Q) from 0.001 to 1000</p>\n', 14008 'type': 'Number', 14009 'optional': true 14010 }, 14011 { 14012 'name': 'timeFromNow', 14013 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 14014 'type': 'Number', 14015 'optional': true 14016 } 14017 ], 14018 'class': 'p5.Filter', 14019 'module': 'p5.sound' 14020 }, 14021 'freq': { 14022 'name': 'freq', 14023 'params': [ 14024 { 14025 'name': 'freq', 14026 'description': '<p>Filter Frequency</p>\n', 14027 'type': 'Number' 14028 }, 14029 { 14030 'name': 'timeFromNow', 14031 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 14032 'type': 'Number', 14033 'optional': true 14034 } 14035 ], 14036 'class': 'p5.Filter', 14037 'module': 'p5.sound' 14038 }, 14039 'res': { 14040 'name': 'res', 14041 'params': [ 14042 { 14043 'name': 'res', 14044 'description': '<p>Resonance/Width of filter freq\n from 0.001 to 1000</p>\n', 14045 'type': 'Number' 14046 }, 14047 { 14048 'name': 'timeFromNow', 14049 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 14050 'type': 'Number', 14051 'optional': true 14052 } 14053 ], 14054 'class': 'p5.Filter', 14055 'module': 'p5.sound' 14056 }, 14057 'gain': { 14058 'name': 'gain', 14059 'params': [ 14060 { 14061 'name': 'gain', 14062 'description': '', 14063 'type': 'Number' 14064 } 14065 ], 14066 'class': 'p5.Filter', 14067 'module': 'p5.sound' 14068 }, 14069 'toggle': { 14070 'name': 'toggle', 14071 'class': 'p5.Filter', 14072 'module': 'p5.sound' 14073 }, 14074 'setType': { 14075 'name': 'setType', 14076 'params': [ 14077 { 14078 'name': 't', 14079 'description': '', 14080 'type': 'String' 14081 } 14082 ], 14083 'class': 'p5.Filter', 14084 'module': 'p5.sound' 14085 } 14086 }, 14087 'p5.EQ': { 14088 'bands': { 14089 'name': 'bands', 14090 'class': 'p5.EQ', 14091 'module': 'p5.sound' 14092 }, 14093 'process': { 14094 'name': 'process', 14095 'params': [ 14096 { 14097 'name': 'src', 14098 'description': '<p>Audio source</p>\n', 14099 'type': 'Object' 14100 } 14101 ], 14102 'class': 'p5.EQ', 14103 'module': 'p5.sound' 14104 } 14105 }, 14106 'p5.Panner3D': { 14107 'panner': { 14108 'name': 'panner', 14109 'class': 'p5.Panner3D', 14110 'module': 'p5.sound' 14111 }, 14112 'process': { 14113 'name': 'process', 14114 'params': [ 14115 { 14116 'name': 'src', 14117 'description': '<p>Input source</p>\n', 14118 'type': 'Object' 14119 } 14120 ], 14121 'class': 'p5.Panner3D', 14122 'module': 'p5.sound' 14123 }, 14124 'set': { 14125 'name': 'set', 14126 'params': [ 14127 { 14128 'name': 'xVal', 14129 'description': '', 14130 'type': 'Number' 14131 }, 14132 { 14133 'name': 'yVal', 14134 'description': '', 14135 'type': 'Number' 14136 }, 14137 { 14138 'name': 'zVal', 14139 'description': '', 14140 'type': 'Number' 14141 }, 14142 { 14143 'name': 'time', 14144 'description': '', 14145 'type': 'Number' 14146 } 14147 ], 14148 'class': 'p5.Panner3D', 14149 'module': 'p5.sound' 14150 }, 14151 'positionX': { 14152 'name': 'positionX', 14153 'class': 'p5.Panner3D', 14154 'module': 'p5.sound' 14155 }, 14156 'positionY': { 14157 'name': 'positionY', 14158 'class': 'p5.Panner3D', 14159 'module': 'p5.sound' 14160 }, 14161 'positionZ': { 14162 'name': 'positionZ', 14163 'class': 'p5.Panner3D', 14164 'module': 'p5.sound' 14165 }, 14166 'orient': { 14167 'name': 'orient', 14168 'params': [ 14169 { 14170 'name': 'xVal', 14171 'description': '', 14172 'type': 'Number' 14173 }, 14174 { 14175 'name': 'yVal', 14176 'description': '', 14177 'type': 'Number' 14178 }, 14179 { 14180 'name': 'zVal', 14181 'description': '', 14182 'type': 'Number' 14183 }, 14184 { 14185 'name': 'time', 14186 'description': '', 14187 'type': 'Number' 14188 } 14189 ], 14190 'class': 'p5.Panner3D', 14191 'module': 'p5.sound' 14192 }, 14193 'orientX': { 14194 'name': 'orientX', 14195 'class': 'p5.Panner3D', 14196 'module': 'p5.sound' 14197 }, 14198 'orientY': { 14199 'name': 'orientY', 14200 'class': 'p5.Panner3D', 14201 'module': 'p5.sound' 14202 }, 14203 'orientZ': { 14204 'name': 'orientZ', 14205 'class': 'p5.Panner3D', 14206 'module': 'p5.sound' 14207 }, 14208 'setFalloff': { 14209 'name': 'setFalloff', 14210 'params': [ 14211 { 14212 'name': 'maxDistance', 14213 'description': '', 14214 'type': 'Number', 14215 'optional': true 14216 }, 14217 { 14218 'name': 'rolloffFactor', 14219 'description': '', 14220 'type': 'Number', 14221 'optional': true 14222 } 14223 ], 14224 'class': 'p5.Panner3D', 14225 'module': 'p5.sound' 14226 }, 14227 'maxDist': { 14228 'name': 'maxDist', 14229 'params': [ 14230 { 14231 'name': 'maxDistance', 14232 'description': '', 14233 'type': 'Number' 14234 } 14235 ], 14236 'class': 'p5.Panner3D', 14237 'module': 'p5.sound' 14238 }, 14239 'rollof': { 14240 'name': 'rollof', 14241 'params': [ 14242 { 14243 'name': 'rolloffFactor', 14244 'description': '', 14245 'type': 'Number' 14246 } 14247 ], 14248 'class': 'p5.Panner3D', 14249 'module': 'p5.sound' 14250 } 14251 }, 14252 'p5.Delay': { 14253 'leftDelay': { 14254 'name': 'leftDelay', 14255 'class': 'p5.Delay', 14256 'module': 'p5.sound' 14257 }, 14258 'rightDelay': { 14259 'name': 'rightDelay', 14260 'class': 'p5.Delay', 14261 'module': 'p5.sound' 14262 }, 14263 'process': { 14264 'name': 'process', 14265 'params': [ 14266 { 14267 'name': 'Signal', 14268 'description': '<p>An object that outputs audio</p>\n', 14269 'type': 'Object' 14270 }, 14271 { 14272 'name': 'delayTime', 14273 'description': '<p>Time (in seconds) of the delay/echo.\n Some browsers limit delayTime to\n 1 second.</p>\n', 14274 'type': 'Number', 14275 'optional': true 14276 }, 14277 { 14278 'name': 'feedback', 14279 'description': '<p>sends the delay back through itself\n in a loop that decreases in volume\n each time.</p>\n', 14280 'type': 'Number', 14281 'optional': true 14282 }, 14283 { 14284 'name': 'lowPass', 14285 'description': '<p>Cutoff frequency. Only frequencies\n below the lowPass will be part of the\n delay.</p>\n', 14286 'type': 'Number', 14287 'optional': true 14288 } 14289 ], 14290 'class': 'p5.Delay', 14291 'module': 'p5.sound' 14292 }, 14293 'delayTime': { 14294 'name': 'delayTime', 14295 'params': [ 14296 { 14297 'name': 'delayTime', 14298 'description': '<p>Time (in seconds) of the delay</p>\n', 14299 'type': 'Number' 14300 } 14301 ], 14302 'class': 'p5.Delay', 14303 'module': 'p5.sound' 14304 }, 14305 'feedback': { 14306 'name': 'feedback', 14307 'params': [ 14308 { 14309 'name': 'feedback', 14310 'description': '<p>0.0 to 1.0, or an object such as an\n Oscillator that can be used to\n modulate this param</p>\n', 14311 'type': 'Number|Object' 14312 } 14313 ], 14314 'class': 'p5.Delay', 14315 'module': 'p5.sound' 14316 }, 14317 'filter': { 14318 'name': 'filter', 14319 'params': [ 14320 { 14321 'name': 'cutoffFreq', 14322 'description': '<p>A lowpass filter will cut off any\n frequencies higher than the filter frequency.</p>\n', 14323 'type': 'Number|Object' 14324 }, 14325 { 14326 'name': 'res', 14327 'description': '<p>Resonance of the filter frequency\n cutoff, or an object (i.e. a p5.Oscillator)\n that can be used to modulate this parameter.\n High numbers (i.e. 15) will produce a resonance,\n low numbers (i.e. .2) will produce a slope.</p>\n', 14328 'type': 'Number|Object' 14329 } 14330 ], 14331 'class': 'p5.Delay', 14332 'module': 'p5.sound' 14333 }, 14334 'setType': { 14335 'name': 'setType', 14336 'params': [ 14337 { 14338 'name': 'type', 14339 'description': '<p>\'pingPong\' (1) or \'default\' (0)</p>\n', 14340 'type': 'String|Number' 14341 } 14342 ], 14343 'class': 'p5.Delay', 14344 'module': 'p5.sound' 14345 }, 14346 'amp': { 14347 'name': 'amp', 14348 'params': [ 14349 { 14350 'name': 'volume', 14351 'description': '<p>amplitude between 0 and 1.0</p>\n', 14352 'type': 'Number' 14353 }, 14354 { 14355 'name': 'rampTime', 14356 'description': '<p>create a fade that lasts rampTime</p>\n', 14357 'type': 'Number', 14358 'optional': true 14359 }, 14360 { 14361 'name': 'timeFromNow', 14362 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 14363 'type': 'Number', 14364 'optional': true 14365 } 14366 ], 14367 'class': 'p5.Delay', 14368 'module': 'p5.sound' 14369 }, 14370 'connect': { 14371 'name': 'connect', 14372 'params': [ 14373 { 14374 'name': 'unit', 14375 'description': '', 14376 'type': 'Object' 14377 } 14378 ], 14379 'class': 'p5.Delay', 14380 'module': 'p5.sound' 14381 }, 14382 'disconnect': { 14383 'name': 'disconnect', 14384 'class': 'p5.Delay', 14385 'module': 'p5.sound' 14386 } 14387 }, 14388 'p5.Reverb': { 14389 'process': { 14390 'name': 'process', 14391 'params': [ 14392 { 14393 'name': 'src', 14394 'description': '<p>p5.sound / Web Audio object with a sound\n
14394 output.</p>\n', 14395 'type': 'Object' 14396 }, 14397 { 14398 'name': 'seconds', 14399 'description': '<p>Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.</p>\n', 14400 'type': 'Number', 14401 'optional': true 14402 }, 14403 { 14404 'name': 'decayRate', 14405 'description': '<p>Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.</p>\n', 14406 'type': 'Number', 14407 'optional': true 14408 }, 14409 { 14410 'name': 'reverse', 14411 'description': '<p>Play the reverb backwards or forwards.</p>\n', 14412 'type': 'Boolean', 14413 'optional': true 14414 } 14415 ], 14416 'class': 'p5.Reverb', 14417 'module': 'p5.sound' 14418 }, 14419 'set': { 14420 'name': 'set', 14421 'params': [ 14422 { 14423 'name': 'seconds', 14424 'description': '<p>Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.</p>\n', 14425 'type': 'Number', 14426 'optional': true 14427 }, 14428 { 14429 'name': 'decayRate', 14430 'description': '<p>Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.</p>\n', 14431 'type': 'Number', 14432 'optional': true 14433 }, 14434 { 14435 'name': 'reverse', 14436 'description': '<p>Play the reverb backwards or forwards.</p>\n', 14437 'type': 'Boolean', 14438 'optional': true 14439 } 14440 ], 14441 'class': 'p5.Reverb', 14442 'module': 'p5.sound' 14443 }, 14444 'amp': { 14445 'name': 'amp', 14446 'params': [ 14447 { 14448 'name': 'volume', 14449 'description': '<p>amplitude between 0 and 1.0</p>\n', 14450 'type': 'Number' 14451 }, 14452 { 14453 'name': 'rampTime', 14454 'description': '<p>create a fade that lasts rampTime</p>\n', 14455 'type': 'Number', 14456 'optional': true 14457 }, 14458 { 14459 'name': 'timeFromNow', 14460 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 14461 'type': 'Number', 14462 'optional': true 14463 } 14464 ], 14465 'class': 'p5.Reverb', 14466 'module': 'p5.sound' 14467 }, 14468 'connect': { 14469 'name': 'connect', 14470 'params': [ 14471 { 14472 'name': 'unit', 14473 'description': '', 14474 'type': 'Object' 14475 } 14476 ], 14477 'class': 'p5.Reverb', 14478 'module': 'p5.sound' 14479 }, 14480 'disconnect': { 14481 'name': 'disconnect', 14482 'class': 'p5.Reverb', 14483 'module': 'p5.sound' 14484 } 14485 }, 14486 'p5.Convolver': { 14487 'convolverNode': { 14488 'name': 'convolverNode', 14489 'class': 'p5.Convolver', 14490 'module': 'p5.sound' 14491 }, 14492 'impulses': { 14493 'name': 'impulses', 14494 'class': 'p5.Convolver', 14495 'module': 'p5.sound' 14496 }, 14497 'process': { 14498 'name': 'process', 14499 'params': [ 14500 { 14501 'name': 'src', 14502 'description': '<p>p5.sound / Web Audio object with a sound\n output.</p>\n', 14503 'type': 'Object' 14504 } 14505 ], 14506 'class': 'p5.Convolver', 14507 'module': 'p5.sound' 14508 }, 14509 'addImpulse': { 14510 'name': 'addImpulse', 14511 'params': [ 14512 { 14513 'name': 'path', 14514 'description': '<p>
14514path to a sound file</p>\n', 14515 'type': 'String' 14516 }, 14517 { 14518 'name': 'callback', 14519 'description': '<p>function (optional)</p>\n', 14520 'type': 'Function' 14521 }, 14522 { 14523 'name': 'errorCallback', 14524 'description': '<p>function (optional)</p>\n', 14525 'type': 'Function' 14526 } 14527 ], 14528 'class': 'p5.Convolver', 14529 'module': 'p5.sound' 14530 }, 14531 'resetImpulse': { 14532 'name': 'resetImpulse', 14533 'params': [ 14534 { 14535 'name': 'path', 14536 'description': '<p>path to a sound file</p>\n', 14537 'type': 'String' 14538 }, 14539 { 14540 'name': 'callback', 14541 'description': '<p>function (optional)</p>\n', 14542 'type': 'Function' 14543 }, 14544 { 14545 'name': 'errorCallback', 14546 'description': '<p>function (optional)</p>\n', 14547 'type': 'Function' 14548 } 14549 ], 14550 'class': 'p5.Convolver', 14551 'module': 'p5.sound' 14552 }, 14553 'toggleImpulse': { 14554 'name': 'toggleImpulse', 14555 'params': [ 14556 { 14557 'name': 'id', 14558 'description': '<p>Identify the impulse by its original filename\n (String), or by its position in the\n <code>.impulses</code> Array (Number).</p>\n', 14559 'type': 'String|Number' 14560 } 14561 ], 14562 'class': 'p5.Convolver', 14563 'module': 'p5.sound' 14564 } 14565 }, 14566 'p5.Phrase': { 14567 'sequence': { 14568 'name': 'sequence', 14569 'class': 'p5.Phrase', 14570 'module': 'p5.sound' 14571 } 14572 }, 14573 'p5.Part': { 14574 'setBPM': { 14575 'name': 'setBPM', 14576 'params': [ 14577 { 14578 'name': 'BPM', 14579 'description': '<p>Beats Per Minute</p>\n', 14580 'type': 'Number' 14581 }, 14582 { 14583 'name': 'rampTime', 14584 'description': '<p>Seconds from now</p>\n', 14585 'type': 'Number', 14586 'optional': true 14587 } 14588 ], 14589 'class': 'p5.Part', 14590 'module': 'p5.sound' 14591 }, 14592 'getBPM': { 14593 'name': 'getBPM', 14594 'class': 'p5.Part', 14595 'module': 'p5.sound' 14596 }, 14597 'start': { 14598 'name': 'start', 14599 'params': [ 14600 { 14601 'name': 'time', 14602 'description': '<p>seconds from now</p>\n', 14603 'type': 'Number', 14604 'optional': true 14605 } 14606 ], 14607 'class': 'p5.Part', 14608 'module': 'p5.sound' 14609 }, 14610 'loop': { 14611 'name': 'loop', 14612 'params': [ 14613 { 14614 'name': 'time', 14615 'description': '<p>seconds from now</p>\n', 14616 'type': 'Number', 14617 'optional': true 14618 } 14619 ], 14620 'class': 'p5.Part', 14621 'module': 'p5.sound' 14622 }, 14623 'noLoop': { 14624 'name': 'noLoop', 14625 'class': 'p5.Part', 14626 'module': 'p5.sound' 14627 }, 14628 'stop': { 14629 'name': 'stop', 14630 'params': [ 14631 { 14632 'name': 'time', 14633 'description': '<p>seconds from now</p>\n', 14634 'type': 'Number', 14635 'optional': true 14636 } 14637 ], 14638 'class': 'p5.Part', 14639 'module': 'p5.sound' 14640 }, 14641 'pause': { 14642 'name': 'pause', 14643 'params': [ 14644 { 14645 'name': 'time', 14646 'description': '<p>seconds from now</p>\n', 14647 'type': 'Number' 14648 } 14649 ], 14650 'class': 'p5.Part', 14651 'module': 'p5.sound' 14652 }, 14653 'addPhrase': { 14654 'name': 'addPhrase', 14655 'params': [ 14656 { 14657 'name': 'phrase', 14658 'description': '<p>reference to a p5.Phrase</p>\n', 14659 'type': 'p5.Phrase' 14660 } 14661 ], 14662 'class': 'p5.Part', 14663 'module': 'p5.sound' 14664 }, 14665 'removePhrase': { 14666 'name': 'removePhrase', 14667 'params': [ 14668 { 14669 'name': 'phraseName', 14670 'description': '', 14671 'type': 'String' 14672 } 14673 ], 14674 'class': 'p5.Part', 14675 'module': 'p5.sound' 14676 }, 14677 'getPhrase': { 14678 'name': 'getPhrase', 14679 'params': [ 14680 { 14681 'name': 'phraseName', 14682 'description': '', 14683 'type': 'String' 14684 } 14685 ], 14686 'class': 'p5.Part', 14687 'module': 'p5.sound' 14688 }, 14689 'replaceSequence': { 14690 'name': 'replaceSequence', 14691 'params': [ 14692 { 14693 'name': 'phraseName', 14694 'description': '', 14695 'type': 'String' 14696 }, 14697 { 14698 'name': 'sequence', 14699 'description': '<p>Array of values to pass into the callback\n at each step of the phrase.</p>\n', 14700 'type': 'Array' 14701 } 14702 ], 14703 'class': 'p5.Part', 14704 'module': 'p5.sound' 14705 }, 14706 'onStep': { 14707 'name': 'onStep', 14708 'params': [ 14709 { 14710 'name': 'callback', 14711 'description': '<p>The name of the callback\n you want to fire\n on every beat/tatum.</p>\n', 14712 'type': 'Function' 14713 } 14714 ], 14715 'class': 'p5.Part', 14716 'module': 'p5.sound' 14717 } 14718 }, 14719 'p5.Score': { 14720 'start': { 14721 'name': 'start', 14722 'class': 'p5.Score', 14723 'module': 'p5.sound' 14724 }, 14725 'stop': { 14726 'name': 'stop', 14727 'class': 'p5.Score', 14728 'module': 'p5.sound' 14729 }, 14730 'pause': { 14731 'name': 'pause', 14732 'class': 'p5.Score', 14733 'module': 'p5.sound' 14734 }, 14735 'loop': { 14736 'name': 'loop', 14737 'class': 'p5.Score', 14738 'module': 'p5.sound' 14739 }, 14740 'noLoop': { 14741 'name': 'noLoop', 14742 'class': 'p5.Score', 14743 'module': 'p5.sound' 14744 }, 14745 'setBPM': { 14746 'name': 'setBPM', 14747 'params': [ 14748 { 14749 'name': 'BPM', 14750 'description': '<p>Beats Per Minute</p>\n', 14751 'type': 'Number' 14752 }, 14753 { 14754 'name': 'rampTime', 14755 'description': '<p>Seconds from now</p>\n', 14756 'type': 'Number' 14757 } 14758 ], 14759 'class': 'p5.Score', 14760 'module': 'p5.sound' 14761 } 14762 }, 14763 'p5.SoundLoop': { 14764 'bpm': { 14765 'name': 'bpm', 14766 'class': 'p5.SoundLoop', 14767 'module': 'p5.sound' 14768 }, 14769 'timeSignature': { 14770 'name': 'timeSignature', 14771 'class': 'p5.SoundLoop', 14772 'module': 'p5.sound' 14773 }, 14774 'interval': { 14775 'name': 'interval', 14776 'class': 'p5.SoundLoop', 14777 'module': 'p5.sound' 14778 }, 14779 'iterations': { 14780 'name': 'iterations', 14781 'class': 'p5.SoundLoop', 14782 'module': 'p5.sound' 14783 }, 14784 'musicalTimeMode': { 14785 'name': 'musicalTimeMode', 14786 'class': 'p5.SoundLoop', 14787 'module': 'p5.sound' 14788 }, 14789 'maxIterations': { 14790 'name': 'maxIterations', 14791 'class': 'p5.SoundLoop', 14792 'module': 'p5.sound' 14793 }, 14794 'start': { 14795 'name': 'start', 14796 'params': [ 14797 { 14798 'name': 'timeFromNow', 14799 'description': '<p>schedule a starting time</p>\n', 14800 'type': 'Number', 14801 'optional': true 14802 } 14803 ], 14804 'class': 'p5.SoundLoop', 14805 'module': 'p5.sound' 14806 }, 14807 'stop': { 14808 'name': 'stop', 14809 'params': [ 14810 { 14811 'name': 'timeFromNow', 14812 'description': '<p>schedule a stopping time</p>\n', 14813 'type': 'Number', 14814 'optional': true 14815 } 14816 ], 14817 'class': 'p5.SoundLoop', 14818 'module': 'p5.sound' 14819 }, 14820 'pause': { 14821 'name': 'pause', 14822 'params': [ 14823 { 14824 'name': 'timeFromNow', 14825 'description': '<p>schedule a pausing time</p>\n', 14826 'type': 'Number', 14827 'optional': true 14828 } 14829 ], 14830 'class': 'p5.SoundLoop', 14831 'module': 'p5.sound' 14832 }, 14833 'syncedStart': { 14834 'name': 'syncedStart', 14835 'params': [ 14836 { 14837 'name': 'otherLoop', 14838 'description': '<p>a p5.SoundLoop to sync with</p>\n', 14839 'type': 'Object' 14840 }, 14841 { 14842 'name': 'timeFromNow', 14843 'description': '<p>Start the loops in sync after timeFromNow seconds</p>\n', 14844 'type': 'Number', 14845 'optional': true 14846 } 14847 ], 14848 'class': 'p5.SoundLoop', 14849 'module': 'p5.sound' 14850 } 14851 }, 14852 'p5.Compressor': { 14853 'compressor': { 14854 'name': 'compressor', 14855 'class': 'p5.Compressor', 14856 'module': 'p5.sound' 14857 }, 14858 'process': { 14859 'name': 'process', 14860 'params': [ 14861 { 14862 'name': 'src', 14863 'description': '<p>Sound source to be connected</p>\n', 14864 'type': 'Object' 14865 }, 14866 { 14867 'name': 'attack', 14868 'description': '<p>The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1</p>\n', 14869 'type': 'Number', 14870 'optional': true 14871 }, 14872 { 14873 'name': 'knee', 14874 'description': '<p>A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40</p>\n', 14875 'type': 'Number', 14876 'optional': true 14877 }, 14878 { 14879 'name': 'ratio', 14880 'description': '<p>The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20</p>\n', 14881 'type': 'Number', 14882 'optional': true 14883 }, 14884 { 14885 'name': 'threshold', 14886 'description': '<p>The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0</p>\n', 14887 'type': 'Number', 14888 'optional': true 14889 }, 14890 { 14891 'name': 'release', 14892 'description': '<p>The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1</p>\n', 14893 'type': 'Number', 14894 'optional': true 14895 } 14896 ], 14897 'class': 'p5.Compressor', 14898 'module': 'p5.sound' 14899 }, 14900 'set': { 14901 'name': 'set', 14902 'params': [ 14903 { 14904 'name': 'attack', 14905 'description': '<p>The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1</p>\n', 14906 'type': 'Number' 14907 }, 14908 { 14909 'name': 'knee', 14910 'description': '<p>A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40</p>\n', 14911 'type': 'Number' 14912 }, 14913 { 14914 'name': 'ratio', 14915 'description': '<p>The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20</p>\n', 14916 'type': 'Number' 14917 }, 14918 { 14919 'name': 'threshold', 14920 'description': '<p>The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0</p>\n', 14921 'type': 'Number' 14922 }, 14923 { 14924 'name': 'release', 14925 'description': '<p>The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1</p>\n', 14926 'type': 'Number' 14927 } 14928 ], 14929 'class': 'p5.Compressor', 14930 'module': 'p5.sound' 14931 }, 14932 'attack': { 14933 'name': 'attack', 14934 'params': [ 14935 { 14936 'name': 'attack', 14937 'description': '<p>Attack is the amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1</p>\n', 14938 'type': 'Number', 14939 'optional': true 14940 }, 14941 { 14942 'name': 'time', 14943 'description': '<p>Assign time value to schedule the change in value</p>\n', 14944 'type': 'Number', 14945 'optional': true 14946 } 14947 ], 14948 'class': 'p5.Compressor', 14949 'module': 'p5.sound' 14950 }, 14951 'knee': { 14952 'name': 'knee', 14953 'params': [ 14954 { 14955 'name': 'knee', 14956 'description': '<p>A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40</p>\n', 14957 'type': 'Number', 14958 'optional': true 14959 }, 14960 { 14961 'name': 'time', 14962 'description': '<p>Assign time value to schedule the change in value</p>\n', 14963 'type': 'Number', 14964 'optional': true 14965 } 14966 ], 14967 'class': 'p5.Compressor', 14968 'module': 'p5.sound' 14969 }, 14970 'ratio': { 14971 'name': 'ratio', 14972 'params': [ 14973 { 14974 'name': 'ratio', 14975 'description': '<p>The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20</p>\n', 14976 'type': 'Number', 14977 'optional': true 14978 }, 14979 { 14980 'name': 'time', 14981 'description': '<p>Assign time value to schedule the ch
14981ange in value</p>\n', 14982 'type': 'Number', 14983 'optional': true 14984 } 14985 ], 14986 'class': 'p5.Compressor', 14987 'module': 'p5.sound' 14988 }, 14989 'threshold': { 14990 'name': 'threshold', 14991 'params': [ 14992 { 14993 'name': 'threshold', 14994 'description': '<p>The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0</p>\n', 14995 'type': 'Number' 14996 }, 14997 { 14998 'name': 'time', 14999 'description': '<p>Assign time value to schedule the change in value</p>\n', 15000 'type': 'Number', 15001 'optional': true 15002 } 15003 ], 15004 'class': 'p5.Compressor', 15005 'module': 'p5.sound' 15006 }, 15007 'release': { 15008 'name': 'release', 15009 'params': [ 15010 { 15011 'name': 'release', 15012 'description': '<p>The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1</p>\n', 15013 'type': 'Number' 15014 }, 15015 { 15016 'name': 'time', 15017 'description': '<p>Assign time value to schedule the change in value</p>\n', 15018 'type': 'Number', 15019 'optional': true 15020 } 15021 ], 15022 'class': 'p5.Compressor', 15023 'module': 'p5.sound' 15024 }, 15025 'reduction': { 15026 'name': 'reduction', 15027 'class': 'p5.Compressor', 15028 'module': 'p5.sound' 15029 } 15030 }, 15031 'p5.PeakDetect': { 15032 'isDetected': { 15033 'name': 'isDetected', 15034 'class': 'p5.PeakDetect', 15035 'module': 'p5.sound' 15036 }, 15037 'update': { 15038 'name': 'update', 15039 'params': [ 15040 { 15041 'name': 'fftObject', 15042 'description': '<p>A p5.FFT object</p>\n', 15043 'type': 'p5.FFT' 15044 } 15045 ], 15046 'class': 'p5.PeakDetect', 15047 'module': 'p5.sound' 15048 }, 15049 'onPeak': { 15050 'name': 'onPeak', 15051 'params': [ 15052 { 15053 'name': 'callback', 15054 'description': '<p>Name of a function that will\n be called when a peak is\n detected.</p>\n', 15055 'type': 'Function' 15056 }, 15057 { 15058 'name': 'val', 15059 'description': '<p>Optional value to pass\n into the function when\n a peak is detected.</p>\n', 15060 'type': 'Object', 15061 'optional': true 15062 } 15063 ], 15064 'class': 'p5.PeakDetect', 15065 'module': 'p5.sound' 15066 } 15067 }, 15068 'p5.SoundRecorder': { 15069 'setInput': { 15070 'name': 'setInput', 15071 'params': [ 15072 { 15073 'name': 'unit', 15074 'description': '<p>p5.sound object or a web audio unit\n that outputs sound</p>\n', 15075 'type': 'Object', 15076 'optional': true 15077 } 15078 ], 15079 'class': 'p5.SoundRecorder', 15080 'module': 'p5.sound' 15081 }, 15082 'record': { 15083 'name': 'record', 15084 'params': [ 15085 { 15086 'name': 'soundFile', 15087 'description': '<p>p5.SoundFile</p>\n', 15088 'type': 'p5.SoundFile' 15089 }, 15090 { 15091 'name': 'duration', 15092 'description': '<p>Time (in seconds)</p>\n', 15093 'type': 'Number', 15094 'optional': true 15095 }, 15096 { 15097 'name': 'callback', 15098 'description': '<p>The name of a function that will be\n called once the recording completes</p>\n', 15099 'type': 'Function', 15100 'optional': true 15101 } 15102 ], 15103 'class': 'p5.SoundRecorder', 15104 'module': 'p5.sound' 15105 }, 15106 'stop': { 15107 'name': 'stop', 15108 'class': 'p5.SoundRecorder', 15109 'module': 'p5.sound' 15110 } 15111 }, 15112 'p5.Distortion': { 15113 'WaveShaperNode': { 15114 'name': 'WaveShaperNode', 15115 'class': 'p5.Distortion', 15116 'module': 'p5.sound' 15117 }, 15118 'process': { 15119 'name': 'process', 15120 'params': [ 15121 { 15122 'name': 'amount', 15123 'description': '<p>Unbounded distortion amount.\n Normal values range from 0-1.</p>\n', 15124 'type': 'Number', 15125 'optional': true, 15126 'optdefault': '0.25' 15127 }, 15128 { 15129 'name': 'oversample', 15130 'description': '<p>\'none\', \'2x\', or \'4x\'.</p>\n', 15131 'type': 'String', 15132 'optional': true, 15133 'optdefault': '\'none\'' 15134 } 15135 ], 15136 'class': 'p5.Distortion', 15137 'module': 'p5.sound' 15138 }, 15139 'set': { 15140 'name': 'set', 15141 'params': [ 15142 { 15143 'name': 'amount', 15144 'description': '<p>Unbounded distortion amount.\n Normal values range from 0-1.</p>\n', 15145 'type': 'Number', 15146 'optional': true, 15147 'optdefault': '0.25' 15148 }, 15149 { 15150 'name': 'oversample', 15151 'description': '<p>\'none\', \'2x\', or \'4x\'.</p>\n', 15152 'type': 'String', 15153 'optional': true, 15154 'optdefault': '\'none\'' 15155 } 15156 ], 15157 'class': 'p5.Distortion', 15158 'module': 'p5.sound' 15159 }, 15160 'getAmount': { 15161 'name': 'getAmount', 15162 'class': 'p5.Distortion', 15163 'module': 'p5.sound' 15164 }, 15165 'getOversample': { 15166 'name': 'getOversample', 15167 'class': 'p5.Distortion', 15168 'module': 'p5.sound' 15169 } 15170 }, 15171 'p5.Gain': { 15172 'setInput': { 15173 'name': 'setInput', 15174 'params': [ 15175 { 15176 'name': 'src', 15177 'description': '<p>p5.sound / Web Audio object with a sound\n output.</p>\n', 15178 'type': 'Object' 15179 } 15180 ], 15181 'class': 'p5.Gain', 15182 'module': 'p5.sound' 15183 }, 15184 'connect': { 15185 'name': 'connect', 15186 'params': [ 15187 { 15188 'name': 'unit', 15189 'description': '', 15190 'type': 'Object' 15191 } 15192 ], 15193 'class': 'p5.Gain', 15194 'module': 'p5.sound' 15195 }, 15196 'disconnect': { 15197 'name': 'disconnect', 15198 'class': 'p5.Gain', 15199 'module': 'p5.sound' 15200 }, 15201 'amp': { 15202 'name': 'amp', 15203 'params': [ 15204 { 15205 'name': 'volume', 15206 'description': '<p>amplitude between 0 and 1.0</p>\n', 15207 'type': 'Number' 15208 }, 15209 { 15210 'name': 'rampTime', 15211 'description': '<p>create a fade that lasts rampTime</p>\n', 15212 'type': 'Number', 15213 'optional': true 15214 }, 15215 { 15216 'name': 'timeFromNow', 15217 'description': '<p>schedule this event to happen\n seconds from now</p>\n', 15218 'type': 'Number', 15219 'optional': true 15220 } 15221 ], 15222 'class': 'p5.Gain', 15223 'module': 'p5.sound' 15224 } 15225 }, 15226 'p5.AudioVoice': { 15227 'connect': { 15228 'name': 'connect', 15229 'params': [ 15230 { 15231 'name': 'unit', 15232 'description': '', 15233 'type': 'Object' 15234 } 15235 ], 15236 'class': 'p5.AudioVoice', 15237 'module': 'p5.sound' 15238 }, 15239 'disconnect': { 15240 'name': 'disconnect', 15241 'class': 'p5.AudioVoice', 15242 'module': 'p5.sound' 15243 } 15244 }, 15245 'p5.MonoSynth': { 15246 'attack': { 15247 'name': 'attack', 15248 'class': 'p5.MonoSynth', 15249 'module': 'p5.sound' 15250 }, 15251 'decay': { 15252 'name': 'decay', 15253 'class': 'p5.MonoSynth', 15254 'module': 'p5.sound' 15255 }, 15256 'sustain': { 15257 'name': 'sustain', 15258 'class': 'p5.MonoSynth', 15259 'module': 'p5.sound' 15260 }, 15261 'release': { 15262 'name': 'release', 15263 'class': 'p5.MonoSynth', 15264 'module': 'p5.sound' 15265 }, 15266 'play': { 15267 'name': 'play', 15268 'params': [ 15269 { 15270 'name': 'note', 15271 'description': '<p>the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See <a href = "https://github.com/Tonejs/Tone.js/wiki/Instruments">\n Tone</a>. Defaults to 440 hz.</p>\n', 15272 'type': 'String | Number' 15273 }, 15274 { 15275 'name': 'velocity', 15276 'description': '<p>velocity of the note to play (ranging from 0 to 1)</p>\n', 15277 'type': 'Number', 15278 'optional': true 15279 }, 15280 { 15281 'name': 'secondsFromNow', 15282 'description': '<p>time from now (in seconds) at which to play</p>\n', 15283 'type': 'Number', 15284 'optional': true 15285 }, 15286 { 15287 'name': 'sustainTime', 15288 'description': '<p>time to sustain before releasing the envelope. Defaults to 0.15 seconds.</p>\n', 15289 'type': 'Number', 15290 'optional': true 15291 } 15292 ], 15293 'class': 'p5.MonoSynth', 15294 'module': 'p5.sound' 15295 }, 15296 'triggerAttack': { 15297 'params': [ 15298 { 15299 'name': 'note', 15300 'description': '<p>the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See <a href = "https://github.com/Tonejs/Tone.js/wiki/Instruments">\n Tone</a>. Defaults to 440 hz</p>\n', 15301 'type': 'String | Number' 15302 }, 15303 { 15304 'name': 'velocity', 15305 'description': '<p>velocity of the note to play (ranging from 0 to 1)</p>\n', 15306 'type': 'Number', 15307 'optional': true 15308 }, 15309 { 15310 'name': 'secondsFromNow', 15311 'description': '<p>time from now (in seconds) at which to play</p>\n', 15312 'type': 'Number', 15313 'optional': true 15314 } 15315 ], 15316 'name': 'triggerAttack', 15317 'class': 'p5.MonoSynth', 15318 'module': 'p5.sound' 15319 }, 15320 'triggerRelease': { 15321 'params': [ 15322 { 15323 'name': 'secondsFromNow', 15324 'description': '<p>time to trigger the release</p>\n', 15325 'type': 'Number' 15326 } 15327 ], 15328 'name': 'triggerRelease', 15329 'class': 'p5.MonoSynth', 15330 'module': 'p5.sound' 15331 }, 15332 'setADSR': { 15333 'name': 'setADSR', 15334 'params': [ 15335 { 15336 'name': 'attackTime', 15337 'description': '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n', 15338 'type': 'Number' 15339 }, 15340 { 15341 'name': 'decayTime', 15342 'description': '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n', 15343 'type': 'Number', 15344 'optional': true 15345 }, 15346 { 15347 'name': 'susRatio', 15348 'description': '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n', 15349 'type': 'Number', 15350 'optional': true 15351 }, 15352 { 15353 'name': 'releaseTime', 15354 'description': '<p>Time in seconds from now (defaults to 0)</p>\n', 15355 'type': 'Number', 15356 'optional': true 15357 } 15358 ], 15359 'class': 'p5.MonoSynth', 15360 'module': 'p5.sound' 15361 }, 15362 'amp': { 15363 'name': 'amp', 15364 'params': [ 15365 { 15366 'name': 'vol', 15367 'description': '<p>desired volume</p>\n', 15368 'type': 'Number' 15369 }, 15370 { 15371 'name': 'rampTime', 15372 'description': '<p>Time to reach new volume</p>\n', 15373 'type': 'Number', 15374 'optional': true 15375 } 15376 ], 15377 'class': 'p5.MonoSynth', 15378 'module': 'p5.sound' 15379 }, 15380 'connect': { 15381 'name': 'connect', 15382 'params': [ 15383 { 15384 'name': 'unit', 15385 'description': '<p>A p5.sound or Web Audio object</p>\n', 15386 'type': 'Object' 15387 } 15388 ], 15389 'class': 'p5.MonoSynth', 15390 'module': 'p5.sound' 15391 }, 15392 'disconnect': { 15393 'name': 'disconnect', 15394 'class': 'p5.MonoSynth', 15395 'module': 'p5.sound' 15396 }, 15397 'dispose': { 15398 'name': 'dispose', 15399 'class': 'p5.MonoSynth', 15400 'module': 'p5.sound' 15401 } 15402 }, 15403 'p5.PolySynth': { 15404 'notes': { 15405 'name': 'notes', 15406 'class': 'p5.PolySynth', 15407 'module': 'p5.sound' 15408 }, 15409 'polyvalue': { 15410 'name': 'polyvalue', 15411 'class': 'p5.PolySynth', 15412 'module': 'p5.sound' 15413 }, 15414 'AudioVoice': { 15415 'name': 'AudioVoice', 15416 'class': 'p5.PolySynth', 15417 'module': 'p5.sound' 15418 }, 15419 'play': { 15420 'name': 'play', 15421 'params': [ 15422 { 15423 'name': 'note', 15424 'description': '<p>midi note to play
15424(ranging from 0 to 127 - 60 being a middle C)</p>\n', 15425 'type': 'Number', 15426 'optional': true 15427 }, 15428 { 15429 'name': 'velocity', 15430 'description': '<p>velocity of the note to play (ranging from 0 to 1)</p>\n', 15431 'type': 'Number', 15432 'optional': true 15433 }, 15434 { 15435 'name': 'secondsFromNow', 15436 'description': '<p>time from now (in seconds) at which to play</p>\n', 15437 'type': 'Number', 15438 'optional': true 15439 }, 15440 { 15441 'name': 'sustainTime', 15442 'description': '<p>time to sustain before releasing the envelope</p>\n', 15443 'type': 'Number', 15444 'optional': true 15445 } 15446 ], 15447 'class': 'p5.PolySynth', 15448 'module': 'p5.sound' 15449 }, 15450 'noteADSR': { 15451 'name': 'noteADSR', 15452 'params': [ 15453 { 15454 'name': 'note', 15455 'description': '<p>Midi note on which ADSR should be set.</p>\n', 15456 'type': 'Number', 15457 'optional': true 15458 }, 15459 { 15460 'name': 'attackTime', 15461 'description': '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n', 15462 'type': 'Number', 15463 'optional': true 15464 }, 15465 { 15466 'name': 'decayTime', 15467 'description': '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n', 15468 'type': 'Number', 15469 'optional': true 15470 }, 15471 { 15472 'name': 'susRatio', 15473 'description': '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n', 15474 'type': 'Number', 15475 'optional': true 15476 }, 15477 { 15478 'name': 'releaseTime', 15479 'description': '<p>Time in seconds from now (defaults to 0)</p>\n', 15480 'type': 'Number', 15481 'optional': true 15482 } 15483 ], 15484 'class': 'p5.PolySynth', 15485 'module': 'p5.sound' 15486 }, 15487 'setADSR': { 15488 'name': 'setADSR', 15489 'params': [ 15490 { 15491 'name': 'attackTime', 15492 'description': '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n', 15493 'type': 'Number', 15494 'optional': true 15495 }, 15496 { 15497 'name': 'decayTime', 15498 'description': '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n', 15499 'type': 'Number', 15500 'optional': true 15501 }, 15502 { 15503 'name': 'susRatio', 15504 'description': '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n', 15505 'type': 'Number', 15506 'optional': true 15507 }, 15508 { 15509 'name': 'releaseTime', 15510 'description': '<p>Time in seconds from now (defaults to 0)</p>\n', 15511 'type': 'Number', 15512 'optional': true 15513 } 15514 ], 15515 'class': 'p5.PolySynth', 15516 'module': 'p5.sound' 15517 }, 15518 'noteAttack': { 15519 'name': 'noteAttack', 15520 'params': [ 15521 { 15522 'name': 'note', 15523 'description': '<p>midi note on which attack should be triggered.</p>\n', 15524 'type': 'Number', 15525 'optional': true 15526 }, 15527 { 15528 'name': 'velocity', 15529 'description': '<p>velocity of the note to play (ranging from 0 to 1)/</p>\n', 15530 'type': 'Number', 15531 'optional': true 15532 }, 15533 { 15534 'name': 'secondsFromNow', 15535 'description': '<p>time from now (in seconds)</p>\n', 15536 'type': 'Number', 15537 'optional': true 15538 } 15539 ], 15540 'class': 'p5.PolySynth', 15541 'module': 'p5.sound' 15542 }, 15543 'noteRelease': { 15544 'name': 'noteRelease', 15545 'params': [ 15546 { 15547 'name': 'note', 15548 'description': '<p>midi note on which attack should be triggered.\n If no value is provided, all notes will be released.</p>\n', 15549 'type': 'Number', 15550 'optional': true 15551 }, 15552 { 15553 'name': 'secondsFromNow', 15554 'description': '<p>time to trigger the release</p>\n', 15555 'type': 'Number', 15556 'optional': true 15557 } 15558 ], 15559 'class': 'p5.PolySynth', 15560 'module': 'p5.sound' 15561 }, 15562 'connect': { 15563 'name': 'connect', 15564 'params': [ 15565 { 15566 'name': 'unit', 15567 'description': '<p>A p5.sound or Web Audio object</p>\n', 15568 'type': 'Object' 15569 } 15570 ], 15571 'class': 'p5.PolySynth', 15572 'module': 'p5.sound' 15573 }, 15574 'disconnect': { 15575 'name': 'disconnect', 15576 'class': 'p5.PolySynth', 15577 'module': 'p5.sound' 15578 }, 15579 'dispose': { 15580 'name': 'dispose', 15581 'class': 'p5.PolySynth', 15582 'module': 'p5.sound' 15583 } 15584 } 15585 } 15586 }, 15587 { 15588 } 15589 ], 15590 2: [
15591 function (_dereq_, module, exports) { 15592 function _arrayWithHoles(arr) { 15593 if (Array.isArray(arr)) return arr; 15594 } 15595 module.exports = _arrayWithHoles; 15596 }, 15597 { 15598 } 15599 ], 15600 3: [ 15601 function (_dereq_, module, exports) { 15602 function _arrayWithoutHoles(arr) { 15603 if (Array.isArray(arr)) { 15604 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 15605 arr2[i] = arr[i]; 15606 } 15607 return arr2; 15608 } 15609 } 15610 module.exports = _arrayWithoutHoles; 15611 }, 15612 { 15613 } 15614 ], 15615 4: [ 15616 function (_dereq_, module, exports) { 15617 function _assertThisInitialized(self) { 15618 if (self === void 0) { 15619 throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called'); 15620 } 15621 return self; 15622 } 15623 module.exports = _assertThisInitialized; 15624 }, 15625 { 15626 } 15627 ], 15628 5: [ 15629 function (_dereq_, module, exports) { 15630 function _classCallCheck(instance, Constructor) { 15631 if (!(instance instanceof Constructor)) { 15632 throw new TypeError('Cannot call a class as a function'); 15633 } 15634 } 15635 module.exports = _classCallCheck; 15636 }, 15637 { 15638 } 15639 ], 15640 6: [ 15641 function (_dereq_, module, exports) { 15642 function _defineProperties(target, props) { 15643 for (var i = 0; i < props.length; i++) { 15644 var descriptor = props[i]; 15645 descriptor.enumerable = descriptor.enumerable || false; 15646 descriptor.configurable = true; 15647 if ('value' in descriptor) descriptor.writable = true; 15648 Object.defineProperty(target, descriptor.key, descriptor); 15649 } 15650 } 15651 function _createClass(Constructor, protoProps, staticProps) { 15652 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 15653 if (staticProps) _defineProperties(Constructor, staticProps); 15654 return Constructor; 15655 } 15656 module.exports = _createClass; 15657 }, 15658 { 15659 } 15660 ], 15661 7: [ 15662 function (_dereq_, module, exports) { 15663 function _defineProperty(obj, key, value) { 15664 if (key in obj) { 15665 Object.defineProperty(obj, key, { 15666 value: value, 15667 enumerable: true, 15668 configurable: true, 15669 writable: true 15670 }); 15671 } else { 15672 obj[key] = value; 15673 } 15674 return obj; 15675 } 15676 module.exports = _defineProperty; 15677 }, 15678 { 15679 } 15680 ], 15681 8: [ 15682 function (_dereq_, module, exports) { 15683 function _getPrototypeOf(o) { 15684 module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { 15685 return o.__proto__ || Object.getPrototypeOf(o); 15686 }; 15687 return _getPrototypeOf(o); 15688 } 15689 module.exports = _getPrototypeOf; 15690 }, 15691 { 15692 } 15693 ], 15694 9: [ 15695 function (_dereq_, module, exports) { 15696 var setPrototypeOf = _dereq_('./setPrototypeOf'); 15697 function _inherits(subClass, superClass) { 15698 if (typeof superClass !== 'function' && superClass !== null) { 15699 throw new TypeError('Super expression must either be null or a function'); 15700 } 15701 subClass.prototype = Object.create(superClass && superClass.prototype, { 15702 constructor: { 15703 value: subClass, 15704 writable: true, 15705 configurable: true 15706 } 15707 }); 15708 if (superClass) setPrototypeOf(subClass, superClass); 15709 } 15710 module.exports = _inherits; 15711 }, 15712 { 15713 './setPrototypeOf': 16 15714 } 15715 ], 15716 10: [ 15717 function (_dereq_, module, exports) { 15718 function _iterableToArray(iter) { 15719 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') return Array.from(iter); 15720 } 15721 module.exports = _iterableToArray; 15722 }, 15723 { 15724 } 15725 ], 15726 11: [ 15727 function (_dereq_, module, exports) { 15728 function _iterableToArrayLimit(arr, i) { 15729 var _arr = [ 15730 ]; 15731 var _n = true; 15732 var _d = false;
15733 var _e = undefined; 15734 try { 15735 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { 15736 _arr.push(_s.value); 15737 if (i && _arr.length === i) break; 15738 } 15739 } catch (err) { 15740 _d = true; 15741 _e = err; 15742 } finally { 15743 try { 15744 if (!_n && _i['return'] != null) _i['return'](); 15745 } finally { 15746 if (_d) throw _e; 15747 } 15748 } 15749 return _arr; 15750 } 15751 module.exports = _iterableToArrayLimit; 15752 }, 15753 { 15754 } 15755 ], 15756 12: [ 15757 function (_dereq_, module, exports) { 15758 function _nonIterableRest() { 15759 throw new TypeError('Invalid attempt to destructure non-iterable instance'); 15760 } 15761 module.exports = _nonIterableRest; 15762 }, 15763 { 15764 } 15765 ], 15766 13: [ 15767 function (_dereq_, module, exports) { 15768 function _nonIterableSpread() { 15769 throw new TypeError('Invalid attempt to spread non-iterable instance'); 15770 } 15771 module.exports = _nonIterableSpread; 15772 }, 15773 { 15774 } 15775 ], 15776 14: [ 15777 function (_dereq_, module, exports) { 15778 var defineProperty = _dereq_('./defineProperty'); 15779 function _objectSpread(target) { 15780 for (var i = 1; i < arguments.length; i++) { 15781 var source = arguments[i] != null ? arguments[i] : { 15782 }; 15783 var ownKeys = Object.keys(source); 15784 if (typeof Object.getOwnPropertySymbols === 'function') { 15785 ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { 15786 return Object.getOwnPropertyDescriptor(source, sym).enumerable; 15787 })); 15788 } 15789 ownKeys.forEach(function (key) { 15790 defineProperty(target, key, source[key]); 15791 }); 15792 } 15793 return target; 15794 } 15795 module.exports = _objectSpread; 15796 }, 15797 { 15798 './defineProperty': 7 15799 } 15800 ], 15801 15: [ 15802 function (_dereq_, module, exports) { 15803 var _typeof = _dereq_('../helpers/typeof'); 15804 var assertThisInitialized = _dereq_('./assertThisInitialized'); 15805 function _possibleConstructorReturn(self, call) { 15806 if (call && (_typeof(call) === 'object' || typeof call === 'function')) { 15807 return call; 15808 } 15809 return assertThisInitialized(self); 15810 } 15811 module.exports = _possibleConstructorReturn; 15812 }, 15813 { 15814 '../helpers/typeof': 19, 15815 './assertThisInitialized': 4 15816 } 15817 ], 15818 16: [ 15819 function (_dereq_, module, exports) { 15820 function _setPrototypeOf(o, p) { 15821 module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { 15822 o.__proto__ = p; 15823 return o; 15824 }; 15825 return _setPrototypeOf(o, p); 15826 } 15827 module.exports = _setPrototypeOf; 15828 }, 15829 { 15830 } 15831 ], 15832 17: [ 15833 function (_dereq_, module, exports) { 15834 var arrayWithHoles = _dereq_('./arrayWithHoles'); 15835 var iterableToArrayLimit = _dereq_('./iterableToArrayLimit'); 15836 var nonIterableRest = _dereq_('./nonIterableRest'); 15837 function _slicedToArray(arr, i) { 15838 return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest(); 15839 } 15840 module.exports = _slicedToArray; 15841 }, 15842 { 15843 './arrayWithHoles': 2, 15844 './iterableToArrayLimit': 11, 15845 './nonIterableRest': 12 15846 } 15847 ], 15848 18: [ 15849 function (_dereq_, module, exports) { 15850 var arrayWithoutHoles = _dereq_('./arrayWithoutHoles'); 15851 var iterableToArray = _dereq_('./iterableToArray'); 15852 var nonIterableSpread = _dereq_('./nonIterableSpread'); 15853 function _toConsumableArray(arr) { 15854 return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread(); 15855 } 15856 module.exports = _toConsumableArray; 15857 }, 15858 { 15859 './arrayWithoutHoles': 3, 15860 './iterableToArray': 10, 15861 './nonIterableSpread': 13 15862 } 15863 ], 15864 19: [
vendor: 5,748 bytes, lines 15865-16002
15865 function (_dereq_, module, exports) { 15866 function _typeof2(obj) { 15867 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 15868 _typeof2 = function _typeof2(obj) { 15869 return typeof obj; 15870 }; 15871 } else { 15872 _typeof2 = function _typeof2(obj) { 15873 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 15874 }; 15875 } 15876 return _typeof2(obj); 15877 } 15878 function _typeof(obj) { 15879 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 15880 module.exports = _typeof = function _typeof(obj) { 15881 return _typeof2(obj); 15882 }; 15883 } else { 15884 module.exports = _typeof = function _typeof(obj) { 15885 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 15886 }; 15887 } 15888 return _typeof(obj); 15889 } 15890 module.exports = _typeof; 15891 }, 15892 { 15893 } 15894 ], 15895 20: [ 15896 function (_dereq_, module, exports) { 15897 'use strict'; 15898 exports.byteLength = byteLength; 15899 exports.toByteArray = toByteArray; 15900 exports.fromByteArray = fromByteArray; 15901 var lookup = [ 15902 ]; 15903 var revLookup = [ 15904 ]; 15905 var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; 15906 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; 15907 for (var i = 0, len = code.length; i < len; ++i) { 15908 lookup[i] = code[i]; 15909 revLookup[code.charCodeAt(i)] = i; 15910 } // Support decoding URL-safe base64 strings, as Node.js does. 15911 // See: https://en.wikipedia.org/wiki/Base64#URL_applications 15912 15913 revLookup['-'.charCodeAt(0)] = 62; 15914 revLookup['_'.charCodeAt(0)] = 63; 15915 function getLens(b64) { 15916 var len = b64.length; 15917 if (len % 4 > 0) { 15918 throw new Error('Invalid string. Length must be a multiple of 4'); 15919 } // Trim off extra bytes after placeholder bytes are found 15920 // See: https://github.com/beatgammit/base64-js/issues/42 15921 15922 var validLen = b64.indexOf('='); 15923 if (validLen === - 1) validLen = len; 15924 var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; 15925 return [validLen, 15926 placeHoldersLen]; 15927 } // base64 is 4/3 + up to two characters of the original data 15928 15929 function byteLength(b64) { 15930 var lens = getLens(b64); 15931 var validLen = lens[0]; 15932 var placeHoldersLen = lens[1]; 15933 return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; 15934 } 15935 function _byteLength(b64, validLen, placeHoldersLen) { 15936 return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; 15937 } 15938 function toByteArray(b64) { 15939 var tmp; 15940 var lens = getLens(b64); 15941 var validLen = lens[0]; 15942 var placeHoldersLen = lens[1]; 15943 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); 15944 var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars 15945 var len = placeHoldersLen > 0 ? validLen - 4 : validLen; 15946 var i; 15947 for (i = 0; i < len; i += 4) { 15948 tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; 15949 arr[curByte++] = tmp >> 16 & 255; 15950 arr[curByte++] = tmp >> 8 & 255; 15951 arr[curByte++] = tmp & 255; 15952 } 15953 if (placeHoldersLen === 2) { 15954 tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; 15955 arr[curByte++] = tmp & 255; 15956 } 15957 if (placeHoldersLen === 1) { 15958 tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; 15959 arr[curByte++] = tmp >> 8 & 255; 15960 arr[curByte++] = tmp & 255; 15961 } 15962 return arr; 15963 } 15964 function tripletToBase64(num) { 15965 return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63]; 15966 } 15967 function encodeChunk(uint8, start, end) { 15968 var tmp; 15969 var output = [ 15970 ]; 15971 for (var i = start; i < end; i += 3) { 15972 tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255); 15973 output.push(tripletToBase64(tmp)); 15974 } 15975 return output.join(''); 15976 } 15977 function fromByteArray(uint8) { 15978 var tmp; 15979 var len = uint8.length; 15980 var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes 15981 var parts = [ 15982 ]; 15983 var maxChunkLength = 16383; // must be multiple of 3 15984 // go through the array every three bytes, we'll deal with trailing stuff later 15985 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { 15986 parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); 15987 } // pad the end with zeros, but make sure to not forget the extra bytes 15988 15989 if (extraBytes === 1) { 15990 tmp = uint8[len - 1]; 15991 parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + '=='); 15992 } else if (extraBytes === 2) { 15993 tmp = (uint8[len - 2] << 8) + uint8[len - 1]; 15994 parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + '='); 15995 } 15996 return parts.join(''); 15997 } 15998 }, 15999 { 16000 } 16001 ], 16002 21: [
vendor: 6,138 bytes, lines 16003-16139
16003 function (_dereq_, module, exports) { 16004 }, 16005 { 16006 } 16007 ], 16008 22: [ 16009 function (_dereq_, module, exports) { 16010 (function (Buffer) { 16011 /*! 16012 * The buffer module from node.js, for the browser. 16013 * 16014 * @author Feross Aboukhadijeh <https://feross.org> 16015 * @license MIT 16016 */ 16017 /* eslint-disable no-proto */ 16018 'use strict'; 16019 var base64 = _dereq_('base64-js'); 16020 var ieee754 = _dereq_('ieee754'); 16021 var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : null; 16022 exports.Buffer = Buffer; 16023 exports.SlowBuffer = SlowBuffer; 16024 exports.INSPECT_MAX_BYTES = 50; 16025 var K_MAX_LENGTH = 2147483647; 16026 exports.kMaxLength = K_MAX_LENGTH; 16027 /** 16028 * If `Buffer.TYPED_ARRAY_SUPPORT`: 16029 * === true Use Uint8Array implementation (fastest) 16030 * === false Print warning and recommend using `buffer` v4.x which has an Object 16031 * implementation (most compatible, even IE6) 16032 * 16033 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, 16034 * Opera 11.6+, iOS 4.2+. 16035 * 16036 * We report that the browser does not support typed arrays if the are not subclassable 16037 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` 16038 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support 16039 * for __proto__ and has a buggy typed array implementation. 16040 */ 16041 Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); 16042 if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') { 16043 console.error('This browser lacks typed array (Uint8Array) support which is required by ' + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'); 16044 } 16045 function typedArraySupport() { 16046 // Can typed array instances can be augmented? 16047 try { 16048 var arr = new Uint8Array(1); 16049 var proto = { 16050 foo: function () { 16051 return 42; 16052 } 16053 }; 16054 Object.setPrototypeOf(proto, Uint8Array.prototype); 16055 Object.setPrototypeOf(arr, proto); 16056 return arr.foo() === 42; 16057 } catch (e) { 16058 return false; 16059 } 16060 } 16061 Object.defineProperty(Buffer.prototype, 'parent', { 16062 enumerable: true, 16063 get: function () { 16064 if (!Buffer.isBuffer(this)) return undefined; 16065 return this.buffer; 16066 } 16067 }); 16068 Object.defineProperty(Buffer.prototype, 'offset', { 16069 enumerable: true, 16070 get: function () { 16071 if (!Buffer.isBuffer(this)) return undefined; 16072 return this.byteOffset; 16073 } 16074 }); 16075 function createBuffer(length) { 16076 if (length > K_MAX_LENGTH) { 16077 throw new RangeError('The value "' + length + '" is invalid for option "size"'); 16078 } // Return an augmented `Uint8Array` instance 16079 16080 var buf = new Uint8Array(length); 16081 Object.setPrototypeOf(buf, Buffer.prototype); 16082 return buf; 16083 } /** 16084 * The Buffer constructor returns instances of `Uint8Array` that have their 16085 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of 16086 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods 16087 * and the `Uint8Array` methods. Square bracket notation works as expected -- it 16088 * returns a single octet. 16089 * 16090 * The `Uint8Array` prototype remains unmodified. 16091 */ 16092 16093 function Buffer(arg, encodingOrOffset, length) { 16094 // Common case. 16095 if (typeof arg === 'number') { 16096 if (typeof encodingOrOffset === 'string') { 16097 throw new TypeError('The "string" argument must be of type string. Received type number'); 16098 } 16099 return allocUnsafe(arg); 16100 } 16101 return from(arg, encodingOrOffset, length); 16102 } // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 16103 16104 if (typeof Symbol !== 'undefined' && Symbol.species != null && Buffer[Symbol.species] === Buffer) { 16105 Object.defineProperty(Buffer, Symbol.species, { 16106 value: null, 16107 configurable: true, 16108 enumerable: false, 16109 writable: false 16110 }); 16111 } 16112 Buffer.poolSize = 8192; // not used by this implementation 16113 function from(value, encodingOrOffset, length) { 16114 if (typeof value === 'string') { 16115 return fromString(value, encodingOrOffset); 16116 } 16117 if (ArrayBuffer.isView(value)) { 16118 return fromArrayLike(value); 16119 } 16120 if (value == null) { 16121 throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + typeof value); 16122 } 16123 if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) { 16124 return fromArrayBuffer(value, encodingOrOffset, length); 16125 } 16126 if (typeof value === 'number') { 16127 throw new TypeError('The "value" argument must not be of type number. Received type number'); 16128 } 16129 var valueOf = value.valueOf && value.valueOf(); 16130 if (valueOf != null && valueOf !== value) { 16131 return Buffer.from(valueOf, encodingOrOffset, length); 16132 } 16133 var b = fromObject(value); 16134 if (b) return b; 16135 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') { 16136 return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length); 16137 } 16138 throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + typeof value); 16139 } /**
vendor: 5,295 bytes, lines 16140-16266
16140 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError 16141 * if value is a number. 16142 * Buffer.from(str[, encoding]) 16143 * Buffer.from(array) 16144 * Buffer.from(buffer) 16145 * Buffer.from(arrayBuffer[, byteOffset[, length]]) 16146 **/ 16147 16148 Buffer.from = function (value, encodingOrOffset, length) { 16149 return from(value, encodingOrOffset, length); 16150 }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: 16151 // https://github.com/feross/buffer/pull/148 16152 Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); 16153 Object.setPrototypeOf(Buffer, Uint8Array); 16154 function assertSize(size) { 16155 if (typeof size !== 'number') { 16156 throw new TypeError('"size" argument must be of type number'); 16157 } else if (size < 0) { 16158 throw new RangeError('The value "' + size + '" is invalid for option "size"'); 16159 } 16160 } 16161 function alloc(size, fill, encoding) { 16162 assertSize(size); 16163 if (size <= 0) { 16164 return createBuffer(size); 16165 } 16166 if (fill !== undefined) { 16167 // Only pay attention to encoding if it's a string. This 16168 // prevents accidentally sending in a number that would 16169 // be interpretted as a start offset. 16170 return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); 16171 } 16172 return createBuffer(size); 16173 } /** 16174 * Creates a new filled Buffer instance. 16175 * alloc(size[, fill[, encoding]]) 16176 **/ 16177 16178 Buffer.alloc = function (size, fill, encoding) { 16179 return alloc(size, fill, encoding); 16180 }; 16181 function allocUnsafe(size) { 16182 assertSize(size); 16183 return createBuffer(size < 0 ? 0 : checked(size) | 0); 16184 } /** 16185 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. 16186 * */ 16187 16188 Buffer.allocUnsafe = function (size) { 16189 return allocUnsafe(size); 16190 }; 16191 /** 16192 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. 16193 */ 16194 Buffer.allocUnsafeSlow = function (size) { 16195 return allocUnsafe(size); 16196 }; 16197 function fromString(string, encoding) { 16198 if (typeof encoding !== 'string' || encoding === '') { 16199 encoding = 'utf8'; 16200 } 16201 if (!Buffer.isEncoding(encoding)) { 16202 throw new TypeError('Unknown encoding: ' + encoding); 16203 } 16204 var length = byteLength(string, encoding) | 0; 16205 var buf = createBuffer(length); 16206 var actual = buf.write(string, encoding); 16207 if (actual !== length) { 16208 // Writing a hex string, for example, that contains invalid characters will 16209 // cause everything after the first invalid character to be ignored. (e.g. 16210 // 'abxxcd' will be treated as 'ab') 16211 buf = buf.slice(0, actual); 16212 } 16213 return buf; 16214 } 16215 function fromArrayLike(array) { 16216 var length = array.length < 0 ? 0 : checked(array.length) | 0; 16217 var buf = createBuffer(length); 16218 for (var i = 0; i < length; i += 1) { 16219 buf[i] = array[i] & 255; 16220 } 16221 return buf; 16222 } 16223 function fromArrayBuffer(array, byteOffset, length) { 16224 if (byteOffset < 0 || array.byteLength < byteOffset) { 16225 throw new RangeError('"offset" is outside of buffer bounds'); 16226 } 16227 if (array.byteLength < byteOffset + (length || 0)) { 16228 throw new RangeError('"length" is outside of buffer bounds'); 16229 } 16230 var buf; 16231 if (byteOffset === undefined && length === undefined) { 16232 buf = new Uint8Array(array); 16233 } else if (length === undefined) { 16234 buf = new Uint8Array(array, byteOffset); 16235 } else { 16236 buf = new Uint8Array(array, byteOffset, length); 16237 } // Return an augmented `Uint8Array` instance 16238 16239 Object.setPrototypeOf(buf, Buffer.prototype); 16240 return buf; 16241 } 16242 function fromObject(obj) { 16243 if (Buffer.isBuffer(obj)) { 16244 var len = checked(obj.length) | 0; 16245 var buf = createBuffer(len); 16246 if (buf.length === 0) { 16247 return buf; 16248 } 16249 obj.copy(buf, 0, 0, len); 16250 return buf; 16251 } 16252 if (obj.length !== undefined) { 16253 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { 16254 return createBuffer(0); 16255 } 16256 return fromArrayLike(obj); 16257 } 16258 if (obj.type === 'Buffer' && Array.isArray(obj.data)) { 16259 return fromArrayLike(obj.data); 16260 } 16261 } 16262 function checked(length) { 16263 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when 16264 // length is NaN (which is otherwise coerced to zero.) 16265 if (length >= K_MAX_LENGTH) { 16266 throw new RangeError('Attempt to allocate Buffer larger than maximum ' + '
vendor: 4,785 bytes, lines 16266-16391
16266size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes'); 16267 } 16268 return length | 0; 16269 } 16270 function SlowBuffer(length) { 16271 if ( + length != length) { 16272 // eslint-disable-line eqeqeq 16273 length = 0; 16274 } 16275 return Buffer.alloc( + length); 16276 } 16277 Buffer.isBuffer = function isBuffer(b) { 16278 return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false 16279 }; 16280 Buffer.compare = function compare(a, b) { 16281 if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); 16282 if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); 16283 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { 16284 throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'); 16285 } 16286 if (a === b) return 0; 16287 var x = a.length; 16288 var y = b.length; 16289 for (var i = 0, len = Math.min(x, y); i < len; ++i) { 16290 if (a[i] !== b[i]) { 16291 x = a[i]; 16292 y = b[i]; 16293 break; 16294 } 16295 } 16296 if (x < y) return - 1; 16297 if (y < x) return 1; 16298 return 0; 16299 }; 16300 Buffer.isEncoding = function isEncoding(encoding) { 16301 switch (String(encoding).toLowerCase()) { 16302 case 'hex': 16303 case 'utf8': 16304 case 'utf-8': 16305 case 'ascii': 16306 case 'latin1': 16307 case 'binary': 16308 case 'base64': 16309 case 'ucs2': 16310 case 'ucs-2': 16311 case 'utf16le': 16312 case 'utf-16le': 16313 return true; 16314 default: 16315 return false; 16316 } 16317 }; 16318 Buffer.concat = function concat(list, length) { 16319 if (!Array.isArray(list)) { 16320 throw new TypeError('"list" argument must be an Array of Buffers'); 16321 } 16322 if (list.length === 0) { 16323 return Buffer.alloc(0); 16324 } 16325 var i; 16326 if (length === undefined) { 16327 length = 0; 16328 for (i = 0; i < list.length; ++i) { 16329 length += list[i].length; 16330 } 16331 } 16332 var buffer = Buffer.allocUnsafe(length); 16333 var pos = 0; 16334 for (i = 0; i < list.length; ++i) { 16335 var buf = list[i]; 16336 if (isInstance(buf, Uint8Array)) { 16337 buf = Buffer.from(buf); 16338 } 16339 if (!Buffer.isBuffer(buf)) { 16340 throw new TypeError('"list" argument must be an Array of Buffers'); 16341 } 16342 buf.copy(buffer, pos); 16343 pos += buf.length; 16344 } 16345 return buffer; 16346 }; 16347 function byteLength(string, encoding) { 16348 if (Buffer.isBuffer(string)) { 16349 return string.length; 16350 } 16351 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { 16352 return string.byteLength; 16353 } 16354 if (typeof string !== 'string') { 16355 throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + typeof string); 16356 } 16357 var len = string.length; 16358 var mustMatch = arguments.length > 2 && arguments[2] === true; 16359 if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion 16360 var loweredCase = false; 16361 for (; ; ) { 16362 switch (encoding) { 16363 case 'ascii': 16364 case 'latin1': 16365 case 'binary': 16366 return len; 16367 case 'utf8': 16368 case 'utf-8': 16369 return utf8ToBytes(string).length; 16370 case 'ucs2': 16371 case 'ucs-2': 16372 case 'utf16le': 16373 case 'utf-16le': 16374 return len * 2; 16375 case 'hex': 16376 return len >>> 1; 16377 case 'base64': 16378 return base64ToBytes(string).length; 16379 default: 16380 if (loweredCase) { 16381 return mustMatch ? - 1 : utf8ToBytes(string).length; // assume utf8 16382 } 16383 encoding = ('' + encoding).toLowerCase(); 16384 loweredCase = true; 16385 } 16386 } 16387 } 16388 Buffer.byteLength = byteLength; 16389 function slowToString(encoding, start, end) { 16390 var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only 16391 // property of a typed array.
vendor: 4,159 bytes, lines 16392-16494
16392 // This behaves neither like String nor Uint8Array in that we set start/end 16393 // to their upper/lower bounds if the value passed is out of range. 16394 // undefined is handled specially as per ECMA-262 6th Edition, 16395 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. 16396 if (start === undefined || start < 0) { 16397 start = 0; 16398 } // Return early if start > this.length. Done here to prevent potential uint32 16399 // coercion fail below. 16400 16401 if (start > this.length) { 16402 return ''; 16403 } 16404 if (end === undefined || end > this.length) { 16405 end = this.length; 16406 } 16407 if (end <= 0) { 16408 return ''; 16409 } // Force coersion to uint32. This will also coerce falsey/NaN values to 0. 16410 16411 end >>>= 0; 16412 start >>>= 0; 16413 if (end <= start) { 16414 return ''; 16415 } 16416 if (!encoding) encoding = 'utf8'; 16417 while (true) { 16418 switch (encoding) { 16419 case 'hex': 16420 return hexSlice(this, start, end); 16421 case 'utf8': 16422 case 'utf-8': 16423 return utf8Slice(this, start, end); 16424 case 'ascii': 16425 return asciiSlice(this, start, end); 16426 case 'latin1': 16427 case 'binary': 16428 return latin1Slice(this, start, end); 16429 case 'base64': 16430 return base64Slice(this, start, end); 16431 case 'ucs2': 16432 case 'ucs-2': 16433 case 'utf16le': 16434 case 'utf-16le': 16435 return utf16leSlice(this, start, end); 16436 default: 16437 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); 16438 encoding = (encoding + '').toLowerCase(); 16439 loweredCase = true; 16440 } 16441 } 16442 } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) 16443 // to detect a Buffer instance. It's not possible to use `instanceof Buffer` 16444 // reliably in a browserify context because there could be multiple different 16445 // copies of the 'buffer' package in use. This method works even for Buffer 16446 // instances that were created from another copy of the `buffer` package. 16447 // See: https://github.com/feross/buffer/issues/154 16448 16449 Buffer.prototype._isBuffer = true; 16450 function swap(b, n, m) { 16451 var i = b[n]; 16452 b[n] = b[m]; 16453 b[m] = i; 16454 } 16455 Buffer.prototype.swap16 = function swap16() { 16456 var len = this.length; 16457 if (len % 2 !== 0) { 16458 throw new RangeError('Buffer size must be a multiple of 16-bits'); 16459 } 16460 for (var i = 0; i < len; i += 2) { 16461 swap(this, i, i + 1); 16462 } 16463 return this; 16464 }; 16465 Buffer.prototype.swap32 = function swap32() { 16466 var len = this.length; 16467 if (len % 4 !== 0) { 16468 throw new RangeError('Buffer size must be a multiple of 32-bits'); 16469 } 16470 for (var i = 0; i < len; i += 4) { 16471 swap(this, i, i + 3); 16472 swap(this, i + 1, i + 2); 16473 } 16474 return this; 16475 }; 16476 Buffer.prototype.swap64 = function swap64() { 16477 var len = this.length; 16478 if (len % 8 !== 0) { 16479 throw new RangeError('Buffer size must be a multiple of 64-bits'); 16480 } 16481 for (var i = 0; i < len; i += 8) { 16482 swap(this, i, i + 7); 16483 swap(this, i + 1, i + 6); 16484 swap(this, i + 2, i + 5); 16485 swap(this, i + 3, i + 4); 16486 } 16487 return this; 16488 }; 16489 Buffer.prototype.toString = function toString() { 16490 var length = this.length; 16491 if (length === 0) return ''; 16492 if (arguments.length === 0) return utf8Slice(this, 0, length); 16493 return slowToString.apply(this, arguments); 16494 };
vendor: 4,655 bytes, lines 16495-16602
16495 Buffer.prototype.toLocaleString = Buffer.prototype.toString; 16496 Buffer.prototype.equals = function equals(b) { 16497 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); 16498 if (this === b) return true; 16499 return Buffer.compare(this, b) === 0; 16500 }; 16501 Buffer.prototype.inspect = function inspect() { 16502 var str = ''; 16503 var max = exports.INSPECT_MAX_BYTES; 16504 str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); 16505 if (this.length > max) str += ' ... '; 16506 return '<Buffer ' + str + '>'; 16507 }; 16508 if (customInspectSymbol) { 16509 Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect; 16510 } 16511 Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { 16512 if (isInstance(target, Uint8Array)) { 16513 target = Buffer.from(target, target.offset, target.byteLength); 16514 } 16515 if (!Buffer.isBuffer(target)) { 16516 throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + typeof target); 16517 } 16518 if (start === undefined) { 16519 start = 0; 16520 } 16521 if (end === undefined) { 16522 end = target ? target.length : 0; 16523 } 16524 if (thisStart === undefined) { 16525 thisStart = 0; 16526 } 16527 if (thisEnd === undefined) { 16528 thisEnd = this.length; 16529 } 16530 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { 16531 throw new RangeError('out of range index'); 16532 } 16533 if (thisStart >= thisEnd && start >= end) { 16534 return 0; 16535 } 16536 if (thisStart >= thisEnd) { 16537 return - 1; 16538 } 16539 if (start >= end) { 16540 return 1; 16541 } 16542 start >>>= 0; 16543 end >>>= 0; 16544 thisStart >>>= 0; 16545 thisEnd >>>= 0; 16546 if (this === target) return 0; 16547 var x = thisEnd - thisStart; 16548 var y = end - start; 16549 var len = Math.min(x, y); 16550 var thisCopy = this.slice(thisStart, thisEnd); 16551 var targetCopy = target.slice(start, end); 16552 for (var i = 0; i < len; ++i) { 16553 if (thisCopy[i] !== targetCopy[i]) { 16554 x = thisCopy[i]; 16555 y = targetCopy[i]; 16556 break; 16557 } 16558 } 16559 if (x < y) return - 1; 16560 if (y < x) return 1; 16561 return 0; 16562 }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, 16563 // OR the last index of `val` in `buffer` at offset <= `byteOffset`. 16564 // 16565 // Arguments: 16566 // - buffer - a Buffer to search 16567 // - val - a string, Buffer, or number 16568 // - byteOffset - an index into `buffer`; will be clamped to an int32 16569 // - encoding - an optional encoding, relevant is val is a string 16570 // - dir - true for indexOf, false for lastIndexOf 16571 function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { 16572 // Empty buffer means no match 16573 if (buffer.length === 0) return - 1; // Normalize byteOffset 16574 if (typeof byteOffset === 'string') { 16575 encoding = byteOffset; 16576 byteOffset = 0; 16577 } else if (byteOffset > 2147483647) { 16578 byteOffset = 2147483647; 16579 } else if (byteOffset < - 2147483648) { 16580 byteOffset = - 2147483648; 16581 } 16582 byteOffset = + byteOffset; // Coerce to Number. 16583 if (numberIsNaN(byteOffset)) { 16584 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer 16585 byteOffset = dir ? 0 : buffer.length - 1; 16586 } // Normalize byteOffset: negative offsets start from the end of the buffer 16587 16588 if (byteOffset < 0) byteOffset = buffer.length + byteOffset; 16589 if (byteOffset >= buffer.length) { 16590 if (dir) return - 1; 16591 else byteOffset = buffer.length - 1; 16592 } else if (byteOffset < 0) { 16593 if (dir) byteOffset = 0; 16594 else return - 1; 16595 } // Normalize val 16596 16597 if (typeof val === 'string') { 16598 val = Buffer.from(val, encoding); 16599 } // Finally, search either indexOf (if dir is true) or lastIndexOf 16600 16601 if (Buffer.isBuffer(val)) { 16602 // Special case: looking for empty string/buffer always fail
vendor: 26,941 bytes, lines 16602-17221
16602s 16603 if (val.length === 0) { 16604 return - 1; 16605 } 16606 return arrayIndexOf(buffer, val, byteOffset, encoding, dir); 16607 } else if (typeof val === 'number') { 16608 val = val & 255; // Search for a byte value [0-255] 16609 if (typeof Uint8Array.prototype.indexOf === 'function') { 16610 if (dir) { 16611 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); 16612 } else { 16613 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); 16614 } 16615 } 16616 return arrayIndexOf(buffer, [ 16617 val 16618 ], byteOffset, encoding, dir); 16619 } 16620 throw new TypeError('val must be string, number or Buffer'); 16621 } 16622 function arrayIndexOf(arr, val, byteOffset, encoding, dir) { 16623 var indexSize = 1; 16624 var arrLength = arr.length; 16625 var valLength = val.length; 16626 if (encoding !== undefined) { 16627 encoding = String(encoding).toLowerCase(); 16628 if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') { 16629 if (arr.length < 2 || val.length < 2) { 16630 return - 1; 16631 } 16632 indexSize = 2; 16633 arrLength /= 2; 16634 valLength /= 2; 16635 byteOffset /= 2; 16636 } 16637 } 16638 function read(buf, i) { 16639 if (indexSize === 1) { 16640 return buf[i]; 16641 } else { 16642 return buf.readUInt16BE(i * indexSize); 16643 } 16644 } 16645 var i; 16646 if (dir) { 16647 var foundIndex = - 1; 16648 for (i = byteOffset; i < arrLength; i++) { 16649 if (read(arr, i) === read(val, foundIndex === - 1 ? 0 : i - foundIndex)) { 16650 if (foundIndex === - 1) foundIndex = i; 16651 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; 16652 } else { 16653 if (foundIndex !== - 1) i -= i - foundIndex; 16654 foundIndex = - 1; 16655 } 16656 } 16657 } else { 16658 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; 16659 for (i = byteOffset; i >= 0; i--) { 16660 var found = true; 16661 for (var j = 0; j < valLength; j++) { 16662 if (read(arr, i + j) !== read(val, j)) { 16663 found = false; 16664 break; 16665 } 16666 } 16667 if (found) return i; 16668 } 16669 } 16670 return - 1; 16671 } 16672 Buffer.prototype.includes = function includes(val, byteOffset, encoding) { 16673 return this.indexOf(val, byteOffset, encoding) !== - 1; 16674 }; 16675 Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { 16676 return bidirectionalIndexOf(this, val, byteOffset, encoding, true); 16677 }; 16678 Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { 16679 return bidirectionalIndexOf(this, val, byteOffset, encoding, false); 16680 }; 16681 function hexWrite(buf, string, offset, length) { 16682 offset = Number(offset) || 0; 16683 var remaining = buf.length - offset; 16684 if (!length) { 16685 length = remaining; 16686 } else { 16687 length = Number(length); 16688 if (length > remaining) { 16689 length = remaining; 16690 } 16691 } 16692 var strLen = string.length; 16693 if (length > strLen / 2) { 16694 length = strLen / 2; 16695 } 16696 for (var i = 0; i < length; ++i) { 16697 var parsed = parseInt(string.substr(i * 2, 2), 16); 16698 if (numberIsNaN(parsed)) return i; 16699 buf[offset + i] = parsed; 16700 } 16701 return i; 16702 } 16703 function utf8Write(buf, string, offset, length) { 16704 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); 16705 } 16706 function asciiWrite(buf, string, offset, length) { 16707 return blitBuffer(asciiToBytes(string), buf, offset, length); 16708 } 16709 function latin1Write(buf, string, offset, length) { 16710 return asciiWrite(buf, string, offset, length); 16711 } 16712 function base64Write(buf, string, offset, length) { 16713 return blitBuffer(base64ToBytes(string), buf, offset, length); 16714 } 16715 function ucs2Write(buf, string, offset, length) { 16716 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); 16717 } 16718 Buffer.prototype.write = function write(string, offset, length, encoding) { 16719 // Buffer#write(string) 16720 if (offset === undefined) { 16721 encoding = 'utf8'; 16722 length = this.length; 16723 offset = 0; // Buffer#write(string, encoding) 16724 } else if (length === undefined && typeof offset === 'string') { 16725 encoding = offset; 16726 length = this.length; 16727 offset = 0; // Buffer#write(string, offset[, length][, encoding]) 16728 } else if (isFinite(offset)) { 16729 offset = offset >>> 0; 16730 if (isFinite(length)) { 16731 length = length >>> 0; 16732 if (encoding === undefined) encoding = 'utf8'; 16733 } else { 16734 encoding = length; 16735 length = undefined; 16736 } 16737 } else { 16738 throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported'); 16739 } 16740 var remaining = this.length - offset; 16741 if (length === undefined || length > remaining) length = remaining; 16742 if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { 16743 throw new RangeError('Attempt to write outside buffer bounds'); 16744 } 16745 if (!encoding) encoding = 'utf8'; 16746 var loweredCase = false; 16747 for (; ; ) { 16748 switch (encoding) { 16749 case 'hex': 16750 return hexWrite(this, string, offset, length); 16751 case 'utf8': 16752 case 'utf-8': 16753 return utf8Write(this, string, offset, length); 16754 case 'ascii': 16755 return asciiWrite(this, string, offset, length); 16756 case 'latin1': 16757 case 'binary': 16758 return latin1Write(this, string, offset, length); 16759 case 'base64': 16760 // Warning: maxLength not taken into account in base64Write 16761 return base64Write(this, string, offset, length); 16762 case 'ucs2': 16763 case 'ucs-2': 16764 case 'utf16le': 16765 case 'utf-16le': 16766 return ucs2Write(this, string, offset, length); 16767 default: 16768 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); 16769 encoding = ('' + encoding).toLowerCase(); 16770 loweredCase = true; 16771 } 16772 } 16773 }; 16774 Buffer.prototype.toJSON = function toJSON() { 16775 return { 16776 type: 'Buffer', 16777 data: Array.prototype.slice.call(this._arr || this, 0) 16778 }; 16779 }; 16780 function base64Slice(buf, start, end) { 16781 if (start === 0 && end === buf.length) { 16782 return base64.fromByteArray(buf); 16783 } else { 16784 return base64.fromByteArray(buf.slice(start, end)); 16785 } 16786 } 16787 function utf8Slice(buf, start, end) { 16788 end = Math.min(buf.length, end); 16789 var res = [ 16790 ]; 16791 var i = start; 16792 while (i < end) { 16793 var firstByte = buf[i]; 16794 var codePoint = null; 16795 var bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; 16796 if (i + bytesPerSequence <= end) { 16797 var secondByte, 16798 thirdByte, 16799 fourthByte, 16800 tempCodePoint; 16801 switch (bytesPerSequence) { 16802 case 1: 16803 if (firstByte < 128) { 16804 codePoint = firstByte; 16805 } 16806 break; 16807 case 2: 16808 secondByte = buf[i + 1]; 16809 if ((secondByte & 192) === 128) { 16810 tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; 16811 if (tempCodePoint > 127) { 16812 codePoint = tempCodePoint; 16813 } 16814 } 16815 break; 16816 case 3: 16817 secondByte = buf[i + 1]; 16818 thirdByte = buf[i + 2]; 16819 if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { 16820 tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; 16821 if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { 16822 codePoint = tempCodePoint; 16823 } 16824 } 16825 break; 16826 case 4: 16827 secondByte = buf[i + 1]; 16828 thirdByte = buf[i + 2]; 16829 fourthByte = buf[i + 3]; 16830 if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { 16831 tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; 16832 if (tempCodePoint > 65535 && tempCodePoint < 1114112) { 16833 codePoint = tempCodePoint; 16834 } 16835 } 16836 } 16837 } 16838 if (codePoint === null) { 16839 // we did not generate a valid codePoint so insert a 16840 // replacement char (U+FFFD) and advance only 1 byte 16841 codePoint = 65533; 16842 bytesPerSequence = 1; 16843 } else if (codePoint > 65535) { 16844 // encode to utf16 (surrogate pair dance) 16845 codePoint -= 65536; 16846 res.push(codePoint >>> 10 & 1023 | 55296); 16847 codePoint = 56320 | codePoint & 1023; 16848 } 16849 res.push(codePoint); 16850 i += bytesPerSequence; 16851 } 16852 return decodeCodePointsArray(res); 16853 } // Based on http://stackoverflow.com/a/22747272/680742, the browser with 16854 // the lowest limit is Chrome, with 0x10000 args. 16855 // We go 1 magnitude less, for safety 16856 16857 var MAX_ARGUMENTS_LENGTH = 4096; 16858 function decodeCodePointsArray(codePoints) { 16859 var len = codePoints.length; 16860 if (len <= MAX_ARGUMENTS_LENGTH) { 16861 return String.fromCharCode.apply(String, codePoints); // avoid extra slice() 16862 } // Decode in chunks to avoid "call stack size exceeded". 16863 16864 var res = ''; 16865 var i = 0; 16866 while (i < len) { 16867 res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); 16868 } 16869 return res; 16870 } 16871 function asciiSlice(buf, start, end) { 16872 var ret = ''; 16873 end = Math.min(buf.length, end); 16874 for (var i = start; i < end; ++i) { 16875 ret += String.fromCharCode(buf[i] & 127); 16876 } 16877 return ret; 16878 } 16879 function latin1Slice(buf, start, end) { 16880 var ret = ''; 16881 end = Math.min(buf.length, end); 16882 for (var i = start; i < end; ++i) { 16883 ret += String.fromCharCode(buf[i]); 16884 } 16885 return ret; 16886 } 16887 function hexSlice(buf, start, end) { 16888 var len = buf.length; 16889 if (!start || start < 0) start = 0; 16890 if (!end || end < 0 || end > len) end = len; 16891 var out = ''; 16892 for (var i = start; i < end; ++i) { 16893 out += hexSliceLookupTable[buf[i]]; 16894 } 16895 return out; 16896 } 16897 function utf16leSlice(buf, start, end) { 16898 var bytes = buf.slice(start, end); 16899 var res = ''; 16900 for (var i = 0; i < bytes.length; i += 2) { 16901 res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); 16902 } 16903 return res; 16904 } 16905 Buffer.prototype.slice = function slice(start, end) { 16906 var len = this.length; 16907 start = ~~start; 16908 end = end === undefined ? len : ~~end; 16909 if (start < 0) { 16910 start += len; 16911 if (start < 0) start = 0; 16912 } else if (start > len) { 16913 start = len; 16914 } 16915 if (end < 0) { 16916 end += len; 16917 if (end < 0) end = 0; 16918 } else if (end > len) { 16919 end = len; 16920 } 16921 if (end < start) end = start; 16922 var newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance 16923 Object.setPrototypeOf(newBuf, Buffer.prototype); 16924 return newBuf; 16925 }; 16926 /* 16927 * Need to make sure that buffer isn't trying to write out of bounds. 16928 */ 16929 function checkOffset(offset, ext, length) { 16930 if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); 16931 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length'); 16932 } 16933 Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { 16934 offset = offset >>> 0; 16935 byteLength = byteLength >>> 0; 16936 if (!noAssert) checkOffset(offset, byteLength, this.length); 16937 var val = this[offset]; 16938 var mul = 1; 16939 var i = 0; 16940 while (++i < byteLength && (mul *= 256)) { 16941 val += this[offset + i] * mul; 16942 } 16943 return val; 16944 }; 16945 Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { 16946 offset = offset >>> 0; 16947 byteLength = byteLength >>> 0; 16948 if (!noAssert) { 16949 checkOffset(offset, byteLength, this.length); 16950 } 16951 var val = this[offset + --byteLength]; 16952 var mul = 1; 16953 while (byteLength > 0 && (mul *= 256)) { 16954 val += this[offset + --byteLength] * mul; 16955 } 16956 return val; 16957 }; 16958 Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { 16959 offset = offset >>> 0; 16960 if (!noAssert) checkOffset(offset, 1, this.length); 16961 return this[offset]; 16962 }; 16963 Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { 16964 offset = offset >>> 0; 16965 if (!noAssert) checkOffset(offset, 2, this.length); 16966 return this[offset] | this[offset + 1] << 8; 16967 }; 16968 Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { 16969 offset = offset >>> 0; 16970 if (!noAssert) checkOffset(offset, 2, this.length); 16971 return this[offset] << 8 | this[offset + 1]; 16972 }; 16973 Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { 16974 offset = offset >>> 0; 16975 if (!noAssert) checkOffset(offset, 4, this.length); 16976 return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216; 16977 }; 16978 Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { 16979 offset = offset >>> 0; 16980 if (!noAssert) checkOffset(offset, 4, this.length); 16981 return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); 16982 }; 16983 Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { 16984 offset = offset >>> 0; 16985 byteLength = byteLength >>> 0; 16986 if (!noAssert) checkOffset(offset, byteLength, this.length); 16987 var val = this[offset]; 16988 var mul = 1; 16989 var i = 0; 16990 while (++i < byteLength && (mul *= 256)) { 16991 val += this[offset + i] * mul; 16992 } 16993 mul *= 128; 16994 if (val >= mul) val -= Math.pow(2, 8 * byteLength); 16995 return val; 16996 }; 16997 Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { 16998 offset = offset >>> 0; 16999 byteLength = byteLength >>> 0; 17000 if (!noAssert) checkOffset(offset, byteLength, this.length); 17001 var i = byteLength; 17002 var mul = 1; 17003 var val = this[offset + --i]; 17004 while (i > 0 && (mul *= 256)) { 17005 val += this[offset + --i] * mul; 17006 } 17007 mul *= 128; 17008 if (val >= mul) val -= Math.pow(2, 8 * byteLength); 17009 return val; 17010 }; 17011 Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { 17012 offset = offset >>> 0; 17013 if (!noAssert) checkOffset(offset, 1, this.length); 17014 if (!(this[offset] & 128)) return this[offset]; 17015 return (255 - this[offset] + 1) * - 1; 17016 }; 17017 Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { 17018 offset = offset >>> 0; 17019 if (!noAssert) checkOffset(offset, 2, this.length); 17020 var val = this[offset] | this[offset + 1] << 8; 17021 return val & 32768 ? val | 4294901760 : val; 17022 }; 17023 Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { 17024 offset = offset >>> 0; 17025 if (!noAssert) checkOffset(offset, 2, this.length); 17026 var val = this[offset + 1] | this[offset] << 8; 17027 return val & 32768 ? val | 4294901760 : val; 17028 }; 17029 Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { 17030 offset = offset >>> 0; 17031 if (!noAssert) checkOffset(offset, 4, this.length); 17032 return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; 17033 }; 17034 Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { 17035 offset = offset >>> 0; 17036 if (!noAssert) checkOffset(offset, 4, this.length); 17037 return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; 17038 }; 17039 Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { 17040 offset = offset >>> 0; 17041 if (!noAssert) checkOffset(offset, 4, this.length); 17042 return ieee754.read(this, offset, true, 23, 4); 17043 }; 17044 Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { 17045 offset = offset >>> 0; 17046 if (!noAssert) checkOffset(offset, 4, this.length); 17047 return ieee754.read(this, offset, false, 23, 4); 17048 }; 17049 Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { 17050 offset = offset >>> 0; 17051 if (!noAssert) checkOffset(offset, 8, this.length); 17052 return ieee754.read(this, offset, true, 52, 8); 17053 }; 17054 Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { 17055 offset = offset >>> 0; 17056 if (!noAssert) checkOffset(offset, 8, this.length); 17057 return ieee754.read(this, offset, false, 52, 8); 17058 }; 17059 function checkInt(buf, value, offset, ext, max, min) { 17060 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance'); 17061 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); 17062 if (offset + ext > buf.length) throw new RangeError('Index out of range'); 17063 } 17064 Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { 17065 value = + value; 17066 offset = offset >>> 0; 17067 byteLength = byteLength >>> 0; 17068 if (!noAssert) { 17069 var maxBytes = Math.pow(2, 8 * byteLength) - 1; 17070 checkInt(this, value, offset, byteLength, maxBytes, 0); 17071 } 17072 var mul = 1; 17073 var i = 0; 17074 this[offset] = value & 255; 17075 while (++i < byteLength && (mul *= 256)) { 17076 this[offset + i] = value / mul & 255; 17077 } 17078 return offset + byteLength; 17079 }; 17080 Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { 17081 value = + value; 17082 offset = offset >>> 0; 17083 byteLength = byteLength >>> 0; 17084 if (!noAssert) { 17085 var maxBytes = Math.pow(2, 8 * byteLength) - 1; 17086 checkInt(this, value, offset, byteLength, maxBytes, 0); 17087 } 17088 var i = byteLength - 1; 17089 var mul = 1; 17090 this[offset + i] = value & 255; 17091 while (--i >= 0 && (mul *= 256)) { 17092 this[offset + i] = value / mul & 255; 17093 } 17094 return offset + byteLength; 17095 }; 17096 Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { 17097 value = + value; 17098 offset = offset >>> 0; 17099 if (!noAssert) checkInt(this, value, offset, 1, 255, 0); 17100 this[offset] = value & 255; 17101 return offset + 1; 17102 }; 17103 Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { 17104 value = + value; 17105 offset = offset >>> 0; 17106 if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); 17107 this[offset] = value & 255; 17108 this[offset + 1] = value >>> 8; 17109 return offset + 2; 17110 }; 17111 Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { 17112 value = + value; 17113 offset = offset >>> 0; 17114 if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); 17115 this[offset] = value >>> 8; 17116 this[offset + 1] = value & 255; 17117 return offset + 2; 17118 }; 17119 Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { 17120 value = + value; 17121 offset = offset >>> 0; 17122 if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); 17123 this[offset + 3] = value >>> 24; 17124 this[offset + 2] = value >>> 16; 17125 this[offset + 1] = value >>> 8; 17126 this[offset] = value & 255; 17127 return offset + 4; 17128 }; 17129 Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { 17130 value = + value; 17131 offset = offset >>> 0; 17132 if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); 17133 this[offset] = value >>> 24; 17134 this[offset + 1] = value >>> 16; 17135 this[offset + 2] = value >>> 8; 17136 this[offset + 3] = value & 255; 17137 return offset + 4; 17138 }; 17139 Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { 17140 value = + value; 17141 offset = offset >>> 0; 17142 if (!noAssert) { 17143 var limit = Math.pow(2, 8 * byteLength - 1); 17144 checkInt(this, value, offset, byteLength, limit - 1, - limit); 17145 } 17146 var i = 0; 17147 var mul = 1; 17148 var sub = 0; 17149 this[offset] = value & 255; 17150 while (++i < byteLength && (mul *= 256)) { 17151 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { 17152 sub = 1; 17153 } 17154 this[offset + i] = (value / mul >> 0) - sub & 255; 17155 } 17156 return offset + byteLength; 17157 }; 17158 Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { 17159 value = + value; 17160 offset = offset >>> 0; 17161 if (!noAssert) { 17162 var limit = Math.pow(2, 8 * byteLength - 1); 17163 checkInt(this, value, offset, byteLength, limit - 1, - limit); 17164 } 17165 var i = byteLength - 1; 17166 var mul = 1; 17167 var sub = 0; 17168 this[offset + i] = value & 255; 17169 while (--i >= 0 && (mul *= 256)) { 17170 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { 17171 sub = 1; 17172 } 17173 this[offset + i] = (value / mul >> 0) - sub & 255; 17174 } 17175 return offset + byteLength; 17176 }; 17177 Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { 17178 value = + value; 17179 offset = offset >>> 0; 17180 if (!noAssert) checkInt(this, value, offset, 1, 127, - 128); 17181 if (value < 0) value = 255 + value + 1; 17182 this[offset] = value & 255; 17183 return offset + 1; 17184 }; 17185 Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { 17186 value = + value; 17187 offset = offset >>> 0; 17188 if (!noAssert) checkInt(this, value, offset, 2, 32767, - 32768); 17189 this[offset] = value & 255; 17190 this[offset + 1] = value >>> 8; 17191 return offset + 2; 17192 }; 17193 Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { 17194 value = + value; 17195 offset = offset >>> 0; 17196 if (!noAssert) checkInt(this, value, offset, 2, 32767, - 32768); 17197 this[offset] = value >>> 8; 17198 this[offset + 1] = value & 255; 17199 return offset + 2; 17200 }; 17201 Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { 17202 value = + value; 17203 offset = offset >>> 0; 17204 if (!noAssert) checkInt(this, value, offset, 4, 2147483647, - 2147483648); 17205 this[offset] = value & 255; 17206 this[offset + 1] = value >>> 8; 17207 this[offset + 2] = value >>> 16; 17208 this[offset + 3] = value >>> 24; 17209 return offset + 4; 17210 }; 17211 Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { 17212 value = + value; 17213 offset = offset >>> 0; 17214 if (!noAssert) checkInt(this, value, offset, 4, 2147483647, - 2147483648); 17215 if (value < 0) value = 4294967295 + value + 1; 17216 this[offset] = value >>> 24; 17217 this[offset + 1] = value >>> 16; 17218 this[offset + 2] = value >>> 8; 17219 this[offset + 3] = value & 255; 17220 return offset + 4; 17221 };
vendor: 5,814 bytes, lines 17222-17339
17222 function checkIEEE754(buf, value, offset, ext, max, min) { 17223 if (offset + ext > buf.length) throw new RangeError('Index out of range'); 17224 if (offset < 0) throw new RangeError('Index out of range'); 17225 } 17226 function writeFloat(buf, value, offset, littleEndian, noAssert) { 17227 value = + value; 17228 offset = offset >>> 0; 17229 if (!noAssert) { 17230 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, - 3.4028234663852886e+38); 17231 } 17232 ieee754.write(buf, value, offset, littleEndian, 23, 4); 17233 return offset + 4; 17234 } 17235 Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { 17236 return writeFloat(this, value, offset, true, noAssert); 17237 }; 17238 Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { 17239 return writeFloat(this, value, offset, false, noAssert); 17240 }; 17241 function writeDouble(buf, value, offset, littleEndian, noAssert) { 17242 value = + value; 17243 offset = offset >>> 0; 17244 if (!noAssert) { 17245 checkIEEE754(buf, value, offset, 8, 1.7976931348623157e+308, - 1.7976931348623157e+308); 17246 } 17247 ieee754.write(buf, value, offset, littleEndian, 52, 8); 17248 return offset + 8; 17249 } 17250 Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { 17251 return writeDouble(this, value, offset, true, noAssert); 17252 }; 17253 Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { 17254 return writeDouble(this, value, offset, false, noAssert); 17255 }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) 17256 Buffer.prototype.copy = function copy(target, targetStart, start, end) { 17257 if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer'); 17258 if (!start) start = 0; 17259 if (!end && end !== 0) end = this.length; 17260 if (targetStart >= target.length) targetStart = target.length; 17261 if (!targetStart) targetStart = 0; 17262 if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done 17263 if (end === start) return 0; 17264 if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions 17265 if (targetStart < 0) { 17266 throw new RangeError('targetStart out of bounds'); 17267 } 17268 if (start < 0 || start >= this.length) throw new RangeError('Index out of range'); 17269 if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob? 17270 if (end > this.length) end = this.length; 17271 if (target.length - targetStart < end - start) { 17272 end = target.length - targetStart + start; 17273 } 17274 var len = end - start; 17275 if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { 17276 // Use built-in when available, missing from IE11 17277 this.copyWithin(targetStart, start, end); 17278 } else if (this === target && start < targetStart && targetStart < end) { 17279 // descending copy from end 17280 for (var i = len - 1; i >= 0; --i) { 17281 target[i + targetStart] = this[i + start]; 17282 } 17283 } else { 17284 Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart); 17285 } 17286 return len; 17287 }; // Usage: 17288 // buffer.fill(number[, offset[, end]]) 17289 // buffer.fill(buffer[, offset[, end]]) 17290 // buffer.fill(string[, offset[, end]][, encoding]) 17291 Buffer.prototype.fill = function fill(val, start, end, encoding) { 17292 // Handle string cases: 17293 if (typeof val === 'string') { 17294 if (typeof start === 'string') { 17295 encoding = start; 17296 start = 0; 17297 end = this.length; 17298 } else if (typeof end === 'string') { 17299 encoding = end; 17300 end = this.length; 17301 } 17302 if (encoding !== undefined && typeof encoding !== 'string') { 17303 throw new TypeError('encoding must be a string'); 17304 } 17305 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { 17306 throw new TypeError('Unknown encoding: ' + encoding); 17307 } 17308 if (val.length === 1) { 17309 var code = val.charCodeAt(0); 17310 if (encoding === 'utf8' && code < 128 || encoding === 'latin1') { 17311 // Fast path: If `val` fits into a single byte, use that numeric value. 17312 val = code; 17313 } 17314 } 17315 } else if (typeof val === 'number') { 17316 val = val & 255; 17317 } else if (typeof val === 'boolean') { 17318 val = Number(val); 17319 } // Invalid ranges are not set to a default, so can range check early. 17320 17321 if (start < 0 || this.length < start || this.length < end) { 17322 throw new RangeError('Out of range index'); 17323 } 17324 if (end <= start) { 17325 return this; 17326 } 17327 start = start >>> 0; 17328 end = end === undefined ? this.length : end >>> 0; 17329 if (!val) val = 0; 17330 var i; 17331 if (typeof val === 'number') { 17332 for (i = start; i < end; ++i) { 17333 this[i] = val; 17334 } 17335 } else { 17336 var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding); 17337 var len = bytes.length; 17338 if (len === 0) { 17339 throw new TypeError('The value "' + val + '" is invali
vendor: 5,437 bytes, lines 17339-17468
17339d for argument "value"'); 17340 } 17341 for (i = 0; i < end - start; ++i) { 17342 this[i + start] = bytes[i % len]; 17343 } 17344 } 17345 return this; 17346 }; // HELPER FUNCTIONS 17347 // ================ 17348 var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; 17349 function base64clean(str) { 17350 // Node takes equal signs as end of the Base64 encoding 17351 str = str.split('=') [0]; // Node strips out invalid characters like \n and \t from the string, base64-js does not 17352 str = str.trim().replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to '' 17353 if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not 17354 while (str.length % 4 !== 0) { 17355 str = str + '='; 17356 } 17357 return str; 17358 } 17359 function utf8ToBytes(string, units) { 17360 units = units || Infinity; 17361 var codePoint; 17362 var length = string.length; 17363 var leadSurrogate = null; 17364 var bytes = [ 17365 ]; 17366 for (var i = 0; i < length; ++i) { 17367 codePoint = string.charCodeAt(i); // is surrogate component 17368 if (codePoint > 55295 && codePoint < 57344) { 17369 // last char was a lead 17370 if (!leadSurrogate) { 17371 // no lead yet 17372 if (codePoint > 56319) { 17373 // unexpected trail 17374 if ((units -= 3) > - 1) bytes.push(239, 191, 189); 17375 continue; 17376 } else if (i + 1 === length) { 17377 // unpaired lead 17378 if ((units -= 3) > - 1) bytes.push(239, 191, 189); 17379 continue; 17380 } // valid lead 17381 17382 leadSurrogate = codePoint; 17383 continue; 17384 } // 2 leads in a row 17385 17386 if (codePoint < 56320) { 17387 if ((units -= 3) > - 1) bytes.push(239, 191, 189); 17388 leadSurrogate = codePoint; 17389 continue; 17390 } // valid surrogate pair 17391 17392 codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536; 17393 } else if (leadSurrogate) { 17394 // valid bmp char, but last char was a lead 17395 if ((units -= 3) > - 1) bytes.push(239, 191, 189); 17396 } 17397 leadSurrogate = null; // encode utf8 17398 if (codePoint < 128) { 17399 if ((units -= 1) < 0) break; 17400 bytes.push(codePoint); 17401 } else if (codePoint < 2048) { 17402 if ((units -= 2) < 0) break; 17403 bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128); 17404 } else if (codePoint < 65536) { 17405 if ((units -= 3) < 0) break; 17406 bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); 17407 } else if (codePoint < 1114112) { 17408 if ((units -= 4) < 0) break; 17409 bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); 17410 } else { 17411 throw new Error('Invalid code point'); 17412 } 17413 } 17414 return bytes; 17415 } 17416 function asciiToBytes(str) { 17417 var byteArray = [ 17418 ]; 17419 for (var i = 0; i < str.length; ++i) { 17420 // Node's code seems to be doing this and not & 0x7F.. 17421 byteArray.push(str.charCodeAt(i) & 255); 17422 } 17423 return byteArray; 17424 } 17425 function utf16leToBytes(str, units) { 17426 var c, 17427 hi, 17428 lo; 17429 var byteArray = [ 17430 ]; 17431 for (var i = 0; i < str.length; ++i) { 17432 if ((units -= 2) < 0) break; 17433 c = str.charCodeAt(i); 17434 hi = c >> 8; 17435 lo = c % 256; 17436 byteArray.push(lo); 17437 byteArray.push(hi); 17438 } 17439 return byteArray; 17440 } 17441 function base64ToBytes(str) { 17442 return base64.toByteArray(base64clean(str)); 17443 } 17444 function blitBuffer(src, dst, offset, length) { 17445 for (var i = 0; i < length; ++i) { 17446 if (i + offset >= dst.length || i >= src.length) break; 17447 dst[i + offset] = src[i]; 17448 } 17449 return i; 17450 } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass 17451 // the `instanceof` check but they should be treated as of that type. 17452 // See: https://github.com/feross/buffer/issues/166 17453 17454 function isInstance(obj, type) { 17455 return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name; 17456 } 17457 function numberIsNaN(obj) { 17458 // For IE11 support 17459 return obj !== obj; // eslint-disable-line no-self-compare 17460 } // Create lookup table for `toString('hex')` 17461 // See: https://github.com/feross/buffer/issues/219 17462 17463 var hexSliceLookupTable = function () { 17464 var alphabet = '0123456789abcdef'; 17465 var table = new Array(256); 17466 for (var i = 0; i < 16; ++i) { 17467 var i16 = i * 16; 17468 for (var j = 0; j < 16; ++j) {
17469 table[i16 + j] = alphabet[i] + alphabet[j]; 17470 } 17471 } 17472 return table; 17473 }(); 17474 }).call(this, _dereq_('buffer').Buffer) 17475 }, 17476 { 17477 'base64-js': 20, 17478 'buffer': 22, 17479 'ieee754': 260 17480 } 17481 ], 17482 23: [ 17483 function (_dereq_, module, exports) { 17484 module.exports = function (it) { 17485 if (typeof it != 'function') { 17486 throw TypeError(String(it) + ' is not a function'); 17487 } 17488 return it; 17489 }; 17490 }, 17491 { 17492 } 17493 ], 17494 24: [ 17495 function (_dereq_, module, exports) { 17496 var isObject = _dereq_('../internals/is-object'); 17497 module.exports = function (it) { 17498 if (!isObject(it) && it !== null) { 17499 throw TypeError('Can\'t set ' + String(it) + ' as a prototype'); 17500 } 17501 return it; 17502 }; 17503 }, 17504 { 17505 '../internals/is-object': 92 17506 } 17507 ], 17508 25: [ 17509 function (_dereq_, module, exports) { 17510 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 17511 var create = _dereq_('../internals/object-create'); 17512 var definePropertyModule = _dereq_('../internals/object-define-property'); 17513 var UNSCOPABLES = wellKnownSymbol('unscopables'); 17514 var ArrayPrototype = Array.prototype; // Array.prototype[@@unscopables] 17515 // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables 17516 if (ArrayPrototype[UNSCOPABLES] == undefined) { 17517 definePropertyModule.f(ArrayPrototype, UNSCOPABLES, { 17518 configurable: true, 17519 value: create(null) 17520 }); 17521 } // add a key to Array.prototype[@@unscopables] 17522 17523 module.exports = function (key) { 17524 ArrayPrototype[UNSCOPABLES][key] = true; 17525 }; 17526 }, 17527 { 17528 '../internals/object-create': 108, 17529 '../internals/object-define-property': 110, 17530 '../internals/well-known-symbol': 164 17531 } 17532 ], 17533 26: [ 17534 function (_dereq_, module, exports) { 17535 'use strict'; 17536 var charAt = _dereq_('../internals/string-multibyte').charAt; // `AdvanceStringIndex` abstract operation 17537 // https://tc39.github.io/ecma262/#sec-advancestringindex 17538 module.exports = function (S, index, unicode) { 17539 return index + (unicode ? charAt(S, index).length : 1); 17540 }; 17541 }, 17542 { 17543 '../internals/string-multibyte': 141 17544 } 17545 ], 17546 27: [ 17547 function (_dereq_, module, exports) { 17548 module.exports = function (it, Constructor, name) { 17549 if (!(it instanceof Constructor)) { 17550 throw TypeError('Incorrect ' + (name ? name + ' ' : '') + 'invocation'); 17551 } 17552 return it; 17553 }; 17554 }, 17555 { 17556 } 17557 ], 17558 28: [ 17559 function (_dereq_, module, exports) { 17560 var isObject = _dereq_('../internals/is-object'); 17561 module.exports = function (it) { 17562 if (!isObject(it)) { 17563 throw TypeError(String(it) + ' is not an object'); 17564 } 17565 return it; 17566 }; 17567 }, 17568 { 17569 '../internals/is-object': 92 17570 } 17571 ], 17572 29: [ 17573 function (_dereq_, module, exports) { 17574 module.exports = typeof ArrayBuffer !== 'undefined' && typeof DataView !== 'undefined'; 17575 }, 17576 { 17577 } 17578 ], 17579 30: [ 17580 function (_dereq_, module, exports) { 17581 'use strict'; 17582 var NATIVE_ARRAY_BUFFER = _dereq_('../internals/array-buffer-native'); 17583 var DESCRIPTORS = _dereq_('../internals/descriptors'); 17584 var global = _dereq_('../internals/global'); 17585 var isObject = _dereq_('../internals/is-object'); 17586 var has = _dereq_('../internals/has'); 17587 var classof = _dereq_('../internals/classof'); 17588 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 17589 var redefine = _dereq_('../internals/redefine'); 17590 var defineProperty = _dereq_('../internals/object-define-property').f; 17591 var getPrototypeOf = _dereq_('../internals/object-get-prototype-of'); 17592 var setPrototypeOf = _dereq_('../internals/object-set-prototype-of'); 17593 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 17594 var uid = _dereq_('../internals/uid'); 17595 var Int8Array = global.Int8Array; 17596 var Int8ArrayPrototype = Int8Array && Int8Array.prototype; 17597 var Uint8ClampedArray = global.Uint8ClampedArray; 17598 var Uint8ClampedArrayPrototype = Uint8ClampedArray && Uint8ClampedArray.prototype; 17599 var TypedArray = Int8Array && getPrototypeOf(Int8Array); 17600 var TypedArrayPrototype = Int8ArrayPrototype && getPrototypeOf(Int8ArrayPrototype); 17601 var ObjectPrototype = Object.prototype; 17602 var isPrototypeOf = ObjectPrototype.isPrototypeOf; 17603 var TO_STRING_TAG = wellKnownSymbol('toStringTag'); 17604 var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG'); // Fixing native typed arrays in Opera Presto crashes the browser, see #595 17605 var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof(global.opera) !== 'Opera'; 17606 var TYPED_ARRAY_TAG_REQIRED = false;
vendor: 12,005 bytes, lines 17607-17870
17607 var NAME; 17608 var TypedArrayConstructorsList = { 17609 Int8Array: 1, 17610 Uint8Array: 1, 17611 Uint8ClampedArray: 1, 17612 Int16Array: 2, 17613 Uint16Array: 2, 17614 Int32Array: 4, 17615 Uint32Array: 4, 17616 Float32Array: 4, 17617 Float64Array: 8 17618 }; 17619 var isView = function isView(it) { 17620 var klass = classof(it); 17621 return klass === 'DataView' || has(TypedArrayConstructorsList, klass); 17622 }; 17623 var isTypedArray = function (it) { 17624 return isObject(it) && has(TypedArrayConstructorsList, classof(it)); 17625 }; 17626 var aTypedArray = function (it) { 17627 if (isTypedArray(it)) return it; 17628 throw TypeError('Target is not a typed array'); 17629 }; 17630 var aTypedArrayConstructor = function (C) { 17631 if (setPrototypeOf) { 17632 if (isPrototypeOf.call(TypedArray, C)) return C; 17633 } else for (var ARRAY in TypedArrayConstructorsList) if (has(TypedArrayConstructorsList, NAME)) { 17634 var TypedArrayConstructor = global[ARRAY]; 17635 if (TypedArrayConstructor && (C === TypedArrayConstructor || isPrototypeOf.call(TypedArrayConstructor, C))) { 17636 return C; 17637 } 17638 } 17639 throw TypeError('Target is not a typed array constructor'); 17640 }; 17641 var exportTypedArrayMethod = function (KEY, property, forced) { 17642 if (!DESCRIPTORS) return; 17643 if (forced) for (var ARRAY in TypedArrayConstructorsList) { 17644 var TypedArrayConstructor = global[ARRAY]; 17645 if (TypedArrayConstructor && has(TypedArrayConstructor.prototype, KEY)) { 17646 delete TypedArrayConstructor.prototype[KEY]; 17647 } 17648 } 17649 if (!TypedArrayPrototype[KEY] || forced) { 17650 redefine(TypedArrayPrototype, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property); 17651 } 17652 }; 17653 var exportTypedArrayStaticMethod = function (KEY, property, forced) { 17654 var ARRAY, 17655 TypedArrayConstructor; 17656 if (!DESCRIPTORS) return; 17657 if (setPrototypeOf) { 17658 if (forced) for (ARRAY in TypedArrayConstructorsList) { 17659 TypedArrayConstructor = global[ARRAY]; 17660 if (TypedArrayConstructor && has(TypedArrayConstructor, KEY)) { 17661 delete TypedArrayConstructor[KEY]; 17662 } 17663 } 17664 if (!TypedArray[KEY] || forced) { 17665 // V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable 17666 try { 17667 return redefine(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && Int8Array[KEY] || property); 17668 } catch (error) { 17669 /* empty */ 17670 } 17671 } else return; 17672 } 17673 for (ARRAY in TypedArrayConstructorsList) { 17674 TypedArrayConstructor = global[ARRAY]; 17675 if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) { 17676 redefine(TypedArrayConstructor, KEY, property); 17677 } 17678 } 17679 }; 17680 for (NAME in TypedArrayConstructorsList) { 17681 if (!global[NAME]) NATIVE_ARRAY_BUFFER_VIEWS = false; 17682 } // WebKit bug - typed arrays constructors prototype is Object.prototype 17683 17684 if (!NATIVE_ARRAY_BUFFER_VIEWS || typeof TypedArray != 'function' || TypedArray === Function.prototype) { 17685 // eslint-disable-next-line no-shadow 17686 TypedArray = function TypedArray() { 17687 throw TypeError('Incorrect invocation'); 17688 }; 17689 if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) { 17690 if (global[NAME]) setPrototypeOf(global[NAME], TypedArray); 17691 } 17692 } 17693 if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) { 17694 TypedArrayPrototype = TypedArray.prototype; 17695 if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) { 17696 if (global[NAME]) setPrototypeOf(global[NAME].prototype, TypedArrayPrototype); 17697 } 17698 } // WebKit bug - one more object in Uint8ClampedArray prototype chain 17699 17700 if (NATIVE_ARRAY_BUFFER_VIEWS && getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype) { 17701 setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype); 17702 } 17703 if (DESCRIPTORS && !has(TypedArrayPrototype, TO_STRING_TAG)) { 17704 TYPED_ARRAY_TAG_REQIRED = true; 17705 defineProperty(TypedArrayPrototype, TO_STRING_TAG, { 17706 get: function () { 17707 return isObject(this) ? this[TYPED_ARRAY_TAG] : undefined; 17708 } 17709 }); 17710 for (NAME in TypedArrayConstructorsList) if (global[NAME]) { 17711 createNonEnumerableProperty(global[NAME], TYPED_ARRAY_TAG, NAME); 17712 } 17713 } 17714 module.exports = { 17715 NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS, 17716 TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQIRED && TYPED_ARRAY_TAG, 17717 aTypedArray: aTypedArray, 17718 aTypedArrayConstructor: aTypedArrayConstructor, 17719 exportTypedArrayMethod: exportTypedArrayMethod, 17720 exportTypedArrayStaticMethod: exportTypedArrayStaticMethod, 17721 isView: isView, 17722 isTypedArray: isTypedArray, 17723 TypedArray: TypedArray, 17724 TypedArrayPrototype: TypedArrayPrototype 17725 }; 17726 }, 17727 { 17728 '../internals/array-buffer-native': 29, 17729 '../internals/classof': 47, 17730 '../internals/create-non-enumerable-property': 56, 17731 '../internals/descriptors': 61, 17732 '../internals/global': 77, 17733 '../internals/has': 78, 17734 '../internals/is-object': 92, 17735 '../internals/object-define-property': 110, 17736 '../internals/object-get-prototype-of': 115, 17737 '../internals/object-set-prototype-of': 119, 17738 '../internals/redefine': 126, 17739 '../internals/uid': 161, 17740 '../internals/well-known-symbol': 164 17741 } 17742 ], 17743 31: [ 17744 function (_dereq_, module, exports) { 17745 'use strict'; 17746 var global = _dereq_('../internals/global'); 17747 var DESCRIPTORS = _dereq_('../internals/descriptors'); 17748 var NATIVE_ARRAY_BUFFER = _dereq_('../internals/array-buffer-native'); 17749 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 17750 var redefineAll = _dereq_('../internals/redefine-all'); 17751 var fails = _dereq_('../internals/fails'); 17752 var anInstance = _dereq_('../internals/an-instance'); 17753 var toInteger = _dereq_('../internals/to-integer'); 17754 var toLength = _dereq_('../internals/to-length'); 17755 var toIndex = _dereq_('../internals/to-index'); 17756 var IEEE754 = _dereq_('../internals/ieee754'); 17757 var getPrototypeOf = _dereq_('../internals/object-get-prototype-of'); 17758 var setPrototypeOf = _dereq_('../internals/object-set-prototype-of'); 17759 var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f; 17760 var defineProperty = _dereq_('../internals/object-define-property').f; 17761 var arrayFill = _dereq_('../internals/array-fill'); 17762 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 17763 var InternalStateModule = _dereq_('../internals/internal-state'); 17764 var getInternalState = InternalStateModule.get; 17765 var setInternalState = InternalStateModule.set; 17766 var ARRAY_BUFFER = 'ArrayBuffer'; 17767 var DATA_VIEW = 'DataView'; 17768 var PROTOTYPE = 'prototype'; 17769 var WRONG_LENGTH = 'Wrong length'; 17770 var WRONG_INDEX = 'Wrong index'; 17771 var NativeArrayBuffer = global[ARRAY_BUFFER]; 17772 var $ArrayBuffer = NativeArrayBuffer; 17773 var $DataView = global[DATA_VIEW]; 17774 var $DataViewPrototype = $DataView && $DataView[PROTOTYPE]; 17775 var ObjectPrototype = Object.prototype; 17776 var RangeError = global.RangeError; 17777 var packIEEE754 = IEEE754.pack; 17778 var unpackIEEE754 = IEEE754.unpack; 17779 var packInt8 = function (number) { 17780 return [number & 255]; 17781 }; 17782 var packInt16 = function (number) { 17783 return [number & 255, 17784 number >> 8 & 255]; 17785 }; 17786 var packInt32 = function (number) { 17787 return [number & 255, 17788 number >> 8 & 255, 17789 number >> 16 & 255, 17790 number >> 24 & 255]; 17791 }; 17792 var unpackInt32 = function (buffer) { 17793 return buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]; 17794 }; 17795 var packFloat32 = function (number) { 17796 return packIEEE754(number, 23, 4); 17797 }; 17798 var packFloat64 = function (number) { 17799 return packIEEE754(number, 52, 8); 17800 }; 17801 var addGetter = function (Constructor, key) { 17802 defineProperty(Constructor[PROTOTYPE], key, { 17803 get: function () { 17804 return getInternalState(this) [key]; 17805 } 17806 }); 17807 }; 17808 var get = function (view, count, index, isLittleEndian) { 17809 var intIndex = toIndex(index); 17810 var store = getInternalState(view); 17811 if (intIndex + count > store.byteLength) throw RangeError(WRONG_INDEX); 17812 var bytes = getInternalState(store.buffer).bytes; 17813 var start = intIndex + store.byteOffset; 17814 var pack = bytes.slice(start, start + count); 17815 return isLittleEndian ? pack : pack.reverse(); 17816 }; 17817 var set = function (view, count, index, conversion, value, isLittleEndian) { 17818 var intIndex = toIndex(index); 17819 var store = getInternalState(view); 17820 if (intIndex + count > store.byteLength) throw RangeError(WRONG_INDEX); 17821 var bytes = getInternalState(store.buffer).bytes; 17822 var start = intIndex + store.byteOffset; 17823 var pack = conversion( + value); 17824 for (var i = 0; i < count; i++) bytes[start + i] = pack[isLittleEndian ? i : count - i - 1]; 17825 }; 17826 if (!NATIVE_ARRAY_BUFFER) { 17827 $ArrayBuffer = function ArrayBuffer(length) { 17828 anInstance(this, $ArrayBuffer, ARRAY_BUFFER); 17829 var byteLength = toIndex(length); 17830 setInternalState(this, { 17831 bytes: arrayFill.call(new Array(byteLength), 0), 17832 byteLength: byteLength 17833 }); 17834 if (!DESCRIPTORS) this.byteLength = byteLength; 17835 }; 17836 $DataView = function DataView(buffer, byteOffset, byteLength) { 17837 anInstance(this, $DataView, DATA_VIEW); 17838 anInstance(buffer, $ArrayBuffer, DATA_VIEW); 17839 var bufferLength = getInternalState(buffer).byteLength; 17840 var offset = toInteger(byteOffset); 17841 if (offset < 0 || offset > bufferLength) throw RangeError('Wrong offset'); 17842 byteLength = byteLength === undefined ? bufferLength - offset : toLength(byteLength); 17843 if (offset + byteLength > bufferLength) throw RangeError(WRONG_LENGTH); 17844 setInternalState(this, { 17845 buffer: buffer, 17846 byteLength: byteLength, 17847 byteOffset: offset 17848 }); 17849 if (!DESCRIPTORS) { 17850 this.buffer = buffer; 17851 this.byteLength = byteLength; 17852 this.byteOffset = offset; 17853 } 17854 }; 17855 if (DESCRIPTORS) { 17856 addGetter($ArrayBuffer, 'byteLength'); 17857 addGetter($DataView, 'buffer'); 17858 addGetter($DataView, 'byteLength'); 17859 addGetter($DataView, 'byteOffset'); 17860 } 17861 redefineAll($DataView[PROTOTYPE], { 17862 getInt8: function getInt8(byteOffset) { 17863 return get(this, 1, byteOffset) [0] << 24 >> 24; 17864 }, 17865 getUint8: function getUint8(byteOffset) { 17866 return get(this, 1, byteOffset) [0]; 17867 }, 17868 getInt16: function getInt16(byteOffset /* , littleEndian */ 17869 ) { 17870 var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : undefined);
vendor: 12,233 bytes, lines 17871-18142
17871 return (bytes[1] << 8 | bytes[0]) << 16 >> 16; 17872 }, 17873 getUint16: function getUint16(byteOffset /* , littleEndian */ 17874 ) { 17875 var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : undefined); 17876 return bytes[1] << 8 | bytes[0]; 17877 }, 17878 getInt32: function getInt32(byteOffset /* , littleEndian */ 17879 ) { 17880 return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined)); 17881 }, 17882 getUint32: function getUint32(byteOffset /* , littleEndian */ 17883 ) { 17884 return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined)) >>> 0; 17885 }, 17886 getFloat32: function getFloat32(byteOffset /* , littleEndian */ 17887 ) { 17888 return unpackIEEE754(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined), 23); 17889 }, 17890 getFloat64: function getFloat64(byteOffset /* , littleEndian */ 17891 ) { 17892 return unpackIEEE754(get(this, 8, byteOffset, arguments.length > 1 ? arguments[1] : undefined), 52); 17893 }, 17894 setInt8: function setInt8(byteOffset, value) { 17895 set(this, 1, byteOffset, packInt8, value); 17896 }, 17897 setUint8: function setUint8(byteOffset, value) { 17898 set(this, 1, byteOffset, packInt8, value); 17899 }, 17900 setInt16: function setInt16(byteOffset, value /* , littleEndian */ 17901 ) { 17902 set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : undefined); 17903 }, 17904 setUint16: function setUint16(byteOffset, value /* , littleEndian */ 17905 ) { 17906 set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : undefined); 17907 }, 17908 setInt32: function setInt32(byteOffset, value /* , littleEndian */ 17909 ) { 17910 set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : undefined); 17911 }, 17912 setUint32: function setUint32(byteOffset, value /* , littleEndian */ 17913 ) { 17914 set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : undefined); 17915 }, 17916 setFloat32: function setFloat32(byteOffset, value /* , littleEndian */ 17917 ) { 17918 set(this, 4, byteOffset, packFloat32, value, arguments.length > 2 ? arguments[2] : undefined); 17919 }, 17920 setFloat64: function setFloat64(byteOffset, value /* , littleEndian */ 17921 ) { 17922 set(this, 8, byteOffset, packFloat64, value, arguments.length > 2 ? arguments[2] : undefined); 17923 } 17924 }); 17925 } else { 17926 if (!fails(function () { 17927 NativeArrayBuffer(1); 17928 }) || !fails(function () { 17929 new NativeArrayBuffer( - 1); // eslint-disable-line no-new 17930 }) || fails(function () { 17931 new NativeArrayBuffer(); // eslint-disable-line no-new 17932 new NativeArrayBuffer(1.5); // eslint-disable-line no-new 17933 new NativeArrayBuffer(NaN); // eslint-disable-line no-new 17934 return NativeArrayBuffer.name != ARRAY_BUFFER; 17935 })) { 17936 $ArrayBuffer = function ArrayBuffer(length) { 17937 anInstance(this, $ArrayBuffer); 17938 return new NativeArrayBuffer(toIndex(length)); 17939 }; 17940 var ArrayBufferPrototype = $ArrayBuffer[PROTOTYPE] = NativeArrayBuffer[PROTOTYPE]; 17941 for (var keys = getOwnPropertyNames(NativeArrayBuffer), j = 0, key; keys.length > j; ) { 17942 if (!((key = keys[j++]) in $ArrayBuffer)) { 17943 createNonEnumerableProperty($ArrayBuffer, key, NativeArrayBuffer[key]); 17944 } 17945 } 17946 ArrayBufferPrototype.constructor = $ArrayBuffer; 17947 } // WebKit bug - the same parent prototype for typed arrays and data view 17948 17949 if (setPrototypeOf && getPrototypeOf($DataViewPrototype) !== ObjectPrototype) { 17950 setPrototypeOf($DataViewPrototype, ObjectPrototype); 17951 } // iOS Safari 7.x bug 17952 17953 var testView = new $DataView(new $ArrayBuffer(2)); 17954 var nativeSetInt8 = $DataViewPrototype.setInt8; 17955 testView.setInt8(0, 2147483648); 17956 testView.setInt8(1, 2147483649); 17957 if (testView.getInt8(0) || !testView.getInt8(1)) redefineAll($DataViewPrototype, { 17958 setInt8: function setInt8(byteOffset, value) { 17959 nativeSetInt8.call(this, byteOffset, value << 24 >> 24); 17960 }, 17961 setUint8: function setUint8(byteOffset, value) { 17962 nativeSetInt8.call(this, byteOffset, value << 24 >> 24); 17963 } 17964 }, { 17965 unsafe: true 17966 }); 17967 } 17968 setToStringTag($ArrayBuffer, ARRAY_BUFFER); 17969 setToStringTag($DataView, DATA_VIEW); 17970 module.exports = { 17971 ArrayBuffer: $ArrayBuffer, 17972 DataView: $DataView 17973 }; 17974 }, 17975 { 17976 '../internals/an-instance': 27, 17977 '../internals/array-buffer-native': 29, 17978 '../internals/array-fill': 33, 17979 '../internals/create-non-enumerable-property': 56, 17980 '../internals/descriptors': 61, 17981 '../internals/fails': 69, 17982 '../internals/global': 77, 17983 '../internals/ieee754': 83, 17984 '../internals/internal-state': 88, 17985 '../internals/object-define-property': 110, 17986 '../internals/object-get-own-property-names': 113, 17987 '../internals/object-get-prototype-of': 115, 17988 '../internals/object-set-prototype-of': 119, 17989 '../internals/redefine-all': 125, 17990 '../internals/set-to-string-tag': 135, 17991 '../internals/to-index': 149, 17992 '../internals/to-integer': 151, 17993 '../internals/to-length': 152 17994 } 17995 ], 17996 32: [ 17997 function (_dereq_, module, exports) { 17998 'use strict'; 17999 var toObject = _dereq_('../internals/to-object'); 18000 var toAbsoluteIndex = _dereq_('../internals/to-absolute-index'); 18001 var toLength = _dereq_('../internals/to-length'); 18002 var min = Math.min; // `Array.prototype.copyWithin` method implementation 18003 // https://tc39.github.io/ecma262/#sec-array.prototype.copywithin 18004 module.exports = [ 18005 ].copyWithin || function copyWithin(target /* = 0 */ 18006 , start /* = 0, end = @length */ 18007 ) { 18008 var O = toObject(this); 18009 var len = toLength(O.length); 18010 var to = toAbsoluteIndex(target, len); 18011 var from = toAbsoluteIndex(start, len); 18012 var end = arguments.length > 2 ? arguments[2] : undefined; 18013 var count = min((end === undefined ? len : toAbsoluteIndex(end, len)) - from, len - to); 18014 var inc = 1; 18015 if (from < to && to < from + count) { 18016 inc = - 1; 18017 from += count - 1; 18018 to += count - 1; 18019 } 18020 while (count-- > 0) { 18021 if (from in O) O[to] = O[from]; 18022 else delete O[to]; 18023 to += inc; 18024 from += inc; 18025 } 18026 return O; 18027 }; 18028 }, 18029 { 18030 '../internals/to-absolute-index': 148, 18031 '../internals/to-length': 152, 18032 '../internals/to-object': 153 18033 } 18034 ], 18035 33: [ 18036 function (_dereq_, module, exports) { 18037 'use strict'; 18038 var toObject = _dereq_('../internals/to-object'); 18039 var toAbsoluteIndex = _dereq_('../internals/to-absolute-index'); 18040 var toLength = _dereq_('../internals/to-length'); // `Array.prototype.fill` method implementation 18041 // https://tc39.github.io/ecma262/#sec-array.prototype.fill 18042 module.exports = function fill(value /* , start = 0, end = @length */ 18043 ) { 18044 var O = toObject(this); 18045 var length = toLength(O.length); 18046 var argumentsLength = arguments.length; 18047 var index = toAbsoluteIndex(argumentsLength > 1 ? arguments[1] : undefined, length); 18048 var end = argumentsLength > 2 ? arguments[2] : undefined; 18049 var endPos = end === undefined ? length : toAbsoluteIndex(end, length); 18050 while (endPos > index) O[index++] = value; 18051 return O; 18052 }; 18053 }, 18054 { 18055 '../internals/to-absolute-index': 148, 18056 '../internals/to-length': 152, 18057 '../internals/to-object': 153 18058 } 18059 ], 18060 34: [ 18061 function (_dereq_, module, exports) { 18062 'use strict'; 18063 var $forEach = _dereq_('../internals/array-iteration').forEach; 18064 var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict'); 18065 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 18066 var STRICT_METHOD = arrayMethodIsStrict('forEach'); 18067 var USES_TO_LENGTH = arrayMethodUsesToLength('forEach'); // `Array.prototype.forEach` method implementation 18068 // https://tc39.github.io/ecma262/#sec-array.prototype.foreach 18069 module.exports = !STRICT_METHOD || !USES_TO_LENGTH ? function forEach(callbackfn /* , thisArg */ 18070 ) { 18071 return $forEach(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); 18072 } 18073 : [ 18074 ].forEach; 18075 }, 18076 { 18077 '../internals/array-iteration': 37, 18078 '../internals/array-method-is-strict': 40, 18079 '../internals/array-method-uses-to-length': 41 18080 } 18081 ], 18082 35: [ 18083 function (_dereq_, module, exports) { 18084 'use strict'; 18085 var bind = _dereq_('../internals/function-bind-context'); 18086 var toObject = _dereq_('../internals/to-object'); 18087 var callWithSafeIterationClosing = _dereq_('../internals/call-with-safe-iteration-closing'); 18088 var isArrayIteratorMethod = _dereq_('../internals/is-array-iterator-method'); 18089 var toLength = _dereq_('../internals/to-length'); 18090 var createProperty = _dereq_('../internals/create-property'); 18091 var getIteratorMethod = _dereq_('../internals/get-iterator-method'); // `Array.from` method implementation 18092 // https://tc39.github.io/ecma262/#sec-array.from 18093 module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undefined */ 18094 ) { 18095 var O = toObject(arrayLike); 18096 var C = typeof this == 'function' ? this : Array; 18097 var argumentsLength = arguments.length; 18098 var mapfn = argumentsLength > 1 ? arguments[1] : undefined; 18099 var mapping = mapfn !== undefined; 18100 var iteratorMethod = getIteratorMethod(O); 18101 var index = 0; 18102 var length, 18103 result, 18104 step, 18105 iterator, 18106 next, 18107 value; 18108 if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2); // if the target is not iterable or it's an array with the default iterator - use a simple case 18109 if (iteratorMethod != undefined && !(C == Array && isArrayIteratorMethod(iteratorMethod))) { 18110 iterator = iteratorMethod.call(O); 18111 next = iterator.next; 18112 result = new C(); 18113 for (; !(step = next.call(iterator)).done; index++) { 18114 value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [ 18115 step.value, 18116 index 18117 ], true) : step.value; 18118 createProperty(result, index, value); 18119 } 18120 } else { 18121 length = toLength(O.length); 18122 result = new C(length); 18123 for (; length > index; index++) { 18124 value = mapping ? mapfn(O[index], index) : O[index]; 18125 createProperty(result, index, value); 18126 } 18127 } 18128 result.length = index; 18129 return result; 18130 }; 18131 }, 18132 { 18133 '../internals/call-with-safe-iteration-closing': 44, 18134 '../internals/create-property': 58, 18135 '../internals/function-bind-context': 72, 18136 '../internals/get-iterator-method': 75, 18137 '../internals/is-array-iterator-method': 89, 18138 '../internals/to-length': 152, 18139 '../internals/to-object': 153 18140 } 18141 ], 18142 36: [
vendor: 5,203 bytes, lines 18143-18260
18143 function (_dereq_, module, exports) { 18144 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 18145 var toLength = _dereq_('../internals/to-length'); 18146 var toAbsoluteIndex = _dereq_('../internals/to-absolute-index'); // `Array.prototype.{ indexOf, includes }` methods implementation 18147 var createMethod = function (IS_INCLUDES) { 18148 return function ($this, el, fromIndex) { 18149 var O = toIndexedObject($this); 18150 var length = toLength(O.length); 18151 var index = toAbsoluteIndex(fromIndex, length); 18152 var value; // Array#includes uses SameValueZero equality algorithm 18153 // eslint-disable-next-line no-self-compare 18154 if (IS_INCLUDES && el != el) while (length > index) { 18155 value = O[index++]; // eslint-disable-next-line no-self-compare 18156 if (value != value) return true; // Array#indexOf ignores holes, Array#includes - not 18157 } else for (; length > index; index++) { 18158 if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; 18159 } 18160 return !IS_INCLUDES && - 1; 18161 }; 18162 }; 18163 module.exports = { 18164 // `Array.prototype.includes` method 18165 // https://tc39.github.io/ecma262/#sec-array.prototype.includes 18166 includes: createMethod(true), 18167 // `Array.prototype.indexOf` method 18168 // https://tc39.github.io/ecma262/#sec-array.prototype.indexof 18169 indexOf: createMethod(false) 18170 }; 18171 }, 18172 { 18173 '../internals/to-absolute-index': 148, 18174 '../internals/to-indexed-object': 150, 18175 '../internals/to-length': 152 18176 } 18177 ], 18178 37: [ 18179 function (_dereq_, module, exports) { 18180 var bind = _dereq_('../internals/function-bind-context'); 18181 var IndexedObject = _dereq_('../internals/indexed-object'); 18182 var toObject = _dereq_('../internals/to-object'); 18183 var toLength = _dereq_('../internals/to-length'); 18184 var arraySpeciesCreate = _dereq_('../internals/array-species-create'); 18185 var push = [ 18186 ].push; // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation 18187 var createMethod = function (TYPE) { 18188 var IS_MAP = TYPE == 1; 18189 var IS_FILTER = TYPE == 2; 18190 var IS_SOME = TYPE == 3; 18191 var IS_EVERY = TYPE == 4; 18192 var IS_FIND_INDEX = TYPE == 6; 18193 var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; 18194 return function ($this, callbackfn, that, specificCreate) { 18195 var O = toObject($this); 18196 var self = IndexedObject(O); 18197 var boundFunction = bind(callbackfn, that, 3); 18198 var length = toLength(self.length); 18199 var index = 0; 18200 var create = specificCreate || arraySpeciesCreate; 18201 var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined; 18202 var value, 18203 result; 18204 for (; length > index; index++) if (NO_HOLES || index in self) { 18205 value = self[index]; 18206 result = boundFunction(value, index, O); 18207 if (TYPE) { 18208 if (IS_MAP) target[index] = result; // map 18209 else if (result) switch (TYPE) { 18210 case 3: 18211 return true; 18212 // some 18213 case 5: 18214 return value; 18215 // find 18216 case 6: 18217 return index; 18218 // findIndex 18219 case 2: 18220 push.call(target, value); 18221 // filter 18222 } else if (IS_EVERY) return false; // every 18223 } 18224 } 18225 return IS_FIND_INDEX ? - 1 : IS_SOME || IS_EVERY ? IS_EVERY : target; 18226 }; 18227 }; 18228 module.exports = { 18229 // `Array.prototype.forEach` method 18230 // https://tc39.github.io/ecma262/#sec-array.prototype.foreach 18231 forEach: createMethod(0), 18232 // `Array.prototype.map` method 18233 // https://tc39.github.io/ecma262/#sec-array.prototype.map 18234 map: createMethod(1), 18235 // `Array.prototype.filter` method 18236 // https://tc39.github.io/ecma262/#sec-array.prototype.filter 18237 filter: createMethod(2), 18238 // `Array.prototype.some` method 18239 // https://tc39.github.io/ecma262/#sec-array.prototype.some 18240 some: createMethod(3), 18241 // `Array.prototype.every` method 18242 // https://tc39.github.io/ecma262/#sec-array.prototype.every 18243 every: createMethod(4), 18244 // `Array.prototype.find` method 18245 // https://tc39.github.io/ecma262/#sec-array.prototype.find 18246 find: createMethod(5), 18247 // `Array.prototype.findIndex` method 18248 // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex 18249 findIndex: createMethod(6) 18250 }; 18251 }, 18252 { 18253 '../internals/array-species-create': 43, 18254 '../internals/function-bind-context': 72, 18255 '../internals/indexed-object': 84, 18256 '../internals/to-length': 152, 18257 '../internals/to-object': 153 18258 } 18259 ], 18260 38: [
18261 function (_dereq_, module, exports) { 18262 'use strict'; 18263 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 18264 var toInteger = _dereq_('../internals/to-integer'); 18265 var toLength = _dereq_('../internals/to-length'); 18266 var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict'); 18267 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 18268 var min = Math.min; 18269 var nativeLastIndexOf = [ 18270 ].lastIndexOf; 18271 var NEGATIVE_ZERO = !!nativeLastIndexOf && 1 / [ 18272 1 18273 ].lastIndexOf(1, - 0) < 0; 18274 var STRICT_METHOD = arrayMethodIsStrict('lastIndexOf'); // For preventing possible almost infinite loop in non-standard implementations, test the forward version of the method 18275 var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { 18276 ACCESSORS: true, 18277 1: 0 18278 }); 18279 var FORCED = NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH; // `Array.prototype.lastIndexOf` method implementation 18280 // https://tc39.github.io/ecma262/#sec-array.prototype.lastindexof 18281 module.exports = FORCED ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */ 18282 ) { 18283 // convert -0 to +0 18284 if (NEGATIVE_ZERO) return nativeLastIndexOf.apply(this, arguments) || 0; 18285 var O = toIndexedObject(this); 18286 var length = toLength(O.length); 18287 var index = length - 1; 18288 if (arguments.length > 1) index = min(index, toInteger(arguments[1])); 18289 if (index < 0) index = length + index; 18290 for (; index >= 0; index--) if (index in O && O[index] === searchElement) return index || 0; 18291 return - 1; 18292 } 18293 : nativeLastIndexOf; 18294 }, 18295 { 18296 '../internals/array-method-is-strict': 40, 18297 '../internals/array-method-uses-to-length': 41, 18298 '../internals/to-indexed-object': 150, 18299 '../internals/to-integer': 151, 18300 '../internals/to-length': 152 18301 } 18302 ], 18303 39: [ 18304 function (_dereq_, module, exports) { 18305 var fails = _dereq_('../internals/fails'); 18306 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 18307 var V8_VERSION = _dereq_('../internals/engine-v8-version'); 18308 var SPECIES = wellKnownSymbol('species'); 18309 module.exports = function (METHOD_NAME) { 18310 // We can't use this feature detection in V8 since it causes 18311 // deoptimization and serious performance degradation 18312 // https://github.com/zloirock/core-js/issues/677 18313 return V8_VERSION >= 51 || !fails(function () { 18314 var array = [ 18315 ]; 18316 var constructor = array.constructor = { 18317 }; 18318 constructor[SPECIES] = function () { 18319 return { 18320 foo: 1 18321 }; 18322 }; 18323 return array[METHOD_NAME](Boolean).foo !== 1; 18324 }); 18325 }; 18326 }, 18327 { 18328 '../internals/engine-v8-version': 66, 18329 '../internals/fails': 69, 18330 '../internals/well-known-symbol': 164 18331 } 18332 ], 18333 40: [ 18334 function (_dereq_, module, exports) { 18335 'use strict'; 18336 var fails = _dereq_('../internals/fails'); 18337 module.exports = function (METHOD_NAME, argument) { 18338 var method = [ 18339 ][METHOD_NAME]; 18340 return !!method && fails(function () { 18341 // eslint-disable-next-line no-useless-call,no-throw-literal 18342 method.call(null, argument || function () { 18343 throw 1; 18344 }, 1); 18345 }); 18346 }; 18347 }, 18348 { 18349 '../internals/fails': 69 18350 } 18351 ], 18352 41: [ 18353 function (_dereq_, module, exports) { 18354 var DESCRIPTORS = _dereq_('../internals/descriptors'); 18355 var fails = _dereq_('../internals/fails'); 18356 var has = _dereq_('../internals/has'); 18357 var defineProperty = Object.defineProperty; 18358 var cache = { 18359 }; 18360 var thrower = function (it) { 18361 throw it; 18362 }; 18363 module.exports = function (METHOD_NAME, options) { 18364 if (has(cache, METHOD_NAME)) return cache[METHOD_NAME]; 18365 if (!options) options = { 18366 }; 18367 var method = [ 18368 ][METHOD_NAME]; 18369 var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS
vendor: 4,309 bytes, lines 18369-18482
18369: false; 18370 var argument0 = has(options, 0) ? options[0] : thrower; 18371 var argument1 = has(options, 1) ? options[1] : undefined; 18372 return cache[METHOD_NAME] = !!method && !fails(function () { 18373 if (ACCESSORS && !DESCRIPTORS) return true; 18374 var O = { 18375 length: - 1 18376 }; 18377 if (ACCESSORS) defineProperty(O, 1, { 18378 enumerable: true, 18379 get: thrower 18380 }); 18381 else O[1] = 1; 18382 method.call(O, argument0, argument1); 18383 }); 18384 }; 18385 }, 18386 { 18387 '../internals/descriptors': 61, 18388 '../internals/fails': 69, 18389 '../internals/has': 78 18390 } 18391 ], 18392 42: [ 18393 function (_dereq_, module, exports) { 18394 var aFunction = _dereq_('../internals/a-function'); 18395 var toObject = _dereq_('../internals/to-object'); 18396 var IndexedObject = _dereq_('../internals/indexed-object'); 18397 var toLength = _dereq_('../internals/to-length'); // `Array.prototype.{ reduce, reduceRight }` methods implementation 18398 var createMethod = function (IS_RIGHT) { 18399 return function (that, callbackfn, argumentsLength, memo) { 18400 aFunction(callbackfn); 18401 var O = toObject(that); 18402 var self = IndexedObject(O); 18403 var length = toLength(O.length); 18404 var index = IS_RIGHT ? length - 1 : 0; 18405 var i = IS_RIGHT ? - 1 : 1; 18406 if (argumentsLength < 2) while (true) { 18407 if (index in self) { 18408 memo = self[index]; 18409 index += i; 18410 break; 18411 } 18412 index += i; 18413 if (IS_RIGHT ? index < 0 : length <= index) { 18414 throw TypeError('Reduce of empty array with no initial value'); 18415 } 18416 } 18417 for (; IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) { 18418 memo = callbackfn(memo, self[index], index, O); 18419 } 18420 return memo; 18421 }; 18422 }; 18423 module.exports = { 18424 // `Array.prototype.reduce` method 18425 // https://tc39.github.io/ecma262/#sec-array.prototype.reduce 18426 left: createMethod(false), 18427 // `Array.prototype.reduceRight` method 18428 // https://tc39.github.io/ecma262/#sec-array.prototype.reduceright 18429 right: createMethod(true) 18430 }; 18431 }, 18432 { 18433 '../internals/a-function': 23, 18434 '../internals/indexed-object': 84, 18435 '../internals/to-length': 152, 18436 '../internals/to-object': 153 18437 } 18438 ], 18439 43: [ 18440 function (_dereq_, module, exports) { 18441 var isObject = _dereq_('../internals/is-object'); 18442 var isArray = _dereq_('../internals/is-array'); 18443 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 18444 var SPECIES = wellKnownSymbol('species'); // `ArraySpeciesCreate` abstract operation 18445 // https://tc39.github.io/ecma262/#sec-arrayspeciescreate 18446 module.exports = function (originalArray, length) { 18447 var C; 18448 if (isArray(originalArray)) { 18449 C = originalArray.constructor; // cross-realm fallback 18450 if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined; 18451 else if (isObject(C)) { 18452 C = C[SPECIES]; 18453 if (C === null) C = undefined; 18454 } 18455 } 18456 return new (C === undefined ? Array : C) (length === 0 ? 0 : length); 18457 }; 18458 }, 18459 { 18460 '../internals/is-array': 90, 18461 '../internals/is-object': 92, 18462 '../internals/well-known-symbol': 164 18463 } 18464 ], 18465 44: [ 18466 function (_dereq_, module, exports) { 18467 var anObject = _dereq_('../internals/an-object'); // call something on iterator step with safe closing on error 18468 module.exports = function (iterator, fn, value, ENTRIES) { 18469 try { 18470 return ENTRIES ? fn(anObject(value) [0], value[1]) : fn(value); // 7.4.6 IteratorClose(iterator, completion) 18471 } catch (error) { 18472 var returnMethod = iterator['return']; 18473 if (returnMethod !== undefined) anObject(returnMethod.call(iterator)); 18474 throw error; 18475 } 18476 }; 18477 }, 18478 { 18479 '../internals/an-object': 28 18480 } 18481 ], 18482 45: [
vendor: 12,004 bytes, lines 18483-18782
18483 function (_dereq_, module, exports) { 18484 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 18485 var ITERATOR = wellKnownSymbol('iterator'); 18486 var SAFE_CLOSING = false; 18487 try { 18488 var called = 0; 18489 var iteratorWithReturn = { 18490 next: function () { 18491 return { 18492 done: !!called++ 18493 }; 18494 }, 18495 'return': function () { 18496 SAFE_CLOSING = true; 18497 } 18498 }; 18499 iteratorWithReturn[ITERATOR] = function () { 18500 return this; 18501 }; // eslint-disable-next-line no-throw-literal 18502 Array.from(iteratorWithReturn, function () { 18503 throw 2; 18504 }); 18505 } catch (error) { 18506 /* empty */ 18507 } 18508 module.exports = function (exec, SKIP_CLOSING) { 18509 if (!SKIP_CLOSING && !SAFE_CLOSING) return false; 18510 var ITERATION_SUPPORT = false; 18511 try { 18512 var object = { 18513 }; 18514 object[ITERATOR] = function () { 18515 return { 18516 next: function () { 18517 return { 18518 done: ITERATION_SUPPORT = true 18519 }; 18520 } 18521 }; 18522 }; 18523 exec(object); 18524 } catch (error) { 18525 /* empty */ 18526 } 18527 return ITERATION_SUPPORT; 18528 }; 18529 }, 18530 { 18531 '../internals/well-known-symbol': 164 18532 } 18533 ], 18534 46: [ 18535 function (_dereq_, module, exports) { 18536 var toString = { 18537 }.toString; 18538 module.exports = function (it) { 18539 return toString.call(it).slice(8, - 1); 18540 }; 18541 }, 18542 { 18543 } 18544 ], 18545 47: [ 18546 function (_dereq_, module, exports) { 18547 var TO_STRING_TAG_SUPPORT = _dereq_('../internals/to-string-tag-support'); 18548 var classofRaw = _dereq_('../internals/classof-raw'); 18549 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 18550 var TO_STRING_TAG = wellKnownSymbol('toStringTag'); // ES3 wrong here 18551 var CORRECT_ARGUMENTS = classofRaw(function () { 18552 return arguments; 18553 }()) == 'Arguments'; // fallback for IE11 Script Access Denied error 18554 var tryGet = function (it, key) { 18555 try { 18556 return it[key]; 18557 } catch (error) { 18558 /* empty */ 18559 } 18560 }; // getting tag from ES6+ `Object.prototype.toString` 18561 module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) { 18562 var O, 18563 tag, 18564 result; 18565 return it === undefined ? 'Undefined' : it === null ? 'Null' // @@toStringTag case 18566 : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG)) == 'string' ? tag // builtinTag case 18567 : CORRECT_ARGUMENTS ? classofRaw(O) // ES3 arguments fallback 18568 : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result; 18569 }; 18570 }, 18571 { 18572 '../internals/classof-raw': 46, 18573 '../internals/to-string-tag-support': 157, 18574 '../internals/well-known-symbol': 164 18575 } 18576 ], 18577 48: [ 18578 function (_dereq_, module, exports) { 18579 'use strict'; 18580 var defineProperty = _dereq_('../internals/object-define-property').f; 18581 var create = _dereq_('../internals/object-create'); 18582 var redefineAll = _dereq_('../internals/redefine-all'); 18583 var bind = _dereq_('../internals/function-bind-context'); 18584 var anInstance = _dereq_('../internals/an-instance'); 18585 var iterate = _dereq_('../internals/iterate'); 18586 var defineIterator = _dereq_('../internals/define-iterator'); 18587 var setSpecies = _dereq_('../internals/set-species'); 18588 var DESCRIPTORS = _dereq_('../internals/descriptors'); 18589 var fastKey = _dereq_('../internals/internal-metadata').fastKey; 18590 var InternalStateModule = _dereq_('../internals/internal-state'); 18591 var setInternalState = InternalStateModule.set; 18592 var internalStateGetterFor = InternalStateModule.getterFor; 18593 module.exports = { 18594 getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) { 18595 var C = wrapper(function (that, iterable) { 18596 anInstance(that, C, CONSTRUCTOR_NAME); 18597 setInternalState(that, { 18598 type: CONSTRUCTOR_NAME, 18599 index: create(null), 18600 first: undefined, 18601 last: undefined, 18602 size: 0 18603 }); 18604 if (!DESCRIPTORS) that.size = 0; 18605 if (iterable != undefined) iterate(iterable, that[ADDER], that, IS_MAP); 18606 }); 18607 var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME); 18608 var define = function (that, key, value) { 18609 var state = getInternalState(that); 18610 var entry = getEntry(that, key); 18611 var previous, 18612 index; // change existing entry 18613 if (entry) { 18614 entry.value = value; // create new entry 18615 } else { 18616 state.last = entry = { 18617 index: index = fastKey(key, true), 18618 key: key, 18619 value: value, 18620 previous: previous = state.last, 18621 next: undefined, 18622 removed: false 18623 }; 18624 if (!state.first) state.first = entry; 18625 if (previous) previous.next = entry; 18626 if (DESCRIPTORS) state.size++; 18627 else that.size++; // add to index 18628 if (index !== 'F') state.index[index] = entry; 18629 } 18630 return that; 18631 }; 18632 var getEntry = function (that, key) { 18633 var state = getInternalState(that); // fast case 18634 var index = fastKey(key); 18635 var entry; 18636 if (index !== 'F') return state.index[index]; // frozen object case 18637 for (entry = state.first; entry; entry = entry.next) { 18638 if (entry.key == key) return entry; 18639 } 18640 }; 18641 redefineAll(C.prototype, { 18642 // 23.1.3.1 Map.prototype.clear() 18643 // 23.2.3.2 Set.prototype.clear() 18644 clear: function clear() { 18645 var that = this; 18646 var state = getInternalState(that); 18647 var data = state.index; 18648 var entry = state.first; 18649 while (entry) { 18650 entry.removed = true; 18651 if (entry.previous) entry.previous = entry.previous.next = undefined; 18652 delete data[entry.index]; 18653 entry = entry.next; 18654 } 18655 state.first = state.last = undefined; 18656 if (DESCRIPTORS) state.size = 0; 18657 else that.size = 0; 18658 }, 18659 // 23.1.3.3 Map.prototype.delete(key) 18660 // 23.2.3.4 Set.prototype.delete(value) 18661 'delete': function (key) { 18662 var that = this; 18663 var state = getInternalState(that); 18664 var entry = getEntry(that, key); 18665 if (entry) { 18666 var next = entry.next; 18667 var prev = entry.previous; 18668 delete state.index[entry.index]; 18669 entry.removed = true; 18670 if (prev) prev.next = next; 18671 if (next) next.previous = prev; 18672 if (state.first == entry) state.first = next; 18673 if (state.last == entry) state.last = prev; 18674 if (DESCRIPTORS) state.size--; 18675 else that.size--; 18676 } 18677 return !!entry; 18678 }, 18679 // 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined) 18680 // 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined) 18681 forEach: function forEach(callbackfn /* , that = undefined */ 18682 ) { 18683 var state = getInternalState(this); 18684 var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3); 18685 var entry; 18686 while (entry = entry ? entry.next : state.first) { 18687 boundFunction(entry.value, entry.key, this); // revert to the last existing entry 18688 while (entry && entry.removed) entry = entry.previous; 18689 } 18690 }, 18691 // 23.1.3.7 Map.prototype.has(key) 18692 // 23.2.3.7 Set.prototype.has(value) 18693 has: function has(key) { 18694 return !!getEntry(this, key); 18695 } 18696 }); 18697 redefineAll(C.prototype, IS_MAP ? { 18698 // 23.1.3.6 Map.prototype.get(key) 18699 get: function get(key) { 18700 var entry = getEntry(this, key); 18701 return entry && entry.value; 18702 }, 18703 // 23.1.3.9 Map.prototype.set(key, value) 18704 set: function set(key, value) { 18705 return define(this, key === 0 ? 0 : key, value); 18706 } 18707 } 18708 : { 18709 // 23.2.3.1 Set.prototype.add(value) 18710 add: function add(value) { 18711 return define(this, value = value === 0 ? 0 : value, value); 18712 } 18713 }); 18714 if (DESCRIPTORS) defineProperty(C.prototype, 'size', { 18715 get: function () { 18716 return getInternalState(this).size; 18717 } 18718 }); 18719 return C; 18720 }, 18721 setStrong: function (C, CONSTRUCTOR_NAME, IS_MAP) { 18722 var ITERATOR_NAME = CONSTRUCTOR_NAME + ' Iterator'; 18723 var getInternalCollectionState = internalStateGetterFor(CONSTRUCTOR_NAME); 18724 var getInternalIteratorState = internalStateGetterFor(ITERATOR_NAME); // add .keys, .values, .entries, [@@iterator] 18725 // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11 18726 defineIterator(C, CONSTRUCTOR_NAME, function (iterated, kind) { 18727 setInternalState(this, { 18728 type: ITERATOR_NAME, 18729 target: iterated, 18730 state: getInternalCollectionState(iterated), 18731 kind: kind, 18732 last: undefined 18733 }); 18734 }, function () { 18735 var state = getInternalIteratorState(this); 18736 var kind = state.kind; 18737 var entry = state.last; // revert to the last existing entry 18738 while (entry && entry.removed) entry = entry.previous; // get next entry 18739 if (!state.target || !(state.last = entry = entry ? entry.next : state.state.first)) { 18740 // or finish the iteration 18741 state.target = undefined; 18742 return { 18743 value: undefined, 18744 done: true 18745 }; 18746 } // return step by kind 18747 18748 if (kind == 'keys') return { 18749 value: entry.key, 18750 done: false 18751 }; 18752 if (kind == 'values') return { 18753 value: entry.value, 18754 done: false 18755 }; 18756 return { 18757 value: [ 18758 entry.key, 18759 entry.value 18760 ], 18761 done: false 18762 }; 18763 }, IS_MAP ? 'entries' : 'values', !IS_MAP, true); // add [@@species], 23.1.2.2, 23.2.2.2 18764 setSpecies(CONSTRUCTOR_NAME); 18765 } 18766 }; 18767 }, 18768 { 18769 '../internals/an-instance': 27, 18770 '../internals/define-iterator': 59, 18771 '../internals/descriptors': 61, 18772 '../internals/function-bind-context': 72, 18773 '../internals/internal-metadata': 87, 18774 '../internals/internal-state': 88, 18775 '../internals/iterate': 95, 18776 '../internals/object-create': 108, 18777 '../internals/object-define-property': 110, 18778 '../internals/redefine-all': 125, 18779 '../internals/set-species': 134 18780 } 18781 ], 18782 49: [
18783 function (_dereq_, module, exports) { 18784 'use strict'; 18785 var redefineAll = _dereq_('../internals/redefine-all'); 18786 var getWeakData = _dereq_('../internals/internal-metadata').getWeakData; 18787 var anObject = _dereq_('../internals/an-object'); 18788 var isObject = _dereq_('../internals/is-object'); 18789 var anInstance = _dereq_('../internals/an-instance'); 18790 var iterate = _dereq_('../internals/iterate'); 18791 var ArrayIterationModule = _dereq_('../internals/array-iteration'); 18792 var $has = _dereq_('../internals/has'); 18793 var InternalStateModule = _dereq_('../internals/internal-state'); 18794 var setInternalState = InternalStateModule.set; 18795 var internalStateGetterFor = InternalStateModule.getterFor; 18796 var find = ArrayIterationModule.find; 18797 var findIndex = ArrayIterationModule.findIndex; 18798 var id = 0; // fallback for uncaught frozen keys 18799 var uncaughtFrozenStore = function (store) { 18800 return store.frozen || (store.frozen = new UncaughtFrozenStore()); 18801 }; 18802 var UncaughtFrozenStore = function () { 18803 this.entries = [ 18804 ]; 18805 }; 18806 var findUncaughtFrozen = function (store, key) { 18807 return find(store.entries, function (it) { 18808 return it[0] === key; 18809 }); 18810 }; 18811 UncaughtFrozenStore.prototype = { 18812 get: function (key) { 18813 var entry = findUncaughtFrozen(this, key); 18814 if (entry) return entry[1]; 18815 }, 18816 has: function (key) { 18817 return !!findUncaughtFrozen(this, key); 18818 }, 18819 set: function (key, value) { 18820 var entry = findUncaughtFrozen(this, key); 18821 if (entry) entry[1] = value; 18822 else this.entries.push([key, 18823 value]); 18824 }, 18825 'delete': function (key) { 18826 var index = findIndex(this.entries, function (it) { 18827 return it[0] === key; 18828 }); 18829 if (~index) this.entries.splice(index, 1); 18830 return !!~index; 18831 } 18832 }; 18833 module.exports = { 18834 getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) { 18835 var C = wrapper(function (that, iterable) { 18836 anInstance(that, C, CONSTRUCTOR_NAME); 18837 setInternalState(that, { 18838 type: CONSTRUCTOR_NAME, 18839 id: id++, 18840 frozen: undefined 18841 }); 18842 if (iterable != undefined) iterate(iterable, that[ADDER], that, IS_MAP); 18843 }); 18844 var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME); 18845 var define = function (that, key, value) { 18846 var state = getInternalState(that); 18847 var data = getWeakData(anObject(key), true); 18848 if (data === true) uncaughtFrozenStore(state).set(key, value); 18849 else data[state.id] = value; 18850 return that; 18851 }; 18852 redefineAll(C.prototype, { 18853 // 23.3.3.2 WeakMap.prototype.delete(key) 18854 // 23.4.3.3 WeakSet.prototype.delete(value) 18855 'delete': function (key) { 18856 var state = getInternalState(this); 18857 if (!isObject(key)) return false; 18858 var data = getWeakData(key); 18859 if (data === true) return uncaughtFrozenStore(state) ['delete'](key); 18860 return data && $has(data, state.id) && delete data[state.id]; 18861 }, 18862 // 23.3.3.4 WeakMap.prototype.has(key) 18863 // 23.4.3.4 WeakSet.prototype.has(value) 18864 has: function has(key) { 18865 var state = getInternalState(this); 18866 if (!isObject(key)) return false; 18867 var data = getWeakData(key); 18868 if (data === true) return uncaughtFrozenStore(state).has(key); 18869 return data && $has(data, state.id); 18870 } 18871 }); 18872 redefineAll(C.prototype, IS_MAP ? { 18873 // 23.3.3.3 WeakMap.prototype.get(key) 18874 get: function get(key) { 18875 var state = getInternalState(this); 18876 if (isObject(key)) { 18877 var data = getWeakData(key); 18878 if (data === true) return uncaughtFrozenStore(state).get(key); 18879 return data ? data[state.id] : undefined; 18880 } 18881 }, 18882 // 23.3.3.5 WeakMap.prototype.set(key, value) 18883 set: function set(key, value) { 18884 return define(this, key, value); 18885 } 18886 } 18887 : { 18888 // 23.4.3.1 WeakSet.prototype.add(value) 18889 add: function add(value) { 18890 return define(this, value, true); 18891 } 18892 }); 18893 return C; 18894 } 18895 }; 18896 }, 18897 { 18898 '../internals/an-instance': 27, 18899 '../internals/an-object': 28, 18900 '../internals/array-iteration': 37, 18901 '../internals/has': 78, 18902 '../internals/internal-metadata': 87, 18903 '../internals/internal-state': 88, 18904 '../internals/is-object': 92, 18905 '../internals/iterate': 95, 18906 '../internals/redefine-all': 125 18907 } 18908 ], 18909 50: [
vendor: 5,616 bytes, lines 18910-19021
18910 function (_dereq_, module, exports) { 18911 'use strict'; 18912 var $ = _dereq_('../internals/export'); 18913 var global = _dereq_('../internals/global'); 18914 var isForced = _dereq_('../internals/is-forced'); 18915 var redefine = _dereq_('../internals/redefine'); 18916 var InternalMetadataModule = _dereq_('../internals/internal-metadata'); 18917 var iterate = _dereq_('../internals/iterate'); 18918 var anInstance = _dereq_('../internals/an-instance'); 18919 var isObject = _dereq_('../internals/is-object'); 18920 var fails = _dereq_('../internals/fails'); 18921 var checkCorrectnessOfIteration = _dereq_('../internals/check-correctness-of-iteration'); 18922 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 18923 var inheritIfRequired = _dereq_('../internals/inherit-if-required'); 18924 module.exports = function (CONSTRUCTOR_NAME, wrapper, common) { 18925 var IS_MAP = CONSTRUCTOR_NAME.indexOf('Map') !== - 1; 18926 var IS_WEAK = CONSTRUCTOR_NAME.indexOf('Weak') !== - 1; 18927 var ADDER = IS_MAP ? 'set' : 'add'; 18928 var NativeConstructor = global[CONSTRUCTOR_NAME]; 18929 var NativePrototype = NativeConstructor && NativeConstructor.prototype; 18930 var Constructor = NativeConstructor; 18931 var exported = { 18932 }; 18933 var fixMethod = function (KEY) { 18934 var nativeMethod = NativePrototype[KEY]; 18935 redefine(NativePrototype, KEY, KEY == 'add' ? function add(value) { 18936 nativeMethod.call(this, value === 0 ? 0 : value); 18937 return this; 18938 } 18939 : KEY == 'delete' ? function (key) { 18940 return IS_WEAK && !isObject(key) ? false : nativeMethod.call(this, key === 0 ? 0 : key); 18941 } 18942 : KEY == 'get' ? function get(key) { 18943 return IS_WEAK && !isObject(key) ? undefined : nativeMethod.call(this, key === 0 ? 0 : key); 18944 } 18945 : KEY == 'has' ? function has(key) { 18946 return IS_WEAK && !isObject(key) ? false : nativeMethod.call(this, key === 0 ? 0 : key); 18947 } 18948 : function set(key, value) { 18949 nativeMethod.call(this, key === 0 ? 0 : key, value); 18950 return this; 18951 }); 18952 }; // eslint-disable-next-line max-len 18953 if (isForced(CONSTRUCTOR_NAME, typeof NativeConstructor != 'function' || !(IS_WEAK || NativePrototype.forEach && !fails(function () { 18954 new NativeConstructor().entries().next(); 18955 })))) { 18956 // create collection constructor 18957 Constructor = common.getConstructor(wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER); 18958 InternalMetadataModule.REQUIRED = true; 18959 } else if (isForced(CONSTRUCTOR_NAME, true)) { 18960 var instance = new Constructor(); // early implementations not supports chaining 18961 var HASNT_CHAINING = instance[ADDER](IS_WEAK ? { 18962 } 18963 : - 0, 1) != instance; // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false 18964 var THROWS_ON_PRIMITIVES = fails(function () { 18965 instance.has(1); 18966 }); // most early implementations doesn't supports iterables, most modern - not close it correctly 18967 // eslint-disable-next-line no-new 18968 var ACCEPT_ITERABLES = checkCorrectnessOfIteration(function (iterable) { 18969 new NativeConstructor(iterable); 18970 }); // for early implementations -0 and +0 not the same 18971 var BUGGY_ZERO = !IS_WEAK && fails(function () { 18972 // V8 ~ Chromium 42- fails only with 5+ elements 18973 var $instance = new NativeConstructor(); 18974 var index = 5; 18975 while (index--) $instance[ADDER](index, index); 18976 return !$instance.has( - 0); 18977 }); 18978 if (!ACCEPT_ITERABLES) { 18979 Constructor = wrapper(function (dummy, iterable) { 18980 anInstance(dummy, Constructor, CONSTRUCTOR_NAME); 18981 var that = inheritIfRequired(new NativeConstructor(), dummy, Constructor); 18982 if (iterable != undefined) iterate(iterable, that[ADDER], that, IS_MAP); 18983 return that; 18984 }); 18985 Constructor.prototype = NativePrototype; 18986 NativePrototype.constructor = Constructor; 18987 } 18988 if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) { 18989 fixMethod('delete'); 18990 fixMethod('has'); 18991 IS_MAP && fixMethod('get'); 18992 } 18993 if (BUGGY_ZERO || HASNT_CHAINING) fixMethod(ADDER); // weak collections should not contains .clear method 18994 if (IS_WEAK && NativePrototype.clear) delete NativePrototype.clear; 18995 } 18996 exported[CONSTRUCTOR_NAME] = Constructor; 18997 $({ 18998 global: true, 18999 forced: Constructor != NativeConstructor 19000 }, exported); 19001 setToStringTag(Constructor, CONSTRUCTOR_NAME); 19002 if (!IS_WEAK) common.setStrong(Constructor, CONSTRUCTOR_NAME, IS_MAP); 19003 return Constructor; 19004 }; 19005 }, 19006 { 19007 '../internals/an-instance': 27, 19008 '../internals/check-correctness-of-iteration': 45, 19009 '../internals/export': 68, 19010 '../internals/fails': 69, 19011 '../internals/global': 77, 19012 '../internals/inherit-if-required': 85, 19013 '../internals/internal-metadata': 87, 19014 '../internals/is-forced': 91, 19015 '../internals/is-object': 92, 19016 '../internals/iterate': 95, 19017 '../internals/redefine': 126, 19018 '../internals/set-to-string-tag': 135 19019 } 19020 ], 19021 51: [
vendor: 4,658 bytes, lines 19022-19146
19022 function (_dereq_, module, exports) { 19023 var has = _dereq_('../internals/has'); 19024 var ownKeys = _dereq_('../internals/own-keys'); 19025 var getOwnPropertyDescriptorModule = _dereq_('../internals/object-get-own-property-descriptor'); 19026 var definePropertyModule = _dereq_('../internals/object-define-property'); 19027 module.exports = function (target, source) { 19028 var keys = ownKeys(source); 19029 var defineProperty = definePropertyModule.f; 19030 var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; 19031 for (var i = 0; i < keys.length; i++) { 19032 var key = keys[i]; 19033 if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key)); 19034 } 19035 }; 19036 }, 19037 { 19038 '../internals/has': 78, 19039 '../internals/object-define-property': 110, 19040 '../internals/object-get-own-property-descriptor': 111, 19041 '../internals/own-keys': 121 19042 } 19043 ], 19044 52: [ 19045 function (_dereq_, module, exports) { 19046 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 19047 var MATCH = wellKnownSymbol('match'); 19048 module.exports = function (METHOD_NAME) { 19049 var regexp = /./; 19050 try { 19051 '/./'[METHOD_NAME](regexp); 19052 } catch (e) { 19053 try { 19054 regexp[MATCH] = false; 19055 return '/./'[METHOD_NAME](regexp); 19056 } catch (f) { 19057 /* empty */ 19058 } 19059 } 19060 return false; 19061 }; 19062 }, 19063 { 19064 '../internals/well-known-symbol': 164 19065 } 19066 ], 19067 53: [ 19068 function (_dereq_, module, exports) { 19069 var fails = _dereq_('../internals/fails'); 19070 module.exports = !fails(function () { 19071 function F() { 19072 /* empty */ 19073 } 19074 F.prototype.constructor = null; 19075 return Object.getPrototypeOf(new F()) !== F.prototype; 19076 }); 19077 }, 19078 { 19079 '../internals/fails': 69 19080 } 19081 ], 19082 54: [ 19083 function (_dereq_, module, exports) { 19084 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 19085 var quot = /"/g; // B.2.3.2.1 CreateHTML(string, tag, attribute, value) 19086 // https://tc39.github.io/ecma262/#sec-createhtml 19087 module.exports = function (string, tag, attribute, value) { 19088 var S = String(requireObjectCoercible(string)); 19089 var p1 = '<' + tag; 19090 if (attribute !== '') p1 += ' ' + attribute + '="' + String(value).replace(quot, '"') + '"'; 19091 return p1 + '>' + S + '</' + tag + '>'; 19092 }; 19093 }, 19094 { 19095 '../internals/require-object-coercible': 131 19096 } 19097 ], 19098 55: [ 19099 function (_dereq_, module, exports) { 19100 'use strict'; 19101 var IteratorPrototype = _dereq_('../internals/iterators-core').IteratorPrototype; 19102 var create = _dereq_('../internals/object-create'); 19103 var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor'); 19104 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 19105 var Iterators = _dereq_('../internals/iterators'); 19106 var returnThis = function () { 19107 return this; 19108 }; 19109 module.exports = function (IteratorConstructor, NAME, next) { 19110 var TO_STRING_TAG = NAME + ' Iterator'; 19111 IteratorConstructor.prototype = create(IteratorPrototype, { 19112 next: createPropertyDescriptor(1, next) 19113 }); 19114 setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true); 19115 Iterators[TO_STRING_TAG] = returnThis; 19116 return IteratorConstructor; 19117 }; 19118 }, 19119 { 19120 '../internals/create-property-descriptor': 57, 19121 '../internals/iterators': 97, 19122 '../internals/iterators-core': 96, 19123 '../internals/object-create': 108, 19124 '../internals/set-to-string-tag': 135 19125 } 19126 ], 19127 56: [ 19128 function (_dereq_, module, exports) { 19129 var DESCRIPTORS = _dereq_('../internals/descriptors'); 19130 var definePropertyModule = _dereq_('../internals/object-define-property'); 19131 var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor'); 19132 module.exports = DESCRIPTORS ? function (object, key, value) { 19133 return definePropertyModule.f(object, key, createPropertyDescriptor(1, value)); 19134 } 19135 : function (object, key, value) { 19136 object[key] = value; 19137 return object; 19138 }; 19139 }, 19140 { 19141 '../internals/create-property-descriptor': 57, 19142 '../internals/descriptors': 61, 19143 '../internals/object-define-property': 110 19144 } 19145 ], 19146 57: [
vendor: 4,905 bytes, lines 19147-19249
19147 function (_dereq_, module, exports) { 19148 module.exports = function (bitmap, value) { 19149 return { 19150 enumerable: !(bitmap & 1), 19151 configurable: !(bitmap & 2), 19152 writable: !(bitmap & 4), 19153 value: value 19154 }; 19155 }; 19156 }, 19157 { 19158 } 19159 ], 19160 58: [ 19161 function (_dereq_, module, exports) { 19162 'use strict'; 19163 var toPrimitive = _dereq_('../internals/to-primitive'); 19164 var definePropertyModule = _dereq_('../internals/object-define-property'); 19165 var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor'); 19166 module.exports = function (object, key, value) { 19167 var propertyKey = toPrimitive(key); 19168 if (propertyKey in object) definePropertyModule.f(object, propertyKey, createPropertyDescriptor(0, value)); 19169 else object[propertyKey] = value; 19170 }; 19171 }, 19172 { 19173 '../internals/create-property-descriptor': 57, 19174 '../internals/object-define-property': 110, 19175 '../internals/to-primitive': 156 19176 } 19177 ], 19178 59: [ 19179 function (_dereq_, module, exports) { 19180 'use strict'; 19181 var $ = _dereq_('../internals/export'); 19182 var createIteratorConstructor = _dereq_('../internals/create-iterator-constructor'); 19183 var getPrototypeOf = _dereq_('../internals/object-get-prototype-of'); 19184 var setPrototypeOf = _dereq_('../internals/object-set-prototype-of'); 19185 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 19186 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 19187 var redefine = _dereq_('../internals/redefine'); 19188 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 19189 var IS_PURE = _dereq_('../internals/is-pure'); 19190 var Iterators = _dereq_('../internals/iterators'); 19191 var IteratorsCore = _dereq_('../internals/iterators-core'); 19192 var IteratorPrototype = IteratorsCore.IteratorPrototype; 19193 var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS; 19194 var ITERATOR = wellKnownSymbol('iterator'); 19195 var KEYS = 'keys'; 19196 var VALUES = 'values'; 19197 var ENTRIES = 'entries'; 19198 var returnThis = function () { 19199 return this; 19200 }; 19201 module.exports = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) { 19202 createIteratorConstructor(IteratorConstructor, NAME, next); 19203 var getIterationMethod = function (KIND) { 19204 if (KIND === DEFAULT && defaultIterator) return defaultIterator; 19205 if (!BUGGY_SAFARI_ITERATORS && KIND in IterablePrototype) return IterablePrototype[KIND]; 19206 switch (KIND) { 19207 case KEYS: 19208 return function keys() { 19209 return new IteratorConstructor(this, KIND); 19210 }; 19211 case VALUES: 19212 return function values() { 19213 return new IteratorConstructor(this, KIND); 19214 }; 19215 case ENTRIES: 19216 return function entries() { 19217 return new IteratorConstructor(this, KIND); 19218 }; 19219 } 19220 return function () { 19221 return new IteratorConstructor(this); 19222 }; 19223 }; 19224 var TO_STRING_TAG = NAME + ' Iterator'; 19225 var INCORRECT_VALUES_NAME = false; 19226 var IterablePrototype = Iterable.prototype; 19227 var nativeIterator = IterablePrototype[ITERATOR] || IterablePrototype['@@iterator'] || DEFAULT && IterablePrototype[DEFAULT]; 19228 var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT); 19229 var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator; 19230 var CurrentIteratorPrototype, 19231 methods, 19232 KEY; // fix native 19233 if (anyNativeIterator) { 19234 CurrentIteratorPrototype = getPrototypeOf(anyNativeIterator.call(new Iterable())); 19235 if (IteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) { 19236 if (!IS_PURE && getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype) { 19237 if (setPrototypeOf) { 19238 setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype); 19239 } else if (typeof CurrentIteratorPrototype[ITERATOR] != 'function') { 19240 createNonEnumerableProperty(CurrentIteratorPrototype, ITERATOR, returnThis); 19241 } 19242 } // Set @@toStringTag to native iterators 19243 19244 setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true); 19245 if (IS_PURE) Iterators[TO_STRING_TAG] = returnThis; 19246 } 19247 } // fix Array#{values, @@iterator}.name in V8 / FF 19248 19249 if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
vendor: 4,572 bytes, lines 19250-19387
19250 INCORRECT_VALUES_NAME = true; 19251 defaultIterator = function values() { 19252 return nativeIterator.call(this); 19253 }; 19254 } // define iterator 19255 19256 if ((!IS_PURE || FORCED) && IterablePrototype[ITERATOR] !== defaultIterator) { 19257 createNonEnumerableProperty(IterablePrototype, ITERATOR, defaultIterator); 19258 } 19259 Iterators[NAME] = defaultIterator; // export additional methods 19260 if (DEFAULT) { 19261 methods = { 19262 values: getIterationMethod(VALUES), 19263 keys: IS_SET ? defaultIterator : getIterationMethod(KEYS), 19264 entries: getIterationMethod(ENTRIES) 19265 }; 19266 if (FORCED) for (KEY in methods) { 19267 if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) { 19268 redefine(IterablePrototype, KEY, methods[KEY]); 19269 } 19270 } else $({ 19271 target: NAME, 19272 proto: true, 19273 forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME 19274 }, methods); 19275 } 19276 return methods; 19277 }; 19278 }, 19279 { 19280 '../internals/create-iterator-constructor': 55, 19281 '../internals/create-non-enumerable-property': 56, 19282 '../internals/export': 68, 19283 '../internals/is-pure': 93, 19284 '../internals/iterators': 97, 19285 '../internals/iterators-core': 96, 19286 '../internals/object-get-prototype-of': 115, 19287 '../internals/object-set-prototype-of': 119, 19288 '../internals/redefine': 126, 19289 '../internals/set-to-string-tag': 135, 19290 '../internals/well-known-symbol': 164 19291 } 19292 ], 19293 60: [ 19294 function (_dereq_, module, exports) { 19295 var path = _dereq_('../internals/path'); 19296 var has = _dereq_('../internals/has'); 19297 var wrappedWellKnownSymbolModule = _dereq_('../internals/well-known-symbol-wrapped'); 19298 var defineProperty = _dereq_('../internals/object-define-property').f; 19299 module.exports = function (NAME) { 19300 var Symbol = path.Symbol || (path.Symbol = { 19301 }); 19302 if (!has(Symbol, NAME)) defineProperty(Symbol, NAME, { 19303 value: wrappedWellKnownSymbolModule.f(NAME) 19304 }); 19305 }; 19306 }, 19307 { 19308 '../internals/has': 78, 19309 '../internals/object-define-property': 110, 19310 '../internals/path': 122, 19311 '../internals/well-known-symbol-wrapped': 163 19312 } 19313 ], 19314 61: [ 19315 function (_dereq_, module, exports) { 19316 var fails = _dereq_('../internals/fails'); // Thank's IE8 for his funny defineProperty 19317 module.exports = !fails(function () { 19318 return Object.defineProperty({ 19319 }, 1, { 19320 get: function () { 19321 return 7; 19322 } 19323 }) [1] != 7; 19324 }); 19325 }, 19326 { 19327 '../internals/fails': 69 19328 } 19329 ], 19330 62: [ 19331 function (_dereq_, module, exports) { 19332 var global = _dereq_('../internals/global'); 19333 var isObject = _dereq_('../internals/is-object'); 19334 var document = global.document; // typeof document.createElement is 'object' in old IE 19335 var EXISTS = isObject(document) && isObject(document.createElement); 19336 module.exports = function (it) { 19337 return EXISTS ? document.createElement(it) : { 19338 }; 19339 }; 19340 }, 19341 { 19342 '../internals/global': 77, 19343 '../internals/is-object': 92 19344 } 19345 ], 19346 63: [ 19347 function (_dereq_, module, exports) { 19348 // iterable DOM collections 19349 // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods 19350 module.exports = { 19351 CSSRuleList: 0, 19352 CSSStyleDeclaration: 0, 19353 CSSValueList: 0, 19354 ClientRectList: 0, 19355 DOMRectList: 0, 19356 DOMStringList: 0, 19357 DOMTokenList: 1, 19358 DataTransferItemList: 0, 19359 FileList: 0, 19360 HTMLAllCollection: 0, 19361 HTMLCollection: 0, 19362 HTMLFormElement: 0, 19363 HTMLSelectElement: 0, 19364 MediaList: 0, 19365 MimeTypeArray: 0, 19366 NamedNodeMap: 0, 19367 NodeList: 1, 19368 PaintRequestList: 0, 19369 Plugin: 0, 19370 PluginArray: 0, 19371 SVGLengthList: 0, 19372 SVGNumberList: 0, 19373 SVGPathSegList: 0, 19374 SVGPointList: 0, 19375 SVGStringList: 0, 19376 SVGTransformList: 0, 19377 SourceBufferList: 0, 19378 StyleSheetList: 0, 19379 TextTrackCueList: 0, 19380 TextTrackList: 0, 19381 TouchList: 0 19382 }; 19383 }, 19384 { 19385 } 19386 ], 19387 64: [
vendor: 4,325 bytes, lines 19388-19499
19388 function (_dereq_, module, exports) { 19389 var userAgent = _dereq_('../internals/engine-user-agent'); 19390 module.exports = /(iphone|ipod|ipad).*applewebkit/i.test(userAgent); 19391 }, 19392 { 19393 '../internals/engine-user-agent': 65 19394 } 19395 ], 19396 65: [ 19397 function (_dereq_, module, exports) { 19398 var getBuiltIn = _dereq_('../internals/get-built-in'); 19399 module.exports = getBuiltIn('navigator', 'userAgent') || ''; 19400 }, 19401 { 19402 '../internals/get-built-in': 74 19403 } 19404 ], 19405 66: [ 19406 function (_dereq_, module, exports) { 19407 var global = _dereq_('../internals/global'); 19408 var userAgent = _dereq_('../internals/engine-user-agent'); 19409 var process = global.process; 19410 var versions = process && process.versions; 19411 var v8 = versions && versions.v8; 19412 var match, 19413 version; 19414 if (v8) { 19415 match = v8.split('.'); 19416 version = match[0] + match[1]; 19417 } else if (userAgent) { 19418 match = userAgent.match(/Edge\/(\d+)/); 19419 if (!match || match[1] >= 74) { 19420 match = userAgent.match(/Chrome\/(\d+)/); 19421 if (match) version = match[1]; 19422 } 19423 } 19424 module.exports = version && + version; 19425 }, 19426 { 19427 '../internals/engine-user-agent': 65, 19428 '../internals/global': 77 19429 } 19430 ], 19431 67: [ 19432 function (_dereq_, module, exports) { 19433 // IE8- don't enum bug keys 19434 module.exports = [ 19435 'constructor', 19436 'hasOwnProperty', 19437 'isPrototypeOf', 19438 'propertyIsEnumerable', 19439 'toLocaleString', 19440 'toString', 19441 'valueOf' 19442 ]; 19443 }, 19444 { 19445 } 19446 ], 19447 68: [ 19448 function (_dereq_, module, exports) { 19449 var global = _dereq_('../internals/global'); 19450 var getOwnPropertyDescriptor = _dereq_('../internals/object-get-own-property-descriptor').f; 19451 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 19452 var redefine = _dereq_('../internals/redefine'); 19453 var setGlobal = _dereq_('../internals/set-global'); 19454 var copyConstructorProperties = _dereq_('../internals/copy-constructor-properties'); 19455 var isForced = _dereq_('../internals/is-forced'); 19456 /* 19457 options.target - name of the target object 19458 options.global - target is the global object 19459 options.stat - export as static methods of target 19460 options.proto - export as prototype methods of target 19461 options.real - real prototype method for the `pure` version 19462 options.forced - export even if the native feature is available 19463 options.bind - bind methods to the target, required for the `pure` version 19464 options.wrap - wrap constructors to preventing global pollution, required for the `pure` version 19465 options.unsafe - use the simple assignment of property instead of delete + defineProperty 19466 options.sham - add a flag to not completely full polyfills 19467 options.enumerable - export as enumerable property 19468 options.noTargetGet - prevent calling a getter on target 19469*/ 19470 module.exports = function (options, source) { 19471 var TARGET = options.target; 19472 var GLOBAL = options.global; 19473 var STATIC = options.stat; 19474 var FORCED, 19475 target, 19476 key, 19477 targetProperty, 19478 sourceProperty, 19479 descriptor; 19480 if (GLOBAL) { 19481 target = global; 19482 } else if (STATIC) { 19483 target = global[TARGET] || setGlobal(TARGET, { 19484 }); 19485 } else { 19486 target = (global[TARGET] || { 19487 }).prototype; 19488 } 19489 if (target) for (key in source) { 19490 sourceProperty = source[key]; 19491 if (options.noTargetGet) { 19492 descriptor = getOwnPropertyDescriptor(target, key); 19493 targetProperty = descriptor && descriptor.value; 19494 } else targetProperty = target[key]; 19495 FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); // contained in target 19496 if (!FORCED && targetProperty !== undefined) { 19497 if (typeof sourceProperty === typeof targetProperty) continue; 19498 copyConstructorProperties(sourceProperty, targetProperty); 19499 }
19499 // add a flag to not completely full polyfills 19500 19501 if (options.sham || targetProperty && targetProperty.sham) { 19502 createNonEnumerableProperty(sourceProperty, 'sham', true); 19503 } // extend global 19504 19505 redefine(target, key, sourceProperty, options); 19506 } 19507 }; 19508 }, 19509 { 19510 '../internals/copy-constructor-properties': 51, 19511 '../internals/create-non-enumerable-property': 56, 19512 '../internals/global': 77, 19513 '../internals/is-forced': 91, 19514 '../internals/object-get-own-property-descriptor': 111, 19515 '../internals/redefine': 126, 19516 '../internals/set-global': 133 19517 } 19518 ], 19519 69: [ 19520 function (_dereq_, module, exports) { 19521 module.exports = function (exec) { 19522 try { 19523 return !!exec(); 19524 } catch (error) { 19525 return true; 19526 } 19527 }; 19528 }, 19529 { 19530 } 19531 ], 19532 70: [ 19533 function (_dereq_, module, exports) { 19534 'use strict'; // TODO: Remove from `core-js@4` since it's moved to entry points 19535 _dereq_('../modules/es.regexp.exec'); 19536 var redefine = _dereq_('../internals/redefine'); 19537 var fails = _dereq_('../internals/fails'); 19538 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 19539 var regexpExec = _dereq_('../internals/regexp-exec'); 19540 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 19541 var SPECIES = wellKnownSymbol('species'); 19542 var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () { 19543 // #replace needs built-in support for named groups. 19544 // #match works fine because it just return the exec results, even if it has 19545 // a "grops" property. 19546 var re = /./; 19547 re.exec = function () { 19548 var result = [ 19549 ]; 19550 result.groups = { 19551 a: '7' 19552 }; 19553 return result; 19554 }; 19555 return ''.replace(re, '$<a>') !== '7'; 19556 }); // IE <= 11 replaces $0 with the whole match, as if it was $& 19557 // https://stackoverflow.com/questions/6024666/getting-ie-to-replace-a-regex-with-the-literal-string-0 19558 var REPLACE_KEEPS_$0 = function () { 19559 return 'a'.replace(/./, '$0') === '$0'; 19560 }(); 19561 var REPLACE = wellKnownSymbol('replace'); // Safari <= 13.0.3(?) substitutes nth capture where n>m with an empty string 19562 var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = function () { 19563 if (/./[REPLACE]) { 19564 return /./[REPLACE]('a', '$0') === ''; 19565 } 19566 return false; 19567 }(); // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec 19568 // Weex JS has frozen built-in prototypes, so use try / catch wrapper 19569 var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function () { 19570 var re = /(?:)/; 19571 var originalExec = re.exec; 19572 re.exec = function () { 19573 return originalExec.apply(this, arguments); 19574 }; 19575 var result = 'ab'.split(re); 19576 return result.length !== 2 || result[0] !== 'a' || result[1] !== 'b'; 19577 }); 19578 module.exports = function (KEY, length, exec, sham) { 19579 var SYMBOL = wellKnownSymbol(KEY); 19580 var DELEGATES_TO_SYMBOL = !fails(function () { 19581 // String methods call symbol-named RegEp methods 19582 var O = { 19583 }; 19584 O[SYMBOL] = function () { 19585 return 7; 19586 }; 19587 return ''[KEY](O) != 7; 19588 }); 19589 var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () { 19590 // Symbol-named RegExp methods call .exec 19591 var execCalled = false; 19592 var re = /a/; 19593 if (KEY === 'split') { 19594 // We can't use real regex here since it causes deoptimization 19595 // and serious performance degradation in V8 19596 // https://github.com/zloirock/core-js/issues/306 19597 re = { 19598 }; // RegExp[@@split] doesn't call the regex's exec method, but first creates 19599 // a new one. We need to return the patched regex when creating the new one. 19600 re.constructor = { 19601 }; 19602 re.constructor[SPECIES] = function () { 19603 return re; 19604 }; 19605 re.flags = ''; 19606 re[SYMBOL] = /./[SYMBOL]; 19607 } 19608 re.exec = function () { 19609 execCalled = true; 19610 return null; 19611 }; 19612 re[SYMBOL](''); 19613 return !execCalled; 19614 }); 19615 if (!DELEGATES_TO_SYMBOL || !DELEGATES_TO_EXEC || KEY === 'replace' && !(REPLACE_SUPPORTS_NAMED_GROUPS && REPLACE_KEEPS_$0 && !REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE) || KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC) { 19616 var nativeRegExpMethod = /./[SYMBOL]; 19617 var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) { 19618 if (regexp.exec === regexpExec) { 19619 if (DELEGATES_TO_SYMBOL && !forceStringMethod) { 19620 // The native String method already delegates to @@method (this 19621 // polyfilled function), leasing to infinite recursion. 19622 // We avoid it by directly calling the native @@method method. 19623 return { 19624 done: true, 19625 value: nativeRegExpMethod.call(regexp, str, arg2) 19626 }; 19627 } 19628 return { 19629 done: true, 19630 value: nativeMethod.call(str, regexp, arg2) 19631 }; 19632 } 19633 return { 19634 done: false 19635 }; 19636 }, { 19637 REPLACE_KEEPS_$0: REPLACE_KEEPS_$0, 19638 REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE: REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE 19639 }); 19640 var stringMethod = methods[0]; 19641 var regexMethod = methods[1]; 19642 redefine(String.prototype, KEY, stringMethod); 19643 redefine(RegExp.prototype, SYMBOL, length == 2 // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
vendor: 4,219 bytes, lines 19644-19764
19644 // 21.2.5.11 RegExp.prototype[@@split](string, limit) 19645 ? function (string, arg) { 19646 return regexMethod.call(string, this, arg); 19647 } // 21.2.5.6 RegExp.prototype[@@match](string) 19648 // 21.2.5.9 RegExp.prototype[@@search](string) 19649 19650 : function (string) { 19651 return regexMethod.call(string, this); 19652 }); 19653 } 19654 if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true); 19655 }; 19656 }, 19657 { 19658 '../internals/create-non-enumerable-property': 56, 19659 '../internals/fails': 69, 19660 '../internals/redefine': 126, 19661 '../internals/regexp-exec': 128, 19662 '../internals/well-known-symbol': 164, 19663 '../modules/es.regexp.exec': 199 19664 } 19665 ], 19666 71: [ 19667 function (_dereq_, module, exports) { 19668 var fails = _dereq_('../internals/fails'); 19669 module.exports = !fails(function () { 19670 return Object.isExtensible(Object.preventExtensions({ 19671 })); 19672 }); 19673 }, 19674 { 19675 '../internals/fails': 69 19676 } 19677 ], 19678 72: [ 19679 function (_dereq_, module, exports) { 19680 var aFunction = _dereq_('../internals/a-function'); // optional / simple context binding 19681 module.exports = function (fn, that, length) { 19682 aFunction(fn); 19683 if (that === undefined) return fn; 19684 switch (length) { 19685 case 0: 19686 return function () { 19687 return fn.call(that); 19688 }; 19689 case 1: 19690 return function (a) { 19691 return fn.call(that, a); 19692 }; 19693 case 2: 19694 return function (a, b) { 19695 return fn.call(that, a, b); 19696 }; 19697 case 3: 19698 return function (a, b, c) { 19699 return fn.call(that, a, b, c); 19700 }; 19701 } 19702 return function () /* ...args */ 19703 { 19704 return fn.apply(that, arguments); 19705 }; 19706 }; 19707 }, 19708 { 19709 '../internals/a-function': 23 19710 } 19711 ], 19712 73: [ 19713 function (_dereq_, module, exports) { 19714 'use strict'; 19715 var aFunction = _dereq_('../internals/a-function'); 19716 var isObject = _dereq_('../internals/is-object'); 19717 var slice = [ 19718 ].slice; 19719 var factories = { 19720 }; 19721 var construct = function (C, argsLength, args) { 19722 if (!(argsLength in factories)) { 19723 for (var list = [ 19724 ], i = 0; i < argsLength; i++) list[i] = 'a[' + i + ']'; // eslint-disable-next-line no-new-func 19725 factories[argsLength] = Function('C,a', 'return new C(' + list.join(',') + ')'); 19726 } 19727 return factories[argsLength](C, args); 19728 }; // `Function.prototype.bind` method implementation 19729 // https://tc39.github.io/ecma262/#sec-function.prototype.bind 19730 module.exports = Function.bind || function bind(that /* , ...args */ 19731 ) { 19732 var fn = aFunction(this); 19733 var partArgs = slice.call(arguments, 1); 19734 var boundFunction = function bound() /* args... */ 19735 { 19736 var args = partArgs.concat(slice.call(arguments)); 19737 return this instanceof boundFunction ? construct(fn, args.length, args) : fn.apply(that, args); 19738 }; 19739 if (isObject(fn.prototype)) boundFunction.prototype = fn.prototype; 19740 return boundFunction; 19741 }; 19742 }, 19743 { 19744 '../internals/a-function': 23, 19745 '../internals/is-object': 92 19746 } 19747 ], 19748 74: [ 19749 function (_dereq_, module, exports) { 19750 var path = _dereq_('../internals/path'); 19751 var global = _dereq_('../internals/global'); 19752 var aFunction = function (variable) { 19753 return typeof variable == 'function' ? variable : undefined; 19754 }; 19755 module.exports = function (namespace, method) { 19756 return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global[namespace]) : path[namespace] && path[namespace][method] || global[namespace] && global[namespace][method]; 19757 }; 19758 }, 19759 { 19760 '../internals/global': 77, 19761 '../internals/path': 122 19762 } 19763 ], 19764 75: [
19765 function (_dereq_, module, exports) { 19766 var classof = _dereq_('../internals/classof'); 19767 var Iterators = _dereq_('../internals/iterators'); 19768 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 19769 var ITERATOR = wellKnownSymbol('iterator'); 19770 module.exports = function (it) { 19771 if (it != undefined) return it[ITERATOR] || it['@@iterator'] || Iterators[classof(it)]; 19772 }; 19773 }, 19774 { 19775 '../internals/classof': 47, 19776 '../internals/iterators': 97, 19777 '../internals/well-known-symbol': 164 19778 } 19779 ], 19780 76: [ 19781 function (_dereq_, module, exports) { 19782 var anObject = _dereq_('../internals/an-object'); 19783 var getIteratorMethod = _dereq_('../internals/get-iterator-method'); 19784 module.exports = function (it) { 19785 var iteratorMethod = getIteratorMethod(it); 19786 if (typeof iteratorMethod != 'function') { 19787 throw TypeError(String(it) + ' is not iterable'); 19788 } 19789 return anObject(iteratorMethod.call(it)); 19790 }; 19791 }, 19792 { 19793 '../internals/an-object': 28, 19794 '../internals/get-iterator-method': 75 19795 } 19796 ], 19797 77: [ 19798 function (_dereq_, module, exports) { 19799 (function (global) { 19800 var check = function (it) { 19801 return it && it.Math == Math && it; 19802 }; // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 19803 module.exports = // eslint-disable-next-line no-undef 19804 check(typeof globalThis == 'object' && globalThis) || check(typeof window == 'object' && window) || check(typeof self == 'object' && self) || check(typeof global == 'object' && global) || // eslint-disable-next-line no-new-func 19805 Function('return this') (); 19806 }).call(this, typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : { 19807 }) 19808 }, 19809 { 19810 } 19811 ], 19812 78: [ 19813 function (_dereq_, module, exports) { 19814 var hasOwnProperty = { 19815 }.hasOwnProperty; 19816 module.exports = function (it, key) { 19817 return hasOwnProperty.call(it, key); 19818 }; 19819 }, 19820 { 19821 } 19822 ], 19823 79: [ 19824 function (_dereq_, module, exports) { 19825 module.exports = { 19826 }; 19827 }, 19828 { 19829 } 19830 ], 19831 80: [ 19832 function (_dereq_, module, exports) { 19833 var global = _dereq_('../internals/global'); 19834 module.exports = function (a, b) { 19835 var console = global.console; 19836 if (console && console.error) { 19837 arguments.length === 1 ? console.error(a) : console.error(a, b); 19838 } 19839 }; 19840 }, 19841 { 19842 '../internals/global': 77 19843 } 19844 ], 19845 81: [ 19846 function (_dereq_, module, exports) { 19847 var getBuiltIn = _dereq_('../internals/get-built-in'); 19848 module.exports = getBuiltIn('document', 'documentElement'); 19849 }, 19850 { 19851 '../internals/get-built-in': 74 19852 } 19853 ], 19854 82: [ 19855 function (_dereq_, module, exports) { 19856 var DESCRIPTORS = _dereq_('../internals/descriptors'); 19857 var fails = _dereq_('../internals/fails'); 19858 var createElement = _dereq_('../internals/document-create-element'); // Thank's IE8 for his funny defineProperty 19859 module.exports = !DESCRIPTORS && !fails(function () { 19860 return Object.defineProperty(createElement('div'), 'a', { 19861 get: function () { 19862 return 7; 19863 } 19864 }).a != 7; 19865 }); 19866 }, 19867 { 19868 '../internals/descriptors': 61, 19869 '../internals/document-create-element': 62, 19870 '../internals/fails': 69 19871 } 19872 ], 19873 83: [ 19874 function (_dereq_, module, exports) { 19875 // IEEE754 conversions based on https://github.com/feross/ieee754 19876 // eslint-disable-next-line no-shadow-restricted-names 19877 var Infinity = 1 / 0; 19878 var abs = Math.abs; 19879 var pow = Math.pow; 19880 var floor = Math.floor; 19881 var log = Math.log; 19882 var LN2 = Math.LN2; 19883 var pack = function (number, mantissaLength, bytes) { 19884 var buffer = new Array(bytes); 19885 var exponentLength = bytes * 8 - mantissaLength - 1; 19886 var eMax = (1 << exponentLength) - 1; 19887 var eBias = eMax >> 1; 19888 var rt = mantissaLength === 23 ? pow(2, - 24) - pow(2, - 77) : 0; 19889 var sign = number < 0 || number === 0 && 1 / number < 0 ? 1 : 0; 19890 var index = 0; 19891 var exponent, 19892 mantissa, 19893 c; 19894 number = abs(number); // eslint-disable-next-line no-self-compare 19895 if (number != number || number === Infinity) { 19896 // eslint-disable-next-line no-self-compare 19897 mantissa = number != number ? 1 : 0; 19898 exponent = eMax; 19899 } else { 19900 exponent = floor(log(number) / LN2); 19901 if (number * (c = pow(2, - exponent)) < 1) { 19902 exponent--; 19903 c *= 2; 19904 } 19905 if (exponent + eBias >= 1) { 19906 number += rt / c; 19907 } else { 19908 number += rt * pow(2, 1 - eBias); 19909 } 19910 if (number * c >= 2) { 19911 exponent++; 19912 c /= 2; 19913 } 19914 if (exponent + eBias >= eMax) { 19915 mantissa = 0; 19916 exponent = eMax; 19917 } else if (exponent + eBias >= 1) { 19918 mantissa = (number * c - 1) * pow(2, mantissaLength); 19919 exponent = exponent + eBias; 19920 } else { 19921 mantissa = number * pow(2, eBias - 1) * pow(2, mantissaLength); 19922 exponent = 0; 19923 } 19924 } 19925 for (; mantissaLength >= 8; buffer[index++] = mantissa & 255, mantissa /= 256, mantissaLength -= 8); 19926 exponent = exponent << mantissaLength | mantissa; 19927 exponentLength += mantissaLength; 19928 for (; exponentLength > 0; buffer[index++] = exponent & 255, exponent /= 256, exponentLength -= 8); 19929 buffer[--index] |= sign * 128; 19930 return buffer; 19931 }; 19932 var unpack = function (buffer, mantissaLength) { 19933 var bytes = buffer.length; 19934 var exponentLength = bytes * 8 - mantissaLength - 1; 19935 var eMax = (1 << exponentLength) - 1; 19936 var eBias = eMax >> 1;
19937 var nBits = exponentLength - 7; 19938 var index = bytes - 1; 19939 var sign = buffer[index--]; 19940 var exponent = sign & 127; 19941 var mantissa; 19942 sign >>= 7; 19943 for (; nBits > 0; exponent = exponent * 256 + buffer[index], index--, nBits -= 8); 19944 mantissa = exponent & (1 << - nBits) - 1; 19945 exponent >>= - nBits; 19946 nBits += mantissaLength; 19947 for (; nBits > 0; mantissa = mantissa * 256 + buffer[index], index--, nBits -= 8); 19948 if (exponent === 0) { 19949 exponent = 1 - eBias; 19950 } else if (exponent === eMax) { 19951 return mantissa ? NaN : sign ? - Infinity : Infinity; 19952 } else { 19953 mantissa = mantissa + pow(2, mantissaLength); 19954 exponent = exponent - eBias; 19955 } 19956 return (sign ? - 1 : 1) * mantissa * pow(2, exponent - mantissaLength); 19957 }; 19958 module.exports = { 19959 pack: pack, 19960 unpack: unpack 19961 }; 19962 }, 19963 { 19964 } 19965 ], 19966 84: [ 19967 function (_dereq_, module, exports) { 19968 var fails = _dereq_('../internals/fails'); 19969 var classof = _dereq_('../internals/classof-raw'); 19970 var split = ''.split; // fallback for non-array-like ES3 and non-enumerable old V8 strings 19971 module.exports = fails(function () { 19972 // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 19973 // eslint-disable-next-line no-prototype-builtins 19974 return !Object('z').propertyIsEnumerable(0); 19975 }) ? function (it) { 19976 return classof(it) == 'String' ? split.call(it, '') : Object(it); 19977 } 19978 : Object; 19979 }, 19980 { 19981 '../internals/classof-raw': 46, 19982 '../internals/fails': 69 19983 } 19984 ], 19985 85: [ 19986 function (_dereq_, module, exports) { 19987 var isObject = _dereq_('../internals/is-object'); 19988 var setPrototypeOf = _dereq_('../internals/object-set-prototype-of'); // makes subclassing work correct for wrapped built-ins 19989 module.exports = function ($this, dummy, Wrapper) { 19990 var NewTarget, 19991 NewTargetPrototype; 19992 if ( // it can work only with native `setPrototypeOf` 19993 setPrototypeOf && // we haven't completely correct pre-ES6 way for getting `new.target`, so use this 19994 typeof (NewTarget = dummy.constructor) == 'function' && NewTarget !== Wrapper && isObject(NewTargetPrototype = NewTarget.prototype) && NewTargetPrototype !== Wrapper.prototype) setPrototypeOf($this, NewTargetPrototype); 19995 return $this; 19996 }; 19997 }, 19998 { 19999 '../internals/is-object': 92, 20000 '../internals/object-set-prototype-of': 119 20001 } 20002 ], 20003 86: [ 20004 function (_dereq_, module, exports) { 20005 var store = _dereq_('../internals/shared-store'); 20006 var functionToString = Function.toString; // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper 20007 if (typeof store.inspectSource != 'function') { 20008 store.inspectSource = function (it) { 20009 return functionToString.call(it); 20010 }; 20011 } 20012 module.exports = store.inspectSource; 20013 }, 20014 { 20015 '../internals/shared-store': 137 20016 } 20017 ], 20018 87: [ 20019 function (_dereq_, module, exports) { 20020 var hiddenKeys = _dereq_('../internals/hidden-keys'); 20021 var isObject = _dereq_('../internals/is-object'); 20022 var has = _dereq_('../internals/has'); 20023 var defineProperty = _dereq_('../internals/object-define-property').f; 20024 var uid = _dereq_('../internals/uid'); 20025 var FREEZING = _dereq_('../internals/freezing'); 20026 var METADATA = uid('meta'); 20027 var id = 0; 20028 var isExtensible = Object.isExtensible || function () { 20029 return true; 20030 }; 20031 var setMetadata = function (it) { 20032 defineProperty(it, METADATA, { 20033 value: { 20034 objectID: 'O' + ++id, 20035 // object ID 20036 weakData: { 20037 } // weak collections IDs 20038 20039 } 20040 }); 20041 }; 20042 var fastKey = function (it, create) { 20043 // return a primitive with prefix 20044 if (!isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; 20045 if (!has(it, METADATA)) { 20046 // can't set metadata to uncaught frozen object 20047 if (!isExtensible(it)) return 'F'; // not necessary to add metadata 20048 if (!create) return 'E'; // add missing metadata 20049 setMetadata(it); // return object ID 20050 } 20051 return it[METADATA].objectID; 20052 }; 20053 var getWeakData = function (it, create) { 20054 if (!has(it, METADATA)) { 20055 // can't set metadata to uncaught frozen object 20056 if (!isExtensible(it)) return true; // not necessary to add metadata 20057 if (!create) return false; // add missing metadata 20058 setMetadata(it); // return the store of weak collections IDs 20059 } 20060 return it[METADATA].weakData; 20061 }; // add metadata on freeze-family methods calling 20062 var onFreeze = function (it) { 20063 if (FREEZING && meta.REQUIRED && isExtensible(it) && !has(it, METADATA)) setMetadata(it); 20064 return it; 20065 }; 20066 var meta = module.exports = { 20067 REQUIRED: false, 20068 fastKey: fastKey, 20069 getWeakData: getWeakData, 20070 onFreeze: onFreeze 20071 }; 20072 hiddenKeys[METADATA] = true; 20073 }, 20074 { 20075 '../internals/freezing': 71, 20076 '../internals/has': 78, 20077 '../internals/hidden-keys': 79, 20078 '../internals/is-object': 92, 20079 '../internals/object-define-property': 110, 20080 '../internals/uid': 161 20081 } 20082 ], 20083 88: [
vendor: 4,191 bytes, lines 20084-20206
20084 function (_dereq_, module, exports) { 20085 var NATIVE_WEAK_MAP = _dereq_('../internals/native-weak-map'); 20086 var global = _dereq_('../internals/global'); 20087 var isObject = _dereq_('../internals/is-object'); 20088 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 20089 var objectHas = _dereq_('../internals/has'); 20090 var sharedKey = _dereq_('../internals/shared-key'); 20091 var hiddenKeys = _dereq_('../internals/hidden-keys'); 20092 var WeakMap = global.WeakMap; 20093 var set, 20094 get, 20095 has; 20096 var enforce = function (it) { 20097 return has(it) ? get(it) : set(it, { 20098 }); 20099 }; 20100 var getterFor = function (TYPE) { 20101 return function (it) { 20102 var state; 20103 if (!isObject(it) || (state = get(it)).type !== TYPE) { 20104 throw TypeError('Incompatible receiver, ' + TYPE + ' required'); 20105 } 20106 return state; 20107 }; 20108 }; 20109 if (NATIVE_WEAK_MAP) { 20110 var store = new WeakMap(); 20111 var wmget = store.get; 20112 var wmhas = store.has; 20113 var wmset = store.set; 20114 set = function (it, metadata) { 20115 wmset.call(store, it, metadata); 20116 return metadata; 20117 }; 20118 get = function (it) { 20119 return wmget.call(store, it) || { 20120 }; 20121 }; 20122 has = function (it) { 20123 return wmhas.call(store, it); 20124 }; 20125 } else { 20126 var STATE = sharedKey('state'); 20127 hiddenKeys[STATE] = true; 20128 set = function (it, metadata) { 20129 createNonEnumerableProperty(it, STATE, metadata); 20130 return metadata; 20131 }; 20132 get = function (it) { 20133 return objectHas(it, STATE) ? it[STATE] : { 20134 }; 20135 }; 20136 has = function (it) { 20137 return objectHas(it, STATE); 20138 }; 20139 } 20140 module.exports = { 20141 set: set, 20142 get: get, 20143 has: has, 20144 enforce: enforce, 20145 getterFor: getterFor 20146 }; 20147 }, 20148 { 20149 '../internals/create-non-enumerable-property': 56, 20150 '../internals/global': 77, 20151 '../internals/has': 78, 20152 '../internals/hidden-keys': 79, 20153 '../internals/is-object': 92, 20154 '../internals/native-weak-map': 103, 20155 '../internals/shared-key': 136 20156 } 20157 ], 20158 89: [ 20159 function (_dereq_, module, exports) { 20160 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 20161 var Iterators = _dereq_('../internals/iterators'); 20162 var ITERATOR = wellKnownSymbol('iterator'); 20163 var ArrayPrototype = Array.prototype; // check on default Array iterator 20164 module.exports = function (it) { 20165 return it !== undefined && (Iterators.Array === it || ArrayPrototype[ITERATOR] === it); 20166 }; 20167 }, 20168 { 20169 '../internals/iterators': 97, 20170 '../internals/well-known-symbol': 164 20171 } 20172 ], 20173 90: [ 20174 function (_dereq_, module, exports) { 20175 var classof = _dereq_('../internals/classof-raw'); // `IsArray` abstract operation 20176 // https://tc39.github.io/ecma262/#sec-isarray 20177 module.exports = Array.isArray || function isArray(arg) { 20178 return classof(arg) == 'Array'; 20179 }; 20180 }, 20181 { 20182 '../internals/classof-raw': 46 20183 } 20184 ], 20185 91: [ 20186 function (_dereq_, module, exports) { 20187 var fails = _dereq_('../internals/fails'); 20188 var replacement = /#|\.prototype\./; 20189 var isForced = function (feature, detection) { 20190 var value = data[normalize(feature)]; 20191 return value == POLYFILL ? true : value == NATIVE ? false : typeof detection == 'function' ? fails(detection) : !!detection; 20192 }; 20193 var normalize = isForced.normalize = function (string) { 20194 return String(string).replace(replacement, '.').toLowerCase(); 20195 }; 20196 var data = isForced.data = { 20197 }; 20198 var NATIVE = isForced.NATIVE = 'N'; 20199 var POLYFILL = isForced.POLYFILL = 'P'; 20200 module.exports = isForced; 20201 }, 20202 { 20203 '../internals/fails': 69 20204 } 20205 ], 20206 92: [
vendor: 5,390 bytes, lines 20207-20339
20207 function (_dereq_, module, exports) { 20208 module.exports = function (it) { 20209 return typeof it === 'object' ? it !== null : typeof it === 'function'; 20210 }; 20211 }, 20212 { 20213 } 20214 ], 20215 93: [ 20216 function (_dereq_, module, exports) { 20217 module.exports = false; 20218 }, 20219 { 20220 } 20221 ], 20222 94: [ 20223 function (_dereq_, module, exports) { 20224 var isObject = _dereq_('../internals/is-object'); 20225 var classof = _dereq_('../internals/classof-raw'); 20226 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 20227 var MATCH = wellKnownSymbol('match'); // `IsRegExp` abstract operation 20228 // https://tc39.github.io/ecma262/#sec-isregexp 20229 module.exports = function (it) { 20230 var isRegExp; 20231 return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classof(it) == 'RegExp'); 20232 }; 20233 }, 20234 { 20235 '../internals/classof-raw': 46, 20236 '../internals/is-object': 92, 20237 '../internals/well-known-symbol': 164 20238 } 20239 ], 20240 95: [ 20241 function (_dereq_, module, exports) { 20242 var anObject = _dereq_('../internals/an-object'); 20243 var isArrayIteratorMethod = _dereq_('../internals/is-array-iterator-method'); 20244 var toLength = _dereq_('../internals/to-length'); 20245 var bind = _dereq_('../internals/function-bind-context'); 20246 var getIteratorMethod = _dereq_('../internals/get-iterator-method'); 20247 var callWithSafeIterationClosing = _dereq_('../internals/call-with-safe-iteration-closing'); 20248 var Result = function (stopped, result) { 20249 this.stopped = stopped; 20250 this.result = result; 20251 }; 20252 var iterate = module.exports = function (iterable, fn, that, AS_ENTRIES, IS_ITERATOR) { 20253 var boundFunction = bind(fn, that, AS_ENTRIES ? 2 : 1); 20254 var iterator, 20255 iterFn, 20256 index, 20257 length, 20258 result, 20259 next, 20260 step; 20261 if (IS_ITERATOR) { 20262 iterator = iterable; 20263 } else { 20264 iterFn = getIteratorMethod(iterable); 20265 if (typeof iterFn != 'function') throw TypeError('Target is not iterable'); // optimisation for array iterators 20266 if (isArrayIteratorMethod(iterFn)) { 20267 for (index = 0, length = toLength(iterable.length); length > index; index++) { 20268 result = AS_ENTRIES ? boundFunction(anObject(step = iterable[index]) [0], step[1]) : boundFunction(iterable[index]); 20269 if (result && result instanceof Result) return result; 20270 } 20271 return new Result(false); 20272 } 20273 iterator = iterFn.call(iterable); 20274 } 20275 next = iterator.next; 20276 while (!(step = next.call(iterator)).done) { 20277 result = callWithSafeIterationClosing(iterator, boundFunction, step.value, AS_ENTRIES); 20278 if (typeof result == 'object' && result && result instanceof Result) return result; 20279 } 20280 return new Result(false); 20281 }; 20282 iterate.stop = function (result) { 20283 return new Result(true, result); 20284 }; 20285 }, 20286 { 20287 '../internals/an-object': 28, 20288 '../internals/call-with-safe-iteration-closing': 44, 20289 '../internals/function-bind-context': 72, 20290 '../internals/get-iterator-method': 75, 20291 '../internals/is-array-iterator-method': 89, 20292 '../internals/to-length': 152 20293 } 20294 ], 20295 96: [ 20296 function (_dereq_, module, exports) { 20297 'use strict'; 20298 var getPrototypeOf = _dereq_('../internals/object-get-prototype-of'); 20299 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 20300 var has = _dereq_('../internals/has'); 20301 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 20302 var IS_PURE = _dereq_('../internals/is-pure'); 20303 var ITERATOR = wellKnownSymbol('iterator'); 20304 var BUGGY_SAFARI_ITERATORS = false; 20305 var returnThis = function () { 20306 return this; 20307 }; // `%IteratorPrototype%` object 20308 // https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object 20309 var IteratorPrototype, 20310 PrototypeOfArrayIteratorPrototype, 20311 arrayIterator; 20312 if ([].keys) { 20313 arrayIterator = [ 20314 ].keys(); // Safari 8 has buggy iterators w/o `next` 20315 if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true; 20316 else { 20317 PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator)); 20318 if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype; 20319 } 20320 } 20321 if (IteratorPrototype == undefined) IteratorPrototype = { 20322 }; // 25.1.2.1.1 %IteratorPrototype%[@@iterator]() 20323 if (!IS_PURE && !has(IteratorPrototype, ITERATOR)) { 20324 createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis); 20325 } 20326 module.exports = { 20327 IteratorPrototype: IteratorPrototype, 20328 BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS 20329 }; 20330 }, 20331 { 20332 '../internals/create-non-enumerable-property': 56, 20333 '../internals/has': 78, 20334 '../internals/is-pure': 93, 20335 '../internals/object-get-prototype-of': 115, 20336 '../internals/well-known-symbol': 164 20337 } 20338 ], 20339 97: [
20340 function (_dereq_, module, exports) { 20341 module.exports = { 20342 }; 20343 }, 20344 { 20345 } 20346 ], 20347 98: [ 20348 function (_dereq_, module, exports) { 20349 // `Math.sign` method implementation 20350 // https://tc39.github.io/ecma262/#sec-math.sign 20351 module.exports = Math.sign || function sign(x) { 20352 // eslint-disable-next-line no-self-compare 20353 return (x = + x) == 0 || x != x ? x : x < 0 ? - 1 : 1; 20354 }; 20355 }, 20356 { 20357 } 20358 ], 20359 99: [ 20360 function (_dereq_, module, exports) { 20361 var global = _dereq_('../internals/global'); 20362 var getOwnPropertyDescriptor = _dereq_('../internals/object-get-own-property-descriptor').f; 20363 var classof = _dereq_('../internals/classof-raw'); 20364 var macrotask = _dereq_('../internals/task').set; 20365 var IS_IOS = _dereq_('../internals/engine-is-ios'); 20366 var MutationObserver = global.MutationObserver || global.WebKitMutationObserver; 20367 var process = global.process; 20368 var Promise = global.Promise; 20369 var IS_NODE = classof(process) == 'process'; // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask` 20370 var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global, 'queueMicrotask'); 20371 var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value; 20372 var flush, 20373 head, 20374 last, 20375 notify, 20376 toggle, 20377 node, 20378 promise, 20379 then; // modern engines have queueMicrotask method 20380 if (!queueMicrotask) { 20381 flush = function () { 20382 var parent, 20383 fn; 20384 if (IS_NODE && (parent = process.domain)) parent.exit(); 20385 while (head) { 20386 fn = head.fn; 20387 head = head.next; 20388 try { 20389 fn(); 20390 } catch (error) { 20391 if (head) notify(); 20392 else last = undefined; 20393 throw error; 20394 } 20395 } 20396 last = undefined; 20397 if (parent) parent.enter(); 20398 }; // Node.js 20399 if (IS_NODE) { 20400 notify = function () { 20401 process.nextTick(flush); 20402 }; // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339 20403 } else if (MutationObserver && !IS_IOS) { 20404 toggle = true; 20405 node = document.createTextNode(''); 20406 new MutationObserver(flush).observe(node, { 20407 characterData: true 20408 }); 20409 notify = function () { 20410 node.data = toggle = !toggle; 20411 }; // environments with maybe non-completely correct, but existent Promise 20412 } else if (Promise && Promise.resolve) { 20413 // Promise.resolve without an argument throws an error in LG WebOS 2 20414 promise = Promise.resolve(undefined); 20415 then = promise.then; 20416 notify = function () { 20417 then.call(promise, flush); 20418 }; // for other environments - macrotask based on: 20419 // - setImmediate 20420 // - MessageChannel 20421 // - window.postMessag 20422 // - onreadystatechange 20423 // - setTimeout 20424 } else { 20425 notify = function () { 20426 // strange IE + webpack dev server bug - use .call(global) 20427 macrotask.call(global, flush); 20428 }; 20429 } 20430 } 20431 module.exports = queueMicrotask || function (fn) { 20432 var task = { 20433 fn: fn, 20434 next: undefined 20435 }; 20436 if (last) last.next = task; 20437 if (!head) { 20438 head = task; 20439 notify(); 20440 } 20441 last = task; 20442 }; 20443 }, 20444 { 20445 '../internals/classof-raw': 46, 20446 '../internals/engine-is-ios': 64, 20447 '../internals/global': 77, 20448 '../internals/object-get-own-property-descriptor': 111, 20449 '../internals/task': 146 20450 } 20451 ], 20452 100: [ 20453 function (_dereq_, module, exports) { 20454 var global = _dereq_('../internals/global'); 20455 module.exports = global.Promise; 20456 }, 20457 { 20458 '../internals/global': 77 20459 } 20460 ], 20461 101: [
20462 function (_dereq_, module, exports) { 20463 var fails = _dereq_('../internals/fails'); 20464 module.exports = !!Object.getOwnPropertySymbols && !fails(function () { 20465 // Chrome 38 Symbol has incorrect toString conversion 20466 // eslint-disable-next-line no-undef 20467 return !String(Symbol()); 20468 }); 20469 }, 20470 { 20471 '../internals/fails': 69 20472 } 20473 ], 20474 102: [ 20475 function (_dereq_, module, exports) { 20476 var fails = _dereq_('../internals/fails'); 20477 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 20478 var IS_PURE = _dereq_('../internals/is-pure'); 20479 var ITERATOR = wellKnownSymbol('iterator'); 20480 module.exports = !fails(function () { 20481 var url = new URL('b?a=1&b=2&c=3', 'http://a'); 20482 var searchParams = url.searchParams; 20483 var result = ''; 20484 url.pathname = 'c%20d'; 20485 searchParams.forEach(function (value, key) { 20486 searchParams['delete']('b'); 20487 result += key + value; 20488 }); 20489 return IS_PURE && !url.toJSON || !searchParams.sort || url.href !== 'http://a/c%20d?a=1&c=3' || searchParams.get('c') !== '3' || String(new URLSearchParams('?a=1')) !== 'a=1' || !searchParams[ITERATOR] // throws in Edge 20490 || new URL('https://a@b').username !== 'a' || new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b' // not punycoded in Edge 20491 || new URL('http://ÑеÑÑ').host !== 'xn--e1aybc' // not escaped in Chrome 62- 20492 || new URL('http://a#б').hash !== '#%D0%B1' // fails in Chrome 66- 20493 || result !== 'a1c3' // throws in Safari 20494 || new URL('http://x', undefined).host !== 'x'; 20495 }); 20496 }, 20497 { 20498 '../internals/fails': 69, 20499 '../internals/is-pure': 93, 20500 '../internals/well-known-symbol': 164 20501 } 20502 ], 20503 103: [ 20504 function (_dereq_, module, exports) { 20505 var global = _dereq_('../internals/global'); 20506 var inspectSource = _dereq_('../internals/inspect-source'); 20507 var WeakMap = global.WeakMap; 20508 module.exports = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap)); 20509 }, 20510 { 20511 '../internals/global': 77, 20512 '../internals/inspect-source': 86 20513 } 20514 ], 20515 104: [ 20516 function (_dereq_, module, exports) { 20517 'use strict'; 20518 var aFunction = _dereq_('../internals/a-function'); 20519 var PromiseCapability = function (C) { 20520 var resolve, 20521 reject; 20522 this.promise = new C(function ($$resolve, $$reject) { 20523 if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor'); 20524 resolve = $$resolve; 20525 reject = $$reject; 20526 }); 20527 this.resolve = aFunction(resolve); 20528 this.reject = aFunction(reject); 20529 }; // 25.4.1.5 NewPromiseCapability(C) 20530 module.exports.f = function (C) { 20531 return new PromiseCapability(C); 20532 }; 20533 }, 20534 { 20535 '../internals/a-function': 23 20536 } 20537 ], 20538 105: [ 20539 function (_dereq_, module, exports) { 20540 var isRegExp = _dereq_('../internals/is-regexp'); 20541 module.exports = function (it) { 20542 if (isRegExp(it)) { 20543 throw TypeError('The method doesn\'t accept regular expressions'); 20544 } 20545 return it; 20546 }; 20547 }, 20548 { 20549 '../internals/is-regexp': 94 20550 } 20551 ], 20552 106: [ 20553 function (_dereq_, module, exports) { 20554 var global = _dereq_('../internals/global'); 20555 var globalIsFinite = global.isFinite; // `Number.isFinite` method 20556 // https://tc39.github.io/ecma262/#sec-number.isfinite 20557 module.exports = Number.isFinite || function isFinite(it) { 20558 return typeof it == 'number' && globalIsFinite(it); 20559 }; 20560 }, 20561 { 20562 '../internals/global': 77 20563 } 20564 ], 20565 107: [ 20566 function (_dereq_, module, exports) { 20567 'use strict'; 20568 var DESCRIPTORS = _dereq_('../internals/descriptors'); 20569 var fails = _dereq_('../internals/fails'); 20570 var objectKeys = _dereq_('../internals/object-keys'); 20571 var getOwnPropertySymbolsModule = _dereq_('../internals/object-get-own-property-symbol
vendor: 6,467 bytes, lines 20571-20720
20571s'); 20572 var propertyIsEnumerableModule = _dereq_('../internals/object-property-is-enumerable'); 20573 var toObject = _dereq_('../internals/to-object'); 20574 var IndexedObject = _dereq_('../internals/indexed-object'); 20575 var nativeAssign = Object.assign; 20576 var defineProperty = Object.defineProperty; // `Object.assign` method 20577 // https://tc39.github.io/ecma262/#sec-object.assign 20578 module.exports = !nativeAssign || fails(function () { 20579 // should have correct order of operations (Edge bug) 20580 if (DESCRIPTORS && nativeAssign({ 20581 b: 1 20582 }, nativeAssign(defineProperty({ 20583 }, 'a', { 20584 enumerable: true, 20585 get: function () { 20586 defineProperty(this, 'b', { 20587 value: 3, 20588 enumerable: false 20589 }); 20590 } 20591 }), { 20592 b: 2 20593 })).b !== 1) return true; // should work with symbols and should have deterministic property order (V8 bug) 20594 var A = { 20595 }; 20596 var B = { 20597 }; // eslint-disable-next-line no-undef 20598 var symbol = Symbol(); 20599 var alphabet = 'abcdefghijklmnopqrst'; 20600 A[symbol] = 7; 20601 alphabet.split('').forEach(function (chr) { 20602 B[chr] = chr; 20603 }); 20604 return nativeAssign({ 20605 }, A) [symbol] != 7 || objectKeys(nativeAssign({ 20606 }, B)).join('') != alphabet; 20607 }) ? function assign(target, source) { 20608 // eslint-disable-line no-unused-vars 20609 var T = toObject(target); 20610 var argumentsLength = arguments.length; 20611 var index = 1; 20612 var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; 20613 var propertyIsEnumerable = propertyIsEnumerableModule.f; 20614 while (argumentsLength > index) { 20615 var S = IndexedObject(arguments[index++]); 20616 var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S); 20617 var length = keys.length; 20618 var j = 0; 20619 var key; 20620 while (length > j) { 20621 key = keys[j++]; 20622 if (!DESCRIPTORS || propertyIsEnumerable.call(S, key)) T[key] = S[key]; 20623 } 20624 } 20625 return T; 20626 } 20627 : nativeAssign; 20628 }, 20629 { 20630 '../internals/descriptors': 61, 20631 '../internals/fails': 69, 20632 '../internals/indexed-object': 84, 20633 '../internals/object-get-own-property-symbols': 114, 20634 '../internals/object-keys': 117, 20635 '../internals/object-property-is-enumerable': 118, 20636 '../internals/to-object': 153 20637 } 20638 ], 20639 108: [ 20640 function (_dereq_, module, exports) { 20641 var anObject = _dereq_('../internals/an-object'); 20642 var defineProperties = _dereq_('../internals/object-define-properties'); 20643 var enumBugKeys = _dereq_('../internals/enum-bug-keys'); 20644 var hiddenKeys = _dereq_('../internals/hidden-keys'); 20645 var html = _dereq_('../internals/html'); 20646 var documentCreateElement = _dereq_('../internals/document-create-element'); 20647 var sharedKey = _dereq_('../internals/shared-key'); 20648 var GT = '>'; 20649 var LT = '<'; 20650 var PROTOTYPE = 'prototype'; 20651 var SCRIPT = 'script'; 20652 var IE_PROTO = sharedKey('IE_PROTO'); 20653 var EmptyConstructor = function () { 20654 /* empty */ 20655 }; 20656 var scriptTag = function (content) { 20657 return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT; 20658 }; // Create object with fake `null` prototype: use ActiveX Object with cleared prototype 20659 var NullProtoObjectViaActiveX = function (activeXDocument) { 20660 activeXDocument.write(scriptTag('')); 20661 activeXDocument.close(); 20662 var temp = activeXDocument.parentWindow.Object; 20663 activeXDocument = null; // avoid memory leak 20664 return temp; 20665 }; // Create object with fake `null` prototype: use iframe Object with cleared prototype 20666 var NullProtoObjectViaIFrame = function () { 20667 // Thrash, waste and sodomy: IE GC bug 20668 var iframe = documentCreateElement('iframe'); 20669 var JS = 'java' + SCRIPT + ':'; 20670 var iframeDocument; 20671 iframe.style.display = 'none'; 20672 html.appendChild(iframe); // https://github.com/zloirock/core-js/issues/475 20673 iframe.src = String(JS); 20674 iframeDocument = iframe.contentWindow.document; 20675 iframeDocument.open(); 20676 iframeDocument.write(scriptTag('document.F=Object')); 20677 iframeDocument.close(); 20678 return iframeDocument.F; 20679 }; // Check for document.domain and active x support 20680 // No need to use active x approach when document.domain is not set 20681 // see https://github.com/es-shims/es5-shim/issues/150 20682 // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346 20683 // avoid IE GC bug 20684 var activeXDocument; 20685 var NullProtoObject = function () { 20686 try { 20687 /* global ActiveXObject */ 20688 activeXDocument = document.domain && new ActiveXObject('htmlfile'); 20689 } catch (error) { 20690 /* ignore */ 20691 } 20692 NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame(); 20693 var length = enumBugKeys.length; 20694 while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]]; 20695 return NullProtoObject(); 20696 }; 20697 hiddenKeys[IE_PROTO] = true; // `Object.create` method 20698 // https://tc39.github.io/ecma262/#sec-object.create 20699 module.exports = Object.create || function create(O, Properties) { 20700 var result; 20701 if (O !== null) { 20702 EmptyConstructor[PROTOTYPE] = anObject(O); 20703 result = new EmptyConstructor(); 20704 EmptyConstructor[PROTOTYPE] = null; // add "__proto__" for Object.getPrototypeOf polyfill 20705 result[IE_PROTO] = O; 20706 } else result = NullProtoObject(); 20707 return Properties === undefined ? result : defineProperties(result, Properties); 20708 }; 20709 }, 20710 { 20711 '../internals/an-object': 28, 20712 '../internals/document-create-element': 62, 20713 '../internals/enum-bug-keys': 67, 20714 '../internals/hidden-keys': 79, 20715 '../internals/html': 81, 20716 '../internals/object-define-properties': 109, 20717 '../internals/shared-key': 136 20718 } 20719 ], 20720 109: [
vendor: 4,831 bytes, lines 20721-20829
20721 function (_dereq_, module, exports) { 20722 var DESCRIPTORS = _dereq_('../internals/descriptors'); 20723 var definePropertyModule = _dereq_('../internals/object-define-property'); 20724 var anObject = _dereq_('../internals/an-object'); 20725 var objectKeys = _dereq_('../internals/object-keys'); // `Object.defineProperties` method 20726 // https://tc39.github.io/ecma262/#sec-object.defineproperties 20727 module.exports = DESCRIPTORS ? Object.defineProperties : function defineProperties(O, Properties) { 20728 anObject(O); 20729 var keys = objectKeys(Properties); 20730 var length = keys.length; 20731 var index = 0; 20732 var key; 20733 while (length > index) definePropertyModule.f(O, key = keys[index++], Properties[key]); 20734 return O; 20735 }; 20736 }, 20737 { 20738 '../internals/an-object': 28, 20739 '../internals/descriptors': 61, 20740 '../internals/object-define-property': 110, 20741 '../internals/object-keys': 117 20742 } 20743 ], 20744 110: [ 20745 function (_dereq_, module, exports) { 20746 var DESCRIPTORS = _dereq_('../internals/descriptors'); 20747 var IE8_DOM_DEFINE = _dereq_('../internals/ie8-dom-define'); 20748 var anObject = _dereq_('../internals/an-object'); 20749 var toPrimitive = _dereq_('../internals/to-primitive'); 20750 var nativeDefineProperty = Object.defineProperty; // `Object.defineProperty` method 20751 // https://tc39.github.io/ecma262/#sec-object.defineproperty 20752 exports.f = DESCRIPTORS ? nativeDefineProperty : function defineProperty(O, P, Attributes) { 20753 anObject(O); 20754 P = toPrimitive(P, true); 20755 anObject(Attributes); 20756 if (IE8_DOM_DEFINE) try { 20757 return nativeDefineProperty(O, P, Attributes); 20758 } catch (error) { 20759 /* empty */ 20760 } 20761 if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported'); 20762 if ('value' in Attributes) O[P] = Attributes.value; 20763 return O; 20764 }; 20765 }, 20766 { 20767 '../internals/an-object': 28, 20768 '../internals/descriptors': 61, 20769 '../internals/ie8-dom-define': 82, 20770 '../internals/to-primitive': 156 20771 } 20772 ], 20773 111: [ 20774 function (_dereq_, module, exports) { 20775 var DESCRIPTORS = _dereq_('../internals/descriptors'); 20776 var propertyIsEnumerableModule = _dereq_('../internals/object-property-is-enumerable'); 20777 var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor'); 20778 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 20779 var toPrimitive = _dereq_('../internals/to-primitive'); 20780 var has = _dereq_('../internals/has'); 20781 var IE8_DOM_DEFINE = _dereq_('../internals/ie8-dom-define'); 20782 var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; // `Object.getOwnPropertyDescriptor` method 20783 // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor 20784 exports.f = DESCRIPTORS ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { 20785 O = toIndexedObject(O); 20786 P = toPrimitive(P, true); 20787 if (IE8_DOM_DEFINE) try { 20788 return nativeGetOwnPropertyDescriptor(O, P); 20789 } catch (error) { 20790 /* empty */ 20791 } 20792 if (has(O, P)) return createPropertyDescriptor(!propertyIsEnumerableModule.f.call(O, P), O[P]); 20793 }; 20794 }, 20795 { 20796 '../internals/create-property-descriptor': 57, 20797 '../internals/descriptors': 61, 20798 '../internals/has': 78, 20799 '../internals/ie8-dom-define': 82, 20800 '../internals/object-property-is-enumerable': 118, 20801 '../internals/to-indexed-object': 150, 20802 '../internals/to-primitive': 156 20803 } 20804 ], 20805 112: [ 20806 function (_dereq_, module, exports) { 20807 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 20808 var nativeGetOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f; 20809 var toString = { 20810 }.toString; 20811 var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : [ 20812 ]; 20813 var getWindowNames = function (it) { 20814 try { 20815 return nativeGetOwnPropertyNames(it); 20816 } catch (error) { 20817 return windowNames.slice(); 20818 } 20819 }; // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window 20820 module.exports.f = function getOwnPropertyNames(it) { 20821 return windowNames && toString.call(it) == '[object Window]' ? getWindowNames(it) : nativeGetOwnPropertyNames(toIndexedObject(it)); 20822 }; 20823 }, 20824 { 20825 '../internals/object-get-own-property-names': 113, 20826 '../internals/to-indexed-object': 150 20827 } 20828 ], 20829 113: [
vendor: 4,139 bytes, lines 20830-20935
20830 function (_dereq_, module, exports) { 20831 var internalObjectKeys = _dereq_('../internals/object-keys-internal'); 20832 var enumBugKeys = _dereq_('../internals/enum-bug-keys'); 20833 var hiddenKeys = enumBugKeys.concat('length', 'prototype'); // `Object.getOwnPropertyNames` method 20834 // https://tc39.github.io/ecma262/#sec-object.getownpropertynames 20835 exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { 20836 return internalObjectKeys(O, hiddenKeys); 20837 }; 20838 }, 20839 { 20840 '../internals/enum-bug-keys': 67, 20841 '../internals/object-keys-internal': 116 20842 } 20843 ], 20844 114: [ 20845 function (_dereq_, module, exports) { 20846 exports.f = Object.getOwnPropertySymbols; 20847 }, 20848 { 20849 } 20850 ], 20851 115: [ 20852 function (_dereq_, module, exports) { 20853 var has = _dereq_('../internals/has'); 20854 var toObject = _dereq_('../internals/to-object'); 20855 var sharedKey = _dereq_('../internals/shared-key'); 20856 var CORRECT_PROTOTYPE_GETTER = _dereq_('../internals/correct-prototype-getter'); 20857 var IE_PROTO = sharedKey('IE_PROTO'); 20858 var ObjectPrototype = Object.prototype; // `Object.getPrototypeOf` method 20859 // https://tc39.github.io/ecma262/#sec-object.getprototypeof 20860 module.exports = CORRECT_PROTOTYPE_GETTER ? Object.getPrototypeOf : function (O) { 20861 O = toObject(O); 20862 if (has(O, IE_PROTO)) return O[IE_PROTO]; 20863 if (typeof O.constructor == 'function' && O instanceof O.constructor) { 20864 return O.constructor.prototype; 20865 } 20866 return O instanceof Object ? ObjectPrototype : null; 20867 }; 20868 }, 20869 { 20870 '../internals/correct-prototype-getter': 53, 20871 '../internals/has': 78, 20872 '../internals/shared-key': 136, 20873 '../internals/to-object': 153 20874 } 20875 ], 20876 116: [ 20877 function (_dereq_, module, exports) { 20878 var has = _dereq_('../internals/has'); 20879 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 20880 var indexOf = _dereq_('../internals/array-includes').indexOf; 20881 var hiddenKeys = _dereq_('../internals/hidden-keys'); 20882 module.exports = function (object, names) { 20883 var O = toIndexedObject(object); 20884 var i = 0; 20885 var result = [ 20886 ]; 20887 var key; 20888 for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key); // Don't enum bug & hidden keys 20889 while (names.length > i) if (has(O, key = names[i++])) { 20890 ~indexOf(result, key) || result.push(key); 20891 } 20892 return result; 20893 }; 20894 }, 20895 { 20896 '../internals/array-includes': 36, 20897 '../internals/has': 78, 20898 '../internals/hidden-keys': 79, 20899 '../internals/to-indexed-object': 150 20900 } 20901 ], 20902 117: [ 20903 function (_dereq_, module, exports) { 20904 var internalObjectKeys = _dereq_('../internals/object-keys-internal'); 20905 var enumBugKeys = _dereq_('../internals/enum-bug-keys'); // `Object.keys` method 20906 // https://tc39.github.io/ecma262/#sec-object.keys 20907 module.exports = Object.keys || function keys(O) { 20908 return internalObjectKeys(O, enumBugKeys); 20909 }; 20910 }, 20911 { 20912 '../internals/enum-bug-keys': 67, 20913 '../internals/object-keys-internal': 116 20914 } 20915 ], 20916 118: [ 20917 function (_dereq_, module, exports) { 20918 'use strict'; 20919 var nativePropertyIsEnumerable = { 20920 }.propertyIsEnumerable; 20921 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; // Nashorn ~ JDK8 bug 20922 var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 20923 1: 2 20924 }, 1); // `Object.prototype.propertyIsEnumerable` method implementation 20925 // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable 20926 exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) { 20927 var descriptor = getOwnPropertyDescriptor(this, V); 20928 return !!descriptor && descriptor.enumerable; 20929 } 20930 : nativePropertyIsEnumerable; 20931 }, 20932 { 20933 } 20934 ], 20935 119: [
vendor: 4,172 bytes, lines 20936-21054
20936 function (_dereq_, module, exports) { 20937 var anObject = _dereq_('../internals/an-object'); 20938 var aPossiblePrototype = _dereq_('../internals/a-possible-prototype'); // `Object.setPrototypeOf` method 20939 // https://tc39.github.io/ecma262/#sec-object.setprototypeof 20940 // Works with __proto__ only. Old v8 can't work with null proto objects. 20941 /* eslint-disable no-proto */ 20942 module.exports = Object.setPrototypeOf || ('__proto__' in { 20943 } 20944 ? function () { 20945 var CORRECT_SETTER = false; 20946 var test = { 20947 }; 20948 var setter; 20949 try { 20950 setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set; 20951 setter.call(test, [ 20952 ]); 20953 CORRECT_SETTER = test instanceof Array; 20954 } catch (error) { 20955 /* empty */ 20956 } 20957 return function setPrototypeOf(O, proto) { 20958 anObject(O); 20959 aPossiblePrototype(proto); 20960 if (CORRECT_SETTER) setter.call(O, proto); 20961 else O.__proto__ = proto; 20962 return O; 20963 }; 20964 }() : undefined); 20965 }, 20966 { 20967 '../internals/a-possible-prototype': 24, 20968 '../internals/an-object': 28 20969 } 20970 ], 20971 120: [ 20972 function (_dereq_, module, exports) { 20973 'use strict'; 20974 var TO_STRING_TAG_SUPPORT = _dereq_('../internals/to-string-tag-support'); 20975 var classof = _dereq_('../internals/classof'); // `Object.prototype.toString` method implementation 20976 // https://tc39.github.io/ecma262/#sec-object.prototype.tostring 20977 module.exports = TO_STRING_TAG_SUPPORT ? { 20978 }.toString : function toString() { 20979 return '[object ' + classof(this) + ']'; 20980 }; 20981 }, 20982 { 20983 '../internals/classof': 47, 20984 '../internals/to-string-tag-support': 157 20985 } 20986 ], 20987 121: [ 20988 function (_dereq_, module, exports) { 20989 var getBuiltIn = _dereq_('../internals/get-built-in'); 20990 var getOwnPropertyNamesModule = _dereq_('../internals/object-get-own-property-names'); 20991 var getOwnPropertySymbolsModule = _dereq_('../internals/object-get-own-property-symbols'); 20992 var anObject = _dereq_('../internals/an-object'); // all object keys, includes non-enumerable and symbols 20993 module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) { 20994 var keys = getOwnPropertyNamesModule.f(anObject(it)); 20995 var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; 20996 return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys; 20997 }; 20998 }, 20999 { 21000 '../internals/an-object': 28, 21001 '../internals/get-built-in': 74, 21002 '../internals/object-get-own-property-names': 113, 21003 '../internals/object-get-own-property-symbols': 114 21004 } 21005 ], 21006 122: [ 21007 function (_dereq_, module, exports) { 21008 var global = _dereq_('../internals/global'); 21009 module.exports = global; 21010 }, 21011 { 21012 '../internals/global': 77 21013 } 21014 ], 21015 123: [ 21016 function (_dereq_, module, exports) { 21017 module.exports = function (exec) { 21018 try { 21019 return { 21020 error: false, 21021 value: exec() 21022 }; 21023 } catch (error) { 21024 return { 21025 error: true, 21026 value: error 21027 }; 21028 } 21029 }; 21030 }, 21031 { 21032 } 21033 ], 21034 124: [ 21035 function (_dereq_, module, exports) { 21036 var anObject = _dereq_('../internals/an-object'); 21037 var isObject = _dereq_('../internals/is-object'); 21038 var newPromiseCapability = _dereq_('../internals/new-promise-capability'); 21039 module.exports = function (C, x) { 21040 anObject(C); 21041 if (isObject(x) && x.constructor === C) return x; 21042 var promiseCapability = newPromiseCapability.f(C); 21043 var resolve = promiseCapability.resolve; 21044 resolve(x); 21045 return promiseCapability.promise; 21046 }; 21047 }, 21048 { 21049 '../internals/an-object': 28, 21050 '../internals/is-object': 92, 21051 '../internals/new-promise-capability': 104 21052 } 21053 ], 21054 125: [
21055 function (_dereq_, module, exports) { 21056 var redefine = _dereq_('../internals/redefine'); 21057 module.exports = function (target, src, options) { 21058 for (var key in src) redefine(target, key, src[key], options); 21059 return target; 21060 }; 21061 }, 21062 { 21063 '../internals/redefine': 126 21064 } 21065 ], 21066 126: [ 21067 function (_dereq_, module, exports) { 21068 var global = _dereq_('../internals/global'); 21069 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 21070 var has = _dereq_('../internals/has'); 21071 var setGlobal = _dereq_('../internals/set-global'); 21072 var inspectSource = _dereq_('../internals/inspect-source'); 21073 var InternalStateModule = _dereq_('../internals/internal-state'); 21074 var getInternalState = InternalStateModule.get; 21075 var enforceInternalState = InternalStateModule.enforce; 21076 var TEMPLATE = String(String).split('String'); 21077 (module.exports = function (O, key, value, options) { 21078 var unsafe = options ? !!options.unsafe : false; 21079 var simple = options ? !!options.enumerable : false; 21080 var noTargetGet = options ? !!options.noTargetGet : false;
vendor: 5,636 bytes, lines 21081-21215
21081 if (typeof value == 'function') { 21082 if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key); 21083 enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : ''); 21084 } 21085 if (O === global) { 21086 if (simple) O[key] = value; 21087 else setGlobal(key, value); 21088 return; 21089 } else if (!unsafe) { 21090 delete O[key]; 21091 } else if (!noTargetGet && O[key]) { 21092 simple = true; 21093 } 21094 if (simple) O[key] = value; 21095 else createNonEnumerableProperty(O, key, value); // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative 21096 }) (Function.prototype, 'toString', function toString() { 21097 return typeof this == 'function' && getInternalState(this).source || inspectSource(this); 21098 }); 21099 }, 21100 { 21101 '../internals/create-non-enumerable-property': 56, 21102 '../internals/global': 77, 21103 '../internals/has': 78, 21104 '../internals/inspect-source': 86, 21105 '../internals/internal-state': 88, 21106 '../internals/set-global': 133 21107 } 21108 ], 21109 127: [ 21110 function (_dereq_, module, exports) { 21111 var classof = _dereq_('./classof-raw'); 21112 var regexpExec = _dereq_('./regexp-exec'); // `RegExpExec` abstract operation 21113 // https://tc39.github.io/ecma262/#sec-regexpexec 21114 module.exports = function (R, S) { 21115 var exec = R.exec; 21116 if (typeof exec === 'function') { 21117 var result = exec.call(R, S); 21118 if (typeof result !== 'object') { 21119 throw TypeError('RegExp exec method returned something other than an Object or null'); 21120 } 21121 return result; 21122 } 21123 if (classof(R) !== 'RegExp') { 21124 throw TypeError('RegExp#exec called on incompatible receiver'); 21125 } 21126 return regexpExec.call(R, S); 21127 }; 21128 }, 21129 { 21130 './classof-raw': 46, 21131 './regexp-exec': 128 21132 } 21133 ], 21134 128: [ 21135 function (_dereq_, module, exports) { 21136 'use strict'; 21137 var regexpFlags = _dereq_('./regexp-flags'); 21138 var stickyHelpers = _dereq_('./regexp-sticky-helpers'); 21139 var nativeExec = RegExp.prototype.exec; // This always refers to the native implementation, because the 21140 // String#replace polyfill uses ./fix-regexp-well-known-symbol-logic.js, 21141 // which loads this file before patching the method. 21142 var nativeReplace = String.prototype.replace; 21143 var patchedExec = nativeExec; 21144 var UPDATES_LAST_INDEX_WRONG = function () { 21145 var re1 = /a/; 21146 var re2 = /b*/g; 21147 nativeExec.call(re1, 'a'); 21148 nativeExec.call(re2, 'a'); 21149 return re1.lastIndex !== 0 || re2.lastIndex !== 0; 21150 }(); 21151 var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y || stickyHelpers.BROKEN_CARET; // nonparticipating capturing group, copied from es5-shim's String#split patch. 21152 var NPCG_INCLUDED = /()??/.exec('') [1] !== undefined; 21153 var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y; 21154 if (PATCH) { 21155 patchedExec = function exec(str) { 21156 var re = this; 21157 var lastIndex, 21158 reCopy, 21159 match, 21160 i; 21161 var sticky = UNSUPPORTED_Y && re.sticky; 21162 var flags = regexpFlags.call(re); 21163 var source = re.source; 21164 var charsAdded = 0; 21165 var strCopy = str; 21166 if (sticky) { 21167 flags = flags.replace('y', ''); 21168 if (flags.indexOf('g') === - 1) { 21169 flags += 'g'; 21170 } 21171 strCopy = String(str).slice(re.lastIndex); // Support anchored sticky behavior. 21172 if (re.lastIndex > 0 && (!re.multiline || re.multiline && str[re.lastIndex - 1] !== '\n')) { 21173 source = '(?: ' + source + ')'; 21174 strCopy = ' ' + strCopy; 21175 charsAdded++; 21176 } // ^(? + rx + ) is needed, in combination with some str slicing, to 21177 // simulate the 'y' flag. 21178 21179 reCopy = new RegExp('^(?:' + source + ')', flags); 21180 } 21181 if (NPCG_INCLUDED) { 21182 reCopy = new RegExp('^' + source + '$(?!\\s)', flags); 21183 } 21184 if (UPDATES_LAST_INDEX_WRONG) lastIndex = re.lastIndex; 21185 match = nativeExec.call(sticky ? reCopy : re, strCopy); 21186 if (sticky) { 21187 if (match) { 21188 match.input = match.input.slice(charsAdded); 21189 match[0] = match[0].slice(charsAdded); 21190 match.index = re.lastIndex; 21191 re.lastIndex += match[0].length; 21192 } else re.lastIndex = 0; 21193 } else if (UPDATES_LAST_INDEX_WRONG && match) { 21194 re.lastIndex = re.global ? match.index + match[0].length : lastIndex; 21195 } 21196 if (NPCG_INCLUDED && match && match.length > 1) { 21197 // Fix browsers whose `exec` methods don't consistently return `undefined` 21198 // for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/ 21199 nativeReplace.call(match[0], reCopy, function () { 21200 for (i = 1; i < arguments.length - 2; i++) { 21201 if (arguments[i] === undefined) match[i] = undefined; 21202 } 21203 }); 21204 } 21205 return match; 21206 }; 21207 } 21208 module.exports = patchedExec; 21209 }, 21210 { 21211 './regexp-flags': 129, 21212 './regexp-sticky-helpers': 130 21213 } 21214 ], 21215 129: [
21216 function (_dereq_, module, exports) { 21217 'use strict'; 21218 var anObject = _dereq_('../internals/an-object'); // `RegExp.prototype.flags` getter implementation 21219 // https://tc39.github.io/ecma262/#sec-get-regexp.prototype.flags 21220 module.exports = function () { 21221 var that = anObject(this); 21222 var result = ''; 21223 if (that.global) result += 'g'; 21224 if (that.ignoreCase) result += 'i'; 21225 if (that.multiline) result += 'm'; 21226 if (that.dotAll) result += 's'; 21227 if (that.unicode) result += 'u'; 21228 if (that.sticky) result += 'y'; 21229 return result; 21230 }; 21231 }, 21232 { 21233 '../internals/an-object': 28 21234 } 21235 ], 21236 130: [ 21237 function (_dereq_, module, exports) { 21238 'use strict'; 21239 var fails = _dereq_('./fails'); // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError, 21240 // so we use an intermediate function. 21241 function RE(s, f) { 21242 return RegExp(s, f); 21243 } 21244 exports.UNSUPPORTED_Y = fails(function () { 21245 // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError 21246 var re = RE('a', 'y'); 21247 re.lastIndex = 2; 21248 return re.exec('abcd') != null; 21249 }); 21250 exports.BROKEN_CARET = fails(function () { 21251 // https://bugzilla.mozilla.org/show_bug.cgi?id=773687 21252 var re = RE('^r', 'gy'); 21253 re.lastIndex = 2; 21254 return re.exec('str') != null; 21255 }); 21256 }, 21257 { 21258 './fails': 69 21259 } 21260 ], 21261 131: [ 21262 function (_dereq_, module, exports) { 21263 // `RequireObjectCoercible` abstract operation 21264 // https://tc39.github.io/ecma262/#sec-requireobjectcoercible 21265 module.exports = function (it) { 21266 if (it == undefined) throw TypeError('Can\'t call method on ' + it); 21267 return it; 21268 }; 21269 }, 21270 { 21271 } 21272 ], 21273 132: [ 21274 function (_dereq_, module, exports) { 21275 // `SameValue` abstract operation 21276 // https://tc39.github.io/ecma262/#sec-samevalue 21277 module.exports = Object.is || function is(x, y) { 21278 // eslint-disable-next-line no-self-compare 21279 return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y; 21280 }; 21281 }, 21282 { 21283 } 21284 ], 21285 133: [ 21286 function (_dereq_, module, exports) { 21287 var global = _dereq_('../internals/global'); 21288 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 21289 module.exports = function (key, value) { 21290 try { 21291 createNonEnumerableProperty(global, key, value); 21292 } catch (error) { 21293 global[key] = value; 21294 } 21295 return value; 21296 }; 21297 }, 21298 { 21299 '../internals/create-non-enumerable-property': 56, 21300 '../internals/global': 77 21301 } 21302 ], 21303 134: [ 21304 function (_dereq_, module, exports) { 21305 'use strict'; 21306 var getBuiltIn = _dereq_('../internals/get-built-in'); 21307 var definePropertyModule = _dereq_('../internals/object-define-property'); 21308 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 21309 var DESCRIPTORS = _dereq_('../internals/descriptors'); 21310 var SPECIES = wellKnownSymbol('species'); 21311 module.exports = function (CONSTRUCTOR_NAME) { 21312 var Constructor = getBuiltIn(CONSTRUCTOR_NAME); 21313 var defineProperty = definePropertyModule.f; 21314 if (DESCRIPTORS && Constructor && !Constructor[SPECIES]) { 21315 defineProperty(Constructor, SPECIES, { 21316 configurable: true, 21317 get: function () { 21318 return this; 21319 } 21320 }); 21321 } 21322 }; 21323 }, 21324 { 21325 '../internals/descriptors': 61, 21326 '../internals/get-built-in': 74, 21327 '../internals/object-define-property': 110, 21328 '../internals/well-known-symbol': 164 21329 } 21330 ], 21331 135: [ 21332 function (_dereq_, module, exports) { 21333 var defineProperty = _dereq_('../internals/object-define-property').f; 21334 var has = _dereq_('../internals/has'); 21335 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 21336 var TO_STRING_TAG = wellKnownSymbol('toStringTag'); 21337 module.exports = function (it, TAG, STATIC) {
21338 if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) { 21339 defineProperty(it, TO_STRING_TAG, { 21340 configurable: true, 21341 value: TAG 21342 }); 21343 } 21344 }; 21345 }, 21346 { 21347 '../internals/has': 78, 21348 '../internals/object-define-property': 110, 21349 '../internals/well-known-symbol': 164 21350 } 21351 ], 21352 136: [ 21353 function (_dereq_, module, exports) { 21354 var shared = _dereq_('../internals/shared'); 21355 var uid = _dereq_('../internals/uid'); 21356 var keys = shared('keys'); 21357 module.exports = function (key) { 21358 return keys[key] || (keys[key] = uid(key)); 21359 }; 21360 }, 21361 { 21362 '../internals/shared': 138, 21363 '../internals/uid': 161 21364 } 21365 ], 21366 137: [ 21367 function (_dereq_, module, exports) { 21368 var global = _dereq_('../internals/global'); 21369 var setGlobal = _dereq_('../internals/set-global'); 21370 var SHARED = '__core-js_shared__'; 21371 var store = global[SHARED] || setGlobal(SHARED, { 21372 }); 21373 module.exports = store; 21374 }, 21375 { 21376 '../internals/global': 77, 21377 '../internals/set-global': 133 21378 } 21379 ], 21380 138: [ 21381 function (_dereq_, module, exports) { 21382 var IS_PURE = _dereq_('../internals/is-pure'); 21383 var store = _dereq_('../internals/shared-store'); 21384 (module.exports = function (key, value) { 21385 return store[key] || (store[key] = value !== undefined ? value : { 21386 }); 21387 }) ('versions', [ 21388 ]).push({ 21389 version: '3.6.5', 21390 mode: IS_PURE ? 'pure' : 'global', 21391 copyright: '© 2020 Denis Pushkarev (zloirock.ru)' 21392 }); 21393 }, 21394 { 21395 '../internals/is-pure': 93, 21396 '../internals/shared-store': 137 21397 } 21398 ], 21399 139: [ 21400 function (_dereq_, module, exports) { 21401 var anObject = _dereq_('../internals/an-object'); 21402 var aFunction = _dereq_('../internals/a-function'); 21403 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 21404 var SPECIES = wellKnownSymbol('species'); // `SpeciesConstructor` abstract operation 21405 // https://tc39.github.io/ecma262/#sec-speciesconstructor 21406 module.exports = function (O, defaultConstructor) { 21407 var C = anObject(O).constructor; 21408 var S; 21409 return C === undefined || (S = anObject(C) [SPECIES]) == undefined ? defaultConstructor : aFunction(S); 21410 }; 21411 }, 21412 { 21413 '../internals/a-function': 23, 21414 '../internals/an-object': 28, 21415 '../internals/well-known-symbol': 164 21416 } 21417 ], 21418 140: [ 21419 function (_dereq_, module, exports) { 21420 var fails = _dereq_('../internals/fails'); // check the existence of a method, lowercase 21421 // of a tag and escaping quotes in arguments 21422 module.exports = function (METHOD_NAME) { 21423 return fails(function () { 21424 var test = ''[METHOD_NAME]('"'); 21425 return test !== test.toLowerCase() || test.split('"').length > 3; 21426 }); 21427 }; 21428 }, 21429 { 21430 '../internals/fails': 69 21431 } 21432 ], 21433 141: [ 21434 function (_dereq_, module, exports) { 21435 var toInteger = _dereq_('../internals/to-integer'); 21436 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); // `String.prototype.{ codePointAt, at }` methods implementation 21437 var createMethod = function (CONVERT_TO_STRING) { 21438 return function ($this, pos) { 21439 var S = String(requireObjectCoercible($this)); 21440 var position = toInteger(pos); 21441 var size = S.length; 21442 var first, 21443 second; 21444 if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined; 21445 first = S.charCodeAt(position); 21446 return first < 55296 || first > 56319 || position + 1 === size || (second = S.charCodeAt(position + 1)) < 56320 || second > 57343 ? CONVERT_TO_STRING ? S.charAt(position) : first : CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 55296 << 10) + (second - 56320) + 65536; 21447 }; 21448 }; 21449 module.exports = { 21450 // `String.prototype.codePointAt` method 21451 // https://tc39.github.io/ecma262/#sec-string.prototype.codepointat 21452 codeAt: createMethod(false), 21453 // `String.prototype.at` method 21454 // https://github.com/mathiasbynens/String.prototype.at 21455 charAt: createMethod(true) 21456 }; 21457 }, 21458 { 21459 '../internals/require-object-coercible': 131, 21460 '../internals/to-integer': 151 21461 } 21462 ], 21463 142: [
vendor: 4,243 bytes, lines 21464-21565
21464 function (_dereq_, module, exports) { 21465 'use strict'; // based on https://github.com/bestiejs/punycode.js/blob/master/punycode.js 21466 var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1 21467 var base = 36; 21468 var tMin = 1; 21469 var tMax = 26; 21470 var skew = 38; 21471 var damp = 700; 21472 var initialBias = 72; 21473 var initialN = 128; // 0x80 21474 var delimiter = '-'; // '\x2D' 21475 var regexNonASCII = /[^\0-\u007E]/; // non-ASCII chars 21476 var regexSeparators = /[.\u3002\uFF0E\uFF61]/g; // RFC 3490 separators 21477 var OVERFLOW_ERROR = 'Overflow: input needs wider integers to process'; 21478 var baseMinusTMin = base - tMin; 21479 var floor = Math.floor; 21480 var stringFromCharCode = String.fromCharCode; 21481 /** 21482 * Creates an array containing the numeric code points of each Unicode 21483 * character in the string. While JavaScript uses UCS-2 internally, 21484 * this function will convert a pair of surrogate halves (each of which 21485 * UCS-2 exposes as separate characters) into a single code point, 21486 * matching UTF-16. 21487 */ 21488 var ucs2decode = function (string) { 21489 var output = [ 21490 ]; 21491 var counter = 0; 21492 var length = string.length; 21493 while (counter < length) { 21494 var value = string.charCodeAt(counter++); 21495 if (value >= 55296 && value <= 56319 && counter < length) { 21496 // It's a high surrogate, and there is a next character. 21497 var extra = string.charCodeAt(counter++); 21498 if ((extra & 64512) == 56320) { 21499 // Low surrogate. 21500 output.push(((value & 1023) << 10) + (extra & 1023) + 65536); 21501 } else { 21502 // It's an unmatched surrogate; only append this code unit, in case the 21503 // next code unit is the high surrogate of a surrogate pair. 21504 output.push(value); 21505 counter--; 21506 } 21507 } else { 21508 output.push(value); 21509 } 21510 } 21511 return output; 21512 }; 21513 /** 21514 * Converts a digit/integer into a basic code point. 21515 */ 21516 var digitToBasic = function (digit) { 21517 // 0..25 map to ASCII a..z or A..Z 21518 // 26..35 map to ASCII 0..9 21519 return digit + 22 + 75 * (digit < 26); 21520 }; 21521 /** 21522 * Bias adaptation function as per section 3.4 of RFC 3492. 21523 * https://tools.ietf.org/html/rfc3492#section-3.4 21524 */ 21525 var adapt = function (delta, numPoints, firstTime) { 21526 var k = 0; 21527 delta = firstTime ? floor(delta / damp) : delta >> 1; 21528 delta += floor(delta / numPoints); 21529 for (; delta > baseMinusTMin * tMax >> 1; k += base) { 21530 delta = floor(delta / baseMinusTMin); 21531 } 21532 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); 21533 }; 21534 /** 21535 * Converts a string of Unicode symbols (e.g. a domain name label) to a 21536 * Punycode string of ASCII-only symbols. 21537 */ 21538 // eslint-disable-next-line max-statements 21539 var encode = function (input) { 21540 var output = [ 21541 ]; // Convert the input in UCS-2 to an array of Unicode code points. 21542 input = ucs2decode(input); // Cache the length. 21543 var inputLength = input.length; // Initialize the state. 21544 var n = initialN; 21545 var delta = 0; 21546 var bias = initialBias; 21547 var i, 21548 currentValue; // Handle the basic code points. 21549 for (i = 0; i < input.length; i++) { 21550 currentValue = input[i]; 21551 if (currentValue < 128) { 21552 output.push(stringFromCharCode(currentValue)); 21553 } 21554 } 21555 var basicLength = output.length; // number of basic code points. 21556 var handledCPCount = basicLength; // number of code points that have been handled; 21557 // Finish the basic string with a delimiter unless it's empty. 21558 if (basicLength) { 21559 output.push(delimiter); 21560 } // Main encoding loop: 21561 21562 while (handledCPCount < inputLength) { 21563 // All non-basic code points < n have been handled already. Find the next larger one: 21564 var m = maxInt; 21565 for (i = 0; i < input.length; i++) {
21566 currentValue = input[i]; 21567 if (currentValue >= n && currentValue < m) { 21568 m = currentValue; 21569 } 21570 } // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>, but guard against overflow. 21571 21572 var handledCPCountPlusOne = handledCPCount + 1; 21573 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { 21574 throw RangeError(OVERFLOW_ERROR); 21575 } 21576 delta += (m - n) * handledCPCountPlusOne; 21577 n = m; 21578 for (i = 0; i < input.length; i++) { 21579 currentValue = input[i]; 21580 if (currentValue < n && ++delta > maxInt) { 21581 throw RangeError(OVERFLOW_ERROR); 21582 } 21583 if (currentValue == n) { 21584 // Represent delta as a generalized variable-length integer. 21585 var q = delta; 21586 for (var k = base; ; /* no condition */ 21587 k += base) { 21588 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; 21589 if (q < t) break; 21590 var qMinusT = q - t; 21591 var baseMinusT = base - t; 21592 output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT))); 21593 q = floor(qMinusT / baseMinusT); 21594 } 21595 output.push(stringFromCharCode(digitToBasic(q))); 21596 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); 21597 delta = 0; 21598 ++handledCPCount; 21599 } 21600 } 21601 ++delta; 21602 ++n; 21603 } 21604 return output.join(''); 21605 }; 21606 module.exports = function (input) { 21607 var encoded = [ 21608 ]; 21609 var labels = input.toLowerCase().replace(regexSeparators, '.').split('.'); 21610 var i, 21611 label; 21612 for (i = 0; i < labels.length; i++) { 21613 label = labels[i]; 21614 encoded.push(regexNonASCII.test(label) ? 'xn--' + encode(label) : label); 21615 } 21616 return encoded.join('.'); 21617 }; 21618 }, 21619 { 21620 } 21621 ], 21622 143: [ 21623 function (_dereq_, module, exports) { 21624 'use strict'; 21625 var toInteger = _dereq_('../internals/to-integer'); 21626 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); // `String.prototype.repeat` method implementation 21627 // https://tc39.github.io/ecma262/#sec-string.prototype.repeat 21628 module.exports = ''.repeat || function repeat(count) { 21629 var str = String(requireObjectCoercible(this)); 21630 var result = ''; 21631 var n = toInteger(count); 21632 if (n < 0 || n == Infinity) throw RangeError('Wrong number of repetitions'); 21633 for (; n > 0; (n >>>= 1) && (str += str)) if (n & 1) result += str; 21634 return result; 21635 }; 21636 }, 21637 { 21638 '../internals/require-object-coercible': 131, 21639 '../internals/to-integer': 151 21640 } 21641 ], 21642 144: [ 21643 function (_dereq_, module, exports) { 21644 var fails = _dereq_('../internals/fails');
vendor: 1,932 bytes, lines 21645-21687
21645 var whitespaces = _dereq_('../internals/whitespaces'); 21646 var non = 'â á '; // check that a method works with the correct list 21647 // of whitespaces and has a correct name 21648 module.exports = function (METHOD_NAME) { 21649 return fails(function () { 21650 return !!whitespaces[METHOD_NAME]() || non[METHOD_NAME]() != non || whitespaces[METHOD_NAME].name !== METHOD_NAME; 21651 }); 21652 }; 21653 }, 21654 { 21655 '../internals/fails': 69, 21656 '../internals/whitespaces': 165 21657 } 21658 ], 21659 145: [ 21660 function (_dereq_, module, exports) { 21661 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 21662 var whitespaces = _dereq_('../internals/whitespaces'); 21663 var whitespace = '[' + whitespaces + ']'; 21664 var ltrim = RegExp('^' + whitespace + whitespace + '*'); 21665 var rtrim = RegExp(whitespace + whitespace + '*$'); // `String.prototype.{ trim, trimStart, trimEnd, trimLeft, trimRight }` methods implementation 21666 var createMethod = function (TYPE) { 21667 return function ($this) { 21668 var string = String(requireObjectCoercible($this)); 21669 if (TYPE & 1) string = string.replace(ltrim, ''); 21670 if (TYPE & 2) string = string.replace(rtrim, ''); 21671 return string; 21672 }; 21673 }; 21674 module.exports = { 21675 // `String.prototype.{ trimLeft, trimStart }` methods 21676 // https://tc39.github.io/ecma262/#sec-string.prototype.trimstart 21677 start: createMethod(1), 21678 // `String.prototype.{ trimRight, trimEnd }` methods 21679 // https://tc39.github.io/ecma262/#sec-string.prototype.trimend 21680 end: createMethod(2), 21681 // `String.prototype.trim` method 21682 // https://tc39.github.io/ecma262/#sec-string.prototype.trim 21683 trim: createMethod(3) 21684 }; 21685 }, 21686 { 21687 '../internals/require-object-coercible': 131,
vendor: 4,109 bytes, lines 21688-21795
21688 '../internals/whitespaces': 165 21689 } 21690 ], 21691 146: [ 21692 function (_dereq_, module, exports) { 21693 var global = _dereq_('../internals/global'); 21694 var fails = _dereq_('../internals/fails'); 21695 var classof = _dereq_('../internals/classof-raw'); 21696 var bind = _dereq_('../internals/function-bind-context'); 21697 var html = _dereq_('../internals/html'); 21698 var createElement = _dereq_('../internals/document-create-element'); 21699 var IS_IOS = _dereq_('../internals/engine-is-ios'); 21700 var location = global.location; 21701 var set = global.setImmediate; 21702 var clear = global.clearImmediate; 21703 var process = global.process; 21704 var MessageChannel = global.MessageChannel; 21705 var Dispatch = global.Dispatch; 21706 var counter = 0; 21707 var queue = { 21708 }; 21709 var ONREADYSTATECHANGE = 'onreadystatechange'; 21710 var defer, 21711 channel, 21712 port; 21713 var run = function (id) { 21714 // eslint-disable-next-line no-prototype-builtins 21715 if (queue.hasOwnProperty(id)) { 21716 var fn = queue[id]; 21717 delete queue[id]; 21718 fn(); 21719 } 21720 }; 21721 var runner = function (id) { 21722 return function () { 21723 run(id); 21724 }; 21725 }; 21726 var listener = function (event) { 21727 run(event.data); 21728 }; 21729 var post = function (id) { 21730 // old engines have not location.origin 21731 global.postMessage(id + '', location.protocol + '//' + location.host); 21732 }; // Node.js 0.9+ & IE10+ has setImmediate, otherwise: 21733 if (!set || !clear) { 21734 set = function setImmediate(fn) { 21735 var args = [ 21736 ]; 21737 var i = 1; 21738 while (arguments.length > i) args.push(arguments[i++]); 21739 queue[++counter] = function () { 21740 // eslint-disable-next-line no-new-func 21741 (typeof fn == 'function' ? fn : Function(fn)).apply(undefined, args); 21742 }; 21743 defer(counter); 21744 return counter; 21745 }; 21746 clear = function clearImmediate(id) { 21747 delete queue[id]; 21748 }; // Node.js 0.8- 21749 if (classof(process) == 'process') { 21750 defer = function (id) { 21751 process.nextTick(runner(id)); 21752 }; // Sphere (JS game engine) Dispatch API 21753 } else if (Dispatch && Dispatch.now) { 21754 defer = function (id) { 21755 Dispatch.now(runner(id)); 21756 }; // Browsers with MessageChannel, includes WebWorkers 21757 // except iOS - https://github.com/zloirock/core-js/issues/624 21758 } else if (MessageChannel && !IS_IOS) { 21759 channel = new MessageChannel(); 21760 port = channel.port2; 21761 channel.port1.onmessage = listener; 21762 defer = bind(port.postMessage, port, 1); // Browsers with postMessage, skip WebWorkers 21763 // IE8 has postMessage, but it's sync & typeof its postMessage is 'object' 21764 } else if (global.addEventListener && typeof postMessage == 'function' && !global.importScripts && !fails(post) && location.protocol !== 'file:') { 21765 defer = post; 21766 global.addEventListener('message', listener, false); // IE8- 21767 } else if (ONREADYSTATECHANGE in createElement('script')) { 21768 defer = function (id) { 21769 html.appendChild(createElement('script')) [ONREADYSTATECHANGE] = function () { 21770 html.removeChild(this); 21771 run(id); 21772 }; 21773 }; // Rest old browsers 21774 } else { 21775 defer = function (id) { 21776 setTimeout(runner(id), 0); 21777 }; 21778 } 21779 } 21780 module.exports = { 21781 set: set, 21782 clear: clear 21783 }; 21784 }, 21785 { 21786 '../internals/classof-raw': 46, 21787 '../internals/document-create-element': 62, 21788 '../internals/engine-is-ios': 64, 21789 '../internals/fails': 69, 21790 '../internals/function-bind-context': 72, 21791 '../internals/global': 77, 21792 '../internals/html': 81 21793 } 21794 ], 21795 147: [
21796 function (_dereq_, module, exports) { 21797 var classof = _dereq_('../internals/classof-raw'); // `thisNumberValue` abstract operation 21798 // https://tc39.github.io/ecma262/#sec-thisnumbervalue 21799 module.exports = function (value) { 21800 if (typeof value != 'number' && classof(value) != 'Number') { 21801 throw TypeError('Incorrect invocation'); 21802 } 21803 return + value; 21804 }; 21805 }, 21806 { 21807 '../internals/classof-raw': 46 21808 } 21809 ], 21810 148: [ 21811 function (_dereq_, module, exports) { 21812 var toInteger = _dereq_('../internals/to-integer'); 21813 var max = Math.max; 21814 var min = Math.min; // Helper for a popular repeating case of the spec: 21815 // Let integer be ? ToInteger(index). 21816 // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). 21817 module.exports = function (index, length) { 21818 var integer = toInteger(index); 21819 return integer < 0 ? max(integer + length, 0) : min(integer, length); 21820 }; 21821 }, 21822 { 21823 '../internals/to-integer': 151 21824 } 21825 ], 21826 149: [ 21827 function (_dereq_, module, exports) { 21828 var toInteger = _dereq_('../internals/to-integer'); 21829 var toLength = _dereq_('../internals/to-length'); // `ToIndex` abstract operation 21830 // https://tc39.github.io/ecma262/#sec-toindex 21831 module.exports = function (it) { 21832 if (it === undefined) return 0; 21833 var number = toInteger(it); 21834 var length = toLength(number); 21835 if (number !== length) throw RangeError('Wrong length or index'); 21836 return length; 21837 }; 21838 }, 21839 { 21840 '../internals/to-integer': 151, 21841 '../internals/to-length': 152 21842 } 21843 ], 21844 150: [ 21845 function (_dereq_, module, exports) { 21846 // toObject with fallback for non-array-like ES3 strings 21847 var IndexedObject = _dereq_('../internals/indexed-object'); 21848 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 21849 module.exports = function (it) { 21850 return IndexedObject(requireObjectCoercible(it)); 21851 }; 21852 }, 21853 { 21854 '../internals/indexed-object': 84, 21855 '../internals/require-object-coercible': 131 21856 } 21857 ], 21858 151: [ 21859 function (_dereq_, module, exports) { 21860 var ceil = Math.ceil; 21861 var floor = Math.floor; // `ToInteger` abstract operation 21862 // https://tc39.github.io/ecma262/#sec-tointeger 21863 module.exports = function (argument) { 21864 return isNaN(argument = + argument) ? 0 : (argument > 0 ? floor : ceil) (argument); 21865 }; 21866 }, 21867 { 21868 } 21869 ], 21870 152: [ 21871 function (_dereq_, module, exports) { 21872 var toInteger = _dereq_('../internals/to-integer'); 21873 var min = Math.min; // `ToLength` abstract operation 21874 // https://tc39.github.io/ecma262/#sec-tolength 21875 module.exports = function (argument) { 21876 return argument > 0 ? min(toInteger(argument), 9007199254740991) : 0; // 2 ** 53 - 1 == 9007199254740991 21877 }; 21878 }, 21879 { 21880 '../internals/to-integer': 151 21881 } 21882 ], 21883 153: [ 21884 function (_dereq_, module, exports) { 21885 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); // `ToObject` abstract operation 21886 // https://tc39.github.io/ecma262/#sec-toobject 21887 module.exports = function (argument) { 21888 return Object(requireObjectCoercible(argument)); 21889 }; 21890 }, 21891 { 21892 '../internals/require-object-coercible': 131 21893 } 21894 ], 21895 154: [ 21896 function (_dereq_, module, exports) { 21897 var toPositiveInteger = _dereq_('../internals/to-positive-integer'); 21898 module.exports = function (it, BYTES) { 21899 var offset = toPositiveInteger(it); 21900 if (offset % BYTES) throw RangeError('Wrong offset'); 21901 return offset; 21902 }; 21903 }, 21904 { 21905 '../internals/to-positive-integer': 155 21906 } 21907 ], 21908 155: [ 21909 function (_dereq_, module, exports) { 21910 var toInteger = _dereq_('../internals/to-integer'); 21911 module.exports = function (it) { 21912 var result = toInteger(it); 21913 if (result < 0) throw RangeError('The argument can\'t be less than 0'); 21914 return result; 21915 }; 21916 }, 21917 { 21918 '../internals/to-integer': 151 21919 } 21920 ], 21921 156: [
vendor: 11,187 bytes, lines 21922-22129
21922 function (_dereq_, module, exports) { 21923 var isObject = _dereq_('../internals/is-object'); // `ToPrimitive` abstract operation 21924 // https://tc39.github.io/ecma262/#sec-toprimitive 21925 // instead of the ES6 spec version, we didn't implement @@toPrimitive case 21926 // and the second argument - flag - preferred type is a string 21927 module.exports = function (input, PREFERRED_STRING) { 21928 if (!isObject(input)) return input; 21929 var fn, 21930 val; 21931 if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val; 21932 if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val; 21933 if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val; 21934 throw TypeError('Can\'t convert object to primitive value'); 21935 }; 21936 }, 21937 { 21938 '../internals/is-object': 92 21939 } 21940 ], 21941 157: [ 21942 function (_dereq_, module, exports) { 21943 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 21944 var TO_STRING_TAG = wellKnownSymbol('toStringTag'); 21945 var test = { 21946 }; 21947 test[TO_STRING_TAG] = 'z'; 21948 module.exports = String(test) === '[object z]'; 21949 }, 21950 { 21951 '../internals/well-known-symbol': 164 21952 } 21953 ], 21954 158: [ 21955 function (_dereq_, module, exports) { 21956 'use strict'; 21957 var $ = _dereq_('../internals/export'); 21958 var global = _dereq_('../internals/global'); 21959 var DESCRIPTORS = _dereq_('../internals/descriptors'); 21960 var TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS = _dereq_('../internals/typed-array-constructors-require-wrappers'); 21961 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 21962 var ArrayBufferModule = _dereq_('../internals/array-buffer'); 21963 var anInstance = _dereq_('../internals/an-instance'); 21964 var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor'); 21965 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 21966 var toLength = _dereq_('../internals/to-length'); 21967 var toIndex = _dereq_('../internals/to-index'); 21968 var toOffset = _dereq_('../internals/to-offset'); 21969 var toPrimitive = _dereq_('../internals/to-primitive'); 21970 var has = _dereq_('../internals/has'); 21971 var classof = _dereq_('../internals/classof'); 21972 var isObject = _dereq_('../internals/is-object'); 21973 var create = _dereq_('../internals/object-create'); 21974 var setPrototypeOf = _dereq_('../internals/object-set-prototype-of'); 21975 var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f; 21976 var typedArrayFrom = _dereq_('../internals/typed-array-from'); 21977 var forEach = _dereq_('../internals/array-iteration').forEach; 21978 var setSpecies = _dereq_('../internals/set-species'); 21979 var definePropertyModule = _dereq_('../internals/object-define-property'); 21980 var getOwnPropertyDescriptorModule = _dereq_('../internals/object-get-own-property-descriptor'); 21981 var InternalStateModule = _dereq_('../internals/internal-state'); 21982 var inheritIfRequired = _dereq_('../internals/inherit-if-required'); 21983 var getInternalState = InternalStateModule.get; 21984 var setInternalState = InternalStateModule.set; 21985 var nativeDefineProperty = definePropertyModule.f; 21986 var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; 21987 var round = Math.round; 21988 var RangeError = global.RangeError; 21989 var ArrayBuffer = ArrayBufferModule.ArrayBuffer; 21990 var DataView = ArrayBufferModule.DataView; 21991 var NATIVE_ARRAY_BUFFER_VIEWS = ArrayBufferViewCore.NATIVE_ARRAY_BUFFER_VIEWS; 21992 var TYPED_ARRAY_TAG = ArrayBufferViewCore.TYPED_ARRAY_TAG; 21993 var TypedArray = ArrayBufferViewCore.TypedArray; 21994 var TypedArrayPrototype = ArrayBufferViewCore.TypedArrayPrototype; 21995 var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; 21996 var isTypedArray = ArrayBufferViewCore.isTypedArray; 21997 var BYTES_PER_ELEMENT = 'BYTES_PER_ELEMENT'; 21998 var WRONG_LENGTH = 'Wrong length'; 21999 var fromList = function (C, list) { 22000 var index = 0; 22001 var length = list.length; 22002 var result = new (aTypedArrayConstructor(C)) (length); 22003 while (length > index) result[index] = list[index++]; 22004 return result; 22005 }; 22006 var addGetter = function (it, key) { 22007 nativeDefineProperty(it, key, { 22008 get: function () { 22009 return getInternalState(this) [key]; 22010 } 22011 }); 22012 }; 22013 var isArrayBuffer = function (it) { 22014 var klass; 22015 return it instanceof ArrayBuffer || (klass = classof(it)) == 'ArrayBuffer' || klass == 'SharedArrayBuffer'; 22016 }; 22017 var isTypedArrayIndex = function (target, key) { 22018 return isTypedArray(target) && typeof key != 'symbol' && key in target && String( + key) == String(key); 22019 }; 22020 var wrappedGetOwnPropertyDescriptor = function getOwnPropertyDescriptor(target, key) { 22021 return isTypedArrayIndex(target, key = toPrimitive(key, true)) ? createPropertyDescriptor(2, target[key]) : nativeGetOwnPropertyDescriptor(target, key); 22022 }; 22023 var wrappedDefineProperty = function defineProperty(target, key, descriptor) { 22024 if (isTypedArrayIndex(target, key = toPrimitive(key, true)) && isObject(descriptor) && has(descriptor, 'value') && !has(descriptor, 'get') && !has(descriptor, 'set') // TODO: add validation descriptor w/o calling accessors 22025 && !descriptor.configurable && (!has(descriptor, 'writable') || descriptor.writable) && (!has(descriptor, 'enumerable') || descriptor.enumerable)) { 22026 target[key] = descriptor.value; 22027 return target; 22028 } 22029 return nativeDefineProperty(target, key, descriptor); 22030 }; 22031 if (DESCRIPTORS) { 22032 if (!NATIVE_ARRAY_BUFFER_VIEWS) { 22033 getOwnPropertyDescriptorModule.f = wrappedGetOwnPropertyDescriptor; 22034 definePropertyModule.f = wrappedDefineProperty; 22035 addGetter(TypedArrayPrototype, 'buffer'); 22036 addGetter(TypedArrayPrototype, 'byteOffset'); 22037 addGetter(TypedArrayPrototype, 'byteLength'); 22038 addGetter(TypedArrayPrototype, 'length'); 22039 } 22040 $({ 22041 target: 'Object', 22042 stat: true, 22043 forced: !NATIVE_ARRAY_BUFFER_VIEWS 22044 }, { 22045 getOwnPropertyDescriptor: wrappedGetOwnPropertyDescriptor, 22046 defineProperty: wrappedDefineProperty 22047 }); 22048 module.exports = function (TYPE, wrapper, CLAMPED) { 22049 var BYTES = TYPE.match(/\d+$/) [0] / 8; 22050 var CONSTRUCTOR_NAME = TYPE + (CLAMPED ? 'Clamped' : '') + 'Array'; 22051 var GETTER = 'get' + TYPE; 22052 var SETTER = 'set' + TYPE; 22053 var NativeTypedArrayConstructor = global[CONSTRUCTOR_NAME]; 22054 var TypedArrayConstructor = NativeTypedArrayConstructor; 22055 var TypedArrayConstructorPrototype = TypedArrayConstructor && TypedArrayConstructor.prototype; 22056 var exported = { 22057 }; 22058 var getter = function (that, index) { 22059 var data = getInternalState(that); 22060 return data.view[GETTER](index * BYTES + data.byteOffset, true); 22061 }; 22062 var setter = function (that, index, value) { 22063 var data = getInternalState(that); 22064 if (CLAMPED) value = (value = round(value)) < 0 ? 0 : value > 255 ? 255 : value & 255; 22065 data.view[SETTER](index * BYTES + data.byteOffset, value, true); 22066 }; 22067 var addElement = function (that, index) { 22068 nativeDefineProperty(that, index, { 22069 get: function () { 22070 return getter(this, index); 22071 }, 22072 set: function (value) { 22073 return setter(this, index, value); 22074 }, 22075 enumerable: true 22076 }); 22077 }; 22078 if (!NATIVE_ARRAY_BUFFER_VIEWS) { 22079 TypedArrayConstructor = wrapper(function (that, data, offset, $length) { 22080 anInstance(that, TypedArrayConstructor, CONSTRUCTOR_NAME); 22081 var index = 0; 22082 var byteOffset = 0; 22083 var buffer, 22084 byteLength, 22085 length; 22086 if (!isObject(data)) { 22087 length = toIndex(data); 22088 byteLength = length * BYTES; 22089 buffer = new ArrayBuffer(byteLength); 22090 } else if (isArrayBuffer(data)) { 22091 buffer = data; 22092 byteOffset = toOffset(offset, BYTES); 22093 var $len = data.byteLength; 22094 if ($length === undefined) { 22095 if ($len % BYTES) throw RangeError(WRONG_LENGTH); 22096 byteLength = $len - byteOffset; 22097 if (byteLength < 0) throw RangeError(WRONG_LENGTH); 22098 } else { 22099 byteLength = toLength($length) * BYTES; 22100 if (byteLength + byteOffset > $len) throw RangeError(WRONG_LENGTH); 22101 } 22102 length = byteLength / BYTES; 22103 } else if (isTypedArray(data)) { 22104 return fromList(TypedArrayConstructor, data); 22105 } else { 22106 return typedArrayFrom.call(TypedArrayConstructor, data); 22107 } 22108 setInternalState(that, { 22109 buffer: buffer, 22110 byteOffset: byteOffset, 22111 byteLength: byteLength, 22112 length: length, 22113 view: new DataView(buffer) 22114 }); 22115 while (index < length) addElement(that, index++); 22116 }); 22117 if (setPrototypeOf) setPrototypeOf(TypedArrayConstructor, TypedArray); 22118 TypedArrayConstructorPrototype = TypedArrayConstructor.prototype = create(TypedArrayPrototype); 22119 } else if (TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS) { 22120 TypedArrayConstructor = wrapper(function (dummy, data, typedArrayOffset, $length) { 22121 anInstance(dummy, TypedArrayConstructor, CONSTRUCTOR_NAME); 22122 return inheritIfRequired(function () { 22123 if (!isObject(data)) return new NativeTypedArrayConstructor(toIndex(data)); 22124 if (isArrayBuffer(data)) return $length !== undefined ? new NativeTypedArrayConstructor(data, toOffset(typedArrayOffset, BYTES), $length) : typedArrayOffset !== undefined ? new NativeTypedArrayConstructor(data, toOffset(typedArrayOffset, BYTES)) : new NativeTypedArrayConstructor(data); 22125 if (isTypedArray(data)) return fromList(TypedArrayConstructor, data); 22126 return typedArrayFrom.call(TypedArrayConstructor, data); 22127 }(), dummy, TypedArrayConstructor); 22128 }); 22129 if (setPrototypeOf) setPrototypeOf(TypedArrayConstructor, TypedArray);
vendor: 5,962 bytes, lines 22130-22270
22130 forEach(getOwnPropertyNames(NativeTypedArrayConstructor), function (key) { 22131 if (!(key in TypedArrayConstructor)) { 22132 createNonEnumerableProperty(TypedArrayConstructor, key, NativeTypedArrayConstructor[key]); 22133 } 22134 }); 22135 TypedArrayConstructor.prototype = TypedArrayConstructorPrototype; 22136 } 22137 if (TypedArrayConstructorPrototype.constructor !== TypedArrayConstructor) { 22138 createNonEnumerableProperty(TypedArrayConstructorPrototype, 'constructor', TypedArrayConstructor); 22139 } 22140 if (TYPED_ARRAY_TAG) { 22141 createNonEnumerableProperty(TypedArrayConstructorPrototype, TYPED_ARRAY_TAG, CONSTRUCTOR_NAME); 22142 } 22143 exported[CONSTRUCTOR_NAME] = TypedArrayConstructor; 22144 $({ 22145 global: true, 22146 forced: TypedArrayConstructor != NativeTypedArrayConstructor, 22147 sham: !NATIVE_ARRAY_BUFFER_VIEWS 22148 }, exported); 22149 if (!(BYTES_PER_ELEMENT in TypedArrayConstructor)) { 22150 createNonEnumerableProperty(TypedArrayConstructor, BYTES_PER_ELEMENT, BYTES); 22151 } 22152 if (!(BYTES_PER_ELEMENT in TypedArrayConstructorPrototype)) { 22153 createNonEnumerableProperty(TypedArrayConstructorPrototype, BYTES_PER_ELEMENT, BYTES); 22154 } 22155 setSpecies(CONSTRUCTOR_NAME); 22156 }; 22157 } else module.exports = function () { 22158 /* empty */ 22159 }; 22160 }, 22161 { 22162 '../internals/an-instance': 27, 22163 '../internals/array-buffer': 31, 22164 '../internals/array-buffer-view-core': 30, 22165 '../internals/array-iteration': 37, 22166 '../internals/classof': 47, 22167 '../internals/create-non-enumerable-property': 56, 22168 '../internals/create-property-descriptor': 57, 22169 '../internals/descriptors': 61, 22170 '../internals/export': 68, 22171 '../internals/global': 77, 22172 '../internals/has': 78, 22173 '../internals/inherit-if-required': 85, 22174 '../internals/internal-state': 88, 22175 '../internals/is-object': 92, 22176 '../internals/object-create': 108, 22177 '../internals/object-define-property': 110, 22178 '../internals/object-get-own-property-descriptor': 111, 22179 '../internals/object-get-own-property-names': 113, 22180 '../internals/object-set-prototype-of': 119, 22181 '../internals/set-species': 134, 22182 '../internals/to-index': 149, 22183 '../internals/to-length': 152, 22184 '../internals/to-offset': 154, 22185 '../internals/to-primitive': 156, 22186 '../internals/typed-array-constructors-require-wrappers': 159, 22187 '../internals/typed-array-from': 160 22188 } 22189 ], 22190 159: [ 22191 function (_dereq_, module, exports) { 22192 /* eslint-disable no-new */ 22193 var global = _dereq_('../internals/global'); 22194 var fails = _dereq_('../internals/fails'); 22195 var checkCorrectnessOfIteration = _dereq_('../internals/check-correctness-of-iteration'); 22196 var NATIVE_ARRAY_BUFFER_VIEWS = _dereq_('../internals/array-buffer-view-core').NATIVE_ARRAY_BUFFER_VIEWS; 22197 var ArrayBuffer = global.ArrayBuffer; 22198 var Int8Array = global.Int8Array; 22199 module.exports = !NATIVE_ARRAY_BUFFER_VIEWS || !fails(function () { 22200 Int8Array(1); 22201 }) || !fails(function () { 22202 new Int8Array( - 1); 22203 }) || !checkCorrectnessOfIteration(function (iterable) { 22204 new Int8Array(); 22205 new Int8Array(null); 22206 new Int8Array(1.5); 22207 new Int8Array(iterable); 22208 }, true) || fails(function () { 22209 // Safari (11+) bug - a reason why even Safari 13 should load a typed array polyfill 22210 return new Int8Array(new ArrayBuffer(2), 1, undefined).length !== 1; 22211 }); 22212 }, 22213 { 22214 '../internals/array-buffer-view-core': 30, 22215 '../internals/check-correctness-of-iteration': 45, 22216 '../internals/fails': 69, 22217 '../internals/global': 77 22218 } 22219 ], 22220 160: [ 22221 function (_dereq_, module, exports) { 22222 var toObject = _dereq_('../internals/to-object'); 22223 var toLength = _dereq_('../internals/to-length'); 22224 var getIteratorMethod = _dereq_('../internals/get-iterator-method'); 22225 var isArrayIteratorMethod = _dereq_('../internals/is-array-iterator-method'); 22226 var bind = _dereq_('../internals/function-bind-context'); 22227 var aTypedArrayConstructor = _dereq_('../internals/array-buffer-view-core').aTypedArrayConstructor; 22228 module.exports = function from(source /* , mapfn, thisArg */ 22229 ) { 22230 var O = toObject(source); 22231 var argumentsLength = arguments.length; 22232 var mapfn = argumentsLength > 1 ? arguments[1] : undefined; 22233 var mapping = mapfn !== undefined; 22234 var iteratorMethod = getIteratorMethod(O); 22235 var i, 22236 length, 22237 result, 22238 step, 22239 iterator, 22240 next; 22241 if (iteratorMethod != undefined && !isArrayIteratorMethod(iteratorMethod)) { 22242 iterator = iteratorMethod.call(O); 22243 next = iterator.next; 22244 O = [ 22245 ]; 22246 while (!(step = next.call(iterator)).done) { 22247 O.push(step.value); 22248 } 22249 } 22250 if (mapping && argumentsLength > 2) { 22251 mapfn = bind(mapfn, arguments[2], 2); 22252 } 22253 length = toLength(O.length); 22254 result = new (aTypedArrayConstructor(this)) (length); 22255 for (i = 0; length > i; i++) { 22256 result[i] = mapping ? mapfn(O[i], i) : O[i]; 22257 } 22258 return result; 22259 }; 22260 }, 22261 { 22262 '../internals/array-buffer-view-core': 30, 22263 '../internals/function-bind-context': 72, 22264 '../internals/get-iterator-method': 75, 22265 '../internals/is-array-iterator-method': 89, 22266 '../internals/to-length': 152, 22267 '../internals/to-object': 153 22268 } 22269 ], 22270 161: [
22271 function (_dereq_, module, exports) { 22272 var id = 0; 22273 var postfix = Math.random(); 22274 module.exports = function (key) { 22275 return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36); 22276 }; 22277 }, 22278 { 22279 } 22280 ], 22281 162: [ 22282 function (_dereq_, module, exports) { 22283 var NATIVE_SYMBOL = _dereq_('../internals/native-symbol'); 22284 module.exports = NATIVE_SYMBOL // eslint-disable-next-line no-undef 22285 && !Symbol.sham // eslint-disable-next-line no-undef 22286 && typeof Symbol.iterator == 'symbol'; 22287 }, 22288 { 22289 '../internals/native-symbol': 101 22290 } 22291 ], 22292 163: [ 22293 function (_dereq_, module, exports) { 22294 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 22295 exports.f = wellKnownSymbol; 22296 }, 22297 { 22298 '../internals/well-known-symbol': 164 22299 } 22300 ], 22301 164: [ 22302 function (_dereq_, module, exports) { 22303 var global = _dereq_('../internals/global'); 22304 var shared = _dereq_('../internals/shared'); 22305 var has = _dereq_('../internals/has'); 22306 var uid = _dereq_('../internals/uid'); 22307 var NATIVE_SYMBOL = _dereq_('../internals/native-symbol'); 22308 var USE_SYMBOL_AS_UID = _dereq_('../internals/use-symbol-as-uid'); 22309 var WellKnownSymbolsStore = shared('wks'); 22310 var Symbol = global.Symbol; 22311 var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol : Symbol && Symbol.withoutSetter || uid; 22312 module.exports = function (name) { 22313 if (!has(WellKnownSymbolsStore, name)) { 22314 if (NATIVE_SYMBOL && has(Symbol, name)) WellKnownSymbolsStore[name] = Symbol[name]; 22315 else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name); 22316 } 22317 return WellKnownSymbolsStore[name]; 22318 }; 22319 }, 22320 { 22321 '../internals/global': 77, 22322 '../internals/has': 78, 22323 '../internals/native-symbol': 101, 22324 '../internals/shared': 138, 22325 '../internals/uid': 161, 22326 '../internals/use-symbol-as-uid': 162 22327 } 22328 ], 22329 165: [ 22330 function (_dereq_, module, exports) { 22331 // a string of all valid unicode whitespaces 22332 // eslint-disable-next-line max-len 22333 module.exports = '\t\n\v\f\r  áââââââ ââââââ¯âã\u2028\u2029'; 22334 }, 22335 { 22336 } 22337 ], 22338 166: [ 22339 function (_dereq_, module, exports) { 22340 'use strict'; 22341 var $ = _dereq_('../internals/export'); 22342 var global = _dereq_('../internals/global'); 22343 var arrayBufferModule = _dereq_('../internals/array-buffer'); 22344 var setSpecies = _dereq_('../internals/set-species'); 22345 var ARRAY_BUFFER = 'ArrayBuffer'; 22346 var ArrayBuffer = arrayBufferModule[ARRAY_BUFFER]; 22347 var NativeArrayBuffer = global[ARRAY_BUFFER]; // `ArrayBuffer` constructor 22348 // https://tc39.github.io/ecma262/#sec-arraybuffer-constructor 22349 $({ 22350 global: true, 22351 forced: NativeArrayBuffer !== ArrayBuffer 22352 }, { 22353 ArrayBuffer: ArrayBuffer 22354 }); 22355 setSpecies(ARRAY_BUFFER); 22356 }, 22357 { 22358 '../internals/array-buffer': 31, 22359 '../internals/export': 68, 22360 '../internals/global': 77, 22361 '../internals/set-species': 134 22362 } 22363 ], 22364 167: [ 22365 function (_dereq_, module, exports) { 22366 'use strict'; 22367 var $ = _dereq_('../internals/export'); 22368 var fails = _dereq_('../internals/fails'); 22369 var isArray = _dereq_('../internals/is-array'); 22370 var isObject = _dereq_('../internals/is-object'); 22371 var toObject = _dereq_('../internals/to-object'); 22372 var toLength = _dereq_('../internals/to-length'); 22373 var createProperty = _dereq_('../internals/create-property'); 22374 var arraySpeciesCreate = _dereq_('../internals/array-species-create'); 22375 var arrayMethodHasSpeciesSupport = _dereq_('../internals/array-method-has-species-support'); 22376 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 22377 var V8_VERSION = _dereq_('../internals/engine-v8-version'); 22378 var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable'); 22379 var MAX_SAFE_INTEGER = 9007199254740991;
vendor: 4,449 bytes, lines 22380-22491
22380 var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded'; // We can't use this feature detection in V8 since it causes 22381 // deoptimization and serious performance degradation 22382 // https://github.com/zloirock/core-js/issues/679 22383 var IS_CONCAT_SPREADABLE_SUPPORT = V8_VERSION >= 51 || !fails(function () { 22384 var array = [ 22385 ]; 22386 array[IS_CONCAT_SPREADABLE] = false; 22387 return array.concat() [0] !== array; 22388 }); 22389 var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat'); 22390 var isConcatSpreadable = function (O) { 22391 if (!isObject(O)) return false; 22392 var spreadable = O[IS_CONCAT_SPREADABLE]; 22393 return spreadable !== undefined ? !!spreadable : isArray(O); 22394 }; 22395 var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT; // `Array.prototype.concat` method 22396 // https://tc39.github.io/ecma262/#sec-array.prototype.concat 22397 // with adding support of @@isConcatSpreadable and @@species 22398 $({ 22399 target: 'Array', 22400 proto: true, 22401 forced: FORCED 22402 }, { 22403 concat: function concat(arg) { 22404 // eslint-disable-line no-unused-vars 22405 var O = toObject(this); 22406 var A = arraySpeciesCreate(O, 0); 22407 var n = 0; 22408 var i, 22409 k, 22410 length, 22411 len, 22412 E; 22413 for (i = - 1, length = arguments.length; i < length; i++) { 22414 E = i === - 1 ? O : arguments[i]; 22415 if (isConcatSpreadable(E)) { 22416 len = toLength(E.length); 22417 if (n + len > MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); 22418 for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]); 22419 } else { 22420 if (n >= MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); 22421 createProperty(A, n++, E); 22422 } 22423 } 22424 A.length = n; 22425 return A; 22426 } 22427 }); 22428 }, 22429 { 22430 '../internals/array-method-has-species-support': 39, 22431 '../internals/array-species-create': 43, 22432 '../internals/create-property': 58, 22433 '../internals/engine-v8-version': 66, 22434 '../internals/export': 68, 22435 '../internals/fails': 69, 22436 '../internals/is-array': 90, 22437 '../internals/is-object': 92, 22438 '../internals/to-length': 152, 22439 '../internals/to-object': 153, 22440 '../internals/well-known-symbol': 164 22441 } 22442 ], 22443 168: [ 22444 function (_dereq_, module, exports) { 22445 var $ = _dereq_('../internals/export'); 22446 var copyWithin = _dereq_('../internals/array-copy-within'); 22447 var addToUnscopables = _dereq_('../internals/add-to-unscopables'); // `Array.prototype.copyWithin` method 22448 // https://tc39.github.io/ecma262/#sec-array.prototype.copywithin 22449 $({ 22450 target: 'Array', 22451 proto: true 22452 }, { 22453 copyWithin: copyWithin 22454 }); // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables 22455 addToUnscopables('copyWithin'); 22456 }, 22457 { 22458 '../internals/add-to-unscopables': 25, 22459 '../internals/array-copy-within': 32, 22460 '../internals/export': 68 22461 } 22462 ], 22463 169: [ 22464 function (_dereq_, module, exports) { 22465 'use strict'; 22466 var $ = _dereq_('../internals/export'); 22467 var $every = _dereq_('../internals/array-iteration').every; 22468 var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict'); 22469 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22470 var STRICT_METHOD = arrayMethodIsStrict('every'); 22471 var USES_TO_LENGTH = arrayMethodUsesToLength('every'); // `Array.prototype.every` method 22472 // https://tc39.github.io/ecma262/#sec-array.prototype.every 22473 $({ 22474 target: 'Array', 22475 proto: true, 22476 forced: !STRICT_METHOD || !USES_TO_LENGTH 22477 }, { 22478 every: function every(callbackfn /* , thisArg */ 22479 ) { 22480 return $every(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); 22481 } 22482 }); 22483 }, 22484 { 22485 '../internals/array-iteration': 37, 22486 '../internals/array-method-is-strict': 40, 22487 '../internals/array-method-uses-to-length': 41, 22488 '../internals/export': 68 22489 } 22490 ], 22491 170: [
22492 function (_dereq_, module, exports) { 22493 var $ = _dereq_('../internals/export'); 22494 var fill = _dereq_('../internals/array-fill'); 22495 var addToUnscopables = _dereq_('../internals/add-to-unscopables'); // `Array.prototype.fill` method 22496 // https://tc39.github.io/ecma262/#sec-array.prototype.fill 22497 $({ 22498 target: 'Array', 22499 proto: true 22500 }, { 22501 fill: fill 22502 }); // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables 22503 addToUnscopables('fill'); 22504 }, 22505 { 22506 '../internals/add-to-unscopables': 25, 22507 '../internals/array-fill': 33, 22508 '../internals/export': 68 22509 } 22510 ], 22511 171: [ 22512 function (_dereq_, module, exports) { 22513 'use strict'; 22514 var $ = _dereq_('../internals/export'); 22515 var $filter = _dereq_('../internals/array-iteration').filter; 22516 var arrayMethodHasSpeciesSupport = _dereq_('../internals/array-method-has-species-support'); 22517 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22518 var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter'); // Edge 14- issue 22519 var USES_TO_LENGTH = arrayMethodUsesToLength('filter'); // `Array.prototype.filter` method 22520 // https://tc39.github.io/ecma262/#sec-array.prototype.filter 22521 // with adding support of @@species 22522 $({ 22523 target: 'Array', 22524 proto: true, 22525 forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH 22526 }, { 22527 filter: function filter(callbackfn /* , thisArg */ 22528 ) { 22529 return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); 22530 } 22531 }); 22532 }, 22533 { 22534 '../internals/array-iteration': 37, 22535 '../internals/array-method-has-species-support': 39, 22536 '../internals/array-method-uses-to-length': 41, 22537 '../internals/export': 68 22538 } 22539 ], 22540 172: [ 22541 function (_dereq_, module, exports) { 22542 'use strict'; 22543 var $ = _dereq_('../internals/export'); 22544 var forEach = _dereq_('../internals/array-for-each'); // `Array.prototype.forEach` method 22545 // https://tc39.github.io/ecma262/#sec-array.prototype.foreach 22546 $({ 22547 target: 'Array', 22548 proto: true, 22549 forced: [ 22550 ].forEach != forEach 22551 }, { 22552 forEach: forEach 22553 }); 22554 }, 22555 { 22556 '../internals/array-for-each': 34, 22557 '../internals/export': 68 22558 } 22559 ], 22560 173: [ 22561 function (_dereq_, module, exports) { 22562 var $ = _dereq_('../internals/export'); 22563 var from = _dereq_('../internals/array-from'); 22564 var checkCorrectnessOfIteration = _dereq_('../internals/check-correctness-of-iteration'); 22565 var INCORRECT_ITERATION = !checkCorrectnessOfIteration(function (iterable) { 22566 Array.from(iterable); 22567 }); // `Array.from` method 22568 // https://tc39.github.io/ecma262/#sec-array.from 22569 $({ 22570 target: 'Array', 22571 stat: true, 22572 forced: INCORRECT_ITERATION 22573 }, { 22574 from: from 22575 }); 22576 }, 22577 { 22578 '../internals/array-from': 35, 22579 '../internals/check-correctness-of-iteration': 45, 22580 '../internals/export': 68 22581 } 22582 ], 22583 174: [ 22584 function (_dereq_, module, exports) { 22585 'use strict'; 22586 var $ = _dereq_('../internals/export'); 22587 var $includes = _dereq_('../internals/array-includes').includes; 22588 var addToUnscopables = _dereq_('../internals/add-to-unscopables'); 22589 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22590 var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { 22591 ACCESSORS: true, 22592 1: 0 22593 }); // `Array.prototype.includes` method 22594 // https://tc39.github.io/ecma262/#sec-array.prototype.includes 22595 $({ 22596 target: 'Array', 22597 proto: true, 22598 forced: !USES_TO_LENGTH 22599 }, { 22600 includes: function includes(el /* , fromIndex = 0 */ 22601 ) { 22602 return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined); 22603 } 22604 }); // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables 22605 addToUnscopables('includes'); 22606 }, 22607 {
vendor: 10,304 bytes, lines 22608-22857
22608 '../internals/add-to-unscopables': 25, 22609 '../internals/array-includes': 36, 22610 '../internals/array-method-uses-to-length': 41, 22611 '../internals/export': 68 22612 } 22613 ], 22614 175: [ 22615 function (_dereq_, module, exports) { 22616 'use strict'; 22617 var $ = _dereq_('../internals/export'); 22618 var $indexOf = _dereq_('../internals/array-includes').indexOf; 22619 var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict'); 22620 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22621 var nativeIndexOf = [ 22622 ].indexOf; 22623 var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [ 22624 1 22625 ].indexOf(1, - 0) < 0; 22626 var STRICT_METHOD = arrayMethodIsStrict('indexOf'); 22627 var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { 22628 ACCESSORS: true, 22629 1: 0 22630 }); // `Array.prototype.indexOf` method 22631 // https://tc39.github.io/ecma262/#sec-array.prototype.indexof 22632 $({ 22633 target: 'Array', 22634 proto: true, 22635 forced: NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH 22636 }, { 22637 indexOf: function indexOf(searchElement /* , fromIndex = 0 */ 22638 ) { 22639 return NEGATIVE_ZERO // convert -0 to +0 22640 ? nativeIndexOf.apply(this, arguments) || 0 : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined); 22641 } 22642 }); 22643 }, 22644 { 22645 '../internals/array-includes': 36, 22646 '../internals/array-method-is-strict': 40, 22647 '../internals/array-method-uses-to-length': 41, 22648 '../internals/export': 68 22649 } 22650 ], 22651 176: [ 22652 function (_dereq_, module, exports) { 22653 'use strict'; 22654 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 22655 var addToUnscopables = _dereq_('../internals/add-to-unscopables'); 22656 var Iterators = _dereq_('../internals/iterators'); 22657 var InternalStateModule = _dereq_('../internals/internal-state'); 22658 var defineIterator = _dereq_('../internals/define-iterator'); 22659 var ARRAY_ITERATOR = 'Array Iterator'; 22660 var setInternalState = InternalStateModule.set; 22661 var getInternalState = InternalStateModule.getterFor(ARRAY_ITERATOR); // `Array.prototype.entries` method 22662 // https://tc39.github.io/ecma262/#sec-array.prototype.entries 22663 // `Array.prototype.keys` method 22664 // https://tc39.github.io/ecma262/#sec-array.prototype.keys 22665 // `Array.prototype.values` method 22666 // https://tc39.github.io/ecma262/#sec-array.prototype.values 22667 // `Array.prototype[@@iterator]` method 22668 // https://tc39.github.io/ecma262/#sec-array.prototype-@@iterator 22669 // `CreateArrayIterator` internal method 22670 // https://tc39.github.io/ecma262/#sec-createarrayiterator 22671 module.exports = defineIterator(Array, 'Array', function (iterated, kind) { 22672 setInternalState(this, { 22673 type: ARRAY_ITERATOR, 22674 target: toIndexedObject(iterated), 22675 // target 22676 index: 0, 22677 // next index 22678 kind: kind // kind 22679 }); // `%ArrayIteratorPrototype%.next` method 22680 // https://tc39.github.io/ecma262/#sec-%arrayiteratorprototype%.next 22681 }, function () { 22682 var state = getInternalState(this); 22683 var target = state.target; 22684 var kind = state.kind; 22685 var index = state.index++; 22686 if (!target || index >= target.length) { 22687 state.target = undefined; 22688 return { 22689 value: undefined, 22690 done: true 22691 }; 22692 } 22693 if (kind == 'keys') return { 22694 value: index, 22695 done: false 22696 }; 22697 if (kind == 'values') return { 22698 value: target[index], 22699 done: false 22700 }; 22701 return { 22702 value: [ 22703 index, 22704 target[index] 22705 ], 22706 done: false 22707 }; 22708 }, 'values'); // argumentsList[@@iterator] is %ArrayProto_values% 22709 // https://tc39.github.io/ecma262/#sec-createunmappedargumentsobject 22710 // https://tc39.github.io/ecma262/#sec-createmappedargumentsobject 22711 Iterators.Arguments = Iterators.Array; // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables 22712 addToUnscopables('keys'); 22713 addToUnscopables('values'); 22714 addToUnscopables('entries'); 22715 }, 22716 { 22717 '../internals/add-to-unscopables': 25, 22718 '../internals/define-iterator': 59, 22719 '../internals/internal-state': 88, 22720 '../internals/iterators': 97, 22721 '../internals/to-indexed-object': 150 22722 } 22723 ], 22724 177: [ 22725 function (_dereq_, module, exports) { 22726 'use strict'; 22727 var $ = _dereq_('../internals/export'); 22728 var IndexedObject = _dereq_('../internals/indexed-object'); 22729 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 22730 var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict'); 22731 var nativeJoin = [ 22732 ].join; 22733 var ES3_STRINGS = IndexedObject != Object; 22734 var STRICT_METHOD = arrayMethodIsStrict('join', ','); // `Array.prototype.join` method 22735 // https://tc39.github.io/ecma262/#sec-array.prototype.join 22736 $({ 22737 target: 'Array', 22738 proto: true, 22739 forced: ES3_STRINGS || !STRICT_METHOD 22740 }, { 22741 join: function join(separator) { 22742 return nativeJoin.call(toIndexedObject(this), separator === undefined ? ',' : separator); 22743 } 22744 }); 22745 }, 22746 { 22747 '../internals/array-method-is-strict': 40, 22748 '../internals/export': 68, 22749 '../internals/indexed-object': 84, 22750 '../internals/to-indexed-object': 150 22751 } 22752 ], 22753 178: [ 22754 function (_dereq_, module, exports) { 22755 var $ = _dereq_('../internals/export'); 22756 var lastIndexOf = _dereq_('../internals/array-last-index-of'); // `Array.prototype.lastIndexOf` method 22757 // https://tc39.github.io/ecma262/#sec-array.prototype.lastindexof 22758 $({ 22759 target: 'Array', 22760 proto: true, 22761 forced: lastIndexOf !== [].lastIndexOf 22762 }, { 22763 lastIndexOf: lastIndexOf 22764 }); 22765 }, 22766 { 22767 '../internals/array-last-index-of': 38, 22768 '../internals/export': 68 22769 } 22770 ], 22771 179: [ 22772 function (_dereq_, module, exports) { 22773 'use strict'; 22774 var $ = _dereq_('../internals/export'); 22775 var $map = _dereq_('../internals/array-iteration').map; 22776 var arrayMethodHasSpeciesSupport = _dereq_('../internals/array-method-has-species-support'); 22777 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22778 var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('map'); // FF49- issue 22779 var USES_TO_LENGTH = arrayMethodUsesToLength('map'); // `Array.prototype.map` method 22780 // https://tc39.github.io/ecma262/#sec-array.prototype.map 22781 // with adding support of @@species 22782 $({ 22783 target: 'Array', 22784 proto: true, 22785 forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH 22786 }, { 22787 map: function map(callbackfn /* , thisArg */ 22788 ) { 22789 return $map(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); 22790 } 22791 }); 22792 }, 22793 { 22794 '../internals/array-iteration': 37, 22795 '../internals/array-method-has-species-support': 39, 22796 '../internals/array-method-uses-to-length': 41, 22797 '../internals/export': 68 22798 } 22799 ], 22800 180: [ 22801 function (_dereq_, module, exports) { 22802 'use strict'; 22803 var $ = _dereq_('../internals/export'); 22804 var isObject = _dereq_('../internals/is-object'); 22805 var isArray = _dereq_('../internals/is-array'); 22806 var toAbsoluteIndex = _dereq_('../internals/to-absolute-index'); 22807 var toLength = _dereq_('../internals/to-length'); 22808 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 22809 var createProperty = _dereq_('../internals/create-property'); 22810 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 22811 var arrayMethodHasSpeciesSupport = _dereq_('../internals/array-method-has-species-support'); 22812 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22813 var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('slice'); 22814 var USES_TO_LENGTH = arrayMethodUsesToLength('slice', { 22815 ACCESSORS: true, 22816 0: 0, 22817 1: 2 22818 }); 22819 var SPECIES = wellKnownSymbol('species'); 22820 var nativeSlice = [ 22821 ].slice; 22822 var max = Math.max; // `Array.prototype.slice` method 22823 // https://tc39.github.io/ecma262/#sec-array.prototype.slice 22824 // fallback for not array-like ES3 strings and DOM objects 22825 $({ 22826 target: 'Array', 22827 proto: true, 22828 forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH 22829 }, { 22830 slice: function slice(start, end) { 22831 var O = toIndexedObject(this); 22832 var length = toLength(O.length); 22833 var k = toAbsoluteIndex(start, length); 22834 var fin = toAbsoluteIndex(end === undefined ? length : end, length); // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible 22835 var Constructor, 22836 result, 22837 n; 22838 if (isArray(O)) { 22839 Constructor = O.constructor; // cross-realm fallback 22840 if (typeof Constructor == 'function' && (Constructor === Array || isArray(Constructor.prototype))) { 22841 Constructor = undefined; 22842 } else if (isObject(Constructor)) { 22843 Constructor = Constructor[SPECIES]; 22844 if (Constructor === null) Constructor = undefined; 22845 } 22846 if (Constructor === Array || Constructor === undefined) { 22847 return nativeSlice.call(O, k, fin); 22848 } 22849 } 22850 result = new (Constructor === undefined ? Array : Constructor) (max(fin - k, 0)); 22851 for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]); 22852 result.length = n; 22853 return result; 22854 } 22855 }); 22856 }, 22857 {
vendor: 4,583 bytes, lines 22858-22964
22858 '../internals/array-method-has-species-support': 39, 22859 '../internals/array-method-uses-to-length': 41, 22860 '../internals/create-property': 58, 22861 '../internals/export': 68, 22862 '../internals/is-array': 90, 22863 '../internals/is-object': 92, 22864 '../internals/to-absolute-index': 148, 22865 '../internals/to-indexed-object': 150, 22866 '../internals/to-length': 152, 22867 '../internals/well-known-symbol': 164 22868 } 22869 ], 22870 181: [ 22871 function (_dereq_, module, exports) { 22872 'use strict'; 22873 var $ = _dereq_('../internals/export'); 22874 var $some = _dereq_('../internals/array-iteration').some; 22875 var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict'); 22876 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22877 var STRICT_METHOD = arrayMethodIsStrict('some'); 22878 var USES_TO_LENGTH = arrayMethodUsesToLength('some'); // `Array.prototype.some` method 22879 // https://tc39.github.io/ecma262/#sec-array.prototype.some 22880 $({ 22881 target: 'Array', 22882 proto: true, 22883 forced: !STRICT_METHOD || !USES_TO_LENGTH 22884 }, { 22885 some: function some(callbackfn /* , thisArg */ 22886 ) { 22887 return $some(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); 22888 } 22889 }); 22890 }, 22891 { 22892 '../internals/array-iteration': 37, 22893 '../internals/array-method-is-strict': 40, 22894 '../internals/array-method-uses-to-length': 41, 22895 '../internals/export': 68 22896 } 22897 ], 22898 182: [ 22899 function (_dereq_, module, exports) { 22900 'use strict'; 22901 var $ = _dereq_('../internals/export'); 22902 var toAbsoluteIndex = _dereq_('../internals/to-absolute-index'); 22903 var toInteger = _dereq_('../internals/to-integer'); 22904 var toLength = _dereq_('../internals/to-length'); 22905 var toObject = _dereq_('../internals/to-object'); 22906 var arraySpeciesCreate = _dereq_('../internals/array-species-create'); 22907 var createProperty = _dereq_('../internals/create-property'); 22908 var arrayMethodHasSpeciesSupport = _dereq_('../internals/array-method-has-species-support'); 22909 var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length'); 22910 var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('splice'); 22911 var USES_TO_LENGTH = arrayMethodUsesToLength('splice', { 22912 ACCESSORS: true, 22913 0: 0, 22914 1: 2 22915 }); 22916 var max = Math.max; 22917 var min = Math.min; 22918 var MAX_SAFE_INTEGER = 9007199254740991; 22919 var MAXIMUM_ALLOWED_LENGTH_EXCEEDED = 'Maximum allowed length exceeded'; // `Array.prototype.splice` method 22920 // https://tc39.github.io/ecma262/#sec-array.prototype.splice 22921 // with adding support of @@species 22922 $({ 22923 target: 'Array', 22924 proto: true, 22925 forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH 22926 }, { 22927 splice: function splice(start, deleteCount /* , ...items */ 22928 ) { 22929 var O = toObject(this); 22930 var len = toLength(O.length); 22931 var actualStart = toAbsoluteIndex(start, len); 22932 var argumentsLength = arguments.length; 22933 var insertCount, 22934 actualDeleteCount, 22935 A, 22936 k, 22937 from, 22938 to; 22939 if (argumentsLength === 0) { 22940 insertCount = actualDeleteCount = 0; 22941 } else if (argumentsLength === 1) { 22942 insertCount = 0; 22943 actualDeleteCount = len - actualStart; 22944 } else { 22945 insertCount = argumentsLength - 2; 22946 actualDeleteCount = min(max(toInteger(deleteCount), 0), len - actualStart); 22947 } 22948 if (len + insertCount - actualDeleteCount > MAX_SAFE_INTEGER) { 22949 throw TypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED); 22950 } 22951 A = arraySpeciesCreate(O, actualDeleteCount); 22952 for (k = 0; k < actualDeleteCount; k++) { 22953 from = actualStart + k; 22954 if (from in O) createProperty(A, k, O[from]); 22955 } 22956 A.length = actualDeleteCount; 22957 if (insertCount < actualDeleteCount) { 22958 for (k = actualStart; k < len - actualDeleteCount; k++) { 22959 from = k + actualDeleteCount; 22960 to = k + insertCount; 22961 if (from in O) O[to] = O[from]; 22962 else delete O[to]; 22963 } 22964 for (k = len; k > len - actualDeleteCount + insertCount;
22964 k--) delete O[k - 1]; 22965 } else if (insertCount > actualDeleteCount) { 22966 for (k = len - actualDeleteCount; k > actualStart; k--) { 22967 from = k + actualDeleteCount - 1; 22968 to = k + insertCount - 1; 22969 if (from in O) O[to] = O[from]; 22970 else delete O[to]; 22971 } 22972 } 22973 for (k = 0; k < insertCount; k++) { 22974 O[k + actualStart] = arguments[k + 2]; 22975 } 22976 O.length = len - actualDeleteCount + insertCount; 22977 return A; 22978 } 22979 }); 22980 }, 22981 { 22982 '../internals/array-method-has-species-support': 39, 22983 '../internals/array-method-uses-to-length': 41, 22984 '../internals/array-species-create': 43, 22985 '../internals/create-property': 58, 22986 '../internals/export': 68, 22987 '../internals/to-absolute-index': 148, 22988 '../internals/to-integer': 151, 22989 '../internals/to-length': 152, 22990 '../internals/to-object': 153 22991 } 22992 ], 22993 183: [ 22994 function (_dereq_, module, exports) { 22995 var DESCRIPTORS = _dereq_('../internals/descriptors'); 22996 var defineProperty = _dereq_('../internals/object-define-property').f; 22997 var FunctionPrototype = Function.prototype; 22998 var FunctionPrototypeToString = FunctionPrototype.toString; 22999 var nameRE = /^\s*function ([^ (]*)/; 23000 var NAME = 'name'; // Function instances `.name` property 23001 // https://tc39.github.io/ecma262/#sec-function-instances-name 23002 if (DESCRIPTORS && !(NAME in FunctionPrototype)) { 23003 defineProperty(FunctionPrototype, NAME, { 23004 configurable: true, 23005 get: function () { 23006 try { 23007 return FunctionPrototypeToString.call(this).match(nameRE) [1]; 23008 } catch (error) { 23009 return ''; 23010 } 23011 } 23012 }); 23013 } 23014 }, 23015 { 23016 '../internals/descriptors': 61, 23017 '../internals/object-define-property': 110 23018 } 23019 ], 23020 184: [ 23021 function (_dereq_, module, exports) { 23022 'use strict'; 23023 var collection = _dereq_('../internals/collection'); 23024 var collectionStrong = _dereq_('../internals/collection-strong'); // `Map` constructor 23025 // https://tc39.github.io/ecma262/#sec-map-objects 23026 module.exports = collection('Map', function (init) { 23027 return function Map() { 23028 return init(this, arguments.length ? arguments[0] : undefined); 23029 }; 23030 }, collectionStrong); 23031 }, 23032 { 23033 '../internals/collection': 50, 23034 '../internals/collection-strong': 48 23035 } 23036 ], 23037 185: [ 23038 function (_dereq_, module, exports) { 23039 var $ = _dereq_('../internals/export'); 23040 var $hypot = Math.hypot; 23041 var abs = Math.abs; 23042 var sqrt = Math.sqrt; // Chrome 77 bug 23043 // https://bugs.chromium.org/p/v8/issues/detail?id=9546 23044 var BUGGY = !!$hypot && $hypot(Infinity, NaN) !== Infinity; // `Math.hypot` method 23045 // https://tc39.github.io/ecma262/#sec-math.hypot 23046 $({ 23047 target: 'Math', 23048 stat: true, 23049 forced: BUGGY 23050 }, { 23051 hypot: function hypot(value1, value2) { 23052 // eslint-disable-line no-unused-vars 23053 var sum = 0; 23054 var i = 0; 23055 var aLen = arguments.length; 23056 var larg = 0; 23057 var arg, 23058 div; 23059 while (i < aLen) { 23060 arg = abs(arguments[i++]); 23061 if (larg < arg) { 23062 div = larg / arg; 23063 sum = sum * div * div + 1; 23064 larg = arg; 23065 } else if (arg > 0) { 23066 div = arg / larg; 23067 sum += div * div; 23068 } else sum += arg; 23069 } 23070 return larg === Infinity ? Infinity : larg * sqrt(sum); 23071 } 23072 }); 23073 }, 23074 { 23075 '../internals/export': 68 23076 } 23077 ], 23078 186: [ 23079 function (_dereq_, module, exports) { 23080 var $ = _dereq_('../internals/export'); 23081 var sign = _dereq_('../internals/math-sign'); // `Math.sign` method 23082 // https://tc39.github.io/ecma262/#sec-math.sign 23083 $({ 23084 target: 'Math', 23085 stat: true 23086 }, { 23087 sign: sign 23088 }); 23089 }, 23090 { 23091 '../internals/export': 68, 23092 '../internals/math-sign': 98 23093 } 23094 ], 23095 187: [
vendor: 5,005 bytes, lines 23096-23201
23096 function (_dereq_, module, exports) { 23097 'use strict'; 23098 var DESCRIPTORS = _dereq_('../internals/descriptors'); 23099 var global = _dereq_('../internals/global'); 23100 var isForced = _dereq_('../internals/is-forced'); 23101 var redefine = _dereq_('../internals/redefine'); 23102 var has = _dereq_('../internals/has'); 23103 var classof = _dereq_('../internals/classof-raw'); 23104 var inheritIfRequired = _dereq_('../internals/inherit-if-required'); 23105 var toPrimitive = _dereq_('../internals/to-primitive'); 23106 var fails = _dereq_('../internals/fails'); 23107 var create = _dereq_('../internals/object-create'); 23108 var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f; 23109 var getOwnPropertyDescriptor = _dereq_('../internals/object-get-own-property-descriptor').f; 23110 var defineProperty = _dereq_('../internals/object-define-property').f; 23111 var trim = _dereq_('../internals/string-trim').trim; 23112 var NUMBER = 'Number'; 23113 var NativeNumber = global[NUMBER]; 23114 var NumberPrototype = NativeNumber.prototype; // Opera ~12 has broken Object#toString 23115 var BROKEN_CLASSOF = classof(create(NumberPrototype)) == NUMBER; // `ToNumber` abstract operation 23116 // https://tc39.github.io/ecma262/#sec-tonumber 23117 var toNumber = function (argument) { 23118 var it = toPrimitive(argument, false); 23119 var first, 23120 third, 23121 radix, 23122 maxCode, 23123 digits, 23124 length, 23125 index, 23126 code; 23127 if (typeof it == 'string' && it.length > 2) { 23128 it = trim(it); 23129 first = it.charCodeAt(0); 23130 if (first === 43 || first === 45) { 23131 third = it.charCodeAt(2); 23132 if (third === 88 || third === 120) return NaN; // Number('+0x1') should be NaN, old V8 fix 23133 } else if (first === 48) { 23134 switch (it.charCodeAt(1)) { 23135 case 66: 23136 case 98: 23137 radix = 2; 23138 maxCode = 49; 23139 break; 23140 // fast equal of /^0b[01]+$/i 23141 case 79: 23142 case 111: 23143 radix = 8; 23144 maxCode = 55; 23145 break; 23146 // fast equal of /^0o[0-7]+$/i 23147 default: 23148 return + it; 23149 } 23150 digits = it.slice(2); 23151 length = digits.length; 23152 for (index = 0; index < length; index++) { 23153 code = digits.charCodeAt(index); // parseInt parses a string to a first unavailable symbol 23154 // but ToNumber should return NaN if a string contains unavailable symbols 23155 if (code < 48 || code > maxCode) return NaN; 23156 } 23157 return parseInt(digits, radix); 23158 } 23159 } 23160 return + it; 23161 }; // `Number` constructor 23162 // https://tc39.github.io/ecma262/#sec-number-constructor 23163 if (isForced(NUMBER, !NativeNumber(' 0o1') || !NativeNumber('0b1') || NativeNumber('+0x1'))) { 23164 var NumberWrapper = function Number(value) { 23165 var it = arguments.length < 1 ? 0 : value; 23166 var dummy = this; 23167 return dummy instanceof NumberWrapper // check on 1..constructor(foo) case 23168 && (BROKEN_CLASSOF ? fails(function () { 23169 NumberPrototype.valueOf.call(dummy); 23170 }) : classof(dummy) != NUMBER) ? inheritIfRequired(new NativeNumber(toNumber(it)), dummy, NumberWrapper) : toNumber(it); 23171 }; 23172 for (var keys = DESCRIPTORS ? getOwnPropertyNames(NativeNumber) : ( // ES3: 23173 'MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,' + // ES2015 (in case, if modules with ES2015 Number statics required before): 23174 'EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,' + 'MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger').split(','), j = 0, key; keys.length > j; j++) { 23175 if (has(NativeNumber, key = keys[j]) && !has(NumberWrapper, key)) { 23176 defineProperty(NumberWrapper, key, getOwnPropertyDescriptor(NativeNumber, key)); 23177 } 23178 } 23179 NumberWrapper.prototype = NumberPrototype; 23180 NumberPrototype.constructor = NumberWrapper; 23181 redefine(global, NUMBER, NumberWrapper); 23182 } 23183 }, 23184 { 23185 '../internals/classof-raw': 46, 23186 '../internals/descriptors': 61, 23187 '../internals/fails': 69, 23188 '../internals/global': 77, 23189 '../internals/has': 78, 23190 '../internals/inherit-if-required': 85, 23191 '../internals/is-forced': 91, 23192 '../internals/object-create': 108, 23193 '../internals/object-define-property': 110, 23194 '../internals/object-get-own-property-descriptor': 111, 23195 '../internals/object-get-own-property-names': 113, 23196 '../internals/redefine': 126, 23197 '../internals/string-trim': 145, 23198 '../internals/to-primitive': 156 23199 } 23200 ], 23201 188: [
vendor: 4,122 bytes, lines 23202-23320
23202 function (_dereq_, module, exports) { 23203 var $ = _dereq_('../internals/export'); 23204 var numberIsFinite = _dereq_('../internals/number-is-finite'); // `Number.isFinite` method 23205 // https://tc39.github.io/ecma262/#sec-number.isfinite 23206 $({ 23207 target: 'Number', 23208 stat: true 23209 }, { 23210 isFinite: numberIsFinite 23211 }); 23212 }, 23213 { 23214 '../internals/export': 68, 23215 '../internals/number-is-finite': 106 23216 } 23217 ], 23218 189: [ 23219 function (_dereq_, module, exports) { 23220 'use strict'; 23221 var $ = _dereq_('../internals/export'); 23222 var toInteger = _dereq_('../internals/to-integer'); 23223 var thisNumberValue = _dereq_('../internals/this-number-value'); 23224 var repeat = _dereq_('../internals/string-repeat'); 23225 var fails = _dereq_('../internals/fails'); 23226 var nativeToFixed = 1 .toFixed; 23227 var floor = Math.floor; 23228 var pow = function (x, n, acc) { 23229 return n === 0 ? acc : n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc); 23230 }; 23231 var log = function (x) { 23232 var n = 0; 23233 var x2 = x; 23234 while (x2 >= 4096) { 23235 n += 12; 23236 x2 /= 4096; 23237 } 23238 while (x2 >= 2) { 23239 n += 1; 23240 x2 /= 2; 23241 } 23242 return n; 23243 }; 23244 var FORCED = nativeToFixed && (0.00008 .toFixed(3) !== '0.000' || 0.9 .toFixed(0) !== '1' || 1.255 .toFixed(2) !== '1.25' || 1000000000000000100 .toFixed(0) !== '1000000000000000128') || !fails(function () { 23245 // V8 ~ Android 4.3- 23246 nativeToFixed.call({ 23247 }); 23248 }); // `Number.prototype.toFixed` method 23249 // https://tc39.github.io/ecma262/#sec-number.prototype.tofixed 23250 $({ 23251 target: 'Number', 23252 proto: true, 23253 forced: FORCED 23254 }, { 23255 // eslint-disable-next-line max-statements 23256 toFixed: function toFixed(fractionDigits) { 23257 var number = thisNumberValue(this); 23258 var fractDigits = toInteger(fractionDigits); 23259 var data = [ 23260 0, 23261 0, 23262 0, 23263 0, 23264 0, 23265 0 23266 ]; 23267 var sign = ''; 23268 var result = '0'; 23269 var e, 23270 z, 23271 j, 23272 k; 23273 var multiply = function (n, c) { 23274 var index = - 1; 23275 var c2 = c; 23276 while (++index < 6) { 23277 c2 += n * data[index]; 23278 data[index] = c2 % 10000000; 23279 c2 = floor(c2 / 10000000); 23280 } 23281 }; 23282 var divide = function (n) { 23283 var index = 6; 23284 var c = 0; 23285 while (--index >= 0) { 23286 c += data[index]; 23287 data[index] = floor(c / n); 23288 c = c % n * 10000000; 23289 } 23290 }; 23291 var dataToString = function () { 23292 var index = 6; 23293 var s = ''; 23294 while (--index >= 0) { 23295 if (s !== '' || index === 0 || data[index] !== 0) { 23296 var t = String(data[index]); 23297 s = s === '' ? t : s + repeat.call('0', 7 - t.length) + t; 23298 } 23299 } 23300 return s; 23301 }; 23302 if (fractDigits < 0 || fractDigits > 20) throw RangeError('Incorrect fraction digits'); // eslint-disable-next-line no-self-compare 23303 if (number != number) return 'NaN'; 23304 if (number <= - 1e+21 || number >= 1e+21) return String(number); 23305 if (number < 0) { 23306 sign = '-'; 23307 number = - number; 23308 } 23309 if (number > 1e-21) { 23310 e = log(number * pow(2, 69, 1)) - 69; 23311 z = e < 0 ? number * pow(2, - e, 1) : number / pow(2, e, 1); 23312 z *= 4503599627370496; 23313 e = 52 - e; 23314 if (e > 0) { 23315 multiply(0, z); 23316 j = fractDigits; 23317 while (j >= 7) { 23318 multiply(10000000, 0); 23319 j -= 7; 23320 }
23321 multiply(pow(10, j, 1), 0); 23322 j = e - 1; 23323 while (j >= 23) { 23324 divide(1 << 23); 23325 j -= 23; 23326 } 23327 divide(1 << j); 23328 multiply(1, 1); 23329 divide(2); 23330 result = dataToString(); 23331 } else { 23332 multiply(0, z); 23333 multiply(1 << - e, 0); 23334 result = dataToString() + repeat.call('0', fractDigits); 23335 } 23336 } 23337 if (fractDigits > 0) { 23338 k = result.length; 23339 result = sign + (k <= fractDigits ? '0.' + repeat.call('0', fractDigits - k) + result : result.slice(0, k - fractDigits) + '.' + result.slice(k - fractDigits)); 23340 } else { 23341 result = sign + result; 23342 } 23343 return result; 23344 } 23345 }); 23346 }, 23347 { 23348 '../internals/export': 68, 23349 '../internals/fails': 69, 23350 '../internals/string-repeat': 143, 23351 '../internals/this-number-value': 147, 23352 '../internals/to-integer': 151 23353 } 23354 ], 23355 190: [ 23356 function (_dereq_, module, exports) { 23357 var $ = _dereq_('../internals/export'); 23358 var assign = _dereq_('../internals/object-assign'); // `Object.assign` method 23359 // https://tc39.github.io/ecma262/#sec-object.assign 23360 $({ 23361 target: 'Object', 23362 stat: true, 23363 forced: Object.assign !== assign 23364 }, { 23365 assign: assign 23366 }); 23367 }, 23368 { 23369 '../internals/export': 68, 23370 '../internals/object-assign': 107 23371 } 23372 ], 23373 191: [ 23374 function (_dereq_, module, exports) { 23375 var $ = _dereq_('../internals/export'); 23376 var fails = _dereq_('../internals/fails'); 23377 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 23378 var nativeGetOwnPropertyDescriptor = _dereq_('../internals/object-get-own-property-descriptor').f; 23379 var DESCRIPTORS = _dereq_('../internals/descriptors'); 23380 var FAILS_ON_PRIMITIVES = fails(function () { 23381 nativeGetOwnPropertyDescriptor(1); 23382 }); 23383 var FORCED = !DESCRIPTORS || FAILS_ON_PRIMITIVES; // `Object.getOwnPropertyDescriptor` method 23384 // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor 23385 $({ 23386 target: 'Object', 23387 stat: true, 23388 forced: FORCED, 23389 sham: !DESCRIPTORS 23390 }, { 23391 getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) { 23392 return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key); 23393 } 23394 }); 23395 }, 23396 { 23397 '../internals/descriptors': 61, 23398 '../internals/export': 68, 23399 '../internals/fails': 69, 23400 '../internals/object-get-own-property-descriptor': 111, 23401 '../internals/to-indexed-object': 150 23402 } 23403 ], 23404 192: [ 23405 function (_dereq_, module, exports) { 23406 var $ = _dereq_('../internals/export'); 23407 var fails = _dereq_('../internals/fails'); 23408 var nativeGetOwnPropertyNames = _dereq_('../internals/object-get-own-property-names-external').f; 23409 var FAILS_ON_PRIMITIVES = fails(function () { 23410 return !Object.getOwnPropertyNames(1); 23411 }); // `Object.getOwnPropertyNames` method 23412 // https://tc39.github.io/ecma262/#sec-object.getownpropertynames 23413 $({ 23414 target: 'Object', 23415 stat: true, 23416 forced: FAILS_ON_PRIMITIVES 23417 }, { 23418 getOwnPropertyNames: nativeGetOwnPropertyNames 23419 }); 23420 }, 23421 { 23422 '../internals/export': 68, 23423 '../internals/fails': 69, 23424 '../internals/object-get-own-property-names-external': 112 23425 } 23426 ], 23427 193: [ 23428 function (_dereq_, module, exports) { 23429 var $ = _dereq_('../internals/export'); 23430 var fails = _dereq_('../internals/fails'); 23431 var toObject = _dereq_('../internals/to-object'); 23432 var nativeGetPrototypeOf = _dereq_('../internals/object-get-prototype-of'); 23433 var CORRECT_PROTOTYPE_GETTER = _dereq_('../internals/correct-prototype-getter'); 23434 var FAILS_ON_PRIMITIVES = fails(function () { 23435 nativeGetPrototypeOf(1); 23436 }); // `Object.getPrototypeOf` method 23437 // https://tc39.github.io/ecma262/#sec-object.getprototypeof 23438 $({ 23439 target: 'Object', 23440 stat: true, 23441 forced: FAILS_ON_PRIMITIVES, 23442 sham: !CORRECT_PROTOTYPE_GETTER 23443 }, { 23444 getPrototypeOf: function getPrototypeOf(it) { 23445 return nativeGetPrototypeOf(toObject(it)); 23446 } 23447 }); 23448 }, 23449 { 23450 '../internals/correct-prototype-getter': 53, 23451 '../internals/export': 68, 23452 '../internals/fails': 69, 23453 '../internals/object-get-prototype-of': 115, 23454 '../internals/to-object': 153 23455 } 23456 ], 23457 194: [
vendor: 6,460 bytes, lines 23458-23593
23458 function (_dereq_, module, exports) { 23459 var $ = _dereq_('../internals/export'); 23460 var toObject = _dereq_('../internals/to-object'); 23461 var nativeKeys = _dereq_('../internals/object-keys'); 23462 var fails = _dereq_('../internals/fails'); 23463 var FAILS_ON_PRIMITIVES = fails(function () { 23464 nativeKeys(1); 23465 }); // `Object.keys` method 23466 // https://tc39.github.io/ecma262/#sec-object.keys 23467 $({ 23468 target: 'Object', 23469 stat: true, 23470 forced: FAILS_ON_PRIMITIVES 23471 }, { 23472 keys: function keys(it) { 23473 return nativeKeys(toObject(it)); 23474 } 23475 }); 23476 }, 23477 { 23478 '../internals/export': 68, 23479 '../internals/fails': 69, 23480 '../internals/object-keys': 117, 23481 '../internals/to-object': 153 23482 } 23483 ], 23484 195: [ 23485 function (_dereq_, module, exports) { 23486 var TO_STRING_TAG_SUPPORT = _dereq_('../internals/to-string-tag-support'); 23487 var redefine = _dereq_('../internals/redefine'); 23488 var toString = _dereq_('../internals/object-to-string'); // `Object.prototype.toString` method 23489 // https://tc39.github.io/ecma262/#sec-object.prototype.tostring 23490 if (!TO_STRING_TAG_SUPPORT) { 23491 redefine(Object.prototype, 'toString', toString, { 23492 unsafe: true 23493 }); 23494 } 23495 }, 23496 { 23497 '../internals/object-to-string': 120, 23498 '../internals/redefine': 126, 23499 '../internals/to-string-tag-support': 157 23500 } 23501 ], 23502 196: [ 23503 function (_dereq_, module, exports) { 23504 'use strict'; 23505 var $ = _dereq_('../internals/export'); 23506 var IS_PURE = _dereq_('../internals/is-pure'); 23507 var global = _dereq_('../internals/global'); 23508 var getBuiltIn = _dereq_('../internals/get-built-in'); 23509 var NativePromise = _dereq_('../internals/native-promise-constructor'); 23510 var redefine = _dereq_('../internals/redefine'); 23511 var redefineAll = _dereq_('../internals/redefine-all'); 23512 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 23513 var setSpecies = _dereq_('../internals/set-species'); 23514 var isObject = _dereq_('../internals/is-object'); 23515 var aFunction = _dereq_('../internals/a-function'); 23516 var anInstance = _dereq_('../internals/an-instance'); 23517 var classof = _dereq_('../internals/classof-raw'); 23518 var inspectSource = _dereq_('../internals/inspect-source'); 23519 var iterate = _dereq_('../internals/iterate'); 23520 var checkCorrectnessOfIteration = _dereq_('../internals/check-correctness-of-iteration'); 23521 var speciesConstructor = _dereq_('../internals/species-constructor'); 23522 var task = _dereq_('../internals/task').set; 23523 var microtask = _dereq_('../internals/microtask'); 23524 var promiseResolve = _dereq_('../internals/promise-resolve'); 23525 var hostReportErrors = _dereq_('../internals/host-report-errors'); 23526 var newPromiseCapabilityModule = _dereq_('../internals/new-promise-capability'); 23527 var perform = _dereq_('../internals/perform'); 23528 var InternalStateModule = _dereq_('../internals/internal-state'); 23529 var isForced = _dereq_('../internals/is-forced'); 23530 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 23531 var V8_VERSION = _dereq_('../internals/engine-v8-version'); 23532 var SPECIES = wellKnownSymbol('species'); 23533 var PROMISE = 'Promise'; 23534 var getInternalState = InternalStateModule.get; 23535 var setInternalState = InternalStateModule.set; 23536 var getInternalPromiseState = InternalStateModule.getterFor(PROMISE); 23537 var PromiseConstructor = NativePromise; 23538 var TypeError = global.TypeError; 23539 var document = global.document; 23540 var process = global.process; 23541 var $fetch = getBuiltIn('fetch'); 23542 var newPromiseCapability = newPromiseCapabilityModule.f; 23543 var newGenericPromiseCapability = newPromiseCapability; 23544 var IS_NODE = classof(process) == 'process'; 23545 var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent); 23546 var UNHANDLED_REJECTION = 'unhandledrejection'; 23547 var REJECTION_HANDLED = 'rejectionhandled'; 23548 var PENDING = 0; 23549 var FULFILLED = 1; 23550 var REJECTED = 2; 23551 var HANDLED = 1; 23552 var UNHANDLED = 2; 23553 var Internal, 23554 OwnPromiseCapability, 23555 PromiseWrapper, 23556 nativeThen; 23557 var FORCED = isForced(PROMISE, function () { 23558 var GLOBAL_CORE_JS_PROMISE = inspectSource(PromiseConstructor) !== String(PromiseConstructor); 23559 if (!GLOBAL_CORE_JS_PROMISE) { 23560 // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables 23561 // https://bugs.chromium.org/p/chromium/issues/detail?id=830565 23562 // We can't detect it synchronously, so just check versions 23563 if (V8_VERSION === 66) return true; // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test 23564 if (!IS_NODE && typeof PromiseRejectionEvent != 'function') return true; 23565 } // We need Promise#finally in the pure version for preventing prototype pollution 23566 23567 if (IS_PURE && !PromiseConstructor.prototype['finally']) return true; // We can't use @@species feature detection in V8 since it causes 23568 // deoptimization and performance degradation 23569 // https://github.com/zloirock/core-js/issues/679 23570 if (V8_VERSION >= 51 && /native code/.test(PromiseConstructor)) return false; // Detect correctness of subclassing with @@species support 23571 var promise = PromiseConstructor.resolve(1); 23572 var FakePromise = function (exec) { 23573 exec(function () { 23574 /* empty */ 23575 }, function () { 23576 /* empty */ 23577 }); 23578 }; 23579 var constructor = promise.constructor = { 23580 }; 23581 constructor[SPECIES] = FakePromise; 23582 return !(promise.then(function () { 23583 /* empty */ 23584 }) instanceof FakePromise); 23585 }); 23586 var INCORRECT_ITERATION = FORCED || !checkCorrectnessOfIteration(function (iterable) { 23587 PromiseConstructor.all(iterable) ['catch'](function () { 23588 /* empty */ 23589 }); 23590 }); // helpers 23591 var isThenable = function (it) { 23592 var then; 23593 return isObject(it) && typeof (then = it.then) == 'function' ? then : false;
vendor: 10,709 bytes, lines 23594-23861
23594 }; 23595 var notify = function (promise, state, isReject) { 23596 if (state.notified) return; 23597 state.notified = true; 23598 var chain = state.reactions; 23599 microtask(function () { 23600 var value = state.value; 23601 var ok = state.state == FULFILLED; 23602 var index = 0; // variable length - can't use forEach 23603 while (chain.length > index) { 23604 var reaction = chain[index++]; 23605 var handler = ok ? reaction.ok : reaction.fail; 23606 var resolve = reaction.resolve; 23607 var reject = reaction.reject; 23608 var domain = reaction.domain; 23609 var result, 23610 then, 23611 exited; 23612 try { 23613 if (handler) { 23614 if (!ok) { 23615 if (state.rejection === UNHANDLED) onHandleUnhandled(promise, state); 23616 state.rejection = HANDLED; 23617 } 23618 if (handler === true) result = value; 23619 else { 23620 if (domain) domain.enter(); 23621 result = handler(value); // can throw 23622 if (domain) { 23623 domain.exit(); 23624 exited = true; 23625 } 23626 } 23627 if (result === reaction.promise) { 23628 reject(TypeError('Promise-chain cycle')); 23629 } else if (then = isThenable(result)) { 23630 then.call(result, resolve, reject); 23631 } else resolve(result); 23632 } else reject(value); 23633 } catch (error) { 23634 if (domain && !exited) domain.exit(); 23635 reject(error); 23636 } 23637 } 23638 state.reactions = [ 23639 ]; 23640 state.notified = false; 23641 if (isReject && !state.rejection) onUnhandled(promise, state); 23642 }); 23643 }; 23644 var dispatchEvent = function (name, promise, reason) { 23645 var event, 23646 handler; 23647 if (DISPATCH_EVENT) { 23648 event = document.createEvent('Event'); 23649 event.promise = promise; 23650 event.reason = reason; 23651 event.initEvent(name, false, true); 23652 global.dispatchEvent(event); 23653 } else event = { 23654 promise: promise, 23655 reason: reason 23656 }; 23657 if (handler = global['on' + name]) handler(event); 23658 else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason); 23659 }; 23660 var onUnhandled = function (promise, state) { 23661 task.call(global, function () { 23662 var value = state.value; 23663 var IS_UNHANDLED = isUnhandled(state); 23664 var result; 23665 if (IS_UNHANDLED) { 23666 result = perform(function () { 23667 if (IS_NODE) { 23668 process.emit('unhandledRejection', value, promise); 23669 } else dispatchEvent(UNHANDLED_REJECTION, promise, value); 23670 }); // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should 23671 state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED; 23672 if (result.error) throw result.value; 23673 } 23674 }); 23675 }; 23676 var isUnhandled = function (state) { 23677 return state.rejection !== HANDLED && !state.parent; 23678 }; 23679 var onHandleUnhandled = function (promise, state) { 23680 task.call(global, function () { 23681 if (IS_NODE) { 23682 process.emit('rejectionHandled', promise); 23683 } else dispatchEvent(REJECTION_HANDLED, promise, state.value); 23684 }); 23685 }; 23686 var bind = function (fn, promise, state, unwrap) { 23687 return function (value) { 23688 fn(promise, state, value, unwrap); 23689 }; 23690 }; 23691 var internalReject = function (promise, state, value, unwrap) { 23692 if (state.done) return; 23693 state.done = true; 23694 if (unwrap) state = unwrap; 23695 state.value = value; 23696 state.state = REJECTED; 23697 notify(promise, state, true); 23698 }; 23699 var internalResolve = function (promise, state, value, unwrap) { 23700 if (state.done) return; 23701 state.done = true; 23702 if (unwrap) state = unwrap; 23703 try { 23704 if (promise === value) throw TypeError('Promise can\'t be resolved itself'); 23705 var then = isThenable(value); 23706 if (then) { 23707 microtask(function () { 23708 var wrapper = { 23709 done: false 23710 }; 23711 try { 23712 then.call(value, bind(internalResolve, promise, wrapper, state), bind(internalReject, promise, wrapper, state)); 23713 } catch (error) { 23714 internalReject(promise, wrapper, error, state); 23715 } 23716 }); 23717 } else { 23718 state.value = value; 23719 state.state = FULFILLED; 23720 notify(promise, state, false); 23721 } 23722 } catch (error) { 23723 internalReject(promise, { 23724 done: false 23725 }, error, state); 23726 } 23727 }; // constructor polyfill 23728 if (FORCED) { 23729 // 25.4.3.1 Promise(executor) 23730 PromiseConstructor = function Promise(executor) { 23731 anInstance(this, PromiseConstructor, PROMISE); 23732 aFunction(executor); 23733 Internal.call(this); 23734 var state = getInternalState(this); 23735 try { 23736 executor(bind(internalResolve, this, state), bind(internalReject, this, state)); 23737 } catch (error) { 23738 internalReject(this, state, error); 23739 } 23740 }; // eslint-disable-next-line no-unused-vars 23741 Internal = function Promise(executor) { 23742 setInternalState(this, { 23743 type: PROMISE, 23744 done: false, 23745 notified: false, 23746 parent: false, 23747 reactions: [ 23748 ], 23749 rejection: false, 23750 state: PENDING, 23751 value: undefined 23752 }); 23753 }; 23754 Internal.prototype = redefineAll(PromiseConstructor.prototype, { 23755 // `Promise.prototype.then` method 23756 // https://tc39.github.io/ecma262/#sec-promise.prototype.then 23757 then: function then(onFulfilled, onRejected) { 23758 var state = getInternalPromiseState(this); 23759 var reaction = newPromiseCapability(speciesConstructor(this, PromiseConstructor)); 23760 reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; 23761 reaction.fail = typeof onRejected == 'function' && onRejected; 23762 reaction.domain = IS_NODE ? process.domain : undefined; 23763 state.parent = true; 23764 state.reactions.push(reaction); 23765 if (state.state != PENDING) notify(this, state, false); 23766 return reaction.promise; 23767 }, 23768 // `Promise.prototype.catch` method 23769 // https://tc39.github.io/ecma262/#sec-promise.prototype.catch 23770 'catch': function (onRejected) { 23771 return this.then(undefined, onRejected); 23772 } 23773 }); 23774 OwnPromiseCapability = function () { 23775 var promise = new Internal(); 23776 var state = getInternalState(promise); 23777 this.promise = promise; 23778 this.resolve = bind(internalResolve, promise, state); 23779 this.reject = bind(internalReject, promise, state); 23780 }; 23781 newPromiseCapabilityModule.f = newPromiseCapability = function (C) { 23782 return C === PromiseConstructor || C === PromiseWrapper ? new OwnPromiseCapability(C) : newGenericPromiseCapability(C); 23783 }; 23784 if (!IS_PURE && typeof NativePromise == 'function') { 23785 nativeThen = NativePromise.prototype.then; // wrap native Promise#then for native async functions 23786 redefine(NativePromise.prototype, 'then', function then(onFulfilled, onRejected) { 23787 var that = this; 23788 return new PromiseConstructor(function (resolve, reject) { 23789 nativeThen.call(that, resolve, reject); 23790 }).then(onFulfilled, onRejected); // https://github.com/zloirock/core-js/issues/640 23791 }, { 23792 unsafe: true 23793 }); // wrap fetch result 23794 if (typeof $fetch == 'function') $({ 23795 global: true, 23796 enumerable: true, 23797 forced: true 23798 }, { 23799 // eslint-disable-next-line no-unused-vars 23800 fetch: function fetch(input /* , init */ 23801 ) { 23802 return promiseResolve(PromiseConstructor, $fetch.apply(global, arguments)); 23803 } 23804 }); 23805 } 23806 } 23807 $({ 23808 global: true, 23809 wrap: true, 23810 forced: FORCED 23811 }, { 23812 Promise: PromiseConstructor 23813 }); 23814 setToStringTag(PromiseConstructor, PROMISE, false, true); 23815 setSpecies(PROMISE); 23816 PromiseWrapper = getBuiltIn(PROMISE); // statics 23817 $({ 23818 target: PROMISE, 23819 stat: true, 23820 forced: FORCED 23821 }, { 23822 // `Promise.reject` method 23823 // https://tc39.github.io/ecma262/#sec-promise.reject 23824 reject: function reject(r) { 23825 var capability = newPromiseCapability(this); 23826 capability.reject.call(undefined, r); 23827 return capability.promise; 23828 } 23829 }); 23830 $({ 23831 target: PROMISE, 23832 stat: true, 23833 forced: IS_PURE || FORCED 23834 }, { 23835 // `Promise.resolve` method 23836 // https://tc39.github.io/ecma262/#sec-promise.resolve 23837 resolve: function resolve(x) { 23838 return promiseResolve(IS_PURE && this === PromiseWrapper ? PromiseConstructor : this, x); 23839 } 23840 }); 23841 $({ 23842 target: PROMISE, 23843 stat: true, 23844 forced: INCORRECT_ITERATION 23845 }, { 23846 // `Promise.all` method 23847 // https://tc39.github.io/ecma262/#sec-promise.all 23848 all: function all(iterable) { 23849 var C = this; 23850 var capability = newPromiseCapability(C); 23851 var resolve = capability.resolve; 23852 var reject = capability.reject; 23853 var result = perform(function () { 23854 var $promiseResolve = aFunction(C.resolve); 23855 var values = [ 23856 ]; 23857 var counter = 0; 23858 var remaining = 1; 23859 iterate(iterable, function (promise) { 23860 var index = counter++; 23861 var alreadyCalled = false;
vendor: 5,567 bytes, lines 23862-24004
23862 values.push(undefined); 23863 remaining++; 23864 $promiseResolve.call(C, promise).then(function (value) { 23865 if (alreadyCalled) return; 23866 alreadyCalled = true; 23867 values[index] = value; 23868 --remaining || resolve(values); 23869 }, reject); 23870 }); 23871 --remaining || resolve(values); 23872 }); 23873 if (result.error) reject(result.value); 23874 return capability.promise; 23875 }, 23876 // `Promise.race` method 23877 // https://tc39.github.io/ecma262/#sec-promise.race 23878 race: function race(iterable) { 23879 var C = this; 23880 var capability = newPromiseCapability(C); 23881 var reject = capability.reject; 23882 var result = perform(function () { 23883 var $promiseResolve = aFunction(C.resolve); 23884 iterate(iterable, function (promise) { 23885 $promiseResolve.call(C, promise).then(capability.resolve, reject); 23886 }); 23887 }); 23888 if (result.error) reject(result.value); 23889 return capability.promise; 23890 } 23891 }); 23892 }, 23893 { 23894 '../internals/a-function': 23, 23895 '../internals/an-instance': 27, 23896 '../internals/check-correctness-of-iteration': 45, 23897 '../internals/classof-raw': 46, 23898 '../internals/engine-v8-version': 66, 23899 '../internals/export': 68, 23900 '../internals/get-built-in': 74, 23901 '../internals/global': 77, 23902 '../internals/host-report-errors': 80, 23903 '../internals/inspect-source': 86, 23904 '../internals/internal-state': 88, 23905 '../internals/is-forced': 91, 23906 '../internals/is-object': 92, 23907 '../internals/is-pure': 93, 23908 '../internals/iterate': 95, 23909 '../internals/microtask': 99, 23910 '../internals/native-promise-constructor': 100, 23911 '../internals/new-promise-capability': 104, 23912 '../internals/perform': 123, 23913 '../internals/promise-resolve': 124, 23914 '../internals/redefine': 126, 23915 '../internals/redefine-all': 125, 23916 '../internals/set-species': 134, 23917 '../internals/set-to-string-tag': 135, 23918 '../internals/species-constructor': 139, 23919 '../internals/task': 146, 23920 '../internals/well-known-symbol': 164 23921 } 23922 ], 23923 197: [ 23924 function (_dereq_, module, exports) { 23925 var $ = _dereq_('../internals/export'); 23926 var getBuiltIn = _dereq_('../internals/get-built-in'); 23927 var aFunction = _dereq_('../internals/a-function'); 23928 var anObject = _dereq_('../internals/an-object'); 23929 var isObject = _dereq_('../internals/is-object'); 23930 var create = _dereq_('../internals/object-create'); 23931 var bind = _dereq_('../internals/function-bind'); 23932 var fails = _dereq_('../internals/fails'); 23933 var nativeConstruct = getBuiltIn('Reflect', 'construct'); // `Reflect.construct` method 23934 // https://tc39.github.io/ecma262/#sec-reflect.construct 23935 // MS Edge supports only 2 arguments and argumentsList argument is optional 23936 // FF Nightly sets third argument as `new.target`, but does not create `this` from it 23937 var NEW_TARGET_BUG = fails(function () { 23938 function F() { 23939 /* empty */ 23940 } 23941 return !(nativeConstruct(function () { 23942 /* empty */ 23943 }, [ 23944 ], F) instanceof F); 23945 }); 23946 var ARGS_BUG = !fails(function () { 23947 nativeConstruct(function () { 23948 /* empty */ 23949 }); 23950 }); 23951 var FORCED = NEW_TARGET_BUG || ARGS_BUG; 23952 $({ 23953 target: 'Reflect', 23954 stat: true, 23955 forced: FORCED, 23956 sham: FORCED 23957 }, { 23958 construct: function construct(Target, args /* , newTarget */ 23959 ) { 23960 aFunction(Target); 23961 anObject(args); 23962 var newTarget = arguments.length < 3 ? Target : aFunction(arguments[2]); 23963 if (ARGS_BUG && !NEW_TARGET_BUG) return nativeConstruct(Target, args, newTarget); 23964 if (Target == newTarget) { 23965 // w/o altered newTarget, optimization for 0-4 arguments 23966 switch (args.length) { 23967 case 0: 23968 return new Target(); 23969 case 1: 23970 return new Target(args[0]); 23971 case 2: 23972 return new Target(args[0], args[1]); 23973 case 3: 23974 return new Target(args[0], args[1], args[2]); 23975 case 4: 23976 return new Target(args[0], args[1], args[2], args[3]); 23977 } // w/o altered newTarget, lot of arguments case 23978 23979 var $args = [ 23980 null 23981 ]; 23982 $args.push.apply($args, args); 23983 return new (bind.apply(Target, $args)) (); 23984 } // with altered newTarget, not support built-in constructors 23985 23986 var proto = newTarget.prototype; 23987 var instance = create(isObject(proto) ? proto : Object.prototype); 23988 var result = Function.apply.call(Target, instance, args); 23989 return isObject(result) ? result : instance; 23990 } 23991 }); 23992 }, 23993 { 23994 '../internals/a-function': 23, 23995 '../internals/an-object': 28, 23996 '../internals/export': 68, 23997 '../internals/fails': 69, 23998 '../internals/function-bind': 73, 23999 '../internals/get-built-in': 74, 24000 '../internals/is-object': 92, 24001 '../internals/object-create': 108 24002 } 24003 ], 24004 198: [
vendor: 4,400 bytes, lines 24005-24095
24005 function (_dereq_, module, exports) { 24006 var DESCRIPTORS = _dereq_('../internals/descriptors'); 24007 var global = _dereq_('../internals/global'); 24008 var isForced = _dereq_('../internals/is-forced'); 24009 var inheritIfRequired = _dereq_('../internals/inherit-if-required'); 24010 var defineProperty = _dereq_('../internals/object-define-property').f; 24011 var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f; 24012 var isRegExp = _dereq_('../internals/is-regexp'); 24013 var getFlags = _dereq_('../internals/regexp-flags'); 24014 var stickyHelpers = _dereq_('../internals/regexp-sticky-helpers'); 24015 var redefine = _dereq_('../internals/redefine'); 24016 var fails = _dereq_('../internals/fails'); 24017 var setInternalState = _dereq_('../internals/internal-state').set; 24018 var setSpecies = _dereq_('../internals/set-species'); 24019 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 24020 var MATCH = wellKnownSymbol('match'); 24021 var NativeRegExp = global.RegExp; 24022 var RegExpPrototype = NativeRegExp.prototype; 24023 var re1 = /a/g; 24024 var re2 = /a/g; // "new" should create a new object, old webkit bug 24025 var CORRECT_NEW = new NativeRegExp(re1) !== re1; 24026 var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y; 24027 var FORCED = DESCRIPTORS && isForced('RegExp', !CORRECT_NEW || UNSUPPORTED_Y || fails(function () { 24028 re2[MATCH] = false; // RegExp constructor can alter flags and IsRegExp works correct with @@match 24029 return NativeRegExp(re1) != re1 || NativeRegExp(re2) == re2 || NativeRegExp(re1, 'i') != '/a/i'; 24030 })); // `RegExp` constructor 24031 // https://tc39.github.io/ecma262/#sec-regexp-constructor 24032 if (FORCED) { 24033 var RegExpWrapper = function RegExp(pattern, flags) { 24034 var thisIsRegExp = this instanceof RegExpWrapper; 24035 var patternIsRegExp = isRegExp(pattern); 24036 var flagsAreUndefined = flags === undefined; 24037 var sticky; 24038 if (!thisIsRegExp && patternIsRegExp && pattern.constructor === RegExpWrapper && flagsAreUndefined) { 24039 return pattern; 24040 } 24041 if (CORRECT_NEW) { 24042 if (patternIsRegExp && !flagsAreUndefined) pattern = pattern.source; 24043 } else if (pattern instanceof RegExpWrapper) { 24044 if (flagsAreUndefined) flags = getFlags.call(pattern); 24045 pattern = pattern.source; 24046 } 24047 if (UNSUPPORTED_Y) { 24048 sticky = !!flags && flags.indexOf('y') > - 1; 24049 if (sticky) flags = flags.replace(/y/g, ''); 24050 } 24051 var result = inheritIfRequired(CORRECT_NEW ? new NativeRegExp(pattern, flags) : NativeRegExp(pattern, flags), thisIsRegExp ? this : RegExpPrototype, RegExpWrapper); 24052 if (UNSUPPORTED_Y && sticky) setInternalState(result, { 24053 sticky: sticky 24054 }); 24055 return result; 24056 }; 24057 var proxy = function (key) { 24058 key in RegExpWrapper || defineProperty(RegExpWrapper, key, { 24059 configurable: true, 24060 get: function () { 24061 return NativeRegExp[key]; 24062 }, 24063 set: function (it) { 24064 NativeRegExp[key] = it; 24065 } 24066 }); 24067 }; 24068 var keys = getOwnPropertyNames(NativeRegExp); 24069 var index = 0; 24070 while (keys.length > index) proxy(keys[index++]); 24071 RegExpPrototype.constructor = RegExpWrapper; 24072 RegExpWrapper.prototype = RegExpPrototype; 24073 redefine(global, 'RegExp', RegExpWrapper); 24074 } // https://tc39.github.io/ecma262/#sec-get-regexp-@@species 24075 24076 setSpecies('RegExp'); 24077 }, 24078 { 24079 '../internals/descriptors': 61, 24080 '../internals/fails': 69, 24081 '../internals/global': 77, 24082 '../internals/inherit-if-required': 85, 24083 '../internals/internal-state': 88, 24084 '../internals/is-forced': 91, 24085 '../internals/is-regexp': 94, 24086 '../internals/object-define-property': 110, 24087 '../internals/object-get-own-property-names': 113, 24088 '../internals/redefine': 126, 24089 '../internals/regexp-flags': 129, 24090 '../internals/regexp-sticky-helpers': 130, 24091 '../internals/set-species': 134, 24092 '../internals/well-known-symbol': 164 24093 } 24094 ], 24095 199: [
vendor: 4,725 bytes, lines 24096-24212
24096 function (_dereq_, module, exports) { 24097 'use strict'; 24098 var $ = _dereq_('../internals/export'); 24099 var exec = _dereq_('../internals/regexp-exec'); 24100 $({ 24101 target: 'RegExp', 24102 proto: true, 24103 forced: /./.exec !== exec 24104 }, { 24105 exec: exec 24106 }); 24107 }, 24108 { 24109 '../internals/export': 68, 24110 '../internals/regexp-exec': 128 24111 } 24112 ], 24113 200: [ 24114 function (_dereq_, module, exports) { 24115 'use strict'; 24116 var redefine = _dereq_('../internals/redefine'); 24117 var anObject = _dereq_('../internals/an-object'); 24118 var fails = _dereq_('../internals/fails'); 24119 var flags = _dereq_('../internals/regexp-flags'); 24120 var TO_STRING = 'toString'; 24121 var RegExpPrototype = RegExp.prototype; 24122 var nativeToString = RegExpPrototype[TO_STRING]; 24123 var NOT_GENERIC = fails(function () { 24124 return nativeToString.call({ 24125 source: 'a', 24126 flags: 'b' 24127 }) != '/a/b'; 24128 }); // FF44- RegExp#toString has a wrong name 24129 var INCORRECT_NAME = nativeToString.name != TO_STRING; // `RegExp.prototype.toString` method 24130 // https://tc39.github.io/ecma262/#sec-regexp.prototype.tostring 24131 if (NOT_GENERIC || INCORRECT_NAME) { 24132 redefine(RegExp.prototype, TO_STRING, function toString() { 24133 var R = anObject(this); 24134 var p = String(R.source); 24135 var rf = R.flags; 24136 var f = String(rf === undefined && R instanceof RegExp && !('flags' in RegExpPrototype) ? flags.call(R) : rf); 24137 return '/' + p + '/' + f; 24138 }, { 24139 unsafe: true 24140 }); 24141 } 24142 }, 24143 { 24144 '../internals/an-object': 28, 24145 '../internals/fails': 69, 24146 '../internals/redefine': 126, 24147 '../internals/regexp-flags': 129 24148 } 24149 ], 24150 201: [ 24151 function (_dereq_, module, exports) { 24152 'use strict'; 24153 var collection = _dereq_('../internals/collection'); 24154 var collectionStrong = _dereq_('../internals/collection-strong'); // `Set` constructor 24155 // https://tc39.github.io/ecma262/#sec-set-objects 24156 module.exports = collection('Set', function (init) { 24157 return function Set() { 24158 return init(this, arguments.length ? arguments[0] : undefined); 24159 }; 24160 }, collectionStrong); 24161 }, 24162 { 24163 '../internals/collection': 50, 24164 '../internals/collection-strong': 48 24165 } 24166 ], 24167 202: [ 24168 function (_dereq_, module, exports) { 24169 'use strict'; 24170 var $ = _dereq_('../internals/export'); 24171 var getOwnPropertyDescriptor = _dereq_('../internals/object-get-own-property-descriptor').f; 24172 var toLength = _dereq_('../internals/to-length'); 24173 var notARegExp = _dereq_('../internals/not-a-regexp'); 24174 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 24175 var correctIsRegExpLogic = _dereq_('../internals/correct-is-regexp-logic'); 24176 var IS_PURE = _dereq_('../internals/is-pure'); 24177 var nativeEndsWith = ''.endsWith; 24178 var min = Math.min; 24179 var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('endsWith'); // https://github.com/zloirock/core-js/pull/702 24180 var MDN_POLYFILL_BUG = !IS_PURE && !CORRECT_IS_REGEXP_LOGIC && !!function () { 24181 var descriptor = getOwnPropertyDescriptor(String.prototype, 'endsWith'); 24182 return descriptor && !descriptor.writable; 24183 }(); // `String.prototype.endsWith` method 24184 // https://tc39.github.io/ecma262/#sec-string.prototype.endswith 24185 $({ 24186 target: 'String', 24187 proto: true, 24188 forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC 24189 }, { 24190 endsWith: function endsWith(searchString /* , endPosition = @length */ 24191 ) { 24192 var that = String(requireObjectCoercible(this)); 24193 notARegExp(searchString); 24194 var endPosition = arguments.length > 1 ? arguments[1] : undefined; 24195 var len = toLength(that.length); 24196 var end = endPosition === undefined ? len : min(toLength(endPosition), len); 24197 var search = String(searchString); 24198 return nativeEndsWith ? nativeEndsWith.call(that, search, end) : that.slice(end - search.length, end) === search; 24199 } 24200 }); 24201 }, 24202 { 24203 '../internals/correct-is-regexp-logic': 52, 24204 '../internals/export': 68, 24205 '../internals/is-pure': 93, 24206 '../internals/not-a-regexp': 105, 24207 '../internals/object-get-own-property-descriptor': 111, 24208 '../internals/require-object-coercible': 131, 24209 '../internals/to-length': 152 24210 } 24211 ], 24212 203: [
vendor: 4,409 bytes, lines 24213-24311
24213 function (_dereq_, module, exports) { 24214 'use strict'; 24215 var $ = _dereq_('../internals/export'); 24216 var notARegExp = _dereq_('../internals/not-a-regexp'); 24217 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 24218 var correctIsRegExpLogic = _dereq_('../internals/correct-is-regexp-logic'); // `String.prototype.includes` method 24219 // https://tc39.github.io/ecma262/#sec-string.prototype.includes 24220 $({ 24221 target: 'String', 24222 proto: true, 24223 forced: !correctIsRegExpLogic('includes') 24224 }, { 24225 includes: function includes(searchString /* , position = 0 */ 24226 ) { 24227 return !!~String(requireObjectCoercible(this)).indexOf(notARegExp(searchString), arguments.length > 1 ? arguments[1] : undefined); 24228 } 24229 }); 24230 }, 24231 { 24232 '../internals/correct-is-regexp-logic': 52, 24233 '../internals/export': 68, 24234 '../internals/not-a-regexp': 105, 24235 '../internals/require-object-coercible': 131 24236 } 24237 ], 24238 204: [ 24239 function (_dereq_, module, exports) { 24240 'use strict'; 24241 var charAt = _dereq_('../internals/string-multibyte').charAt; 24242 var InternalStateModule = _dereq_('../internals/internal-state'); 24243 var defineIterator = _dereq_('../internals/define-iterator'); 24244 var STRING_ITERATOR = 'String Iterator'; 24245 var setInternalState = InternalStateModule.set; 24246 var getInternalState = InternalStateModule.getterFor(STRING_ITERATOR); // `String.prototype[@@iterator]` method 24247 // https://tc39.github.io/ecma262/#sec-string.prototype-@@iterator 24248 defineIterator(String, 'String', function (iterated) { 24249 setInternalState(this, { 24250 type: STRING_ITERATOR, 24251 string: String(iterated), 24252 index: 0 24253 }); // `%StringIteratorPrototype%.next` method 24254 // https://tc39.github.io/ecma262/#sec-%stringiteratorprototype%.next 24255 }, function next() { 24256 var state = getInternalState(this); 24257 var string = state.string; 24258 var index = state.index; 24259 var point; 24260 if (index >= string.length) return { 24261 value: undefined, 24262 done: true 24263 }; 24264 point = charAt(string, index); 24265 state.index += point.length; 24266 return { 24267 value: point, 24268 done: false 24269 }; 24270 }); 24271 }, 24272 { 24273 '../internals/define-iterator': 59, 24274 '../internals/internal-state': 88, 24275 '../internals/string-multibyte': 141 24276 } 24277 ], 24278 205: [ 24279 function (_dereq_, module, exports) { 24280 'use strict'; 24281 var fixRegExpWellKnownSymbolLogic = _dereq_('../internals/fix-regexp-well-known-symbol-logic'); 24282 var anObject = _dereq_('../internals/an-object'); 24283 var toLength = _dereq_('../internals/to-length'); 24284 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 24285 var advanceStringIndex = _dereq_('../internals/advance-string-index'); 24286 var regExpExec = _dereq_('../internals/regexp-exec-abstract'); // @@match logic 24287 fixRegExpWellKnownSymbolLogic('match', 1, function (MATCH, nativeMatch, maybeCallNative) { 24288 return [ // `String.prototype.match` method 24289 // https://tc39.github.io/ecma262/#sec-string.prototype.match 24290 function match(regexp) { 24291 var O = requireObjectCoercible(this); 24292 var matcher = regexp == undefined ? undefined : regexp[MATCH]; 24293 return matcher !== undefined ? matcher.call(regexp, O) : new RegExp(regexp) [MATCH](String(O)); 24294 }, // `RegExp.prototype[@@match]` method 24295 // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@match 24296 function (regexp) { 24297 var res = maybeCallNative(nativeMatch, regexp, this); 24298 if (res.done) return res.value; 24299 var rx = anObject(regexp); 24300 var S = String(this); 24301 if (!rx.global) return regExpExec(rx, S); 24302 var fullUnicode = rx.unicode; 24303 rx.lastIndex = 0; 24304 var A = [ 24305 ]; 24306 var n = 0; 24307 var result; 24308 while ((result = regExpExec(rx, S)) !== null) { 24309 var matchStr = String(result[0]); 24310 A[n] = matchStr; 24311 if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLe
vendor: 7,304 bytes, lines 24311-24470
24311ngth(rx.lastIndex), fullUnicode); 24312 n++; 24313 } 24314 return n === 0 ? null : A; 24315 } 24316 ]; 24317 }); 24318 }, 24319 { 24320 '../internals/advance-string-index': 26, 24321 '../internals/an-object': 28, 24322 '../internals/fix-regexp-well-known-symbol-logic': 70, 24323 '../internals/regexp-exec-abstract': 127, 24324 '../internals/require-object-coercible': 131, 24325 '../internals/to-length': 152 24326 } 24327 ], 24328 206: [ 24329 function (_dereq_, module, exports) { 24330 var $ = _dereq_('../internals/export'); 24331 var repeat = _dereq_('../internals/string-repeat'); // `String.prototype.repeat` method 24332 // https://tc39.github.io/ecma262/#sec-string.prototype.repeat 24333 $({ 24334 target: 'String', 24335 proto: true 24336 }, { 24337 repeat: repeat 24338 }); 24339 }, 24340 { 24341 '../internals/export': 68, 24342 '../internals/string-repeat': 143 24343 } 24344 ], 24345 207: [ 24346 function (_dereq_, module, exports) { 24347 'use strict'; 24348 var fixRegExpWellKnownSymbolLogic = _dereq_('../internals/fix-regexp-well-known-symbol-logic'); 24349 var anObject = _dereq_('../internals/an-object'); 24350 var toObject = _dereq_('../internals/to-object'); 24351 var toLength = _dereq_('../internals/to-length'); 24352 var toInteger = _dereq_('../internals/to-integer'); 24353 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 24354 var advanceStringIndex = _dereq_('../internals/advance-string-index'); 24355 var regExpExec = _dereq_('../internals/regexp-exec-abstract'); 24356 var max = Math.max; 24357 var min = Math.min; 24358 var floor = Math.floor; 24359 var SUBSTITUTION_SYMBOLS = /\$([$&'`]|\d\d?|<[^>]*>)/g; 24360 var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&'`]|\d\d?)/g; 24361 var maybeToString = function (it) { 24362 return it === undefined ? it : String(it); 24363 }; // @@replace logic 24364 fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, maybeCallNative, reason) { 24365 var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = reason.REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE; 24366 var REPLACE_KEEPS_$0 = reason.REPLACE_KEEPS_$0; 24367 var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE ? '$' : '$0'; 24368 return [ // `String.prototype.replace` method 24369 // https://tc39.github.io/ecma262/#sec-string.prototype.replace 24370 function replace(searchValue, replaceValue) { 24371 var O = requireObjectCoercible(this); 24372 var replacer = searchValue == undefined ? undefined : searchValue[REPLACE]; 24373 return replacer !== undefined ? replacer.call(searchValue, O, replaceValue) : nativeReplace.call(String(O), searchValue, replaceValue); 24374 }, // `RegExp.prototype[@@replace]` method 24375 // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace 24376 function (regexp, replaceValue) { 24377 if (!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE && REPLACE_KEEPS_$0 || typeof replaceValue === 'string' && replaceValue.indexOf(UNSAFE_SUBSTITUTE) === - 1) { 24378 var res = maybeCallNative(nativeReplace, regexp, this, replaceValue); 24379 if (res.done) return res.value; 24380 } 24381 var rx = anObject(regexp); 24382 var S = String(this); 24383 var functionalReplace = typeof replaceValue === 'function'; 24384 if (!functionalReplace) replaceValue = String(replaceValue); 24385 var global = rx.global; 24386 if (global) { 24387 var fullUnicode = rx.unicode; 24388 rx.lastIndex = 0; 24389 } 24390 var results = [ 24391 ]; 24392 while (true) { 24393 var result = regExpExec(rx, S); 24394 if (result === null) break; 24395 results.push(result); 24396 if (!global) break; 24397 var matchStr = String(result[0]); 24398 if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode); 24399 } 24400 var accumulatedResult = ''; 24401 var nextSourcePosition = 0; 24402 for (var i = 0; i < results.length; i++) { 24403 result = results[i]; 24404 var matched = String(result[0]); 24405 var position = max(min(toInteger(result.index), S.length), 0); 24406 var captures = [ 24407 ]; // NOTE: This is equivalent to 24408 // captures = result.slice(1).map(maybeToString) 24409 // but for some reason `nativeSlice.call(result, 1, result.length)` (called in 24410 // the slice polyfill when slicing native arrays) "doesn't work" in safari 9 and 24411 // causes a crash (https://pastebin.com/N21QzeQA) when trying to debug it. 24412 for (var j = 1; j < result.length; j++) captures.push(maybeToString(result[j])); 24413 var namedCaptures = result.groups; 24414 if (functionalReplace) { 24415 var replacerArgs = [ 24416 matched 24417 ].concat(captures, position, S); 24418 if (namedCaptures !== undefined) replacerArgs.push(namedCaptures); 24419 var replacement = String(replaceValue.apply(undefined, replacerArgs)); 24420 } else { 24421 replacement = getSubstitution(matched, S, position, captures, namedCaptures, replaceValue); 24422 } 24423 if (position >= nextSourcePosition) { 24424 accumulatedResult += S.slice(nextSourcePosition, position) + replacement; 24425 nextSourcePosition = position + matched.length; 24426 } 24427 } 24428 return accumulatedResult + S.slice(nextSourcePosition); 24429 } 24430 ]; // https://tc39.github.io/ecma262/#sec-getsubstitution 24431 function getSubstitution(matched, str, position, captures, namedCaptures, replacement) { 24432 var tailPos = position + matched.length; 24433 var m = captures.length; 24434 var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED; 24435 if (namedCaptures !== undefined) { 24436 namedCaptures = toObject(namedCaptures); 24437 symbols = SUBSTITUTION_SYMBOLS; 24438 } 24439 return nativeReplace.call(replacement, symbols, function (match, ch) { 24440 var capture; 24441 switch (ch.charAt(0)) { 24442 case '$': 24443 return '$'; 24444 case '&': 24445 return matched; 24446 case '`': 24447 return str.slice(0, position); 24448 case '\'': 24449 return str.slice(tailPos); 24450 case '<': 24451 capture = namedCaptures[ch.slice(1, - 1)]; 24452 break; 24453 default: 24454 // \d\d? 24455 var n = + ch; 24456 if (n === 0) return match; 24457 if (n > m) { 24458 var f = floor(n / 10); 24459 if (f === 0) return match; 24460 if (f <= m) return captures[f - 1] === undefined ? ch.charAt(1) : captures[f - 1] + ch.charAt(1); 24461 return match; 24462 } 24463 capture = captures[n - 1]; 24464 } 24465 return capture === undefined ? '' : capture; 24466 }); 24467 } 24468 }); 24469 }, 24470 {
vendor: 6,461 bytes, lines 24471-24588
24471 '../internals/advance-string-index': 26, 24472 '../internals/an-object': 28, 24473 '../internals/fix-regexp-well-known-symbol-logic': 70, 24474 '../internals/regexp-exec-abstract': 127, 24475 '../internals/require-object-coercible': 131, 24476 '../internals/to-integer': 151, 24477 '../internals/to-length': 152, 24478 '../internals/to-object': 153 24479 } 24480 ], 24481 208: [ 24482 function (_dereq_, module, exports) { 24483 'use strict'; 24484 var fixRegExpWellKnownSymbolLogic = _dereq_('../internals/fix-regexp-well-known-symbol-logic'); 24485 var anObject = _dereq_('../internals/an-object'); 24486 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 24487 var sameValue = _dereq_('../internals/same-value'); 24488 var regExpExec = _dereq_('../internals/regexp-exec-abstract'); // @@search logic 24489 fixRegExpWellKnownSymbolLogic('search', 1, function (SEARCH, nativeSearch, maybeCallNative) { 24490 return [ // `String.prototype.search` method 24491 // https://tc39.github.io/ecma262/#sec-string.prototype.search 24492 function search(regexp) { 24493 var O = requireObjectCoercible(this); 24494 var searcher = regexp == undefined ? undefined : regexp[SEARCH]; 24495 return searcher !== undefined ? searcher.call(regexp, O) : new RegExp(regexp) [SEARCH](String(O)); 24496 }, // `RegExp.prototype[@@search]` method 24497 // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@search 24498 function (regexp) { 24499 var res = maybeCallNative(nativeSearch, regexp, this); 24500 if (res.done) return res.value; 24501 var rx = anObject(regexp); 24502 var S = String(this); 24503 var previousLastIndex = rx.lastIndex; 24504 if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0; 24505 var result = regExpExec(rx, S); 24506 if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex; 24507 return result === null ? - 1 : result.index; 24508 } 24509 ]; 24510 }); 24511 }, 24512 { 24513 '../internals/an-object': 28, 24514 '../internals/fix-regexp-well-known-symbol-logic': 70, 24515 '../internals/regexp-exec-abstract': 127, 24516 '../internals/require-object-coercible': 131, 24517 '../internals/same-value': 132 24518 } 24519 ], 24520 209: [ 24521 function (_dereq_, module, exports) { 24522 'use strict'; 24523 var fixRegExpWellKnownSymbolLogic = _dereq_('../internals/fix-regexp-well-known-symbol-logic'); 24524 var isRegExp = _dereq_('../internals/is-regexp'); 24525 var anObject = _dereq_('../internals/an-object'); 24526 var requireObjectCoercible = _dereq_('../internals/require-object-coercible'); 24527 var speciesConstructor = _dereq_('../internals/species-constructor'); 24528 var advanceStringIndex = _dereq_('../internals/advance-string-index'); 24529 var toLength = _dereq_('../internals/to-length'); 24530 var callRegExpExec = _dereq_('../internals/regexp-exec-abstract'); 24531 var regexpExec = _dereq_('../internals/regexp-exec'); 24532 var fails = _dereq_('../internals/fails'); 24533 var arrayPush = [ 24534 ].push; 24535 var min = Math.min; 24536 var MAX_UINT32 = 4294967295; // babel-minify transpiles RegExp('x', 'y') -> /x/y and it causes SyntaxError 24537 var SUPPORTS_Y = !fails(function () { 24538 return !RegExp(MAX_UINT32, 'y'); 24539 }); // @@split logic 24540 fixRegExpWellKnownSymbolLogic('split', 2, function (SPLIT, nativeSplit, maybeCallNative) { 24541 var internalSplit; 24542 if ('abbc'.split(/(b)*/) [1] == 'c' || 'test'.split(/(?:)/, - 1).length != 4 || 'ab'.split(/(?:ab)*/).length != 2 || '.'.split(/(.?)(.?)/).length != 4 || '.'.split(/()()/).length > 1 || ''.split(/.?/).length) { 24543 // based on es5-shim implementation, need to rework it 24544 internalSplit = function (separator, limit) { 24545 var string = String(requireObjectCoercible(this)); 24546 var lim = limit === undefined ? MAX_UINT32 : limit >>> 0; 24547 if (lim === 0) return []; 24548 if (separator === undefined) return [string]; // If `separator` is not a regex, use native split 24549 if (!isRegExp(separator)) { 24550 return nativeSplit.call(string, separator, lim); 24551 } 24552 var output = [ 24553 ]; 24554 var flags = (separator.ignoreCase ? 'i' : '') + (separator.multiline ? 'm' : '') + (separator.unicode ? 'u' : '') + (separator.sticky ? 'y' : ''); 24555 var lastLastIndex = 0; // Make `global` and avoid `lastIndex` issues by working with a copy 24556 var separatorCopy = new RegExp(separator.source, flags + 'g'); 24557 var match, 24558 lastIndex, 24559 lastLength; 24560 while (match = regexpExec.call(separatorCopy, string)) { 24561 lastIndex = separatorCopy.lastIndex; 24562 if (lastIndex > lastLastIndex) { 24563 output.push(string.slice(lastLastIndex, match.index)); 24564 if (match.length > 1 && match.index < string.length) arrayPush.apply(output, match.slice(1)); 24565 lastLength = match[0].length; 24566 lastLastIndex = lastIndex; 24567 if (output.length >= lim) break; 24568 } 24569 if (separatorCopy.lastIndex === match.index) separatorCopy.lastIndex++; // Avoid an infinite loop 24570 } 24571 if (lastLastIndex === string.length) { 24572 if (lastLength || !separatorCopy.test('')) output.push(''); 24573 } else output.push(string.slice(lastLastIndex)); 24574 return output.length > lim ? output.slice(0, lim) : output; 24575 }; // Chakra, V8 24576 } else if ('0'.split(undefined, 0).length) { 24577 internalSplit = function (separator, limit) { 24578 return separator === undefined && limit === 0 ? [ 24579 ] : nativeSplit.call(this, separator, limit); 24580 }; 24581 } else internalSplit = nativeSplit; 24582 return [ // `String.prototype.split` method 24583 // https://tc39.github.io/ecma262/#sec-string.prototype.split 24584 function split(separator, limit) { 24585 var O = requireObjectCoercible(this); 24586 var splitter = separator == undefined ? undefined : separator[SPLIT]; 24587 return splitter !== undefined ? splitter.call(separator, O, limit) : internalSplit.call(String(O), separator, limit); 24588 }
vendor: 6,878 bytes, lines 24588-24752
24588, // `RegExp.prototype[@@split]` method 24589 // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@split 24590 // 24591 // NOTE: This cannot be properly polyfilled in engines that don't support 24592 // the 'y' flag. 24593 function (regexp, limit) { 24594 var res = maybeCallNative(internalSplit, regexp, this, limit, internalSplit !== nativeSplit); 24595 if (res.done) return res.value; 24596 var rx = anObject(regexp); 24597 var S = String(this); 24598 var C = speciesConstructor(rx, RegExp); 24599 var unicodeMatching = rx.unicode; 24600 var flags = (rx.ignoreCase ? 'i' : '') + (rx.multiline ? 'm' : '') + (rx.unicode ? 'u' : '') + (SUPPORTS_Y ? 'y' : 'g'); // ^(? + rx + ) is needed, in combination with some S slicing, to 24601 // simulate the 'y' flag. 24602 var splitter = new C(SUPPORTS_Y ? rx : '^(?:' + rx.source + ')', flags); 24603 var lim = limit === undefined ? MAX_UINT32 : limit >>> 0; 24604 if (lim === 0) return []; 24605 if (S.length === 0) return callRegExpExec(splitter, S) === null ? [ 24606 S 24607 ] : [ 24608 ]; 24609 var p = 0; 24610 var q = 0; 24611 var A = [ 24612 ]; 24613 while (q < S.length) { 24614 splitter.lastIndex = SUPPORTS_Y ? q : 0; 24615 var z = callRegExpExec(splitter, SUPPORTS_Y ? S : S.slice(q)); 24616 var e; 24617 if (z === null || (e = min(toLength(splitter.lastIndex + (SUPPORTS_Y ? 0 : q)), S.length)) === p) { 24618 q = advanceStringIndex(S, q, unicodeMatching); 24619 } else { 24620 A.push(S.slice(p, q)); 24621 if (A.length === lim) return A; 24622 for (var i = 1; i <= z.length - 1; i++) { 24623 A.push(z[i]); 24624 if (A.length === lim) return A; 24625 } 24626 q = p = e; 24627 } 24628 } 24629 A.push(S.slice(p)); 24630 return A; 24631 } 24632 ]; 24633 }, !SUPPORTS_Y); 24634 }, 24635 { 24636 '../internals/advance-string-index': 26, 24637 '../internals/an-object': 28, 24638 '../internals/fails': 69, 24639 '../internals/fix-regexp-well-known-symbol-logic': 70, 24640 '../internals/is-regexp': 94, 24641 '../internals/regexp-exec': 128, 24642 '../internals/regexp-exec-abstract': 127, 24643 '../internals/require-object-coercible': 131, 24644 '../internals/species-constructor': 139, 24645 '../internals/to-length': 152 24646 } 24647 ], 24648 210: [ 24649 function (_dereq_, module, exports) { 24650 'use strict'; 24651 var $ = _dereq_('../internals/export'); 24652 var createHTML = _dereq_('../internals/create-html'); 24653 var forcedStringHTMLMethod = _dereq_('../internals/string-html-forced'); // `String.prototype.sub` method 24654 // https://tc39.github.io/ecma262/#sec-string.prototype.sub 24655 $({ 24656 target: 'String', 24657 proto: true, 24658 forced: forcedStringHTMLMethod('sub') 24659 }, { 24660 sub: function sub() { 24661 return createHTML(this, 'sub', '', ''); 24662 } 24663 }); 24664 }, 24665 { 24666 '../internals/create-html': 54, 24667 '../internals/export': 68, 24668 '../internals/string-html-forced': 140 24669 } 24670 ], 24671 211: [ 24672 function (_dereq_, module, exports) { 24673 'use strict'; 24674 var $ = _dereq_('../internals/export'); 24675 var $trim = _dereq_('../internals/string-trim').trim; 24676 var forcedStringTrimMethod = _dereq_('../internals/string-trim-forced'); // `String.prototype.trim` method 24677 // https://tc39.github.io/ecma262/#sec-string.prototype.trim 24678 $({ 24679 target: 'String', 24680 proto: true, 24681 forced: forcedStringTrimMethod('trim') 24682 }, { 24683 trim: function trim() { 24684 return $trim(this); 24685 } 24686 }); 24687 }, 24688 { 24689 '../internals/export': 68, 24690 '../internals/string-trim': 145, 24691 '../internals/string-trim-forced': 144 24692 } 24693 ], 24694 212: [ 24695 function (_dereq_, module, exports) { 24696 // `Symbol.prototype.description` getter 24697 // https://tc39.github.io/ecma262/#sec-symbol.prototype.description 24698 'use strict'; 24699 var $ = _dereq_('../internals/export'); 24700 var DESCRIPTORS = _dereq_('../internals/descriptors'); 24701 var global = _dereq_('../internals/global'); 24702 var has = _dereq_('../internals/has'); 24703 var isObject = _dereq_('../internals/is-object'); 24704 var defineProperty = _dereq_('../internals/object-define-property').f; 24705 var copyConstructorProperties = _dereq_('../internals/copy-constructor-properties'); 24706 var NativeSymbol = global.Symbol; 24707 if (DESCRIPTORS && typeof NativeSymbol == 'function' && (!('description' in NativeSymbol.prototype) || // Safari 12 bug 24708 NativeSymbol().description !== undefined)) { 24709 var EmptyStringDescriptionStore = { 24710 }; // wrap Symbol constructor for correct work with undefined description 24711 var SymbolWrapper = function Symbol() { 24712 var description = arguments.length < 1 || arguments[0] === undefined ? undefined : String(arguments[0]); 24713 var result = this instanceof SymbolWrapper ? new NativeSymbol(description) // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)' 24714 : description === undefined ? NativeSymbol() : NativeSymbol(description); 24715 if (description === '') EmptyStringDescriptionStore[result] = true; 24716 return result; 24717 }; 24718 copyConstructorProperties(SymbolWrapper, NativeSymbol); 24719 var symbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype; 24720 symbolPrototype.constructor = SymbolWrapper; 24721 var symbolToString = symbolPrototype.toString; 24722 var native = String(NativeSymbol('test')) == 'Symbol(test)'; 24723 var regexp = /^Symbol\((.*)\)[^)]+$/; 24724 defineProperty(symbolPrototype, 'description', { 24725 configurable: true, 24726 get: function description() { 24727 var symbol = isObject(this) ? this.valueOf() : this; 24728 var string = symbolToString.call(symbol); 24729 if (has(EmptyStringDescriptionStore, symbol)) return ''; 24730 var desc = native ? string.slice(7, - 1) : string.replace(regexp, '$1'); 24731 return desc === '' ? undefined : desc; 24732 } 24733 }); 24734 $({ 24735 global: true, 24736 forced: true 24737 }, { 24738 Symbol: SymbolWrapper 24739 }); 24740 } 24741 }, 24742 { 24743 '../internals/copy-constructor-properties': 51, 24744 '../internals/descriptors': 61, 24745 '../internals/export': 68, 24746 '../internals/global': 77, 24747 '../internals/has': 78, 24748 '../internals/is-object': 92, 24749 '../internals/object-define-property': 110 24750 } 24751 ], 24752 213: [
24753 function (_dereq_, module, exports) { 24754 var defineWellKnownSymbol = _dereq_('../internals/define-well-known-symbol'); // `Symbol.iterator` well-known symbol 24755 // https://tc39.github.io/ecma262/#sec-symbol.iterator 24756 defineWellKnownSymbol('iterator'); 24757 }, 24758 { 24759 '../internals/define-well-known-symbol': 60 24760 } 24761 ], 24762 214: [ 24763 function (_dereq_, module, exports) { 24764 'use strict'; 24765 var $ = _dereq_('../internals/export'); 24766 var global = _dereq_('../internals/global'); 24767 var getBuiltIn = _dereq_('../internals/get-built-in'); 24768 var IS_PURE = _dereq_('../internals/is-pure'); 24769 var DESCRIPTORS = _dereq_('../internals/descriptors'); 24770 var NATIVE_SYMBOL = _dereq_('../internals/native-symbol'); 24771 var USE_SYMBOL_AS_UID = _dereq_('../internals/use-symbol-as-uid'); 24772 var fails = _dereq_('../internals/fails'); 24773 var has = _dereq_('../internals/has'); 24774 var isArray = _dereq_('../internals/is-array'); 24775 var isObject = _dereq_('../internals/is-object'); 24776 var anObject = _dereq_('../internals/an-object'); 24777 var toObject = _dereq_('../internals/to-object'); 24778 var toIndexedObject = _dereq_('../internals/to-indexed-object'); 24779 var toPrimitive = _dereq_('../internals/to-primitive'); 24780 var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor'); 24781 var nativeObjectCreate = _dereq_('../internals/object-create'); 24782 var objectKeys = _dereq_('../internals/object-keys'); 24783 var getOwnPropertyNamesModule = _dereq_('../internals/object-get-own-property-names'); 24784 var getOwnPropertyNamesExternal = _dereq_('../internals/object-get-own-property-names-external'); 24785 var getOwnPropertySymbolsModule = _dereq_('../internals/object-get-own-property-symbols'); 24786 var getOwnPropertyDescriptorModule = _dereq_('../internals/object-get-own-property-descriptor'); 24787 var definePropertyModule = _dereq_('../internals/object-define-property'); 24788 var propertyIsEnumerableModule = _dereq_('../internals/object-property-is-enumerable'); 24789 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 24790 var redefine = _dereq_('../internals/redefine'); 24791 var shared = _dereq_('../internals/shared'); 24792 var sharedKey = _dereq_('../internals/shared-key'); 24793 var hiddenKeys = _dereq_('../internals/hidden-keys'); 24794 var uid = _dereq_('../internals/uid'); 24795 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 24796 var wrappedWellKnownSymbolModule = _dereq_('../internals/well-known-symbol-wrapped'); 24797 var defineWellKnownSymbol = _dereq_('../internals/define-well-known-symbol'); 24798 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 24799 var InternalStateModule = _dereq_('../internals/internal-state'); 24800 var $forEach = _dereq_('../internals/array-iteration').forEach; 24801 var HIDDEN = sharedKey('hidden'); 24802 var SYMBOL = 'Symbol'; 24803 var PROTOTYPE = 'prototype'; 24804 var TO_PRIMITIVE = wellKnownSymbol('toPrimitive'); 24805 var setInternalState = InternalStateModule.set; 24806 var getInternalState = InternalStateModule.getterFor(SYMBOL); 24807 var ObjectPrototype = Object[PROTOTYPE]; 24808 var $Symbol = global.Symbol; 24809 var $stringify = getBuiltIn('JSON', 'stringify'); 24810 var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; 24811 var nativeDefineProperty = definePropertyModule.f; 24812 var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f; 24813 var nativePropertyIsEnumerable = propertyIsEnumerableModule.f; 24814 var AllSymbols = shared('symbols'); 24815 var ObjectPrototypeSymbols = shared('op-symbols'); 24816 var StringToSymbolRegistry = shared('string-to-symbol-registry'); 24817 var SymbolToStringRegistry = shared('symbol-to-string-registry'); 24818 var WellKnownSymbolsStore = shared('wks'); 24819 var QObject = global.QObject; // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173 24820 var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findC
vendor: 10,832 bytes, lines 24820-25067
24820hild; // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687 24821 var setSymbolDescriptor = DESCRIPTORS && fails(function () { 24822 return nativeObjectCreate(nativeDefineProperty({ 24823 }, 'a', { 24824 get: function () { 24825 return nativeDefineProperty(this, 'a', { 24826 value: 7 24827 }).a; 24828 } 24829 })).a != 7; 24830 }) ? function (O, P, Attributes) { 24831 var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P); 24832 if (ObjectPrototypeDescriptor) delete ObjectPrototype[P]; 24833 nativeDefineProperty(O, P, Attributes); 24834 if (ObjectPrototypeDescriptor && O !== ObjectPrototype) { 24835 nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor); 24836 } 24837 } 24838 : nativeDefineProperty; 24839 var wrap = function (tag, description) { 24840 var symbol = AllSymbols[tag] = nativeObjectCreate($Symbol[PROTOTYPE]); 24841 setInternalState(symbol, { 24842 type: SYMBOL, 24843 tag: tag, 24844 description: description 24845 }); 24846 if (!DESCRIPTORS) symbol.description = description; 24847 return symbol; 24848 }; 24849 var isSymbol = USE_SYMBOL_AS_UID ? function (it) { 24850 return typeof it == 'symbol'; 24851 } 24852 : function (it) { 24853 return Object(it) instanceof $Symbol; 24854 }; 24855 var $defineProperty = function defineProperty(O, P, Attributes) { 24856 if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes); 24857 anObject(O); 24858 var key = toPrimitive(P, true); 24859 anObject(Attributes); 24860 if (has(AllSymbols, key)) { 24861 if (!Attributes.enumerable) { 24862 if (!has(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, { 24863 })); 24864 O[HIDDEN][key] = true; 24865 } else { 24866 if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false; 24867 Attributes = nativeObjectCreate(Attributes, { 24868 enumerable: createPropertyDescriptor(0, false) 24869 }); 24870 } 24871 return setSymbolDescriptor(O, key, Attributes); 24872 } 24873 return nativeDefineProperty(O, key, Attributes); 24874 }; 24875 var $defineProperties = function defineProperties(O, Properties) { 24876 anObject(O); 24877 var properties = toIndexedObject(Properties); 24878 var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties)); 24879 $forEach(keys, function (key) { 24880 if (!DESCRIPTORS || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]); 24881 }); 24882 return O; 24883 }; 24884 var $create = function create(O, Properties) { 24885 return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties); 24886 }; 24887 var $propertyIsEnumerable = function propertyIsEnumerable(V) { 24888 var P = toPrimitive(V, true); 24889 var enumerable = nativePropertyIsEnumerable.call(this, P); 24890 if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) return false; 24891 return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true; 24892 }; 24893 var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) { 24894 var it = toIndexedObject(O); 24895 var key = toPrimitive(P, true); 24896 if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) return; 24897 var descriptor = nativeGetOwnPropertyDescriptor(it, key); 24898 if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) { 24899 descriptor.enumerable = true; 24900 } 24901 return descriptor; 24902 }; 24903 var $getOwnPropertyNames = function getOwnPropertyNames(O) { 24904 var names = nativeGetOwnPropertyNames(toIndexedObject(O)); 24905 var result = [ 24906 ]; 24907 $forEach(names, function (key) { 24908 if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key); 24909 }); 24910 return result; 24911 }; 24912 var $getOwnPropertySymbols = function getOwnPropertySymbols(O) { 24913 var IS_OBJECT_PROTOTYPE = O === ObjectPrototype; 24914 var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O)); 24915 var result = [ 24916 ]; 24917 $forEach(names, function (key) { 24918 if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) { 24919 result.push(AllSymbols[key]); 24920 } 24921 }); 24922 return result; 24923 }; // `Symbol` constructor 24924 // https://tc39.github.io/ecma262/#sec-symbol-constructor 24925 if (!NATIVE_SYMBOL) { 24926 $Symbol = function Symbol() { 24927 if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor'); 24928 var description = !arguments.length || arguments[0] === undefined ? undefined : String(arguments[0]); 24929 var tag = uid(description); 24930 var setter = function (value) { 24931 if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value); 24932 if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false; 24933 setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value)); 24934 }; 24935 if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { 24936 configurable: true, 24937 set: setter 24938 }); 24939 return wrap(tag, description); 24940 }; 24941 redefine($Symbol[PROTOTYPE], 'toString', function toString() { 24942 return getInternalState(this).tag; 24943 }); 24944 redefine($Symbol, 'withoutSetter', function (description) { 24945 return wrap(uid(description), description); 24946 }); 24947 propertyIsEnumerableModule.f = $propertyIsEnumerable; 24948 definePropertyModule.f = $defineProperty; 24949 getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor; 24950 getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames; 24951 getOwnPropertySymbolsModule.f = $getOwnPropertySymbols; 24952 wrappedWellKnownSymbolModule.f = function (name) { 24953 return wrap(wellKnownSymbol(name), name); 24954 }; 24955 if (DESCRIPTORS) { 24956 // https://github.com/tc39/proposal-Symbol-description 24957 nativeDefineProperty($Symbol[PROTOTYPE], 'description', { 24958 configurable: true, 24959 get: function description() { 24960 return getInternalState(this).description; 24961 } 24962 }); 24963 if (!IS_PURE) { 24964 redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { 24965 unsafe: true 24966 }); 24967 } 24968 } 24969 } 24970 $({ 24971 global: true, 24972 wrap: true, 24973 forced: !NATIVE_SYMBOL, 24974 sham: !NATIVE_SYMBOL 24975 }, { 24976 Symbol: $Symbol 24977 }); 24978 $forEach(objectKeys(WellKnownSymbolsStore), function (name) { 24979 defineWellKnownSymbol(name); 24980 }); 24981 $({ 24982 target: SYMBOL, 24983 stat: true, 24984 forced: !NATIVE_SYMBOL 24985 }, { 24986 // `Symbol.for` method 24987 // https://tc39.github.io/ecma262/#sec-symbol.for 24988 'for': function (key) { 24989 var string = String(key); 24990 if (has(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string]; 24991 var symbol = $Symbol(string); 24992 StringToSymbolRegistry[string] = symbol; 24993 SymbolToStringRegistry[symbol] = string; 24994 return symbol; 24995 }, 24996 // `Symbol.keyFor` method 24997 // https://tc39.github.io/ecma262/#sec-symbol.keyfor 24998 keyFor: function keyFor(sym) { 24999 if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol'); 25000 if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym]; 25001 }, 25002 useSetter: function () { 25003 USE_SETTER = true; 25004 }, 25005 useSimple: function () { 25006 USE_SETTER = false; 25007 } 25008 }); 25009 $({ 25010 target: 'Object', 25011 stat: true, 25012 forced: !NATIVE_SYMBOL, 25013 sham: !DESCRIPTORS 25014 }, { 25015 // `Object.create` method 25016 // https://tc39.github.io/ecma262/#sec-object.create 25017 create: $create, 25018 // `Object.defineProperty` method 25019 // https://tc39.github.io/ecma262/#sec-object.defineproperty 25020 defineProperty: $defineProperty, 25021 // `Object.defineProperties` method 25022 // https://tc39.github.io/ecma262/#sec-object.defineproperties 25023 defineProperties: $defineProperties, 25024 // `Object.getOwnPropertyDescriptor` method 25025 // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors 25026 getOwnPropertyDescriptor: $getOwnPropertyDescriptor 25027 }); 25028 $({ 25029 target: 'Object', 25030 stat: true, 25031 forced: !NATIVE_SYMBOL 25032 }, { 25033 // `Object.getOwnPropertyNames` method 25034 // https://tc39.github.io/ecma262/#sec-object.getownpropertynames 25035 getOwnPropertyNames: $getOwnPropertyNames, 25036 // `Object.getOwnPropertySymbols` method 25037 // https://tc39.github.io/ecma262/#sec-object.getownpropertysymbols 25038 getOwnPropertySymbols: $getOwnPropertySymbols 25039 }); // Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives 25040 // https://bugs.chromium.org/p/v8/issues/detail?id=3443 25041 $({ 25042 target: 'Object', 25043 stat: true, 25044 forced: fails(function () { 25045 getOwnPropertySymbolsModule.f(1); 25046 }) 25047 }, { 25048 getOwnPropertySymbols: function getOwnPropertySymbols(it) { 25049 return getOwnPropertySymbolsModule.f(toObject(it)); 25050 } 25051 }); // `JSON.stringify` method behavior with symbols 25052 // https://tc39.github.io/ecma262/#sec-json.stringify 25053 if ($stringify) { 25054 var FORCED_JSON_STRINGIFY = !NATIVE_SYMBOL || fails(function () { 25055 var symbol = $Symbol(); // MS Edge converts symbol values to JSON as {} 25056 return $stringify([symbol]) != '[null]' // WebKit converts symbol values to JSON as null 25057 || $stringify({ 25058 a: symbol 25059 }) != '{}' // V8 throws on boxed symbols 25060 || $stringify(Object(symbol)) != '{}'; 25061 }); 25062 $({ 25063 target: 'JSON', 25064 stat: true, 25065 forced: FORCED_JSON_STRINGIFY 25066 }, { 25067 // eslint-disable-next-line no-unused-vars
25068 stringify: function stringify(it, replacer, space) { 25069 var args = [ 25070 it 25071 ]; 25072 var index = 1; 25073 var $replacer; 25074 while (arguments.length > index) args.push(arguments[index++]); 25075 $replacer = replacer; 25076 if (!isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined 25077 if (!isArray(replacer)) replacer = function (key, value) { 25078 if (typeof $replacer == 'function') value = $replacer.call(this, key, value); 25079 if (!isSymbol(value)) return value; 25080 }; 25081 args[1] = replacer; 25082 return $stringify.apply(null, args); 25083 } 25084 }); 25085 } // `Symbol.prototype[@@toPrimitive]` method 25086 // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@toprimitive 25087 25088 if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) { 25089 createNonEnumerableProperty($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf); 25090 } // `Symbol.prototype[@@toStringTag]` property 25091 // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@tostringtag 25092 25093 setToStringTag($Symbol, SYMBOL); 25094 hiddenKeys[HIDDEN] = true; 25095 }, 25096 { 25097 '../internals/an-object': 28, 25098 '../internals/array-iteration': 37, 25099 '../internals/create-non-enumerable-property': 56, 25100 '../internals/create-property-descriptor': 57, 25101 '../internals/define-well-known-symbol': 60, 25102 '../internals/descriptors': 61, 25103 '../internals/export': 68, 25104 '../internals/fails': 69, 25105 '../internals/get-built-in': 74, 25106 '../internals/global': 77, 25107 '../internals/has': 78, 25108 '../internals/hidden-keys': 79, 25109 '../internals/internal-state': 88, 25110 '../internals/is-array': 90, 25111 '../internals/is-object': 92, 25112 '../internals/is-pure': 93, 25113 '../internals/native-symbol': 101, 25114 '../internals/object-create': 108, 25115 '../internals/object-define-property': 110, 25116 '../internals/object-get-own-property-descriptor': 111, 25117 '../internals/object-get-own-property-names': 113, 25118 '../internals/object-get-own-property-names-external': 112, 25119 '../internals/object-get-own-property-symbols': 114, 25120 '../internals/object-keys': 117, 25121 '../internals/object-property-is-enumerable': 118, 25122 '../internals/redefine': 126, 25123 '../internals/set-to-string-tag': 135, 25124 '../internals/shared': 138, 25125 '../internals/shared-key': 136, 25126 '../internals/to-indexed-object': 150, 25127 '../internals/to-object': 153, 25128 '../internals/to-primitive': 156, 25129 '../internals/uid': 161, 25130 '../internals/use-symbol-as-uid': 162, 25131 '../internals/well-known-symbol': 164, 25132 '../internals/well-known-symbol-wrapped': 163 25133 } 25134 ], 25135 215: [ 25136 function (_dereq_, module, exports) { 25137 'use strict'; 25138 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25139 var $copyWithin = _dereq_('../internals/array-copy-within'); 25140 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25141 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.copyWithin` method 25142 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.copywithin 25143 exportTypedArrayMethod('copyWithin', function copyWithin(target, start /* , end */ 25144 ) { 25145 return $copyWithin.call(aTypedArray(this), target, start, arguments.length > 2 ? arguments[2] : undefined); 25146 }); 25147 }, 25148 { 25149 '../internals/array-buffer-view-core': 30, 25150 '../internals/array-copy-within': 32 25151 } 25152 ], 25153 216: [ 25154 function (_dereq_, module, exports) { 25155 'use strict'; 25156 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25157 var $every = _dereq_('../internals/array-iteration').every; 25158 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25159 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.every` method 25160 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.every 25161 exportTypedArrayMethod('every', function every(callbackfn /* , thisArg */ 25162 ) { 25163 return $every(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined); 25164 }); 25165 }, 25166 { 25167 '../internals/array-buffer-view-core': 30, 25168 '../internals/array-iteration': 37 25169 } 25170 ], 25171 217: [
25172 function (_dereq_, module, exports) { 25173 'use strict'; 25174 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25175 var $fill = _dereq_('../internals/array-fill'); 25176 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25177 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.fill` method 25178 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.fill 25179 // eslint-disable-next-line no-unused-vars 25180 exportTypedArrayMethod('fill', function fill(value /* , start, end */ 25181 ) { 25182 return $fill.apply(aTypedArray(this), arguments); 25183 }); 25184 }, 25185 { 25186 '../internals/array-buffer-view-core': 30, 25187 '../internals/array-fill': 33 25188 } 25189 ], 25190 218: [ 25191 function (_dereq_, module, exports) { 25192 'use strict'; 25193 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25194 var $filter = _dereq_('../internals/array-iteration').filter; 25195 var speciesConstructor = _dereq_('../internals/species-constructor'); 25196 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25197 var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; 25198 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.filter` method 25199 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.filter 25200 exportTypedArrayMethod('filter', function filter(callbackfn /* , thisArg */ 25201 ) { 25202 var list = $filter(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined); 25203 var C = speciesConstructor(this, this.constructor); 25204 var index = 0; 25205 var length = list.length; 25206 var result = new (aTypedArrayConstructor(C)) (length); 25207 while (length > index) result[index] = list[index++]; 25208 return result; 25209 }); 25210 }, 25211 { 25212 '../internals/array-buffer-view-core': 30, 25213 '../internals/array-iteration': 37, 25214 '../internals/species-constructor': 139 25215 } 25216 ], 25217 219: [ 25218 function (_dereq_, module, exports) { 25219 'use strict'; 25220 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25221 var $findIndex = _dereq_('../internals/array-iteration').findIndex; 25222 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25223 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.findIndex` method 25224 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.findindex 25225 exportTypedArrayMethod('findIndex', function findIndex(predicate /* , thisArg */ 25226 ) { 25227 return $findIndex(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined); 25228 }); 25229 }, 25230 { 25231 '../internals/array-buffer-view-core': 30, 25232 '../internals/array-iteration': 37 25233 } 25234 ], 25235 220: [ 25236 function (_dereq_, module, exports) { 25237 'use strict'; 25238 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25239 var $find = _dereq_('../internals/array-iteration').find; 25240 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25241 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.find` method 25242 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.find 25243 exportTypedArrayMethod('find', function find(predicate /* , thisArg */ 25244 ) { 25245 return $find(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined); 25246 }); 25247 }, 25248 { 25249 '../internals/array-buffer-view-core': 30, 25250 '../internals/array-iteration': 37 25251 } 25252 ], 25253 221: [ 25254 function (_dereq_, module, exports) { 25255 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Float32Array` constructor 25256 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25257 createTypedArrayConstructor('Float32', function (init) { 25258 return function Float32Array(data, byteOffset, length) { 25259 return init(this, data, byteOffset, length); 25260 }; 25261 }); 25262 }, 25263 { 25264 '../internals/typed-array-constructor': 158 25265 } 25266 ], 25267 222: [
vendor: 4,146 bytes, lines 25268-25363
25268 function (_dereq_, module, exports) { 25269 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Float64Array` constructor 25270 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25271 createTypedArrayConstructor('Float64', function (init) { 25272 return function Float64Array(data, byteOffset, length) { 25273 return init(this, data, byteOffset, length); 25274 }; 25275 }); 25276 }, 25277 { 25278 '../internals/typed-array-constructor': 158 25279 } 25280 ], 25281 223: [ 25282 function (_dereq_, module, exports) { 25283 'use strict'; 25284 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25285 var $forEach = _dereq_('../internals/array-iteration').forEach; 25286 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25287 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.forEach` method 25288 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.foreach 25289 exportTypedArrayMethod('forEach', function forEach(callbackfn /* , thisArg */ 25290 ) { 25291 $forEach(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined); 25292 }); 25293 }, 25294 { 25295 '../internals/array-buffer-view-core': 30, 25296 '../internals/array-iteration': 37 25297 } 25298 ], 25299 224: [ 25300 function (_dereq_, module, exports) { 25301 'use strict'; 25302 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25303 var $includes = _dereq_('../internals/array-includes').includes; 25304 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25305 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.includes` method 25306 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.includes 25307 exportTypedArrayMethod('includes', function includes(searchElement /* , fromIndex */ 25308 ) { 25309 return $includes(aTypedArray(this), searchElement, arguments.length > 1 ? arguments[1] : undefined); 25310 }); 25311 }, 25312 { 25313 '../internals/array-buffer-view-core': 30, 25314 '../internals/array-includes': 36 25315 } 25316 ], 25317 225: [ 25318 function (_dereq_, module, exports) { 25319 'use strict'; 25320 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25321 var $indexOf = _dereq_('../internals/array-includes').indexOf; 25322 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25323 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.indexOf` method 25324 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.indexof 25325 exportTypedArrayMethod('indexOf', function indexOf(searchElement /* , fromIndex */ 25326 ) { 25327 return $indexOf(aTypedArray(this), searchElement, arguments.length > 1 ? arguments[1] : undefined); 25328 }); 25329 }, 25330 { 25331 '../internals/array-buffer-view-core': 30, 25332 '../internals/array-includes': 36 25333 } 25334 ], 25335 226: [ 25336 function (_dereq_, module, exports) { 25337 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Int16Array` constructor 25338 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25339 createTypedArrayConstructor('Int16', function (init) { 25340 return function Int16Array(data, byteOffset, length) { 25341 return init(this, data, byteOffset, length); 25342 }; 25343 }); 25344 }, 25345 { 25346 '../internals/typed-array-constructor': 158 25347 } 25348 ], 25349 227: [ 25350 function (_dereq_, module, exports) { 25351 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Int32Array` constructor 25352 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25353 createTypedArrayConstructor('Int32', function (init) { 25354 return function Int32Array(data, byteOffset, length) { 25355 return init(this, data, byteOffset, length); 25356 }; 25357 }); 25358 }, 25359 { 25360 '../internals/typed-array-constructor': 158 25361 } 25362 ], 25363 228: [
25364 function (_dereq_, module, exports) { 25365 'use strict'; 25366 var global = _dereq_('../internals/global'); 25367 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25368 var ArrayIterators = _dereq_('../modules/es.array.iterator'); 25369 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 25370 var ITERATOR = wellKnownSymbol('iterator'); 25371 var Uint8Array = global.Uint8Array; 25372 var arrayValues = ArrayIterators.values; 25373 var arrayKeys = ArrayIterators.keys; 25374 var arrayEntries = ArrayIterators.entries; 25375 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25376 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; 25377 var nativeTypedArrayIterator = Uint8Array && Uint8Array.prototype[ITERATOR]; 25378 var CORRECT_ITER_NAME = !!nativeTypedArrayIterator && (nativeTypedArrayIterator.name == 'values' || nativeTypedArrayIterator.name == undefined); 25379 var typedArrayValues = function values() { 25380 return arrayValues.call(aTypedArray(this)); 25381 }; // `%TypedArray%.prototype.entries` method 25382 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.entries 25383 exportTypedArrayMethod('entries', function entries() { 25384 return arrayEntries.call(aTypedArray(this)); 25385 }); // `%TypedArray%.prototype.keys` method 25386 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.keys 25387 exportTypedArrayMethod('keys', function keys() { 25388 return arrayKeys.call(aTypedArray(this)); 25389 }); // `%TypedArray%.prototype.values` method 25390 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.values 25391 exportTypedArrayMethod('values', typedArrayValues, !CORRECT_ITER_NAME); // `%TypedArray%.prototype[@@iterator]` method 25392 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype-@@iterator 25393 exportTypedArrayMethod(ITERATOR, typedArrayValues, !CORRECT_ITER_NAME); 25394 }, 25395 { 25396 '../internals/array-buffer-view-core': 30, 25397 '../internals/global': 77, 25398 '../internals/well-known-symbol': 164, 25399 '../modules/es.array.iterator': 176 25400 } 25401 ], 25402 229: [ 25403 function (_dereq_, module, exports) { 25404 'use strict'; 25405 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25406 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25407 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; 25408 var $join = [ 25409 ].join; // `%TypedArray%.prototype.join` method 25410 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.join 25411 // eslint-disable-next-line no-unused-vars 25412 exportTypedArrayMethod('join', function join(separator) { 25413 return $join.apply(aTypedArray(this), arguments); 25414 }); 25415 }, 25416 { 25417 '../internals/array-buffer-view-core': 30 25418 } 25419 ], 25420 230: [ 25421 function (_dereq_, module, exports) { 25422 'use strict'; 25423 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25424 var $lastIndexOf = _dereq_('../internals/array-last-index-of'); 25425 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25426 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.lastIndexOf` method 25427 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.lastindexof 25428 // eslint-disable-next-line no-unused-vars 25429 exportTypedArrayMethod('lastIndexOf', function lastIndexOf(searchElement /* , fromIndex */ 25430 ) { 25431 return $lastIndexOf.apply(aTypedArray(this), arguments); 25432 }); 25433 }, 25434 { 25435 '../internals/array-buffer-view-core': 30, 25436 '../internals/array-last-index-of': 38 25437 } 25438 ], 25439 231: [ 25440 function (_dereq_, module, exports) { 25441 'use strict'; 25442 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25443 var $map = _dereq_('../internals/array-iteration').map; 25444 var speciesConstructor = _dereq_('../internals/species-constructor'); 25445 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25446 var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; 25447 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.map` method 25448 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.map 25449 exportTypedArrayMethod('map', function map(mapfn /* , thisArg */ 25450 ) { 25451 return $map(aTypedArray(this), mapfn, arguments.length > 1 ? arguments[1] : undefined, function (O, length) { 25452 return new (aTypedArrayConstructor(speciesConstructor(O, O.constructor))) (length); 25453 }); 25454 }); 25455 }, 25456 { 25457 '../internals/array-buffer-view-core': 30, 25458 '../internals/array-iteration': 37, 25459 '../internals/species-constructor': 139 25460 } 25461 ], 25462 232: [
vendor: 4,213 bytes, lines 25463-25560
25463 function (_dereq_, module, exports) { 25464 'use strict'; 25465 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25466 var $reduceRight = _dereq_('../internals/array-reduce').right; 25467 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25468 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.reduceRicht` method 25469 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduceright 25470 exportTypedArrayMethod('reduceRight', function reduceRight(callbackfn /* , initialValue */ 25471 ) { 25472 return $reduceRight(aTypedArray(this), callbackfn, arguments.length, arguments.length > 1 ? arguments[1] : undefined); 25473 }); 25474 }, 25475 { 25476 '../internals/array-buffer-view-core': 30, 25477 '../internals/array-reduce': 42 25478 } 25479 ], 25480 233: [ 25481 function (_dereq_, module, exports) { 25482 'use strict'; 25483 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25484 var $reduce = _dereq_('../internals/array-reduce').left; 25485 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25486 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.reduce` method 25487 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduce 25488 exportTypedArrayMethod('reduce', function reduce(callbackfn /* , initialValue */ 25489 ) { 25490 return $reduce(aTypedArray(this), callbackfn, arguments.length, arguments.length > 1 ? arguments[1] : undefined); 25491 }); 25492 }, 25493 { 25494 '../internals/array-buffer-view-core': 30, 25495 '../internals/array-reduce': 42 25496 } 25497 ], 25498 234: [ 25499 function (_dereq_, module, exports) { 25500 'use strict'; 25501 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25502 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25503 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; 25504 var floor = Math.floor; // `%TypedArray%.prototype.reverse` method 25505 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reverse 25506 exportTypedArrayMethod('reverse', function reverse() { 25507 var that = this; 25508 var length = aTypedArray(that).length; 25509 var middle = floor(length / 2); 25510 var index = 0; 25511 var value; 25512 while (index < middle) { 25513 value = that[index]; 25514 that[index++] = that[--length]; 25515 that[length] = value; 25516 } 25517 return that; 25518 }); 25519 }, 25520 { 25521 '../internals/array-buffer-view-core': 30 25522 } 25523 ], 25524 235: [ 25525 function (_dereq_, module, exports) { 25526 'use strict'; 25527 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25528 var toLength = _dereq_('../internals/to-length'); 25529 var toOffset = _dereq_('../internals/to-offset'); 25530 var toObject = _dereq_('../internals/to-object'); 25531 var fails = _dereq_('../internals/fails'); 25532 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25533 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; 25534 var FORCED = fails(function () { 25535 // eslint-disable-next-line no-undef 25536 new Int8Array(1).set({ 25537 }); 25538 }); // `%TypedArray%.prototype.set` method 25539 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.set 25540 exportTypedArrayMethod('set', function set(arrayLike /* , offset */ 25541 ) { 25542 aTypedArray(this); 25543 var offset = toOffset(arguments.length > 1 ? arguments[1] : undefined, 1); 25544 var length = this.length; 25545 var src = toObject(arrayLike); 25546 var len = toLength(src.length); 25547 var index = 0; 25548 if (len + offset > length) throw RangeError('Wrong length'); 25549 while (index < len) this[offset + index] = src[index++]; 25550 }, FORCED); 25551 }, 25552 { 25553 '../internals/array-buffer-view-core': 30, 25554 '../internals/fails': 69, 25555 '../internals/to-length': 152, 25556 '../internals/to-object': 153, 25557 '../internals/to-offset': 154 25558 } 25559 ], 25560 236: [
25561 function (_dereq_, module, exports) { 25562 'use strict'; 25563 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25564 var speciesConstructor = _dereq_('../internals/species-constructor'); 25565 var fails = _dereq_('../internals/fails'); 25566 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25567 var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; 25568 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; 25569 var $slice = [ 25570 ].slice; 25571 var FORCED = fails(function () { 25572 // eslint-disable-next-line no-undef 25573 new Int8Array(1).slice(); 25574 }); // `%TypedArray%.prototype.slice` method 25575 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.slice 25576 exportTypedArrayMethod('slice', function slice(start, end) { 25577 var list = $slice.call(aTypedArray(this), start, end); 25578 var C = speciesConstructor(this, this.constructor); 25579 var index = 0; 25580 var length = list.length; 25581 var result = new (aTypedArrayConstructor(C)) (length); 25582 while (length > index) result[index] = list[index++]; 25583 return result; 25584 }, FORCED); 25585 }, 25586 { 25587 '../internals/array-buffer-view-core': 30, 25588 '../internals/fails': 69, 25589 '../internals/species-constructor': 139 25590 } 25591 ], 25592 237: [ 25593 function (_dereq_, module, exports) { 25594 'use strict'; 25595 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25596 var $some = _dereq_('../internals/array-iteration').some; 25597 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25598 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.some` method 25599 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.some 25600 exportTypedArrayMethod('some', function some(callbackfn /* , thisArg */ 25601 ) { 25602 return $some(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined); 25603 }); 25604 }, 25605 { 25606 '../internals/array-buffer-view-core': 30, 25607 '../internals/array-iteration': 37 25608 } 25609 ], 25610 238: [ 25611 function (_dereq_, module, exports) { 25612 'use strict'; 25613 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25614 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25615 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; 25616 var $sort = [ 25617 ].sort; // `%TypedArray%.prototype.sort` method 25618 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.sort 25619 exportTypedArrayMethod('sort', function sort(comparefn) { 25620 return $sort.call(aTypedArray(this), comparefn); 25621 }); 25622 }, 25623 { 25624 '../internals/array-buffer-view-core': 30 25625 } 25626 ], 25627 239: [ 25628 function (_dereq_, module, exports) { 25629 'use strict'; 25630 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25631 var toLength = _dereq_('../internals/to-length'); 25632 var toAbsoluteIndex = _dereq_('../internals/to-absolute-index'); 25633 var speciesConstructor = _dereq_('../internals/species-constructor'); 25634 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25635 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; // `%TypedArray%.prototype.subarray` method 25636 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.subarray 25637 exportTypedArrayMethod('subarray', function subarray(begin, end) { 25638 var O = aTypedArray(this); 25639 var length = O.length; 25640 var beginIndex = toAbsoluteIndex(begin, length); 25641 return new (speciesConstructor(O, O.constructor)) (O.buffer, O.byteOffset + beginIndex * O.BYTES_PER_ELEMENT, toLength((end === undefined ? length : toAbsoluteIndex(end, length)) - beginIndex)); 25642 }); 25643 }, 25644 { 25645 '../internals/array-buffer-view-core': 30, 25646 '../internals/species-constructor': 139, 25647 '../internals/to-absolute-index': 148, 25648 '../internals/to-length': 152 25649 } 25650 ], 25651 240: [
vendor: 4,230 bytes, lines 25652-25759
25652 function (_dereq_, module, exports) { 25653 'use strict'; 25654 var global = _dereq_('../internals/global'); 25655 var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core'); 25656 var fails = _dereq_('../internals/fails'); 25657 var Int8Array = global.Int8Array; 25658 var aTypedArray = ArrayBufferViewCore.aTypedArray; 25659 var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; 25660 var $toLocaleString = [ 25661 ].toLocaleString; 25662 var $slice = [ 25663 ].slice; // iOS Safari 6.x fails here 25664 var TO_LOCALE_STRING_BUG = !!Int8Array && fails(function () { 25665 $toLocaleString.call(new Int8Array(1)); 25666 }); 25667 var FORCED = fails(function () { 25668 return [1, 25669 2].toLocaleString() != new Int8Array([1, 25670 2]).toLocaleString(); 25671 }) || !fails(function () { 25672 Int8Array.prototype.toLocaleString.call([1, 25673 2]); 25674 }); // `%TypedArray%.prototype.toLocaleString` method 25675 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.tolocalestring 25676 exportTypedArrayMethod('toLocaleString', function toLocaleString() { 25677 return $toLocaleString.apply(TO_LOCALE_STRING_BUG ? $slice.call(aTypedArray(this)) : aTypedArray(this), arguments); 25678 }, FORCED); 25679 }, 25680 { 25681 '../internals/array-buffer-view-core': 30, 25682 '../internals/fails': 69, 25683 '../internals/global': 77 25684 } 25685 ], 25686 241: [ 25687 function (_dereq_, module, exports) { 25688 'use strict'; 25689 var exportTypedArrayMethod = _dereq_('../internals/array-buffer-view-core').exportTypedArrayMethod; 25690 var fails = _dereq_('../internals/fails'); 25691 var global = _dereq_('../internals/global'); 25692 var Uint8Array = global.Uint8Array; 25693 var Uint8ArrayPrototype = Uint8Array && Uint8Array.prototype || { 25694 }; 25695 var arrayToString = [ 25696 ].toString; 25697 var arrayJoin = [ 25698 ].join; 25699 if (fails(function () { 25700 arrayToString.call({ 25701 }); 25702 })) { 25703 arrayToString = function toString() { 25704 return arrayJoin.call(this); 25705 }; 25706 } 25707 var IS_NOT_ARRAY_METHOD = Uint8ArrayPrototype.toString != arrayToString; // `%TypedArray%.prototype.toString` method 25708 // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.tostring 25709 exportTypedArrayMethod('toString', arrayToString, IS_NOT_ARRAY_METHOD); 25710 }, 25711 { 25712 '../internals/array-buffer-view-core': 30, 25713 '../internals/fails': 69, 25714 '../internals/global': 77 25715 } 25716 ], 25717 242: [ 25718 function (_dereq_, module, exports) { 25719 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Uint16Array` constructor 25720 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25721 createTypedArrayConstructor('Uint16', function (init) { 25722 return function Uint16Array(data, byteOffset, length) { 25723 return init(this, data, byteOffset, length); 25724 }; 25725 }); 25726 }, 25727 { 25728 '../internals/typed-array-constructor': 158 25729 } 25730 ], 25731 243: [ 25732 function (_dereq_, module, exports) { 25733 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Uint32Array` constructor 25734 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25735 createTypedArrayConstructor('Uint32', function (init) { 25736 return function Uint32Array(data, byteOffset, length) { 25737 return init(this, data, byteOffset, length); 25738 }; 25739 }); 25740 }, 25741 { 25742 '../internals/typed-array-constructor': 158 25743 } 25744 ], 25745 244: [ 25746 function (_dereq_, module, exports) { 25747 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Uint8Array` constructor 25748 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25749 createTypedArrayConstructor('Uint8', function (init) { 25750 return function Uint8Array(data, byteOffset, length) { 25751 return init(this, data, byteOffset, length); 25752 }; 25753 }); 25754 }, 25755 { 25756 '../internals/typed-array-constructor': 158 25757 } 25758 ], 25759 245: [
25760 function (_dereq_, module, exports) { 25761 var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor'); // `Uint8ClampedArray` constructor 25762 // https://tc39.github.io/ecma262/#sec-typedarray-objects 25763 createTypedArrayConstructor('Uint8', function (init) { 25764 return function Uint8ClampedArray(data, byteOffset, length) { 25765 return init(this, data, byteOffset, length); 25766 }; 25767 }, true); 25768 }, 25769 { 25770 '../internals/typed-array-constructor': 158 25771 } 25772 ], 25773 246: [ 25774 function (_dereq_, module, exports) { 25775 'use strict'; 25776 var global = _dereq_('../internals/global'); 25777 var redefineAll = _dereq_('../internals/redefine-all'); 25778 var InternalMetadataModule = _dereq_('../internals/internal-metadata'); 25779 var collection = _dereq_('../internals/collection'); 25780 var collectionWeak = _dereq_('../internals/collection-weak'); 25781 var isObject = _dereq_('../internals/is-object'); 25782 var enforceIternalState = _dereq_('../internals/internal-state').enforce; 25783 var NATIVE_WEAK_MAP = _dereq_('../internals/native-weak-map'); 25784 var IS_IE11 = !global.ActiveXObject && 'ActiveXObject' in global; 25785 var isExtensible = Object.isExtensible; 25786 var InternalWeakMap; 25787 var wrapper = function (init) { 25788 return function WeakMap() { 25789 return init(this, arguments.length ? arguments[0] : undefined); 25790 }; 25791 }; // `WeakMap` constructor 25792 // https://tc39.github.io/ecma262/#sec-weakmap-constructor 25793 var $WeakMap = module.exports = collection('WeakMap', wrapper, collectionWeak); // IE11 WeakMap frozen keys fix 25794 // We can't use feature detection because it crash some old IE builds 25795 // https://github.com/zloirock/core-js/issues/485 25796 if (NATIVE_WEAK_MAP && IS_IE11) { 25797 InternalWeakMap = collectionWeak.getConstructor(wrapper, 'WeakMap', true); 25798 InternalMetadataModule.REQUIRED = true; 25799 var WeakMapPrototype = $WeakMap.prototype; 25800 var nativeDelete = WeakMapPrototype['delete']; 25801 var nativeHas = WeakMapPrototype.has; 25802 var nativeGet = WeakMapPrototype.get; 25803 var nativeSet = WeakMapPrototype.set; 25804 redefineAll(WeakMapPrototype, { 25805 'delete': function (key) { 25806 if (isObject(key) && !isExtensible(key)) { 25807 var state = enforceIternalState(this); 25808 if (!state.frozen) state.frozen = new InternalWeakMap(); 25809 return nativeDelete.call(this, key) || state.frozen['delete'](key); 25810 } 25811 return nativeDelete.call(this, key); 25812 }, 25813 has: function has(key) { 25814 if (isObject(key) && !isExtensible(key)) { 25815 var state = enforceIternalState(this); 25816 if (!state.frozen) state.frozen = new InternalWeakMap(); 25817 return nativeHas.call(this, key) || state.frozen.has(key); 25818 } 25819 return nativeHas.call(this, key); 25820 }, 25821 get: function get(key) { 25822 if (isObject(key) && !isExtensible(key)) { 25823 var state = enforceIternalState(this); 25824 if (!state.frozen) state.frozen = new InternalWeakMap(); 25825 return nativeHas.call(this, key) ? nativeGet.call(this, key) : state.frozen.get(key); 25826 } 25827 return nativeGet.call(this, key); 25828 }, 25829 set: function set(key, value) { 25830 if (isObject(key) && !isExtensible(key)) { 25831 var state = enforceIternalState(this); 25832 if (!state.frozen) state.frozen = new InternalWeakMap(); 25833 nativeHas.call(this, key) ? nativeSet.call(this, key, value) : state.frozen.set(key, value); 25834 } else nativeSet.call(this, key, value); 25835 return this; 25836 } 25837 }); 25838 } 25839 }, 25840 { 25841 '../internals/collection': 50, 25842 '../internals/collection-weak': 49, 25843 '../internals/global': 77, 25844 '../internals/internal-metadata': 87, 25845 '../internals/internal-state': 88, 25846 '../internals/is-object': 92, 25847 '../internals/native-weak-map': 103, 25848 '../internals/redefine-all': 125 25849 } 25850 ], 25851 247: [
vendor: 5,385 bytes, lines 25852-25950
25852 function (_dereq_, module, exports) { 25853 var global = _dereq_('../internals/global'); 25854 var DOMIterables = _dereq_('../internals/dom-iterables'); 25855 var forEach = _dereq_('../internals/array-for-each'); 25856 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 25857 for (var COLLECTION_NAME in DOMIterables) { 25858 var Collection = global[COLLECTION_NAME]; 25859 var CollectionPrototype = Collection && Collection.prototype; // some Chrome versions have non-configurable methods on DOMTokenList 25860 if (CollectionPrototype && CollectionPrototype.forEach !== forEach) try { 25861 createNonEnumerableProperty(CollectionPrototype, 'forEach', forEach); 25862 } catch (error) { 25863 CollectionPrototype.forEach = forEach; 25864 } 25865 } 25866 }, 25867 { 25868 '../internals/array-for-each': 34, 25869 '../internals/create-non-enumerable-property': 56, 25870 '../internals/dom-iterables': 63, 25871 '../internals/global': 77 25872 } 25873 ], 25874 248: [ 25875 function (_dereq_, module, exports) { 25876 var global = _dereq_('../internals/global'); 25877 var DOMIterables = _dereq_('../internals/dom-iterables'); 25878 var ArrayIteratorMethods = _dereq_('../modules/es.array.iterator'); 25879 var createNonEnumerableProperty = _dereq_('../internals/create-non-enumerable-property'); 25880 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 25881 var ITERATOR = wellKnownSymbol('iterator'); 25882 var TO_STRING_TAG = wellKnownSymbol('toStringTag'); 25883 var ArrayValues = ArrayIteratorMethods.values; 25884 for (var COLLECTION_NAME in DOMIterables) { 25885 var Collection = global[COLLECTION_NAME]; 25886 var CollectionPrototype = Collection && Collection.prototype; 25887 if (CollectionPrototype) { 25888 // some Chrome versions have non-configurable methods on DOMTokenList 25889 if (CollectionPrototype[ITERATOR] !== ArrayValues) try { 25890 createNonEnumerableProperty(CollectionPrototype, ITERATOR, ArrayValues); 25891 } catch (error) { 25892 CollectionPrototype[ITERATOR] = ArrayValues; 25893 } 25894 if (!CollectionPrototype[TO_STRING_TAG]) { 25895 createNonEnumerableProperty(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME); 25896 } 25897 if (DOMIterables[COLLECTION_NAME]) for (var METHOD_NAME in ArrayIteratorMethods) { 25898 // some Chrome versions have non-configurable methods on DOMTokenList 25899 if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) try { 25900 createNonEnumerableProperty(CollectionPrototype, METHOD_NAME, ArrayIteratorMethods[METHOD_NAME]); 25901 } catch (error) { 25902 CollectionPrototype[METHOD_NAME] = ArrayIteratorMethods[METHOD_NAME]; 25903 } 25904 } 25905 } 25906 } 25907 }, 25908 { 25909 '../internals/create-non-enumerable-property': 56, 25910 '../internals/dom-iterables': 63, 25911 '../internals/global': 77, 25912 '../internals/well-known-symbol': 164, 25913 '../modules/es.array.iterator': 176 25914 } 25915 ], 25916 249: [ 25917 function (_dereq_, module, exports) { 25918 'use strict'; // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env` 25919 _dereq_('../modules/es.array.iterator'); 25920 var $ = _dereq_('../internals/export'); 25921 var getBuiltIn = _dereq_('../internals/get-built-in'); 25922 var USE_NATIVE_URL = _dereq_('../internals/native-url'); 25923 var redefine = _dereq_('../internals/redefine'); 25924 var redefineAll = _dereq_('../internals/redefine-all'); 25925 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 25926 var createIteratorConstructor = _dereq_('../internals/create-iterator-constructor'); 25927 var InternalStateModule = _dereq_('../internals/internal-state'); 25928 var anInstance = _dereq_('../internals/an-instance'); 25929 var hasOwn = _dereq_('../internals/has'); 25930 var bind = _dereq_('../internals/function-bind-context'); 25931 var classof = _dereq_('../internals/classof'); 25932 var anObject = _dereq_('../internals/an-object'); 25933 var isObject = _dereq_('../internals/is-object'); 25934 var create = _dereq_('../internals/object-create'); 25935 var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor'); 25936 var getIterator = _dereq_('../internals/get-iterator'); 25937 var getIteratorMethod = _dereq_('../internals/get-iterator-method'); 25938 var wellKnownSymbol = _dereq_('../internals/well-known-symbol'); 25939 var $fetch = getBuiltIn('fetch'); 25940 var Headers = getBuiltIn('Headers'); 25941 var ITERATOR = wellKnownSymbol('iterator'); 25942 var URL_SEARCH_PARAMS = 'URLSearchParams'; 25943 var URL_SEARCH_PARAMS_ITERATOR = URL_SEARCH_PARAMS + 'Iterator'; 25944 var setInternalState = InternalStateModule.set; 25945 var getInternalParamsState = InternalStateModule.getterFor(URL_SEARCH_PARAMS); 25946 var getInternalIteratorState = InternalStateModule.getterFor(URL_SEARCH_PARAMS_ITERATOR); 25947 var plus = /\+/g; 25948 var sequences = Array(4); 25949 var percentSequence = function (bytes) { 25950 return sequences[bytes - 1] || (sequences[bytes - 1] = RegExp('((?:%[\\da-f]{2}){' + bytes + '}
vendor: 4,110 bytes, lines 25950-26064
25950)', 'gi')); 25951 }; 25952 var percentDecode = function (sequence) { 25953 try { 25954 return decodeURIComponent(sequence); 25955 } catch (error) { 25956 return sequence; 25957 } 25958 }; 25959 var deserialize = function (it) { 25960 var result = it.replace(plus, ' '); 25961 var bytes = 4; 25962 try { 25963 return decodeURIComponent(result); 25964 } catch (error) { 25965 while (bytes) { 25966 result = result.replace(percentSequence(bytes--), percentDecode); 25967 } 25968 return result; 25969 } 25970 }; 25971 var find = /[!'()~]|%20/g; 25972 var replace = { 25973 '!': '%21', 25974 '\'': '%27', 25975 '(': '%28', 25976 ')': '%29', 25977 '~': '%7E', 25978 '%20': '+' 25979 }; 25980 var replacer = function (match) { 25981 return replace[match]; 25982 }; 25983 var serialize = function (it) { 25984 return encodeURIComponent(it).replace(find, replacer); 25985 }; 25986 var parseSearchParams = function (result, query) { 25987 if (query) { 25988 var attributes = query.split('&'); 25989 var index = 0; 25990 var attribute, 25991 entry; 25992 while (index < attributes.length) { 25993 attribute = attributes[index++]; 25994 if (attribute.length) { 25995 entry = attribute.split('='); 25996 result.push({ 25997 key: deserialize(entry.shift()), 25998 value: deserialize(entry.join('=')) 25999 }); 26000 } 26001 } 26002 } 26003 }; 26004 var updateSearchParams = function (query) { 26005 this.entries.length = 0; 26006 parseSearchParams(this.entries, query); 26007 }; 26008 var validateArgumentsLength = function (passed, required) { 26009 if (passed < required) throw TypeError('Not enough arguments'); 26010 }; 26011 var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params, kind) { 26012 setInternalState(this, { 26013 type: URL_SEARCH_PARAMS_ITERATOR, 26014 iterator: getIterator(getInternalParamsState(params).entries), 26015 kind: kind 26016 }); 26017 }, 'Iterator', function next() { 26018 var state = getInternalIteratorState(this); 26019 var kind = state.kind; 26020 var step = state.iterator.next(); 26021 var entry = step.value; 26022 if (!step.done) { 26023 step.value = kind === 'keys' ? entry.key : kind === 'values' ? entry.value : [ 26024 entry.key, 26025 entry.value 26026 ]; 26027 } 26028 return step; 26029 }); // `URLSearchParams` constructor 26030 // https://url.spec.whatwg.org/#interface-urlsearchparams 26031 var URLSearchParamsConstructor = function URLSearchParams() /* init */ 26032 { 26033 anInstance(this, URLSearchParamsConstructor, URL_SEARCH_PARAMS); 26034 var init = arguments.length > 0 ? arguments[0] : undefined; 26035 var that = this; 26036 var entries = [ 26037 ]; 26038 var iteratorMethod, 26039 iterator, 26040 next, 26041 step, 26042 entryIterator, 26043 entryNext, 26044 first, 26045 second, 26046 key; 26047 setInternalState(that, { 26048 type: URL_SEARCH_PARAMS, 26049 entries: entries, 26050 updateURL: function () { 26051 /* empty */ 26052 }, 26053 updateSearchParams: updateSearchParams 26054 }); 26055 if (init !== undefined) { 26056 if (isObject(init)) { 26057 iteratorMethod = getIteratorMethod(init); 26058 if (typeof iteratorMethod === 'function') { 26059 iterator = iteratorMethod.call(init); 26060 next = iterator.next; 26061 while (!(step = next.call(iterator)).done) { 26062 entryIterator = getIterator(anObject(step.value)); 26063 entryNext = entryIterator.next; 26064 if ((first = entryNext.call(entryIterator)).done || (second = entryNext.call(entryIterator)).done || !entryNext.call(entryIterator).done) throw TypeError('Expected sequence with length 2');
vendor: 9,603 bytes, lines 26065-26307
26065 entries.push({ 26066 key: first.value + '', 26067 value: second.value + '' 26068 }); 26069 } 26070 } else for (key in init) if (hasOwn(init, key)) entries.push({ 26071 key: key, 26072 value: init[key] + '' 26073 }); 26074 } else { 26075 parseSearchParams(entries, typeof init === 'string' ? init.charAt(0) === '?' ? init.slice(1) : init : init + ''); 26076 } 26077 } 26078 }; 26079 var URLSearchParamsPrototype = URLSearchParamsConstructor.prototype; 26080 redefineAll(URLSearchParamsPrototype, { 26081 // `URLSearchParams.prototype.appent` method 26082 // https://url.spec.whatwg.org/#dom-urlsearchparams-append 26083 append: function append(name, value) { 26084 validateArgumentsLength(arguments.length, 2); 26085 var state = getInternalParamsState(this); 26086 state.entries.push({ 26087 key: name + '', 26088 value: value + '' 26089 }); 26090 state.updateURL(); 26091 }, 26092 // `URLSearchParams.prototype.delete` method 26093 // https://url.spec.whatwg.org/#dom-urlsearchparams-delete 26094 'delete': function (name) { 26095 validateArgumentsLength(arguments.length, 1); 26096 var state = getInternalParamsState(this); 26097 var entries = state.entries; 26098 var key = name + ''; 26099 var index = 0; 26100 while (index < entries.length) { 26101 if (entries[index].key === key) entries.splice(index, 1); 26102 else index++; 26103 } 26104 state.updateURL(); 26105 }, 26106 // `URLSearchParams.prototype.get` method 26107 // https://url.spec.whatwg.org/#dom-urlsearchparams-get 26108 get: function get(name) { 26109 validateArgumentsLength(arguments.length, 1); 26110 var entries = getInternalParamsState(this).entries; 26111 var key = name + ''; 26112 var index = 0; 26113 for (; index < entries.length; index++) { 26114 if (entries[index].key === key) return entries[index].value; 26115 } 26116 return null; 26117 }, 26118 // `URLSearchParams.prototype.getAll` method 26119 // https://url.spec.whatwg.org/#dom-urlsearchparams-getall 26120 getAll: function getAll(name) { 26121 validateArgumentsLength(arguments.length, 1); 26122 var entries = getInternalParamsState(this).entries; 26123 var key = name + ''; 26124 var result = [ 26125 ]; 26126 var index = 0; 26127 for (; index < entries.length; index++) { 26128 if (entries[index].key === key) result.push(entries[index].value); 26129 } 26130 return result; 26131 }, 26132 // `URLSearchParams.prototype.has` method 26133 // https://url.spec.whatwg.org/#dom-urlsearchparams-has 26134 has: function has(name) { 26135 validateArgumentsLength(arguments.length, 1); 26136 var entries = getInternalParamsState(this).entries; 26137 var key = name + ''; 26138 var index = 0; 26139 while (index < entries.length) { 26140 if (entries[index++].key === key) return true; 26141 } 26142 return false; 26143 }, 26144 // `URLSearchParams.prototype.set` method 26145 // https://url.spec.whatwg.org/#dom-urlsearchparams-set 26146 set: function set(name, value) { 26147 validateArgumentsLength(arguments.length, 1); 26148 var state = getInternalParamsState(this); 26149 var entries = state.entries; 26150 var found = false; 26151 var key = name + ''; 26152 var val = value + ''; 26153 var index = 0; 26154 var entry; 26155 for (; index < entries.length; index++) { 26156 entry = entries[index]; 26157 if (entry.key === key) { 26158 if (found) entries.splice(index--, 1); 26159 else { 26160 found = true; 26161 entry.value = val; 26162 } 26163 } 26164 } 26165 if (!found) entries.push({ 26166 key: key, 26167 value: val 26168 }); 26169 state.updateURL(); 26170 }, 26171 // `URLSearchParams.prototype.sort` method 26172 // https://url.spec.whatwg.org/#dom-urlsearchparams-sort 26173 sort: function sort() { 26174 var state = getInternalParamsState(this); 26175 var entries = state.entries; // Array#sort is not stable in some engines 26176 var slice = entries.slice(); 26177 var entry, 26178 entriesIndex, 26179 sliceIndex; 26180 entries.length = 0; 26181 for (sliceIndex = 0; sliceIndex < slice.length; sliceIndex++) { 26182 entry = slice[sliceIndex]; 26183 for (entriesIndex = 0; entriesIndex < sliceIndex; entriesIndex++) { 26184 if (entries[entriesIndex].key > entry.key) { 26185 entries.splice(entriesIndex, 0, entry); 26186 break; 26187 } 26188 } 26189 if (entriesIndex === sliceIndex) entries.push(entry); 26190 } 26191 state.updateURL(); 26192 }, 26193 // `URLSearchParams.prototype.forEach` method 26194 forEach: function forEach(callback /* , thisArg */ 26195 ) { 26196 var entries = getInternalParamsState(this).entries; 26197 var boundFunction = bind(callback, arguments.length > 1 ? arguments[1] : undefined, 3); 26198 var index = 0; 26199 var entry; 26200 while (index < entries.length) { 26201 entry = entries[index++]; 26202 boundFunction(entry.value, entry.key, this); 26203 } 26204 }, 26205 // `URLSearchParams.prototype.keys` method 26206 keys: function keys() { 26207 return new URLSearchParamsIterator(this, 'keys'); 26208 }, 26209 // `URLSearchParams.prototype.values` method 26210 values: function values() { 26211 return new URLSearchParamsIterator(this, 'values'); 26212 }, 26213 // `URLSearchParams.prototype.entries` method 26214 entries: function entries() { 26215 return new URLSearchParamsIterator(this, 'entries'); 26216 } 26217 }, { 26218 enumerable: true 26219 }); // `URLSearchParams.prototype[@@iterator]` method 26220 redefine(URLSearchParamsPrototype, ITERATOR, URLSearchParamsPrototype.entries); // `URLSearchParams.prototype.toString` method 26221 // https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior 26222 redefine(URLSearchParamsPrototype, 'toString', function toString() { 26223 var entries = getInternalParamsState(this).entries; 26224 var result = [ 26225 ]; 26226 var index = 0; 26227 var entry; 26228 while (index < entries.length) { 26229 entry = entries[index++]; 26230 result.push(serialize(entry.key) + '=' + serialize(entry.value)); 26231 } 26232 return result.join('&'); 26233 }, { 26234 enumerable: true 26235 }); 26236 setToStringTag(URLSearchParamsConstructor, URL_SEARCH_PARAMS); 26237 $({ 26238 global: true, 26239 forced: !USE_NATIVE_URL 26240 }, { 26241 URLSearchParams: URLSearchParamsConstructor 26242 }); // Wrap `fetch` for correct work with polyfilled `URLSearchParams` 26243 // https://github.com/zloirock/core-js/issues/674 26244 if (!USE_NATIVE_URL && typeof $fetch == 'function' && typeof Headers == 'function') { 26245 $({ 26246 global: true, 26247 enumerable: true, 26248 forced: true 26249 }, { 26250 fetch: function fetch(input /* , init */ 26251 ) { 26252 var args = [ 26253 input 26254 ]; 26255 var init, 26256 body, 26257 headers; 26258 if (arguments.length > 1) { 26259 init = arguments[1]; 26260 if (isObject(init)) { 26261 body = init.body; 26262 if (classof(body) === URL_SEARCH_PARAMS) { 26263 headers = init.headers ? new Headers(init.headers) : new Headers(); 26264 if (!headers.has('content-type')) { 26265 headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); 26266 } 26267 init = create(init, { 26268 body: createPropertyDescriptor(0, String(body)), 26269 headers: createPropertyDescriptor(0, headers) 26270 }); 26271 } 26272 } 26273 args.push(init); 26274 } 26275 return $fetch.apply(this, args); 26276 } 26277 }); 26278 } 26279 module.exports = { 26280 URLSearchParams: URLSearchParamsConstructor, 26281 getState: getInternalParamsState 26282 }; 26283 }, 26284 { 26285 '../internals/an-instance': 27, 26286 '../internals/an-object': 28, 26287 '../internals/classof': 47, 26288 '../internals/create-iterator-constructor': 55, 26289 '../internals/create-property-descriptor': 57, 26290 '../internals/export': 68, 26291 '../internals/function-bind-context': 72, 26292 '../internals/get-built-in': 74, 26293 '../internals/get-iterator': 76, 26294 '../internals/get-iterator-method': 75, 26295 '../internals/has': 78, 26296 '../internals/internal-state': 88, 26297 '../internals/is-object': 92, 26298 '../internals/native-url': 102, 26299 '../internals/object-create': 108, 26300 '../internals/redefine': 126, 26301 '../internals/redefine-all': 125, 26302 '../internals/set-to-string-tag': 135, 26303 '../internals/well-known-symbol': 164, 26304 '../modules/es.array.iterator': 176 26305 } 26306 ], 26307 250: [
vendor: 4,208 bytes, lines 26308-26394
26308 function (_dereq_, module, exports) { 26309 'use strict'; // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env` 26310 _dereq_('../modules/es.string.iterator'); 26311 var $ = _dereq_('../internals/export'); 26312 var DESCRIPTORS = _dereq_('../internals/descriptors'); 26313 var USE_NATIVE_URL = _dereq_('../internals/native-url'); 26314 var global = _dereq_('../internals/global'); 26315 var defineProperties = _dereq_('../internals/object-define-properties'); 26316 var redefine = _dereq_('../internals/redefine'); 26317 var anInstance = _dereq_('../internals/an-instance'); 26318 var has = _dereq_('../internals/has'); 26319 var assign = _dereq_('../internals/object-assign'); 26320 var arrayFrom = _dereq_('../internals/array-from'); 26321 var codeAt = _dereq_('../internals/string-multibyte').codeAt; 26322 var toASCII = _dereq_('../internals/string-punycode-to-ascii'); 26323 var setToStringTag = _dereq_('../internals/set-to-string-tag'); 26324 var URLSearchParamsModule = _dereq_('../modules/web.url-search-params'); 26325 var InternalStateModule = _dereq_('../internals/internal-state'); 26326 var NativeURL = global.URL; 26327 var URLSearchParams = URLSearchParamsModule.URLSearchParams; 26328 var getInternalSearchParamsState = URLSearchParamsModule.getState; 26329 var setInternalState = InternalStateModule.set; 26330 var getInternalURLState = InternalStateModule.getterFor('URL'); 26331 var floor = Math.floor; 26332 var pow = Math.pow; 26333 var INVALID_AUTHORITY = 'Invalid authority'; 26334 var INVALID_SCHEME = 'Invalid scheme'; 26335 var INVALID_HOST = 'Invalid host'; 26336 var INVALID_PORT = 'Invalid port'; 26337 var ALPHA = /[A-Za-z]/; 26338 var ALPHANUMERIC = /[\d+-.A-Za-z]/; 26339 var DIGIT = /\d/; 26340 var HEX_START = /^(0x|0X)/; 26341 var OCT = /^[0-7]+$/; 26342 var DEC = /^\d+$/; 26343 var HEX = /^[\dA-Fa-f]+$/; // eslint-disable-next-line no-control-regex 26344 var FORBIDDEN_HOST_CODE_POINT = /[\u0000\u0009\u000A\u000D #%/:?@[\\]]/; // eslint-disable-next-line no-control-regex 26345 var FORBIDDEN_HOST_CODE_POINT_EXCLUDING_PERCENT = /[\u0000\u0009\u000A\u000D #/:?@[\\]]/; // eslint-disable-next-line no-control-regex 26346 var LEADING_AND_TRAILING_C0_CONTROL_OR_SPACE = /^[\u0000-\u001F ]+|[\u0000-\u001F ]+$/g; // eslint-disable-next-line no-control-regex 26347 var TAB_AND_NEW_LINE = /[\u0009\u000A\u000D]/g; 26348 var EOF; 26349 var parseHost = function (url, input) { 26350 var result, 26351 codePoints, 26352 index; 26353 if (input.charAt(0) == '[') { 26354 if (input.charAt(input.length - 1) != ']') return INVALID_HOST; 26355 result = parseIPv6(input.slice(1, - 1)); 26356 if (!result) return INVALID_HOST; 26357 url.host = result; // opaque host 26358 } else if (!isSpecial(url)) { 26359 if (FORBIDDEN_HOST_CODE_POINT_EXCLUDING_PERCENT.test(input)) return INVALID_HOST; 26360 result = ''; 26361 codePoints = arrayFrom(input); 26362 for (index = 0; index < codePoints.length; index++) { 26363 result += percentEncode(codePoints[index], C0ControlPercentEncodeSet); 26364 } 26365 url.host = result; 26366 } else { 26367 input = toASCII(input); 26368 if (FORBIDDEN_HOST_CODE_POINT.test(input)) return INVALID_HOST; 26369 result = parseIPv4(input); 26370 if (result === null) return INVALID_HOST; 26371 url.host = result; 26372 } 26373 }; 26374 var parseIPv4 = function (input) { 26375 var parts = input.split('.'); 26376 var partsLength, 26377 numbers, 26378 index, 26379 part, 26380 radix, 26381 number, 26382 ipv4; 26383 if (parts.length && parts[parts.length - 1] == '') { 26384 parts.pop(); 26385 } 26386 partsLength = parts.length; 26387 if (partsLength > 4) return input; 26388 numbers = [ 26389 ]; 26390 for (index = 0; index < partsLength; index++) { 26391 part = parts[index]; 26392 if (part == '') return input; 26393 radix = 10; 26394 if (part.length > 1 && part.charAt(0) == '0') {
vendor: 27,896 bytes, lines 26395-27121
26395 radix = HEX_START.test(part) ? 16 : 8; 26396 part = part.slice(radix == 8 ? 1 : 2); 26397 } 26398 if (part === '') { 26399 number = 0; 26400 } else { 26401 if (!(radix == 10 ? DEC : radix == 8 ? OCT : HEX).test(part)) return input; 26402 number = parseInt(part, radix); 26403 } 26404 numbers.push(number); 26405 } 26406 for (index = 0; index < partsLength; index++) { 26407 number = numbers[index]; 26408 if (index == partsLength - 1) { 26409 if (number >= pow(256, 5 - partsLength)) return null; 26410 } else if (number > 255) return null; 26411 } 26412 ipv4 = numbers.pop(); 26413 for (index = 0; index < numbers.length; index++) { 26414 ipv4 += numbers[index] * pow(256, 3 - index); 26415 } 26416 return ipv4; 26417 }; // eslint-disable-next-line max-statements 26418 var parseIPv6 = function (input) { 26419 var address = [ 26420 0, 26421 0, 26422 0, 26423 0, 26424 0, 26425 0, 26426 0, 26427 0 26428 ]; 26429 var pieceIndex = 0; 26430 var compress = null; 26431 var pointer = 0; 26432 var value, 26433 length, 26434 numbersSeen, 26435 ipv4Piece, 26436 number, 26437 swaps, 26438 swap; 26439 var char = function () { 26440 return input.charAt(pointer); 26441 }; 26442 if (char() == ':') { 26443 if (input.charAt(1) != ':') return; 26444 pointer += 2; 26445 pieceIndex++; 26446 compress = pieceIndex; 26447 } 26448 while (char()) { 26449 if (pieceIndex == 8) return; 26450 if (char() == ':') { 26451 if (compress !== null) return; 26452 pointer++; 26453 pieceIndex++; 26454 compress = pieceIndex; 26455 continue; 26456 } 26457 value = length = 0; 26458 while (length < 4 && HEX.test(char())) { 26459 value = value * 16 + parseInt(char(), 16); 26460 pointer++; 26461 length++; 26462 } 26463 if (char() == '.') { 26464 if (length == 0) return; 26465 pointer -= length; 26466 if (pieceIndex > 6) return; 26467 numbersSeen = 0; 26468 while (char()) { 26469 ipv4Piece = null; 26470 if (numbersSeen > 0) { 26471 if (char() == '.' && numbersSeen < 4) pointer++; 26472 else return; 26473 } 26474 if (!DIGIT.test(char())) return; 26475 while (DIGIT.test(char())) { 26476 number = parseInt(char(), 10); 26477 if (ipv4Piece === null) ipv4Piece = number; 26478 else if (ipv4Piece == 0) return; 26479 else ipv4Piece = ipv4Piece * 10 + number; 26480 if (ipv4Piece > 255) return; 26481 pointer++; 26482 } 26483 address[pieceIndex] = address[pieceIndex] * 256 + ipv4Piece; 26484 numbersSeen++; 26485 if (numbersSeen == 2 || numbersSeen == 4) pieceIndex++; 26486 } 26487 if (numbersSeen != 4) return; 26488 break; 26489 } else if (char() == ':') { 26490 pointer++; 26491 if (!char()) return; 26492 } else if (char()) return; 26493 address[pieceIndex++] = value; 26494 } 26495 if (compress !== null) { 26496 swaps = pieceIndex - compress; 26497 pieceIndex = 7; 26498 while (pieceIndex != 0 && swaps > 0) { 26499 swap = address[pieceIndex]; 26500 address[pieceIndex--] = address[compress + swaps - 1]; 26501 address[compress + --swaps] = swap; 26502 } 26503 } else if (pieceIndex != 8) return; 26504 return address; 26505 }; 26506 var findLongestZeroSequence = function (ipv6) { 26507 var maxIndex = null; 26508 var maxLength = 1; 26509 var currStart = null; 26510 var currLength = 0; 26511 var index = 0; 26512 for (; index < 8; index++) { 26513 if (ipv6[index] !== 0) { 26514 if (currLength > maxLength) { 26515 maxIndex = currStart; 26516 maxLength = currLength; 26517 } 26518 currStart = null; 26519 currLength = 0; 26520 } else { 26521 if (currStart === null) currStart = index; 26522 ++currLength; 26523 } 26524 } 26525 if (currLength > maxLength) { 26526 maxIndex = currStart; 26527 maxLength = currLength; 26528 } 26529 return maxIndex; 26530 }; 26531 var serializeHost = function (host) { 26532 var result, 26533 index, 26534 compress, 26535 ignore0; // ipv4 26536 if (typeof host == 'number') { 26537 result = [ 26538 ]; 26539 for (index = 0; index < 4; index++) { 26540 result.unshift(host % 256); 26541 host = floor(host / 256); 26542 } 26543 return result.join('.'); // ipv6 26544 } else if (typeof host == 'object') { 26545 result = ''; 26546 compress = findLongestZeroSequence(host); 26547 for (index = 0; index < 8; index++) { 26548 if (ignore0 && host[index] === 0) continue; 26549 if (ignore0) ignore0 = false; 26550 if (compress === index) { 26551 result += index ? ':' : '::'; 26552 ignore0 = true; 26553 } else { 26554 result += host[index].toString(16); 26555 if (index < 7) result += ':'; 26556 } 26557 } 26558 return '[' + result + ']'; 26559 } 26560 return host; 26561 }; 26562 var C0ControlPercentEncodeSet = { 26563 }; 26564 var fragmentPercentEncodeSet = assign({ 26565 }, C0ControlPercentEncodeSet, { 26566 ' ': 1, 26567 '"': 1, 26568 '<': 1, 26569 '>': 1, 26570 '`': 1 26571 }); 26572 var pathPercentEncodeSet = assign({ 26573 }, fragmentPercentEncodeSet, { 26574 '#': 1, 26575 '?': 1, 26576 '{': 1, 26577 '}': 1 26578 }); 26579 var userinfoPercentEncodeSet = assign({ 26580 }, pathPercentEncodeSet, { 26581 '/': 1, 26582 ':': 1, 26583 ';': 1, 26584 '=': 1, 26585 '@': 1, 26586 '[': 1, 26587 '\\': 1, 26588 ']': 1, 26589 '^': 1, 26590 '|': 1 26591 }); 26592 var percentEncode = function (char, set) { 26593 var code = codeAt(char, 0); 26594 return code > 32 && code < 127 && !has(set, char) ? char : encodeURIComponent(char); 26595 }; 26596 var specialSchemes = { 26597 ftp: 21, 26598 file: null, 26599 http: 80, 26600 https: 443, 26601 ws: 80, 26602 wss: 443 26603 }; 26604 var isSpecial = function (url) { 26605 return has(specialSchemes, url.scheme); 26606 }; 26607 var includesCredentials = function (url) { 26608 return url.username != '' || url.password != ''; 26609 }; 26610 var cannotHaveUsernamePasswordPort = function (url) { 26611 return !url.host || url.cannotBeABaseURL || url.scheme == 'file'; 26612 }; 26613 var isWindowsDriveLetter = function (string, normalized) { 26614 var second; 26615 return string.length == 2 && ALPHA.test(string.charAt(0)) && ((second = string.charAt(1)) == ':' || !normalized && second == '|'); 26616 }; 26617 var startsWithWindowsDriveLetter = function (string) { 26618 var third; 26619 return string.length > 1 && isWindowsDriveLetter(string.slice(0, 2)) && (string.length == 2 || (third = string.charAt(2)) === '/' || third === '\\' || third === '?' || third === '#'); 26620 }; 26621 var shortenURLsPath = function (url) { 26622 var path = url.path; 26623 var pathSize = path.length; 26624 if (pathSize && (url.scheme != 'file' || pathSize != 1 || !isWindowsDriveLetter(path[0], true))) { 26625 path.pop(); 26626 } 26627 }; 26628 var isSingleDot = function (segment) { 26629 return segment === '.' || segment.toLowerCase() === '%2e'; 26630 }; 26631 var isDoubleDot = function (segment) { 26632 segment = segment.toLowerCase(); 26633 return segment === '..' || segment === '%2e.' || segment === '.%2e' || segment === '%2e%2e'; 26634 }; // States: 26635 var SCHEME_START = { 26636 }; 26637 var SCHEME = { 26638 }; 26639 var NO_SCHEME = { 26640 }; 26641 var SPECIAL_RELATIVE_OR_AUTHORITY = { 26642 }; 26643 var PATH_OR_AUTHORITY = { 26644 }; 26645 var RELATIVE = { 26646 }; 26647 var RELATIVE_SLASH = { 26648 }; 26649 var SPECIAL_AUTHORITY_SLASHES = { 26650 }; 26651 var SPECIAL_AUTHORITY_IGNORE_SLASHES = { 26652 }; 26653 var AUTHORITY = { 26654 }; 26655 var HOST = { 26656 }; 26657 var HOSTNAME = { 26658 }; 26659 var PORT = { 26660 }; 26661 var FILE = { 26662 }; 26663 var FILE_SLASH = { 26664 }; 26665 var FILE_HOST = { 26666 }; 26667 var PATH_START = { 26668 }; 26669 var PATH = { 26670 }; 26671 var CANNOT_BE_A_BASE_URL_PATH = { 26672 }; 26673 var QUERY = { 26674 }; 26675 var FRAGMENT = { 26676 }; // eslint-disable-next-line max-statements 26677 var parseURL = function (url, input, stateOverride, base) { 26678 var state = stateOverride || SCHEME_START; 26679 var pointer = 0; 26680 var buffer = ''; 26681 var seenAt = false; 26682 var seenBracket = false; 26683 var seenPasswordToken = false; 26684 var codePoints, 26685 char, 26686 bufferCodePoints, 26687 failure; 26688 if (!stateOverride) { 26689 url.scheme = ''; 26690 url.username = ''; 26691 url.password = ''; 26692 url.host = null; 26693 url.port = null; 26694 url.path = [ 26695 ]; 26696 url.query = null; 26697 url.fragment = null; 26698 url.cannotBeABaseURL = false; 26699 input = input.replace(LEADING_AND_TRAILING_C0_CONTROL_OR_SPACE, ''); 26700 } 26701 input = input.replace(TAB_AND_NEW_LINE, ''); 26702 codePoints = arrayFrom(input); 26703 while (pointer <= codePoints.length) { 26704 char = codePoints[pointer]; 26705 switch (state) { 26706 case SCHEME_START: 26707 if (char && ALPHA.test(char)) { 26708 buffer += char.toLowerCase(); 26709 state = SCHEME; 26710 } else if (!stateOverride) { 26711 state = NO_SCHEME; 26712 continue; 26713 } else return INVALID_SCHEME; 26714 break; 26715 case SCHEME: 26716 if (char && (ALPHANUMERIC.test(char) || char == '+' || char == '-' || char == '.')) { 26717 buffer += char.toLowerCase(); 26718 } else if (char == ':') { 26719 if (stateOverride && (isSpecial(url) != has(specialSchemes, buffer) || buffer == 'file' && (includesCredentials(url) || url.port !== null) || url.scheme == 'file' && !url.host)) return; 26720 url.scheme = buffer; 26721 if (stateOverride) { 26722 if (isSpecial(url) && specialSchemes[url.scheme] == url.port) url.port = null; 26723 return; 26724 } 26725 buffer = ''; 26726 if (url.scheme == 'file') { 26727 state = FILE; 26728 } else if (isSpecial(url) && base && base.scheme == url.scheme) { 26729 state = SPECIAL_RELATIVE_OR_AUTHORITY; 26730 } else if (isSpecial(url)) { 26731 state = SPECIAL_AUTHORITY_SLASHES; 26732 } else if (codePoints[pointer + 1] == '/') { 26733 state = PATH_OR_AUTHORITY; 26734 pointer++; 26735 } else { 26736 url.cannotBeABaseURL = true; 26737 url.path.push(''); 26738 state = CANNOT_BE_A_BASE_URL_PATH; 26739 } 26740 } else if (!stateOverride) { 26741 buffer = ''; 26742 state = NO_SCHEME; 26743 pointer = 0; 26744 continue; 26745 } else return INVALID_SCHEME; 26746 break; 26747 case NO_SCHEME: 26748 if (!base || base.cannotBeABaseURL && char != '#') return INVALID_SCHEME; 26749 if (base.cannotBeABaseURL && char == '#') { 26750 url.scheme = base.scheme; 26751 url.path = base.path.slice(); 26752 url.query = base.query; 26753 url.fragment = ''; 26754 url.cannotBeABaseURL = true; 26755 state = FRAGMENT; 26756 break; 26757 } 26758 state = base.scheme == 'file' ? FILE : RELATIVE; 26759 continue; 26760 case SPECIAL_RELATIVE_OR_AUTHORITY: 26761 if (char == '/' && codePoints[pointer + 1] == '/') { 26762 state = SPECIAL_AUTHORITY_IGNORE_SLASHES; 26763 pointer++; 26764 } else { 26765 state = RELATIVE; 26766 continue; 26767 } 26768 break; 26769 case PATH_OR_AUTHORITY: 26770 if (char == '/') { 26771 state = AUTHORITY; 26772 break; 26773 } else { 26774 state = PATH; 26775 continue; 26776 } 26777 case RELATIVE: 26778 url.scheme = base.scheme; 26779 if (char == EOF) { 26780 url.username = base.username; 26781 url.password = base.password; 26782 url.host = base.host; 26783 url.port = base.port; 26784 url.path = base.path.slice(); 26785 url.query = base.query; 26786 } else if (char == '/' || char == '\\' && isSpecial(url)) { 26787 state = RELATIVE_SLASH; 26788 } else if (char == '?') { 26789 url.username = base.username; 26790 url.password = base.password; 26791 url.host = base.host; 26792 url.port = base.port; 26793 url.path = base.path.slice(); 26794 url.query = ''; 26795 state = QUERY; 26796 } else if (char == '#') { 26797 url.username = base.username; 26798 url.password = base.password; 26799 url.host = base.host; 26800 url.port = base.port; 26801 url.path = base.path.slice(); 26802 url.query = base.query; 26803 url.fragment = ''; 26804 state = FRAGMENT; 26805 } else { 26806 url.username = base.username; 26807 url.password = base.password; 26808 url.host = base.host; 26809 url.port = base.port; 26810 url.path = base.path.slice(); 26811 url.path.pop(); 26812 state = PATH; 26813 continue; 26814 } 26815 break; 26816 case RELATIVE_SLASH: 26817 if (isSpecial(url) && (char == '/' || char == '\\')) { 26818 state = SPECIAL_AUTHORITY_IGNORE_SLASHES; 26819 } else if (char == '/') { 26820 state = AUTHORITY; 26821 } else { 26822 url.username = base.username; 26823 url.password = base.password; 26824 url.host = base.host; 26825 url.port = base.port; 26826 state = PATH; 26827 continue; 26828 } 26829 break; 26830 case SPECIAL_AUTHORITY_SLASHES: 26831 state = SPECIAL_AUTHORITY_IGNORE_SLASHES; 26832 if (char != '/' || buffer.charAt(pointer + 1) != '/') continue; 26833 pointer++; 26834 break; 26835 case SPECIAL_AUTHORITY_IGNORE_SLASHES: 26836 if (char != '/' && char != '\\') { 26837 state = AUTHORITY; 26838 continue; 26839 } 26840 break; 26841 case AUTHORITY: 26842 if (char == '@') { 26843 if (seenAt) buffer = '%40' + buffer; 26844 seenAt = true; 26845 bufferCodePoints = arrayFrom(buffer); 26846 for (var i = 0; i < bufferCodePoints.length; i++) { 26847 var codePoint = bufferCodePoints[i]; 26848 if (codePoint == ':' && !seenPasswordToken) { 26849 seenPasswordToken = true; 26850 continue; 26851 } 26852 var encodedCodePoints = percentEncode(codePoint, userinfoPercentEncodeSet); 26853 if (seenPasswordToken) url.password += encodedCodePoints; 26854 else url.username += encodedCodePoints; 26855 } 26856 buffer = ''; 26857 } else if (char == EOF || char == '/' || char == '?' || char == '#' || char == '\\' && isSpecial(url)) { 26858 if (seenAt && buffer == '') return INVALID_AUTHORITY; 26859 pointer -= arrayFrom(buffer).length + 1; 26860 buffer = ''; 26861 state = HOST; 26862 } else buffer += char; 26863 break; 26864 case HOST: 26865 case HOSTNAME: 26866 if (stateOverride && url.scheme == 'file') { 26867 state = FILE_HOST; 26868 continue; 26869 } else if (char == ':' && !seenBracket) { 26870 if (buffer == '') return INVALID_HOST; 26871 failure = parseHost(url, buffer); 26872 if (failure) return failure; 26873 buffer = ''; 26874 state = PORT; 26875 if (stateOverride == HOSTNAME) return; 26876 } else if (char == EOF || char == '/' || char == '?' || char == '#' || char == '\\' && isSpecial(url)) { 26877 if (isSpecial(url) && buffer == '') return INVALID_HOST; 26878 if (stateOverride && buffer == '' && (includesCredentials(url) || url.port !== null)) return; 26879 failure = parseHost(url, buffer); 26880 if (failure) return failure; 26881 buffer = ''; 26882 state = PATH_START; 26883 if (stateOverride) return; 26884 continue; 26885 } else { 26886 if (char == '[') seenBracket = true; 26887 else if (char == ']') seenBracket = false; 26888 buffer += char; 26889 } 26890 break; 26891 case PORT: 26892 if (DIGIT.test(char)) { 26893 buffer += char; 26894 } else if (char == EOF || char == '/' || char == '?' || char == '#' || char == '\\' && isSpecial(url) || stateOverride) { 26895 if (buffer != '') { 26896 var port = parseInt(buffer, 10); 26897 if (port > 65535) return INVALID_PORT; 26898 url.port = isSpecial(url) && port === specialSchemes[url.scheme] ? null : port; 26899 buffer = ''; 26900 } 26901 if (stateOverride) return; 26902 state = PATH_START; 26903 continue; 26904 } else return INVALID_PORT; 26905 break; 26906 case FILE: 26907 url.scheme = 'file'; 26908 if (char == '/' || char == '\\') state = FILE_SLASH; 26909 else if (base && base.scheme == 'file') { 26910 if (char == EOF) { 26911 url.host = base.host; 26912 url.path = base.path.slice(); 26913 url.query = base.query; 26914 } else if (char == '?') { 26915 url.host = base.host; 26916 url.path = base.path.slice(); 26917 url.query = ''; 26918 state = QUERY; 26919 } else if (char == '#') { 26920 url.host = base.host; 26921 url.path = base.path.slice(); 26922 url.query = base.query; 26923 url.fragment = ''; 26924 state = FRAGMENT; 26925 } else { 26926 if (!startsWithWindowsDriveLetter(codePoints.slice(pointer).join(''))) { 26927 url.host = base.host; 26928 url.path = base.path.slice(); 26929 shortenURLsPath(url); 26930 } 26931 state = PATH; 26932 continue; 26933 } 26934 } else { 26935 state = PATH; 26936 continue; 26937 } 26938 break; 26939 case FILE_SLASH: 26940 if (char == '/' || char == '\\') { 26941 state = FILE_HOST; 26942 break; 26943 } 26944 if (base && base.scheme == 'file' && !startsWithWindowsDriveLetter(codePoints.slice(pointer).join(''))) { 26945 if (isWindowsDriveLetter(base.path[0], true)) url.path.push(base.path[0]); 26946 else url.host = base.host; 26947 } 26948 state = PATH; 26949 continue; 26950 case FILE_HOST: 26951 if (char == EOF || char == '/' || char == '\\' || char == '?' || char == '#') { 26952 if (!stateOverride && isWindowsDriveLetter(buffer)) { 26953 state = PATH; 26954 } else if (buffer == '') { 26955 url.host = ''; 26956 if (stateOverride) return; 26957 state = PATH_START; 26958 } else { 26959 failure = parseHost(url, buffer); 26960 if (failure) return failure; 26961 if (url.host == 'localhost') url.host = ''; 26962 if (stateOverride) return; 26963 buffer = ''; 26964 state = PATH_START; 26965 } 26966 continue; 26967 } else buffer += char; 26968 break; 26969 case PATH_START: 26970 if (isSpecial(url)) { 26971 state = PATH; 26972 if (char != '/' && char != '\\') continue; 26973 } else if (!stateOverride && char == '?') { 26974 url.query = ''; 26975 state = QUERY; 26976 } else if (!stateOverride && char == '#') { 26977 url.fragment = ''; 26978 state = FRAGMENT; 26979 } else if (char != EOF) { 26980 state = PATH; 26981 if (char != '/') continue; 26982 } 26983 break; 26984 case PATH: 26985 if (char == EOF || char == '/' || char == '\\' && isSpecial(url) || !stateOverride && (char == '?' || char == '#')) { 26986 if (isDoubleDot(buffer)) { 26987 shortenURLsPath(url); 26988 if (char != '/' && !(char == '\\' && isSpecial(url))) { 26989 url.path.push(''); 26990 } 26991 } else if (isSingleDot(buffer)) { 26992 if (char != '/' && !(char == '\\' && isSpecial(url))) { 26993 url.path.push(''); 26994 } 26995 } else { 26996 if (url.scheme == 'file' && !url.path.length && isWindowsDriveLetter(buffer)) { 26997 if (url.host) url.host = ''; 26998 buffer = buffer.charAt(0) + ':'; // normalize windows drive letter 26999 } 27000 url.path.push(buffer); 27001 } 27002 buffer = ''; 27003 if (url.scheme == 'file' && (char == EOF || char == '?' || char == '#')) { 27004 while (url.path.length > 1 && url.path[0] === '') { 27005 url.path.shift(); 27006 } 27007 } 27008 if (char == '?') { 27009 url.query = ''; 27010 state = QUERY; 27011 } else if (char == '#') { 27012 url.fragment = ''; 27013 state = FRAGMENT; 27014 } 27015 } else { 27016 buffer += percentEncode(char, pathPercentEncodeSet); 27017 } 27018 break; 27019 case CANNOT_BE_A_BASE_URL_PATH: 27020 if (char == '?') { 27021 url.query = ''; 27022 state = QUERY; 27023 } else if (char == '#') { 27024 url.fragment = ''; 27025 state = FRAGMENT; 27026 } else if (char != EOF) { 27027 url.path[0] += percentEncode(char, C0ControlPercentEncodeSet); 27028 } 27029 break; 27030 case QUERY: 27031 if (!stateOverride && char == '#') { 27032 url.fragment = ''; 27033 state = FRAGMENT; 27034 } else if (char != EOF) { 27035 if (char == '\'' && isSpecial(url)) url.query += '%27'; 27036 else if (char == '#') url.query += '%23'; 27037 else url.query += percentEncode(char, C0ControlPercentEncodeSet); 27038 } 27039 break; 27040 case FRAGMENT: 27041 if (char != EOF) url.fragment += percentEncode(char, fragmentPercentEncodeSet); 27042 break; 27043 } 27044 pointer++; 27045 } 27046 }; // `URL` constructor 27047 // https://url.spec.whatwg.org/#url-class 27048 var URLConstructor = function URL(url /* , base */ 27049 ) { 27050 var that = anInstance(this, URLConstructor, 'URL'); 27051 var base = arguments.length > 1 ? arguments[1] : undefined; 27052 var urlString = String(url); 27053 var state = setInternalState(that, { 27054 type: 'URL' 27055 }); 27056 var baseState, 27057 failure; 27058 if (base !== undefined) { 27059 if (base instanceof URLConstructor) baseState = getInternalURLState(base); 27060 else { 27061 failure = parseURL(baseState = { 27062 }, String(base)); 27063 if (failure) throw TypeError(failure); 27064 } 27065 } 27066 failure = parseURL(state, urlString, null, baseState); 27067 if (failure) throw TypeError(failure); 27068 var searchParams = state.searchParams = new URLSearchParams(); 27069 var searchParamsState = getInternalSearchParamsState(searchParams); 27070 searchParamsState.updateSearchParams(state.query); 27071 searchParamsState.updateURL = function () { 27072 state.query = String(searchParams) || null; 27073 }; 27074 if (!DESCRIPTORS) { 27075 that.href = serializeURL.call(that); 27076 that.origin = getOrigin.call(that); 27077 that.protocol = getProtocol.call(that); 27078 that.username = getUsername.call(that); 27079 that.password = getPassword.call(that); 27080 that.host = getHost.call(that); 27081 that.hostname = getHostname.call(that); 27082 that.port = getPort.call(that); 27083 that.pathname = getPathname.call(that); 27084 that.search = getSearch.call(that); 27085 that.searchParams = getSearchParams.call(that); 27086 that.hash = getHash.call(that); 27087 } 27088 }; 27089 var URLPrototype = URLConstructor.prototype; 27090 var serializeURL = function () { 27091 var url = getInternalURLState(this); 27092 var scheme = url.scheme; 27093 var username = url.username; 27094 var password = url.password; 27095 var host = url.host; 27096 var port = url.port; 27097 var path = url.path; 27098 var query = url.query; 27099 var fragment = url.fragment; 27100 var output = scheme + ':'; 27101 if (host !== null) { 27102 output += '//'; 27103 if (includesCredentials(url)) { 27104 output += username + (password ? ':' + password : '') + '@'; 27105 } 27106 output += serializeHost(host); 27107 if (port !== null) output += ':' + port; 27108 } else if (scheme == 'file') output += '//'; 27109 output += url.cannotBeABaseURL ? path[0] : path.length ? '/' + path.join('/') : ''; 27110 if (query !== null) output += '?' + query; 27111 if (fragment !== null) output += '#' + fragment; 27112 return output; 27113 }; 27114 var getOrigin = function () { 27115 var url = getInternalURLState(this); 27116 var scheme = url.scheme; 27117 var port = url.port; 27118 if (scheme == 'blob') try { 27119 return new URL(scheme.path[0]).origin; 27120 } catch (error) { 27121 return 'null';
vendor: 6,589 bytes, lines 27122-27265
27122 } 27123 if (scheme == 'file' || !isSpecial(url)) return 'null'; 27124 return scheme + '://' + serializeHost(url.host) + (port !== null ? ':' + port : ''); 27125 }; 27126 var getProtocol = function () { 27127 return getInternalURLState(this).scheme + ':'; 27128 }; 27129 var getUsername = function () { 27130 return getInternalURLState(this).username; 27131 }; 27132 var getPassword = function () { 27133 return getInternalURLState(this).password; 27134 }; 27135 var getHost = function () { 27136 var url = getInternalURLState(this); 27137 var host = url.host; 27138 var port = url.port; 27139 return host === null ? '' : port === null ? serializeHost(host) : serializeHost(host) + ':' + port; 27140 }; 27141 var getHostname = function () { 27142 var host = getInternalURLState(this).host; 27143 return host === null ? '' : serializeHost(host); 27144 }; 27145 var getPort = function () { 27146 var port = getInternalURLState(this).port; 27147 return port === null ? '' : String(port); 27148 }; 27149 var getPathname = function () { 27150 var url = getInternalURLState(this); 27151 var path = url.path; 27152 return url.cannotBeABaseURL ? path[0] : path.length ? '/' + path.join('/') : ''; 27153 }; 27154 var getSearch = function () { 27155 var query = getInternalURLState(this).query; 27156 return query ? '?' + query : ''; 27157 }; 27158 var getSearchParams = function () { 27159 return getInternalURLState(this).searchParams; 27160 }; 27161 var getHash = function () { 27162 var fragment = getInternalURLState(this).fragment; 27163 return fragment ? '#' + fragment : ''; 27164 }; 27165 var accessorDescriptor = function (getter, setter) { 27166 return { 27167 get: getter, 27168 set: setter, 27169 configurable: true, 27170 enumerable: true 27171 }; 27172 }; 27173 if (DESCRIPTORS) { 27174 defineProperties(URLPrototype, { 27175 // `URL.prototype.href` accessors pair 27176 // https://url.spec.whatwg.org/#dom-url-href 27177 href: accessorDescriptor(serializeURL, function (href) { 27178 var url = getInternalURLState(this); 27179 var urlString = String(href); 27180 var failure = parseURL(url, urlString); 27181 if (failure) throw TypeError(failure); 27182 getInternalSearchParamsState(url.searchParams).updateSearchParams(url.query); 27183 }), 27184 // `URL.prototype.origin` getter 27185 // https://url.spec.whatwg.org/#dom-url-origin 27186 origin: accessorDescriptor(getOrigin), 27187 // `URL.prototype.protocol` accessors pair 27188 // https://url.spec.whatwg.org/#dom-url-protocol 27189 protocol: accessorDescriptor(getProtocol, function (protocol) { 27190 var url = getInternalURLState(this); 27191 parseURL(url, String(protocol) + ':', SCHEME_START); 27192 }), 27193 // `URL.prototype.username` accessors pair 27194 // https://url.spec.whatwg.org/#dom-url-username 27195 username: accessorDescriptor(getUsername, function (username) { 27196 var url = getInternalURLState(this); 27197 var codePoints = arrayFrom(String(username)); 27198 if (cannotHaveUsernamePasswordPort(url)) return; 27199 url.username = ''; 27200 for (var i = 0; i < codePoints.length; i++) { 27201 url.username += percentEncode(codePoints[i], userinfoPercentEncodeSet); 27202 } 27203 }), 27204 // `URL.prototype.password` accessors pair 27205 // https://url.spec.whatwg.org/#dom-url-password 27206 password: accessorDescriptor(getPassword, function (password) { 27207 var url = getInternalURLState(this); 27208 var codePoints = arrayFrom(String(password)); 27209 if (cannotHaveUsernamePasswordPort(url)) return; 27210 url.password = ''; 27211 for (var i = 0; i < codePoints.length; i++) { 27212 url.password += percentEncode(codePoints[i], userinfoPercentEncodeSet); 27213 } 27214 }), 27215 // `URL.prototype.host` accessors pair 27216 // https://url.spec.whatwg.org/#dom-url-host 27217 host: accessorDescriptor(getHost, function (host) { 27218 var url = getInternalURLState(this); 27219 if (url.cannotBeABaseURL) return; 27220 parseURL(url, String(host), HOST); 27221 }), 27222 // `URL.prototype.hostname` accessors pair 27223 // https://url.spec.whatwg.org/#dom-url-hostname 27224 hostname: accessorDescriptor(getHostname, function (hostname) { 27225 var url = getInternalURLState(this); 27226 if (url.cannotBeABaseURL) return; 27227 parseURL(url, String(hostname), HOSTNAME); 27228 }), 27229 // `URL.prototype.port` accessors pair 27230 // https://url.spec.whatwg.org/#dom-url-port 27231 port: accessorDescriptor(getPort, function (port) { 27232 var url = getInternalURLState(this); 27233 if (cannotHaveUsernamePasswordPort(url)) return; 27234 port = String(port); 27235 if (port == '') url.port = null; 27236 else parseURL(url, port, PORT); 27237 }), 27238 // `URL.prototype.pathname` accessors pair 27239 // https://url.spec.whatwg.org/#dom-url-pathname 27240 pathname: accessorDescriptor(getPathname, function (pathname) { 27241 var url = getInternalURLState(this); 27242 if (url.cannotBeABaseURL) return; 27243 url.path = [ 27244 ]; 27245 parseURL(url, pathname + '', PATH_START); 27246 }), 27247 // `URL.prototype.search` accessors pair 27248 // https://url.spec.whatwg.org/#dom-url-search 27249 search: accessorDescriptor(getSearch, function (search) { 27250 var url = getInternalURLState(this); 27251 search = String(search); 27252 if (search == '') { 27253 url.query = null; 27254 } else { 27255 if ('?' == search.charAt(0)) search = search.slice(1); 27256 url.query = ''; 27257 parseURL(url, search, QUERY); 27258 } 27259 getInternalSearchParamsState(url.searchParams).updateSearchParams(url.query); 27260 }), 27261 // `URL.prototype.searchParams` getter 27262 // https://url.spec.whatwg.org/#dom-url-searchparams 27263 searchParams: accessorDescriptor(getSearchParams), 27264 // `URL.prototype.hash` accessors pair 27265 // https://url.spec.whatwg.org/#dom-url-hash
27266 hash: accessorDescriptor(getHash, function (hash) { 27267 var url = getInternalURLState(this); 27268 hash = String(hash); 27269 if (hash == '') { 27270 url.fragment = null; 27271 return; 27272 } 27273 if ('#' == hash.charAt(0)) hash = hash.slice(1); 27274 url.fragment = ''; 27275 parseURL(url, hash, FRAGMENT); 27276 }) 27277 }); 27278 } // `URL.prototype.toJSON` method 27279 // https://url.spec.whatwg.org/#dom-url-tojson 27280 27281 redefine(URLPrototype, 'toJSON', function toJSON() { 27282 return serializeURL.call(this); 27283 }, { 27284 enumerable: true 27285 }); // `URL.prototype.toString` method 27286 // https://url.spec.whatwg.org/#URL-stringification-behavior 27287 redefine(URLPrototype, 'toString', function toString() { 27288 return serializeURL.call(this); 27289 }, { 27290 enumerable: true 27291 }); 27292 if (NativeURL) { 27293 var nativeCreateObjectURL = NativeURL.createObjectURL; 27294 var nativeRevokeObjectURL = NativeURL.revokeObjectURL; // `URL.createObjectURL` method 27295 // https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL 27296 // eslint-disable-next-line no-unused-vars 27297 if (nativeCreateObjectURL) redefine(URLConstructor, 'createObjectURL', function createObjectURL(blob) { 27298 return nativeCreateObjectURL.apply(NativeURL, arguments); 27299 }); // `URL.revokeObjectURL` method 27300 // https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL 27301 // eslint-disable-next-line no-unused-vars 27302 if (nativeRevokeObjectURL) redefine(URLConstructor, 'revokeObjectURL', function revokeObjectURL(url) { 27303 return nativeRevokeObjectURL.apply(NativeURL, arguments); 27304 }); 27305 } 27306 setToStringTag(URLConstructor, 'URL'); 27307 $({ 27308 global: true, 27309 forced: !USE_NATIVE_URL, 27310 sham: !DESCRIPTORS 27311 }, { 27312 URL: URLConstructor 27313 }); 27314 }, 27315 { 27316 '../internals/an-instance': 27, 27317 '../internals/array-from': 35, 27318 '../internals/descriptors': 61, 27319 '../internals/export': 68, 27320 '../internals/global': 77, 27321 '../internals/has': 78, 27322 '../internals/internal-state': 88, 27323 '../internals/native-url': 102, 27324 '../internals/object-assign': 107, 27325 '../internals/object-define-properties': 109, 27326 '../internals/redefine': 126, 27327 '../internals/set-to-string-tag': 135, 27328 '../internals/string-multibyte': 141, 27329 '../internals/string-punycode-to-ascii': 142, 27330 '../modules/es.string.iterator': 204, 27331 '../modules/web.url-search-params': 249 27332 } 27333 ], 27334 251: [ 27335 function (_dereq_, module, exports) { 27336 // This file can be required in Browserify and Node.js for automatic polyfill 27337 // To use it: require('es6-promise/auto'); 27338 'use strict'; 27339 module.exports = _dereq_('./').polyfill(); 27340 }, 27341 { 27342 './': 252 27343 } 27344 ], 27345 252: [ 27346 function (_dereq_, module, exports) { 27347 (function (process, global) { 27348 /*! 27349 * @overview es6-promise - a tiny implementation of Promises/A+. 27350 * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) 27351 * @license Licensed under MIT license 27352 * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE 27353 * @version v4.2.8+1e68dce6 27354 */ 27355 (function (global, factory) { 27356 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.ES6Promise = factory(); 27357 }) (this, function () { 27358 'use strict'; 27359 function objectOrFunction(x) { 27360 var type = typeof x; 27361 return x !== null && (type === 'object' || type === 'function'); 27362 } 27363 function isFunction(x) { 27364 return typeof x === 'function'; 27365 } 27366 var _isArray = void 0; 27367 if (Array.isArray) { 27368 _isArray = Array.isArray; 27369 } else { 27370 _isArray = function (x) { 27371 return Object.prototype.toString.call(x) === '[object Array]'; 27372 }; 27373 } 27374 var isArray = _isArray; 27375 var len = 0; 27376 var vertxNext = void 0; 27377 var customSchedulerFn = void 0; 27378 var asap = function asap(callback, arg) { 27379 queue[len] = callback; 27380 queue[len + 1] = arg;
vendor: 5,223 bytes, lines 27381-27510
27381 len += 2; 27382 if (len === 2) { 27383 // If len is 2, that means that we need to schedule an async flush. 27384 // If additional callbacks are queued before the queue is flushed, they 27385 // will be processed by this flush that we are scheduling. 27386 if (customSchedulerFn) { 27387 customSchedulerFn(flush); 27388 } else { 27389 scheduleFlush(); 27390 } 27391 } 27392 }; 27393 function setScheduler(scheduleFn) { 27394 customSchedulerFn = scheduleFn; 27395 } 27396 function setAsap(asapFn) { 27397 asap = asapFn; 27398 } 27399 var browserWindow = typeof window !== 'undefined' ? window : undefined; 27400 var browserGlobal = browserWindow || { 27401 }; 27402 var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; 27403 var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && { 27404 }.toString.call(process) === '[object process]'; // test for web worker but not in IE10 27405 var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; // node 27406 function useNextTick() { 27407 // node version 0.10.x displays a deprecation warning when nextTick is used recursively 27408 // see https://github.com/cujojs/when/issues/410 for details 27409 return function () { 27410 return process.nextTick(flush); 27411 }; 27412 } // vertx 27413 27414 function useVertxTimer() { 27415 if (typeof vertxNext !== 'undefined') { 27416 return function () { 27417 vertxNext(flush); 27418 }; 27419 } 27420 return useSetTimeout(); 27421 } 27422 function useMutationObserver() { 27423 var iterations = 0; 27424 var observer = new BrowserMutationObserver(flush); 27425 var node = document.createTextNode(''); 27426 observer.observe(node, { 27427 characterData: true 27428 }); 27429 return function () { 27430 node.data = iterations = ++iterations % 2; 27431 }; 27432 } // web worker 27433 27434 function useMessageChannel() { 27435 var channel = new MessageChannel(); 27436 channel.port1.onmessage = flush; 27437 return function () { 27438 return channel.port2.postMessage(0); 27439 }; 27440 } 27441 function useSetTimeout() { 27442 // Store setTimeout reference so es6-promise will be unaffected by 27443 // other code modifying setTimeout (like sinon.useFakeTimers()) 27444 var globalSetTimeout = setTimeout; 27445 return function () { 27446 return globalSetTimeout(flush, 1); 27447 }; 27448 } 27449 var queue = new Array(1000); 27450 function flush() { 27451 for (var i = 0; i < len; i += 2) { 27452 var callback = queue[i]; 27453 var arg = queue[i + 1]; 27454 callback(arg); 27455 queue[i] = undefined; 27456 queue[i + 1] = undefined; 27457 } 27458 len = 0; 27459 } 27460 function attemptVertx() { 27461 try { 27462 var vertx = Function('return this') ().require('vertx'); 27463 vertxNext = vertx.runOnLoop || vertx.runOnContext; 27464 return useVertxTimer(); 27465 } catch (e) { 27466 return useSetTimeout(); 27467 } 27468 } 27469 var scheduleFlush = void 0; // Decide what async method to use to triggering processing of queued callbacks: 27470 if (isNode) { 27471 scheduleFlush = useNextTick(); 27472 } else if (BrowserMutationObserver) { 27473 scheduleFlush = useMutationObserver(); 27474 } else if (isWorker) { 27475 scheduleFlush = useMessageChannel(); 27476 } else if (browserWindow === undefined && typeof _dereq_ === 'function') { 27477 scheduleFlush = attemptVertx(); 27478 } else { 27479 scheduleFlush = useSetTimeout(); 27480 } 27481 function then(onFulfillment, onRejection) { 27482 var parent = this; 27483 var child = new this.constructor(noop); 27484 if (child[PROMISE_ID] === undefined) { 27485 makePromise(child); 27486 } 27487 var _state = parent._state; 27488 if (_state) { 27489 var callback = arguments[_state - 1]; 27490 asap(function () { 27491 return invokeCallback(_state, child, callback, parent._result); 27492 }); 27493 } else { 27494 subscribe(parent, child, onFulfillment, onRejection); 27495 } 27496 return child; 27497 } /** 27498 `Promise.resolve` returns a promise that will become resolved with the 27499 passed `value`. It is shorthand for the following: 27500 27501 ```javascript 27502 let promise = new Promise(function(resolve, reject){ 27503 resolve(1); 27504 }); 27505 27506 promise.then(function(value){ 27507 // value === 1 27508 }); 27509 ``` 27510
vendor: 15,056 bytes, lines 27511-27919
27511 Instead of writing the above, your code now simply becomes the following: 27512 27513 ```javascript 27514 let promise = Promise.resolve(1); 27515 27516 promise.then(function(value){ 27517 // value === 1 27518 }); 27519 ``` 27520 27521 @method resolve 27522 @static 27523 @param {Any} value value that the returned promise will be resolved with 27524 Useful for tooling. 27525 @return {Promise} a promise that will become fulfilled with the given 27526 `value` 27527 */ 27528 27529 function resolve$1(object) { 27530 /*jshint validthis:true */ 27531 var Constructor = this; 27532 if (object && typeof object === 'object' && object.constructor === Constructor) { 27533 return object; 27534 } 27535 var promise = new Constructor(noop); 27536 resolve(promise, object); 27537 return promise; 27538 } 27539 var PROMISE_ID = Math.random().toString(36).substring(2); 27540 function noop() { 27541 } 27542 var PENDING = void 0; 27543 var FULFILLED = 1; 27544 var REJECTED = 2; 27545 function selfFulfillment() { 27546 return new TypeError('You cannot resolve a promise with itself'); 27547 } 27548 function cannotReturnOwn() { 27549 return new TypeError('A promises callback cannot return that same promise.'); 27550 } 27551 function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { 27552 try { 27553 then$$1.call(value, fulfillmentHandler, rejectionHandler); 27554 } catch (e) { 27555 return e; 27556 } 27557 } 27558 function handleForeignThenable(promise, thenable, then$$1) { 27559 asap(function (promise) { 27560 var sealed = false; 27561 var error = tryThen(then$$1, thenable, function (value) { 27562 if (sealed) { 27563 return; 27564 } 27565 sealed = true; 27566 if (thenable !== value) { 27567 resolve(promise, value); 27568 } else { 27569 fulfill(promise, value); 27570 } 27571 }, function (reason) { 27572 if (sealed) { 27573 return; 27574 } 27575 sealed = true; 27576 reject(promise, reason); 27577 }, 'Settle: ' + (promise._label || ' unknown promise')); 27578 if (!sealed && error) { 27579 sealed = true; 27580 reject(promise, error); 27581 } 27582 }, promise); 27583 } 27584 function handleOwnThenable(promise, thenable) { 27585 if (thenable._state === FULFILLED) { 27586 fulfill(promise, thenable._result); 27587 } else if (thenable._state === REJECTED) { 27588 reject(promise, thenable._result); 27589 } else { 27590 subscribe(thenable, undefined, function (value) { 27591 return resolve(promise, value); 27592 }, function (reason) { 27593 return reject(promise, reason); 27594 }); 27595 } 27596 } 27597 function handleMaybeThenable(promise, maybeThenable, then$$1) { 27598 if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) { 27599 handleOwnThenable(promise, maybeThenable); 27600 } else { 27601 if (then$$1 === undefined) { 27602 fulfill(promise, maybeThenable); 27603 } else if (isFunction(then$$1)) { 27604 handleForeignThenable(promise, maybeThenable, then$$1); 27605 } else { 27606 fulfill(promise, maybeThenable); 27607 } 27608 } 27609 } 27610 function resolve(promise, value) { 27611 if (promise === value) { 27612 reject(promise, selfFulfillment()); 27613 } else if (objectOrFunction(value)) { 27614 var then$$1 = void 0; 27615 try { 27616 then$$1 = value.then; 27617 } catch (error) { 27618 reject(promise, error); 27619 return; 27620 } 27621 handleMaybeThenable(promise, value, then$$1); 27622 } else { 27623 fulfill(promise, value); 27624 } 27625 } 27626 function publishRejection(promise) { 27627 if (promise._onerror) { 27628 promise._onerror(promise._result); 27629 } 27630 publish(promise); 27631 } 27632 function fulfill(promise, value) { 27633 if (promise._state !== PENDING) { 27634 return; 27635 } 27636 promise._result = value; 27637 promise._state = FULFILLED; 27638 if (promise._subscribers.length !== 0) { 27639 asap(publish, promise); 27640 } 27641 } 27642 function reject(promise, reason) { 27643 if (promise._state !== PENDING) { 27644 return; 27645 } 27646 promise._state = REJECTED; 27647 promise._result = reason; 27648 asap(publishRejection, promise); 27649 } 27650 function subscribe(parent, child, onFulfillment, onRejection) { 27651 var _subscribers = parent._subscribers; 27652 var length = _subscribers.length; 27653 parent._onerror = null; 27654 _subscribers[length] = child; 27655 _subscribers[length + FULFILLED] = onFulfillment; 27656 _subscribers[length + REJECTED] = onRejection; 27657 if (length === 0 && parent._state) { 27658 asap(publish, parent); 27659 } 27660 } 27661 function publish(promise) { 27662 var subscribers = promise._subscribers; 27663 var settled = promise._state; 27664 if (subscribers.length === 0) { 27665 return; 27666 } 27667 var child = void 0, 27668 callback = void 0, 27669 detail = promise._result; 27670 for (var i = 0; i < subscribers.length; i += 3) { 27671 child = subscribers[i]; 27672 callback = subscribers[i + settled]; 27673 if (child) { 27674 invokeCallback(settled, child, callback, detail); 27675 } else { 27676 callback(detail); 27677 } 27678 } 27679 promise._subscribers.length = 0; 27680 } 27681 function invokeCallback(settled, promise, callback, detail) { 27682 var hasCallback = isFunction(callback), 27683 value = void 0, 27684 error = void 0, 27685 succeeded = true; 27686 if (hasCallback) { 27687 try { 27688 value = callback(detail); 27689 } catch (e) { 27690 succeeded = false; 27691 error = e; 27692 } 27693 if (promise === value) { 27694 reject(promise, cannotReturnOwn()); 27695 return; 27696 } 27697 } else { 27698 value = detail; 27699 } 27700 if (promise._state !== PENDING) { // noop 27701 } else if (hasCallback && succeeded) { 27702 resolve(promise, value); 27703 } else if (succeeded === false) { 27704 reject(promise, error); 27705 } else if (settled === FULFILLED) { 27706 fulfill(promise, value); 27707 } else if (settled === REJECTED) { 27708 reject(promise, value); 27709 } 27710 } 27711 function initializePromise(promise, resolver) { 27712 try { 27713 resolver(function resolvePromise(value) { 27714 resolve(promise, value); 27715 }, function rejectPromise(reason) { 27716 reject(promise, reason); 27717 }); 27718 } catch (e) { 27719 reject(promise, e); 27720 } 27721 } 27722 var id = 0; 27723 function nextId() { 27724 return id++; 27725 } 27726 function makePromise(promise) { 27727 promise[PROMISE_ID] = id++; 27728 promise._state = undefined; 27729 promise._result = undefined; 27730 promise._subscribers = [ 27731 ]; 27732 } 27733 function validationError() { 27734 return new Error('Array Methods must be provided an Array'); 27735 } 27736 var Enumerator = function () { 27737 function Enumerator(Constructor, input) { 27738 this._instanceConstructor = Constructor; 27739 this.promise = new Constructor(noop); 27740 if (!this.promise[PROMISE_ID]) { 27741 makePromise(this.promise); 27742 } 27743 if (isArray(input)) { 27744 this.length = input.length; 27745 this._remaining = input.length; 27746 this._result = new Array(this.length); 27747 if (this.length === 0) { 27748 fulfill(this.promise, this._result); 27749 } else { 27750 this.length = this.length || 0; 27751 this._enumerate(input); 27752 if (this._remaining === 0) { 27753 fulfill(this.promise, this._result); 27754 } 27755 } 27756 } else { 27757 reject(this.promise, validationError()); 27758 } 27759 } 27760 Enumerator.prototype._enumerate = function _enumerate(input) { 27761 for (var i = 0; this._state === PENDING && i < input.length; i++) { 27762 this._eachEntry(input[i], i); 27763 } 27764 }; 27765 Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { 27766 var c = this._instanceConstructor; 27767 var resolve$$1 = c.resolve; 27768 if (resolve$$1 === resolve$1) { 27769 var _then = void 0; 27770 var error = void 0; 27771 var didError = false; 27772 try { 27773 _then = entry.then; 27774 } catch (e) { 27775 didError = true; 27776 error = e; 27777 } 27778 if (_then === then && entry._state !== PENDING) { 27779 this._settledAt(entry._state, i, entry._result); 27780 } else if (typeof _then !== 'function') { 27781 this._remaining--; 27782 this._result[i] = entry; 27783 } else if (c === Promise$1) { 27784 var promise = new c(noop); 27785 if (didError) { 27786 reject(promise, error); 27787 } else { 27788 handleMaybeThenable(promise, entry, _then); 27789 } 27790 this._willSettleAt(promise, i); 27791 } else { 27792 this._willSettleAt(new c(function (resolve$$1) { 27793 return resolve$$1(entry); 27794 }), i); 27795 } 27796 } else { 27797 this._willSettleAt(resolve$$1(entry), i); 27798 } 27799 }; 27800 Enumerator.prototype._settledAt = function _settledAt(state, i, value) { 27801 var promise = this.promise; 27802 if (promise._state === PENDING) { 27803 this._remaining--; 27804 if (state === REJECTED) { 27805 reject(promise, value); 27806 } else { 27807 this._result[i] = value; 27808 } 27809 } 27810 if (this._remaining === 0) { 27811 fulfill(promise, this._result); 27812 } 27813 }; 27814 Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { 27815 var enumerator = this; 27816 subscribe(promise, undefined, function (value) { 27817 return enumerator._settledAt(FULFILLED, i, value); 27818 }, function (reason) { 27819 return enumerator._settledAt(REJECTED, i, reason); 27820 }); 27821 }; 27822 return Enumerator; 27823 }(); 27824 /** 27825 `Promise.all` accepts an array of promises, and returns a new promise which 27826 is fulfilled with an array of fulfillment values for the passed promises, or 27827 rejected with the reason of the first passed promise to be rejected. It casts all 27828 elements of the passed iterable to promises as it runs this algorithm. 27829 27830 Example: 27831 27832 ```javascript 27833 let promise1 = resolve(1); 27834 let promise2 = resolve(2); 27835 let promise3 = resolve(3); 27836 let promises = [ promise1, promise2, promise3 ]; 27837 27838 Promise.all(promises).then(function(array){ 27839 // The array here would be [ 1, 2, 3 ]; 27840 }); 27841 ``` 27842 27843 If any of the `promises` given to `all` are rejected, the first promise 27844 that is rejected will be given as an argument to the returned promises's 27845 rejection handler. For example: 27846 27847 Example: 27848 27849 ```javascript 27850 let promise1 = resolve(1); 27851 let promise2 = reject(new Error("2")); 27852 let promise3 = reject(new Error("3")); 27853 let promises = [ promise1, promise2, promise3 ]; 27854 27855 Promise.all(promises).then(function(array){ 27856 // Code here never runs because there are rejected promises! 27857 }, function(error) { 27858 // error.message === "2" 27859 }); 27860 ``` 27861 27862 @method all 27863 @static 27864 @param {Array} entries array of promises 27865 @param {String} label optional string for labeling the promise. 27866 Useful for tooling. 27867 @return {Promise} promise that is fulfilled when all `promises` have been 27868 fulfilled, or rejected if any of them become rejected. 27869 @static 27870 */ 27871 function all(entries) { 27872 return new Enumerator(this, entries).promise; 27873 } /** 27874 `Promise.race` returns a new promise which is settled in the same way as the 27875 first passed promise to settle. 27876 27877 Example: 27878 27879 ```javascript 27880 let promise1 = new Promise(function(resolve, reject){ 27881 setTimeout(function(){ 27882 resolve('promise 1'); 27883 }, 200); 27884 }); 27885 27886 let promise2 = new Promise(function(resolve, reject){ 27887 setTimeout(function(){ 27888 resolve('promise 2'); 27889 }, 100); 27890 }); 27891 27892 Promise.race([promise1, promise2]).then(function(result){ 27893 // result === 'promise 2' because it was resolved before promise1 27894 // was resolved. 27895 }); 27896 ``` 27897 27898 `Promise.race` is deterministic in that only the state of the first 27899 settled promise matters. For example, even if other promises given to the 27900 `promises` array argument are resolved, but the first settled promise has 27901 become rejected before the other promises became fulfilled, the returned 27902 promise will become rejected: 27903 27904 ```javascript 27905 let promise1 = new Promise(function(resolve, reject){ 27906 setTimeout(function(){ 27907 resolve('promise 1'); 27908 }, 200); 27909 }); 27910 27911 let promise2 = new Promise(function(resolve, reject){ 27912 setTimeout(function(){ 27913 reject(new Error('promise 2')); 27914 }, 100); 27915 }); 27916 27917 Promise.race([promise1, promise2]).then(function(result){ 27918 // Code here never runs 27919 }, function(reason){
27920 // reason.message === 'promise 2' because promise 2 became rejected before 27921 // promise 1 became fulfilled 27922 }); 27923 ``` 27924 27925 An example real-world use case is implementing timeouts: 27926 27927 ```javascript 27928 Promise.race([ajax('foo.json'), timeout(5000)]) 27929 ``` 27930 27931 @method race 27932 @static 27933 @param {Array} promises array of promises to observe 27934 Useful for tooling. 27935 @return {Promise} a promise which settles in the same way as the first passed 27936 promise to settle. 27937 */ 27938 27939 function race(entries) { 27940 /*jshint validthis:true */ 27941 var Constructor = this; 27942 if (!isArray(entries)) { 27943 return new Constructor(function (_, reject) { 27944 return reject(new TypeError('You must pass an array to race.')); 27945 }); 27946 } else { 27947 return new Constructor(function (resolve, reject) { 27948 var length = entries.length; 27949 for (var i = 0; i < length; i++) { 27950 Constructor.resolve(entries[i]).then(resolve, reject); 27951 } 27952 }); 27953 } 27954 } /** 27955 `Promise.reject` returns a promise rejected with the passed `reason`. 27956 It is shorthand for the following: 27957 27958 ```javascript 27959 let promise = new Promise(function(resolve, reject){ 27960 reject(new Error('WHOOPS')); 27961 }); 27962 27963 promise.then(function(value){ 27964 // Code here doesn't run because the promise is rejected! 27965 }, function(reason){ 27966 // reason.message === 'WHOOPS' 27967 }); 27968 ``` 27969 27970 Instead of writing the above, your code now simply becomes the following: 27971 27972 ```javascript 27973 let promise = Promise.reject(new Error('WHOOPS')); 27974 27975 promise.then(function(value){ 27976 // Code here doesn't run because the promise is rejected! 27977 }, function(reason){ 27978 // reason.message === 'WHOOPS' 27979 }); 27980 ``` 27981 27982 @method reject 27983 @static 27984 @param {Any} reason value that the returned promise will be rejected with. 27985 Useful for tooling. 27986 @return {Promise} a promise rejected with the given `reason`. 27987 */ 27988 27989 function reject$1(reason) { 27990 /*jshint validthis:true */ 27991 var Constructor = this; 27992 var promise = new Constructor(noop); 27993 reject(promise, reason); 27994 return promise; 27995 } 27996 function needsResolver() { 27997 throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); 27998 } 27999 function needsNew() { 28000 throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object c
28000onstructor cannot be called as a function.'); 28001 } /** 28002 Promise objects represent the eventual result of an asynchronous operation. The 28003 primary way of interacting with a promise is through its `then` method, which 28004 registers callbacks to receive either a promise's eventual value or the reason 28005 why the promise cannot be fulfilled. 28006 28007 Terminology 28008 ----------- 28009 28010 - `promise` is an object or function with a `then` method whose behavior conforms to this specification. 28011 - `thenable` is an object or function that defines a `then` method. 28012 - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). 28013 - `exception` is a value that is thrown using the throw statement. 28014 - `reason` is a value that indicates why a promise was rejected. 28015 - `settled` the final resting state of a promise, fulfilled or rejected. 28016 28017 A promise can be in one of three states: pending, fulfilled, or rejected. 28018 28019 Promises that are fulfilled have a fulfillment value and are in the fulfilled 28020 state. Promises that are rejected have a rejection reason and are in the 28021 rejected state. A fulfillment value is never a thenable. 28022 28023 Promises can also be said to *resolve* a value. If this value is also a 28024 promise, then the original promise's settled state will match the value's 28025 settled state. So a promise that *resolves* a promise that rejects will 28026 itself reject, and a promise that *resolves* a promise that fulfills will 28027 itself fulfill. 28028 28029 28030 Basic Usage: 28031 ------------ 28032 28033 ```js 28034 let promise = new Promise(function(resolve, reject) { 28035 // on success 28036 resolve(value); 28037 28038 // on failure 28039 reject(reason); 28040 }); 28041 28042 promise.then(function(value) { 28043 // on fulfillment 28044 }, function(reason) { 28045 // on rejection 28046 }); 28047 ``` 28048 28049 Advanced Usage: 28050 --------------- 28051 28052 Promises shine when abstracting away asynchronous interactions such as 28053 `XMLHttpRequest`s. 28054 28055 ```js 28056 function getJSON(url) { 28057 return new Promise(function(resolve, reject){ 28058 let xhr = new XMLHttpRequest(); 28059 28060 xhr.open('GET', url); 28061 xhr.onreadystatechange = handler; 28062 xhr.responseType = 'json'; 28063 xhr.setRequestHeader('Accept', 'application/json'); 28064 xhr.send(); 28065 28066 function handler() { 28067 if (this.readyState === this.DONE) { 28068 if (this.status === 200) { 28069 resolve(this.response); 28070 } else { 28071 reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); 28072 } 28073 } 28074 }; 28075 }); 28076 } 28077 28078 getJSON('/posts.json').then(function(json) { 28079 // on fulfillment 28080 }, function(reason) { 28081 // on rejection 28082 }); 28083 ``` 28084 28085 Unlike callbacks, promises are great composable primitives. 28086 28087 ```js 28088 Promise.all([ 28089 getJSON('/posts'), 28090 getJSON('/comments') 28091 ]).then(function(values){ 28092 values[0] // => postsJSON 28093 values[1] // => commentsJSON 28094 28095 return values; 28096 }); 28097 ``` 28098 28099 @class Promise 28100 @param {Function} resolver 28101 Useful for tooling. 28102 @constructor 28103 */ 28104 28105 var Promise$1 = function () { 28106 function Promise(resolver) { 28107 this[PROMISE_ID] = nextId(); 28108 this._result = this._state = undefined; 28109 this._subscribers = [ 28110 ]; 28111 if (noop !== resolver) { 28112 typeof resolver !== 'function' && needsResolver(); 28113 this instanceof Promise ? initializePromise(this, resolver) : needsNew(); 28114 } 28115 } /** 28116 The primary way of interacting with a promise is through its `then` method, 28117 which registers callbacks to receive either a promise's eventual value or the 28118 reason why the promise cannot be fulfilled. 28119 ```js 28120 findUser().then(function(user){ 28121 // user is available 28122 }, function(reason){ 28123 // user is unavailable, and you are given the reason why 28124 }); 28125 ``` 28126 Chaining 28127 -------- 28128 The return value of `then` is itself a promise. This second, 'downstream' 28129 promise is resolved with the return value of the first promise's fulfillment 28130 or rejection handler, or rejected if the handler throws an exception. 28131 ```js 28132 findUser().then(function (user) { 28133 return user.name; 28134 }, function (reason) { 28135 return 'default name'; 28136 }).then(function (userName) { 28137 // If `findUser` fulfilled, `userName` will be the user's name, otherwise it 28138 // will be `'default name'` 28139 }); 28140 findUser().then(function (user) { 28141 throw new Error('Found user, but still unhappy'); 28142 }, function (reason) { 28143 throw new Error('`findUser` rejected and we're unhappy'); 28144 }).then(function (value) { 28145 // never reached 28146 }, function (reason) { 28147 // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. 28148 // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. 28149 }); 28150 ``` 28151 If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. 28152 ```js 28153 findUser().then(function (user) { 28154 throw new PedagogicalException('Upstream error'); 28155 }).then(function (value) { 28156 // never reached 28157 }).then(function (value) { 28158 // never reached 28159 }, function (reason) { 28160 // The `PedgagocialException` is propagated all the way down to here 28161 }); 28162 ``` 28163 Assimilation 28164 ------------ 28165 Sometimes the value you want to propagate to a downstream promise can only be 28166 retrieved asynchronously. This can be achieved by returning a promise in the 28167 fulfillment or rejection handler. The downstream promise will then be pending 28168 until the returned promise is settled. This is called *assimilation*. 28169 ```js 28170 findUser().then(function (user) { 28171 return findCommentsByAuthor(user); 28172 }).then(function (comments) { 28173 // The user's comments are now available 28174 }); 28175 ``` 28176 If the assimliated promise rejects, then the downstream promise will also reject. 28177 ```js 28178 findUser().then(function (user) { 28179 return findCommentsByAuthor(user); 28180 }).then(function (comments) { 28181 // If `findCommentsByAuthor` fulfills, we'll have the value here 28182 }, function (reason) { 28183 // If `findCommentsByAuthor` rejects, we'll have the reason here 28184 }); 28185 ```
28186 Simple Example 28187 -------------- 28188 Synchronous Example 28189 ```javascript 28190 let result; 28191 try { 28192 result = findResult(); 28193 // success 28194 } catch(reason) { 28195 // failure 28196 } 28197 ``` 28198 Errback Example 28199 ```js 28200 findResult(function(result, err){ 28201 if (err) { 28202 // failure 28203 } else { 28204 // success 28205 } 28206 }); 28207 ``` 28208 Promise Example; 28209 ```javascript 28210 findResult().then(function(result){ 28211 // success 28212 }, function(reason){ 28213 // failure 28214 }); 28215 ``` 28216 Advanced Example 28217 -------------- 28218 Synchronous Example 28219 ```javascript 28220 let author, books; 28221 try { 28222 author = findAuthor(); 28223 books = findBooksByAuthor(author); 28224 // success 28225 } catch(reason) { 28226 // failure 28227 } 28228 ``` 28229 Errback Example 28230 ```js 28231 function foundBooks(books) { 28232 } 28233 function failure(reason) { 28234 } 28235 findAuthor(function(author, err){ 28236 if (err) { 28237 failure(err); 28238 // failure 28239 } else { 28240 try { 28241 findBoooksByAuthor(author, function(books, err) { 28242 if (err) { 28243 failure(err); 28244 } else { 28245 try { 28246 foundBooks(books); 28247 } catch(reason) { 28248 failure(reason); 28249 } 28250 } 28251 }); 28252 } catch(error) { 28253 failure(err); 28254 } 28255 // success 28256 } 28257 }); 28258 ``` 28259 Promise Example; 28260 ```javascript 28261 findAuthor(). 28262 then(findBooksByAuthor). 28263 then(function(books){ 28264 // found books 28265 }).catch(function(reason){ 28266 // something went wrong 28267 }); 28268 ``` 28269 @method then 28270 @param {Function} onFulfilled 28271 @param {Function} onRejected 28272 Useful for tooling. 28273 @return {Promise} 28274 */ 28275 /** 28276 `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same 28277 as the catch block of a try/catch statement. 28278 ```js 28279 function findAuthor(){ 28280 throw new Error('couldn't find that author'); 28281 } 28282 // synchronous 28283 try { 28284 findAuthor(); 28285 } catch(reason) { 28286 // something went wrong 28287 } 28288 // async with promises 28289 findAuthor().catch(function(reason){ 28290 // something went wrong 28291 }); 28292 ``` 28293 @method catch 28294 @param {Function} onRejection 28295 Useful for tooling. 28296 @return {Promise} 28297 */ 28298 28299 Promise.prototype.catch = function _catch(onRejection) { 28300 return this.then(null, onRejection); 28301 }; 28302 /** 28303 `finally` will be invoked regardless of the promise's fate just as native 28304 try/catch/finally behaves 28305 28306 Synchronous example: 28307 28308 ```js 28309 findAuthor() { 28310 if (Math.random() > 0.5) { 28311 throw new Error(); 28312 } 28313 return new Author(); 28314 } 28315 28316 try { 28317 return findAuthor(); // succeed or fail 28318 } catch(error) { 28319 return findOtherAuther(); 28320 } finally { 28321 // always runs 28322 // doesn't affect the return value 28323 } 28324 ``` 28325 28326 Asynchronous example: 28327 28328 ```js 28329 findAuthor().catch(function(reason){ 28330 return findOtherAuther(); 28331 }).finally(function(){ 28332 // author was either found, or not 28333 }); 28334 ``` 28335 28336 @method finally 28337 @param {Function} callback 28338 @return {Promise} 28339 */ 28340 Promise.prototype.finally = function _finally(callback) { 28341 var promise = this; 28342 var constructor = promise.constructor; 28343 if (isFunction(callback)) { 28344 return promise.then(function (value) { 28345 return constructor.resolve(callback()).then(function () { 28346 return value; 28347 }); 28348 }, function (reason) { 28349 return constructor.resolve(callback()).then(function () { 28350 throw reason; 28351 }); 28352 }); 28353 } 28354 return promise.then(callback, callback); 28355 }; 28356 return Promise; 28357 }(); 28358 Promise$1.prototype.then = then; 28359 Promise$1.all = all; 28360 Promise$1.race = race; 28361 Promise$1.resolve = resolve$1; 28362 Promise$1.reject = reject$1; 28363 Promise$1._setScheduler = setScheduler; 28364 Promise$1._setAsap = setAsap; 28365 Promise$1._asap = asap; 28366 /*global self*/ 28367 function polyfill() { 28368 var local = void 0; 28369 if (typeof global !== 'undefined') { 28370 local = global; 28371 } else if (typeof self !== 'undefined') { 28372 local = self; 28373 } else { 28374 try { 28375 local = Function('return this') (); 28376 } catch (e) { 28377 throw new Error('polyfill failed because global object is unavailable in this environment'); 28378 } 28379 } 28380 var P = local.Promise; 28381 if (P) { 28382 var promiseToString = null; 28383 try { 28384 promiseToString = Object.prototype.toString.call(P.resolve()); 28385 } catch (e) { // silently ignored 28386 } 28387 if (promiseToString === '[object Promise]' && !P.cast) { 28388 return; 28389 } 28390 } 28391 local.Promise = Promise$1; 28392 } // Strange compat.. 28393 28394 Promise$1.polyfill = polyfill; 28395 Promise$1.Promise = Promise$1; 28396 return Promise$1; 28397 }); 28398 }).call(this, _dereq_('_process'), typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : { 28399 }) 28400 }, 28401 { 28402 '_process': 265 28403 } 28404 ], 28405 253: [
vendor: 4,351 bytes, lines 28406-28515
28406 function (_dereq_, module, exports) { 28407 (function (global, factory) { 28408 if (typeof define === 'function' && define.amd) { 28409 define(['exports', 28410 'module'], factory); 28411 } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') { 28412 factory(exports, module); 28413 } else { 28414 var mod = { 28415 exports: { 28416 } 28417 }; 28418 factory(mod.exports, mod); 28419 global.fetchJsonp = mod.exports; 28420 } 28421 }) (this, function (exports, module) { 28422 'use strict'; 28423 var defaultOptions = { 28424 timeout: 5000, 28425 jsonpCallback: 'callback', 28426 jsonpCallbackFunction: null 28427 }; 28428 function generateCallbackFunction() { 28429 return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000); 28430 } 28431 function clearFunction(functionName) { 28432 // IE8 throws an exception when you try to delete a property on window 28433 // http://stackoverflow.com/a/1824228/751089 28434 try { 28435 delete window[functionName]; 28436 } catch (e) { 28437 window[functionName] = undefined; 28438 } 28439 } 28440 function removeScript(scriptId) { 28441 var script = document.getElementById(scriptId); 28442 if (script) { 28443 document.getElementsByTagName('head') [0].removeChild(script); 28444 } 28445 } 28446 function fetchJsonp(_url) { 28447 var options = arguments.length <= 1 || arguments[1] === undefined ? { 28448 } 28449 : arguments[1]; // to avoid param reassign 28450 var url = _url; 28451 var timeout = options.timeout || defaultOptions.timeout; 28452 var jsonpCallback = options.jsonpCallback || defaultOptions.jsonpCallback; 28453 var timeoutId = undefined; 28454 return new Promise(function (resolve, reject) { 28455 var callbackFunction = options.jsonpCallbackFunction || generateCallbackFunction(); 28456 var scriptId = jsonpCallback + '_' + callbackFunction; 28457 window[callbackFunction] = function (response) { 28458 resolve({ 28459 ok: true, 28460 // keep consistent with fetch API 28461 json: function json() { 28462 return Promise.resolve(response); 28463 } 28464 }); 28465 if (timeoutId) clearTimeout(timeoutId); 28466 removeScript(scriptId); 28467 clearFunction(callbackFunction); 28468 }; // Check if the user set their own params, and if not add a ? to start a list of params 28469 url += url.indexOf('?') === - 1 ? '?' : '&'; 28470 var jsonpScript = document.createElement('script'); 28471 jsonpScript.setAttribute('src', '' + url + jsonpCallback + '=' + callbackFunction); 28472 if (options.charset) { 28473 jsonpScript.setAttribute('charset', options.charset); 28474 } 28475 jsonpScript.id = scriptId; 28476 document.getElementsByTagName('head') [0].appendChild(jsonpScript); 28477 timeoutId = setTimeout(function () { 28478 reject(new Error('JSONP request to ' + _url + ' timed out')); 28479 clearFunction(callbackFunction); 28480 removeScript(scriptId); 28481 window[callbackFunction] = function () { 28482 clearFunction(callbackFunction); 28483 }; 28484 }, timeout); // Caught if got 404/500 28485 jsonpScript.onerror = function () { 28486 reject(new Error('JSONP request to ' + _url + ' failed')); 28487 clearFunction(callbackFunction); 28488 removeScript(scriptId); 28489 if (timeoutId) clearTimeout(timeoutId); 28490 }; 28491 }); 28492 } // export as global function 28493 /* 28494 let local; 28495 if (typeof global !== 'undefined') { 28496 local = global; 28497 } else if (typeof self !== 'undefined') { 28498 local = self; 28499 } else { 28500 try { 28501 local = Function('return this')(); 28502 } catch (e) { 28503 throw new Error('polyfill failed because global object is unavailable in this environment'); 28504 } 28505 } 28506 local.fetchJsonp = fetchJsonp; 28507 */ 28508 28509 module.exports = fetchJsonp; 28510 }); 28511 }, 28512 { 28513 } 28514 ], 28515 254: [
vendor: 5,623 bytes, lines 28516-28644
28516 function (_dereq_, module, exports) { 28517 /* FileSaver.js 28518 * A saveAs() FileSaver implementation. 28519 * 1.3.2 28520 * 2016-06-16 18:25:19 28521 * 28522 * By Eli Grey, http://eligrey.com 28523 * License: MIT 28524 * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md 28525 */ 28526 /*global self */ 28527 /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */ 28528 /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ 28529 var saveAs = saveAs || function (view) { 28530 'use strict'; // IE <10 is explicitly unsupported 28531 if (typeof view === 'undefined' || typeof navigator !== 'undefined' && /MSIE [1-9]\./.test(navigator.userAgent)) { 28532 return; 28533 } 28534 var doc = view.document // only get URL when necessary in case Blob.js hasn't overridden it yet 28535 , 28536 get_URL = function () { 28537 return view.URL || view.webkitURL || view; 28538 }, 28539 save_link = doc.createElementNS('http://www.w3.org/1999/xhtml', 'a'), 28540 can_use_save_link = 'download' in save_link, 28541 click = function (node) { 28542 var event = new MouseEvent('click'); 28543 node.dispatchEvent(event); 28544 }, 28545 is_safari = /constructor/i.test(view.HTMLElement) || view.safari, 28546 is_chrome_ios = /CriOS\/[\d]+/.test(navigator.userAgent), 28547 throw_outside = function (ex) { 28548 (view.setImmediate || view.setTimeout) (function () { 28549 throw ex; 28550 }, 0); 28551 }, 28552 force_saveable_type = 'application/octet-stream' // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to 28553 , 28554 arbitrary_revoke_timeout = 1000 * 40 // in ms 28555 , 28556 revoke = function (file) { 28557 var revoker = function () { 28558 if (typeof file === 'string') { 28559 // file is an object URL 28560 get_URL().revokeObjectURL(file); 28561 } else { 28562 // file is a File 28563 file.remove(); 28564 } 28565 }; 28566 setTimeout(revoker, arbitrary_revoke_timeout); 28567 }, 28568 dispatch = function (filesaver, event_types, event) { 28569 event_types = [ 28570 ].concat(event_types); 28571 var i = event_types.length; 28572 while (i--) { 28573 var listener = filesaver['on' + event_types[i]]; 28574 if (typeof listener === 'function') { 28575 try { 28576 listener.call(filesaver, event || filesaver); 28577 } catch (ex) { 28578 throw_outside(ex); 28579 } 28580 } 28581 } 28582 }, 28583 auto_bom = function (blob) { 28584 // prepend BOM for UTF-8 XML and text/* types (including HTML) 28585 // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF 28586 if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) { 28587 return new Blob([String.fromCharCode(65279), 28588 blob], { 28589 type: blob.type 28590 }); 28591 } 28592 return blob; 28593 }, 28594 FileSaver = function (blob, name, no_auto_bom) { 28595 if (!no_auto_bom) { 28596 blob = auto_bom(blob); 28597 } // First try a.download, then web filesystem, then object URLs 28598 28599 var filesaver = this, 28600 type = blob.type, 28601 force = type === force_saveable_type, 28602 object_url, 28603 dispatch_all = function () { 28604 dispatch(filesaver, 'writestart progress write writeend'.split(' ')); 28605 } // on any filesys errors revert to saving with object URLs 28606 , 28607 fs_error = function () { 28608 if ((is_chrome_ios || force && is_safari) && view.FileReader) { 28609 // Safari doesn't allow downloading of blob urls 28610 var reader = new FileReader(); 28611 reader.onloadend = function () { 28612 var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;'); 28613 var popup = view.open(url, '_blank'); 28614 if (!popup) view.location.href = url; 28615 url = undefined; // release reference before dispatching 28616 filesaver.readyState = filesaver.DONE; 28617 dispatch_all(); 28618 }; 28619 reader.readAsDataURL(blob); 28620 filesaver.readyState = filesaver.INIT; 28621 return; 28622 } // don't create more object URLs than needed 28623 28624 if (!object_url) { 28625 object_url = get_URL().createObjectURL(blob); 28626 } 28627 if (force) { 28628 view.location.href = object_url; 28629 } else { 28630 var opened = view.open(object_url, '_blank'); 28631 if (!opened) { 28632 // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html 28633 view.location.href = object_url; 28634 } 28635 } 28636 filesaver.readyState = filesaver.DONE; 28637 dispatch_all(); 28638 revoke(object_url); 28639 }; 28640 filesaver.readyState = filesaver.INIT; 28641 if (can_use_save_link) { 28642 object_url = get_URL().createObjectURL(blob); 28643 setTimeout(function () { 28644 save_link.href = object_url;
28645 save_link.download = name; 28646 click(save_link); 28647 dispatch_all(); 28648 revoke(object_url); 28649 filesaver.readyState = filesaver.DONE; 28650 }); 28651 return; 28652 } 28653 fs_error(); 28654 }, 28655 FS_proto = FileSaver.prototype, 28656 saveAs = function (blob, name, no_auto_bom) { 28657 return new FileSaver(blob, name || blob.name || 'download', no_auto_bom); 28658 }; // IE 10+ (native saveAs) 28659 if (typeof navigator !== 'undefined' && navigator.msSaveOrOpenBlob) { 28660 return function (blob, name, no_auto_bom) { 28661 name = name || blob.name || 'download'; 28662 if (!no_auto_bom) { 28663 blob = auto_bom(blob); 28664 } 28665 return navigator.msSaveOrOpenBlob(blob, name); 28666 }; 28667 } 28668 FS_proto.abort = function () { 28669 }; 28670 FS_proto.readyState = FS_proto.INIT = 0; 28671 FS_proto.WRITING = 1; 28672 FS_proto.DONE = 2; 28673 FS_proto.error = FS_proto.onwritestart = FS_proto.onprogress = FS_proto.onwrite = FS_proto.onabort = FS_proto.onerror = FS_proto.onwriteend = null; 28674 return saveAs; 28675 }(typeof self !== 'undefined' && self || typeof window !== 'undefined' && window || this.content); // `self` is undefined in Firefox for Android content script context 28676 // while `this` is nsIContentFrameMessageManager 28677 // with an attribute `content` that corresponds to the window 28678 if (typeof module !== 'undefined' && module.exports) { 28679 module.exports.saveAs = saveAs; 28680 } else if (typeof define !== 'undefined' && define !== null && define.amd !== null) { 28681 define('FileSaver.js', function () { 28682 return saveAs; 28683 }); 28684 } 28685 }, 28686 { 28687 } 28688 ], 28689 255: [ 28690 function (_dereq_, module, exports) { 28691 var __defProp = Object.defineProperty; 28692 var __markAsModule = target=>__defProp(target, '__esModule', { 28693 value: true 28694 }); 28695 var __export = (target, all) =>{ 28696 for (var name in all) __defProp(target, name, { 28697 get: all[name], 28698 enumerable: true 28699 }); 28700 }; // src/index.js 28701 __markAsModule(exports); 28702 __export(exports, { 28703 GIFEncoder: () =>GIFEncoder, 28704 applyPalette: () =>applyPalette, 28705 default: 28706 () =>src_default, 28707 nearestColor: () =>nearestColor, 28708 nearestColorIndex: () =>nearestColorIndex, 28709 nearestColorIndexWithDistance: () =>nearestColorIndexWithDistance, 28710 prequantize: () =>prequantize, 28711 quantize: () =>quantize, 28712 snapColorsToPalette: () =>snapColorsToPalette 28713 }); // src/constants.js 28714 var constants_default = { 28715 signature: 'GIF', 28716 version: '89a', 28717 trailer: 59, 28718 extensionIntroducer: 33, 28719 applicationExtensionLabel: 255, 28720 graphicControlExtensionLabel: 249, 28721 imageSeparator: 44, 28722 signatureSize: 3, 28723 versionSize: 3, 28724 globalColorTableFlagMask: 128, 28725 colorResolutionMask: 112, 28726 sortFlagMask: 8, 28727 globalColorTableSizeMask: 7, 28728 applicationIdentifierSize: 8, 28729 applicationAuthCodeSize: 3, 28730 disposalMethodMask: 28, 28731 userInputFlagMask: 2, 28732 transparentColorFlagMask: 1, 28733 localColorTableFlagMask: 128, 28734 interlaceFlagMask: 64, 28735 idSortFlagMask: 32, 28736 localColorTableSizeMask: 7 28737 }; // src/stream.js 28738 function createStream(initialCapacity = 256) { 28739 let cursor = 0; 28740 let contents = new Uint8Array(initialCapacity); 28741 return { 28742 get buffer() { 28743 return contents.buffer; 28744 }, 28745 reset() { 28746 cursor = 0; 28747 }, 28748 bytesView() { 28749 return contents.subarray(0, cursor); 28750 }, 28751 bytes() { 28752 return contents.slice(0, cursor); 28753 }, 28754 writeByte(byte) { 28755 expand(cursor + 1); 28756 contents[cursor] = byte; 28757 cursor++; 28758 }, 28759 writeBytes(data, offset = 0, byteLength = data.length) { 28760 expand(cursor + byteLength); 28761 for (let i = 0; i < byteLength; i++) { 28762 contents[cursor++] = data[i + offset]; 28763 } 28764 }, 28765 writeBytesView(data, offset = 0, byteLength = data.byteLength) { 28766 expand(cursor + byteLength); 28767 contents.set(data.subarray(offset, offset + byteLength), cursor); 28768 cursor += byteLength; 28769 } 28770 }; 28771 function expand(newCapacity) { 28772 var prevCapacity = contents.length; 28773 if (prevCapacity >= newCapacity) return; 28774 var CAPACITY_DOUBLING_MAX = 1024 * 1024; 28775 newCapacity = Math.max(newCapacity, prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125) >>> 0); 28776 if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); 28777 const oldContents = contents; 28778 contents = new Uint8Array(newCapacity); 28779 if (cursor > 0) contents.set(oldContents.subarray(0, cursor), 0); 28780 } 28781 } // src/lzwEncode.js 28782 28783 var BITS = 12; 28784 var DEFAULT_HSIZE = 5003; 28785 var MASKS = [ 28786 0, 28787 1, 28788 3, 28789 7, 28790 15, 28791 31, 28792 63, 28793 127, 28794 255, 28795 511, 28796 1023, 28797 2047, 28798 4095, 28799 8191, 28800 16383, 28801 32767, 28802 65535 28803 ]; 28804 function lzwEncode(width, height, pixels, colorDepth, outStream = createStream(512), accum = new Uint8Array(256), htab = new Int32Array(DEFAULT_HSIZE), codetab = new Int32Array(DEFAULT_HSIZE)) { 28805 const hsize = htab.length;
28806 const initCodeSize = Math.max(2, colorDepth); 28807 accum.fill(0); 28808 codetab.fill(0); 28809 htab.fill( - 1); 28810 let cur_accum = 0; 28811 let cur_bits = 0; 28812 const init_bits = initCodeSize + 1; 28813 const g_init_bits = init_bits; 28814 let clear_flg = false; 28815 let n_bits = g_init_bits; 28816 let maxcode = (1 << n_bits) - 1; 28817 const ClearCode = 1 << init_bits - 1; 28818 const EOFCode = ClearCode + 1; 28819 let free_ent = ClearCode + 2; 28820 let a_count = 0; 28821 let ent = pixels[0]; 28822 let hshift = 0; 28823 for (let fcode = hsize; fcode < 65536; fcode *= 2) { 28824 ++hshift; 28825 } 28826 hshift = 8 - hshift; 28827 outStream.writeByte(initCodeSize); 28828 output(ClearCode); 28829 const length = pixels.length; 28830 for (let idx = 1; idx < length; idx++) { 28831 next_block: { 28832 const c = pixels[idx]; 28833 const fcode = (c << BITS) + ent; 28834 let i = c << hshift ^ ent; 28835 if (htab[i] === fcode) { 28836 ent = codetab[i]; 28837 break next_block; 28838 } 28839 const disp = i === 0 ? 1 : hsize - i; 28840 while (htab[i] >= 0) { 28841 i -= disp; 28842 if (i < 0) i += hsize; 28843 if (htab[i] === fcode) { 28844 ent = codetab[i]; 28845 break next_block; 28846 } 28847 } 28848 output(ent); 28849 ent = c; 28850 if (free_ent < 1 << BITS) { 28851 codetab[i] = free_ent++; 28852 htab[i] = fcode; 28853 } else { 28854 htab.fill( - 1); 28855 free_ent = ClearCode + 2; 28856 clear_flg = true; 28857 output(ClearCode); 28858 } 28859 } 28860 } 28861 output(ent); 28862 output(EOFCode); 28863 outStream.writeByte(0); 28864 return outStream.bytesView(); 28865 function output(code) { 28866 cur_accum &= MASKS[cur_bits]; 28867 if (cur_bits > 0) cur_accum |= code << cur_bits; 28868 else cur_accum = code; 28869 cur_bits += n_bits; 28870 while (cur_bits >= 8) { 28871 accum[a_count++] = cur_accum & 255; 28872 if (a_count >= 254) { 28873 outStream.writeByte(a_count); 28874 outStream.writeBytesView(accum, 0, a_count); 28875 a_count = 0; 28876 } 28877 cur_accum >>= 8; 28878 cur_bits -= 8; 28879 } 28880 if (free_ent > maxcode || clear_flg) { 28881 if (clear_flg) { 28882 n_bits = g_init_bits; 28883 maxcode = (1 << n_bits) - 1; 28884 clear_flg = false; 28885 } else { 28886 ++n_bits; 28887 maxcode = n_bits === BITS ? 1 << n_bits : (1 << n_bits) - 1; 28888 } 28889 } 28890 if (code == EOFCode) { 28891 while (cur_bits > 0) { 28892 accum[a_count++] = cur_accum & 255; 28893 if (a_count >= 254) { 28894 outStream.writeByte(a_count); 28895 outStream.writeBytesView(accum, 0, a_count); 28896 a_count = 0; 28897 } 28898 cur_accum >>= 8; 28899 cur_bits -= 8; 28900 } 28901 if (a_count > 0) { 28902 outStream.writeByte(a_count); 28903 outStream.writeBytesView(accum, 0, a_count); 28904 a_count = 0; 28905 } 28906 } 28907 } 28908 } 28909 var lzwEncode_default = lzwEncode; // src/rgb-packing.js 28910 function rgb888_to_rgb565(r, g, b) { 28911 return r << 8 & 63488 | g << 2 & 992 | b >> 3; 28912 } 28913 function rgba8888_to_rgba4444(r, g, b, a) { 28914 return r >> 4 | g & 240 | (b & 240) << 4 | (a & 240) << 8; 28915 } 28916 function rgb888_to_rgb444(r, g, b) { 28917 return r >> 4 << 8 | g & 240 | b >> 4; 28918 } // src/pnnquant2.js 28919 28920 function clamp(value, min, max) { 28921 return value < min ? min : value > max ? max : value; 28922 } 28923 function sqr(value) { 28924 return value * value; 28925 } 28926 function find_nn(bins, idx, hasAlpha) { 28927 var nn = 0; 28928 var err = 1e+100; 28929 const bin1 = bins[idx]; 28930 const n1 = bin1.cnt; 28931 const wa = bin1.ac; 28932 const wr = bin1.rc; 28933 const wg = bin1.gc; 28934 const wb = bin1.bc; 28935 for (var i = bin1.fw; i != 0; i = bins[i].fw) { 28936 const bin = bins[i]; 28937 const n2 = bin.cnt; 28938 const nerr2 = n1 * n2 / (n1 + n2); 28939 if (nerr2 >= err) continue; 28940 var nerr = 0; 28941 if (hasAlpha) { 28942 nerr += nerr2 * sqr(bin.ac - wa); 28943 if (nerr >= err) continue; 28944 } 28945 nerr += nerr2 * sqr(bin.rc - wr); 28946 if (nerr >= err) continue; 28947 nerr += nerr2 * sqr(bin.gc - wg); 28948 if (nerr >= err) continue; 28949 nerr += nerr2 * sqr(bin.bc - wb); 28950 if (nerr >= err) continue; 28951 err = nerr; 28952 nn = i; 28953 } 28954 bin1.err = err;
28955 bin1.nn = nn; 28956 } 28957 function create_bin() { 28958 return { 28959 ac: 0, 28960 rc: 0, 28961 gc: 0, 28962 bc: 0, 28963 cnt: 0, 28964 nn: 0, 28965 fw: 0, 28966 bk: 0, 28967 tm: 0, 28968 mtm: 0, 28969 err: 0 28970 }; 28971 } 28972 function create_bin_list(data, format) { 28973 const bincount = format === 'rgb444' ? 4096 : 65536; 28974 const bins = new Array(bincount); 28975 const size = data.length; 28976 if (format === 'rgba4444') { 28977 for (let i = 0; i < size; ++i) { 28978 const color = data[i]; 28979 const a = color >> 24 & 255; 28980 const b = color >> 16 & 255; 28981 const g = color >> 8 & 255; 28982 const r = color & 255; 28983 const index = rgba8888_to_rgba4444(r, g, b, a); 28984 let bin = index in bins ? bins[index] : bins[index] = create_bin(); 28985 bin.rc += r; 28986 bin.gc += g; 28987 bin.bc += b; 28988 bin.ac += a; 28989 bin.cnt++; 28990 } 28991 } else if (format === 'rgb444') { 28992 for (let i = 0; i < size; ++i) { 28993 const color = data[i]; 28994 const b = color >> 16 & 255; 28995 const g = color >> 8 & 255; 28996 const r = color & 255; 28997 const index = rgb888_to_rgb444(r, g, b); 28998 let bin = index in bins ? bins[index] : bins[index] = create_bin(); 28999 bin.rc += r; 29000 bin.gc += g; 29001 bin.bc += b; 29002 bin.cnt++; 29003 } 29004 } else { 29005 for (let i = 0; i < size; ++i) { 29006 const color = data[i]; 29007 const b = color >> 16 & 255; 29008 const g = color >> 8 & 255; 29009 const r = color & 255; 29010 const index = rgb888_to_rgb565(r, g, b); 29011 let bin = index in bins ? bins[index] : bins[index] = create_bin(); 29012 bin.rc += r; 29013 bin.gc += g; 29014 bin.bc += b; 29015 bin.cnt++; 29016 } 29017 } 29018 return bins; 29019 } 29020 function quantize(rgba, maxColors, opts = { 29021 }) { 29022 const { 29023 format = 'rgb565', 29024 clearAlpha = true, 29025 clearAlphaColor = 0, 29026 clearAlphaThreshold = 0, 29027 oneBitAlpha = false 29028 } 29029 = opts; 29030 if (!rgba || !rgba.buffer) { 29031 throw new Error('quantize() expected RGBA Uint8Array data'); 29032 } 29033 if (!(rgba instanceof Uint8Array) && !(rgba instanceof Uint8ClampedArray)) { 29034 throw new Error('quantize() expected RGBA Uint8Array data'); 29035 } 29036 const data = new Uint32Array(rgba.buffer); 29037 let useSqrt = opts.useSqrt !== false; 29038 const hasAlpha = format === 'rgba4444'; 29039 const bins = create_bin_list(data, format); 29040 const bincount = bins.length; 29041 const bincountMinusOne = bincount - 1; 29042 const heap = new Uint32Array(bincount + 1); 29043 var maxbins = 0; 29044 for (var i = 0; i < bincount; ++i) { 29045 const bin = bins[i]; 29046 if (bin != null) { 29047 var d = 1 / bin.cnt; 29048 if (hasAlpha) bin.ac *= d; 29049 bin.rc *= d; 29050 bin.gc *= d; 29051 bin.bc *= d; 29052 bins[maxbins++] = bin; 29053 } 29054 } 29055 if (sqr(maxColors) / maxbins < 0.022) { 29056 useSqrt = false; 29057 } 29058 var i = 0; 29059 for (; i < maxbins - 1; ++i) { 29060 bins[i].fw = i + 1; 29061 bins[i + 1].bk = i; 29062 if (useSqrt) bins[i].cnt = Math.sqrt(bins[i].cnt); 29063 } 29064 if (useSqrt) bins[i].cnt = Math.sqrt(bins[i].cnt); 29065 var h, 29066 l, 29067 l2; 29068 for (i = 0; i < maxbins; ++i) { 29069 find_nn(bins, i, false); 29070 var err = bins[i].err; 29071 for (l = ++heap[0]; l > 1; l = l2) { 29072 l2 = l >> 1; 29073 if (bins[h = heap[l2]].err <= err) break; 29074 heap[l] = h; 29075 } 29076 heap[l] = i; 29077 } 29078 var extbins = maxbins - maxColors; 29079 for (i = 0; i < extbins; ) { 29080 var tb; 29081 for (; ; ) { 29082 var b1 = heap[1]; 29083 tb = bins[b1]; 29084 if (tb.tm >= tb.mtm && bins[tb.nn].mtm <= tb.tm) break; 29085 if (tb.mtm == bincountMinusOne) b1 = heap[1] = heap[heap[0]--]; 29086 else { 29087 find_nn(bins, b1, false); 29088 tb.tm = i; 29089 }
29090 var err = bins[b1].err; 29091 for (l = 1; (l2 = l + l) <= heap[0]; l = l2) { 29092 if (l2 < heap[0] && bins[heap[l2]].err > bins[heap[l2 + 1]].err) l2++; 29093 if (err <= bins[h = heap[l2]].err) break; 29094 heap[l] = h; 29095 } 29096 heap[l] = b1; 29097 } 29098 var nb = bins[tb.nn]; 29099 var n1 = tb.cnt; 29100 var n2 = nb.cnt; 29101 var d = 1 / (n1 + n2); 29102 if (hasAlpha) tb.ac = d * (n1 * tb.ac + n2 * nb.ac); 29103 tb.rc = d * (n1 * tb.rc + n2 * nb.rc); 29104 tb.gc = d * (n1 * tb.gc + n2 * nb.gc); 29105 tb.bc = d * (n1 * tb.bc + n2 * nb.bc); 29106 tb.cnt += nb.cnt; 29107 tb.mtm = ++i; 29108 bins[nb.bk].fw = nb.fw; 29109 bins[nb.fw].bk = nb.bk; 29110 nb.mtm = bincountMinusOne; 29111 } 29112 let palette = [ 29113 ]; 29114 var k = 0; 29115 for (i = 0; ; ++k) { 29116 let r = clamp(Math.round(bins[i].rc), 0, 255); 29117 let g = clamp(Math.round(bins[i].gc), 0, 255); 29118 let b = clamp(Math.round(bins[i].bc), 0, 255); 29119 let a = 255; 29120 if (hasAlpha) { 29121 a = clamp(Math.round(bins[i].ac), 0, 255); 29122 if (oneBitAlpha) { 29123 const threshold = typeof oneBitAlpha === 'number' ? oneBitAlpha : 127; 29124 a = a <= threshold ? 0 : 255; 29125 } 29126 if (clearAlpha && a <= clearAlphaThreshold) { 29127 r = g = b = clearAlphaColor; 29128 a = 0; 29129 } 29130 } 29131 const color = hasAlpha ? [ 29132 r, 29133 g, 29134 b, 29135 a 29136 ] : [ 29137 r, 29138 g, 29139 b 29140 ]; 29141 const exists = existsInPalette(palette, color); 29142 if (!exists) palette.push(color); 29143 if ((i = bins[i].fw) == 0) break; 29144 } 29145 return palette; 29146 } 29147 function existsInPalette(palette, color) { 29148 for (let i = 0; i < palette.length; i++) { 29149 const p = palette[i]; 29150 let matchesRGB = p[0] === color[0] && p[1] === color[1] && p[2] === color[2]; 29151 let matchesAlpha = p.length >= 4 && color.length >= 4 ? p[3] === color[3] : true; 29152 if (matchesRGB && matchesAlpha) return true; 29153 } 29154 return false; 29155 } // src/color.js 29156 29157 function euclideanDistanceSquared(a, b) { 29158 var sum = 0; 29159 var n; 29160 for (n = 0; n < a.length; n++) { 29161 const dx = a[n] - b[n]; 29162 sum += dx * dx; 29163 } 29164 return sum; 29165 } // src/palettize.js 29166 29167 function roundStep(byte, step) { 29168 return step > 1 ? Math.round(byte / step) * step : byte; 29169 } 29170 function prequantize(rgba, { 29171 roundRGB = 5, 29172 roundAlpha = 10, 29173 oneBitAlpha = null 29174 } 29175 = { 29176 }) { 29177 const data = new Uint32Array(rgba.buffer); 29178 for (let i = 0; i < data.length; i++) { 29179 const color = data[i]; 29180 let a = color >> 24 & 255; 29181 let b = color >> 16 & 255; 29182 let g = color >> 8 & 255; 29183 let r = color & 255; 29184 a = roundStep(a, roundAlpha); 29185 if (oneBitAlpha) { 29186 const threshold = typeof oneBitAlpha === 'number' ? oneBitAlpha : 127; 29187 a = a <= threshold ? 0 : 255; 29188 } 29189 r = roundStep(r, roundRGB); 29190 g = roundStep(g, roundRGB); 29191 b = roundStep(b, roundRGB); 29192 data[i] = a << 24 | b << 16 | g << 8 | r << 0; 29193 } 29194 } 29195 function applyPalette(rgba, palette, format = 'rgb565') { 29196 if (!rgba || !rgba.buffer) { 29197 throw new Error('quantize() expected RGBA Uint8Array data'); 29198 } 29199 if (!(rgba instanceof Uint8Array) && !(rgba instanceof Uint8ClampedArray)) { 29200 throw new Error('quantize() expected RGBA Uint8Array data'); 29201 } 29202 if (palette.length > 256) { 29203 throw new Error('applyPalette() only works with 256 colors or less'); 29204 } 29205 const data = new Uint32Array(rgba.buffer); 29206 const length = data.length; 29207 const bincount = format === 'rgb444' ? 4096 : 65536; 29208 const index = new Uint8Array(length); 29209 const cache = new Array(bincount); 29210 const hasAlpha = format === 'rgba4444'; 29211 if (format === 'rgba4444') { 29212 for (let i = 0; i < length; i++) { 29213 const color = data[i]; 29214 const a = color >> 24 & 255; 29215 const b = color >> 16 & 255; 29216 const g = color >> 8 & 255; 29217 const r = color & 255;
29218 const key = rgba8888_to_rgba4444(r, g, b, a); 29219 const idx = key in cache ? cache[key] : cache[key] = nearestColorIndexRGBA(r, g, b, a, palette); 29220 index[i] = idx; 29221 } 29222 } else { 29223 const rgb888_to_key = format === 'rgb444' ? rgb888_to_rgb444 : rgb888_to_rgb565; 29224 for (let i = 0; i < length; i++) { 29225 const color = data[i]; 29226 const b = color >> 16 & 255; 29227 const g = color >> 8 & 255; 29228 const r = color & 255; 29229 const key = rgb888_to_key(r, g, b); 29230 const idx = key in cache ? cache[key] : cache[key] = nearestColorIndexRGB(r, g, b, palette); 29231 index[i] = idx; 29232 } 29233 } 29234 return index; 29235 } 29236 function nearestColorIndexRGBA(r, g, b, a, palette) { 29237 let k = 0; 29238 let mindist = 1e+100; 29239 for (let i = 0; i < palette.length; i++) { 29240 const px2 = palette[i]; 29241 const a2 = px2[3]; 29242 let curdist = sqr2(a2 - a); 29243 if (curdist > mindist) continue; 29244 const r2 = px2[0]; 29245 curdist += sqr2(r2 - r); 29246 if (curdist > mindist) continue; 29247 const g2 = px2[1]; 29248 curdist += sqr2(g2 - g); 29249 if (curdist > mindist) continue; 29250 const b2 = px2[2]; 29251 curdist += sqr2(b2 - b); 29252 if (curdist > mindist) continue; 29253 mindist = curdist; 29254 k = i; 29255 } 29256 return k; 29257 } 29258 function nearestColorIndexRGB(r, g, b, palette) { 29259 let k = 0; 29260 let mindist = 1e+100; 29261 for (let i = 0; i < palette.length; i++) { 29262 const px2 = palette[i]; 29263 const r2 = px2[0]; 29264 let curdist = sqr2(r2 - r); 29265 if (curdist > mindist) continue; 29266 const g2 = px2[1]; 29267 curdist += sqr2(g2 - g); 29268 if (curdist > mindist) continue; 29269 const b2 = px2[2]; 29270 curdist += sqr2(b2 - b); 29271 if (curdist > mindist) continue; 29272 mindist = curdist; 29273 k = i; 29274 } 29275 return k; 29276 } 29277 function snapColorsToPalette(palette, knownColors, threshold = 5) { 29278 if (!palette.length || !knownColors.length) return; 29279 const paletteRGB = palette.map(p=>p.slice(0, 3)); 29280 const thresholdSq = threshold * threshold; 29281 const dim = palette[0].length; 29282 for (let i = 0; i < knownColors.length; i++) { 29283 let color = knownColors[i]; 29284 if (color.length < dim) { 29285 color = [ 29286 color[0], 29287 color[1], 29288 color[2], 29289 255 29290 ]; 29291 } else if (color.length > dim) { 29292 color = color.slice(0, 3); 29293 } else { 29294 color = color.slice(); 29295 } 29296 const r = nearestColorIndexWithDistance(paletteRGB, color.slice(0, 3), euclideanDistanceSquared); 29297 const idx = r[0]; 29298 const distanceSq = r[1]; 29299 if (distanceSq > 0 && distanceSq <= thresholdSq) { 29300 palette[idx] = color; 29301 } 29302 } 29303 } 29304 function sqr2(a) { 29305 return a * a; 29306 } 29307 function nearestColorIndex(colors, pixel, distanceFn = euclideanDistanceSquared) { 29308 let minDist = Infinity; 29309 let minDistIndex = - 1; 29310 for (let j = 0; j < colors.length; j++) { 29311 const paletteColor = colors[j]; 29312 const dist = distanceFn(pixel, paletteColor); 29313 if (dist < minDist) { 29314 minDist = dist; 29315 minDistIndex = j; 29316 } 29317 } 29318 return minDistIndex; 29319 } 29320 function nearestColorIndexWithDistance(colors, pixel, distanceFn = euclideanDistanceSquared) { 29321 let minDist = Infinity; 29322 let minDistIndex = - 1; 29323 for (let j = 0; j < colors.length; j++) { 29324 const paletteColor = colors[j]; 29325 const dist = distanceFn(pixel, paletteColor); 29326 if (dist < minDist) { 29327 minDist = dist; 29328 minDistIndex = j; 29329 } 29330 } 29331 return [minDistIndex, 29332 minDist]; 29333 } 29334 function nearestColor(colors, pixel, distanceFn = euclideanDistanceSquared) { 29335 return colors[nearestColorIndex(colors, pixel, distanceFn)]; 29336 } // src/index.js 29337 29338 function GIFEncoder(opt = { 29339 }) { 29340 const { 29341 initialCapacity = 4096, 29342 auto = true 29343 } 29344 = opt; 29345 const stream = createStream(initialCapacity); 29346 const HSIZE = 5003; 29347 const accum = new Uint8Array(256); 29348 const htab = new Int32Array(HSIZE); 29349 const codetab = new Int32Array(HSIZE); 29350 let hasInit = false;
29351 return { 29352 reset() { 29353 stream.reset(); 29354 hasInit = false; 29355 }, 29356 finish() { 29357 stream.writeByte(constants_default.trailer); 29358 }, 29359 bytes() { 29360 return stream.bytes(); 29361 }, 29362 bytesView() { 29363 return stream.bytesView(); 29364 }, 29365 get buffer() { 29366 return stream.buffer; 29367 }, 29368 get stream() { 29369 return stream; 29370 }, 29371 writeHeader, 29372 writeFrame(index, width, height, opts = { 29373 }) { 29374 const { 29375 transparent = false, 29376 transparentIndex = 0, 29377 delay = 0, 29378 palette = null, 29379 repeat = 0, 29380 colorDepth = 8, 29381 dispose = - 1 29382 } 29383 = opts; 29384 let first = false; 29385 if (auto) { 29386 if (!hasInit) { 29387 first = true; 29388 writeHeader(); 29389 hasInit = true; 29390 } 29391 } else { 29392 first = Boolean(opts.first); 29393 } 29394 width = Math.max(0, Math.floor(width)); 29395 height = Math.max(0, Math.floor(height)); 29396 if (first) { 29397 if (!palette) { 29398 throw new Error('First frame must include a { palette } option'); 29399 } 29400 encodeLogicalScreenDescriptor(stream, width, height, palette, colorDepth); 29401 encodeColorTable(stream, palette); 29402 if (repeat >= 0) { 29403 encodeNetscapeExt(stream, repeat); 29404 } 29405 } 29406 const delayTime = Math.round(delay / 10); 29407 encodeGraphicControlExt(stream, dispose, delayTime, transparent, transparentIndex); 29408 const useLocalColorTable = Boolean(palette) && !first; 29409 encodeImageDescriptor(stream, width, height, useLocalColorTable ? palette : null); 29410 if (useLocalColorTable) encodeColorTable(stream, palette); 29411 encodePixels(stream, index, width, height, colorDepth, accum, htab, codetab); 29412 } 29413 }; 29414 function writeHeader() { 29415 writeUTFBytes(stream, 'GIF89a'); 29416 } 29417 } 29418 function encodeGraphicControlExt(stream, dispose, delay, transparent, transparentIndex) { 29419 stream.writeByte(33); 29420 stream.writeByte(249); 29421 stream.writeByte(4); 29422 if (transparentIndex < 0) { 29423 transparentIndex = 0; 29424 transparent = false; 29425 } 29426 var transp, 29427 disp; 29428 if (!transparent) { 29429 transp = 0; 29430 disp = 0; 29431 } else { 29432 transp = 1; 29433 disp = 2; 29434 } 29435 if (dispose >= 0) { 29436 disp = dispose & 7; 29437 } 29438 disp <<= 2; 29439 const userInput = 0; 29440 stream.writeByte(0 | disp | userInput | transp); 29441 writeUInt16(stream, delay); 29442 stream.writeByte(transparentIndex || 0); 29443 stream.writeByte(0); 29444 } 29445 function encodeLogicalScreenDescriptor(stream, width, height, palette, colorDepth = 8) { 29446 const globalColorTableFlag = 1; 29447 const sortFlag = 0; 29448 const globalColorTableSize = colorTableSize(palette.length) - 1; 29449 const fields = globalColorTableFlag << 7 | colorDepth - 1 << 4 | sortFlag << 3 | globalColorTableSize; 29450 const backgroundColorIndex = 0; 29451 const pixelAspectRatio = 0; 29452 writeUInt16(stream, width); 29453 writeUInt16(stream, height); 29454 stream.writeBytes([fields, 29455 backgroundColorIndex, 29456 pixelAspectRatio]); 29457 } 29458 function encodeNetscapeExt(stream, repeat) { 29459 stream.writeByte(33); 29460 stream.writeByte(255); 29461 stream.writeByte(11); 29462 writeUTFBytes(stream, 'NETSCAPE2.0'); 29463 stream.writeByte(3); 29464 stream.writeByte(1); 29465 writeUInt16(stream, repeat); 29466 stream.writeByte(0); 29467 } 29468 function encodeColorTable(stream, palette) { 29469 const colorTableLength = 1 << colorTableSize(palette.length); 29470 for (let i = 0; i < colorTableLength; i++) { 29471 let color = [ 29472 0, 29473 0, 29474 0 29475 ]; 29476 if (i < palette.length) { 29477 color = palette[i]; 29478 } 29479 stream.writeByte(color[0]); 29480 stream.writeByte(color[1]); 29481 stream.writeByte(color[2]); 29482 } 29483 } 29484 function encodeImageDescriptor(stream, width, height, localPalette) { 29485 stream.writeByte(44); 29486 writeUInt16(stream, 0); 29487 writeUInt16(stream, 0); 29488 writeUInt16(stream, width); 29489 writeUInt16(stream, height); 29490 if (localPalette) { 29491 const interlace = 0; 29492 const sorted = 0; 29493 const palSize = colorTableSize(localPalette.length) - 1; 29494 stream.writeByte(128 | interlace | sorted | 0 | palSize); 29495 } else { 29496 stream.writeByte(0); 29497 } 29498 } 29499 function encodePixels(stream, index, width, height, colorDepth = 8, accum, htab, codetab) { 29500 lzwEncode_default(width, height, index, colorDepth, stream, accum, htab, codetab); 29501 } 29502 function writeUInt16(stream, short) { 29503 stream.writeByte(short & 255); 29504 stream.writeByte(short >> 8 & 255); 29505 } 29506 function writeUTFBytes(stream, text) { 29507 for (var i = 0; i < text.length; i++) { 29508 stream.writeByte(text.charCodeAt(i)); 29509 } 29510 } 29511 function colorTableSize(length) { 29512 return Math.max(Math.ceil(Math.log2(length)), 1); 29513 } 29514 var src_default = GIFEncoder; 29515 }, 29516 { 29517 } 29518 ], 29519 256: [
29520 function (_dereq_, module, exports) { 29521 'use strict'; 29522 function _interopDefault(ex) { 29523 return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex; 29524 } 29525 var _classCallCheck = _interopDefault(_dereq_('@babel/runtime/helpers/classCallCheck')); 29526 var _createClass = _interopDefault(_dereq_('@babel/runtime/helpers/createClass')); 29527 var arr = [ 29528 ]; 29529 var each = arr.forEach; 29530 var slice = arr.slice; 29531 function defaults(obj) { 29532 each.call(slice.call(arguments, 1), function (source) { 29533 if (source) { 29534 for (var prop in source) { 29535 if (obj[prop] === undefined) obj[prop] = source[prop]; 29536 } 29537 } 29538 }); 29539 return obj; 29540 } 29541 var cookie = { 29542 create: function create(name, value, minutes, domain) { 29543 var expires; 29544 if (minutes) { 29545 var date = new Date(); 29546 date.setTime(date.getTime() + minutes * 60 * 1000); 29547 expires = '; expires=' + date.toGMTString(); 29548 } else expires = ''; 29549 domain = domain ? 'domain=' + domain + ';' : ''; 29550 document.cookie = name + '=' + value + expires + ';' + domain + 'path=/'; 29551 }, 29552 read: function read(name) { 29553 var nameEQ = name + '='; 29554 var ca = document.cookie.split(';'); 29555 for (var i = 0; i < ca.length; i++) { 29556 var c = ca[i]; 29557 while (c.charAt(0) === ' ') { 29558 c = c.substring(1, c.length); 29559 } 29560 if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); 29561 } 29562 return null; 29563 }, 29564 remove: function remove(name) { 29565 this.create(name, '', - 1); 29566 } 29567 }; 29568 var cookie$1 = { 29569 name: 'cookie', 29570 lookup: function lookup(options) { 29571 var found; 29572 if (options.lookupCookie && typeof document !== 'undefined') { 29573 var c = cookie.read(options.lookupCookie); 29574 if (c) found = c; 29575 } 29576 return found; 29577 }, 29578 cacheUserLanguage: function cacheUserLanguage(lng, options) { 29579 if (options.lookupCookie && typeof document !== 'undefined') { 29580 cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain); 29581 } 29582 } 29583 }; 29584 var querystring = { 29585 name: 'querystring', 29586 lookup: function lookup(options) { 29587 var found; 29588 if (typeof window !== 'undefined') { 29589 var query = window.location.search.substring(1); 29590 var params = query.split('&'); 29591 for (var i = 0; i < params.length; i++) { 29592 var pos = params[i].indexOf('='); 29593 if (pos > 0) { 29594 var key = params[i].substring(0, pos); 29595 if (key === options.lookupQuerystring) { 29596 found = params[i].substring(pos + 1); 29597 } 29598 } 29599 } 29600 } 29601 return found; 29602 } 29603 }; 29604 var hasLocalStorageSupport; 29605 try { 29606 hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null; 29607 var testKey = 'i18next.translate.boo'; 29608 window.localStorage.setItem(testKey, 'foo'); 29609 window.localStorage.removeItem(testKey); 29610 } catch (e) { 29611 hasLocalStorageSupport = false; 29612 } 29613 var localStorage = { 29614 name: 'localStorage', 29615 lookup: function lookup(options) { 29616 var found; 29617 if (options.lookupLocalStorage && hasLocalStorageSupport) { 29618 var lng = window.localStorage.getItem(options.lookupLocalStorage); 29619 if (lng) found = lng; 29620 } 29621 return found; 29622 }, 29623 cacheUserLanguage: function cacheUserLanguage(lng, options) { 29624 if (options.lookupLocalStorage && hasLocalStorageSupport) { 29625 window.localStorage.setItem(options.lookupLocalStorage, lng); 29626 } 29627 } 29628 }; 29629 var navigator$1 = { 29630 name: 'navigator', 29631 lookup: function lookup(options) { 29632 var found = [ 29633 ]; 29634 if (typeof navigator !== 'undefined') { 29635 if (navigator.languages) { 29636 // chrome only; not an array, so can't use .push.apply instead of iterating 29637 for (var i = 0; i < navigator.languages.length; i++) { 29638 found.push(navigator.languages[i]); 29639 } 29640 } 29641 if (navigator.userLanguage) { 29642 found.push(navigator.userLanguage); 29643 } 29644 if (navigator.language) { 29645 found.push(navigator.language); 29646 } 29647 } 29648 return found.length > 0 ? found : undefined; 29649 } 29650 }; 29651 var htmlTag = { 29652 name: 'htmlTag', 29653 lookup: function lookup(options) { 29654 var found; 29655 var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null); 29656 if (htmlTag && typeof htmlTag.getAttribute === 'function') { 29657 found = htmlTag.getAttribute('lang'); 29658 } 29659 return found; 29660 } 29661 }; 29662 var path = { 29663 name: 'path', 29664 lookup: function lookup(options) { 29665 var found; 29666 if (typeof window !== 'undefined') { 29667 var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g); 29668 if (language instanceof Array) { 29669 if (typeof options.lookupFromPathIndex === 'number') { 29670 if (typeof language[options.lookupFromPathIndex] !== 'string') { 29671 return undefined; 29672 } 29673 found = language[options.lookupFromPathIndex].replace('/', ''); 29674 } else { 29675 found = language[0].replace('/', ''); 29676 } 29677 } 29678 } 29679 return found; 29680 } 29681 }; 29682 var subdomain = { 29683 name: 'subdomain', 29684 lookup: function lookup(options) { 29685 var found; 29686 if (typeof window !== 'undefined') { 29687 var language = window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi); 29688 if (language instanceof Array) { 29689 if (typeof options.lookupFromSubdomainIndex === 'number') { 29690 found = language[options.lookupFromSubdomainIndex].replace('http://', '').replace('https://', '').replace('.', ''); 29691 } else { 29692 found = language[0].replace('http://', '').replace('https://', '').replace('.', ''); 29693 } 29694 } 29695 } 29696 return found; 29697 } 29698 }; 29699 function getDefaults() { 29700 return { 29701 order: [ 29702 'querystring',
29703 'cookie', 29704 'localStorage', 29705 'navigator', 29706 'htmlTag' 29707 ], 29708 lookupQuerystring: 'lng', 29709 lookupCookie: 'i18next', 29710 lookupLocalStorage: 'i18nextLng', 29711 // cache user language 29712 caches: [ 29713 'localStorage' 29714 ], 29715 excludeCacheFor: [ 29716 'cimode' 29717 ], 29718 //cookieMinutes: 10, 29719 //cookieDomain: 'myDomain' 29720 checkWhitelist: true 29721 }; 29722 } 29723 var Browser = /*#__PURE__*/ 29724 function () { 29725 function Browser(services) { 29726 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 29727 }; 29728 _classCallCheck(this, Browser); 29729 this.type = 'languageDetector'; 29730 this.detectors = { 29731 }; 29732 this.init(services, options); 29733 } 29734 _createClass(Browser, [ 29735 { 29736 key: 'init', 29737 value: function init(services) { 29738 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 29739 }; 29740 var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { 29741 }; 29742 this.services = services; 29743 this.options = defaults(options, this.options || { 29744 }, getDefaults()); // backwards compatibility 29745 if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex; 29746 this.i18nOptions = i18nOptions; 29747 this.addDetector(cookie$1); 29748 this.addDetector(querystring); 29749 this.addDetector(localStorage); 29750 this.addDetector(navigator$1); 29751 this.addDetector(htmlTag); 29752 this.addDetector(path); 29753 this.addDetector(subdomain); 29754 } 29755 }, 29756 { 29757 key: 'addDetector', 29758 value: function addDetector(detector) { 29759 this.detectors[detector.name] = detector; 29760 } 29761 }, 29762 { 29763 key: 'detect', 29764 value: function detect(detectionOrder) { 29765 var _this = this; 29766 if (!detectionOrder) detectionOrder = this.options.order; 29767 var detected = [ 29768 ]; 29769 detectionOrder.forEach(function (detectorName) { 29770 if (_this.detectors[detectorName]) { 29771 var lookup = _this.detectors[detectorName].lookup(_this.options); 29772 if (lookup && typeof lookup === 'string') lookup = [ 29773 lookup 29774 ]; 29775 if (lookup) detected = detected.concat(lookup); 29776 } 29777 }); 29778 var found; 29779 detected.forEach(function (lng) { 29780 if (found) return; 29781 var cleanedLng = _this.services.languageUtils.formatLanguageCode(lng); 29782 if (!_this.options.checkWhitelist || _this.services.languageUtils.isWhitelisted(cleanedLng)) found = cleanedLng; 29783 }); 29784 if (!found) { 29785 var fallbacks = this.i18nOptions.fallbackLng; 29786 if (typeof fallbacks === 'string') fallbacks = [ 29787 fallbacks 29788 ]; 29789 if (!fallbacks) fallbacks = [ 29790 ]; 29791 if (Object.prototype.toString.apply(fallbacks) === '[object Array]') { 29792 found = fallbacks[0]; 29793 } else { 29794 found = fallbacks[0] || fallbacks['default'] && fallbacks['default'][0]; 29795 } 29796 } 29797 return found; 29798 } 29799 }, 29800 { 29801 key: 'cacheUserLanguage', 29802 value: function cacheUserLanguage(lng, caches) { 29803 var _this2 = this; 29804 if (!caches) caches = this.options.caches; 29805 if (!caches) return; 29806 if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > - 1) return;
29807 caches.forEach(function (cacheName) { 29808 if (_this2.detectors[cacheName]) _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options); 29809 }); 29810 } 29811 } 29812 ]); 29813 return Browser; 29814 }(); 29815 Browser.type = 'languageDetector'; 29816 module.exports = Browser; 29817 }, 29818 { 29819 '@babel/runtime/helpers/classCallCheck': 257, 29820 '@babel/runtime/helpers/createClass': 258 29821 } 29822 ], 29823 257: [ 29824 function (_dereq_, module, exports) { 29825 arguments[4][5][0].apply(exports, arguments) 29826 }, 29827 { 29828 'dup': 5 29829 } 29830 ], 29831 258: [ 29832 function (_dereq_, module, exports) { 29833 arguments[4][6][0].apply(exports, arguments) 29834 }, 29835 { 29836 'dup': 6 29837 } 29838 ], 29839 259: [ 29840 function (_dereq_, module, exports) { 29841 'use strict'; 29842 function _interopDefault(ex) { 29843 return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex; 29844 } 29845 var _typeof = _interopDefault(_dereq_('@babel/runtime/helpers/typeof')); 29846 var _objectSpread = _interopDefault(_dereq_('@babel/runtime/helpers/objectSpread')); 29847 var _classCallCheck = _interopDefault(_dereq_('@babel/runtime/helpers/classCallCheck')); 29848 var _createClass = _interopDefault(_dereq_('@babel/runtime/helpers/createClass')); 29849 var _possibleConstructorReturn = _interopDefault(_dereq_('@babel/runtime/helpers/possibleConstructorReturn')); 29850 var _getPrototypeOf = _interopDefault(_dereq_('@babel/runtime/helpers/getPrototypeOf')); 29851 var _assertThisInitialized = _interopDefault(_dereq_('@babel/runtime/helpers/assertThisInitialized')); 29852 var _inherits = _interopDefault(_dereq_('@babel/runtime/helpers/inherits')); 29853 var _toConsumableArray = _interopDefault(_dereq_('@babel/runtime/helpers/toConsumableArray')); 29854 var _slicedToArray = _interopDefault(_dereq_('@babel/runtime/helpers/slicedToArray')); 29855 var consoleLogger = { 29856 type: 'logger', 29857 log: function log(args) { 29858 this.output('log', args); 29859 }, 29860 warn: function warn(args) { 29861 this.output('warn', args); 29862 }, 29863 error: function error(args) { 29864 this.output('error', args); 29865 }, 29866 output: function output(type, args) { 29867 var _console; 29868 /* eslint no-console: 0 */ 29869 if (console && console[type]) (_console = console) [type].apply(_console, _toConsumableArray(args)); 29870 } 29871 }; 29872 var Logger = /*#__PURE__*/ 29873 function () { 29874 function Logger(concreteLogger) { 29875 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 29876 }; 29877 _classCallCheck(this, Logger); 29878 this.init(concreteLogger, options); 29879 } 29880 _createClass(Logger, [ 29881 { 29882 key: 'init', 29883 value: function init(concreteLogger) { 29884 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 29885 }; 29886 this.prefix = options.prefix || 'i18next:'; 29887 this.logger = concreteLogger || consoleLogger; 29888 this.options = options; 29889 this.debug = options.debug; 29890 } 29891 }, 29892 { 29893 key: 'setDebug', 29894 value: function setDebug(bool) { 29895 this.debug = bool; 29896 } 29897 }, 29898 { 29899 key: 'log', 29900 value: function log() { 29901 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 29902 args[_key] = arguments[_key]; 29903 } 29904 return this.forward(args, 'log', '', true); 29905 } 29906 }, 29907 { 29908 key: 'warn', 29909 value: function warn() { 29910 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 29911 args[_key2] = arguments[_key2]; 29912 } 29913 return this.forward(args, 'warn', '', true); 29914 } 29915 }, 29916 { 29917 key: 'error', 29918 value: function error() { 29919 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 29920 args[_key3] = arguments[_key3]; 29921 } 29922 return this.forward(args, 'error', ''); 29923 } 29924 }, 29925 { 29926 key: 'deprecate', 29927 value: function deprecate() { 29928 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
vendor: 5,915 bytes, lines 29929-30093
29929 args[_key4] = arguments[_key4]; 29930 } 29931 return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true); 29932 } 29933 }, 29934 { 29935 key: 'forward', 29936 value: function forward(args, lvl, prefix, debugOnly) { 29937 if (debugOnly && !this.debug) return null; 29938 if (typeof args[0] === 'string') args[0] = ''.concat(prefix).concat(this.prefix, ' ').concat(args[0]); 29939 return this.logger[lvl](args); 29940 } 29941 }, 29942 { 29943 key: 'create', 29944 value: function create(moduleName) { 29945 return new Logger(this.logger, _objectSpread({ 29946 }, { 29947 prefix: ''.concat(this.prefix, ':').concat(moduleName, ':') 29948 }, this.options)); 29949 } 29950 } 29951 ]); 29952 return Logger; 29953 }(); 29954 var baseLogger = new Logger(); 29955 var EventEmitter = /*#__PURE__*/ 29956 function () { 29957 function EventEmitter() { 29958 _classCallCheck(this, EventEmitter); 29959 this.observers = { 29960 }; 29961 } 29962 _createClass(EventEmitter, [ 29963 { 29964 key: 'on', 29965 value: function on(events, listener) { 29966 var _this = this; 29967 events.split(' ').forEach(function (event) { 29968 _this.observers[event] = _this.observers[event] || [ 29969 ]; 29970 _this.observers[event].push(listener); 29971 }); 29972 return this; 29973 } 29974 }, 29975 { 29976 key: 'off', 29977 value: function off(event, listener) { 29978 if (!this.observers[event]) return; 29979 if (!listener) { 29980 delete this.observers[event]; 29981 return; 29982 } 29983 this.observers[event] = this.observers[event].filter(function (l) { 29984 return l !== listener; 29985 }); 29986 } 29987 }, 29988 { 29989 key: 'emit', 29990 value: function emit(event) { 29991 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 29992 args[_key - 1] = arguments[_key]; 29993 } 29994 if (this.observers[event]) { 29995 var cloned = [ 29996 ].concat(this.observers[event]); 29997 cloned.forEach(function (observer) { 29998 observer.apply(void 0, args); 29999 }); 30000 } 30001 if (this.observers['*']) { 30002 var _cloned = [ 30003 ].concat(this.observers['*']); 30004 _cloned.forEach(function (observer) { 30005 observer.apply(observer, [ 30006 event 30007 ].concat(args)); 30008 }); 30009 } 30010 } 30011 } 30012 ]); 30013 return EventEmitter; 30014 }(); // http://lea.verou.me/2016/12/resolve-promises-externally-with-this-one-weird-trick/ 30015 function defer() { 30016 var res; 30017 var rej; 30018 var promise = new Promise(function (resolve, reject) { 30019 res = resolve; 30020 rej = reject; 30021 }); 30022 promise.resolve = res; 30023 promise.reject = rej; 30024 return promise; 30025 } 30026 function makeString(object) { 30027 if (object == null) return ''; 30028 /* eslint prefer-template: 0 */ 30029 return '' + object; 30030 } 30031 function copy(a, s, t) { 30032 a.forEach(function (m) { 30033 if (s[m]) t[m] = s[m]; 30034 }); 30035 } 30036 function getLastOfPath(object, path, Empty) { 30037 function cleanKey(key) { 30038 return key && key.indexOf('###') > - 1 ? key.replace(/###/g, '.') : key; 30039 } 30040 function canNotTraverseDeeper() { 30041 return !object || typeof object === 'string'; 30042 } 30043 var stack = typeof path !== 'string' ? [ 30044 ].concat(path) : path.split('.'); 30045 while (stack.length > 1) { 30046 if (canNotTraverseDeeper()) return { 30047 }; 30048 var key = cleanKey(stack.shift()); 30049 if (!object[key] && Empty) object[key] = new Empty(); 30050 object = object[key]; 30051 } 30052 if (canNotTraverseDeeper()) return { 30053 }; 30054 return { 30055 obj: object, 30056 k: cleanKey(stack.shift()) 30057 }; 30058 } 30059 function setPath(object, path, newValue) { 30060 var _getLastOfPath = getLastOfPath(object, path, Object), 30061 obj = _getLastOfPath.obj, 30062 k = _getLastOfPath.k; 30063 obj[k] = newValue; 30064 } 30065 function pushPath(object, path, newValue, concat) { 30066 var _getLastOfPath2 = getLastOfPath(object, path, Object), 30067 obj = _getLastOfPath2.obj, 30068 k = _getLastOfPath2.k; 30069 obj[k] = obj[k] || [ 30070 ]; 30071 if (concat) obj[k] = obj[k].concat(newValue); 30072 if (!concat) obj[k].push(newValue); 30073 } 30074 function getPath(object, path) { 30075 var _getLastOfPath3 = getLastOfPath(object, path), 30076 obj = _getLastOfPath3.obj, 30077 k = _getLastOfPath3.k; 30078 if (!obj) return undefined; 30079 return obj[k]; 30080 } 30081 function getPathWithDefaults(data, defaultData, key) { 30082 var value = getPath(data, key); 30083 if (value !== undefined) { 30084 return value; 30085 } // Fallback to default values 30086 30087 return getPath(defaultData, key); 30088 } 30089 function deepExtend(target, source, overwrite) { 30090 /* eslint no-restricted-syntax: 0 */ 30091 for (var prop in source) { 30092 if (prop in target) { 30093 // If we reached a leaf string in target or source then replace with source or skip depen
vendor: 14,933 bytes, lines 30093-30433
30093ding on the 'overwrite' switch 30094 if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) { 30095 if (overwrite) target[prop] = source[prop]; 30096 } else { 30097 deepExtend(target[prop], source[prop], overwrite); 30098 } 30099 } else { 30100 target[prop] = source[prop]; 30101 } 30102 } 30103 return target; 30104 } 30105 function regexEscape(str) { 30106 /* eslint no-useless-escape: 0 */ 30107 return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); 30108 } /* eslint-disable */ 30109 30110 var _entityMap = { 30111 '&': '&', 30112 '<': '<', 30113 '>': '>', 30114 '"': '"', 30115 '\'': ''', 30116 '/': '/' 30117 }; 30118 /* eslint-enable */ 30119 function escape(data) { 30120 if (typeof data === 'string') { 30121 return data.replace(/[&<>"'\/]/g, function (s) { 30122 return _entityMap[s]; 30123 }); 30124 } 30125 return data; 30126 } 30127 var ResourceStore = /*#__PURE__*/ 30128 function (_EventEmitter) { 30129 _inherits(ResourceStore, _EventEmitter); 30130 function ResourceStore(data) { 30131 var _this; 30132 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 30133 ns: [ 30134 'translation' 30135 ], 30136 defaultNS: 'translation' 30137 }; 30138 _classCallCheck(this, ResourceStore); 30139 _this = _possibleConstructorReturn(this, _getPrototypeOf(ResourceStore).call(this)); 30140 EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor) 30141 _this.data = data || { 30142 }; 30143 _this.options = options; 30144 if (_this.options.keySeparator === undefined) { 30145 _this.options.keySeparator = '.'; 30146 } 30147 return _this; 30148 } 30149 _createClass(ResourceStore, [ 30150 { 30151 key: 'addNamespaces', 30152 value: function addNamespaces(ns) { 30153 if (this.options.ns.indexOf(ns) < 0) { 30154 this.options.ns.push(ns); 30155 } 30156 } 30157 }, 30158 { 30159 key: 'removeNamespaces', 30160 value: function removeNamespaces(ns) { 30161 var index = this.options.ns.indexOf(ns); 30162 if (index > - 1) { 30163 this.options.ns.splice(index, 1); 30164 } 30165 } 30166 }, 30167 { 30168 key: 'getResource', 30169 value: function getResource(lng, ns, key) { 30170 var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { 30171 }; 30172 var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator; 30173 var path = [ 30174 lng, 30175 ns 30176 ]; 30177 if (key && typeof key !== 'string') path = path.concat(key); 30178 if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key); 30179 if (lng.indexOf('.') > - 1) { 30180 path = lng.split('.'); 30181 } 30182 return getPath(this.data, path); 30183 } 30184 }, 30185 { 30186 key: 'addResource', 30187 value: function addResource(lng, ns, key, value) { 30188 var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : { 30189 silent: false 30190 }; 30191 var keySeparator = this.options.keySeparator; 30192 if (keySeparator === undefined) keySeparator = '.'; 30193 var path = [ 30194 lng, 30195 ns 30196 ]; 30197 if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key); 30198 if (lng.indexOf('.') > - 1) { 30199 path = lng.split('.'); 30200 value = ns; 30201 ns = path[1]; 30202 } 30203 this.addNamespaces(ns); 30204 setPath(this.data, path, value); 30205 if (!options.silent) this.emit('added', lng, ns, key, value); 30206 } 30207 }, 30208 { 30209 key: 'addResources', 30210 value: function addResources(lng, ns, resources) { 30211 var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { 30212 silent: false 30213 }; 30214 /* eslint no-restricted-syntax: 0 */ 30215 for (var m in resources) { 30216 if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], { 30217 silent: true 30218 }); 30219 } 30220 if (!options.silent) this.emit('added', lng, ns, resources); 30221 } 30222 }, 30223 { 30224 key: 'addResourceBundle', 30225 value: function addResourceBundle(lng, ns, resources, deep, overwrite) { 30226 var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : { 30227 silent: false 30228 }; 30229 var path = [ 30230 lng, 30231 ns 30232 ]; 30233 if (lng.indexOf('.') > - 1) { 30234 path = lng.split('.'); 30235 deep = resources; 30236 resources = ns; 30237 ns = path[1]; 30238 } 30239 this.addNamespaces(ns); 30240 var pack = getPath(this.data, path) || { 30241 }; 30242 if (deep) { 30243 deepExtend(pack, resources, overwrite); 30244 } else { 30245 pack = _objectSpread({ 30246 }, pack, resources); 30247 } 30248 setPath(this.data, path, pack); 30249 if (!options.silent) this.emit('added', lng, ns, resources); 30250 } 30251 }, 30252 { 30253 key: 'removeResourceBundle', 30254 value: function removeResourceBundle(lng, ns) { 30255 if (this.hasResourceBundle(lng, ns)) { 30256 delete this.data[lng][ns]; 30257 } 30258 this.removeNamespaces(ns); 30259 this.emit('removed', lng, ns); 30260 } 30261 }, 30262 { 30263 key: 'hasResourceBundle', 30264 value: function hasResourceBundle(lng, ns) { 30265 return this.getResource(lng, ns) !== undefined; 30266 } 30267 }, 30268 { 30269 key: 'getResourceBundle', 30270 value: function getResourceBundle(lng, ns) { 30271 if (!ns) ns = this.options.defaultNS; // COMPATIBILITY: remove extend in v2.1.0 30272 if (this.options.compatibilityAPI === 'v1') return _objectSpread({ 30273 }, { 30274 }, this.getResource(lng, ns)); 30275 return this.getResource(lng, ns); 30276 } 30277 }, 30278 { 30279 key: 'getDataByLanguage', 30280 value: function getDataByLanguage(lng) { 30281 return this.data[lng]; 30282 } 30283 }, 30284 { 30285 key: 'toJSON', 30286 value: function toJSON() { 30287 return this.data; 30288 } 30289 } 30290 ]); 30291 return ResourceStore; 30292 }(EventEmitter); 30293 var postProcessor = { 30294 processors: { 30295 }, 30296 addPostProcessor: function addPostProcessor(module) { 30297 this.processors[module.name] = module; 30298 }, 30299 handle: function handle(processors, value, key, options, translator) { 30300 var _this = this; 30301 processors.forEach(function (processor) { 30302 if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator); 30303 }); 30304 return value; 30305 } 30306 }; 30307 var checkedLoadedFor = { 30308 }; 30309 var Translator = /*#__PURE__*/ 30310 function (_EventEmitter) { 30311 _inherits(Translator, _EventEmitter); 30312 function Translator(services) { 30313 var _this; 30314 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 30315 }; 30316 _classCallCheck(this, Translator); 30317 _this = _possibleConstructorReturn(this, _getPrototypeOf(Translator).call(this)); 30318 EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor) 30319 copy(['resourceStore', 30320 'languageUtils', 30321 'pluralResolver', 30322 'interpolator', 30323 'backendConnector', 30324 'i18nFormat', 30325 'utils'], services, _assertThisInitialized(_this)); 30326 _this.options = options; 30327 if (_this.options.keySeparator === undefined) { 30328 _this.options.keySeparator = '.'; 30329 } 30330 _this.logger = baseLogger.create('translator'); 30331 return _this; 30332 } 30333 _createClass(Translator, [ 30334 { 30335 key: 'changeLanguage', 30336 value: function changeLanguage(lng) { 30337 if (lng) this.language = lng; 30338 } 30339 }, 30340 { 30341 key: 'exists', 30342 value: function exists(key) { 30343 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 30344 interpolation: { 30345 } 30346 }; 30347 var resolved = this.resolve(key, options); 30348 return resolved && resolved.res !== undefined; 30349 } 30350 }, 30351 { 30352 key: 'extractFromKey', 30353 value: function extractFromKey(key, options) { 30354 var nsSeparator = options.nsSeparator || this.options.nsSeparator; 30355 if (nsSeparator === undefined) nsSeparator = ':'; 30356 var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator; 30357 var namespaces = options.ns || this.options.defaultNS; 30358 if (nsSeparator && key.indexOf(nsSeparator) > - 1) { 30359 var parts = key.split(nsSeparator); 30360 if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > - 1) namespaces = parts.shift(); 30361 key = parts.join(keySeparator); 30362 } 30363 if (typeof namespaces === 'string') namespaces = [ 30364 namespaces 30365 ]; 30366 return { 30367 key: key, 30368 namespaces: namespaces 30369 }; 30370 } 30371 }, 30372 { 30373 key: 'translate', 30374 value: function translate(keys, options) { 30375 var _this2 = this; 30376 if (_typeof(options) !== 'object' && this.options.overloadTranslationOptionHandler) { 30377 /* eslint prefer-rest-params: 0 */ 30378 options = this.options.overloadTranslationOptionHandler(arguments); 30379 } 30380 if (!options) options = { 30381 }; // non valid keys handling 30382 if (keys === undefined || keys === null /* || keys === ''*/ 30383 ) return ''; 30384 if (!Array.isArray(keys)) keys = [ 30385 String(keys) 30386 ]; // separators 30387 var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator; // get namespace(s) 30388 var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options), 30389 key = _this$extractFromKey.key, 30390 namespaces = _this$extractFromKey.namespaces; 30391 var namespace = namespaces[namespaces.length - 1]; // return key on CIMode 30392 var lng = options.lng || this.language; 30393 var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode; 30394 if (lng && lng.toLowerCase() === 'cimode') { 30395 if (appendNamespaceToCIMode) { 30396 var nsSeparator = options.nsSeparator || this.options.nsSeparator; 30397 return namespace + nsSeparator + key; 30398 } 30399 return key; 30400 } // resolve from store 30401 30402 var resolved = this.resolve(keys, options); 30403 var res = resolved && resolved.res; 30404 var resUsedKey = resolved && resolved.usedKey || key; 30405 var resExactUsedKey = resolved && resolved.exactUsedKey || key; 30406 var resType = Object.prototype.toString.apply(res); 30407 var noObject = [ 30408 '[object Number]', 30409 '[object Function]', 30410 '[object RegExp]' 30411 ]; 30412 var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays; // object 30413 var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject; 30414 var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number'; 30415 if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) { 30416 if (!options.returnObjects && !this.options.returnObjects) { 30417 this.logger.warn('accessing an object - but returnObjects options is not enabled!'); 30418 return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, options) : 'key \''.concat(key, ' (').concat(this.language, ')\' returned an object instead of string.'); 30419 } // if we got a separator we loop over children - else we just return object as is 30420 // as having it set to false means no hierarchy so no lookup for nested values 30421 30422 if (keySeparator) { 30423 var resTypeIsArray = resType === '[object Array]'; 30424 var copy$$1 = resTypeIsArray ? [ 30425 ] : { 30426 }; // apply child translation on a copy 30427 /* eslint no-restricted-syntax: 0 */ 30428 var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey; 30429 for (var m in res) { 30430 if (Object.prototype.hasOwnProperty.call(res, m)) { 30431 var deepKey = ''.concat(newKeyToUse).concat(keySeparator).concat(m); 30432 copy$$1[m] = this.translate(deepKey, _objectSpread({ 30433 }, options, {
30434 joinArrays: false, 30435 ns: namespaces 30436 })); 30437 if (copy$$1[m] === deepKey) copy$$1[m] = res[m]; // if nothing found use orginal value as fallback 30438 } 30439 } 30440 res = copy$$1; 30441 } 30442 } else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') { 30443 // array special treatment 30444 res = res.join(joinArrays); 30445 if (res) res = this.extendTranslation(res, keys, options); 30446 } else { 30447 // string, empty or null 30448 var usedDefault = false; 30449 var usedKey = false; // fallback value 30450 if (!this.isValidLookup(res) && options.defaultValue !== undefined) { 30451 usedDefault = true; 30452 if (options.count !== undefined) { 30453 var suffix = this.pluralResolver.getSuffix(lng, options.count); 30454 res = options['defaultValue'.concat(suffix)]; 30455 } 30456 if (!res) res = options.defaultValue; 30457 } 30458 if (!this.isValidLookup(res)) { 30459 usedKey = true; 30460 res = key; 30461 } // save missing 30462 30463 var updateMissing = options.defaultValue && options.defaultValue !== res && this.options.updateMissing; 30464 if (usedKey || usedDefault || updateMissing) { 30465 this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? options.defaultValue : res); 30466 var lngs = [ 30467 ]; 30468 var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language); 30469 if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) { 30470 for (var i = 0; i < fallbackLngs.length; i++) { 30471 lngs.push(fallbackLngs[i]); 30472 } 30473 } else if (this.options.saveMissingTo === 'all') { 30474 lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language); 30475 } else { 30476 lngs.push(options.lng || this.language); 30477 } 30478 var send = function send(l, k) { 30479 if (_this2.options.missingKeyHandler) { 30480 _this2.options.missingKeyHandler(l, namespace, k, updateMissing ? options.defaultValue : res, updateMissing, options); 30481 } else if (_this2.backendConnector && _this2.backendConnector.saveMissing) { 30482 _this2.backendConnector.saveMissing(l, namespace, k, updateMissing ? options.defaultValue : res, updateMissing, options); 30483 } 30484 _this2.emit('missingKey', l, namespace, k, res); 30485 }; 30486 if (this.options.saveMissing) { 30487 var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string'; 30488 if (this.options.saveMissingPlurals && needsPluralHandling) { 30489 lngs.forEach(function (l) { 30490 var plurals = _this2.pluralResolver.getPluralFormsOfKey(l, key); 30491 plurals.forEach(function (p) { 30492 return send([l], p); 30493 }); 30494 }); 30495 } else { 30496 send(lngs, key); 30497 } 30498 } 30499 } // extend 30500 30501 res = this.extendTranslation(res, keys, options, resolved); // append namespace if still key 30502 if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = ''.concat(namespace, ':').concat(key); // parseMissingKeyHandler 30503 if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res); 30504 } // return 30505 30506 return res; 30507 } 30508 }, 30509 { 30510 key: 'extendTranslation', 30511 value: function extendTranslation(res, key, options, resolved) { 30512 var _this3 = this; 30513 if (this.i18nFormat && this.i18nFormat.parse) { 30514 res = this.i18nFormat.parse(res, options, resolved.usedLng, resolved.usedNS, resolved.usedKey, { 30515 resolved: resolved 30516 }); 30517 } else if (!options.skipInterpolation) { 30518 // i18next.parsing 30519 if (options.interpolation) this.interpolator.init(_objectSpread({ 30520 }, options, { 30521 interpolation: _objectSpread({ 30522 }, this.options.interpolation, options.interpolation) 30523 })); // interpolate 30524 var data = options.replace && typeof options.replace !== 'string' ? options.replace : options; 30525 if (this.options.interpolation.defaultVariables) data = _objectSpread({ 30526 }, this.options.interpolation.defaultVariables, data); 30527 res = this.interpolator.interpolate(res, data, options.lng || this.language, options); // nesting 30528 if (options.nest !== false) res = this.interpolator.nest(res, function () { 30529 return _this3.translate.apply(_this3, arguments); 30530 }, options); 30531 if (options.interpolation) this.interpolator.reset(); 30532 } // post process 30533 30534 var postProcess = options.postProcess || this.options.postProcess; 30535 var postProcessorNames = typeof postProcess === 'string' ? [ 30536 postProcess 30537 ] : postProcess; 30538 if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) { 30539 res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread({ 30540 i18nResolved: resolved 30541 }, options) : options, this); 30542 } 30543 return res; 30544 } 30545 }, 30546 { 30547 key: 'resolve', 30548 value: function resolve(keys) { 30549 var _this4 = this; 30550 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 30551 }; 30552 var found; 30553 var usedKey; // plain key 30554 var exactUsedKey; // key with context / plural 30555 var usedLng; 30556 var usedNS; 30557 if (typeof keys === 'string') keys = [ 30558 keys 30559 ]; // forEach possible key 30560 keys.forEach(function (k) { 30561 if (_this4.isValidLookup(found)) return; 30562 var extracted = _this4.extractFromKey(k, options); 30563 var key = extracted.key; 30564 usedKey = key; 30565 var namespaces = extracted.namespaces; 30566 if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS); 30567 var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string'; 30568 var needsContextHandling = options.context !== undefined && typeof options.context === 'string' && options.context !== ''; 30569 var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
vendor: 7,512 bytes, lines 30570-30716
30570 namespaces.forEach(function (ns) { 30571 if (_this4.isValidLookup(found)) return; 30572 usedNS = ns; 30573 if (!checkedLoadedFor[''.concat(codes[0], '-').concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) { 30574 checkedLoadedFor[''.concat(codes[0], '-').concat(ns)] = true; 30575 _this4.logger.warn('key "'.concat(usedKey, '" for namespace "').concat(usedNS, '" for languages "').concat(codes.join(', '), '" won\'t get resolved as namespace was not yet loaded'), 'This means something IS WRONG in your application setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!'); 30576 } 30577 codes.forEach(function (code) { 30578 if (_this4.isValidLookup(found)) return; 30579 usedLng = code; 30580 var finalKey = key; 30581 var finalKeys = [ 30582 finalKey 30583 ]; 30584 if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) { 30585 _this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options); 30586 } else { 30587 var pluralSuffix; 30588 if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count); // fallback for plural if context not found 30589 if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix); // get key for context if needed 30590 if (needsContextHandling) finalKeys.push(finalKey += ''.concat(_this4.options.contextSeparator).concat(options.context)); // get key for plural if needed 30591 if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix); 30592 } // iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only 30593 30594 var possibleKey; 30595 /* eslint no-cond-assign: 0 */ 30596 while (possibleKey = finalKeys.pop()) { 30597 if (!_this4.isValidLookup(found)) { 30598 exactUsedKey = possibleKey; 30599 found = _this4.getResource(code, ns, possibleKey, options); 30600 } 30601 } 30602 }); 30603 }); 30604 }); 30605 return { 30606 res: found, 30607 usedKey: usedKey, 30608 exactUsedKey: exactUsedKey, 30609 usedLng: usedLng, 30610 usedNS: usedNS 30611 }; 30612 } 30613 }, 30614 { 30615 key: 'isValidLookup', 30616 value: function isValidLookup(res) { 30617 return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === ''); 30618 } 30619 }, 30620 { 30621 key: 'getResource', 30622 value: function getResource(code, ns, key) { 30623 var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { 30624 }; 30625 if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options); 30626 return this.resourceStore.getResource(code, ns, key, options); 30627 } 30628 } 30629 ]); 30630 return Translator; 30631 }(EventEmitter); 30632 function capitalize(string) { 30633 return string.charAt(0).toUpperCase() + string.slice(1); 30634 } 30635 var LanguageUtil = /*#__PURE__*/ 30636 function () { 30637 function LanguageUtil(options) { 30638 _classCallCheck(this, LanguageUtil); 30639 this.options = options; 30640 this.whitelist = this.options.whitelist || false; 30641 this.logger = baseLogger.create('languageUtils'); 30642 } 30643 _createClass(LanguageUtil, [ 30644 { 30645 key: 'getScriptPartFromCode', 30646 value: function getScriptPartFromCode(code) { 30647 if (!code || code.indexOf('-') < 0) return null; 30648 var p = code.split('-'); 30649 if (p.length === 2) return null; 30650 p.pop(); 30651 return this.formatLanguageCode(p.join('-')); 30652 } 30653 }, 30654 { 30655 key: 'getLanguagePartFromCode', 30656 value: function getLanguagePartFromCode(code) { 30657 if (!code || code.indexOf('-') < 0) return code; 30658 var p = code.split('-'); 30659 return this.formatLanguageCode(p[0]); 30660 } 30661 }, 30662 { 30663 key: 'formatLanguageCode', 30664 value: function formatLanguageCode(code) { 30665 // http://www.iana.org/assignments/language-tags/language-tags.xhtml 30666 if (typeof code === 'string' && code.indexOf('-') > - 1) { 30667 var specialCases = [ 30668 'hans', 30669 'hant', 30670 'latn', 30671 'cyrl', 30672 'cans', 30673 'mong', 30674 'arab' 30675 ]; 30676 var p = code.split('-'); 30677 if (this.options.lowerCaseLng) { 30678 p = p.map(function (part) { 30679 return part.toLowerCase(); 30680 }); 30681 } else if (p.length === 2) { 30682 p[0] = p[0].toLowerCase(); 30683 p[1] = p[1].toUpperCase(); 30684 if (specialCases.indexOf(p[1].toLowerCase()) > - 1) p[1] = capitalize(p[1].toLowerCase()); 30685 } else if (p.length === 3) { 30686 p[0] = p[0].toLowerCase(); // if lenght 2 guess it's a country 30687 if (p[1].length === 2) p[1] = p[1].toUpperCase(); 30688 if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase(); 30689 if (specialCases.indexOf(p[1].toLowerCase()) > - 1) p[1] = capitalize(p[1].toLowerCase()); 30690 if (specialCases.indexOf(p[2].toLowerCase()) > - 1) p[2] = capitalize(p[2].toLowerCase()); 30691 } 30692 return p.join('-'); 30693 } 30694 return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code; 30695 } 30696 }, 30697 { 30698 key: 'isWhitelisted', 30699 value: function isWhitelisted(code) { 30700 if (this.options.load === 'languageOnly' || this.options.nonExplicitWhitelist) { 30701 code = this.getLanguagePartFromCode(code); 30702 } 30703 return !this.whitelist || !this.whitelist.length || this.whitelist.indexOf(code) > - 1; 30704 } 30705 }, 30706 { 30707 key: 'getFallbackCodes', 30708 value: function getFallbackCodes(fallbacks, code) { 30709 if (!fallbacks) return []; 30710 if (typeof fallbacks === 'string') fallbacks = [ 30711 fallbacks 30712 ]; 30713 if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks; 30714 if (!code) return fallbacks['default'] || [ 30715 ]; // asume we have an object defining fallbacks 30716 var found = fallbacks[code];
vendor: 4,089 bytes, lines 30717-30872
30717 if (!found) found = fallbacks[this.getScriptPartFromCode(code)]; 30718 if (!found) found = fallbacks[this.formatLanguageCode(code)]; 30719 if (!found) found = fallbacks['default']; 30720 return found || [ 30721 ]; 30722 } 30723 }, 30724 { 30725 key: 'toResolveHierarchy', 30726 value: function toResolveHierarchy(code, fallbackCode) { 30727 var _this = this; 30728 var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [ 30729 ], code); 30730 var codes = [ 30731 ]; 30732 var addCode = function addCode(c) { 30733 if (!c) return; 30734 if (_this.isWhitelisted(c)) { 30735 codes.push(c); 30736 } else { 30737 _this.logger.warn('rejecting non-whitelisted language code: '.concat(c)); 30738 } 30739 }; 30740 if (typeof code === 'string' && code.indexOf('-') > - 1) { 30741 if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code)); 30742 if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code)); 30743 if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code)); 30744 } else if (typeof code === 'string') { 30745 addCode(this.formatLanguageCode(code)); 30746 } 30747 fallbackCodes.forEach(function (fc) { 30748 if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc)); 30749 }); 30750 return codes; 30751 } 30752 } 30753 ]); 30754 return LanguageUtil; 30755 }(); 30756 /* eslint-disable */ 30757 var sets = [ 30758 { 30759 lngs: [ 30760 'ach', 30761 'ak', 30762 'am', 30763 'arn', 30764 'br', 30765 'fil', 30766 'gun', 30767 'ln', 30768 'mfe', 30769 'mg', 30770 'mi', 30771 'oc', 30772 'pt', 30773 'pt-BR', 30774 'tg', 30775 'ti', 30776 'tr', 30777 'uz', 30778 'wa' 30779 ], 30780 nr: [ 30781 1, 30782 2 30783 ], 30784 fc: 1 30785 }, 30786 { 30787 lngs: [ 30788 'af', 30789 'an', 30790 'ast', 30791 'az', 30792 'bg', 30793 'bn', 30794 'ca', 30795 'da', 30796 'de', 30797 'dev', 30798 'el', 30799 'en', 30800 'eo', 30801 'es', 30802 'et', 30803 'eu', 30804 'fi', 30805 'fo', 30806 'fur', 30807 'fy', 30808 'gl', 30809 'gu', 30810 'ha', 30811 'hi', 30812 'hu', 30813 'hy', 30814 'ia', 30815 'it', 30816 'kn', 30817 'ku', 30818 'lb', 30819 'mai', 30820 'ml', 30821 'mn', 30822 'mr', 30823 'nah', 30824 'nap', 30825 'nb', 30826 'ne', 30827 'nl', 30828 'nn', 30829 'no', 30830 'nso', 30831 'pa', 30832 'pap', 30833 'pms', 30834 'ps', 30835 'pt-PT', 30836 'rm', 30837 'sco', 30838 'se', 30839 'si', 30840 'so', 30841 'son', 30842 'sq', 30843 'sv', 30844 'sw', 30845 'ta', 30846 'te', 30847 'tk', 30848 'ur', 30849 'yo' 30850 ], 30851 nr: [ 30852 1, 30853 2 30854 ], 30855 fc: 2 30856 }, 30857 { 30858 lngs: [ 30859 'ay', 30860 'bo', 30861 'cgg', 30862 'fa', 30863 'id', 30864 'ja', 30865 'jbo', 30866 'ka', 30867 'kk', 30868 'km', 30869 'ko', 30870 'ky', 30871 'lo', 30872 'ms',
30873 'sah', 30874 'su', 30875 'th', 30876 'tt', 30877 'ug', 30878 'vi', 30879 'wo', 30880 'zh' 30881 ], 30882 nr: [ 30883 1 30884 ], 30885 fc: 3 30886 }, 30887 { 30888 lngs: [ 30889 'be', 30890 'bs', 30891 'cnr', 30892 'dz', 30893 'hr', 30894 'ru', 30895 'sr', 30896 'uk' 30897 ], 30898 nr: [ 30899 1, 30900 2, 30901 5 30902 ], 30903 fc: 4 30904 }, 30905 { 30906 lngs: [ 30907 'ar' 30908 ], 30909 nr: [ 30910 0, 30911 1, 30912 2, 30913 3, 30914 11, 30915 100 30916 ], 30917 fc: 5 30918 }, 30919 { 30920 lngs: [ 30921 'cs', 30922 'sk' 30923 ], 30924 nr: [ 30925 1, 30926 2, 30927 5 30928 ], 30929 fc: 6 30930 }, 30931 { 30932 lngs: [ 30933 'csb', 30934 'pl' 30935 ], 30936 nr: [ 30937 1, 30938 2, 30939 5 30940 ], 30941 fc: 7 30942 }, 30943 { 30944 lngs: [ 30945 'cy' 30946 ], 30947 nr: [ 30948 1, 30949 2, 30950 3, 30951 8 30952 ], 30953 fc: 8 30954 }, 30955 { 30956 lngs: [ 30957 'fr' 30958 ], 30959 nr: [ 30960 1, 30961 2 30962 ], 30963 fc: 9 30964 }, 30965 { 30966 lngs: [ 30967 'ga' 30968 ], 30969 nr: [ 30970 1, 30971 2, 30972 3, 30973 7, 30974 11 30975 ], 30976 fc: 10 30977 }, 30978 { 30979 lngs: [ 30980 'gd' 30981 ], 30982 nr: [ 30983 1, 30984 2, 30985 3, 30986 20 30987 ], 30988 fc: 11 30989 }, 30990 { 30991 lngs: [ 30992 'is' 30993 ], 30994 nr: [ 30995 1, 30996 2 30997 ], 30998 fc: 12 30999 }, 31000 { 31001 lngs: [ 31002 'jv' 31003 ], 31004 nr: [ 31005 0, 31006 1 31007 ], 31008 fc: 13 31009 }, 31010 { 31011 lngs: [ 31012 'kw' 31013 ], 31014 nr: [ 31015 1, 31016 2, 31017 3, 31018 4 31019 ], 31020 fc: 14 31021 }, 31022 { 31023 lngs: [ 31024 'lt' 31025 ], 31026 nr: [ 31027 1, 31028 2, 31029 10 31030 ], 31031 fc: 15 31032 }, 31033 { 31034 lngs: [ 31035 'lv' 31036 ], 31037 nr: [ 31038 1, 31039 2, 31040 0 31041 ], 31042 fc: 16 31043 }, 31044 { 31045 lngs: [ 31046 'mk' 31047 ], 31048 nr: [ 31049 1, 31050 2 31051 ], 31052 fc: 17 31053 }, 31054 { 31055 lngs: [ 31056 'mnk' 31057 ], 31058 nr: [ 31059 0, 31060 1, 31061 2 31062 ], 31063 fc: 18 31064 }, 31065 { 31066 lngs: [ 31067 'mt' 31068 ], 31069 nr: [ 31070 1, 31071 2, 31072 11, 31073 20 31074 ], 31075 fc: 19 31076 }, 31077 { 31078 lngs: [ 31079 'or' 31080 ], 31081 nr: [ 31082 2, 31083 1 31084 ], 31085 fc: 2 31086 }, 31087 { 31088 lngs: [ 31089 'ro' 31090 ], 31091 nr: [ 31092 1, 31093 2, 31094 20 31095 ], 31096 fc: 20 31097 }, 31098 { 31099 lngs: [ 31100 'sl' 31101 ], 31102 nr: [ 31103 5, 31104 1, 31105 2, 31106 3 31107 ], 31108 fc: 21 31109 }, 31110 { 31111 lngs: [ 31112 'he' 31113 ], 31114 nr: [ 31115 1, 31116 2, 31117 20, 31118 21 31119 ], 31120 fc: 22 31121 } 31122 ];
vendor: 8,125 bytes, lines 31123-31317
31123 var _rulesPluralsTypes = { 31124 1: function _(n) { 31125 return Number(n > 1); 31126 }, 31127 2: function _(n) { 31128 return Number(n != 1); 31129 }, 31130 3: function _(n) { 31131 return 0; 31132 }, 31133 4: function _(n) { 31134 return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); 31135 }, 31136 5: function _(n) { 31137 return Number(n === 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); 31138 }, 31139 6: function _(n) { 31140 return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2); 31141 }, 31142 7: function _(n) { 31143 return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); 31144 }, 31145 8: function _(n) { 31146 return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3); 31147 }, 31148 9: function _(n) { 31149 return Number(n >= 2); 31150 }, 31151 10: function _(n) { 31152 return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4); 31153 }, 31154 11: function _(n) { 31155 return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3); 31156 }, 31157 12: function _(n) { 31158 return Number(n % 10 != 1 || n % 100 == 11); 31159 }, 31160 13: function _(n) { 31161 return Number(n !== 0); 31162 }, 31163 14: function _(n) { 31164 return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3); 31165 }, 31166 15: function _(n) { 31167 return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); 31168 }, 31169 16: function _(n) { 31170 return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2); 31171 }, 31172 17: function _(n) { 31173 return Number(n == 1 || n % 10 == 1 ? 0 : 1); 31174 }, 31175 18: function _(n) { 31176 return Number(n == 0 ? 0 : n == 1 ? 1 : 2); 31177 }, 31178 19: function _(n) { 31179 return Number(n == 1 ? 0 : n === 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3); 31180 }, 31181 20: function _(n) { 31182 return Number(n == 1 ? 0 : n === 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2); 31183 }, 31184 21: function _(n) { 31185 return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0); 31186 }, 31187 22: function _(n) { 31188 return Number(n === 1 ? 0 : n === 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3); 31189 } 31190 }; 31191 /* eslint-enable */ 31192 function createRules() { 31193 var rules = { 31194 }; 31195 sets.forEach(function (set) { 31196 set.lngs.forEach(function (l) { 31197 rules[l] = { 31198 numbers: set.nr, 31199 plurals: _rulesPluralsTypes[set.fc] 31200 }; 31201 }); 31202 }); 31203 return rules; 31204 } 31205 var PluralResolver = /*#__PURE__*/ 31206 function () { 31207 function PluralResolver(languageUtils) { 31208 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 31209 }; 31210 _classCallCheck(this, PluralResolver); 31211 this.languageUtils = languageUtils; 31212 this.options = options; 31213 this.logger = baseLogger.create('pluralResolver'); 31214 this.rules = createRules(); 31215 } 31216 _createClass(PluralResolver, [ 31217 { 31218 key: 'addRule', 31219 value: function addRule(lng, obj) { 31220 this.rules[lng] = obj; 31221 } 31222 }, 31223 { 31224 key: 'getRule', 31225 value: function getRule(code) { 31226 return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)]; 31227 } 31228 }, 31229 { 31230 key: 'needsPlural', 31231 value: function needsPlural(code) { 31232 var rule = this.getRule(code); 31233 return rule && rule.numbers.length > 1; 31234 } 31235 }, 31236 { 31237 key: 'getPluralFormsOfKey', 31238 value: function getPluralFormsOfKey(code, key) { 31239 var _this = this; 31240 var ret = [ 31241 ]; 31242 var rule = this.getRule(code); 31243 if (!rule) return ret; 31244 rule.numbers.forEach(function (n) { 31245 var suffix = _this.getSuffix(code, n); 31246 ret.push(''.concat(key).concat(suffix)); 31247 }); 31248 return ret; 31249 } 31250 }, 31251 { 31252 key: 'getSuffix', 31253 value: function getSuffix(code, count) { 31254 var _this2 = this; 31255 var rule = this.getRule(code); 31256 if (rule) { 31257 // if (rule.numbers.length === 1) return ''; // only singular 31258 var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count)); 31259 var suffix = rule.numbers[idx]; // special treatment for lngs only having singular and plural 31260 if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) { 31261 if (suffix === 2) { 31262 suffix = 'plural'; 31263 } else if (suffix === 1) { 31264 suffix = ''; 31265 } 31266 } 31267 var returnSuffix = function returnSuffix() { 31268 return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString(); 31269 }; // COMPATIBILITY JSON 31270 // v1 31271 if (this.options.compatibilityJSON === 'v1') { 31272 if (suffix === 1) return ''; 31273 if (typeof suffix === 'number') return '_plural_'.concat(suffix.toString()); 31274 return returnSuffix(); 31275 } else if ( /* v2 */ 31276 this.options.compatibilityJSON === 'v2') { 31277 return returnSuffix(); 31278 } else if ( /* v3 - gettext index */ 31279 this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) { 31280 return returnSuffix(); 31281 } 31282 return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString(); 31283 } 31284 this.logger.warn('no plural rule found for: '.concat(code)); 31285 return ''; 31286 } 31287 } 31288 ]); 31289 return PluralResolver; 31290 }(); 31291 var Interpolator = /*#__PURE__*/ 31292 function () { 31293 function Interpolator() { 31294 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 31295 }; 31296 _classCallCheck(this, Interpolator); 31297 this.logger = baseLogger.create('interpolator'); 31298 this.options = options; 31299 this.format = options.interpolation && options.interpolation.format || function (value) { 31300 return value; 31301 }; 31302 this.init(options); 31303 } /* eslint no-param-reassign: 0 */ 31304 31305 _createClass(Interpolator, [ 31306 { 31307 key: 'init', 31308 value: function init() { 31309 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 31310 }; 31311 if (!options.interpolation) options.interpolation = { 31312 escapeValue: true 31313 }; 31314 var iOpts = options.interpolation; 31315 this.escape = iOpts.escape !== undefined ? iOpts.escape : escape; 31316 this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true; 31317 this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
31318 this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{'; 31319 this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}'; 31320 this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ','; 31321 this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-'; 31322 this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || ''; 31323 this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t('); 31324 this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')'); 31325 this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000; // the regexp 31326 this.resetRegExp(); 31327 } 31328 }, 31329 { 31330 key: 'reset', 31331 value: function reset() { 31332 if (this.options) this.init(this.options); 31333 } 31334 }, 31335 { 31336 key: 'resetRegExp', 31337 value: function resetRegExp() { 31338 // the regexp 31339 var regexpStr = ''.concat(this.prefix, '(.+?)').concat(this.suffix); 31340 this.regexp = new RegExp(regexpStr, 'g'); 31341 var regexpUnescapeStr = ''.concat(this.prefix).concat(this.unescapePrefix, '(.+?)').concat(this.unescapeSuffix).concat(this.suffix); 31342 this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g'); 31343 var nestingRegexpStr = ''.concat(this.nestingPrefix, '(.+?)').concat(this.nestingSuffix); 31344 this.nestingRegexp = new RegExp(nestingRegexpStr, 'g'); 31345 } 31346 }, 31347 { 31348 key: 'interpolate', 31349 value: function interpolate(str, data, lng, options) { 31350 var _this = this; 31351 var match; 31352 var value; 31353 var replaces; 31354 var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || { 31355 }; 31356 function regexSafe(val) { 31357 return val.replace(/\$/g, '$$$$'); 31358 } 31359 var handleFormat = function handleFormat(key) { 31360 if (key.indexOf(_this.formatSeparator) < 0) { 31361 return getPathWithDefaults(data, defaultData, key); 31362 } 31363 var p = key.split(_this.formatSeparator); 31364 var k = p.shift().trim(); 31365 var f = p.join(_this.formatSeparator).trim(); 31366 return _this.format(getPathWithDefaults(data, defaultData, k), f, lng); 31367 }; 31368 this.resetRegExp(); 31369 var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler; 31370 replaces = 0; // unescape if has unescapePrefix/Suffix 31371 /* eslint no-cond-assign: 0 */ 31372 while (match = this.regexpUnescape.exec(str)) { 31373 value = handleFormat(match[1].trim()); 31374 if (value === undefined) { 31375 if (typeof missingInterpolationHandler === 'function') { 31376 var temp = missingInterpolationHandler(str, match, options); 31377 value = typeof temp === 'string' ? temp : ''; 31378 } else { 31379 this.logger.warn('missed to pass in variable '.concat(match[1], ' for interpolating ').concat(str)); 31380 value = ''; 31381 } 31382 } else if (typeof value !== 'string' && !this.useRawValueToEscape) { 31383 value = makeString(value); 31384 } 31385 str = str.replace(match[0], regexSafe(value)); 31386 this.regexpUnescape.lastIndex = 0; 31387 replaces++; 31388 if (replaces >= this.maxReplaces) { 31389 break; 31390 } 31391 } 31392 replaces = 0; // regular escape on demand 31393 while (match = this.regexp.exec(str)) { 31394 value = handleFormat(match[1].trim()); 31395 if (value === undefined) { 31396 if (typeof missingInterpolationHandler === 'function') { 31397 var _temp = missingInterpolationHandler(str, match, options); 31398 value = typeof _temp === 'string' ? _temp : ''; 31399 } else { 31400 this.logger.warn('missed to pass in variable '.concat(match[1], ' for interpolating ').concat(str)); 31401 value = ''; 31402 } 31403 } else if (typeof value !== 'string' && !this.useRawValueToEscape) { 31404 value = makeString(value); 31405 } 31406 value = this.escapeValue ? regexSafe(this.escape(value)) : regexSafe(value); 31407 str = str.replace(match[0], value); 31408 this.regexp.lastIndex = 0; 31409 replaces++; 31410 if (replaces >= this.maxReplaces) { 31411 break; 31412 } 31413 } 31414 return str; 31415 } 31416 }, 31417 { 31418 key: 'nest', 31419 value: function nest(str, fc) { 31420 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { 31421 }; 31422 var match; 31423 var value; 31424 var clonedOptions = _objectSpread({ 31425 }, options); 31426 clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup 31427 delete clonedOptions.defaultValue; // assert we do not get a endless loop on interpolating defaultValue again and again 31428 // if value is something like "myKey": "lorem $(anotherKey, { "count": {{aValueInOptions}} })"
31429 function handleHasOptions(key, inheritedOptions) { 31430 if (key.indexOf(',') < 0) return key; 31431 var p = key.split(','); 31432 key = p.shift(); 31433 var optionsString = p.join(','); 31434 optionsString = this.interpolate(optionsString, clonedOptions); 31435 optionsString = optionsString.replace(/'/g, '"'); 31436 try { 31437 clonedOptions = JSON.parse(optionsString); 31438 if (inheritedOptions) clonedOptions = _objectSpread({ 31439 }, inheritedOptions, clonedOptions); 31440 } catch (e) { 31441 this.logger.error('failed parsing options string in nesting for key '.concat(key), e); 31442 } // assert we do not get a endless loop on interpolating defaultValue again and again 31443 31444 delete clonedOptions.defaultValue; 31445 return key; 31446 } // regular escape on demand 31447 31448 while (match = this.nestingRegexp.exec(str)) { 31449 value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions); // is only the nesting key (key1 = '$(key2)') return the value without stringify 31450 if (value && match[0] === str && typeof value !== 'string') return value; // no string to include or empty 31451 if (typeof value !== 'string') value = makeString(value); 31452 if (!value) { 31453 this.logger.warn('missed to resolve '.concat(match[1], ' for nesting ').concat(str)); 31454 value = ''; 31455 } // Nested keys should not be escaped by default #854 31456 // value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); 31457 31458 str = str.replace(match[0], value); 31459 this.regexp.lastIndex = 0; 31460 } 31461 return str; 31462 } 31463 } 31464 ]); 31465 return Interpolator; 31466 }(); 31467 function remove(arr, what) { 31468 var found = arr.indexOf(what); 31469 while (found !== - 1) { 31470 arr.splice(found, 1); 31471 found = arr.indexOf(what); 31472 } 31473 } 31474 var Connector = /*#__PURE__*/ 31475 function (_EventEmitter) { 31476 _inherits(Connector, _EventEmitter); 31477 function Connector(backend, store, services) { 31478 var _this; 31479 var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { 31480 }; 31481 _classCallCheck(this, Connector); 31482 _this = _possibleConstructorReturn(this, _getPrototypeOf(Connector).call(this)); 31483 EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor) 31484 _this.backend = backend; 31485 _this.store = store; 31486 _this.services = services; 31487 _this.languageUtils = services.languageUtils; 31488 _this.options = options; 31489 _this.logger = baseLogger.create('backendConnector'); 31490 _this.state = { 31491 }; 31492 _this.queue = [ 31493 ]; 31494 if (_this.backend && _this.backend.init) { 31495 _this.backend.init(services, options.backend, options); 31496 } 31497 return _this; 31498 } 31499 _createClass(Connector, [ 31500 { 31501 key: 'queueLoad', 31502 value: function queueLoad(languages, namespaces, options, callback) { 31503 var _this2 = this; // find what needs to be loaded 31504 var toLoad = [ 31505 ]; 31506 var pending = [ 31507 ]; 31508 var toLoadLanguages = [ 31509 ]; 31510 var toLoadNamespaces = [ 31511 ];
31512 languages.forEach(function (lng) { 31513 var hasAllNamespaces = true; 31514 namespaces.forEach(function (ns) { 31515 var name = ''.concat(lng, '|').concat(ns); 31516 if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) { 31517 _this2.state[name] = 2; // loaded 31518 } else if (_this2.state[name] < 0); 31519 else if (_this2.state[name] === 1) { 31520 if (pending.indexOf(name) < 0) pending.push(name); 31521 } else { 31522 _this2.state[name] = 1; // pending 31523 hasAllNamespaces = false; 31524 if (pending.indexOf(name) < 0) pending.push(name); 31525 if (toLoad.indexOf(name) < 0) toLoad.push(name); 31526 if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns); 31527 } 31528 }); 31529 if (!hasAllNamespaces) toLoadLanguages.push(lng); 31530 }); 31531 if (toLoad.length || pending.length) { 31532 this.queue.push({ 31533 pending: pending, 31534 loaded: { 31535 }, 31536 errors: [ 31537 ], 31538 callback: callback 31539 }); 31540 } 31541 return { 31542 toLoad: toLoad, 31543 pending: pending, 31544 toLoadLanguages: toLoadLanguages, 31545 toLoadNamespaces: toLoadNamespaces 31546 }; 31547 } 31548 }, 31549 { 31550 key: 'loaded', 31551 value: function loaded(name, err, data) { 31552 var _name$split = name.split('|'), 31553 _name$split2 = _slicedToArray(_name$split, 2), 31554 lng = _name$split2[0], 31555 ns = _name$split2[1]; 31556 if (err) this.emit('failedLoading', lng, ns, err); 31557 if (data) { 31558 this.store.addResourceBundle(lng, ns, data); 31559 } // set loaded 31560 31561 this.state[name] = err ? - 1 : 2; // consolidated loading done in this run - only emit once for a loaded namespace 31562 var loaded = { 31563 }; // callback if ready 31564 this.queue.forEach(function (q) { 31565 pushPath(q.loaded, [ 31566 lng 31567 ], ns); 31568 remove(q.pending, name); 31569 if (err) q.errors.push(err); 31570 if (q.pending.length === 0 && !q.done) { 31571 // only do once per loaded -> this.emit('loaded', q.loaded); 31572 Object.keys(q.loaded).forEach(function (l) { 31573 if (!loaded[l]) loaded[l] = [ 31574 ]; 31575 if (q.loaded[l].length) { 31576 q.loaded[l].forEach(function (ns) { 31577 if (loaded[l].indexOf(ns) < 0) loaded[l].push(ns); 31578 }); 31579 } 31580 }); 31581 /* eslint no-param-reassign: 0 */ 31582 q.done = true; 31583 if (q.errors.length) { 31584 q.callback(q.errors); 31585 } else { 31586 q.callback(); 31587 } 31588 } 31589 }); // emit consolidated loaded event 31590 this.emit('loaded', loaded); // remove done load requests 31591 this.queue = this.queue.filter(function (q) { 31592 return !q.done; 31593 }); 31594 } 31595 }, 31596 { 31597 key: 'read', 31598 value: function read(lng, ns, fcName) { 31599 var _this3 = this; 31600 var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; 31601 var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 250; 31602 var callback = arguments.length > 5 ? arguments[5] : undefined; 31603 if (!lng.length) return callback(null, { 31604 }); // noting to load 31605 return this.backend[fcName](lng, ns, function (err, data) { 31606 if (err && data /* = retryFlag */ 31607 && tried < 5) { 31608 setTimeout(function () { 31609 _this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback); 31610 }, wait); 31611 return; 31612 } 31613 callback(err, data); 31614 }); 31615 } /* eslint consistent-return: 0 */ 31616 31617 }, 31618 { 31619 key: 'prepareLoading', 31620 value: function prepareLoading(languages, namespaces) { 31621 var _this4 = this; 31622 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { 31623 }; 31624 var callback = arguments.length > 3 ? arguments[3] : undefined; 31625 if (!this.backend) { 31626 this.logger.warn('No backend was added via i18next.use. Will not load resources.'); 31627 return callback && callback(); 31628 } 31629 if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages); 31630 if (typeof namespaces === 'string') namespaces = [ 31631 namespaces 31632 ]; 31633 var toLoad = this.queueLoad(languages, namespaces, options, callback); 31634 if (!toLoad.toLoad.length) { 31635 if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now 31636 return null; // pendings will trigger callback 31637 }
vendor: 4,772 bytes, lines 31638-31743
31638 toLoad.toLoad.forEach(function (name) { 31639 _this4.loadOne(name); 31640 }); 31641 } 31642 }, 31643 { 31644 key: 'load', 31645 value: function load(languages, namespaces, callback) { 31646 this.prepareLoading(languages, namespaces, { 31647 }, callback); 31648 } 31649 }, 31650 { 31651 key: 'reload', 31652 value: function reload(languages, namespaces, callback) { 31653 this.prepareLoading(languages, namespaces, { 31654 reload: true 31655 }, callback); 31656 } 31657 }, 31658 { 31659 key: 'loadOne', 31660 value: function loadOne(name) { 31661 var _this5 = this; 31662 var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; 31663 var _name$split3 = name.split('|'), 31664 _name$split4 = _slicedToArray(_name$split3, 2), 31665 lng = _name$split4[0], 31666 ns = _name$split4[1]; 31667 this.read(lng, ns, 'read', null, null, function (err, data) { 31668 if (err) _this5.logger.warn(''.concat(prefix, 'loading namespace ').concat(ns, ' for language ').concat(lng, ' failed'), err); 31669 if (!err && data) _this5.logger.log(''.concat(prefix, 'loaded namespace ').concat(ns, ' for language ').concat(lng), data); 31670 _this5.loaded(name, err, data); 31671 }); 31672 } 31673 }, 31674 { 31675 key: 'saveMissing', 31676 value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) { 31677 var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : { 31678 }; 31679 if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) { 31680 this.logger.warn('did not save key "'.concat(key, '" for namespace "').concat(namespace, '" as the namespace was not yet loaded'), 'This means something IS WRONG in your application setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!'); 31681 return; 31682 } // ignore non valid keys 31683 31684 if (key === undefined || key === null || key === '') return; 31685 if (this.backend && this.backend.create) { 31686 this.backend.create(languages, namespace, key, fallbackValue, null /* unused callback */ 31687 , _objectSpread({ 31688 }, options, { 31689 isUpdate: isUpdate 31690 })); 31691 } // write to store to avoid resending 31692 31693 if (!languages || !languages[0]) return; 31694 this.store.addResource(languages[0], namespace, key, fallbackValue); 31695 } 31696 } 31697 ]); 31698 return Connector; 31699 }(EventEmitter); 31700 function get() { 31701 return { 31702 debug: false, 31703 initImmediate: true, 31704 ns: [ 31705 'translation' 31706 ], 31707 defaultNS: [ 31708 'translation' 31709 ], 31710 fallbackLng: [ 31711 'dev' 31712 ], 31713 fallbackNS: false, 31714 // string or array of namespaces 31715 whitelist: false, 31716 // array with whitelisted languages 31717 nonExplicitWhitelist: false, 31718 load: 'all', 31719 // | currentOnly | languageOnly 31720 preload: false, 31721 // array with preload languages 31722 simplifyPluralSuffix: true, 31723 keySeparator: '.', 31724 nsSeparator: ':', 31725 pluralSeparator: '_', 31726 contextSeparator: '_', 31727 partialBundledLanguages: false, 31728 // allow bundling certain languages that are not remotely fetched 31729 saveMissing: false, 31730 // enable to send missing values 31731 updateMissing: false, 31732 // enable to update default values if different from translated value (only useful on initial development, or when keeping code as source of truth) 31733 saveMissingTo: 'fallback', 31734 // 'current' || 'all' 31735 saveMissingPlurals: true, 31736 // will save all forms not only singular key 31737 missingKeyHandler: false, 31738 // function(lng, ns, key, fallbackValue) -> override if prefer on handling 31739 missingInterpolationHandler: false, 31740 // function(str, match) 31741 postProcess: false, 31742 // string or array of postProcessor names 31743 postProcessPassResolved: false,
31744 // pass resolved object into 'options.i18nResolved' for postprocessor 31745 returnNull: true, 31746 // allows null value as valid translation 31747 returnEmptyString: true, 31748 // allows empty string value as valid translation 31749 returnObjects: false, 31750 joinArrays: false, 31751 // or string to join array 31752 returnedObjectHandler: false, 31753 // function(key, value, options) triggered if key returns object but returnObjects is set to false 31754 parseMissingKeyHandler: false, 31755 // function(key) parsed a key that was not found in t() before returning 31756 appendNamespaceToMissingKey: false, 31757 appendNamespaceToCIMode: false, 31758 overloadTranslationOptionHandler: function handle(args) { 31759 var ret = { 31760 }; 31761 if (_typeof(args[1]) === 'object') ret = args[1]; 31762 if (typeof args[1] === 'string') ret.defaultValue = args[1]; 31763 if (typeof args[2] === 'string') ret.tDescription = args[2]; 31764 if (_typeof(args[2]) === 'object' || _typeof(args[3]) === 'object') { 31765 var options = args[3] || args[2]; 31766 Object.keys(options).forEach(function (key) { 31767 ret[key] = options[key]; 31768 }); 31769 } 31770 return ret; 31771 }, 31772 interpolation: { 31773 escapeValue: true, 31774 format: function format(value, _format, lng) { 31775 return value; 31776 }, 31777 prefix: '{{', 31778 suffix: '}}', 31779 formatSeparator: ',', 31780 // prefixEscaped: '{{', 31781 // suffixEscaped: '}}', 31782 // unescapeSuffix: '', 31783 unescapePrefix: '-', 31784 nestingPrefix: '$t(', 31785 nestingSuffix: ')', 31786 // nestingPrefixEscaped: '$t(', 31787 // nestingSuffixEscaped: ')', 31788 // defaultVariables: undefined // object that can have values to interpolate on - extends passed in interpolation data 31789 maxReplaces: 1000 // max replaces to prevent endless loop 31790 } 31791 }; 31792 } /* eslint no-param-reassign: 0 */ 31793 31794 function transformOptions(options) { 31795 // create namespace object if namespace is passed in as string 31796 if (typeof options.ns === 'string') options.ns = [ 31797 options.ns 31798 ]; 31799 if (typeof options.fallbackLng === 'string') options.fallbackLng = [ 31800 options.fallbackLng 31801 ]; 31802 if (typeof options.fallbackNS === 'string') options.fallbackNS = [ 31803 options.fallbackNS 31804 ]; // extend whitelist with cimode 31805 if (options.whitelist && options.whitelist.indexOf('cimode') < 0) { 31806 options.whitelist = options.whitelist.concat(['cimode']); 31807 } 31808 return options; 31809 } 31810 function noop() { 31811 } 31812 var I18n = /*#__PURE__*/ 31813 function (_EventEmitter) { 31814 _inherits(I18n, _EventEmitter); 31815 function I18n() { 31816 var _this; 31817 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 31818 }; 31819 var callback = arguments.length > 1 ? arguments[1] : undefined; 31820 _classCallCheck(this, I18n); 31821 _this = _possibleConstructorReturn(this, _getPrototypeOf(I18n).call(this)); 31822 EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor) 31823 _this.options = transformOptions(options); 31824 _this.services = { 31825 }; 31826 _this.logger = baseLogger; 31827 _this.modules = { 31828 external: [ 31829 ] 31830 }; 31831 if (callback && !_this.isInitialized && !options.isClone) { 31832 // https://github.com/i18next/i18next/issues/879 31833 if (!_this.options.initImmediate) { 31834 _this.init(options, callback); 31835 return _possibleConstructorReturn(_this, _assertThisInitialized(_this)); 31836 } 31837 setTimeout(function () { 31838 _this.init(options, callback); 31839 }, 0); 31840 } 31841 return _this; 31842 } 31843 _createClass(I18n, [ 31844 { 31845 key: 'init',
vendor: 13,199 bytes, lines 31846-32134
31846 value: function init() { 31847 var _this2 = this; 31848 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 31849 }; 31850 var callback = arguments.length > 1 ? arguments[1] : undefined; 31851 if (typeof options === 'function') { 31852 callback = options; 31853 options = { 31854 }; 31855 } 31856 this.options = _objectSpread({ 31857 }, get(), this.options, transformOptions(options)); 31858 this.format = this.options.interpolation.format; 31859 if (!callback) callback = noop; 31860 function createClassOnDemand(ClassOrObject) { 31861 if (!ClassOrObject) return null; 31862 if (typeof ClassOrObject === 'function') return new ClassOrObject(); 31863 return ClassOrObject; 31864 } // init services 31865 31866 if (!this.options.isClone) { 31867 if (this.modules.logger) { 31868 baseLogger.init(createClassOnDemand(this.modules.logger), this.options); 31869 } else { 31870 baseLogger.init(null, this.options); 31871 } 31872 var lu = new LanguageUtil(this.options); 31873 this.store = new ResourceStore(this.options.resources, this.options); 31874 var s = this.services; 31875 s.logger = baseLogger; 31876 s.resourceStore = this.store; 31877 s.languageUtils = lu; 31878 s.pluralResolver = new PluralResolver(lu, { 31879 prepend: this.options.pluralSeparator, 31880 compatibilityJSON: this.options.compatibilityJSON, 31881 simplifyPluralSuffix: this.options.simplifyPluralSuffix 31882 }); 31883 s.interpolator = new Interpolator(this.options); 31884 s.utils = { 31885 hasLoadedNamespace: this.hasLoadedNamespace.bind(this) 31886 }; 31887 s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options); // pipe events from backendConnector 31888 s.backendConnector.on('*', function (event) { 31889 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 31890 args[_key - 1] = arguments[_key]; 31891 } 31892 _this2.emit.apply(_this2, [ 31893 event 31894 ].concat(args)); 31895 }); 31896 if (this.modules.languageDetector) { 31897 s.languageDetector = createClassOnDemand(this.modules.languageDetector); 31898 s.languageDetector.init(s, this.options.detection, this.options); 31899 } 31900 if (this.modules.i18nFormat) { 31901 s.i18nFormat = createClassOnDemand(this.modules.i18nFormat); 31902 if (s.i18nFormat.init) s.i18nFormat.init(this); 31903 } 31904 this.translator = new Translator(this.services, this.options); // pipe events from translator 31905 this.translator.on('*', function (event) { 31906 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { 31907 args[_key2 - 1] = arguments[_key2]; 31908 } 31909 _this2.emit.apply(_this2, [ 31910 event 31911 ].concat(args)); 31912 }); 31913 this.modules.external.forEach(function (m) { 31914 if (m.init) m.init(_this2); 31915 }); 31916 } // append api 31917 31918 var storeApi = [ 31919 'getResource', 31920 'addResource', 31921 'addResources', 31922 'addResourceBundle', 31923 'removeResourceBundle', 31924 'hasResourceBundle', 31925 'getResourceBundle', 31926 'getDataByLanguage' 31927 ]; 31928 storeApi.forEach(function (fcName) { 31929 _this2[fcName] = function () { 31930 var _this2$store; 31931 return (_this2$store = _this2.store) [fcName].apply(_this2$store, arguments); 31932 }; 31933 }); 31934 var deferred = defer(); 31935 var load = function load() { 31936 _this2.changeLanguage(_this2.options.lng, function (err, t) { 31937 _this2.isInitialized = true; 31938 _this2.logger.log('initialized', _this2.options); 31939 _this2.emit('initialized', _this2.options); 31940 deferred.resolve(t); // not rejecting on err (as err is only a loading translation failed warning) 31941 callback(err, t); 31942 }); 31943 }; 31944 if (this.options.resources || !this.options.initImmediate) { 31945 load(); 31946 } else { 31947 setTimeout(load, 0); 31948 } 31949 return deferred; 31950 } /* eslint consistent-return: 0 */ 31951 31952 }, 31953 { 31954 key: 'loadResources', 31955 value: function loadResources(language) { 31956 var _this3 = this; 31957 var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop; 31958 var usedCallback = callback; 31959 var usedLng = typeof language === 'string' ? language : this.language; 31960 if (typeof language === 'function') usedCallback = language; 31961 if (!this.options.resources || this.options.partialBundledLanguages) { 31962 if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback(); // avoid loading resources for cimode 31963 var toLoad = [ 31964 ]; 31965 var append = function append(lng) { 31966 if (!lng) return; 31967 var lngs = _this3.services.languageUtils.toResolveHierarchy(lng); 31968 lngs.forEach(function (l) { 31969 if (toLoad.indexOf(l) < 0) toLoad.push(l); 31970 }); 31971 }; 31972 if (!usedLng) { 31973 // at least load fallbacks in this case 31974 var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng); 31975 fallbacks.forEach(function (l) { 31976 return append(l); 31977 }); 31978 } else { 31979 append(usedLng); 31980 } 31981 if (this.options.preload) { 31982 this.options.preload.forEach(function (l) { 31983 return append(l); 31984 }); 31985 } 31986 this.services.backendConnector.load(toLoad, this.options.ns, usedCallback); 31987 } else { 31988 usedCallback(null); 31989 } 31990 } 31991 }, 31992 { 31993 key: 'reloadResources', 31994 value: function reloadResources(lngs, ns, callback) { 31995 var deferred = defer(); 31996 if (!lngs) lngs = this.languages; 31997 if (!ns) ns = this.options.ns; 31998 if (!callback) callback = noop; 31999 this.services.backendConnector.reload(lngs, ns, function (err) { 32000 deferred.resolve(); // not rejecting on err (as err is only a loading translation failed warning) 32001 callback(err); 32002 }); 32003 return deferred; 32004 } 32005 }, 32006 { 32007 key: 'use', 32008 value: function use(module) { 32009 if (module.type === 'backend') { 32010 this.modules.backend = module; 32011 } 32012 if (module.type === 'logger' || module.log && module.warn && module.error) { 32013 this.modules.logger = module; 32014 } 32015 if (module.type === 'languageDetector') { 32016 this.modules.languageDetector = module; 32017 } 32018 if (module.type === 'i18nFormat') { 32019 this.modules.i18nFormat = module; 32020 } 32021 if (module.type === 'postProcessor') { 32022 postProcessor.addPostProcessor(module); 32023 } 32024 if (module.type === '3rdParty') { 32025 this.modules.external.push(module); 32026 } 32027 return this; 32028 } 32029 }, 32030 { 32031 key: 'changeLanguage', 32032 value: function changeLanguage(lng, callback) { 32033 var _this4 = this; 32034 this.isLanguageChangingTo = lng; 32035 var deferred = defer(); 32036 this.emit('languageChanging', lng); 32037 var done = function done(err, l) { 32038 if (l) { 32039 _this4.language = l; 32040 _this4.languages = _this4.services.languageUtils.toResolveHierarchy(l); 32041 _this4.translator.changeLanguage(l); 32042 _this4.isLanguageChangingTo = undefined; 32043 _this4.emit('languageChanged', l); 32044 _this4.logger.log('languageChanged', l); 32045 } else { 32046 _this4.isLanguageChangingTo = undefined; 32047 } 32048 deferred.resolve(function () { 32049 return _this4.t.apply(_this4, arguments); 32050 }); 32051 if (callback) callback(err, function () { 32052 return _this4.t.apply(_this4, arguments); 32053 }); 32054 }; 32055 var setLng = function setLng(l) { 32056 if (l) { 32057 if (!_this4.language) { 32058 _this4.language = l; 32059 _this4.languages = _this4.services.languageUtils.toResolveHierarchy(l); 32060 } 32061 if (!_this4.translator.language) _this4.translator.changeLanguage(l); 32062 if (_this4.services.languageDetector) _this4.services.languageDetector.cacheUserLanguage(l); 32063 } 32064 _this4.loadResources(l, function (err) { 32065 done(err, l); 32066 }); 32067 }; 32068 if (!lng && this.services.languageDetector && !this.services.languageDetector.async) { 32069 setLng(this.services.languageDetector.detect()); 32070 } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) { 32071 this.services.languageDetector.detect(setLng); 32072 } else { 32073 setLng(lng); 32074 } 32075 return deferred; 32076 } 32077 }, 32078 { 32079 key: 'getFixedT', 32080 value: function getFixedT(lng, ns) { 32081 var _this5 = this; 32082 var fixedT = function fixedT(key, opts) { 32083 var options; 32084 if (_typeof(opts) !== 'object') { 32085 for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { 32086 rest[_key3 - 2] = arguments[_key3]; 32087 } 32088 options = _this5.options.overloadTranslationOptionHandler([key, 32089 opts].concat(rest)); 32090 } else { 32091 options = _objectSpread({ 32092 }, opts); 32093 } 32094 options.lng = options.lng || fixedT.lng; 32095 options.lngs = options.lngs || fixedT.lngs; 32096 options.ns = options.ns || fixedT.ns; 32097 return _this5.t(key, options); 32098 }; 32099 if (typeof lng === 'string') { 32100 fixedT.lng = lng; 32101 } else { 32102 fixedT.lngs = lng; 32103 } 32104 fixedT.ns = ns; 32105 return fixedT; 32106 } 32107 }, 32108 { 32109 key: 't', 32110 value: function t() { 32111 var _this$translator; 32112 return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments); 32113 } 32114 }, 32115 { 32116 key: 'exists', 32117 value: function exists() { 32118 var _this$translator2; 32119 return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments); 32120 } 32121 }, 32122 { 32123 key: 'setDefaultNamespace', 32124 value: function setDefaultNamespace(ns) { 32125 this.options.defaultNS = ns; 32126 } 32127 }, 32128 { 32129 key: 'hasLoadedNamespace', 32130 value: function hasLoadedNamespace(ns) { 32131 var _this6 = this; 32132 if (!this.isInitialized) { 32133 this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages); 32134 return false;
vendor: 4,722 bytes, lines 32135-32264
32135 } 32136 if (!this.languages || !this.languages.length) { 32137 this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages); 32138 return false; 32139 } 32140 var lng = this.languages[0]; 32141 var fallbackLng = this.options ? this.options.fallbackLng : false; 32142 var lastLng = this.languages[this.languages.length - 1]; // we're in cimode so this shall pass 32143 if (lng.toLowerCase() === 'cimode') return true; 32144 var loadNotPending = function loadNotPending(l, n) { 32145 var loadState = _this6.services.backendConnector.state[''.concat(l, '|').concat(n)]; 32146 return loadState === - 1 || loadState === 2; 32147 }; // loaded -> SUCCESS 32148 if (this.hasResourceBundle(lng, ns)) return true; // were not loading at all -> SEMI SUCCESS 32149 if (!this.services.backendConnector.backend) return true; // failed loading ns - but at least fallback is not pending -> SEMI SUCCESS 32150 if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; 32151 return false; 32152 } 32153 }, 32154 { 32155 key: 'loadNamespaces', 32156 value: function loadNamespaces(ns, callback) { 32157 var _this7 = this; 32158 var deferred = defer(); 32159 if (!this.options.ns) { 32160 callback && callback(); 32161 return Promise.resolve(); 32162 } 32163 if (typeof ns === 'string') ns = [ 32164 ns 32165 ]; 32166 ns.forEach(function (n) { 32167 if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n); 32168 }); 32169 this.loadResources(function (err) { 32170 deferred.resolve(); 32171 if (callback) callback(err); 32172 }); 32173 return deferred; 32174 } 32175 }, 32176 { 32177 key: 'loadLanguages', 32178 value: function loadLanguages(lngs, callback) { 32179 var deferred = defer(); 32180 if (typeof lngs === 'string') lngs = [ 32181 lngs 32182 ]; 32183 var preloaded = this.options.preload || [ 32184 ]; 32185 var newLngs = lngs.filter(function (lng) { 32186 return preloaded.indexOf(lng) < 0; 32187 }); // Exit early if all given languages are already preloaded 32188 if (!newLngs.length) { 32189 if (callback) callback(); 32190 return Promise.resolve(); 32191 } 32192 this.options.preload = preloaded.concat(newLngs); 32193 this.loadResources(function (err) { 32194 deferred.resolve(); 32195 if (callback) callback(err); 32196 }); 32197 return deferred; 32198 } 32199 }, 32200 { 32201 key: 'dir', 32202 value: function dir(lng) { 32203 if (!lng) lng = this.languages && this.languages.length > 0 ? this.languages[0] : this.language; 32204 if (!lng) return 'rtl'; 32205 var rtlLngs = [ 32206 'ar', 32207 'shu', 32208 'sqr', 32209 'ssh', 32210 'xaa', 32211 'yhd', 32212 'yud', 32213 'aao', 32214 'abh', 32215 'abv', 32216 'acm', 32217 'acq', 32218 'acw', 32219 'acx', 32220 'acy', 32221 'adf', 32222 'ads', 32223 'aeb', 32224 'aec', 32225 'afb', 32226 'ajp', 32227 'apc', 32228 'apd', 32229 'arb', 32230 'arq', 32231 'ars', 32232 'ary', 32233 'arz', 32234 'auz', 32235 'avl', 32236 'ayh', 32237 'ayl', 32238 'ayn', 32239 'ayp', 32240 'bbz', 32241 'pga', 32242 'he', 32243 'iw', 32244 'ps', 32245 'pbt', 32246 'pbu', 32247 'pst', 32248 'prp', 32249 'prd', 32250 'ur', 32251 'ydd', 32252 'yds', 32253 'yih', 32254 'ji', 32255 'yi', 32256 'hbo', 32257 'men', 32258 'xmn', 32259 'fa', 32260 'jpr', 32261 'peo', 32262 'pes', 32263 'prs', 32264 'dv',
32265 'sam' 32266 ]; 32267 return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) >= 0 ? 'rtl' : 'ltr'; 32268 } /* eslint class-methods-use-this: 0 */ 32269 32270 }, 32271 { 32272 key: 'createInstance', 32273 value: function createInstance() { 32274 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 32275 }; 32276 var callback = arguments.length > 1 ? arguments[1] : undefined; 32277 return new I18n(options, callback); 32278 } 32279 }, 32280 { 32281 key: 'cloneInstance', 32282 value: function cloneInstance() { 32283 var _this8 = this; 32284 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 32285 }; 32286 var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop; 32287 var mergedOptions = _objectSpread({ 32288 }, this.options, options, { 32289 isClone: true 32290 }); 32291 var clone = new I18n(mergedOptions); 32292 var membersToCopy = [ 32293 'store', 32294 'services', 32295 'language' 32296 ]; 32297 membersToCopy.forEach(function (m) { 32298 clone[m] = _this8[m]; 32299 }); 32300 clone.translator = new Translator(clone.services, clone.options); 32301 clone.translator.on('*', function (event) { 32302 for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { 32303 args[_key4 - 1] = arguments[_key4]; 32304 } 32305 clone.emit.apply(clone, [ 32306 event 32307 ].concat(args)); 32308 }); 32309 clone.init(mergedOptions, callback); 32310 clone.translator.options = clone.options; // sync options 32311 return clone; 32312 } 32313 } 32314 ]); 32315 return I18n; 32316 }(EventEmitter); 32317 var i18next = new I18n(); 32318 module.exports = i18next; 32319 }, 32320 { 32321 '@babel/runtime/helpers/assertThisInitialized': 4, 32322 '@babel/runtime/helpers/classCallCheck': 5, 32323 '@babel/runtime/helpers/createClass': 6, 32324 '@babel/runtime/helpers/getPrototypeOf': 8, 32325 '@babel/runtime/helpers/inherits': 9, 32326 '@babel/runtime/helpers/objectSpread': 14, 32327 '@babel/runtime/helpers/possibleConstructorReturn': 15, 32328 '@babel/runtime/helpers/slicedToArray': 17, 32329 '@babel/runtime/helpers/toConsumableArray': 18, 32330 '@babel/runtime/helpers/typeof': 19 32331 } 32332 ], 32333 260: [ 32334 function (_dereq_, module, exports) { 32335 exports.read = function (buffer, offset, isLE, mLen, nBytes) { 32336 var e, 32337 m; 32338 var eLen = nBytes * 8 - mLen - 1; 32339 var eMax = (1 << eLen) - 1; 32340 var eBias = eMax >> 1; 32341 var nBits = - 7; 32342 var i = isLE ? nBytes - 1 : 0; 32343 var d = isLE ? - 1 : 1; 32344 var s = buffer[offset + i]; 32345 i += d; 32346 e = s & (1 << - nBits) - 1; 32347 s >>= - nBits; 32348 nBits += eLen; 32349 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) { 32350 } 32351 m = e & (1 << - nBits) - 1; 32352 e >>= - nBits; 32353 nBits += mLen; 32354 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) { 32355 } 32356 if (e === 0) { 32357 e = 1 - eBias; 32358 } else if (e === eMax) { 32359 return m ? NaN : (s ? - 1 : 1) * Infinity; 32360 } else { 32361 m = m + Math.pow(2, mLen); 32362 e = e - eBias; 32363 } 32364 return (s ? - 1 : 1) * m * Math.pow(2, e - mLen); 32365 }; 32366 exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { 32367 var e, 32368 m, 32369 c; 32370 var eLen = nBytes * 8 - mLen - 1; 32371 var eMax = (1 << eLen) - 1; 32372 var eBias = eMax >> 1; 32373 var rt = mLen === 23 ? Math.pow(2, - 24) - Math.pow(2, - 77) : 0; 32374 var i = isLE ? 0 : nBytes - 1; 32375 var d = isLE ? 1 : - 1; 32376 var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; 32377 value = Math.abs(value); 32378 if (isNaN(value) || value === Infinity) { 32379 m = isNaN(value) ? 1 : 0; 32380 e = eMax; 32381 } else { 32382 e = Math.floor(Math.log(value) / Math.LN2); 32383 if (value * (c = Math.pow(2, - e)) < 1) { 32384 e--; 32385 c *= 2; 32386 } 32387 if (e + eBias >= 1) { 32388 value += rt / c; 32389 } else { 32390 value += rt * Math.pow(2, 1 - eBias); 32391 } 32392 if (value * c >= 2) { 32393 e++; 32394 c /= 2; 32395 } 32396 if (e + eBias >= eMax) { 32397 m = 0; 32398 e = eMax; 32399 } else if (e + eBias >= 1) { 32400 m = (value * c - 1) * Math.pow(2, mLen); 32401 e = e + eBias; 32402 } else { 32403 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); 32404 e = 0; 32405 } 32406 } 32407 for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) { 32408 } 32409 e = e << mLen | m; 32410 eLen += mLen; 32411 for (; eLen > 0;
32411 buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) { 32412 } 32413 buffer[offset + i - d] |= s * 128; 32414 }; 32415 }, 32416 { 32417 } 32418 ], 32419 261: [ 32420 function (_dereq_, module, exports) { 32421 /* 32422 32423 Copyright 2000, Silicon Graphics, Inc. All Rights Reserved. 32424 Copyright 2015, Google Inc. All Rights Reserved. 32425 32426 Permission is hereby granted, free of charge, to any person obtaining a copy 32427 of this software and associated documentation files (the "Software"), to 32428 deal in the Software without restriction, including without limitation the 32429 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 32430 sell copies of the Software, and to permit persons to whom the Software is 32431 furnished to do so, subject to the following conditions: 32432 32433 The above copyright notice including the dates of first publication and 32434 either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/ 32435 shall be included in all copies or substantial portions of the Software. 32436 32437 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32438 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32439 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 32440 SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 32441 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 32442 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32443 32444 Original Code. The Original Code is: OpenGL Sample Implementation, 32445 Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 32446 Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 32447 Copyright in any portions created by third parties is as indicated 32448 elsewhere herein. All Rights Reserved. 32449*/ 32450 'use strict'; 32451 var n; 32452 function t(a, b) { 32453 return a.b === b.b && a.a === b.a; 32454 } 32455 function u(a, b) { 32456 return a.b < b.b || a.b === b.b && a.a <= b.a; 32457 } 32458 function v(a, b, c) { 32459 var d = b.b - a.b, 32460 e = c.b - b.b; 32461 return 0 < d + e ? d < e ? b.a - a.a + d / (d + e) * (a.a - c.a) : b.a - c.a + e / (d + e) * (c.a - a.a) : 0; 32462 } 32463 function x(a, b, c) { 32464 var d = b.b - a.b, 32465 e = c.b - b.b; 32466 return 0 < d + e ? (b.a - c.a) * d + (b.a - a.a) * e : 0; 32467 } 32468 function z(a, b) { 32469 return a.a < b.a || a.a === b.a && a.b <= b.b; 32470 } 32471 function aa(a, b, c) { 32472 var d = b.a - a.a, 32473 e = c.a - b.a; 32474 return 0 < d + e ? d < e ? b.b - a.b + d / (d + e) * (a.b - c.b) : b.b - c.b + e / (d + e) * (c.b - a.b) : 0; 32475 } 32476 function ba(a, b, c) { 32477 var d = b.a - a.a, 32478 e = c.a - b.a; 32479 return 0 < d + e ? (b.b - c.b) * d + (b.b - a.b) * e : 0; 32480 } 32481 function ca(a) { 32482 return u(a.b.a, a.a); 32483 } 32484 function da(a) { 32485 return u(a.a, a.b.a); 32486 } 32487 function A(a, b, c, d) { 32488 a = 0 > a ? 0 : a; 32489 c = 0 > c ? 0 : c; 32490 return a <= c ? 0 === c ? (b + d) / 2 : b + a / (a + c) * (d - b) : d + c / (a + c) * (b - d); 32491 } 32492 ; 32493 function ea(a) { 32494 var b = B(a.b); 32495 C(b, a.c); 32496 C(b.b, a.c); 32497 D(b, a.a); 32498 return b; 32499 } 32500 function E(a, b) { 32501 var c = !1, 32502 d = !1; 32503 a !== b && (b.a !== a.a && (d = !0, F(b.a, a.a)), b.d !== a.d && (c = !0, G(b.d, a.d)), H(b, a), d || (C(b, a.a), a.a.c = a), c || (D(b, a.d), a.d.a = a)); 32504 } 32505 function I(a) { 32506 var b = a.b, 32507 c = !1; 32508 a.d !== a.b.d && (c = !0, G(a.d, a.b.d)); 32509 a.c === a ? F(a.a, null) : (a.b.d.a = J(a), a.a.c = a.c, H(a, J(a)), c || D(a, a.d)); 32510 b.c === b ? (F(b.a, null), G(b.d, null)) : (a.d.a = J(b), b.a.c = b.c, H(b, J(b))); 32511 fa(a); 32512 } 32513 function K(a) { 32514 var b = B(a), 32515 c = b.b; 32516 H(b, a.e); 32517 b.a = a.b.a; 32518 C(c, b.a); 32519 b.d = c.d = a.d; 32520 b = b.b; 32521 H(a.b, J(a.b)); 32522 H(a.b, b); 32523 a.b.a = b.a;
32524 b.b.a.c = b.b; 32525 b.b.d = a.b.d; 32526 b.f = a.f; 32527 b.b.f = a.b.f; 32528 return b; 32529 } 32530 function L(a, b) { 32531 var c = !1, 32532 d = B(a), 32533 e = d.b; 32534 b.d !== a.d && (c = !0, G(b.d, a.d)); 32535 H(d, a.e); 32536 H(e, b); 32537 d.a = a.b.a; 32538 e.a = b.a; 32539 d.d = e.d = a.d; 32540 a.d.a = e; 32541 c || D(d, a.d); 32542 return d; 32543 } 32544 function B(a) { 32545 var b = new M(), 32546 c = new M(), 32547 d = a.b.h; 32548 c.h = d; 32549 d.b.h = b; 32550 b.h = a; 32551 a.b.h = c; 32552 b.b = c; 32553 b.c = b; 32554 b.e = c; 32555 c.b = b; 32556 c.c = c; 32557 return c.e = b; 32558 } 32559 function H(a, b) { 32560 var c = a.c, 32561 d = b.c; 32562 c.b.e = b; 32563 d.b.e = a; 32564 a.c = d; 32565 b.c = c; 32566 } 32567 function C(a, b) { 32568 var c = b.f, 32569 d = new N(b, c); 32570 c.e = d; 32571 b.f = d; 32572 c = d.c = a; 32573 do c.a = d, 32574 c = c.c; 32575 while (c !== a); 32576 } 32577 function D(a, b) { 32578 var c = b.d, 32579 d = new ga(b, c); 32580 c.b = d; 32581 b.d = d; 32582 d.a = a; 32583 d.c = b.c; 32584 c = a; 32585 do c.d = d, 32586 c = c.e; 32587 while (c !== a); 32588 } 32589 function fa(a) { 32590 var b = a.h; 32591 a = a.b.h; 32592 b.b.h = a; 32593 a.b.h = b; 32594 } 32595 function F(a, b) { 32596 var c = a.c, 32597 d = c; 32598 do d.a = b, 32599 d = d.c; 32600 while (d !== c); 32601 c = a.f; 32602 d = a.e; 32603 d.f = c; 32604 c.e = d; 32605 } 32606 function G(a, b) { 32607 var c = a.a, 32608 d = c; 32609 do d.d = b, 32610 d = d.e; 32611 while (d !== c); 32612 c = a.d; 32613 d = a.b; 32614 d.d = c; 32615 c.b = d; 32616 } 32617 ; 32618 function ha(a) { 32619 var b = 0; 32620 Math.abs(a[1]) > Math.abs(a[0]) && (b = 1); 32621 Math.abs(a[2]) > Math.abs(a[b]) && (b = 2); 32622 return b; 32623 } 32624 ; 32625 var O = 4 * 1e+150; 32626 function P(a, b) { 32627 a.f += b.f; 32628 a.b.f += b.b.f; 32629 } 32630 function ia(a, b, c) { 32631 a = a.a; 32632 b = b.a; 32633 c = c.a; 32634 if (b.b.a === a) return c.b.a === a ? u(b.a, c.a) ? 0 >= x(c.b.a, b.a, c.a) : 0 <= x(b.b.a, c.a, b.a) : 0 >= x(c.b.a, a, c.a); 32635 if (c.b.a === a) return 0 <= x(b.b.a, a, b.a); 32636 b = v(b.b.a, a, b.a); 32637 a = v(c.b.a, a, c.a); 32638 return b >= a; 32639 } 32640 function Q(a) { 32641 a.a.i = null; 32642 var b = a.e; 32643 b.a.c = b.c; 32644 b.c.a = b.a; 32645 a.e = null; 32646 } 32647 function ja(a, b) { 32648 I(a.a); 32649 a.c = !1; 32650 a.a = b; 32651 b.i = a; 32652 } 32653 function ka(a) { 32654 var b = a.a.a; 32655 do a = R(a); 32656 while (a.a.a === b); 32657 a.c && (b = L(S(a).a.b, a.a.e), ja(a, b), a = R(a)); 32658 return a; 32659 } 32660 function la(a, b, c) { 32661 var d = new ma(); 32662 d.a = c; 32663 d.e = na(a.f, b.e, d); 32664 return c.i = d; 32665 } 32666 function oa(a, b) { 32667 switch (a.s) { 32668 case 100130: 32669 return 0 !== (b & 1); 32670 case 100131: 32671 return 0 !== b; 32672 case 100132: 32673 return 0 < b; 32674 case 100133: 32675 return 0 > b; 32676 case 100134: 32677 return 2 <= b || - 2 >= b; 32678 } 32679 return !1; 32680 } 32681 function pa(a) { 32682 var b = a.a, 32683 c = b.d; 32684 c.c = a.d; 32685 c.a = b; 32686 Q(a); 32687 } 32688 function T(a, b, c) { 32689 a = b; 32690 for (b = b.a; a !== c; ) { 32691 a.c = !1; 32692 var d = S(a), 32693 e = d.a; 32694 if (e.a !== b.a) { 32695 if (!d.c) { 32696 pa(a); 32697 break; 32698 } 32699 e = L(b.c.b, e.b); 32700 ja(d, e); 32701 } 32702 b.c !== e && (E(J(e), e), E(b, e)); 32703 pa(a); 32704 b = d.a; 32705 a = d; 32706 } 32707 return b; 32708 } 32709 function U(a, b, c, d, e, f) { 32710 var g = !0; 32711 do la(a, b, c.b), 32712 c = c.c; 32713 while (c !== d); 32714 for (null === e && (e = S(b).a.b.c); ; ) { 32715 d = S(b); 32716 c = d.a.b; 32717 if (c.a !== e.a) break; 32718 c.c !== e && (E(J(c), c), E(J(e), c)); 32719 d.f = b.f - c.f; 32720 d.d = oa(a, d.f); 32721 b.b = !0; 32722 !g && qa(a, b) && (P(c, e), Q(b), I(e)); 32723 g = !1; 32724 b = d; 32725 e = c; 32726 } 32727 b.b = !0; 32728 f && ra(a, b); 32729 } 32730 function sa(a, b, c, d, e) { 32731 var f = [ 32732 b.g[0], 32733 b.g[1], 32734 b.g[2] 32735 ]; 32736 b.d = null; 32737 b.d = a.o ? a.o(f, c, d, a.c) || null : null; 32738 null === b.d && (e ? a.n || (V(a, 100156), a.n = !0) : b.d = c[0]); 32739 } 32740 function ta(a, b, c) { 32741 var d = [ 32742 null, 32743 null, 32744 null, 32745 null 32746 ]; 32747 d[0] = b.a.d; 32748 d[1] = c.a.d; 32749 sa(a, b.a, d, [ 32750 0.5, 32751 0.5, 32752 0, 32753 0 32754 ], !1); 32755 E(b, c); 32756 } 32757 function ua(a, b, c, d, e) { 32758 var f = Math.abs(b.b - a.b) + Math.abs(b.a - a.a), 32759 g = Math.abs(c.b - a.b) + Math.abs(c.a - a.a), 32760 h = e + 1; 32761 d[e] = 0.5 * g / (f + g); 32762 d[h] = 0.5 * f / (f + g); 32763 a.g[0] += d[e] * b.g[0] + d[h] * c.g[0]; 32764 a.g[1] += d[e] * b.g[1] + d[h] * c.g[1]; 32765 a.g[2] += d[e] * b.g[2] + d[h] * c.g[2]; 32766 } 32767 function qa(a, b) { 32768 var c = S(b), 32769 d = b.a, 32770 e = c.a; 32771 if (u(d.a, e.a)) { 32772 if (0 < x(e.b.a, d.a, e.a)) return !1; 32773 if (!t(d.a, e.a)) K(e.b), 32774 E(d, J(e)), 32775 b.b = c.b = !0; 32776 else if (d.a !== e.a) { 32777 var c = a.e, 32778 f = d.a.h; 32779 if (0 <= f) { 32780 var c = c.b, 32781 g = c.d, 32782 h = c.e, 32783 k = c.c, 32784 l = k[f]; 32785 g[l] = g[c.a]; 32786 k[g[l]] = l; 32787 l <= --c.a && (1 >= l ? W(c, l) : u(h[g[l >> 1]], h[g[l]]) ? W(c, l) : va(c, l)); 32788 h[f] = null; 32789 k[f] = c.b; 32790 c.b = f; 32791 } else for (c.c[ - (f + 1)] = null; 0 < c.a && null === c.c[c.d[c.a - 1]]; ) --c.a; 32792 ta(a, J(e), d); 32793 } 32794 } else { 32795 if (0 > x(d.b.a, e.a, d.a)) return !1; 32796 R(b).b = b.b = !0; 32797 K(d.b); 32798 E(J(e), d); 32799 } 32800 return !0; 32801 } 32802 function wa(a, b) { 32803 var c = S(b), 32804 d = b.a, 32805 e = c.a, 32806 f = d.a, 32807 g = e.a, 32808 h = d.b.a, 32809 k = e.b.a,
32810 l = new N(); 32811 x(h, a.a, f); 32812 x(k, a.a, g); 32813 if (f === g || Math.min(f.a, h.a) > Math.max(g.a, k.a)) return !1; 32814 if (u(f, g)) { 32815 if (0 < x(k, f, g)) return !1; 32816 } else if (0 > x(h, g, f)) return !1; 32817 var r = h, 32818 p = f, 32819 q = k, 32820 y = g, 32821 m, 32822 w; 32823 u(r, p) || (m = r, r = p, p = m); 32824 u(q, y) || (m = q, q = y, y = m); 32825 u(r, q) || (m = r, r = q, q = m, m = p, p = y, y = m); 32826 u(q, p) ? u(p, y) ? (m = v(r, q, p), w = v(q, p, y), 0 > m + w && (m = - m, w = - w), l.b = A(m, q.b, w, p.b)) : (m = x(r, q, p), w = - x(r, y, p), 0 > m + w && (m = - m, w = - w), l.b = A(m, q.b, w, y.b)) : l.b = (q.b + p.b) / 2; 32827 z(r, p) || (m = r, r = p, p = m); 32828 z(q, y) || (m = q, q = y, y = m); 32829 z(r, q) || (m = r, r = q, q = m, m = p, p = y, y = m); 32830 z(q, p) ? z(p, y) ? (m = aa(r, q, p), w = aa(q, p, y), 0 > m + w && (m = - m, w = - w), l.a = A(m, q.a, w, p.a)) : (m = ba(r, q, p), w = - ba(r, y, p), 0 > m + w && (m = - m, w = - w), l.a = A(m, q.a, w, y.a)) : l.a = (q.a + p.a) / 2; 32831 u(l, a.a) && (l.b = a.a.b, l.a = a.a.a); 32832 r = u(f, g) ? f : g; 32833 u(r, l) && (l.b = r.b, l.a = r.a); 32834 if (t(l, f) || t(l, g)) return qa(a, b), 32835 !1; 32836 if (!t(h, a.a) && 0 <= x(h, a.a, l) || !t(k, a.a) && 0 >= x(k, a.a, l)) { 32837 if (k === a.a) return K(d.b), 32838 E(e.b, d), 32839 b = ka(b), 32840 d = S(b).a, 32841 T(a, S(b), c), 32842 U(a, b, J(d), d, d, !0), 32843 !0; 32844 if (h === a.a) { 32845 K(e.b); 32846 E(d.e, J(e)); 32847 f = c = b; 32848 g = f.a.b.a; 32849 do f = R(f); 32850 while (f.a.b.a === g); 32851 b = f; 32852 f = S(b).a.b.c; 32853 c.a = J(e); 32854 e = T(a, c, null); 32855 U(a, b, e.c, d.b.c, f, !0); 32856 return !0; 32857 } 32858 0 <= x(h, a.a, l) && (R(b).b = b.b = !0, K(d.b), d.a.b = a.a.b, d.a.a = a.a.a); 32859 0 >= x(k, a.a, l) && (b.b = c.b = !0, K(e.b), e.a.b = a.a.b, e.a.a = a.a.a); 32860 return !1; 32861 } 32862 K(d.b); 32863 K(e.b); 32864 E(J(e), d); 32865 d.a.b = l.b; 32866 d.a.a = l.a; 32867 d.a.h = xa(a.e, d.a); 32868 d = d.a; 32869 e = [ 32870 0, 32871 0, 32872 0, 32873 0 32874 ]; 32875 l = [ 32876 f.d, 32877 h.d, 32878 g.d, 32879 k.d 32880 ]; 32881 d.g[0] = d.g[1] = d.g[2] = 0; 32882 ua(d, f, h, e, 0); 32883 ua(d, g, k, e, 2); 32884 sa(a, d, l, e, !0); 32885 R(b).b = b.b = c.b = !0; 32886 return !1; 32887 } 32888 function ra(a, b) { 32889 for (var c = S(b); ; ) { 32890 for (; c.b; ) b = c, 32891 c = S(c); 32892 if (!b.b && (c = b, b = R(b), null === b || !b.b)) break; 32893 b.b = !1; 32894 var d = b.a, 32895 e = c.a, 32896 f; 32897 if (f = d.b.a !== e.b.a) a: { 32898 f = b; 32899 var g = S(f), 32900 h = f.a, 32901 k = g.a, 32902 l = void 0; 32903 if (u(h.b.a, k.b.a)) { 32904 if (0 > x(h.b.a, k.b.a, h.a)) { 32905 f = !1; 32906 break a; 32907 } 32908 R(f).b = f.b = !0; 32909 l = K(h); 32910 E(k.b, l); 32911 l.d.c = f.d; 32912 } else { 32913 if (0 < x(k.b.a, h.b.a, k.a)) { 32914 f = !1; 32915 break a; 32916 } 32917 f.b = g.b = !0; 32918 l = K(k); 32919 E(h.e, k.b); 32920 l.b.d.c = f.d; 32921 } 32922 f = !0; 32923 } 32924 f && (c.c ? (Q(c), I(e), c = S(b), e = c.a) : b.c && (Q(b), I(d), b = R(c), d = b.a)); 32925 if (d.a !== e.a) if (d.b.a === e.b.a || b.c || c.c || d.b.a !== a.a && e.b.a !== a.a) qa(a, b); 32926 else if (wa(a, b)) break; 32927 d.a === e.a && d.b.a === e.b.a && (P(e, d), Q(b), I(d), b = R(c)); 32928 } 32929 } 32930 function ya(a, b) { 32931 a.a = b; 32932 for (var c = b.c; null === c.i; ) if (c = c.c, c === b.c) { 32933 var c = a, 32934 d = b, 32935 e = new ma(); 32936 e.a = d.c.b; 32937 var f = c.f, 32938 g = f.a; 32939 do g = g.a; 32940 while (null !== g.b && !f.c(f.b, e, g.b)); 32941 var f = g.b, 32942 h = S(f), 32943 e = f.a, 32944 g = h.a; 32945 if (0 === x(e.b.a, d, e.a)) e = f.a, 32946 t(e.a, d) || t(e.b.a, d) || (K(e.b), f.c && (I(e.c), f.c = !1), E(d.c, e), ya(c, d)); 32947 else { 32948 var k = u(g.b.a, e.b.a) ? f : h, 32949 h = void 0; 32950 f.d || k.c ? (k === f ? h = L(d.c.b, e.e) : h = L(g.b.c.b, d.c).b, k.c ? ja(k, h) : (e = c, f = la(c, f, h), f.f = R(f).f + f.a.f, f.d = oa(e, f.f)), ya(c, d)) : U(c, f, d.c, d.c, null, !0); 32951 } 32952 return; 32953 } 32954 c = ka(c.i); 32955 e = S(c); 32956 f = e.a; 32957 e = T(a, e, null); 32958 if (e.c === f) { 32959 var f = e, 32960 e = f.c, 32961 g = S(c), 32962 h = c.a, 32963 k = g.a, 32964 l = !1; 32965 h.b.a !== k.b.a && wa(a, c); 32966 t(h.a, a.a) && (E(J(e), h), c = ka(c), e = S(c).a, T(a, S(c), g), l = !0); 32967 t(k.a, a.a) && (E(f, J(k)), f = T(a, g, null), l = !0); 32968 l ? U(a, c, f.c, e, e, !0) : (u(k.a, h.a) ? d = J(k) : d = h, d = L(f.c.b, d), U(a, c, d, d.c, d.c, !1), d.b.i.c = !0, ra(a, c)); 32969 } else U(a, c, e.c, f, f, !0); 32970 } 32971 function za(a, b) { 32972 var c = new ma(), 32973 d = ea(a.b); 32974 d.a.b = O; 32975 d.a.a = b; 32976 d.b.a.b = - O; 32977 d.b.a.a = b; 32978 a.a = d.b.a; 32979 c.a = d; 32980 c.f = 0; 32981 c.d = !1; 32982 c.c = !1; 32983 c.h = !0; 32984 c.b = !1; 32985 d = a.f; 32986 d = na(d, d.a, c); 32987 c.e = d; 32988 } 32989 ; 32990 function Aa(a) { 32991 this.a = new Ba(); 32992 this.b = a; 32993 this.c = ia; 32994 } 32995 function na(a, b, c) { 32996 do b = b.c; 32997 while (null !== b.b && !a.c(a.b, b.b, c)); 32998 a = new Ba(c, b.a, b); 32999 b.a.c = a; 33000 return b.a = a; 33001 } 33002 ; 33003 function Ba(a, b, c) { 33004 this.b = a || null; 33005 this.a = b || this; 33006 this.c = c || this; 33007 } 33008 ; 33009 function X() { 33010 this.d = Y; 33011 this.p = this.b = this.q = null; 33012 this.j = [ 33013 0, 33014 0, 33015 0 33016 ]; 33017 this.s = 100130; 33018 this.n = !1; 33019 this.o = this.a = this.e = this.f = null; 33020 this.m = !1; 33021 this.c = this.r = this.i = this.k = this.l = this.h = null; 33022 } 33023 var Y = 0; 33024 n = X.prototype; 33025 n.x = function () { 33026 Z(this, Y); 33027 }; 33028 n.B = function (a, b) { 33029 switch (a) { 33030 case 100142: 33031 return; 33032 case 100140: 33033 switch (b) { 33034 case 100130: 33035 case 100131: 33036 case 100132: 33037 case 100133: 33038 case 100134: 33039 this.s = b; 33040 return; 33041 } 33042 break; 33043 case 100141: 33044 this.m = !!b; 33045 return; 33046 default: 33047 V(this, 100900); 33048 return; 33049 } 33050 V(this, 100901); 33051 }; 33052 n.y = function (a) { 33053 switch (a) { 33054 case 100142: 33055 return 0; 33056 case 100140: 33057 return this.s; 33058 case 100141: 33059 return this.m; 33060 default: 33061 V(this, 100900); 33062 } 33063 return !1; 33064 }; 33065 n.A = function (a, b, c) { 33066 this.j[0] = a; 33067 this.j[1] = b; 33068 this.j[2] = c; 33069 }; 33070 n.z = function (a, b) { 33071 var c = b ? b : null; 33072 switch (a) { 33073 case 100100: 33074 case 100106: 33075 this.h = c; 33076 break; 33077 case 100104: 33078 case 100110: 33079 this.l = c; 33080 break; 33081 case 100101: 33082 case 100107: 33083 this.k = c; 33084 break; 33085 case 100102: 33086 case 100108: 33087 this.i = c; 33088 break; 33089 case 100103: 33090 case 100109: 33091 this.p = c; 33092 break; 33093 case 100105: 33094 case 100111: 33095 this.o = c; 33096 break; 33097 case 100112: 33098 this.r = c; 33099 break; 33100 default: 33101 V(this, 100900); 33102 } 33103 }; 33104 n.C = function (a, b) { 33105 var c = !1, 33106 d = [ 33107 0, 33108 0, 33109 0 33110 ]; 33111 Z(this, 2); 33112 for (var e = 0; 3 > e; ++e) { 33113 var f = a[e]; 33114 - 1e+150 > f && (f = - 1e+150, c = !0); 33115 1e+150 < f && (f = 1e+150, c = !0); 33116 d[e] = f; 33117 } 33118 c && V(this, 100155); 33119 c = this.q; 33120 null === c ? (c = ea(this.b), E(c, c.b)) : (K(c), c = c.e); 33121 c.a.d = b; 33122 c.a.g[0] = d[0]; 33123 c.a.g[1] = d[1]; 33124 c.a.g[2] = d[2]; 33125 c.f = 1; 33126 c.b.f = - 1; 33127 this.q = c; 33128 }; 33129 n.u = function (a) { 33130 Z(this, Y); 33131 this.d = 1; 33132 this.b = new Ca(); 33133 this.c = a; 33134 }; 33135 n.t = function () { 33136 Z(this, 1); 33137 this.d = 2; 33138 this.q = null; 33139 }; 33140 n.v = function () { 33141 Z(this, 2); 33142 this.d = 1; 33143 }; 33144 n.w = function () { 33145 Z(this, 1); 33146 this.d = Y; 33147 var a = this.j[0], 33148 b = this.j[1], 33149 c = this.j[2], 33150 d = !1, 33151 e = [ 33152 a, 33153 b, 33154 c 33155 ]; 33156 if (0 === a && 0 === b && 0 === c) { 33157 for (var b = [ 33158 - 2 * 1e+150, 33159 - 2 * 1e+150, 33160 - 2 * 1e+150 33161 ], f = [ 33162 2 * 1e+150, 33163 2 * 1e+150, 33164 2 * 1e+150 33165 ], c = [ 33166 ], g = [ 33167 ], d = this.b.c, a = d.e; a !== d; a = a.e) for (var h = 0; 3 > h; ++h) { 33168 var k = a.g[h]; 33169 k < f[h] && (f[h] = k, g[h] = a); 33170 k > b[h] && (b[h] = k, c[h] = a); 33171 } 33172 a = 0; 33173 b[1] - f[1] > b[0] - f[0] && (a = 1); 33174 b[2] - f[2] > b[a] - f[a] && (a = 2); 33175 if (f[a] >= b[a]) e[0] = 0, 33176 e[1] = 0, 33177 e[2] = 1; 33178 else { 33179 b = 0; 33180 f = g[a]; 33181 c = c[a]; 33182 g = [ 33183 0, 33184 0, 33185 0 33186 ]; 33187 f = [ 33188 f.g[0] - c.g[0], 33189 f.g[1] - c.g[1], 33190 f.g[2] - c.g[2] 33191 ]; 33192 h = [ 33193 0, 33194 0, 33195 0 33196 ]; 33197 for (a = d.e; a !== d; a = a.e) h[0] = a.g[0] - c.g[0], 33198 h[1] = a.g[1] - c.g[1], 33199 h[2] = a.g[2] - c.g[2], 33200 g[0] = f[1] * h[2] - f[2] * h[1], 33201 g[1] = f[2] * h[0] - f[0] * h[2], 33202 g[2] = f[0] * h[1] - f[1] * h[0], 33203 k = g[0] * g[0] + g[1] * g[1] + g[2] * g[2], 33204 k > b && (b = k, e[0] = g[0], e[1] = g[1], e[2] = g[2]); 33205 0 >= b && (e[0] = e[1] = e[2] = 0, e[ha(f)] = 1); 33206 } 33207 d = !0; 33208 } 33209 g = ha(e); 33210 a = this.b.c; 33211 b = (g + 1) % 3; 33212 c = (g + 2) % 3; 33213 g = 0 < e[g] ? 1 : - 1; 33214 for (e = a.e; e !== a; e = e.e) e.b = e.g[b], 33215 e.a = g * e.g[c]; 33216 if (d) { 33217 e = 0; 33218 d = this.b.a; 33219 for (a = d.b; a !== d; a = a.b) if (b = a.a, !(0 >= b.f)) { 33220 do e += (b.a.b - b.b.a.b) * (b.a.a + b.b.a.a), 33221 b = b.e; 33222 while (b !== a.a); 33223 } 33224 if (0 > e) for (e = this.b.c, d = e.e; d !== e; d = d.e) d.a = - d.a; 33225 } 33226 this.n = !1; 33227 e = this.b.b; 33228 for (a = e.h; a !== e; a = d) if (d = a.h, b = a.e, t(a.a, a.b.a) && a.e.e !== a && (ta(this, b, a), I(a), a = b, b = a.e), b.e === a) { 33229 if (b !== a) { 33230 if (b === d || b === d.b) d = d.h; 33231 I(b); 33232 } 33233 if (a === d || a === d.b) d = d.h; 33234 I(a); 33235 } 33236 this.e = e = new Da(); 33237 d = this.b.c; 33238 for (a = d.e; a !== d; a = a.e) a.h = xa(e, a); 33239 Ea(e); 33240 this.f = new Aa(this); 33241 za(this, - O); 33242 for (za(this, O); null !== (e = Fa(this.e)); ) { 33243 for (; ; ) { 33244 a: if (a = this.e, 0 === a.a) d = Ga(a.b); 33245 else if (d = a.c[a.d[a.a - 1]], 0 !== a.b.a && (a = Ga(a.b), u(a, d))) { 33246 d = a; 33247 break a; 33248 } 33249 if (null === d || !t(d, e)) break; 33250 d = Fa(this.e); 33251 ta(this, e.c, d.c); 33252 } 33253 ya(this, e); 33254 } 33255 this.a = this.f.a.a.b.a.a; 33256 for (e = 0; null !== (d = this.f.a.a.b); ) d.h || ++e, 33257 Q(d); 33258 this.f = null; 33259 e = this.e; 33260 e.b = null; 33261 e.d = null; 33262 this.e = e.c = null; 33263 e = this.b; 33264 for (a = e.a.b; a !== e.a; a = d) d = a.b, 33265 a = a.a, 33266 a.e.e === a && (P(a.c, a), I(a)); 33267 if (!this.n) { 33268 e = this.b; 33269 if (this.m) for (a = e.b.h; a !== e.b; a = d) d = a.h, 33270 a.b.d.c !== a.d.c ? a.f = a.d.c ? 1 : - 1 : I(a); 33271 else for (a = e.a.b; a !== e.a; a = d) if (d = a.b, a.c) { 33272 for (a = a.a; u(a.b.a, a.a); a = a.c.b); 33273 for (; u(a.a, a.b.a); a = a.e); 33274 b = a.c.b; 33275 for (c = void 0; a.e !== b; ) if (u(a.b.a, b.a)) { 33276 for (; b.e !== a && (ca(b.e) || 0 >= x(b.a, b.b.a, b.e.b.a)); ) c = L(b.e, b), 33277 b = c.b; 33278 b = b.c.b; 33279 } else { 33280 for (; b.e !== a && (da(a.c.b) || 0 <= x(a.b.a, a.a, a.c.b.a)); ) c = L(a, a.c.b), 33281 a = c.b; 33282 a = a.e; 33283 } 33284 for (; b.e.e !== a; ) c = L(b.e, b), 33285 b = c.b; 33286 } 33287 if (this.h || this.i || this.k || this.l) if (this.m) for (e = this.b, d = e.a.b; d !== e.a; d = d.b) { 33288 if (d.c) { 33289 this.h && this.h(2, this.c); 33290 a = d.a; 33291 do this.k && this.k(a.a.d, this.c), 33292 a = a.e; 33293 while (a !== d.a); 33294 this.i && this.i(this.c); 33295 } 33296 } else { 33297 e = this.b; 33298 d = !!this.l; 33299 a = !1; 33300 b = - 1; 33301 for (c = e.a.d; c !== e.a; c = c.d) if (c.c) { 33302 a || (this.h && this.h(4, this.c), a = !0); 33303 g = c.a; 33304 do d && (f = g.b.d.c ? 0 : 1, b !== f && (b = f, this.l && this.l(!!b, this.c))), 33305 this.k && this.k(g.a.d, this.c), 33306 g = g.e; 33307 while (g !== c.a); 33308 } 33309 a && this.i && this.i(this.c); 33310 } 33311 if (this.r) { 33312 e = this.b; 33313 for (a = e.a.b; a !== e.a; a = d) if (d = a.b, !a.c) { 33314 b = a.a; 33315 c = b.e; 33316 g = void 0; 33317 do g = c, 33318 c = g.e, 33319 g.d = null, 33320 null === g.b.d && (g.c === g ? F(g.a, null) : (g.a.c = g.c, H(g, J(g))), f = g.b, f.c === f ? F(f.a, null) : (f.a.c = f.c, H(f, J(f))), fa(g)); 33321 while (g !== b); 33322 b = a.d; 33323 a = a.b; 33324 a.d = b; 33325 b.b = a; 33326 } 33327 this.r(this.b); 33328 this.c = this.b = null; 33329 return; 33330 } 33331 } 33332 this.b = this.c = null; 33333 }; 33334 function Z(a, b) { 33335 if (a.d !== b) for (; a.d !== b; ) if (a.d < b) switch (a.d) { 33336 case Y: 33337 V(a, 1
3333700151); 33338 a.u(null); 33339 break; 33340 case 1: 33341 V(a, 100152), 33342 a.t(); 33343 } else switch (a.d) { 33344 case 2: 33345 V(a, 100154); 33346 a.v(); 33347 break; 33348 case 1: 33349 V(a, 100153), 33350 a.w(); 33351 } 33352 } 33353 function V(a, b) { 33354 a.p && a.p(b, a.c); 33355 } 33356 ; 33357 function ga(a, b) { 33358 this.b = a || this; 33359 this.d = b || this; 33360 this.a = null; 33361 this.c = !1; 33362 } 33363 ; 33364 function M() { 33365 this.h = this; 33366 this.i = this.d = this.a = this.e = this.c = this.b = null; 33367 this.f = 0; 33368 } 33369 function J(a) { 33370 return a.b.e; 33371 } 33372 ; 33373 function Ca() { 33374 this.c = new N(); 33375 this.a = new ga(); 33376 this.b = new M(); 33377 this.d = new M(); 33378 this.b.b = this.d; 33379 this.d.b = this.b; 33380 } 33381 ; 33382 function N(a, b) { 33383 this.e = a || this; 33384 this.f = b || this; 33385 this.d = this.c = null; 33386 this.g = [ 33387 0, 33388 0, 33389 0 33390 ]; 33391 this.h = this.a = this.b = 0; 33392 } 33393 ; 33394 function Da() { 33395 this.c = [ 33396 ]; 33397 this.d = null; 33398 this.a = 0; 33399 this.e = !1; 33400 this.b = new Ha(); 33401 } 33402 function Ea(a) { 33403 a.d = [ 33404 ]; 33405 for (var b = 0; b < a.a; b++) a.d[b] = b; 33406 a.d.sort(function (a) { 33407 return function (b, e) { 33408 return u(a[b], a[e]) ? 1 : - 1; 33409 }; 33410 }(a.c)); 33411 a.e = !0; 33412 Ia(a.b); 33413 } 33414 function xa(a, b) { 33415 if (a.e) { 33416 var c = a.b, 33417 d = ++c.a; 33418 2 * d > c.f && (c.f *= 2, c.c = Ja(c.c, c.f + 1)); 33419 var e; 33420 0 === c.b ? e = d : (e = c.b, c.b = c.c[c.b]); 33421 c.e[e] = b; 33422 c.c[e] = d; 33423 c.d[d] = e; 33424 c.h && va(c, d); 33425 return e; 33426 } 33427 c = a.a++; 33428 a.c[c] = b; 33429 return - (c + 1); 33430 } 33431 function Fa(a) { 33432 if (0 === a.a) return Ka(a.b); 33433 var b = a.c[a.d[a.a - 1]]; 33434 if (0 !== a.b.a && u(Ga(a.b), b)) return Ka(a.b); 33435 do --a.a; 33436 while (0 < a.a && null === a.c[a.d[a.a - 1]]); 33437 return b; 33438 } 33439 ; 33440 function Ha() { 33441 this.d = Ja([0], 33); 33442 this.e = [ 33443 null, 33444 null 33445 ]; 33446 this.c = [ 33447 0, 33448 0 33449 ]; 33450 this.a = 0; 33451 this.f = 32; 33452 this.b = 0; 33453 this.h = !1; 33454 this.d[1] = 1; 33455 } 33456 function Ja(a, b) { 33457 for (var c = Array(b), d = 0; d < a.length; d++) c[d] = a[d]; 33458 for (; d < b; d++) c[d] = 0; 33459 return c; 33460 } 33461 function Ia(a) { 33462 for (var b = a.a; 1 <= b; --b) W(a, b); 33463 a.h = !0; 33464 } 33465 function Ga(a) { 33466 return a.e[a.d[1]]; 33467 } 33468 function Ka(a) { 33469 var b = a.d, 33470 c = a.e, 33471 d = a.c, 33472 e = b[1], 33473 f = c[e]; 33474 0 < a.a && (b[1] = b[a.a], d[b[1]] = 1, c[e] = null, d[e] = a.b, a.b = e, 0 < --a.a && W(a, 1)); 33475 return f; 33476 } 33477 function W(a, b) { 33478 for (var c = a.d, d = a.e, e = a.c, f = b, g = c[f]; ; ) { 33479 var h = f << 1; 33480 h < a.a && u(d[c[h + 1]], d[c[h]]) && (h += 1); 33481 var k = c[h]; 33482 if (h > a.a || u(d[g], d[k])) { 33483 c[f] = g; 33484 e[g] = f; 33485 break; 33486 } 33487 c[f] = k; 33488 e[k] = f; 33489 f = h; 33490 } 33491 } 33492 function va(a, b) { 33493 for (var c = a.d, d = a.e, e = a.c, f = b, g = c[f]; ; ) { 33494 var h = f >> 1, 33495 k = c[h]; 33496 if (0 === h || u(d[k], d[g])) { 33497 c[f] = g; 33498 e[g] = f; 33499 break; 33500 } 33501 c[f] = k; 33502 e[k] = f; 33503 f = h; 33504 } 33505 } 33506 ; 33507 function ma() { 33508 this.e = this.a = null; 33509 this.f = 0; 33510 this.c = this.b = this.h = this.d = !1; 33511 } 33512 function S(a) { 33513 return a.e.c.b; 33514 } 33515 function R(a) { 33516 return a.e.a.b; 33517 } 33518 ; 33519 this.libtess = { 33520 GluTesselator: X, 33521 windingRule: { 33522 GLU_TESS_WINDING_ODD: 100130, 33523 GLU_TESS_WINDING_NONZERO: 100131, 33524 GLU_TESS_WINDING_POSITIVE: 100132, 33525 GLU_TESS_WINDING_NEGATIVE: 100133, 33526 GLU_TESS_WINDING_ABS_GEQ_TWO: 100134 33527 }, 33528 primitiveType: { 33529 GL_LINE_LOOP: 2, 33530 GL_TRIANGLES: 4, 33531 GL_TRIANGLE_STRIP: 5, 33532 GL_TRIANGLE_FAN: 6 33533 }, 33534 errorType: { 33535 GLU_TESS_MISSING_BEGIN_POLYGON: 100151, 33536 GLU_TESS_MISSING_END_POLYGON: 100153,
33537 GLU_TESS_MISSING_BEGIN_CONTOUR: 100152, 33538 GLU_TESS_MISSING_END_CONTOUR: 100154, 33539 GLU_TESS_COORD_TOO_LARGE: 100155, 33540 GLU_TESS_NEED_COMBINE_CALLBACK: 100156 33541 }, 33542 gluEnum: { 33543 GLU_TESS_MESH: 100112, 33544 GLU_TESS_TOLERANCE: 100142, 33545 GLU_TESS_WINDING_RULE: 100140, 33546 GLU_TESS_BOUNDARY_ONLY: 100141, 33547 GLU_INVALID_ENUM: 100900, 33548 GLU_INVALID_VALUE: 100901, 33549 GLU_TESS_BEGIN: 100100, 33550 GLU_TESS_VERTEX: 100101, 33551 GLU_TESS_END: 100102, 33552 GLU_TESS_ERROR: 100103, 33553 GLU_TESS_EDGE_FLAG: 100104, 33554 GLU_TESS_COMBINE: 100105, 33555 GLU_TESS_BEGIN_DATA: 100106, 33556 GLU_TESS_VERTEX_DATA: 100107, 33557 GLU_TESS_END_DATA: 100108, 33558 GLU_TESS_ERROR_DATA: 100109, 33559 GLU_TESS_EDGE_FLAG_DATA: 100110, 33560 GLU_TESS_COMBINE_DATA: 100111 33561 } 33562 }; 33563 X.prototype.gluDeleteTess = X.prototype.x; 33564 X.prototype.gluTessProperty = X.prototype.B; 33565 X.prototype.gluGetTessProperty = X.prototype.y; 33566 X.prototype.gluTessNormal = X.prototype.A; 33567 X.prototype.gluTessCallback = X.prototype.z; 33568 X.prototype.gluTessVertex = X.prototype.C; 33569 X.prototype.gluTessBeginPolygon = X.prototype.u; 33570 X.prototype.gluTessBeginContour = X.prototype.t; 33571 X.prototype.gluTessEndContour = X.prototype.v; 33572 X.prototype.gluTessEndPolygon = X.prototype.w; 33573 if (typeof module !== 'undefined') { 33574 module.exports = this.libtess; 33575 } 33576 }, 33577 { 33578 } 33579 ], 33580 262: [ 33581 function (_dereq_, module, exports) { 33582 // (c) Dean McNamee <[email protected]>, 2013. 33583 // 33584 // https://github.com/deanm/omggif 33585 // 33586 // Permission is hereby granted, free of charge, to any person obtaining a copy 33587 // of this software and associated documentation files (the "Software"), to 33588 // deal in the Software without restriction, including without limitation the 33589 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 33590 // sell copies of the Software, and to permit persons to whom the Software is 33591 // furnished to do so, subject to the following conditions: 33592 // 33593 // The above copyright notice and this permission notice shall be included in 33594 // all copies or substantial portions of the Software. 33595 // 33596 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33597 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33598 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33599 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33600 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33601 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 33602 // IN THE SOFTWARE. 33603 // 33604 // omggif is a JavaScript implementation of a GIF 89a encoder and decoder, 33605 // including animation and compression. It does not rely on any specific 33606 // underlying system, so should run in the browser, Node, or Plask. 33607 'use strict'; 33608 function GifWriter(buf, width, height, gopts) { 33609 var p = 0; 33610 var gopts = gopts === undefined ? { 33611 } 33612 : gopts; 33613 var loop_count = gopts.loop === undefined ? null : gopts.loop; 33614 var global_palette = gopts.palette === undefined ? null : gopts.palette; 33615 if (width <= 0 || height <= 0 || width > 65535 || height > 65535) throw new Error('Width/Height invalid.'); 33616 function check_palette_and_num_colors(palette) { 33617 var num_colors = palette.length; 33618 if (num_colors < 2 || num_colors > 256 || num_colors & num_colors - 1) { 33619 throw new Error('Invalid code/color length, must be power of 2 and 2 .. 256.'); 33620 } 33621 return num_colors; 33622 } // - Header. 33623 33624 buf[p++] = 71; 33625 buf[p++] = 73; 33626 buf[p++] = 70; // GIF 33627 buf[p++] = 56; 33628 buf[p++] = 57; 33629 buf[p++] = 97; // 89a 33630 // Handling of Global Color Table (palette) and background index. 33631 var gp_num_colors_pow2 = 0; 33632 var background = 0; 33633 if (global_palette !== null) { 33634 var gp_num_colors = check_palette_and_num_colors(global_palette); 33635 while (gp_num_colors >>= 1) ++gp_num_colors_pow2; 33636 gp_num_colors = 1 << gp_num_colors_pow2;
vendor: 10,504 bytes, lines 33637-33843
33637 --gp_num_colors_pow2; 33638 if (gopts.background !== undefined) { 33639 background = gopts.background; 33640 if (background >= gp_num_colors) throw new Error('Background index out of range.'); // The GIF spec states that a background index of 0 should be ignored, so 33641 // this is probably a mistake and you really want to set it to another 33642 // slot in the palette. But actually in the end most browsers, etc end 33643 // up ignoring this almost completely (including for dispose background). 33644 if (background === 0) throw new Error('Background index explicitly passed as 0.'); 33645 } 33646 } // - Logical Screen Descriptor. 33647 // NOTE(deanm): w/h apparently ignored by implementations, but set anyway. 33648 33649 buf[p++] = width & 255; 33650 buf[p++] = width >> 8 & 255; 33651 buf[p++] = height & 255; 33652 buf[p++] = height >> 8 & 255; // NOTE: Indicates 0-bpp original color resolution (unused?). 33653 buf[p++] = (global_palette !== null ? 128 : 0) | // Global Color Table Flag. 33654 gp_num_colors_pow2; // NOTE: No sort flag (unused?). 33655 buf[p++] = background; // Background Color Index. 33656 buf[p++] = 0; // Pixel aspect ratio (unused?). 33657 // - Global Color Table 33658 if (global_palette !== null) { 33659 for (var i = 0, il = global_palette.length; i < il; ++i) { 33660 var rgb = global_palette[i]; 33661 buf[p++] = rgb >> 16 & 255; 33662 buf[p++] = rgb >> 8 & 255; 33663 buf[p++] = rgb & 255; 33664 } 33665 } 33666 if (loop_count !== null) { 33667 // Netscape block for looping. 33668 if (loop_count < 0 || loop_count > 65535) throw new Error('Loop count invalid.'); // Extension code, label, and length. 33669 buf[p++] = 33; 33670 buf[p++] = 255; 33671 buf[p++] = 11; // NETSCAPE2.0 33672 buf[p++] = 78; 33673 buf[p++] = 69; 33674 buf[p++] = 84; 33675 buf[p++] = 83; 33676 buf[p++] = 67; 33677 buf[p++] = 65; 33678 buf[p++] = 80; 33679 buf[p++] = 69; 33680 buf[p++] = 50; 33681 buf[p++] = 46; 33682 buf[p++] = 48; // Sub-block 33683 buf[p++] = 3; 33684 buf[p++] = 1; 33685 buf[p++] = loop_count & 255; 33686 buf[p++] = loop_count >> 8 & 255; 33687 buf[p++] = 0; // Terminator. 33688 } 33689 var ended = false; 33690 this.addFrame = function (x, y, w, h, indexed_pixels, opts) { 33691 if (ended === true) { 33692 --p; 33693 ended = false; 33694 } // Un-end. 33695 33696 opts = opts === undefined ? { 33697 } 33698 : opts; // TODO(deanm): Bounds check x, y. Do they need to be within the virtual 33699 // canvas width/height, I imagine? 33700 if (x < 0 || y < 0 || x > 65535 || y > 65535) throw new Error('x/y invalid.'); 33701 if (w <= 0 || h <= 0 || w > 65535 || h > 65535) throw new Error('Width/Height invalid.'); 33702 if (indexed_pixels.length < w * h) throw new Error('Not enough pixels for the frame size.'); 33703 var using_local_palette = true; 33704 var palette = opts.palette; 33705 if (palette === undefined || palette === null) { 33706 using_local_palette = false; 33707 palette = global_palette; 33708 } 33709 if (palette === undefined || palette === null) throw new Error('Must supply either a local or global palette.'); 33710 var num_colors = check_palette_and_num_colors(palette); // Compute the min_code_size (power of 2), destroying num_colors. 33711 var min_code_size = 0; 33712 while (num_colors >>= 1) ++min_code_size; 33713 num_colors = 1 << min_code_size; // Now we can easily get it back. 33714 var delay = opts.delay === undefined ? 0 : opts.delay; // From the spec: 33715 // 0 - No disposal specified. The decoder is 33716 // not required to take any action. 33717 // 1 - Do not dispose. The graphic is to be left 33718 // in place. 33719 // 2 - Restore to background color. The area used by the 33720 // graphic must be restored to the background color. 33721 // 3 - Restore to previous. The decoder is required to 33722 // restore the area overwritten by the graphic with 33723 // what was there prior to rendering the graphic. 33724 // 4-7 - To be defined. 33725 // NOTE(deanm): Dispose background doesn't really work, apparently most 33726 // browsers ignore the background palette index and clear to transparency. 33727 var disposal = opts.disposal === undefined ? 0 : opts.disposal; 33728 if (disposal < 0 || disposal > 3) // 4-7 is reserved. 33729 throw new Error('Disposal out of range.'); 33730 var use_transparency = false; 33731 var transparent_index = 0; 33732 if (opts.transparent !== undefined && opts.transparent !== null) { 33733 use_transparency = true; 33734 transparent_index = opts.transparent; 33735 if (transparent_index < 0 || transparent_index >= num_colors) throw new Error('Transparent color index.'); 33736 } 33737 if (disposal !== 0 || use_transparency || delay !== 0) { 33738 // - Graphics Control Extension 33739 buf[p++] = 33; 33740 buf[p++] = 249; // Extension / Label. 33741 buf[p++] = 4; // Byte size. 33742 buf[p++] = disposal << 2 | (use_transparency === true ? 1 : 0); 33743 buf[p++] = delay & 255; 33744 buf[p++] = delay >> 8 & 255; 33745 buf[p++] = transparent_index; // Transparent color index. 33746 buf[p++] = 0; // Block Terminator. 33747 } // - Image Descriptor 33748 33749 buf[p++] = 44; // Image Seperator. 33750 buf[p++] = x & 255; 33751 buf[p++] = x >> 8 & 255; // Left. 33752 buf[p++] = y & 255; 33753 buf[p++] = y >> 8 & 255; // Top. 33754 buf[p++] = w & 255; 33755 buf[p++] = w >> 8 & 255; 33756 buf[p++] = h & 255; 33757 buf[p++] = h >> 8 & 255; // NOTE: No sort flag (unused?). 33758 // TODO(deanm): Support interlace. 33759 buf[p++] = using_local_palette === true ? 128 | min_code_size - 1 : 0; // - Local Color Table 33760 if (using_local_palette === true) { 33761 for (var i = 0, il = palette.length; i < il; ++i) { 33762 var rgb = palette[i]; 33763 buf[p++] = rgb >> 16 & 255; 33764 buf[p++] = rgb >> 8 & 255; 33765 buf[p++] = rgb & 255; 33766 } 33767 } 33768 p = GifWriterOutputLZWCodeStream(buf, p, min_code_size < 2 ? 2 : min_code_size, indexed_pixels); 33769 return p; 33770 }; 33771 this.end = function () { 33772 if (ended === false) { 33773 buf[p++] = 59; // Trailer. 33774 ended = true; 33775 } 33776 return p; 33777 }; 33778 this.getOutputBuffer = function () { 33779 return buf; 33780 }; 33781 this.setOutputBuffer = function (v) { 33782 buf = v; 33783 }; 33784 this.getOutputBufferPosition = function () { 33785 return p; 33786 }; 33787 this.setOutputBufferPosition = function (v) { 33788 p = v; 33789 }; 33790 } // Main compression routine, palette indexes -> LZW code stream. 33791 // |index_stream| must have at least one entry. 33792 33793 function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) { 33794 buf[p++] = min_code_size; 33795 var cur_subblock = p++; // Pointing at the length field. 33796 var clear_code = 1 << min_code_size; 33797 var code_mask = clear_code - 1; 33798 var eoi_code = clear_code + 1; 33799 var next_code = eoi_code + 1; 33800 var cur_code_size = min_code_size + 1; // Number of bits per code. 33801 var cur_shift = 0; // We have at most 12-bit codes, so we should have to hold a max of 19 33802 // bits here (and then we would write out). 33803 var cur = 0; 33804 function emit_bytes_to_buffer(bit_block_size) { 33805 while (cur_shift >= bit_block_size) { 33806 buf[p++] = cur & 255; 33807 cur >>= 8; 33808 cur_shift -= 8; 33809 if (p === cur_subblock + 256) { 33810 // Finished a subblock. 33811 buf[cur_subblock] = 255; 33812 cur_subblock = p++; 33813 } 33814 } 33815 } 33816 function emit_code(c) { 33817 cur |= c << cur_shift; 33818 cur_shift += cur_code_size; 33819 emit_bytes_to_buffer(8); 33820 } // I am not an expert on the topic, and I don't want to write a thesis. 33821 // However, it is good to outline here the basic algorithm and the few data 33822 // structures and optimizations here that make this implementation fast. 33823 // The basic idea behind LZW is to build a table of previously seen runs 33824 // addressed by a short id (herein called output code). All data is 33825 // referenced by a code, which represents one or more values from the 33826 // original input stream. All input bytes can be referenced as the same 33827 // value as an output code. So if you didn't want any compression, you 33828 // could more or less just output the original bytes as codes (there are 33829 // some details to this, but it is the idea). In order to achieve 33830 // compression, values greater then the input range (codes can be up to 33831 // 12-bit while input only 8-bit) represent a sequence of previously seen 33832 // inputs. The decompressor is able to build the same mapping while 33833 // decoding, so there is always a shared common knowledge between the 33834 // encoding and decoder, which is also important for "timing" aspects like 33835 // how to handle variable bit width code encoding. 33836 // 33837 // One obvious but very important consequence of the table system is there 33838 // is always a unique id (at most 12-bits) to map the runs. 'A' might be 33839 // 4, then 'AA' might be 10, 'AAA' 11, 'AAAA' 12, etc. This relationship 33840 // can be used for an effecient lookup strategy for the code mapping. We 33841 // need to know if a run has been seen before, and be able to map that run 33842 // to the output code. Since we start with known unique ids (input bytes), 33843 // and then from those build more unique ids (table entr
vendor: 4,148 bytes, lines 33843-33915
33843ies), we can 33844 // continue this chain (almost like a linked list) to always have small 33845 // integer values that represent the current byte chains in the encoder. 33846 // This means instead of tracking the input bytes (AAAABCD) to know our 33847 // current state, we can track the table entry for AAAABC (it is guaranteed 33848 // to exist by the nature of the algorithm) and the next character D. 33849 // Therefor the tuple of (table_entry, byte) is guaranteed to also be 33850 // unique. This allows us to create a simple lookup key for mapping input 33851 // sequences to codes (table indices) without having to store or search 33852 // any of the code sequences. So if 'AAAA' has a table entry of 12, the 33853 // tuple of ('AAAA', K) for any input byte K will be unique, and can be our 33854 // key. This leads to a integer value at most 20-bits, which can always 33855 // fit in an SMI value and be used as a fast sparse array / object key. 33856 // Output code for the current contents of the index buffer. 33857 33858 var ib_code = index_stream[0] & code_mask; // Load first input index. 33859 var code_table = { 33860 }; // Key'd on our 20-bit "tuple". 33861 emit_code(clear_code); // Spec says first code should be a clear code. 33862 // First index already loaded, process the rest of the stream. 33863 for (var i = 1, il = index_stream.length; i < il; ++i) { 33864 var k = index_stream[i] & code_mask; 33865 var cur_key = ib_code << 8 | k; // (prev, k) unique tuple. 33866 var cur_code = code_table[cur_key]; // buffer + k. 33867 // Check if we have to create a new code table entry. 33868 if (cur_code === undefined) { 33869 // We don't have buffer + k. 33870 // Emit index buffer (without k). 33871 // This is an inline version of emit_code, because this is the core 33872 // writing routine of the compressor (and V8 cannot inline emit_code 33873 // because it is a closure here in a different context). Additionally 33874 // we can call emit_byte_to_buffer less often, because we can have 33875 // 30-bits (from our 31-bit signed SMI), and we know our codes will only 33876 // be 12-bits, so can safely have 18-bits there without overflow. 33877 // emit_code(ib_code); 33878 cur |= ib_code << cur_shift; 33879 cur_shift += cur_code_size; 33880 while (cur_shift >= 8) { 33881 buf[p++] = cur & 255; 33882 cur >>= 8; 33883 cur_shift -= 8; 33884 if (p === cur_subblock + 256) { 33885 // Finished a subblock. 33886 buf[cur_subblock] = 255; 33887 cur_subblock = p++; 33888 } 33889 } 33890 if (next_code === 4096) { 33891 // Table full, need a clear. 33892 emit_code(clear_code); 33893 next_code = eoi_code + 1; 33894 cur_code_size = min_code_size + 1; 33895 code_table = { 33896 }; 33897 } else { 33898 // Table not full, insert a new entry. 33899 // Increase our variable bit code sizes if necessary. This is a bit 33900 // tricky as it is based on "timing" between the encoding and 33901 // decoder. From the encoders perspective this should happen after 33902 // we've already emitted the index buffer and are about to create the 33903 // first table entry that would overflow our current code bit size. 33904 if (next_code >= 1 << cur_code_size) ++cur_code_size; 33905 code_table[cur_key] = next_code++; // Insert into code table. 33906 } 33907 ib_code = k; // Index buffer to single input k. 33908 } else { 33909 ib_code = cur_code; // Index buffer to sequence in code table. 33910 } 33911 } 33912 emit_code(ib_code); // There will still be something in the index buffer. 33913 emit_code(eoi_code); // End Of Information. 33914 // Flush / finalize the sub-blocks stream to the buffer. 33915 emit_bytes_to_buffer(1);
vendor: 5,377 bytes, lines 33915-34023
33915 // Finish the sub-blocks, writing out any unfinished lengths and 33916 // terminating with a sub-block of length 0. If we have already started 33917 // but not yet used a sub-block it can just become the terminator. 33918 if (cur_subblock + 1 === p) { 33919 // Started but unused. 33920 buf[cur_subblock] = 0; 33921 } else { 33922 // Started and used, write length and additional terminator block. 33923 buf[cur_subblock] = p - cur_subblock - 1; 33924 buf[p++] = 0; 33925 } 33926 return p; 33927 } 33928 function GifReader(buf) { 33929 var p = 0; // - Header (GIF87a or GIF89a). 33930 if (buf[p++] !== 71 || buf[p++] !== 73 || buf[p++] !== 70 || buf[p++] !== 56 || (buf[p++] + 1 & 253) !== 56 || buf[p++] !== 97) { 33931 throw new Error('Invalid GIF 87a/89a header.'); 33932 } // - Logical Screen Descriptor. 33933 33934 var width = buf[p++] | buf[p++] << 8; 33935 var height = buf[p++] | buf[p++] << 8; 33936 var pf0 = buf[p++]; // <Packed Fields>. 33937 var global_palette_flag = pf0 >> 7; 33938 var num_global_colors_pow2 = pf0 & 7; 33939 var num_global_colors = 1 << num_global_colors_pow2 + 1; 33940 var background = buf[p++]; 33941 buf[p++]; // Pixel aspect ratio (unused?). 33942 var global_palette_offset = null; 33943 var global_palette_size = null; 33944 if (global_palette_flag) { 33945 global_palette_offset = p; 33946 global_palette_size = num_global_colors; 33947 p += num_global_colors * 3; // Seek past palette. 33948 } 33949 var no_eof = true; 33950 var frames = [ 33951 ]; 33952 var delay = 0; 33953 var transparent_index = null; 33954 var disposal = 0; // 0 - No disposal specified. 33955 var loop_count = null; 33956 this.width = width; 33957 this.height = height; 33958 while (no_eof && p < buf.length) { 33959 switch (buf[p++]) { 33960 case 33: 33961 // Graphics Control Extension Block 33962 switch (buf[p++]) { 33963 case 255: 33964 // Application specific block 33965 // Try if it's a Netscape block (with animation loop counter). 33966 if (buf[p] !== 11 || // 21 FF already read, check block size. 33967 // NETSCAPE2.0 33968 buf[p + 1] == 78 && buf[p + 2] == 69 && buf[p + 3] == 84 && buf[p + 4] == 83 && buf[p + 5] == 67 && buf[p + 6] == 65 && buf[p + 7] == 80 && buf[p + 8] == 69 && buf[p + 9] == 50 && buf[p + 10] == 46 && buf[p + 11] == 48 && // Sub-block 33969 buf[p + 12] == 3 && buf[p + 13] == 1 && buf[p + 16] == 0) { 33970 p += 14; 33971 loop_count = buf[p++] | buf[p++] << 8; 33972 p++; // Skip terminator. 33973 } else { 33974 // We don't know what it is, just try to get past it. 33975 p += 12; 33976 while (true) { 33977 // Seek through subblocks. 33978 var block_size = buf[p++]; // Bad block size (ex: undefined from an out of bounds read). 33979 if (!(block_size >= 0)) throw Error('Invalid block size'); 33980 if (block_size === 0) break; // 0 size is terminator 33981 p += block_size; 33982 } 33983 } 33984 break; 33985 case 249: 33986 // Graphics Control Extension 33987 if (buf[p++] !== 4 || buf[p + 4] !== 0) throw new Error('Invalid graphics extension block.'); 33988 var pf1 = buf[p++]; 33989 delay = buf[p++] | buf[p++] << 8; 33990 transparent_index = buf[p++]; 33991 if ((pf1 & 1) === 0) transparent_index = null; 33992 disposal = pf1 >> 2 & 7; 33993 p++; // Skip terminator. 33994 break; 33995 case 254: 33996 // Comment Extension. 33997 while (true) { 33998 // Seek through subblocks. 33999 var block_size = buf[p++]; // Bad block size (ex: undefined from an out of bounds read). 34000 if (!(block_size >= 0)) throw Error('Invalid block size'); 34001 if (block_size === 0) break; // 0 size is terminator 34002 // console.log(buf.slice(p, p+block_size).toString('ascii')); 34003 p += block_size; 34004 } 34005 break; 34006 default: 34007 throw new Error('Unknown graphic control label: 0x' + buf[p - 1].toString(16)); 34008 } 34009 break; 34010 case 44: 34011 // Image Descriptor. 34012 var x = buf[p++] | buf[p++] << 8; 34013 var y = buf[p++] | buf[p++] << 8; 34014 var w = buf[p++] | buf[p++] << 8; 34015 var h = buf[p++] | buf[p++] << 8; 34016 var pf2 = buf[p++]; 34017 var local_palette_flag = pf2 >> 7; 34018 var interlace_flag = pf2 >> 6 & 1; 34019 var num_local_colors_pow2 = pf2 & 7; 34020 var num_local_colors = 1 << num_local_colors_pow2 + 1; 34021 var palette_offset = global_palette_offset; 34022 var palette_size = global_palette_size; 34023 var has_local_palette = false;
vendor: 13,615 bytes, lines 34024-34277
34024 if (local_palette_flag) { 34025 var has_local_palette = true; 34026 palette_offset = p; // Override with local palette. 34027 palette_size = num_local_colors; 34028 p += num_local_colors * 3; // Seek past palette. 34029 } 34030 var data_offset = p; 34031 p++; // codesize 34032 while (true) { 34033 var block_size = buf[p++]; // Bad block size (ex: undefined from an out of bounds read). 34034 if (!(block_size >= 0)) throw Error('Invalid block size'); 34035 if (block_size === 0) break; // 0 size is terminator 34036 p += block_size; 34037 } 34038 frames.push({ 34039 x: x, 34040 y: y, 34041 width: w, 34042 height: h, 34043 has_local_palette: has_local_palette, 34044 palette_offset: palette_offset, 34045 palette_size: palette_size, 34046 data_offset: data_offset, 34047 data_length: p - data_offset, 34048 transparent_index: transparent_index, 34049 interlaced: !!interlace_flag, 34050 delay: delay, 34051 disposal: disposal 34052 }); 34053 break; 34054 case 59: 34055 // Trailer Marker (end of file). 34056 no_eof = false; 34057 break; 34058 default: 34059 throw new Error('Unknown gif block: 0x' + buf[p - 1].toString(16)); 34060 break; 34061 } 34062 } 34063 this.numFrames = function () { 34064 return frames.length; 34065 }; 34066 this.loopCount = function () { 34067 return loop_count; 34068 }; 34069 this.frameInfo = function (frame_num) { 34070 if (frame_num < 0 || frame_num >= frames.length) throw new Error('Frame index out of range.'); 34071 return frames[frame_num]; 34072 }; 34073 this.decodeAndBlitFrameBGRA = function (frame_num, pixels) { 34074 var frame = this.frameInfo(frame_num); 34075 var num_pixels = frame.width * frame.height; 34076 var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices. 34077 GifReaderLZWOutputIndexStream(buf, frame.data_offset, index_stream, num_pixels); 34078 var palette_offset = frame.palette_offset; // NOTE(deanm): It seems to be much faster to compare index to 256 than 34079 // to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in 34080 // the profile, not sure if it's related to using a Uint8Array. 34081 var trans = frame.transparent_index; 34082 if (trans === null) trans = 256; // We are possibly just blitting to a portion of the entire frame. 34083 // That is a subrect within the framerect, so the additional pixels 34084 // must be skipped over after we finished a scanline. 34085 var framewidth = frame.width; 34086 var framestride = width - framewidth; 34087 var xleft = framewidth; // Number of subrect pixels left in scanline. 34088 // Output indicies of the top left and bottom right corners of the subrect. 34089 var opbeg = (frame.y * width + frame.x) * 4; 34090 var opend = ((frame.y + frame.height) * width + frame.x) * 4; 34091 var op = opbeg; 34092 var scanstride = framestride * 4; // Use scanstride to skip past the rows when interlacing. This is skipping 34093 // 7 rows for the first two passes, then 3 then 1. 34094 if (frame.interlaced === true) { 34095 scanstride += width * 4 * 7; // Pass 1. 34096 } 34097 var interlaceskip = 8; // Tracking the row interval in the current pass. 34098 for (var i = 0, il = index_stream.length; i < il; ++i) { 34099 var index = index_stream[i]; 34100 if (xleft === 0) { 34101 // Beginning of new scan line 34102 op += scanstride; 34103 xleft = framewidth; 34104 if (op >= opend) { 34105 // Catch the wrap to switch passes when interlacing. 34106 scanstride = framestride * 4 + width * 4 * (interlaceskip - 1); // interlaceskip / 2 * 4 is interlaceskip << 1. 34107 op = opbeg + (framewidth + framestride) * (interlaceskip << 1); 34108 interlaceskip >>= 1; 34109 } 34110 } 34111 if (index === trans) { 34112 op += 4; 34113 } else { 34114 var r = buf[palette_offset + index * 3]; 34115 var g = buf[palette_offset + index * 3 + 1]; 34116 var b = buf[palette_offset + index * 3 + 2]; 34117 pixels[op++] = b; 34118 pixels[op++] = g; 34119 pixels[op++] = r; 34120 pixels[op++] = 255; 34121 } 34122 --xleft; 34123 } 34124 }; // I will go to copy and paste hell one day... 34125 this.decodeAndBlitFrameRGBA = function (frame_num, pixels) { 34126 var frame = this.frameInfo(frame_num); 34127 var num_pixels = frame.width * frame.height; 34128 var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices. 34129 GifReaderLZWOutputIndexStream(buf, frame.data_offset, index_stream, num_pixels); 34130 var palette_offset = frame.palette_offset; // NOTE(deanm): It seems to be much faster to compare index to 256 than 34131 // to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in 34132 // the profile, not sure if it's related to using a Uint8Array. 34133 var trans = frame.transparent_index; 34134 if (trans === null) trans = 256; // We are possibly just blitting to a portion of the entire frame. 34135 // That is a subrect within the framerect, so the additional pixels 34136 // must be skipped over after we finished a scanline. 34137 var framewidth = frame.width; 34138 var framestride = width - framewidth; 34139 var xleft = framewidth; // Number of subrect pixels left in scanline. 34140 // Output indicies of the top left and bottom right corners of the subrect. 34141 var opbeg = (frame.y * width + frame.x) * 4; 34142 var opend = ((frame.y + frame.height) * width + frame.x) * 4; 34143 var op = opbeg; 34144 var scanstride = framestride * 4; // Use scanstride to skip past the rows when interlacing. This is skipping 34145 // 7 rows for the first two passes, then 3 then 1. 34146 if (frame.interlaced === true) { 34147 scanstride += width * 4 * 7; // Pass 1. 34148 } 34149 var interlaceskip = 8; // Tracking the row interval in the current pass. 34150 for (var i = 0, il = index_stream.length; i < il; ++i) { 34151 var index = index_stream[i]; 34152 if (xleft === 0) { 34153 // Beginning of new scan line 34154 op += scanstride; 34155 xleft = framewidth; 34156 if (op >= opend) { 34157 // Catch the wrap to switch passes when interlacing. 34158 scanstride = framestride * 4 + width * 4 * (interlaceskip - 1); // interlaceskip / 2 * 4 is interlaceskip << 1. 34159 op = opbeg + (framewidth + framestride) * (interlaceskip << 1); 34160 interlaceskip >>= 1; 34161 } 34162 } 34163 if (index === trans) { 34164 op += 4; 34165 } else { 34166 var r = buf[palette_offset + index * 3]; 34167 var g = buf[palette_offset + index * 3 + 1]; 34168 var b = buf[palette_offset + index * 3 + 2]; 34169 pixels[op++] = r; 34170 pixels[op++] = g; 34171 pixels[op++] = b; 34172 pixels[op++] = 255; 34173 } 34174 --xleft; 34175 } 34176 }; 34177 } 34178 function GifReaderLZWOutputIndexStream(code_stream, p, output, output_length) { 34179 var min_code_size = code_stream[p++]; 34180 var clear_code = 1 << min_code_size; 34181 var eoi_code = clear_code + 1; 34182 var next_code = eoi_code + 1; 34183 var cur_code_size = min_code_size + 1; // Number of bits per code. 34184 // NOTE: This shares the same name as the encoder, but has a different 34185 // meaning here. Here this masks each code coming from the code stream. 34186 var code_mask = (1 << cur_code_size) - 1; 34187 var cur_shift = 0; 34188 var cur = 0; 34189 var op = 0; // Output pointer. 34190 var subblock_size = code_stream[p++]; // TODO(deanm): Would using a TypedArray be any faster? At least it would 34191 // solve the fast mode / backing store uncertainty. 34192 // var code_table = Array(4096); 34193 var code_table = new Int32Array(4096); // Can be signed, we only use 20 bits. 34194 var prev_code = null; // Track code-1. 34195 while (true) { 34196 // Read up to two bytes, making sure we always 12-bits for max sized code. 34197 while (cur_shift < 16) { 34198 if (subblock_size === 0) break; // No more data to be read. 34199 cur |= code_stream[p++] << cur_shift; 34200 cur_shift += 8; 34201 if (subblock_size === 1) { 34202 // Never let it get to 0 to hold logic above. 34203 subblock_size = code_stream[p++]; // Next subblock. 34204 } else { 34205 --subblock_size; 34206 } 34207 } // TODO(deanm): We should never really get here, we should have received 34208 // and EOI. 34209 34210 if (cur_shift < cur_code_size) break; 34211 var code = cur & code_mask; 34212 cur >>= cur_code_size; 34213 cur_shift -= cur_code_size; // TODO(deanm): Maybe should check that the first code was a clear code, 34214 // at least this is what you're supposed to do. But actually our encoder 34215 // now doesn't emit a clear code first anyway. 34216 if (code === clear_code) { 34217 // We don't actually have to clear the table. This could be a good idea 34218 // for greater error checking, but we don't really do any anyway. We 34219 // will just track it with next_code and overwrite old entries. 34220 next_code = eoi_code + 1; 34221 cur_code_size = min_code_size + 1; 34222 code_mask = (1 << cur_code_size) - 1; // Don't update prev_code ? 34223 prev_code = null; 34224 continue; 34225 } else if (code === eoi_code) { 34226 break; 34227 } // We have a similar situation as the decoder, where we want to store 34228 // variable length entries (code table entries), but we want to do in a 34229 // faster manner than an array of arrays. The code below stores sort of a 34230 // linked list within the code table, and then "chases" through it to 34231 // construct the dictionary entries. When a new entry is created, just the 34232 // last byte is stored, and the rest (prefix) of the entry is only 34233 // referenced by its table entry. Then the code chases through the 34234 // prefixes until it reaches a single byte code. We have to chase twice, 34235 // first to compute the length, and then to actually copy the data to the 34236 // output (backwards, since we know the length). The alternative would be 34237 // storing something in an intermediate stack, but that doesn't make any 34238 // more sense. I implemented an approach where it also stored the length 34239 // in the code table, although it's a bit tricky because you run out of 34240 // bits (12 + 12 + 8), but I didn't measure much improvements (the table 34241 // entries are generally not the long). Even when I created benchmarks for 34242 // very long table entries the complexity did not seem worth it. 34243 // The code table stores the prefix entry in 12 bits and then the suffix 34244 // byte in 8 bits, so each entry is 20 bits. 34245 34246 var chase_code = code < next_code ? code : prev_code; // Chase what we will output, either {CODE} or {CODE-1}. 34247 var chase_length = 0; 34248 var chase = chase_code; 34249 while (chase > clear_code) { 34250 chase = code_table[chase] >> 8; 34251 ++chase_length; 34252 } 34253 var k = chase; 34254 var op_end = op + chase_length + (chase_code !== code ? 1 : 0); 34255 if (op_end > output_length) { 34256 console.log('Warning, gif stream longer than expected.'); 34257 return; 34258 } // Already have the first byte from the chase, might as well write it fast. 34259 34260 output[op++] = k; 34261 op += chase_length; 34262 var b = op; // Track pointer, writing backwards. 34263 if (chase_code !== code) // The case of emitting {CODE-1} + k. 34264 output[op++] = k; 34265 chase = chase_code; 34266 while (chase_length--) { 34267 chase = code_table[chase]; 34268 output[--b] = chase & 255; // Write backwards. 34269 chase >>= 8; // Pull down to the prefix code. 34270 } 34271 if (prev_code !== null && next_code < 4096) { 34272 code_table[next_code++] = prev_code << 8 | k; // TODO(deanm): Figure out this clearing vs code growth logic better. I 34273 // have an feeling that it should just happen somewhere else, for now it 34274 // is awkward between when we grow past the max and then hit a clear code. 34275 // For now just check if we hit the max 12-bits (then a clear code should 34276 // follow, also of course encoded in 12-bits). 34277 if (next_code >= code_mask + 1 && cur_code_size < 12) {
34278 ++cur_code_size; 34279 code_mask = code_mask << 1 | 1; 34280 } 34281 } 34282 prev_code = code; 34283 } 34284 if (op !== output_length) { 34285 console.log('Warning, gif stream shorter than expected.'); 34286 } 34287 return output; 34288 } // CommonJS. 34289 34290 try { 34291 exports.GifWriter = GifWriter; 34292 exports.GifReader = GifReader; 34293 } catch (e) { 34294 } 34295 }, 34296 { 34297 } 34298 ], 34299 263: [ 34300 function (_dereq_, module, exports) { 34301 (function (Buffer) { 34302 /** 34303 * https://opentype.js.org v0.9.0 | (c) Frederik De Bleser and other contributors | MIT License | Uses tiny-inflate by Devon Govett and string.prototype.codepointat polyfill by Mathias Bynens 34304 */ 34305 (function (global, factory) { 34306 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : factory(global.opentype = { 34307 }); 34308 }) (this, function (exports) { 34309 'use strict'; 34310 /*! https://mths.be/codepointat v0.2.0 by @mathias */ 34311 if (!String.prototype.codePointAt) { 34312 (function () { 34313 var defineProperty = function () { 34314 // IE 8 only supports `Object.defineProperty` on DOM elements 34315 try { 34316 var object = { 34317 }; 34318 var $defineProperty = Object.defineProperty; 34319 var result = $defineProperty(object, object, object) && $defineProperty; 34320 } catch (error) { 34321 } 34322 return result; 34323 }(); 34324 var codePointAt = function (position) { 34325 if (this == null) { 34326 throw TypeError(); 34327 } 34328 var string = String(this); 34329 var size = string.length; // `ToInteger` 34330 var index = position ? Number(position) : 0; 34331 if (index != index) { 34332 // better `isNaN` 34333 index = 0; 34334 } // Account for out-of-bounds indices: 34335 34336 if (index < 0 || index >= size) { 34337 return undefined; 34338 } // Get the first code unit 34339 34340 var first = string.charCodeAt(index); 34341 var second; 34342 if ( // check if itâs the start of a surrogate pair 34343 first >= 55296 && first <= 56319 && // high surrogate 34344 size > index + 1 // there is a next code unit 34345 ) { 34346 second = string.charCodeAt(index + 1); 34347 if (second >= 56320 && second <= 57343) { 34348 // low surrogate 34349 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae 34350 return (first - 55296) * 1024 + second - 56320 + 65536; 34351 } 34352 } 34353 return first; 34354 }; 34355 if (defineProperty) { 34356 defineProperty(String.prototype, 'codePointAt', { 34357 'value': codePointAt, 34358 'configurable': true, 34359 'writable': true 34360 }); 34361 } else { 34362 String.prototype.codePointAt = codePointAt; 34363 } 34364 }) (); 34365 } 34366 var TINF_OK = 0; 34367 var TINF_DATA_ERROR = - 3; 34368 function Tree() { 34369 this.table = new Uint16Array(16); 34370 /* table of code length counts */ 34371 this.trans = new Uint16Array(288); 34372 /* code -> symbol translation table */ 34373 } 34374 function Data(source, dest) { 34375 this.source = source; 34376 this.sourceIndex = 0; 34377 this.tag = 0; 34378 this.bitcount = 0; 34379 this.dest = dest; 34380 this.destLen = 0; 34381 this.ltree = new Tree(); 34382 /* dynamic length/symbol tree */ 34383 this.dtree = new Tree(); 34384 /* dynamic distance tree */ 34385 } /* --------------------------------------------------- *
vendor: 10,710 bytes, lines 34386-34673
34386 * -- uninitialized global data (static structures) -- * 34387 * --------------------------------------------------- */ 34388 34389 var sltree = new Tree(); 34390 var sdtree = new Tree(); 34391 /* extra bits and base tables for length codes */ 34392 var length_bits = new Uint8Array(30); 34393 var length_base = new Uint16Array(30); 34394 /* extra bits and base tables for distance codes */ 34395 var dist_bits = new Uint8Array(30); 34396 var dist_base = new Uint16Array(30); 34397 /* special ordering of code length codes */ 34398 var clcidx = new Uint8Array([16, 34399 17, 34400 18, 34401 0, 34402 8, 34403 7, 34404 9, 34405 6, 34406 10, 34407 5, 34408 11, 34409 4, 34410 12, 34411 3, 34412 13, 34413 2, 34414 14, 34415 1, 34416 15]); 34417 /* used by tinf_decode_trees, avoids allocations every call */ 34418 var code_tree = new Tree(); 34419 var lengths = new Uint8Array(288 + 32); 34420 /* ----------------------- * 34421 * -- utility functions -- * 34422 * ----------------------- */ 34423 /* build extra bits and base tables */ 34424 function tinf_build_bits_base(bits, base, delta, first) { 34425 var i, 34426 sum; 34427 /* build bits table */ 34428 for (i = 0; i < delta; ++i) { 34429 bits[i] = 0; 34430 } 34431 for (i = 0; i < 30 - delta; ++i) { 34432 bits[i + delta] = i / delta | 0; 34433 } /* build base table */ 34434 34435 for (sum = first, i = 0; i < 30; ++i) { 34436 base[i] = sum; 34437 sum += 1 << bits[i]; 34438 } 34439 } /* build the fixed huffman trees */ 34440 34441 function tinf_build_fixed_trees(lt, dt) { 34442 var i; 34443 /* build fixed length tree */ 34444 for (i = 0; i < 7; ++i) { 34445 lt.table[i] = 0; 34446 } 34447 lt.table[7] = 24; 34448 lt.table[8] = 152; 34449 lt.table[9] = 112; 34450 for (i = 0; i < 24; ++i) { 34451 lt.trans[i] = 256 + i; 34452 } 34453 for (i = 0; i < 144; ++i) { 34454 lt.trans[24 + i] = i; 34455 } 34456 for (i = 0; i < 8; ++i) { 34457 lt.trans[24 + 144 + i] = 280 + i; 34458 } 34459 for (i = 0; i < 112; ++i) { 34460 lt.trans[24 + 144 + 8 + i] = 144 + i; 34461 } /* build fixed distance tree */ 34462 34463 for (i = 0; i < 5; ++i) { 34464 dt.table[i] = 0; 34465 } 34466 dt.table[5] = 32; 34467 for (i = 0; i < 32; ++i) { 34468 dt.trans[i] = i; 34469 } 34470 } /* given an array of code lengths, build a tree */ 34471 34472 var offs = new Uint16Array(16); 34473 function tinf_build_tree(t, lengths, off, num) { 34474 var i, 34475 sum; 34476 /* clear code length count table */ 34477 for (i = 0; i < 16; ++i) { 34478 t.table[i] = 0; 34479 } /* scan symbol lengths, and sum code length counts */ 34480 34481 for (i = 0; i < num; ++i) { 34482 t.table[lengths[off + i]]++; 34483 } 34484 t.table[0] = 0; 34485 /* compute offset table for distribution sort */ 34486 for (sum = 0, i = 0; i < 16; ++i) { 34487 offs[i] = sum; 34488 sum += t.table[i]; 34489 } /* create code->symbol translation table (symbols sorted by code) */ 34490 34491 for (i = 0; i < num; ++i) { 34492 if (lengths[off + i]) { 34493 t.trans[offs[lengths[off + i]]++] = i; 34494 } 34495 } 34496 } /* ---------------------- * 34497 * -- decode functions -- * 34498 * ---------------------- */ 34499 /* get one bit from source stream */ 34500 34501 function tinf_getbit(d) { 34502 /* check if tag is empty */ 34503 if (!d.bitcount--) { 34504 /* load next tag */ 34505 d.tag = d.source[d.sourceIndex++]; 34506 d.bitcount = 7; 34507 } /* shift bit out of tag */ 34508 34509 var bit = d.tag & 1; 34510 d.tag >>>= 1; 34511 return bit; 34512 } /* read a num bit value from a stream and add base */ 34513 34514 function tinf_read_bits(d, num, base) { 34515 if (!num) { 34516 return base; 34517 } 34518 while (d.bitcount < 24) { 34519 d.tag |= d.source[d.sourceIndex++] << d.bitcount; 34520 d.bitcount += 8; 34521 } 34522 var val = d.tag & 65535 >>> 16 - num; 34523 d.tag >>>= num; 34524 d.bitcount -= num; 34525 return val + base; 34526 } /* given a data stream and a tree, decode a symbol */ 34527 34528 function tinf_decode_symbol(d, t) { 34529 while (d.bitcount < 24) { 34530 d.tag |= d.source[d.sourceIndex++] << d.bitcount; 34531 d.bitcount += 8; 34532 } 34533 var sum = 0, 34534 cur = 0, 34535 len = 0; 34536 var tag = d.tag; 34537 /* get more bits while code value is above sum */ 34538 do { 34539 cur = 2 * cur + (tag & 1); 34540 tag >>>= 1; 34541 ++len; 34542 sum += t.table[len]; 34543 cur -= t.table[len]; 34544 } while (cur >= 0); 34545 d.tag = tag; 34546 d.bitcount -= len; 34547 return t.trans[sum + cur]; 34548 } /* given a data stream, decode dynamic trees from it */ 34549 34550 function tinf_decode_trees(d, lt, dt) { 34551 var hlit, 34552 hdist, 34553 hclen; 34554 var i, 34555 num, 34556 length; 34557 /* get 5 bits HLIT (257-286) */ 34558 hlit = tinf_read_bits(d, 5, 257); 34559 /* get 5 bits HDIST (1-32) */ 34560 hdist = tinf_read_bits(d, 5, 1); 34561 /* get 4 bits HCLEN (4-19) */ 34562 hclen = tinf_read_bits(d, 4, 4); 34563 for (i = 0; i < 19; ++i) { 34564 lengths[i] = 0; 34565 } /* read code lengths for code length alphabet */ 34566 34567 for (i = 0; i < hclen; ++i) { 34568 /* get 3 bits code length (0-7) */ 34569 var clen = tinf_read_bits(d, 3, 0); 34570 lengths[clcidx[i]] = clen; 34571 } /* build code length tree */ 34572 34573 tinf_build_tree(code_tree, lengths, 0, 19); 34574 /* decode code lengths for the dynamic trees */ 34575 for (num = 0; num < hlit + hdist; ) { 34576 var sym = tinf_decode_symbol(d, code_tree); 34577 switch (sym) { 34578 case 16: 34579 /* copy previous code length 3-6 times (read 2 bits) */ 34580 var prev = lengths[num - 1]; 34581 for (length = tinf_read_bits(d, 2, 3); length; --length) { 34582 lengths[num++] = prev; 34583 } 34584 break; 34585 case 17: 34586 /* repeat code length 0 for 3-10 times (read 3 bits) */ 34587 for (length = tinf_read_bits(d, 3, 3); length; --length) { 34588 lengths[num++] = 0; 34589 } 34590 break; 34591 case 18: 34592 /* repeat code length 0 for 11-138 times (read 7 bits) */ 34593 for (length = tinf_read_bits(d, 7, 11); length; --length) { 34594 lengths[num++] = 0; 34595 } 34596 break; 34597 default: 34598 /* values 0-15 represent the actual code lengths */ 34599 lengths[num++] = sym; 34600 break; 34601 } 34602 } /* build dynamic trees */ 34603 34604 tinf_build_tree(lt, lengths, 0, hlit); 34605 tinf_build_tree(dt, lengths, hlit, hdist); 34606 } /* ----------------------------- * 34607 * -- block inflate functions -- * 34608 * ----------------------------- */ 34609 /* given a stream and two trees, inflate a block of data */ 34610 34611 function tinf_inflate_block_data(d, lt, dt) { 34612 while (1) { 34613 var sym = tinf_decode_symbol(d, lt); 34614 /* check for end of block */ 34615 if (sym === 256) { 34616 return TINF_OK; 34617 } 34618 if (sym < 256) { 34619 d.dest[d.destLen++] = sym; 34620 } else { 34621 var length, 34622 dist, 34623 offs; 34624 var i; 34625 sym -= 257; 34626 /* possibly get more bits from length code */ 34627 length = tinf_read_bits(d, length_bits[sym], length_base[sym]); 34628 dist = tinf_decode_symbol(d, dt); 34629 /* possibly get more bits from distance code */ 34630 offs = d.destLen - tinf_read_bits(d, dist_bits[dist], dist_base[dist]); 34631 /* copy match */ 34632 for (i = offs; i < offs + length; ++i) { 34633 d.dest[d.destLen++] = d.dest[i]; 34634 } 34635 } 34636 } 34637 } /* inflate an uncompressed block of data */ 34638 34639 function tinf_inflate_uncompressed_block(d) { 34640 var length, 34641 invlength; 34642 var i; 34643 /* unread from bitbuffer */ 34644 while (d.bitcount > 8) { 34645 d.sourceIndex--; 34646 d.bitcount -= 8; 34647 } /* get length */ 34648 34649 length = d.source[d.sourceIndex + 1]; 34650 length = 256 * length + d.source[d.sourceIndex]; 34651 /* get one's complement of length */ 34652 invlength = d.source[d.sourceIndex + 3]; 34653 invlength = 256 * invlength + d.source[d.sourceIndex + 2]; 34654 /* check length */ 34655 if (length !== (~invlength & 65535)) { 34656 return TINF_DATA_ERROR; 34657 } 34658 d.sourceIndex += 4; 34659 /* copy block */ 34660 for (i = length; i; --i) { 34661 d.dest[d.destLen++] = d.source[d.sourceIndex++]; 34662 } /* make sure we start next block on a byte boundary */ 34663 34664 d.bitcount = 0; 34665 return TINF_OK; 34666 } /* inflate stream from source to dest */ 34667 34668 function tinf_uncompress(source, dest) { 34669 var d = new Data(source, dest); 34670 var bfinal, 34671 btype, 34672 res; 34673 do {
34674 /* read final block flag */ 34675 bfinal = tinf_getbit(d); 34676 /* read block type (2 bits) */ 34677 btype = tinf_read_bits(d, 2, 0); 34678 /* decompress block */ 34679 switch (btype) { 34680 case 0: 34681 /* decompress uncompressed block */ 34682 res = tinf_inflate_uncompressed_block(d); 34683 break; 34684 case 1: 34685 /* decompress block with fixed huffman trees */ 34686 res = tinf_inflate_block_data(d, sltree, sdtree); 34687 break; 34688 case 2: 34689 /* decompress block with dynamic huffman trees */ 34690 tinf_decode_trees(d, d.ltree, d.dtree); 34691 res = tinf_inflate_block_data(d, d.ltree, d.dtree); 34692 break; 34693 default: 34694 res = TINF_DATA_ERROR; 34695 } 34696 if (res !== TINF_OK) { 34697 throw new Error('Data error'); 34698 } 34699 } while (!bfinal); 34700 if (d.destLen < d.dest.length) { 34701 if (typeof d.dest.slice === 'function') { 34702 return d.dest.slice(0, d.destLen); 34703 } else { 34704 return d.dest.subarray(0, d.destLen); 34705 } 34706 } 34707 return d.dest; 34708 } /* -------------------- * 34709 * -- initialization -- * 34710 * -------------------- */ 34711 /* build fixed huffman trees */ 34712 34713 tinf_build_fixed_trees(sltree, sdtree); 34714 /* build extra bits and base tables */ 34715 tinf_build_bits_base(length_bits, length_base, 4, 3); 34716 tinf_build_bits_base(dist_bits, dist_base, 2, 1); 34717 /* fix a special case */ 34718 length_bits[28] = 0; 34719 length_base[28] = 258; 34720 var tinyInflate = tinf_uncompress; // The Bounding Box object 34721 function derive(v0, v1, v2, v3, t) { 34722 return Math.pow(1 - t, 3) * v0 + 3 * Math.pow(1 - t, 2) * t * v1 + 3 * (1 - t) * Math.pow(t, 2) * v2 + Math.pow(t, 3) * v3; 34723 } /** 34724 * A bounding box is an enclosing box that describes the smallest measure within which all the points lie. 34725 * It is used to calculate the bounding box of a glyph or text path. 34726 * 34727 * On initialization, x1/y1/x2/y2 will be NaN. Check if the bounding box is empty using `isEmpty()`. 34728 * 34729 * @exports opentype.BoundingBox 34730 * @class 34731 * @constructor 34732 */ 34733 34734 function BoundingBox() { 34735 this.x1 = Number.NaN; 34736 this.y1 = Number.NaN; 34737 this.x2 = Number.NaN; 34738 this.y2 = Number.NaN; 34739 } /** 34740 * Returns true if the bounding box is empty, that is, no points have been added to the box yet. 34741 */ 34742 34743 BoundingBox.prototype.isEmpty = function () { 34744 return isNaN(this.x1) || isNaN(this.y1) || isNaN(this.x2) || isNaN(this.y2); 34745 }; 34746 /** 34747 * Add the point to the bounding box. 34748 * The x1/y1/x2/y2 coordinates of the bounding box will now encompass the given point. 34749 * @param {number} x - The X coordinate of the point. 34750 * @param {number} y - The Y coordinate of the point. 34751 */ 34752 BoundingBox.prototype.addPoint = function (x, y) { 34753 if (typeof x === 'number') { 34754 if (isNaN(this.x1) || isNaN(this.x2)) { 34755 this.x1 = x; 34756 this.x2 = x; 34757 } 34758 if (x < this.x1) { 34759 this.x1 = x; 34760 } 34761 if (x > this.x2) { 34762 this.x2 = x; 34763 } 34764 } 34765 if (typeof y === 'number') { 34766 if (isNaN(this.y1) || isNaN(this.y2)) { 34767 this.y1 = y; 34768 this.y2 = y; 34769 } 34770 if (y < this.y1) { 34771 this.y1 = y; 34772 } 34773 if (y > this.y2) { 34774 this.y2 = y; 34775 } 34776 } 34777 }; 34778 /** 34779 * Add a X coordinate to the bounding box. 34780 * This extends the bounding box to include the X coordinate. 34781 * This function is used internally inside of addBezier. 34782 * @param {number} x - The X coordinate of the point. 34783 */ 34784 BoundingBox.prototype.addX = function (x) { 34785 this.addPoint(x, null); 34786 }; 34787 /** 34788 * Add a Y coordinate to the bounding box. 34789 * This extends the bounding box to include the Y coordinate. 34790 * This function is used internally inside of addBezier. 34791 * @param {number} y - The Y coordinate of the point. 34792 */ 34793 BoundingBox.prototype.addY = function (y) { 34794 this.addPoint(null, y); 34795 }; 34796 /** 34797 * Add a Bézier curve to the bounding box. 34798 * This extends the bounding box to include the entire Bézier. 34799 * @param {number} x0 - The starting X coordinate. 34800 * @param {number} y0 - The starting Y coordinate. 34801 * @param {number} x1 - The X coordinate of the first control point. 34802 * @param {number} y1 - The Y coordinate of the first control point. 34803 * @param {number} x2 - The X coordinate of the second control point. 34804 * @param {number} y2 - The Y coordinate of the second control point. 34805 * @param {number} x - The ending X coordinate. 34806 * @param {number} y - The ending Y coordinate. 34807 */ 34808 BoundingBox.prototype.addBezier = function (x0, y0, x1, y1, x2, y2, x, y) { 34809 var this$1 = this; // This code is based on http://nishiohirokazu.blogspot.com/2009/06/how-to-calculate-bezier-curves-bounding.html 34810 // and https://github.com/icons8/svg-path-bounding-box 34811 var p0 = [ 34812 x0, 34813 y0 34814 ]; 34815 var p1 = [ 34816 x1, 34817 y1 34818 ]; 34819 var p2 = [ 34820 x2, 34821 y2 34822 ]; 34823 var p3 = [ 34824 x, 34825 y 34826 ]; 34827 this.addPoint(x0, y0); 34828 this.addPoint(x, y); 34829 for (var i = 0; i <= 1; i++) { 34830 var b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i]; 34831 var a = - 3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i]; 34832 var c = 3 * p1[i] - 3 * p0[i]; 34833 if (a === 0) { 34834 if (b === 0) { 34835 continue; 34836 } 34837 var t = - c / b; 34838 if (0 < t && t < 1) { 34839 if (i === 0) { 34840 this$1.addX(derive(p0[i], p1[i], p2[i], p3[
34840i], t)); 34841 } 34842 if (i === 1) { 34843 this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t)); 34844 } 34845 } 34846 continue; 34847 } 34848 var b2ac = Math.pow(b, 2) - 4 * c * a; 34849 if (b2ac < 0) { 34850 continue; 34851 } 34852 var t1 = ( - b + Math.sqrt(b2ac)) / (2 * a); 34853 if (0 < t1 && t1 < 1) { 34854 if (i === 0) { 34855 this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t1)); 34856 } 34857 if (i === 1) { 34858 this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t1)); 34859 } 34860 } 34861 var t2 = ( - b - Math.sqrt(b2ac)) / (2 * a); 34862 if (0 < t2 && t2 < 1) { 34863 if (i === 0) { 34864 this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t2)); 34865 } 34866 if (i === 1) { 34867 this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t2)); 34868 } 34869 } 34870 } 34871 }; 34872 /** 34873 * Add a quadratic curve to the bounding box. 34874 * This extends the bounding box to include the entire quadratic curve. 34875 * @param {number} x0 - The starting X coordinate. 34876 * @param {number} y0 - The starting Y coordinate. 34877 * @param {number} x1 - The X coordinate of the control point. 34878 * @param {number} y1 - The Y coordinate of the control point. 34879 * @param {number} x - The ending X coordinate. 34880 * @param {number} y - The ending Y coordinate. 34881 */ 34882 BoundingBox.prototype.addQuad = function (x0, y0, x1, y1, x, y) { 34883 var cp1x = x0 + 2 / 3 * (x1 - x0); 34884 var cp1y = y0 + 2 / 3 * (y1 - y0); 34885 var cp2x = cp1x + 1 / 3 * (x - x0); 34886 var cp2y = cp1y + 1 / 3 * (y - y0); 34887 this.addBezier(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y); 34888 }; // Geometric objects 34889 /** 34890 * A bézier path containing a set of path commands similar to a SVG path. 34891 * Paths can be drawn on a context using `draw`. 34892 * @exports opentype.Path 34893 * @class 34894 * @constructor 34895 */ 34896 function Path() { 34897 this.commands = [ 34898 ]; 34899 this.fill = 'black'; 34900 this.stroke = null; 34901 this.strokeWidth = 1; 34902 } /** 34903 * @param {number} x 34904 * @param {number} y 34905 */ 34906 34907 Path.prototype.moveTo = function (x, y) { 34908 this.commands.push({ 34909 type: 'M', 34910 x: x, 34911 y: y 34912 }); 34913 }; 34914 /** 34915 * @param {number} x 34916 * @param {number} y 34917 */ 34918 Path.prototype.lineTo = function (x, y) { 34919 this.commands.push({ 34920 type: 'L', 34921 x: x, 34922 y: y 34923 }); 34924 }; 34925 /** 34926 * Draws cubic curve 34927 * @function 34928 * curveTo 34929 * @memberof opentype.Path.prototype 34930 * @param {number} x1 - x of control 1 34931 * @param {number} y1 - y of control 1 34932 * @param {number} x2 - x of control 2 34933 * @param {number} y2 - y of control 2 34934 * @param {number} x - x of path point 34935 * @param {number} y - y of path point 34936 */ 34937 /** 34938 * Draws cubic curve 34939 * @function 34940 * bezierCurveTo 34941 * @memberof opentype.Path.prototype 34942 * @param {number} x1 - x of control 1 34943 * @param {number} y1 - y of control 1 34944 * @param {number} x2 - x of control 2 34945 * @param {number} y2 - y of control 2 34946 * @param {number} x - x of path point 34947 * @param {number} y - y of path point 34948 * @see curveTo 34949 */ 34950 Path.prototype.curveTo = Path.prototype.bezierCurveTo = function (x1, y1, x2, y2, x, y) { 34951 this.commands.push({ 34952 type: 'C', 34953 x1: x1, 34954 y1: y1, 34955 x2: x2, 34956 y2: y2, 34957 x: x, 34958 y: y 34959 }); 34960 }; 34961 /** 34962 * Draws quadratic curve 34963 * @function 34964 * quadraticCurveTo 34965 * @memberof opentype.Path.prototype 34966 * @param {number} x1 - x of control 34967 * @param {number} y1 - y of control 34968 * @param {number} x - x of path point 34969 * @param {number} y - y of path point 34970 */ 34971 /** 34972 * Draws quadratic curve 34973 * @function 34974 * quadTo 34975 * @memberof opentype.Path.prototype 34976 * @param {number} x1 - x of control 34977 * @param {number} y1 - y of control 34978 * @param {number} x - x of path point 34979 * @param {number} y - y of path point 34980 */ 34981 Path.prototype.quadTo = Path.prototype.quadraticCurveTo = function (x1, y1, x, y) { 34982 this.commands.push({ 34983 type: 'Q', 34984 x1: x1, 34985 y1: y1, 34986 x: x, 34987 y: y 34988 }); 34989 }; 34990 /** 34991 * Closes the path 34992 * @function closePath 34993 * @memberof opentype.Path.prototype 34994 */ 34995 /** 34996 * Close the path 34997 * @function close 34998 * @memberof opentype.Path.prototype 34999 */ 35000 Path.prototype.close = Path.prototype.closePath = function () { 35001 this.commands.push({ 35002 type: 'Z' 35003 }); 35004 }; 35005 /** 35006 * Add the given path or list of commands to the commands of this path. 35007 * @param {Array} pathOrCommands - another opentype.Path, an opentype.BoundingBox, or an array of commands. 35008 */ 35009 Path.prototype.extend = function (pathOrCommands) { 35010 if (pathOrCommands.commands) { 35011 pathOrCommands = pathOrCommands.commands; 35012 } else if (pathOrCommands instanceof BoundingBox) { 35013 var box = pathOrCommands; 35014 this.moveTo(box.x1, box.y1); 35015 this.lineTo(box.x2, box.y1); 35016 this.lineTo(box.x2, box.y2); 35017 this.lineTo(box.x1, box.y2); 35018 this.close(); 35019 return; 35020 } 35021 Array.prototype.push.apply(this.commands, pathOrCommands); 35022 }; 35023 /** 35024 * Calculate the bounding box of the path.
35025 * @returns {opentype.BoundingBox} 35026 */ 35027 Path.prototype.getBoundingBox = function () { 35028 var this$1 = this; 35029 var box = new BoundingBox(); 35030 var startX = 0; 35031 var startY = 0; 35032 var prevX = 0; 35033 var prevY = 0; 35034 for (var i = 0; i < this.commands.length; i++) { 35035 var cmd = this$1.commands[i]; 35036 switch (cmd.type) { 35037 case 'M': 35038 box.addPoint(cmd.x, cmd.y); 35039 startX = prevX = cmd.x; 35040 startY = prevY = cmd.y; 35041 break; 35042 case 'L': 35043 box.addPoint(cmd.x, cmd.y); 35044 prevX = cmd.x; 35045 prevY = cmd.y; 35046 break; 35047 case 'Q': 35048 box.addQuad(prevX, prevY, cmd.x1, cmd.y1, cmd.x, cmd.y); 35049 prevX = cmd.x; 35050 prevY = cmd.y; 35051 break; 35052 case 'C': 35053 box.addBezier(prevX, prevY, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); 35054 prevX = cmd.x; 35055 prevY = cmd.y; 35056 break; 35057 case 'Z': 35058 prevX = startX; 35059 prevY = startY; 35060 break; 35061 default: 35062 throw new Error('Unexpected path command ' + cmd.type); 35063 } 35064 } 35065 if (box.isEmpty()) { 35066 box.addPoint(0, 0); 35067 } 35068 return box; 35069 }; 35070 /** 35071 * Draw the path to a 2D context. 35072 * @param {CanvasRenderingContext2D} ctx - A 2D drawing context. 35073 */ 35074 Path.prototype.draw = function (ctx) { 35075 var this$1 = this; 35076 ctx.beginPath(); 35077 for (var i = 0; i < this.commands.length; i += 1) { 35078 var cmd = this$1.commands[i]; 35079 if (cmd.type === 'M') { 35080 ctx.moveTo(cmd.x, cmd.y); 35081 } else if (cmd.type === 'L') { 35082 ctx.lineTo(cmd.x, cmd.y); 35083 } else if (cmd.type === 'C') { 35084 ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); 35085 } else if (cmd.type === 'Q') { 35086 ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y); 35087 } else if (cmd.type === 'Z') { 35088 ctx.closePath(); 35089 } 35090 } 35091 if (this.fill) { 35092 ctx.fillStyle = this.fill; 35093 ctx.fill(); 35094 } 35095 if (this.stroke) { 35096 ctx.strokeStyle = this.stroke; 35097 ctx.lineWidth = this.strokeWidth; 35098 ctx.stroke(); 35099 } 35100 }; 35101 /** 35102 * Convert the Path to a string of path data instructions 35103 * See http://www.w3.org/TR/SVG/paths.html#PathData 35104 * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values 35105 * @return {string} 35106 */ 35107 Path.prototype.toPathData = function (decimalPlaces) { 35108 var this$1 = this; 35109 decimalPlaces = decimalPlaces !== undefined ? decimalPlaces : 2; 35110 function floatToString(v) { 35111 if (Math.round(v) === v) { 35112 return '' + Math.round(v); 35113 } else { 35114 return v.toFixed(decimalPlaces); 35115 } 35116 } 35117 function packValues() { 35118 var arguments$1 = arguments; 35119 var s = ''; 35120 for (var i = 0; i < arguments.length; i += 1) { 35121 var v = arguments$1[i]; 35122 if (v >= 0 && i > 0) { 35123 s += ' '; 35124 } 35125 s += floatToString(v); 35126 } 35127 return s; 35128 } 35129 var d = ''; 35130 for (var i = 0; i < this.commands.length; i += 1) { 35131 var cmd = this$1.commands[i]; 35132 if (cmd.type === 'M') { 35133 d += 'M' + packValues(cmd.x, cmd.y); 35134 } else if (cmd.type === 'L') { 35135 d += 'L' + packValues(cmd.x, cmd.y); 35136 } else if (cmd.type === 'C') { 35137 d += 'C' + packValues(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); 35138 } else if (cmd.type === 'Q') { 35139 d += 'Q' + packValues(cmd.x1, cmd.y1, cmd.x, cmd.y); 35140 } else if (cmd.type === 'Z') { 35141 d += 'Z'; 35142 } 35143 } 35144 return d; 35145 }; 35146 /** 35147 * Convert the path to an SVG <path> element, as a string. 35148 * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values 35149 * @return {string} 35150 */ 35151 Path.prototype.toSVG = function (decimalPlaces) { 35152 var svg = '<path d="'; 35153 svg += this.toPathData(decimalPlaces); 35154 svg += '"'; 35155 if (this.fill && this.fill !== 'black') { 35156 if (this.fill === null) { 35157 svg += ' fill="none"'; 35158 } else { 35159 svg += ' fill="' + this.fill + '"'; 35160 } 35161 } 35162 if (this.stroke) { 35163 svg += ' stroke="' + this.stroke + '" stroke-width="' + this.strokeWidth + '"'; 35164 } 35165 svg += '/>'; 35166 return svg; 35167 }; 35168 /** 35169 * Convert the path to a DOM element. 35170 * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values 35171 * @return {SVGPathElement} 35172 */ 35173 Path.prototype.toDOMElement = function (decimalPlaces) { 35174 var temporaryPath = this.toPathData(decimalPlaces); 35175 var newPath = document.createElementNS('http://www.w3.org/2000/svg', 'path'); 35176 newPath.setAttribute('d', temporaryPath); 35177 return newPath; 35178 }; // Run-time checking of preconditions. 35179 function fail(message) { 35180 throw new Error(message); 35181 }
vendor: 9,926 bytes, lines 35181-35508
35181 // Precondition function that checks if the given predicate is true. 35182 // If not, it will throw an error. 35183 35184 function argument(predicate, message) { 35185 if (!predicate) { 35186 fail(message); 35187 } 35188 } 35189 var check = { 35190 fail: fail, 35191 argument: argument, 35192 assert: argument 35193 }; // Data types used in the OpenType font file. 35194 var LIMIT16 = 32768; // The limit at which a 16-bit number switches signs == 2^15 35195 var LIMIT32 = 2147483648; // The limit at which a 32-bit number switches signs == 2 ^ 31 35196 /** 35197 * @exports opentype.decode 35198 * @class 35199 */ 35200 var decode = { 35201 }; 35202 /** 35203 * @exports opentype.encode 35204 * @class 35205 */ 35206 var encode = { 35207 }; 35208 /** 35209 * @exports opentype.sizeOf 35210 * @class 35211 */ 35212 var sizeOf = { 35213 }; // Return a function that always returns the same value. 35214 function constant(v) { 35215 return function () { 35216 return v; 35217 }; 35218 } // OpenType data types ////////////////////////////////////////////////////// 35219 /** 35220 * Convert an 8-bit unsigned integer to a list of 1 byte. 35221 * @param {number} 35222 * @returns {Array} 35223 */ 35224 35225 encode.BYTE = function (v) { 35226 check.argument(v >= 0 && v <= 255, 'Byte value should be between 0 and 255.'); 35227 return [v]; 35228 }; 35229 /** 35230 * @constant 35231 * @type {number} 35232 */ 35233 sizeOf.BYTE = constant(1); 35234 /** 35235 * Convert a 8-bit signed integer to a list of 1 byte. 35236 * @param {string} 35237 * @returns {Array} 35238 */ 35239 encode.CHAR = function (v) { 35240 return [v.charCodeAt(0)]; 35241 }; 35242 /** 35243 * @constant 35244 * @type {number} 35245 */ 35246 sizeOf.CHAR = constant(1); 35247 /** 35248 * Convert an ASCII string to a list of bytes. 35249 * @param {string} 35250 * @returns {Array} 35251 */ 35252 encode.CHARARRAY = function (v) { 35253 var b = [ 35254 ]; 35255 for (var i = 0; i < v.length; i += 1) { 35256 b[i] = v.charCodeAt(i); 35257 } 35258 return b; 35259 }; 35260 /** 35261 * @param {Array} 35262 * @returns {number} 35263 */ 35264 sizeOf.CHARARRAY = function (v) { 35265 return v.length; 35266 }; 35267 /** 35268 * Convert a 16-bit unsigned integer to a list of 2 bytes. 35269 * @param {number} 35270 * @returns {Array} 35271 */ 35272 encode.USHORT = function (v) { 35273 return [v >> 8 & 255, 35274 v & 255]; 35275 }; 35276 /** 35277 * @constant 35278 * @type {number} 35279 */ 35280 sizeOf.USHORT = constant(2); 35281 /** 35282 * Convert a 16-bit signed integer to a list of 2 bytes. 35283 * @param {number} 35284 * @returns {Array} 35285 */ 35286 encode.SHORT = function (v) { 35287 // Two's complement 35288 if (v >= LIMIT16) { 35289 v = - (2 * LIMIT16 - v); 35290 } 35291 return [v >> 8 & 255, 35292 v & 255]; 35293 }; 35294 /** 35295 * @constant 35296 * @type {number} 35297 */ 35298 sizeOf.SHORT = constant(2); 35299 /** 35300 * Convert a 24-bit unsigned integer to a list of 3 bytes. 35301 * @param {number} 35302 * @returns {Array} 35303 */ 35304 encode.UINT24 = function (v) { 35305 return [v >> 16 & 255, 35306 v >> 8 & 255, 35307 v & 255]; 35308 }; 35309 /** 35310 * @constant 35311 * @type {number} 35312 */ 35313 sizeOf.UINT24 = constant(3); 35314 /** 35315 * Convert a 32-bit unsigned integer to a list of 4 bytes. 35316 * @param {number} 35317 * @returns {Array} 35318 */ 35319 encode.ULONG = function (v) { 35320 return [v >> 24 & 255, 35321 v >> 16 & 255, 35322 v >> 8 & 255, 35323 v & 255]; 35324 }; 35325 /** 35326 * @constant 35327 * @type {number} 35328 */ 35329 sizeOf.ULONG = constant(4); 35330 /** 35331 * Convert a 32-bit unsigned integer to a list of 4 bytes. 35332 * @param {number} 35333 * @returns {Array} 35334 */ 35335 encode.LONG = function (v) { 35336 // Two's complement 35337 if (v >= LIMIT32) { 35338 v = - (2 * LIMIT32 - v); 35339 } 35340 return [v >> 24 & 255, 35341 v >> 16 & 255, 35342 v >> 8 & 255, 35343 v & 255]; 35344 }; 35345 /** 35346 * @constant 35347 * @type {number} 35348 */ 35349 sizeOf.LONG = constant(4); 35350 encode.FIXED = encode.ULONG; 35351 sizeOf.FIXED = sizeOf.ULONG; 35352 encode.FWORD = encode.SHORT; 35353 sizeOf.FWORD = sizeOf.SHORT; 35354 encode.UFWORD = encode.USHORT; 35355 sizeOf.UFWORD = sizeOf.USHORT; 35356 /** 35357 * Convert a 32-bit Apple Mac timestamp integer to a list of 8 bytes, 64-bit timestamp. 35358 * @param {number} 35359 * @returns {Array} 35360 */ 35361 encode.LONGDATETIME = function (v) { 35362 return [0, 35363 0, 35364 0, 35365 0, 35366 v >> 24 & 255, 35367 v >> 16 & 255, 35368 v >> 8 & 255, 35369 v & 255]; 35370 }; 35371 /** 35372 * @constant 35373 * @type {number} 35374 */ 35375 sizeOf.LONGDATETIME = constant(8); 35376 /** 35377 * Convert a 4-char tag to a list of 4 bytes. 35378 * @param {string} 35379 * @returns {Array} 35380 */ 35381 encode.TAG = function (v) { 35382 check.argument(v.length === 4, 'Tag should be exactly 4 ASCII characters.'); 35383 return [v.charCodeAt(0), 35384 v.charCodeAt(1), 35385 v.charCodeAt(2), 35386 v.charCodeAt(3)]; 35387 }; 35388 /** 35389 * @constant 35390 * @type {number} 35391 */ 35392 sizeOf.TAG = constant(4); // CFF data types /////////////////////////////////////////////////////////// 35393 encode.Card8 = encode.BYTE; 35394 sizeOf.Card8 = sizeOf.BYTE; 35395 encode.Card16 = encode.USHORT; 35396 sizeOf.Card16 = sizeOf.USHORT; 35397 encode.OffSize = encode.BYTE; 35398 sizeOf.OffSize = sizeOf.BYTE; 35399 encode.SID = encode.USHORT; 35400 sizeOf.SID = sizeOf.USHORT; // Convert a numeric operand or charstring number to a variable-size list of bytes. 35401 /** 35402 * Convert a numeric operand or charstring number to a variable-size list of bytes. 35403 * @param {number} 35404 * @returns {Array} 35405 */ 35406 encode.NUMBER = function (v) { 35407 if (v >= - 107 && v <= 107) { 35408 return [v + 139]; 35409 } else if (v >= 108 && v <= 1131) { 35410 v = v - 108; 35411 return [(v >> 8) + 247, 35412 v & 255]; 35413 } else if (v >= - 1131 && v <= - 108) { 35414 v = - v - 108; 35415 return [(v >> 8) + 251, 35416 v & 255]; 35417 } else if (v >= - 32768 && v <= 32767) { 35418 return encode.NUMBER16(v); 35419 } else { 35420 return encode.NUMBER32(v); 35421 } 35422 }; 35423 /** 35424 * @param {number} 35425 * @returns {number} 35426 */ 35427 sizeOf.NUMBER = function (v) { 35428 return encode.NUMBER(v).length; 35429 }; 35430 /** 35431 * Convert a signed number between -32768 and +32767 to a three-byte value. 35432 * This ensures we always use three bytes, but is not the most compact format. 35433 * @param {number} 35434 * @returns {Array} 35435 */ 35436 encode.NUMBER16 = function (v) { 35437 return [28, 35438 v >> 8 & 255, 35439 v & 255]; 35440 }; 35441 /** 35442 * @constant 35443 * @type {number} 35444 */ 35445 sizeOf.NUMBER16 = constant(3); 35446 /** 35447 * Convert a signed number between -(2^31) and +(2^31-1) to a five-byte value. 35448 * This is useful if you want to be sure you always use four bytes, 35449 * at the expense of wasting a few bytes for smaller numbers. 35450 * @param {number} 35451 * @returns {Array} 35452 */ 35453 encode.NUMBER32 = function (v) { 35454 return [29, 35455 v >> 24 & 255, 35456 v >> 16 & 255, 35457 v >> 8 & 255, 35458 v & 255]; 35459 }; 35460 /** 35461 * @constant 35462 * @type {number} 35463 */ 35464 sizeOf.NUMBER32 = constant(5); 35465 /** 35466 * @param {number} 35467 * @returns {Array} 35468 */ 35469 encode.REAL = function (v) { 35470 var value = v.toString(); // Some numbers use an epsilon to encode the value. (e.g. JavaScript will store 0.0000001 as 1e-7) 35471 // This code converts it back to a number without the epsilon. 35472 var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value); 35473 if (m) { 35474 var epsilon = parseFloat('1e' + ((m[2] ? + m[2] : 0) + m[1].length)); 35475 value = (Math.round(v * epsilon) / epsilon).toString(); 35476 } 35477 var nibbles = ''; 35478 for (var i = 0, ii = value.length; i < ii; i += 1) { 35479 var c = value[i]; 35480 if (c === 'e') { 35481 nibbles += value[++i] === '-' ? 'c' : 'b'; 35482 } else if (c === '.') { 35483 nibbles += 'a'; 35484 } else if (c === '-') { 35485 nibbles += 'e'; 35486 } else { 35487 nibbles += c; 35488 } 35489 } 35490 nibbles += nibbles.length & 1 ? 'f' : 'ff'; 35491 var out = [ 35492 30 35493 ]; 35494 for (var i$1 = 0, ii$1 = nibbles.length; i$1 < ii$1; i$1 += 2) { 35495 out.push(parseInt(nibbles.substr(i$1, 2), 16)); 35496 } 35497 return out; 35498 }; 35499 /** 35500 * @param {number} 35501 * @returns {number} 35502 */ 35503 sizeOf.REAL = function (v) { 35504 return encode.REAL(v).length; 35505 }; 35506 encode.NAME = encode.CHARARRAY; 35507 sizeOf.NAME = sizeOf.CHARARRAY; 35508 encode.STRING = encode.CHARARRAY;
35509 sizeOf.STRING = sizeOf.CHARARRAY; 35510 /** 35511 * @param {DataView} data 35512 * @param {number} offset 35513 * @param {number} numBytes 35514 * @returns {string} 35515 */ 35516 decode.UTF8 = function (data, offset, numBytes) { 35517 var codePoints = [ 35518 ]; 35519 var numChars = numBytes; 35520 for (var j = 0; j < numChars; j++, offset += 1) { 35521 codePoints[j] = data.getUint8(offset); 35522 } 35523 return String.fromCharCode.apply(null, codePoints); 35524 }; 35525 /** 35526 * @param {DataView} data 35527 * @param {number} offset 35528 * @param {number} numBytes 35529 * @returns {string} 35530 */ 35531 decode.UTF16 = function (data, offset, numBytes) { 35532 var codePoints = [ 35533 ]; 35534 var numChars = numBytes / 2; 35535 for (var j = 0; j < numChars; j++, offset += 2) { 35536 codePoints[j] = data.getUint16(offset); 35537 } 35538 return String.fromCharCode.apply(null, codePoints); 35539 }; 35540 /** 35541 * Convert a JavaScript string to UTF16-BE. 35542 * @param {string} 35543 * @returns {Array} 35544 */ 35545 encode.UTF16 = function (v) { 35546 var b = [ 35547 ]; 35548 for (var i = 0; i < v.length; i += 1) { 35549 var codepoint = v.charCodeAt(i); 35550 b[b.length] = codepoint >> 8 & 255; 35551 b[b.length] = codepoint & 255; 35552 } 35553 return b; 35554 }; 35555 /** 35556 * @param {string} 35557 * @returns {number} 35558 */ 35559 sizeOf.UTF16 = function (v) { 35560 return v.length * 2; 35561 }; // Data for converting old eight-bit Macintosh encodings to Unicode. 35562 // This representation is optimized for decoding; encoding is slower 35563 // and needs more memory. The assumption is that all opentype.js users 35564 // want to open fonts, but saving a font will be comparatively rare 35565 // so it can be more expensive. Keyed by IANA character set name. 35566 // 35567 // Python script for generating these strings: 35568 // 35569 // s = u''.join([chr(c).decode('mac_greek') for c in range(128, 256)]) 35570 // print(s.encode('utf-8')) 35571 /** 35572 * @private 35573 */ 35574 var eightBitMacEncodings = { 35575 'x-mac-croatian': // Python: 'mac_croatian' 35576 'Ãà ÃÃÃÃÃáà âäãåçéèêëÃìîïñóòôöõúùûüâ °¢£§â¢Â¶Ã®Šâ¢Â´Â¨â ŽÃâ±â¤â¥âµâââÅ¡â«ÂªÂºÎ©Å¾Ã¸' + '¿¡¬âÆâÄ«Äâ¦Â ÃÃÃÅÅÄâââââ÷â©ââ¬â¹âºÃ»â·âââ°ÃÄÃÄÃÃÃÃÃÃÃÄÃÃÃÃıË˯ÏÃË¸ÃæË', 35577 'x-mac-cyrillic': // Python: 'mac_cyrillic' 35578 'ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐРСТУФХЦЧШЩЪЫЬÐЮЯâ °Ò£§â¢Â¶Ð®©â¢ÐÑâ ÐÑâ±â¤â¥ÑµÒÐÐÑÐÑÐÑÐÑ' + 'ÑР¬âÆââ«»â¦Â ÐÑÐÑÑââââââ÷âÐÑÐÑâÐÑÑабвгдежзийклмнопÑÑÑÑÑÑ ÑÑÑÑÑÑÑÑÑ', 35579 'x-mac-gaelic': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/GAELIC.TXT 35580 'Ãà ÃÃÃÃÃáà âäãåçéèêëÃìîïñóòôöõúùûüâ °¢£§â¢Â¶Ã®©â¢Â´Â¨â ÃÃá¸Â±â¤â¥á¸ÄÄá¸á¸á¸á¸Ä Ä¡á¹Ã¦Ã¸' + 'á¹á¹á¹É¼ÆÅ¿á¹ «»â¦Â ÃÃÃÅÅââââââṡáºÃ¿Å¸á¹ªâ¬â¹âºÅ¶Å·á¹«Â·á»²á»³âÃÃÃÃÃÃÃÃÃÃÃâ£ÃÃÃÃıÃýŴŵáºáº áºáºáºáº', 35581 'x-mac-greek': // Python: 'mac_greek' 35582 'ù²Ã³ÃÃΠà âäΨçéèêë£â¢Ã®Ã¯â¢Â½â°Ã´Ã¶Â¦â¬Ã¹Ã»Ã¼â ÎÎÎÎÎΠî©ΣΪ§â °·Î±â¤â¥Â¥ÎÎÎÎÎÎÎΦΫΨΩ' + 'άάÎΡâΤ«»â¦Â ΥΧÎÎÅââââââ÷ÎÎÎÎÎήίÏÎÏαβÏδεÏγηιξκλμνοÏÏÏÏÏθÏÏÏÏ Î¶ÏÏÎΰÂ', 35583 'x-mac-icelandic': // Python: 'mac_iceland' 35584 'Ãà ÃÃÃÃÃáà âäãåçéèêëÃìîïñóòôöõúùûü𢣧â¢Â¶Ã®©â¢Â´Â¨â ÃÃâ±â¤â¥Â¥ÂµâââÏâ«ÂªÂºÎ©Ã¦Ã¸' + '¿¡¬âÆââ«»â¦Â ÃÃÃÅÅââââââ÷âÿŸââ¬ÃðÃþý·âââ°ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃıË˯ËË˸ËËË', 35585 'x-mac-inuit': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/INUIT.TXT 35586 'ááá áááá±á²á³á´á¸á¹áááááááá¦áá®á¯á°á²á³ááááááá°á¡á¥á¦â¢Â¶á§Â®Â©â¢á¨áªá«á»áááá áááá¯á°á±á²á´áµá ááá' + 'ááááªá¨á©áªá«áâ¦Â á®á¾áááââââââáááááááááááá¿áááááá áááááááá±á²á³á´áµá¶áá á¡á¢á£á¤á¥á¦á¼ÅÅ', 35587 'x-mac-ce': // Python: 'mac_latin2' 35588 'ÃÄÄÃÄÃÃÃ¡Ä ÄäÄÄÄ鏟ÄÃÄÄÄÄóÄôöõúÄÄüâ °Ä£§â¢Â¶Ã®©â¢Ä¨â ģĮįĪâ¤â¥Ä«Ä¶ââÅĻļĽľĹĺŠ' + 'ÅŬâÅÅâ«»â¦Â ÅÅÃÅÅââââââ÷âÅÅÅÅâ¹âºÅÅÅÅ ââÅ¡ÅÅÃŤťÃŽžŪÃÃūŮÃůŰűŲųÃýķŻÅżĢË', 35589 macintosh: // Python: 'mac_roman' 35590 'Ãà ÃÃÃÃÃáà âäãåçéèêëÃìîïñóòôöõúùûüâ °¢£§â¢Â¶Ã®©â¢Â´Â¨â ÃÃâ±â¤â¥Â¥ÂµâââÏâ«ÂªÂºÎ©Ã¦Ã¸' + '¿¡¬âÆââ«»â¦Â ÃÃÃÅÅââââââ÷âÿŸââ¬â¹âºï¬ï¬â¡Â·âââ°ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃıË˯ËË˸ËËË', 35591 'x-mac-romanian': // Python: 'mac_romanian' 35592 'Ãà ÃÃÃÃÃáà âäãåçéèêëÃìîïñóòôöõúùûüâ °¢£§â¢Â¶Ã®©â¢Â´Â¨â ÄÈâ±â¤â¥Â¥ÂµâââÏâ«ÂªÂºÎ©ÄÈ' + '¿¡¬âÆââ«»â¦Â ÃÃÃÅÅââââââ÷âÿŸââ¬â¹âºÈÈâ¡Â·âââ°ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃıË˯ËË˸ËËË', 35593 'x-mac-turkish': // Python: 'mac_turkish' 35594 'Ãà ÃÃÃÃÃáà âäãåçéèêëÃìîïñóòôöõúùûüâ °¢£§â¢Â¶Ã®©â¢Â´Â¨â ÃÃâ±â¤â¥Â¥ÂµâââÏâ«ÂªÂºÎ©Ã¦Ã¸' + '¿¡¬âÆââ«»â¦Â ÃÃÃÅÅââââââ÷âÿŸÄÄİıÅÅâ¡Â·âââ°ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃï¢ Ë˯ËË˸ËËË' 35595 }; 35596 /** 35597 * Decodes an old-style Macintosh string. Returns either a Unicode JavaScript 35598 * string, or 'undefined' if the encoding is unsupported. For example, we do 35599 * not support Chinese, Japanese or Korean because these would need large 35600 * mapping tables. 35601 * @param {DataView} dataView 35602 * @param {number} offset 35603 * @param {number} dataLength 35604 * @param {string} encoding 35605 * @returns {string} 35606 */ 35607 decode.MACSTRING = function (dataView, offset, dataLength, encoding) { 35608 var table = eightBitMacEncodings[encoding]; 35609 if (table === undefined) { 35610 return undefined; 35611 } 35612 var result = ''; 35613 for (var i = 0; i < dataLength; i++) { 35614 var c = dataView.getUint8(offset + i); // In all eight-bit Mac encodings, the characters 0x00..0x7F are 35615 // mapped to U+0000..U+007F; we only need to look up the others. 35616 if (c <= 127) { 35617 result += String.fromCharCode(c); 35618 } else { 35619 result += table[c & 127]; 35620 } 35621 } 35622 return result; 35623 }; // Helper function for encode.MACSTRING. Returns a dictionary for mapping 35624 // Unicode character codes to their 8-bit MacOS equivalent. This table 35625 // is not exactly a super cheap data structure, but we do not care because 35626 // encoding Macintosh strings is only rarely needed in typical applications. 35627 var macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap(); 35628 var macEncodingCacheKeys; 35629 var getMacEncodingTable = function (encoding) { 35630 // Since we use encoding as a cache key for WeakMap, it has to be 35631 // a String object and not a literal. And at least on NodeJS 2.10.1, 35632 // WeakMap requires that the same String instance is passed for cache hits. 35633 if (!macEncodingCacheKeys) { 35634 macEncodingCacheKeys = { 35635 }; 35636 for (var e in eightBitMacEncodings) { 35637 /*jshint -W053 */ 35638 // Suppress "Do not use String as a constructor." 35639 macEncodingCacheKeys[e] = new String(e); 35640 } 35641 } 35642 var cacheKey = macEncodingCacheKeys[encoding]; 35643 if (cacheKey === undefined) { 35644 return undefined; 35645 } // We can't do "if (cache.has(key)) {return cache.get(key)}" here: 35646 // since garbage collection may run at any time, it could also kick in 35647 // between the calls to cache.has() and cache.get(). In that case, 35648 // we would return 'undefined' even though we do support the encoding. 35649 35650 if (macEncodingTableCache) { 35651 var cachedTable = macEncodingTableCache.get(cacheKey); 35652 if (cachedTable !== undefined) { 35653 return cachedTable; 35654 } 35655 } 35656 var decodingTable = eightBitMacEncodings[encoding]; 35657 if (decodingTable === undefined) { 35658 return undefined; 35659 } 35660 var encodingTable = { 35661 }; 35662 for (var i = 0; i < decodingTable.length; i++) { 35663 encodingTable[decodingTable.charCodeAt(i)] = i + 128; 35664 } 35665 if (macEncodingTableCache) { 35666 macEncodingTableCache.set(cacheKey, encodingTable); 35667 } 35668 return encodingTable; 35669 }; 35670 /** 35671 * Encodes an old-style Macintosh string. Returns a byte array upon success. 35672 * If the requested encoding is unsupported, or if the input string contains 35673 * a character that cannot be expressed in the encoding, the function returns 35674 * 'undefined'. 35675 * @param {string} str 35676 * @param {string} encoding 35677 * @returns {Array} 35678 */ 35679 encode.MACSTRING = function (str, encoding) { 35680 var table = getMacEncodingTable(encoding); 35681 if (table === undefined) { 35682 return undefined; 35683 } 35684 var result = [ 35685 ]; 35686 for (var i = 0; i < str.length; i++) { 35687 var c = str.charCodeAt(i); // In all eight-bit Mac encodings, the characters 0x00..0x7F are 35688 // mapped to U+0000..U+007F; we only need to look up the others. 35689 if (c >= 128) { 35690 c = table[c]; 35691 if (c === undefined) { 35692 // str contains a Unicode character that cannot be encoded 35693 // in the requested encoding. 35694 return undefined; 35695 } 35696 } 35697 result[i] = c; // result.push(c); 35698 } 35699 return result; 35700 }; 35701 /** 35702 * @param {string} str 35703 * @param {string} encoding 35704 * @returns {number} 35705 */ 35706 sizeOf.MACSTRING = function (str, encoding) { 35707 var b = encode.MACSTRING(str, encoding); 35708 if (b !== undefined) { 35709 return b.length; 35710 } else { 35711 return 0; 35712 } 35713 }; // Helper for encode.VARDELTAS 35714 function isByteEncodable(value) { 35715 return value >= - 128 && value <= 127; 35716 } // Helper for encode.VARDELTAS 35717 35718 function encodeVarDeltaRunAsZeroes(deltas, pos, result) { 35719 var runLength = 0; 35720 var numDeltas = deltas.length; 35721 while (pos < numDeltas && runLength < 64 && deltas[pos] === 0) { 35722 ++pos; 35723 ++runLength; 35724 } 35725 result.push(128 | runLength - 1); 35726 return pos; 35727 } // Helper for encode.VARDELTAS 35728 35729 function encodeVarDeltaRunAsBytes(deltas, offset, result) { 35730 var runLength = 0; 35731 var numDeltas = deltas.length; 35732 var pos = offset; 35733 while (pos < numDeltas && runLength < 64) { 35734 var value = deltas[pos]; 35735 if (!isByteEncodable(value)) { 35736 break; 35737 } // Within a byte-encoded run of deltas, a single zero is best 35738 // stored literally as 0x00 value. However, if we have two or 35739 // more zeroes in a sequence, it is better to start a new run. 35740 // Fore example, the sequence of deltas [15, 15, 0, 15, 15] 35741 // becomes 6 bytes (04 0F 0F 00 0F 0F) when storing the zero 35742 // within the current run, but 7 bytes (01 0F 0F 80 01 0F 0F) 35743 // when starting a new run. 35744 35745 if (value === 0 && pos + 1 < numDeltas && deltas[pos + 1] === 0) { 35746 break; 35747 } 35748 ++pos; 35749 ++runLength; 35750 } 35751 result.push(runLength - 1); 35752 for (var i = offset; i < pos; ++i) { 35753 result.push(deltas[i] + 256 & 255); 35754 } 35755 return pos; 35756 } // Helper for encode.VARDELTAS 35757 35758 function encodeVarDeltaRunAsWords(deltas, offset, result) { 35759 var runLength = 0; 35760 var numDeltas = deltas.length; 35761 var pos = offset; 35762 while (pos < numDeltas && runLength < 64) { 35763 var value = deltas[pos]; // Within a word-encoded run of deltas, it is easiest to start 35764 // a new run (with a different encoding) whenever we encounter 35765 // a zero value. For example, the sequence [0x6666, 0, 0x7777] 35766 // needs 7 bytes when storing the zero inside the current run 35767 // (42 66 66 00 00 77 77), and equally 7 bytes when starting a 35768 // new run (40 66 66 80 40 77 77). 35769 if (value === 0) { 35770 break; 35771 } // Within a word-encoded run of deltas, a single value in the 35772 // range (-128..127) should be encoded within the current run 35773 // because it is more compact. For example, the sequence 35774 // [0x6666, 2, 0x7777] becomes 7 bytes when storing the value 35775 // literally (42 66 66 00 02 77 77), but 8 bytes when starting 35776 // a new run (40 66 66 00 02 40 77 77). 35777 35778 if (isByteEncodable(value) && pos + 1 < numDeltas && isByteEncodable(deltas[pos + 1])) { 35779 break; 35780 } 35781 ++pos; 35782 ++runLength; 35783 } 35784 result.push(64 | runLength - 1); 35785 for (var i = offset; i < pos; ++i) { 35786 var val = deltas[i]; 35787 result.push(val + 65536 >> 8 & 255, val + 256 & 255); 35788 } 35789 return pos; 35790 } /** 35791 * Encode a list of variation adjustment deltas. 35792 * 35793 * Variation adjustment deltas are used in âgvarâ and âcvarâ tables. 35794 * They indicate how points (in âgvarâ) or values (in âcvarâ) get adjusted 35795 * when generating instances of variation fonts. 35796 * 35797 * @see https://www.microsoft.com/typography/otspec/gvar.htm 35798 * @see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gvar.html 35799 * @param {Array} 35800 * @return {Array} 35801 */ 35802 35803 encode.VARDELTAS = function (deltas) { 35804 var pos = 0; 35805 var result = [ 35806 ]; 35807 while (pos < deltas.length) { 35808 var value = deltas[pos]; 35809 if (value === 0) { 35810 pos = encodeVarDeltaRunAsZeroes(deltas, pos, result); 35811 } else if (value >= - 128 && value <= 127) { 35812 pos = encodeVarDeltaRunAsBytes(deltas, pos, result); 35813 } else { 35814 pos = encodeVarDeltaRunAsWords(deltas, pos, result); 35815 } 35816 } 35817 return result; 35818 }; // Convert a list of values to a CFF INDEX structure. 35819 // The values should be objects containing name / type / value. 35820 /** 35821 * @param {Array} l 35822 * @returns {Array} 35823 */ 35824 encode.INDEX = function (l) { 35825 //var offset, offsets, offsetEncoder, encodedOffsets, encodedOffset, data, 35826 // i, v; 35827 // Beca
35827use we have to know which data type to use to encode the offsets, 35828 // we have to go through the values twice: once to encode the data and 35829 // calculate the offsets, then again to encode the offsets using the fitting data type. 35830 var offset = 1; // First offset is always 1. 35831 var offsets = [ 35832 offset 35833 ]; 35834 var data = [ 35835 ]; 35836 for (var i = 0; i < l.length; i += 1) { 35837 var v = encode.OBJECT(l[i]); 35838 Array.prototype.push.apply(data, v); 35839 offset += v.length; 35840 offsets.push(offset); 35841 } 35842 if (data.length === 0) { 35843 return [0, 35844 0]; 35845 } 35846 var encodedOffsets = [ 35847 ]; 35848 var offSize = 1 + Math.floor(Math.log(offset) / Math.log(2)) / 8 | 0; 35849 var offsetEncoder = [ 35850 undefined, 35851 encode.BYTE, 35852 encode.USHORT, 35853 encode.UINT24, 35854 encode.ULONG 35855 ][offSize]; 35856 for (var i$1 = 0; i$1 < offsets.length; i$1 += 1) { 35857 var encodedOffset = offsetEncoder(offsets[i$1]); 35858 Array.prototype.push.apply(encodedOffsets, encodedOffset); 35859 } 35860 return Array.prototype.concat(encode.Card16(l.length), encode.OffSize(offSize), encodedOffsets, data); 35861 }; 35862 /** 35863 * @param {Array} 35864 * @returns {number} 35865 */ 35866 sizeOf.INDEX = function (v) { 35867 return encode.INDEX(v).length; 35868 }; 35869 /** 35870 * Convert an object to a CFF DICT structure. 35871 * The keys should be numeric. 35872 * The values should be objects containing name / type / value. 35873 * @param {Object} m 35874 * @returns {Array} 35875 */ 35876 encode.DICT = function (m) { 35877 var d = [ 35878 ]; 35879 var keys = Object.keys(m); 35880 var length = keys.length; 35881 for (var i = 0; i < length; i += 1) { 35882 // Object.keys() return string keys, but our keys are always numeric. 35883 var k = parseInt(keys[i], 0); 35884 var v = m[k]; // Value comes before the key. 35885 d = d.concat(encode.OPERAND(v.value, v.type)); 35886 d = d.concat(encode.OPERATOR(k)); 35887 } 35888 return d; 35889 }; 35890 /** 35891 * @param {Object} 35892 * @returns {number} 35893 */ 35894 sizeOf.DICT = function (m) { 35895 return encode.DICT(m).length; 35896 }; 35897 /** 35898 * @param {number} 35899 * @returns {Array} 35900 */ 35901 encode.OPERATOR = function (v) { 35902 if (v < 1200) { 35903 return [v]; 35904 } else { 35905 return [12, 35906 v - 1200]; 35907 } 35908 }; 35909 /** 35910 * @param {Array} v 35911 * @param {string} 35912 * @returns {Array} 35913 */ 35914 encode.OPERAND = function (v, type) { 35915 var d = [ 35916 ]; 35917 if (Array.isArray(type)) { 35918 for (var i = 0; i < type.length; i += 1) { 35919 check.argument(v.length === type.length, 'Not enough arguments given for type' + type); 35920 d = d.concat(encode.OPERAND(v[i], type[i])); 35921 } 35922 } else { 35923 if (type === 'SID') { 35924 d = d.concat(encode.NUMBER(v)); 35925 } else if (type === 'offset') { 35926 // We make it easy for ourselves and always encode offsets as 35927 // 4 bytes. This makes offset calculation for the top dict easier. 35928 d = d.concat(encode.NUMBER32(v)); 35929 } else if (type === 'number') { 35930 d = d.concat(encode.NUMBER(v)); 35931 } else if (type === 'real') { 35932 d = d.concat(encode.REAL(v)); 35933 } else { 35934 throw new Error('Unknown operand type ' + type); // FIXME Add support for booleans 35935 } 35936 } 35937 return d; 35938 }; 35939 encode.OP = encode.BYTE; 35940 sizeOf.OP = sizeOf.BYTE; // memoize charstring encoding using WeakMap if available 35941 var wmm = typeof WeakMap === 'function' && new WeakMap(); 35942 /** 35943 * Convert a list of CharString operations to bytes. 35944 * @param {Array} 35945 * @returns {Array} 35946 */ 35947 encode.CHARSTRING = function (ops) { 35948 // See encode.MACSTRING for why we don't do "if (wmm && wmm.has(ops))". 35949 if (wmm) { 35950 var cachedValue = wmm.get(ops); 35951 if (cachedValue !== undefined) { 35952 return cachedValue; 35953 } 35954 } 35955 var d = [ 35956 ]; 35957 var length = ops.length; 35958 for (var i = 0; i < length; i += 1) { 35959 var op = ops[i]; 35960 d = d.concat(encode[op.type](op.value)); 35961 } 35962 if (wmm) { 35963 wmm.set(ops, d); 35964 } 35965 return d; 35966 }; 35967 /** 35968 * @param {Array} 35969 * @returns {number} 35970 */ 35971 sizeOf.CHARSTRING = function (ops) { 35972 return encode.CHARSTRING(ops).length; 35973 }; // Utility functions //////////////////////////////////////////////////////// 35974 /**
35975 * Convert an object containing name / type / value to bytes. 35976 * @param {Object} 35977 * @returns {Array} 35978 */ 35979 encode.OBJECT = function (v) { 35980 var encodingFunction = encode[v.type]; 35981 check.argument(encodingFunction !== undefined, 'No encoding function for type ' + v.type); 35982 return encodingFunction(v.value); 35983 }; 35984 /** 35985 * @param {Object} 35986 * @returns {number} 35987 */ 35988 sizeOf.OBJECT = function (v) { 35989 var sizeOfFunction = sizeOf[v.type]; 35990 check.argument(sizeOfFunction !== undefined, 'No sizeOf function for type ' + v.type); 35991 return sizeOfFunction(v.value); 35992 }; 35993 /** 35994 * Convert a table object to bytes. 35995 * A table contains a list of fields containing the metadata (name, type and default value). 35996 * The table itself has the field values set as attributes. 35997 * @param {opentype.Table} 35998 * @returns {Array} 35999 */ 36000 encode.TABLE = function (table) { 36001 var d = [ 36002 ]; 36003 var length = table.fields.length; 36004 var subtables = [ 36005 ]; 36006 var subtableOffsets = [ 36007 ]; 36008 for (var i = 0; i < length; i += 1) { 36009 var field = table.fields[i]; 36010 var encodingFunction = encode[field.type]; 36011 check.argument(encodingFunction !== undefined, 'No encoding function for field type ' + field.type + ' (' + field.name + ')'); 36012 var value = table[field.name]; 36013 if (value === undefined) { 36014 value = field.value; 36015 } 36016 var bytes = encodingFunction(value); 36017 if (field.type === 'TABLE') { 36018 subtableOffsets.push(d.length); 36019 d = d.concat([0, 36020 0]); 36021 subtables.push(bytes); 36022 } else { 36023 d = d.concat(bytes); 36024 } 36025 } 36026 for (var i$1 = 0; i$1 < subtables.length; i$1 += 1) { 36027 var o = subtableOffsets[i$1]; 36028 var offset = d.length; 36029 check.argument(offset < 65536, 'Table ' + table.tableName + ' too big.'); 36030 d[o] = offset >> 8; 36031 d[o + 1] = offset & 255; 36032 d = d.concat(subtables[i$1]); 36033 } 36034 return d; 36035 }; 36036 /** 36037 * @param {opentype.Table} 36038 * @returns {number} 36039 */ 36040 sizeOf.TABLE = function (table) { 36041 var numBytes = 0; 36042 var length = table.fields.length; 36043 for (var i = 0; i < length; i += 1) { 36044 var field = table.fields[i]; 36045 var sizeOfFunction = sizeOf[field.type]; 36046 check.argument(sizeOfFunction !== undefined, 'No sizeOf function for field type ' + field.type + ' (' + field.name + ')'); 36047 var value = table[field.name]; 36048 if (value === undefined) { 36049 value = field.value; 36050 } 36051 numBytes += sizeOfFunction(value); // Subtables take 2 more bytes for offsets. 36052 if (field.type === 'TABLE') { 36053 numBytes += 2; 36054 } 36055 } 36056 return numBytes; 36057 }; 36058 encode.RECORD = encode.TABLE; 36059 sizeOf.RECORD = sizeOf.TABLE; // Merge in a list of bytes. 36060 encode.LITERAL = function (v) { 36061 return v; 36062 }; 36063 sizeOf.LITERAL = function (v) { 36064 return v.length; 36065 }; // Table metadata 36066 /** 36067 * @exports opentype.Table 36068 * @class 36069 * @param {string} tableName 36070 * @param {Array} fields 36071 * @param {Object} options 36072 * @constructor 36073 */ 36074 function Table(tableName, fields, options) { 36075 var this$1 = this; 36076 for (var i = 0; i < fields.length; i += 1) { 36077 var field = fields[i]; 36078 this$1[field.name] = field.value; 36079 } 36080 this.tableName = tableName; 36081 this.fields = fields; 36082 if (options) { 36083 var optionKeys = Object.keys(options); 36084 for (var i$1 = 0; i$1 < optionKeys.length; i$1 += 1) { 36085 var k = optionKeys[i$1]; 36086 var v = options[k]; 36087 if (this$1[k] !== undefined) { 36088 this$1[k] = v; 36089 } 36090 } 36091 } 36092 } /** 36093 * Encodes the table and returns an array of bytes 36094 * @return {Array} 36095 */ 36096 36097 Table.prototype.encode = function () { 36098 return encode.TABLE(this); 36099 }; 36100 /** 36101 * Get the size of the table. 36102 * @return {number} 36103 */ 36104 Table.prototype.sizeOf = function () { 36105 return sizeOf.TABLE(this); 36106 }; 36107 /** 36108 * @private 36109 */ 36110 function ushortList(itemName, list, count) { 36111 if (count === undefined) { 36112 count = list.length; 36113 } 36114 var fields = new Array(list.length + 1); 36115 fields[0] = { 36116 name: itemName + 'Count', 36117 type: 'USHORT', 36118 value: count 36119 }; 36120 for (var i = 0; i < list.length; i++) { 36121 fields[i + 1] = { 36122 name: itemName + i, 36123 type: 'USHORT', 36124 value: list[i] 36125 }; 36126 } 36127 return fields; 36128 } /** 36129 * @private 36130 */ 36131 36132 function tableList(itemName, records, itemCallback) { 36133 var count = records.length; 36134 var fields = new Array(count + 1); 36135 fields[0] = { 36136 name: itemName + 'Count', 36137 type: 'USHORT', 36138 value: count 36139 }; 36140 for (var i = 0; i < count; i++) { 36141 fields[i + 1] = { 36142 name: itemName + i, 36143 type: 'TABLE', 36144 value: itemCallback(records[i], i) 36145 }; 36146 } 36147 return fields; 36148 } /** 36149 * @private 36150 */ 36151 36152 function recordList(itemName, records, itemCallback) { 36153 var count = records.length; 36154 var fields = [ 36155 ]; 36156 fields[0] = { 36157 name: itemName + 'Count', 36158 type: 'USHORT', 36159 value: count 36160 }; 36161 for (var i = 0; i < count; i++) { 36162 fields = fields.concat(itemCallback(records[i], i)); 36163 } 36164 return fields; 36165 } // Common Layout Tables 36166 /** 36167 * @exports opentype.Coverage 36168 * @class 36169 * @param {opentype.Table} 36170 * @constructor 36171 * @extends opentype.Table 36172 */ 36173 36174 function Coverage(coverageTable) { 36175 if (coverageTable.format === 1) { 36176 Table.call(this, 'coverageTable', [ 36177 { 36178 name: 'coverageFormat', 36179 type: 'USHORT', 36180 value: 1 36181 } 36182 ].concat(ushortList('glyph', coverageTable.glyphs))); 36183 } else { 36184 check.assert(false, 'Can\'t create coverage table format 2 yet.'); 36185 } 36186 } 36187 Coverage.prototype = Object.create(Table.prototype); 36188 Coverage.prototype.constructor = Coverage; 36189 function ScriptList(scriptListTable) { 36190 Table.call(this, 'scriptListTable', recordList('scriptRecord', scriptListTable, function (scriptRecord, i) { 36191 var script = scriptRecord.script; 36192 var defaultLangSys = script.defaultLangSys; 36193 check.assert(!!defaultLangSys, 'Unable to write GSUB: script ' + scriptRecord.tag + ' has no default language system.'); 36194 return [{ 36195 name: 'scriptTag' + i, 36196 type: 'TAG', 36197 value: scriptRecord.tag 36198 }, 36199 { 36200 name: 'script' + i, 36201 type: 'TABLE', 36202 value: new Table('scriptTable', [ 36203 { 36204 name: 'defaultLangSys', 36205 type: 'TABLE', 36206 value: new Table('defaultLangSys', [ 36207 { 36208 name: 'lookupOrder', 36209 type: 'USHORT', 36210 value: 0 36211 }, 36212 { 36213 name: 'reqFeatureIndex', 36214 type: 'USHORT', 36215 value: defaultLangSys.reqFeatureIndex 36216 } 36217 ].concat(ushortList('featureIndex', defaultLangSys.featureIndexes))) 36218 } 36219 ].concat(recordList('langSys', script.langSysRecords, function (langSysRecord, i) { 36220 var langSys = langSysRecord.langSys; 36221 return [{ 36222 name: 'langSysTag' + i, 36223 type: 'TAG', 36224 value: langSysRecord.tag 36225 }, 36226 { 36227 name: 'langSys' + i, 36228 type: 'TABLE', 36229 value: new Table('langSys', [ 36230 { 36231 name: 'lookupOrder', 36232 type: 'USHORT', 36233 value: 0 36234 }, 36235 { 36236 name: 'reqFeatureIndex', 36237 type: 'USHORT', 36238 value: langSys.reqFeatureIndex 36239 } 36240 ].concat(ushortList('featureIndex', langSys.featureIndexes))) 36241 } 36242 ]; 36243 }))) 36244 } 36245 ]; 36246 })); 36247 } 36248 ScriptList.prototype = Object.create(Table.prototype); 36249 ScriptList.prototype.constructor = ScriptList; 36250 /** 36251 * @exports opentype.FeatureList 36252 * @class 36253 * @param {opentype.Table} 36254 * @constructor 36255 * @extends opentype.Table 36256 */ 36257 function FeatureList(featureListTable) { 36258 Table.call(this, 'featureListTable', recordList('featureRecord', featureListTable, function (featureRecord, i) { 36259 var feature = featureRecord.feature; 36260 return [{ 36261 name: 'featureTag' + i, 36262 type: 'TAG', 36263 value: featureRecord.tag 36264 }, 36265 { 36266 name: 'feature' + i, 36267 type: 'TABLE', 36268 value: new Table('featureTable', [ 36269 {
36270 name: 'featureParams', 36271 type: 'USHORT', 36272 value: feature.featureParams 36273 } 36274 ].concat(ushortList('lookupListIndex', feature.lookupListIndexes))) 36275 } 36276 ]; 36277 })); 36278 } 36279 FeatureList.prototype = Object.create(Table.prototype); 36280 FeatureList.prototype.constructor = FeatureList; 36281 /** 36282 * @exports opentype.LookupList 36283 * @class 36284 * @param {opentype.Table} 36285 * @param {Object} 36286 * @constructor 36287 * @extends opentype.Table 36288 */ 36289 function LookupList(lookupListTable, subtableMakers) { 36290 Table.call(this, 'lookupListTable', tableList('lookup', lookupListTable, function (lookupTable) { 36291 var subtableCallback = subtableMakers[lookupTable.lookupType]; 36292 check.assert(!!subtableCallback, 'Unable to write GSUB lookup type ' + lookupTable.lookupType + ' tables.'); 36293 return new Table('lookupTable', [ 36294 { 36295 name: 'lookupType', 36296 type: 'USHORT', 36297 value: lookupTable.lookupType 36298 }, 36299 { 36300 name: 'lookupFlag', 36301 type: 'USHORT', 36302 value: lookupTable.lookupFlag 36303 } 36304 ].concat(tableList('subtable', lookupTable.subtables, subtableCallback))); 36305 })); 36306 } 36307 LookupList.prototype = Object.create(Table.prototype); 36308 LookupList.prototype.constructor = LookupList; // Record = same as Table, but inlined (a Table has an offset and its data is further in the stream) 36309 // Don't use offsets inside Records (probable bug), only in Tables. 36310 var table = { 36311 Table: Table, 36312 Record: Table, 36313 Coverage: Coverage, 36314 ScriptList: ScriptList, 36315 FeatureList: FeatureList, 36316 LookupList: LookupList, 36317 ushortList: ushortList, 36318 tableList: tableList, 36319 recordList: recordList 36320 }; // Parsing utility functions 36321 // Retrieve an unsigned byte from the DataView. 36322 function getByte(dataView, offset) { 36323 return dataView.getUint8(offset); 36324 } // Retrieve an unsigned 16-bit short from the DataView. 36325 // The value is stored in big endian. 36326 36327 function getUShort(dataView, offset) { 36328 return dataView.getUint16(offset, false); 36329 } // Retrieve a signed 16-bit short from the DataView. 36330 // The value is stored in big endian. 36331 36332 function getShort(dataView, offset) { 36333 return dataView.getInt16(offset, false); 36334 } // Retrieve an unsigned 32-bit long from the DataView. 36335 // The value is stored in big endian. 36336 36337 function getULong(dataView, offset) { 36338 return dataView.getUint32(offset, false); 36339 } // Retrieve a 32-bit signed fixed-point number (16.16) from the DataView. 36340 // The value is stored in big endian. 36341 36342 function getFixed(dataView, offset) { 36343 var decimal = dataView.getInt16(offset, false); 36344 var fraction = dataView.getUint16(offset + 2, false); 36345 return decimal + fraction / 65535; 36346 } // Retrieve a 4-character tag from the DataView. 36347 // Tags are used to identify tables. 36348 36349 function getTag(dataView, offset) { 36350 var tag = ''; 36351 for (var i = offset; i < offset + 4; i += 1) { 36352 tag += String.fromCharCode(dataView.getInt8(i)); 36353 } 36354 return tag; 36355 } // Retrieve an offset from the DataView. 36356 // Offsets are 1 to 4 bytes in length, depending on the offSize argument. 36357 36358 function getOffset(dataView, offset, offSize) { 36359 var v = 0; 36360 for (var i = 0; i < offSize; i += 1) { 36361 v <<= 8; 36362 v += dataView.getUint8(offset + i); 36363 } 36364 return v; 36365 } // Retrieve a number of bytes from start offset to the end offset from the DataView. 36366 36367 function getBytes(dataView, startOffset, endOffset) { 36368 var bytes = [ 36369 ]; 36370 for (var i = startOffset; i < endOffset; i += 1) { 36371 bytes.push(dataView.getUint8(i)); 36372 } 36373 return bytes; 36374 }
vendor: 6,627 bytes, lines 36374-36518
36374 // Convert the list of bytes to a string. 36375 36376 function bytesToString(bytes) { 36377 var s = ''; 36378 for (var i = 0; i < bytes.length; i += 1) { 36379 s += String.fromCharCode(bytes[i]); 36380 } 36381 return s; 36382 } 36383 var typeOffsets = { 36384 byte: 1, 36385 uShort: 2, 36386 short: 2, 36387 uLong: 4, 36388 fixed: 4, 36389 longDateTime: 8, 36390 tag: 4 36391 }; // A stateful parser that changes the offset whenever a value is retrieved. 36392 // The data is a DataView. 36393 function Parser(data, offset) { 36394 this.data = data; 36395 this.offset = offset; 36396 this.relativeOffset = 0; 36397 } 36398 Parser.prototype.parseByte = function () { 36399 var v = this.data.getUint8(this.offset + this.relativeOffset); 36400 this.relativeOffset += 1; 36401 return v; 36402 }; 36403 Parser.prototype.parseChar = function () { 36404 var v = this.data.getInt8(this.offset + this.relativeOffset); 36405 this.relativeOffset += 1; 36406 return v; 36407 }; 36408 Parser.prototype.parseCard8 = Parser.prototype.parseByte; 36409 Parser.prototype.parseUShort = function () { 36410 var v = this.data.getUint16(this.offset + this.relativeOffset); 36411 this.relativeOffset += 2; 36412 return v; 36413 }; 36414 Parser.prototype.parseCard16 = Parser.prototype.parseUShort; 36415 Parser.prototype.parseSID = Parser.prototype.parseUShort; 36416 Parser.prototype.parseOffset16 = Parser.prototype.parseUShort; 36417 Parser.prototype.parseShort = function () { 36418 var v = this.data.getInt16(this.offset + this.relativeOffset); 36419 this.relativeOffset += 2; 36420 return v; 36421 }; 36422 Parser.prototype.parseF2Dot14 = function () { 36423 var v = this.data.getInt16(this.offset + this.relativeOffset) / 16384; 36424 this.relativeOffset += 2; 36425 return v; 36426 }; 36427 Parser.prototype.parseULong = function () { 36428 var v = getULong(this.data, this.offset + this.relativeOffset); 36429 this.relativeOffset += 4; 36430 return v; 36431 }; 36432 Parser.prototype.parseOffset32 = Parser.prototype.parseULong; 36433 Parser.prototype.parseFixed = function () { 36434 var v = getFixed(this.data, this.offset + this.relativeOffset); 36435 this.relativeOffset += 4; 36436 return v; 36437 }; 36438 Parser.prototype.parseString = function (length) { 36439 var dataView = this.data; 36440 var offset = this.offset + this.relativeOffset; 36441 var string = ''; 36442 this.relativeOffset += length; 36443 for (var i = 0; i < length; i++) { 36444 string += String.fromCharCode(dataView.getUint8(offset + i)); 36445 } 36446 return string; 36447 }; 36448 Parser.prototype.parseTag = function () { 36449 return this.parseString(4); 36450 }; // LONGDATETIME is a 64-bit integer. 36451 // JavaScript and unix timestamps traditionally use 32 bits, so we 36452 // only take the last 32 bits. 36453 // + Since until 2038 those bits will be filled by zeros we can ignore them. 36454 Parser.prototype.parseLongDateTime = function () { 36455 var v = getULong(this.data, this.offset + this.relativeOffset + 4); // Subtract seconds between 01/01/1904 and 01/01/1970 36456 // to convert Apple Mac timestamp to Standard Unix timestamp 36457 v -= 2082844800; 36458 this.relativeOffset += 8; 36459 return v; 36460 }; 36461 Parser.prototype.parseVersion = function (minorBase) { 36462 var major = getUShort(this.data, this.offset + this.relativeOffset); // How to interpret the minor version is very vague in the spec. 0x5000 is 5, 0x1000 is 1 36463 // Default returns the correct number if minor = 0xN000 where N is 0-9 36464 // Set minorBase to 1 for tables that use minor = N where N is 0-9 36465 var minor = getUShort(this.data, this.offset + this.relativeOffset + 2); 36466 this.relativeOffset += 4; 36467 if (minorBase === undefined) { 36468 minorBase = 4096; 36469 } 36470 return major + minor / minorBase / 10; 36471 }; 36472 Parser.prototype.skip = function (type, amount) { 36473 if (amount === undefined) { 36474 amount = 1; 36475 } 36476 this.relativeOffset += typeOffsets[type] * amount; 36477 }; ///// Parsing lists and records /////////////////////////////// 36478 // Parse a list of 32 bit unsigned integers. 36479 Parser.prototype.parseULongList = function (count) { 36480 if (count === undefined) { 36481 count = this.parseULong(); 36482 } 36483 var offsets = new Array(count); 36484 var dataView = this.data; 36485 var offset = this.offset + this.relativeOffset; 36486 for (var i = 0; i < count; i++) { 36487 offsets[i] = dataView.getUint32(offset); 36488 offset += 4; 36489 } 36490 this.relativeOffset += count * 4; 36491 return offsets; 36492 }; // Parse a list of 16 bit unsigned integers. The length of the list can be read on the stream 36493 // or provided as an argument. 36494 Parser.prototype.parseOffset16List = Parser.prototype.parseUShortList = function (count) { 36495 if (count === undefined) { 36496 count = this.parseUShort(); 36497 } 36498 var offsets = new Array(count); 36499 var dataView = this.data; 36500 var offset = this.offset + this.relativeOffset; 36501 for (var i = 0; i < count; i++) { 36502 offsets[i] = dataView.getUint16(offset); 36503 offset += 2; 36504 } 36505 this.relativeOffset += count * 2; 36506 return offsets; 36507 }; // Parses a list of 16 bit signed integers. 36508 Parser.prototype.parseShortList = function (count) { 36509 var list = new Array(count); 36510 var dataView = this.data; 36511 var offset = this.offset + this.relativeOffset; 36512 for (var i = 0; i < count; i++) { 36513 list[i] = dataView.getInt16(offset); 36514 offset += 2; 36515 } 36516 this.relativeOffset += count * 2; 36517 return list; 36518 };
36518 // Parses a list of bytes. 36519 Parser.prototype.parseByteList = function (count) { 36520 var list = new Array(count); 36521 var dataView = this.data; 36522 var offset = this.offset + this.relativeOffset; 36523 for (var i = 0; i < count; i++) { 36524 list[i] = dataView.getUint8(offset++); 36525 } 36526 this.relativeOffset += count; 36527 return list; 36528 }; 36529 /** 36530 * Parse a list of items. 36531 * Record count is optional, if omitted it is read from the stream. 36532 * itemCallback is one of the Parser methods. 36533 */ 36534 Parser.prototype.parseList = function (count, itemCallback) { 36535 var this$1 = this; 36536 if (!itemCallback) { 36537 itemCallback = count; 36538 count = this.parseUShort(); 36539 } 36540 var list = new Array(count); 36541 for (var i = 0; i < count; i++) { 36542 list[i] = itemCallback.call(this$1); 36543 } 36544 return list; 36545 }; 36546 Parser.prototype.parseList32 = function (count, itemCallback) { 36547 var this$1 = this; 36548 if (!itemCallback) { 36549 itemCallback = count; 36550 count = this.parseULong(); 36551 } 36552 var list = new Array(count); 36553 for (var i = 0; i < count; i++) { 36554 list[i] = itemCallback.call(this$1); 36555 } 36556 return list; 36557 }; 36558 /** 36559 * Parse a list of records. 36560 * Record count is optional, if omitted it is read from the stream. 36561 * Example of recordDescription: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort } 36562 */ 36563 Parser.prototype.parseRecordList = function (count, recordDescription) { 36564 var this$1 = this; // If the count argument is absent, read it in the stream. 36565 if (!recordDescription) { 36566 recordDescription = count; 36567 count = this.parseUShort(); 36568 } 36569 var records = new Array(count); 36570 var fields = Object.keys(recordDescription); 36571 for (var i = 0; i < count; i++) { 36572 var rec = { 36573 }; 36574 for (var j = 0; j < fields.length; j++) { 36575 var fieldName = fields[j]; 36576 var fieldType = recordDescription[fieldName]; 36577 rec[fieldName] = fieldType.call(this$1); 36578 } 36579 records[i] = rec; 36580 } 36581 return records; 36582 }; 36583 Parser.prototype.parseRecordList32 = function (count, recordDescription) { 36584 var this$1 = this; // If the count argument is absent, read it in the stream. 36585 if (!recordDescription) { 36586 recordDescription = count; 36587 count = this.parseULong(); 36588 } 36589 var records = new Array(count); 36590 var fields = Object.keys(recordDescription); 36591 for (var i = 0; i < count; i++) { 36592 var rec = { 36593 }; 36594 for (var j = 0; j < fields.length; j++) { 36595 var fieldName = fields[j]; 36596 var fieldType = recordDescription[fieldName]; 36597 rec[fieldName] = fieldType.call(this$1); 36598 } 36599 records[i] = rec; 36600 } 36601 return records; 36602 }; // Parse a data structure into an object 36603 // Example of description: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort } 36604 Parser.prototype.parseStruct = function (description) { 36605 var this$1 = this; 36606 if (typeof description === 'function') { 36607 return description.call(this); 36608 } else { 36609 var fields = Object.keys(description); 36610 var struct = { 36611 }; 36612 for (var j = 0; j < fields.length; j++) { 36613 var fieldName = fields[j]; 36614 var fieldType = description[fieldName]; 36615 struct[fieldName] = fieldType.call(this$1); 36616 } 36617 return struct; 36618 } 36619 }; 36620 /** 36621 * Parse a GPOS valueRecord
36622 * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record 36623 * valueFormat is optional, if omitted it is read from the stream. 36624 */ 36625 Parser.prototype.parseValueRecord = function (valueFormat) { 36626 if (valueFormat === undefined) { 36627 valueFormat = this.parseUShort(); 36628 } 36629 if (valueFormat === 0) { 36630 // valueFormat2 in kerning pairs is most often 0 36631 // in this case return undefined instead of an empty object, to save space 36632 return; 36633 } 36634 var valueRecord = { 36635 }; 36636 if (valueFormat & 1) { 36637 valueRecord.xPlacement = this.parseShort(); 36638 } 36639 if (valueFormat & 2) { 36640 valueRecord.yPlacement = this.parseShort(); 36641 } 36642 if (valueFormat & 4) { 36643 valueRecord.xAdvance = this.parseShort(); 36644 } 36645 if (valueFormat & 8) { 36646 valueRecord.yAdvance = this.parseShort(); 36647 } // Device table (non-variable font) / VariationIndex table (variable font) not supported 36648 // https://docs.microsoft.com/fr-fr/typography/opentype/spec/chapter2#devVarIdxTbls 36649 36650 if (valueFormat & 16) { 36651 valueRecord.xPlaDevice = undefined; 36652 this.parseShort(); 36653 } 36654 if (valueFormat & 32) { 36655 valueRecord.yPlaDevice = undefined; 36656 this.parseShort(); 36657 } 36658 if (valueFormat & 64) { 36659 valueRecord.xAdvDevice = undefined; 36660 this.parseShort(); 36661 } 36662 if (valueFormat & 128) { 36663 valueRecord.yAdvDevice = undefined; 36664 this.parseShort(); 36665 } 36666 return valueRecord; 36667 }; 36668 /** 36669 * Parse a list of GPOS valueRecords 36670 * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record 36671 * valueFormat and valueCount are read from the stream. 36672 */ 36673 Parser.prototype.parseValueRecordList = function () { 36674 var this$1 = this; 36675 var valueFormat = this.parseUShort(); 36676 var valueCount = this.parseUShort(); 36677 var values = new Array(valueCount); 36678 for (var i = 0; i < valueCount; i++) { 36679 values[i] = this$1.parseValueRecord(valueFormat); 36680 } 36681 return values; 36682 }; 36683 Parser.prototype.parsePointer = function (description) { 36684 var structOffset = this.parseOffset16(); 36685 if (structOffset > 0) { 36686 // NULL offset => return undefined 36687 return new Parser(this.data, this.offset + structOffset).parseStruct(description); 36688 } 36689 return undefined; 36690 }; 36691 Parser.prototype.parsePointer32 = function (description) { 36692 var structOffset = this.parseOffset32(); 36693 if (structOffset > 0) { 36694 // NULL offset => return undefined 36695 return new Parser(this.data, this.offset + structOffset).parseStruct(description); 36696 } 36697 return undefined; 36698 }; 36699 /** 36700 * Parse a list of offsets to lists of 16-bit integers, 36701 * or a list of offsets to lists of offsets to any kind of items. 36702 * If itemCallback is not provided, a list of list of UShort is assumed. 36703 * If provided, itemCallback is called on each item and must parse the item. 36704 * See examples in tables/gsub.js 36705 */ 36706 Parser.prototype.parseListOfLists = function (itemCallback) { 36707 var this$1 = this; 36708 var offsets = this.parseOffset16List(); 36709 var count = offsets.length; 36710 var relativeOffset = this.relativeOffset; 36711 var list = new Array(count); 36712 for (var i = 0; i < count; i++) { 36713 var start = offsets[i]; 36714 if (start === 0) { 36715 // NULL offset 36716 // Add i as owned property to list. Convenient with assert. 36717 list[i] = undefined; 36718 continue; 36719 } 36720 this$1.relativeOffset = start; 36721 if (itemCallback) { 36722 var subOffsets = this$1.parseOffset16List(); 36723 var subList = new Array(subOffsets.length); 36724 for (var j = 0; j < subOffsets.length; j++) { 36725 this$1.relativeOffset = start + subOffsets[j]; 36726 subList[j] = itemCallback.call(this$1); 36727 } 36728 list[i] = subList; 36729 } else { 36730 list[i] = this$1.parseUShortList(); 36731 } 36732 } 36733 this.relativeOffset = relativeOffset; 36734 return list; 36735 };
vendor: 13,826 bytes, lines 36735-37015
36735 ///// Complex tables parsing ////////////////////////////////// 36736 // Parse a coverage table in a GSUB, GPOS or GDEF table. 36737 // https://www.microsoft.com/typography/OTSPEC/chapter2.htm 36738 // parser.offset must point to the start of the table containing the coverage. 36739 Parser.prototype.parseCoverage = function () { 36740 var this$1 = this; 36741 var startOffset = this.offset + this.relativeOffset; 36742 var format = this.parseUShort(); 36743 var count = this.parseUShort(); 36744 if (format === 1) { 36745 return { 36746 format: 1, 36747 glyphs: this.parseUShortList(count) 36748 }; 36749 } else if (format === 2) { 36750 var ranges = new Array(count); 36751 for (var i = 0; i < count; i++) { 36752 ranges[i] = { 36753 start: this$1.parseUShort(), 36754 end: this$1.parseUShort(), 36755 index: this$1.parseUShort() 36756 }; 36757 } 36758 return { 36759 format: 2, 36760 ranges: ranges 36761 }; 36762 } 36763 throw new Error('0x' + startOffset.toString(16) + ': Coverage format must be 1 or 2.'); 36764 }; // Parse a Class Definition Table in a GSUB, GPOS or GDEF table. 36765 // https://www.microsoft.com/typography/OTSPEC/chapter2.htm 36766 Parser.prototype.parseClassDef = function () { 36767 var startOffset = this.offset + this.relativeOffset; 36768 var format = this.parseUShort(); 36769 if (format === 1) { 36770 return { 36771 format: 1, 36772 startGlyph: this.parseUShort(), 36773 classes: this.parseUShortList() 36774 }; 36775 } else if (format === 2) { 36776 return { 36777 format: 2, 36778 ranges: this.parseRecordList({ 36779 start: Parser.uShort, 36780 end: Parser.uShort, 36781 classId: Parser.uShort 36782 }) 36783 }; 36784 } 36785 throw new Error('0x' + startOffset.toString(16) + ': ClassDef format must be 1 or 2.'); 36786 }; ///// Static methods /////////////////////////////////// 36787 // These convenience methods can be used as callbacks and should be called with "this" context set to a Parser instance. 36788 Parser.list = function (count, itemCallback) { 36789 return function () { 36790 return this.parseList(count, itemCallback); 36791 }; 36792 }; 36793 Parser.list32 = function (count, itemCallback) { 36794 return function () { 36795 return this.parseList32(count, itemCallback); 36796 }; 36797 }; 36798 Parser.recordList = function (count, recordDescription) { 36799 return function () { 36800 return this.parseRecordList(count, recordDescription); 36801 }; 36802 }; 36803 Parser.recordList32 = function (count, recordDescription) { 36804 return function () { 36805 return this.parseRecordList32(count, recordDescription); 36806 }; 36807 }; 36808 Parser.pointer = function (description) { 36809 return function () { 36810 return this.parsePointer(description); 36811 }; 36812 }; 36813 Parser.pointer32 = function (description) { 36814 return function () { 36815 return this.parsePointer32(description); 36816 }; 36817 }; 36818 Parser.tag = Parser.prototype.parseTag; 36819 Parser.byte = Parser.prototype.parseByte; 36820 Parser.uShort = Parser.offset16 = Parser.prototype.parseUShort; 36821 Parser.uShortList = Parser.prototype.parseUShortList; 36822 Parser.uLong = Parser.offset32 = Parser.prototype.parseULong; 36823 Parser.uLongList = Parser.prototype.parseULongList; 36824 Parser.struct = Parser.prototype.parseStruct; 36825 Parser.coverage = Parser.prototype.parseCoverage; 36826 Parser.classDef = Parser.prototype.parseClassDef; ///// Script, Feature, Lookup lists /////////////////////////////////////////////// 36827 // https://www.microsoft.com/typography/OTSPEC/chapter2.htm 36828 var langSysTable = { 36829 reserved: Parser.uShort, 36830 reqFeatureIndex: Parser.uShort, 36831 featureIndexes: Parser.uShortList 36832 }; 36833 Parser.prototype.parseScriptList = function () { 36834 return this.parsePointer(Parser.recordList({ 36835 tag: Parser.tag, 36836 script: Parser.pointer({ 36837 defaultLangSys: Parser.pointer(langSysTable), 36838 langSysRecords: Parser.recordList({ 36839 tag: Parser.tag, 36840 langSys: Parser.pointer(langSysTable) 36841 }) 36842 }) 36843 })) || [ 36844 ]; 36845 }; 36846 Parser.prototype.parseFeatureList = function () { 36847 return this.parsePointer(Parser.recordList({ 36848 tag: Parser.tag, 36849 feature: Parser.pointer({ 36850 featureParams: Parser.offset16, 36851 lookupListIndexes: Parser.uShortList 36852 }) 36853 })) || [ 36854 ]; 36855 }; 36856 Parser.prototype.parseLookupList = function (lookupTableParsers) { 36857 return this.parsePointer(Parser.list(Parser.pointer(function () { 36858 var lookupType = this.parseUShort(); 36859 check.argument(1 <= lookupType && lookupType <= 9, 'GPOS/GSUB lookup type ' + lookupType + ' unknown.'); 36860 var lookupFlag = this.parseUShort(); 36861 var useMarkFilteringSet = lookupFlag & 16; 36862 return { 36863 lookupType: lookupType, 36864 lookupFlag: lookupFlag, 36865 subtables: this.parseList(Parser.pointer(lookupTableParsers[lookupType])), 36866 markFilteringSet: useMarkFilteringSet ? this.parseUShort() : undefined 36867 }; 36868 }))) || [ 36869 ]; 36870 }; 36871 Parser.prototype.parseFeatureVariationsList = function () { 36872 return this.parsePointer32(function () { 36873 var majorVersion = this.parseUShort(); 36874 var minorVersion = this.parseUShort(); 36875 check.argument(majorVersion === 1 && minorVersion < 1, 'GPOS/GSUB feature variations table unknown.'); 36876 var featureVariations = this.parseRecordList32({ 36877 conditionSetOffset: Parser.offset32, 36878 featureTableSubstitutionOffset: Parser.offset32 36879 }); 36880 return featureVariations; 36881 }) || [ 36882 ]; 36883 }; 36884 var parse = { 36885 getByte: getByte, 36886 getCard8: getByte, 36887 getUShort: getUShort, 36888 getCard16: getUShort, 36889 getShort: getShort, 36890 getULong: getULong, 36891 getFixed: getFixed, 36892 getTag: getTag, 36893 getOffset: getOffset, 36894 getBytes: getBytes, 36895 bytesToString: bytesToString, 36896 Parser: Parser 36897 }; // The `cmap` table stores the mappings from characters to glyphs. 36898 function parseCmapTableFormat12(cmap, p) { 36899 //Skip reserved. 36900 p.parseUShort(); // Length in bytes of the sub-tables. 36901 cmap.length = p.parseULong(); 36902 cmap.language = p.parseULong(); 36903 var groupCount; 36904 cmap.groupCount = groupCount = p.parseULong(); 36905 cmap.glyphIndexMap = { 36906 }; 36907 for (var i = 0; i < groupCount; i += 1) { 36908 var startCharCode = p.parseULong(); 36909 var endCharCode = p.parseULong(); 36910 var startGlyphId = p.parseULong(); 36911 for (var c = startCharCode; c <= endCharCode; c += 1) { 36912 cmap.glyphIndexMap[c] = startGlyphId; 36913 startGlyphId++; 36914 } 36915 } 36916 } 36917 function parseCmapTableFormat4(cmap, p, data, start, offset) { 36918 // Length in bytes of the sub-tables. 36919 cmap.length = p.parseUShort(); 36920 cmap.language = p.parseUShort(); // segCount is stored x 2. 36921 var segCount; 36922 cmap.segCount = segCount = p.parseUShort() >> 1; // Skip searchRange, entrySelector, rangeShift. 36923 p.skip('uShort', 3); // The "unrolled" mapping from character codes to glyph indices. 36924 cmap.glyphIndexMap = { 36925 }; 36926 var endCountParser = new parse.Parser(data, start + offset + 14); 36927 var startCountParser = new parse.Parser(data, start + offset + 16 + segCount * 2); 36928 var idDeltaParser = new parse.Parser(data, start + offset + 16 + segCount * 4); 36929 var idRangeOffsetParser = new parse.Parser(data, start + offset + 16 + segCount * 6); 36930 var glyphIndexOffset = start + offset + 16 + segCount * 8; 36931 for (var i = 0; i < segCount - 1; i += 1) { 36932 var glyphIndex = void 0; 36933 var endCount = endCountParser.parseUShort(); 36934 var startCount = startCountParser.parseUShort(); 36935 var idDelta = idDeltaParser.parseShort(); 36936 var idRangeOffset = idRangeOffsetParser.parseUShort(); 36937 for (var c = startCount; c <= endCount; c += 1) { 36938 if (idRangeOffset !== 0) { 36939 // The idRangeOffset is relative to the current position in the idRangeOffset array. 36940 // Take the current offset in the idRangeOffset array. 36941 glyphIndexOffset = idRangeOffsetParser.offset + idRangeOffsetParser.relativeOffset - 2; // Add the value of the idRangeOffset, which will move us into the glyphIndex array. 36942 glyphIndexOffset += idRangeOffset; // Then add the character index of the current segment, multiplied by 2 for USHORTs. 36943 glyphIndexOffset += (c - startCount) * 2; 36944 glyphIndex = parse.getUShort(data, glyphIndexOffset); 36945 if (glyphIndex !== 0) { 36946 glyphIndex = glyphIndex + idDelta & 65535; 36947 } 36948 } else { 36949 glyphIndex = c + idDelta & 65535; 36950 } 36951 cmap.glyphIndexMap[c] = glyphIndex; 36952 } 36953 } 36954 } // Parse the `cmap` table. This table stores the mappings from characters to glyphs. 36955 // There are many available formats, but we only support the Windows format 4 and 12. 36956 // This function returns a `CmapEncoding` object or null if no supported format could be found. 36957 36958 function parseCmapTable(data, start) { 36959 var cmap = { 36960 }; 36961 cmap.version = parse.getUShort(data, start); 36962 check.argument(cmap.version === 0, 'cmap table version should be 0.'); // The cmap table can contain many sub-tables, each with their own format. 36963 // We're only interested in a "platform 0" (Unicode format) and "platform 3" (Windows format) table. 36964 cmap.numTables = parse.getUShort(data, start + 2); 36965 var offset = - 1; 36966 for (var i = cmap.numTables - 1; i >= 0; i -= 1) { 36967 var platformId = parse.getUShort(data, start + 4 + i * 8); 36968 var encodingId = parse.getUShort(data, start + 4 + i * 8 + 2); 36969 if (platformId === 3 && (encodingId === 0 || encodingId === 1 || encodingId === 10) || platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 2 || encodingId === 3 || encodingId === 4)) { 36970 offset = parse.getULong(data, start + 4 + i * 8 + 4); 36971 break; 36972 } 36973 } 36974 if (offset === - 1) { 36975 // There is no cmap table in the font that we support. 36976 throw new Error('No valid cmap sub-tables found.'); 36977 } 36978 var p = new parse.Parser(data, start + offset); 36979 cmap.format = p.parseUShort(); 36980 if (cmap.format === 12) { 36981 parseCmapTableFormat12(cmap, p); 36982 } else if (cmap.format === 4) { 36983 parseCmapTableFormat4(cmap, p, data, start, offset); 36984 } else { 36985 throw new Error('Only format 4 and 12 cmap tables are supported (found format ' + cmap.format + ').'); 36986 } 36987 return cmap; 36988 } 36989 function addSegment(t, code, glyphIndex) { 36990 t.segments.push({ 36991 end: code, 36992 start: code, 36993 delta: - (code - glyphIndex), 36994 offset: 0, 36995 glyphIndex: glyphIndex 36996 }); 36997 } 36998 function addTerminatorSegment(t) { 36999 t.segments.push({ 37000 end: 65535, 37001 start: 65535, 37002 delta: 1, 37003 offset: 0 37004 }); 37005 } // Make cmap table, format 4 by default, 12 if needed only 37006 37007 function makeCmapTable(glyphs) { 37008 // Plan 0 is the base Unicode Plan but emojis, for example are on another plan, and needs cmap 12 format (with 32bit) 37009 var isPlan0Only = true; 37010 var i; // Check if we need to add cmap format 12 or if format 4 only is fine 37011 for (i = glyphs.length - 1; i > 0; i -= 1) { 37012 var g = glyphs.get(i); 37013 if (g.unicode > 65535) { 37014 console.log('Adding CMAP format 12 (needed!)'); 37015 isPlan0Only = false;
37016 break; 37017 } 37018 } 37019 var cmapTable = [ 37020 { 37021 name: 'version', 37022 type: 'USHORT', 37023 value: 0 37024 }, 37025 { 37026 name: 'numTables', 37027 type: 'USHORT', 37028 value: isPlan0Only ? 1 : 2 37029 }, // CMAP 4 header 37030 { 37031 name: 'platformID', 37032 type: 'USHORT', 37033 value: 3 37034 }, 37035 { 37036 name: 'encodingID', 37037 type: 'USHORT', 37038 value: 1 37039 }, 37040 { 37041 name: 'offset', 37042 type: 'ULONG', 37043 value: isPlan0Only ? 12 : 12 + 8 37044 } 37045 ]; 37046 if (!isPlan0Only) { 37047 cmapTable = cmapTable.concat([ // CMAP 12 header 37048 { 37049 name: 'cmap12PlatformID', 37050 type: 'USHORT', 37051 value: 3 37052 }, // We encode only for PlatformID = 3 (Windows) because it is supported everywhere 37053 { 37054 name: 'cmap12EncodingID', 37055 type: 'USHORT', 37056 value: 10 37057 }, 37058 { 37059 name: 'cmap12Offset', 37060 type: 'ULONG', 37061 value: 0 37062 } 37063 ]); 37064 } 37065 cmapTable = cmapTable.concat([ // CMAP 4 Subtable 37066 { 37067 name: 'format', 37068 type: 'USHORT', 37069 value: 4 37070 }, 37071 { 37072 name: 'cmap4Length', 37073 type: 'USHORT', 37074 value: 0 37075 }, 37076 { 37077 name: 'language', 37078 type: 'USHORT', 37079 value: 0 37080 }, 37081 { 37082 name: 'segCountX2', 37083 type: 'USHORT', 37084 value: 0 37085 }, 37086 { 37087 name: 'searchRange', 37088 type: 'USHORT', 37089 value: 0 37090 }, 37091 { 37092 name: 'entrySelector', 37093 type: 'USHORT', 37094 value: 0 37095 }, 37096 { 37097 name: 'rangeShift', 37098 type: 'USHORT', 37099 value: 0 37100 } 37101 ]); 37102 var t = new table.Table('cmap', cmapTable); 37103 t.segments = [ 37104 ]; 37105 for (i = 0; i < glyphs.length; i += 1) { 37106 var glyph = glyphs.get(i); 37107 for (var j = 0; j < glyph.unicodes.length; j += 1) { 37108 addSegment(t, glyph.unicodes[j], i); 37109 } 37110 t.segments = t.segments.sort(function (a, b) { 37111 return a.start - b.start; 37112 }); 37113 } 37114 addTerminatorSegment(t); 37115 var segCount = t.segments.length; 37116 var segCountToRemove = 0; // CMAP 4 37117 // Set up parallel segment arrays. 37118 var endCounts = [ 37119 ]; 37120 var startCounts = [ 37121 ]; 37122 var idDeltas = [ 37123 ]; 37124 var idRangeOffsets = [ 37125 ]; 37126 var glyphIds = [ 37127 ]; // CMAP 12 37128 var cmap12Groups = [ 37129 ]; // Reminder this loop is not following the specification at 100% 37130 // The specification -> find suites of characters and make a group 37131 // Here we're doing one group for each letter 37132 // Doing as the spec can save 8 times (or more) space 37133 for (i = 0; i < segCount; i += 1) { 37134 var segment = t.segments[i]; // CMAP 4 37135 if (segment.end <= 65535 && segment.start <= 65535) { 37136 endCounts = endCounts.concat({ 37137 name: 'end_' + i, 37138 type: 'USHORT', 37139 value: segment.end 37140 }); 37141 startCounts = startCounts.concat({ 37142 name: 'start_' + i, 37143 type: 'USHORT', 37144 value: segment.start 37145 }); 37146 idDeltas = idDeltas.concat({ 37147 name: 'idDelta_' + i, 37148 type: 'SHORT', 37149 value: segment.delta 37150 }); 37151 idRangeOffsets = idRangeOffsets.concat({ 37152 name: 'idRangeOffset_' + i, 37153 type: 'USHORT', 37154 value: segment.offset 37155 }); 37156 if (segment.glyphId !== undefined) { 37157 glyphIds = glyphIds.concat({ 37158 name: 'glyph_' + i, 37159 type: 'USHORT', 37160 value: segment.glyphId 37161 }); 37162 } 37163 } else { 37164 // Skip Unicode > 65535 (16bit unsigned max) for CMAP 4, will be added in CMAP 12 37165 segCountToRemove += 1; 37166 } // CMAP 12 37167 // Skip Terminator Segment 37168 37169 if (!isPlan0Only && segment.glyphIndex !== undefined) { 37170 cmap12Groups = cmap12Groups.concat({ 37171 name: 'cmap12Start_' + i, 37172 type: 'ULONG', 37173 value: segment.start 37174 }); 37175 cmap12Groups = cmap12Groups.concat({ 37176 name: 'cmap12End_' + i, 37177 type: 'ULONG', 37178 value: segment.end 37179 }); 37180 cmap12Groups = cmap12Groups.concat({ 37181 name: 'cmap12Glyph_' + i, 37182 type: 'ULONG', 37183 value: segment.glyphIndex 37184 }); 37185 } 37186 } // CMAP 4 Subtable 37187 37188 t.segCountX2 = (segCount - segCountToRemove) * 2;
37189 t.searchRange = Math.pow(2, Math.floor(Math.log(segCount - segCountToRemove) / Math.log(2))) * 2; 37190 t.entrySelector = Math.log(t.searchRange / 2) / Math.log(2); 37191 t.rangeShift = t.segCountX2 - t.searchRange; 37192 t.fields = t.fields.concat(endCounts); 37193 t.fields.push({ 37194 name: 'reservedPad', 37195 type: 'USHORT', 37196 value: 0 37197 }); 37198 t.fields = t.fields.concat(startCounts); 37199 t.fields = t.fields.concat(idDeltas); 37200 t.fields = t.fields.concat(idRangeOffsets); 37201 t.fields = t.fields.concat(glyphIds); 37202 t.cmap4Length = 14 + // Subtable header 37203 endCounts.length * 2 + 2 + // reservedPad 37204 startCounts.length * 2 + idDeltas.length * 2 + idRangeOffsets.length * 2 + glyphIds.length * 2; 37205 if (!isPlan0Only) { 37206 // CMAP 12 Subtable 37207 var cmap12Length = 16 + // Subtable header 37208 cmap12Groups.length * 4; 37209 t.cmap12Offset = 12 + 2 * 2 + 4 + t.cmap4Length; 37210 t.fields = t.fields.concat([{ 37211 name: 'cmap12Format', 37212 type: 'USHORT', 37213 value: 12 37214 }, 37215 { 37216 name: 'cmap12Reserved', 37217 type: 'USHORT', 37218 value: 0 37219 }, 37220 { 37221 name: 'cmap12Length', 37222 type: 'ULONG', 37223 value: cmap12Length 37224 }, 37225 { 37226 name: 'cmap12Language', 37227 type: 'ULONG', 37228 value: 0 37229 }, 37230 { 37231 name: 'cmap12nGroups', 37232 type: 'ULONG', 37233 value: cmap12Groups.length / 3 37234 } 37235 ]); 37236 t.fields = t.fields.concat(cmap12Groups); 37237 } 37238 return t; 37239 } 37240 var cmap = { 37241 parse: parseCmapTable, 37242 make: makeCmapTable 37243 }; // Glyph encoding 37244 var cffStandardStrings = [ 37245 '.notdef', 37246 'space', 37247 'exclam', 37248 'quotedbl', 37249 'numbersign', 37250 'dollar', 37251 'percent', 37252 'ampersand', 37253 'quoteright', 37254 'parenleft', 37255 'parenright', 37256 'asterisk', 37257 'plus', 37258 'comma', 37259 'hyphen', 37260 'period', 37261 'slash', 37262 'zero', 37263 'one', 37264 'two', 37265 'three', 37266 'four', 37267 'five', 37268 'six', 37269 'seven', 37270 'eight', 37271 'nine', 37272 'colon', 37273 'semicolon', 37274 'less', 37275 'equal', 37276 'greater', 37277 'question', 37278 'at', 37279 'A', 37280 'B', 37281 'C', 37282 'D', 37283 'E', 37284 'F', 37285 'G', 37286 'H', 37287 'I', 37288 'J', 37289 'K', 37290 'L', 37291 'M', 37292 'N', 37293 'O', 37294 'P', 37295 'Q', 37296 'R', 37297 'S', 37298 'T', 37299 'U', 37300 'V', 37301 'W', 37302 'X', 37303 'Y', 37304 'Z', 37305 'bracketleft', 37306 'backslash', 37307 'bracketright', 37308 'asciicircum', 37309 'underscore', 37310 'quoteleft', 37311 'a', 37312 'b', 37313 'c', 37314 'd', 37315 'e', 37316 'f', 37317 'g', 37318 'h', 37319 'i', 37320 'j', 37321 'k', 37322 'l', 37323 'm', 37324 'n', 37325 'o', 37326 'p', 37327 'q', 37328 'r', 37329 's', 37330 't', 37331 'u', 37332 'v', 37333 'w', 37334 'x', 37335 'y', 37336 'z', 37337 'braceleft', 37338 'bar', 37339 'braceright', 37340 'asciitilde', 37341 'exclamdown', 37342 'cent', 37343 'sterling', 37344 'fraction', 37345 'yen', 37346 'florin', 37347 'section', 37348 'currency', 37349 'quotesingle', 37350 'quotedblleft', 37351 'guillemotleft', 37352 'guilsinglleft', 37353 'guilsinglright', 37354 'fi', 37355 'fl', 37356 'endash', 37357 'dagger', 37358 'daggerdbl',
37359 'periodcentered', 37360 'paragraph', 37361 'bullet', 37362 'quotesinglbase', 37363 'quotedblbase', 37364 'quotedblright', 37365 'guillemotright', 37366 'ellipsis', 37367 'perthousand', 37368 'questiondown', 37369 'grave', 37370 'acute', 37371 'circumflex', 37372 'tilde', 37373 'macron', 37374 'breve', 37375 'dotaccent', 37376 'dieresis', 37377 'ring', 37378 'cedilla', 37379 'hungarumlaut', 37380 'ogonek', 37381 'caron', 37382 'emdash', 37383 'AE', 37384 'ordfeminine', 37385 'Lslash', 37386 'Oslash', 37387 'OE', 37388 'ordmasculine', 37389 'ae', 37390 'dotlessi', 37391 'lslash', 37392 'oslash', 37393 'oe', 37394 'germandbls', 37395 'onesuperior', 37396 'logicalnot', 37397 'mu', 37398 'trademark', 37399 'Eth', 37400 'onehalf', 37401 'plusminus', 37402 'Thorn', 37403 'onequarter', 37404 'divide', 37405 'brokenbar', 37406 'degree', 37407 'thorn', 37408 'threequarters', 37409 'twosuperior', 37410 'registered', 37411 'minus', 37412 'eth', 37413 'multiply', 37414 'threesuperior', 37415 'copyright', 37416 'Aacute', 37417 'Acircumflex', 37418 'Adieresis', 37419 'Agrave', 37420 'Aring', 37421 'Atilde', 37422 'Ccedilla', 37423 'Eacute', 37424 'Ecircumflex', 37425 'Edieresis', 37426 'Egrave', 37427 'Iacute', 37428 'Icircumflex', 37429 'Idieresis', 37430 'Igrave', 37431 'Ntilde', 37432 'Oacute', 37433 'Ocircumflex', 37434 'Odieresis', 37435 'Ograve', 37436 'Otilde', 37437 'Scaron', 37438 'Uacute', 37439 'Ucircumflex', 37440 'Udieresis', 37441 'Ugrave', 37442 'Yacute', 37443 'Ydieresis', 37444 'Zcaron', 37445 'aacute', 37446 'acircumflex', 37447 'adieresis', 37448 'agrave', 37449 'aring', 37450 'atilde', 37451 'ccedilla', 37452 'eacute', 37453 'ecircumflex', 37454 'edieresis', 37455 'egrave', 37456 'iacute', 37457 'icircumflex', 37458 'idieresis', 37459 'igrave', 37460 'ntilde', 37461 'oacute', 37462 'ocircumflex', 37463 'odieresis', 37464 'ograve', 37465 'otilde', 37466 'scaron', 37467 'uacute', 37468 'ucircumflex', 37469 'udieresis', 37470 'ugrave', 37471 'yacute', 37472 'ydieresis', 37473 'zcaron', 37474 'exclamsmall', 37475 'Hungarumlautsmall', 37476 'dollaroldstyle', 37477 'dollarsuperior', 37478 'ampersandsmall', 37479 'Acutesmall', 37480 'parenleftsuperior', 37481 'parenrightsuperior', 37482 '266 ff', 37483 'onedotenleader', 37484 'zerooldstyle', 37485 'oneoldstyle', 37486 'twooldstyle', 37487 'threeoldstyle', 37488 'fouroldstyle', 37489 'fiveoldstyle', 37490 'sixoldstyle', 37491 'sevenoldstyle', 37492 'eightoldstyle', 37493 'nineoldstyle', 37494 'commasuperior', 37495 'threequartersemdash', 37496 'periodsuperior', 37497 'questionsmall', 37498 'asuperior', 37499 'bsuperior', 37500 'centsuperior', 37501 'dsuperior', 37502 'esuperior', 37503 'isuperior', 37504 'lsuperior', 37505 'msuperior', 37506 'nsuperior', 37507 'osuperior', 37508 'rsuperior', 37509 'ssuperior', 37510 'tsuperior', 37511 'ff', 37512 'ffi', 37513 'ffl', 37514 'parenleftinferior', 37515 'parenrightinferior', 37516 'Circumflexsmall', 37517 'hyphensuperior', 37518 'Gravesmall', 37519 'Asmall', 37520 'Bsmall', 37521 'Csmall', 37522 'Dsmall', 37523 'Esmall', 37524 'Fsmall', 37525 'Gsmall', 37526 'Hsmall', 37527 'Ismall', 37528 'Jsmall', 37529 'Ksmall', 37530 'Lsmall', 37531 'Msmall',
37532 'Nsmall', 37533 'Osmall', 37534 'Psmall', 37535 'Qsmall', 37536 'Rsmall', 37537 'Ssmall', 37538 'Tsmall', 37539 'Usmall', 37540 'Vsmall', 37541 'Wsmall', 37542 'Xsmall', 37543 'Ysmall', 37544 'Zsmall', 37545 'colonmonetary', 37546 'onefitted', 37547 'rupiah', 37548 'Tildesmall', 37549 'exclamdownsmall', 37550 'centoldstyle', 37551 'Lslashsmall', 37552 'Scaronsmall', 37553 'Zcaronsmall', 37554 'Dieresissmall', 37555 'Brevesmall', 37556 'Caronsmall', 37557 'Dotaccentsmall', 37558 'Macronsmall', 37559 'figuredash', 37560 'hypheninferior', 37561 'Ogoneksmall', 37562 'Ringsmall', 37563 'Cedillasmall', 37564 'questiondownsmall', 37565 'oneeighth', 37566 'threeeighths', 37567 'fiveeighths', 37568 'seveneighths', 37569 'onethird', 37570 'twothirds', 37571 'zerosuperior', 37572 'foursuperior', 37573 'fivesuperior', 37574 'sixsuperior', 37575 'sevensuperior', 37576 'eightsuperior', 37577 'ninesuperior', 37578 'zeroinferior', 37579 'oneinferior', 37580 'twoinferior', 37581 'threeinferior', 37582 'fourinferior', 37583 'fiveinferior', 37584 'sixinferior', 37585 'seveninferior', 37586 'eightinferior', 37587 'nineinferior', 37588 'centinferior', 37589 'dollarinferior', 37590 'periodinferior', 37591 'commainferior', 37592 'Agravesmall', 37593 'Aacutesmall', 37594 'Acircumflexsmall', 37595 'Atildesmall', 37596 'Adieresissmall', 37597 'Aringsmall', 37598 'AEsmall', 37599 'Ccedillasmall', 37600 'Egravesmall', 37601 'Eacutesmall', 37602 'Ecircumflexsmall', 37603 'Edieresissmall', 37604 'Igravesmall', 37605 'Iacutesmall', 37606 'Icircumflexsmall', 37607 'Idieresissmall', 37608 'Ethsmall', 37609 'Ntildesmall', 37610 'Ogravesmall', 37611 'Oacutesmall', 37612 'Ocircumflexsmall', 37613 'Otildesmall', 37614 'Odieresissmall', 37615 'OEsmall', 37616 'Oslashsmall', 37617 'Ugravesmall', 37618 'Uacutesmall', 37619 'Ucircumflexsmall', 37620 'Udieresissmall', 37621 'Yacutesmall', 37622 'Thornsmall', 37623 'Ydieresissmall', 37624 '001.000', 37625 '001.001', 37626 '001.002', 37627 '001.003', 37628 'Black', 37629 'Bold', 37630 'Book', 37631 'Light', 37632 'Medium', 37633 'Regular', 37634 'Roman', 37635 'Semibold' 37636 ]; 37637 var cffStandardEncoding = [ 37638 '', 37639 '', 37640 '', 37641 '', 37642 '', 37643 '', 37644 '', 37645 '', 37646 '', 37647 '', 37648 '', 37649 '', 37650 '', 37651 '', 37652 '', 37653 '', 37654 '', 37655 '', 37656 '', 37657 '', 37658 '', 37659 '', 37660 '', 37661 '', 37662 '', 37663 '', 37664 '', 37665 '', 37666 '', 37667 '', 37668 '', 37669 '', 37670 'space', 37671 'exclam', 37672 'quotedbl', 37673 'numbersign', 37674 'dollar', 37675 'percent', 37676 'ampersand', 37677 'quoteright', 37678 'parenleft', 37679 'parenright', 37680 'asterisk', 37681 'plus', 37682 'comma', 37683 'hyphen', 37684 'period', 37685 'slash', 37686 'zero', 37687 'one', 37688 'two', 37689 'three', 37690 'four', 37691 'five', 37692 'six', 37693 'seven', 37694 'eight', 37695 'nine', 37696 'colon', 37697 'semicolon', 37698 'less', 37699 'equal', 37700 'greater', 37701 'question', 37702 'at', 37703 'A', 37704 'B', 37705 'C', 37706 'D', 37707 'E', 37708 'F', 37709 'G', 37710 'H', 37711 'I', 37712 'J', 37713 'K', 37714 'L', 37715 'M',
37716 'N', 37717 'O', 37718 'P', 37719 'Q', 37720 'R', 37721 'S', 37722 'T', 37723 'U', 37724 'V', 37725 'W', 37726 'X', 37727 'Y', 37728 'Z', 37729 'bracketleft', 37730 'backslash', 37731 'bracketright', 37732 'asciicircum', 37733 'underscore', 37734 'quoteleft', 37735 'a', 37736 'b', 37737 'c', 37738 'd', 37739 'e', 37740 'f', 37741 'g', 37742 'h', 37743 'i', 37744 'j', 37745 'k', 37746 'l', 37747 'm', 37748 'n', 37749 'o', 37750 'p', 37751 'q', 37752 'r', 37753 's', 37754 't', 37755 'u', 37756 'v', 37757 'w', 37758 'x', 37759 'y', 37760 'z', 37761 'braceleft', 37762 'bar', 37763 'braceright', 37764 'asciitilde', 37765 '', 37766 '', 37767 '', 37768 '', 37769 '', 37770 '', 37771 '', 37772 '', 37773 '', 37774 '', 37775 '', 37776 '', 37777 '', 37778 '', 37779 '', 37780 '', 37781 '', 37782 '', 37783 '', 37784 '', 37785 '', 37786 '', 37787 '', 37788 '', 37789 '', 37790 '', 37791 '', 37792 '', 37793 '', 37794 '', 37795 '', 37796 '', 37797 '', 37798 '', 37799 'exclamdown', 37800 'cent', 37801 'sterling', 37802 'fraction', 37803 'yen', 37804 'florin', 37805 'section', 37806 'currency', 37807 'quotesingle', 37808 'quotedblleft', 37809 'guillemotleft', 37810 'guilsinglleft', 37811 'guilsinglright', 37812 'fi', 37813 'fl', 37814 '', 37815 'endash', 37816 'dagger', 37817 'daggerdbl',
37818 'periodcentered', 37819 '', 37820 'paragraph', 37821 'bullet', 37822 'quotesinglbase', 37823 'quotedblbase', 37824 'quotedblright', 37825 'guillemotright', 37826 'ellipsis', 37827 'perthousand', 37828 '', 37829 'questiondown', 37830 '', 37831 'grave', 37832 'acute', 37833 'circumflex', 37834 'tilde', 37835 'macron', 37836 'breve', 37837 'dotaccent', 37838 'dieresis', 37839 '', 37840 'ring', 37841 'cedilla', 37842 '', 37843 'hungarumlaut', 37844 'ogonek', 37845 'caron', 37846 'emdash', 37847 '', 37848 '', 37849 '', 37850 '', 37851 '', 37852 '', 37853 '', 37854 '', 37855 '', 37856 '', 37857 '', 37858 '', 37859 '', 37860 '', 37861 '', 37862 '', 37863 'AE', 37864 '', 37865 'ordfeminine', 37866 '', 37867 '', 37868 '', 37869 '', 37870 'Lslash', 37871 'Oslash', 37872 'OE', 37873 'ordmasculine', 37874 '', 37875 '', 37876 '', 37877 '', 37878 '', 37879 'ae', 37880 '', 37881 '', 37882 '', 37883 'dotlessi', 37884 '', 37885 '', 37886 'lslash', 37887 'oslash', 37888 'oe', 37889 'germandbls' 37890 ]; 37891 var cffExpertEncoding = [ 37892 '', 37893 '', 37894 '', 37895 '', 37896 '', 37897 '', 37898 '', 37899 '', 37900 '', 37901 '', 37902 '', 37903 '', 37904 '', 37905 '', 37906 '', 37907 '', 37908 '', 37909 '', 37910 '', 37911 '', 37912 '', 37913 '', 37914 '', 37915 '', 37916 '', 37917 '', 37918 '', 37919 '', 37920 '', 37921 '', 37922 '', 37923 '', 37924 'space', 37925 'exclamsmall', 37926 'Hungarumlautsmall', 37927 '', 37928 'dollaroldstyle', 37929 'dollarsuperior', 37930 'ampersandsmall', 37931 'Acutesmall', 37932 'parenleftsuperior', 37933 'parenrightsuperior', 37934 'twodotenleader', 37935 'onedotenleader', 37936 'comma', 37937 'hyphen', 37938 'period', 37939 'fraction', 37940 'zerooldstyle', 37941 'oneoldstyle', 37942 'twooldstyle', 37943 'threeoldstyle', 37944 'fouroldstyle', 37945 'fiveoldstyle', 37946 'sixoldstyle', 37947 'sevenoldstyle', 37948 'eightoldstyle', 37949 'nineoldstyle', 37950 'colon', 37951 'semicolon', 37952 'commasuperior', 37953 'threequartersemdash', 37954 'periodsuperior', 37955 'questionsmall', 37956 '', 37957 'asuperior', 37958 'bsuperior', 37959 'centsuperior', 37960 'dsuperior', 37961 'esuperior', 37962 '', 37963 '', 37964 'isuperior', 37965 '', 37966 '', 37967 'lsuperior', 37968 'msuperior', 37969 'nsuperior', 37970 'osuperior', 37971 '', 37972 '', 37973 'rsuperior', 37974 'ssuperior', 37975 'tsuperior', 37976 '', 37977 'ff', 37978 'fi', 37979 'fl', 37980 'ffi', 37981 'ffl', 37982 'parenleftinferior', 37983 '', 37984 'parenrightinferior', 37985 'Circumflexsmall', 37986 'hyphensuperior', 37987 'Gravesmall', 37988 'Asmall', 37989 'Bsmall', 37990 'Csmall', 37991 'Dsmall', 37992 'Esmall', 37993 'Fsmall', 37994 'Gsmall', 37995 'Hsmall', 37996 'Ismall', 37997 'Jsmall', 37998 'Ksmall', 37999 'Lsmall', 38000 'Msmall',
38001 'Nsmall', 38002 'Osmall', 38003 'Psmall', 38004 'Qsmall', 38005 'Rsmall', 38006 'Ssmall', 38007 'Tsmall', 38008 'Usmall', 38009 'Vsmall', 38010 'Wsmall', 38011 'Xsmall', 38012 'Ysmall', 38013 'Zsmall', 38014 'colonmonetary', 38015 'onefitted', 38016 'rupiah', 38017 'Tildesmall', 38018 '', 38019 '', 38020 '', 38021 '', 38022 '', 38023 '', 38024 '', 38025 '', 38026 '', 38027 '', 38028 '', 38029 '', 38030 '', 38031 '', 38032 '', 38033 '', 38034 '', 38035 '', 38036 '', 38037 '', 38038 '', 38039 '', 38040 '', 38041 '', 38042 '', 38043 '', 38044 '', 38045 '', 38046 '', 38047 '', 38048 '', 38049 '', 38050 '', 38051 '', 38052 'exclamdownsmall', 38053 'centoldstyle', 38054 'Lslashsmall', 38055 '', 38056 '', 38057 'Scaronsmall', 38058 'Zcaronsmall', 38059 'Dieresissmall', 38060 'Brevesmall', 38061 'Caronsmall', 38062 '', 38063 'Dotaccentsmall', 38064 '', 38065 '', 38066 'Macronsmall', 38067 '', 38068 '', 38069 'figuredash', 38070 'hypheninferior', 38071 '', 38072 '', 38073 'Ogoneksmall', 38074 'Ringsmall', 38075 'Cedillasmall', 38076 '', 38077 '', 38078 '', 38079 'onequarter', 38080 'onehalf', 38081 'threequarters', 38082 'questiondownsmall', 38083 'oneeighth', 38084 'threeeighths', 38085 'fiveeighths', 38086 'seveneighths', 38087 'onethird', 38088 'twothirds', 38089 '', 38090 '', 38091 'zerosuperior', 38092 'onesuperior', 38093 'twosuperior', 38094 'threesuperior', 38095 'foursuperior', 38096 'fivesuperior', 38097 'sixsuperior', 38098 'sevensuperior', 38099 'eightsuperior', 38100 'ninesuperior', 38101 'zeroinferior', 38102 'oneinferior', 38103 'twoinferior', 38104 'threeinferior', 38105 'fourinferior', 38106 'fiveinferior', 38107 'sixinferior', 38108 'seveninferior', 38109 'eightinferior', 38110 'nineinferior', 38111 'centinferior', 38112 'dollarinferior', 38113 'periodinferior', 38114 'commainferior', 38115 'Agravesmall', 38116 'Aacutesmall', 38117 'Acircumflexsmall', 38118 'Atildesmall', 38119 'Adieresissmall', 38120 'Aringsmall', 38121 'AEsmall', 38122 'Ccedillasmall', 38123 'Egravesmall', 38124 'Eacutesmall', 38125 'Ecircumflexsmall', 38126 'Edieresissmall', 38127 'Igravesmall', 38128 'Iacutesmall', 38129 'Icircumflexsmall', 38130 'Idieresissmall', 38131 'Ethsmall', 38132 'Ntildesmall', 38133 'Ogravesmall', 38134 'Oacutesmall', 38135 'Ocircumflexsmall', 38136 'Otildesmall', 38137 'Odieresissmall', 38138 'OEsmall', 38139 'Oslashsmall', 38140 'Ugravesmall', 38141 'Uacutesmall', 38142 'Ucircumflexsmall', 38143 'Udieresissmall', 38144 'Yacutesmall', 38145 'Thornsmall', 38146 'Ydieresissmall' 38147 ]; 38148 var standardNames = [ 38149 '.notdef', 38150 '.null', 38151 'nonmarkingreturn', 38152 'space', 38153 'exclam', 38154 'quotedbl', 38155 'numbersign', 38156 'dollar', 38157 'percent', 38158 'ampersand', 38159 'quotesingle', 38160 'parenleft', 38161 'parenright', 38162 'asterisk', 38163 'plus', 38164 'comma', 38165 'hyphen', 38166 'period', 38167 'slash', 38168 'zero', 38169 'one', 38170 'two', 38171 'three', 38172 'four', 38173 'five', 38174 'six', 38175 'seven', 38176 'eight', 38177 'nine', 38178 'colon', 38179 'semicolon', 38180 'less', 38181 'equal', 38182 'greater', 38183 'question', 38184 'at', 38185 'A', 38186 'B', 38187 'C', 38188 'D', 38189 'E', 38190 'F', 38191 'G', 38192 'H', 38193 'I', 38194 'J', 38195 'K', 38196 'L', 38197 'M',
38198 'N', 38199 'O', 38200 'P', 38201 'Q', 38202 'R', 38203 'S', 38204 'T', 38205 'U', 38206 'V', 38207 'W', 38208 'X', 38209 'Y', 38210 'Z', 38211 'bracketleft', 38212 'backslash', 38213 'bracketright', 38214 'asciicircum', 38215 'underscore', 38216 'grave', 38217 'a', 38218 'b', 38219 'c', 38220 'd', 38221 'e', 38222 'f', 38223 'g', 38224 'h', 38225 'i', 38226 'j', 38227 'k', 38228 'l', 38229 'm', 38230 'n', 38231 'o', 38232 'p', 38233 'q', 38234 'r', 38235 's', 38236 't', 38237 'u', 38238 'v', 38239 'w', 38240 'x', 38241 'y', 38242 'z', 38243 'braceleft', 38244 'bar', 38245 'braceright', 38246 'asciitilde', 38247 'Adieresis', 38248 'Aring', 38249 'Ccedilla', 38250 'Eacute', 38251 'Ntilde', 38252 'Odieresis', 38253 'Udieresis', 38254 'aacute', 38255 'agrave', 38256 'acircumflex', 38257 'adieresis', 38258 'atilde', 38259 'aring', 38260 'ccedilla', 38261 'eacute', 38262 'egrave', 38263 'ecircumflex', 38264 'edieresis', 38265 'iacute', 38266 'igrave', 38267 'icircumflex', 38268 'idieresis', 38269 'ntilde', 38270 'oacute', 38271 'ograve', 38272 'ocircumflex', 38273 'odieresis', 38274 'otilde', 38275 'uacute', 38276 'ugrave', 38277 'ucircumflex', 38278 'udieresis', 38279 'dagger', 38280 'degree', 38281 'cent', 38282 'sterling', 38283 'section', 38284 'bullet', 38285 'paragraph', 38286 'germandbls', 38287 'registered', 38288 'copyright', 38289 'trademark', 38290 'acute', 38291 'dieresis', 38292 'notequal', 38293 'AE', 38294 'Oslash', 38295 'infinity', 38296 'plusminus', 38297 'lessequal', 38298 'greaterequal', 38299 'yen', 38300 'mu', 38301 'partialdiff', 38302 'summation', 38303 'product', 38304 'pi', 38305 'integral', 38306 'ordfeminine', 38307 'ordmasculine', 38308 'Omega', 38309 'ae', 38310 'oslash', 38311 'questiondown', 38312 'exclamdown', 38313 'logicalnot', 38314 'radical', 38315 'florin', 38316 'approxequal', 38317 'Delta', 38318 'guillemotleft', 38319 'guillemotright', 38320 'ellipsis', 38321 'nonbreakingspace', 38322 'Agrave', 38323 'Atilde', 38324 'Otilde', 38325 'OE', 38326 'oe', 38327 'endash', 38328 'emdash', 38329 'quotedblleft', 38330 'quotedblright', 38331 'quoteleft', 38332 'quoteright', 38333 'divide', 38334 'lozenge', 38335 'ydieresis', 38336 'Ydieresis', 38337 'fraction', 38338 'currency', 38339 'guilsinglleft', 38340 'guilsinglright', 38341 'fi', 38342 'fl', 38343 'daggerdbl',
38344 'periodcentered', 38345 'quotesinglbase', 38346 'quotedblbase', 38347 'perthousand', 38348 'Acircumflex', 38349 'Ecircumflex', 38350 'Aacute', 38351 'Edieresis', 38352 'Egrave', 38353 'Iacute', 38354 'Icircumflex', 38355 'Idieresis', 38356 'Igrave', 38357 'Oacute', 38358 'Ocircumflex', 38359 'apple', 38360 'Ograve', 38361 'Uacute', 38362 'Ucircumflex', 38363 'Ugrave', 38364 'dotlessi', 38365 'circumflex', 38366 'tilde', 38367 'macron', 38368 'breve', 38369 'dotaccent', 38370 'ring', 38371 'cedilla', 38372 'hungarumlaut', 38373 'ogonek', 38374 'caron', 38375 'Lslash', 38376 'lslash', 38377 'Scaron', 38378 'scaron', 38379 'Zcaron', 38380 'zcaron', 38381 'brokenbar', 38382 'Eth', 38383 'eth', 38384 'Yacute', 38385 'yacute', 38386 'Thorn', 38387 'thorn', 38388 'minus', 38389 'multiply', 38390 'onesuperior', 38391 'twosuperior', 38392 'threesuperior', 38393 'onehalf', 38394 'onequarter', 38395 'threequarters', 38396 'franc', 38397 'Gbreve', 38398 'gbreve', 38399 'Idotaccent', 38400 'Scedilla', 38401 'scedilla', 38402 'Cacute', 38403 'cacute', 38404 'Ccaron', 38405 'ccaron', 38406 'dcroat' 38407 ]; 38408 /** 38409 * This is the encoding used for fonts created from scratch. 38410 * It loops through all glyphs and finds the appropriate unicode value. 38411 * Since it's linear time, other encodings will be faster. 38412 * @exports opentype.DefaultEncoding 38413 * @class 38414 * @constructor 38415 * @param {opentype.Font} 38416 */ 38417 function DefaultEncoding(font) { 38418 this.font = font; 38419 } 38420 DefaultEncoding.prototype.charToGlyphIndex = function (c) { 38421 var code = c.codePointAt(0); 38422 var glyphs = this.font.glyphs; 38423 if (glyphs) { 38424 for (var i = 0; i < glyphs.length; i += 1) { 38425 var glyph = glyphs.get(i); 38426 for (var j = 0; j < glyph.unicodes.length; j += 1) { 38427 if (glyph.unicodes[j] === code) { 38428 return i; 38429 } 38430 } 38431 } 38432 } 38433 return null; 38434 }; 38435 /** 38436 * @exports opentype.CmapEncoding 38437 * @class 38438 * @constructor 38439 * @param {Object} cmap - a object with the cmap encoded data 38440 */ 38441 function CmapEncoding(cmap) { 38442 this.cmap = cmap; 38443 } /** 38444 * @param {string} c - the character 38445 * @return {number} The glyph index. 38446 */ 38447 38448 CmapEncoding.prototype.charToGlyphIndex = function (c) { 38449 return this.cmap.glyphIndexMap[c.codePointAt(0)] || 0; 38450 }; 38451 /** 38452 * @exports opentype.CffEncoding 38453 * @class 38454 * @constructor 38455 * @param {string} encoding - The encoding 38456 * @param {Array} charset - The character set. 38457 */ 38458 function CffEncoding(encoding, charset) { 38459 this.encoding = encoding; 38460 this.charset = charset; 38461 } /** 38462 * @param {string} s - The character 38463 * @return {number} The index. 38464 */ 38465 38466 CffEncoding.prototype.charToGlyphIndex = function (s) { 38467 var code = s.codePointAt(0); 38468 var charName = this.encoding[code]; 38469 return this.charset.indexOf(charName); 38470 }; 38471 /** 38472 * @exports opentype.GlyphNames 38473 * @class 38474 * @constructor 38475 * @param {Object} post 38476 */ 38477 function GlyphNames(post) { 38478 var this$1 = this; 38479 switch (post.version) { 38480 case 1: 38481 this.names = standardNames.slice(); 38482 break; 38483 case 2: 38484 this.names = new Array(post.numberOfGlyphs); 38485 for (var i = 0; i < post.numberOfGlyphs; i++) { 38486 if (post.glyphNameIndex[i] < standardNames.length) { 38487 this$1.names[i] = standardNames[post.glyphNameIndex[i]]; 38488 } else { 38489 this$1.names[i] = post.names[post.glyphNameIndex[i] - standardNames.length]; 38490 } 38491 } 38492 break; 38493 case 2.5: 38494 this.names = new Array(post.numberOfGlyphs); 38495 for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) { 38496 this$1.names[i$1] = standardNames[i$1 + post.glyphNameIndex[i$1]]; 38497 } 38498 break; 38499 case 3: 38500 this.names = [ 38501 ]; 38502 break; 38503 default: 38504 this.names = [ 38505 ]; 38506 break; 38507 } 38508 } /** 38509 * Gets the index of a glyph by name. 38510 * @param {string} name - The glyph name 38511 * @return {number} The index 38512 */ 38513 38514 GlyphNames.prototype.nameToGlyphIndex = function (name) { 38515 return this.names.indexOf(name); 38516 }; 38517 /** 38518 * @param {number} gid 38519 * @return {string} 38520 */ 38521 GlyphNames.prototype.glyphIndexToName = function (gid) { 38522 return this.names[gid]; 38523 }; 38524 /** 38525 * @alias opentype.addGlyphNames 38526 * @param {opentype.Font} 38527 */ 38528 function addGlyphNames(font) { 38529 var glyph; 38530 var glyphIndexMap = font.tables.cmap.glyphIndexMap;
38531 var charCodes = Object.keys(glyphIndexMap); 38532 for (var i = 0; i < charCodes.length; i += 1) { 38533 var c = charCodes[i]; 38534 var glyphIndex = glyphIndexMap[c]; 38535 glyph = font.glyphs.get(glyphIndex); 38536 glyph.addUnicode(parseInt(c)); 38537 } 38538 for (var i$1 = 0; i$1 < font.glyphs.length; i$1 += 1) { 38539 glyph = font.glyphs.get(i$1); 38540 if (font.cffEncoding) { 38541 if (font.isCIDFont) { 38542 glyph.name = 'gid' + i$1; 38543 } else { 38544 glyph.name = font.cffEncoding.charset[i$1]; 38545 } 38546 } else if (font.glyphNames.names) { 38547 glyph.name = font.glyphNames.glyphIndexToName(i$1); 38548 } 38549 } 38550 } // Drawing utility functions. 38551 // Draw a line on the given context from point `x1,y1` to point `x2,y2`. 38552 38553 function line(ctx, x1, y1, x2, y2) { 38554 ctx.beginPath(); 38555 ctx.moveTo(x1, y1); 38556 ctx.lineTo(x2, y2); 38557 ctx.stroke(); 38558 } 38559 var draw = { 38560 line: line 38561 }; // The Glyph object 38562 // import glyf from './tables/glyf' Can't be imported here, because it's a circular dependency 38563 function getPathDefinition(glyph, path) { 38564 var _path = path || new Path(); 38565 return { 38566 configurable: true, 38567 get: function () { 38568 if (typeof _path === 'function') { 38569 _path = _path(); 38570 } 38571 return _path; 38572 }, 38573 set: function (p) { 38574 _path = p; 38575 } 38576 }; 38577 } /** 38578 * @typedef GlyphOptions 38579 * @type Object 38580 * @property {string} [name] - The glyph name 38581 * @property {number} [unicode] 38582 * @property {Array} [unicodes] 38583 * @property {number} [xMin] 38584 * @property {number} [yMin] 38585 * @property {number} [xMax] 38586 * @property {number} [yMax] 38587 * @property {number} [advanceWidth] 38588 */ 38589 // A Glyph is an individual mark that often corresponds to a character. 38590 // Some glyphs, such as ligatures, are a combination of many characters. 38591 // Glyphs are the basic building blocks of a font. 38592 // 38593 // The `Glyph` class contains utility methods for drawing the path and its points. 38594 /** 38595 * @exports opentype.Glyph 38596 * @class 38597 * @param {GlyphOptions} 38598 * @constructor 38599 */ 38600 38601 function Glyph(options) { 38602 // By putting all the code on a prototype function (which is only declared once) 38603 // we reduce the memory requirements for larger fonts by some 2% 38604 this.bindConstructorValues(options); 38605 } /** 38606 * @param {GlyphOptions} 38607 */ 38608 38609 Glyph.prototype.bindConstructorValues = function (options) { 38610 this.index = options.index || 0; // These three values cannot be deferred for memory optimization: 38611 this.name = options.name || null; 38612 this.unicode = options.unicode || undefined; 38613 this.unicodes = options.unicodes || options.unicode !== undefined ? [ 38614 options.unicode 38615 ] : [ 38616 ]; // But by binding these values only when necessary, we reduce can 38617 // the memory requirements by almost 3% for larger fonts. 38618 if (options.xMin) { 38619 this.xMin = options.xMin; 38620 } 38621 if (options.yMin) { 38622 this.yMin = options.yMin; 38623 } 38624 if (options.xMax) { 38625 this.xMax = options.xMax; 38626 } 38627 if (options.yMax) { 38628 this.yMax = options.yMax; 38629 } 38630 if (options.advanceWidth) { 38631 this.advanceWidth = options.advanceWidth; 38632 } // The path for a glyph is the most memory intensive, and is bound as a value 38633 // with a getter/setter to ensure we actually do path parsing only once the 38634 // path is actually needed by anything. 38635
38636 Object.defineProperty(this, 'path', getPathDefinition(this, options.path)); 38637 }; 38638 /** 38639 * @param {number} 38640 */ 38641 Glyph.prototype.addUnicode = function (unicode) { 38642 if (this.unicodes.length === 0) { 38643 this.unicode = unicode; 38644 } 38645 this.unicodes.push(unicode); 38646 }; 38647 /** 38648 * Calculate the minimum bounding box for this glyph. 38649 * @return {opentype.BoundingBox} 38650 */ 38651 Glyph.prototype.getBoundingBox = function () { 38652 return this.path.getBoundingBox(); 38653 }; 38654 /** 38655 * Convert the glyph to a Path we can draw on a drawing context. 38656 * @param {number} [x=0] - Horizontal position of the beginning of the text. 38657 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 38658 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 38659 * @param {Object=} options - xScale, yScale to stretch the glyph. 38660 * @param {opentype.Font} if hinting is to be used, the font 38661 * @return {opentype.Path} 38662 */ 38663 Glyph.prototype.getPath = function (x, y, fontSize, options, font) { 38664 x = x !== undefined ? x : 0; 38665 y = y !== undefined ? y : 0; 38666 fontSize = fontSize !== undefined ? fontSize : 72; 38667 var commands; 38668 var hPoints; 38669 if (!options) { 38670 options = { 38671 }; 38672 } 38673 var xScale = options.xScale; 38674 var yScale = options.yScale; 38675 if (options.hinting && font && font.hinting) { 38676 // in case of hinting, the hinting engine takes care 38677 // of scaling the points (not the path) before hinting. 38678 hPoints = this.path && font.hinting.exec(this, fontSize); // in case the hinting engine failed hPoints is undefined 38679 // and thus reverts to plain rending 38680 } 38681 if (hPoints) { 38682 // Call font.hinting.getCommands instead of `glyf.getPath(hPoints).commands` to avoid a circular dependency 38683 commands = font.hinting.getCommands(hPoints); 38684 x = Math.round(x); 38685 y = Math.round(y); // TODO in case of hinting xyScaling is not yet supported 38686 xScale = yScale = 1; 38687 } else { 38688 commands = this.path.commands; 38689 var scale = 1 / this.path.unitsPerEm * fontSize; 38690 if (xScale === undefined) { 38691 xScale = scale; 38692 } 38693 if (yScale === undefined) { 38694 yScale = scale; 38695 } 38696 } 38697 var p = new Path(); 38698 for (var i = 0; i < commands.length; i += 1) { 38699 var cmd = commands[i]; 38700 if (cmd.type === 'M') { 38701 p.moveTo(x + cmd.x * xScale, y + - cmd.y * yScale); 38702 } else if (cmd.type === 'L') { 38703 p.lineTo(x + cmd.x * xScale, y + - cmd.y * yScale); 38704 } else if (cmd.type === 'Q') { 38705 p.quadraticCurveTo(x + cmd.x1 * xScale, y + - cmd.y1 * yScale, x + cmd.x * xScale, y + - cmd.y * yScale); 38706 } else if (cmd.type === 'C') { 38707 p.curveTo(x + cmd.x1 * xScale, y + - cmd.y1 * yScale, x + cmd.x2 * xScale, y + - cmd.y2 * yScale, x + cmd.x * xScale, y + - cmd.y * yScale); 38708 } else if (cmd.type === 'Z') { 38709 p.closePath(); 38710 } 38711 } 38712 return p; 38713 }; 38714 /** 38715 * Split the glyph into contours. 38716 * This function is here for backwards compatibility, and to 38717 * provide raw access to the TrueType glyph outlines. 38718 * @return {Array} 38719 */ 38720 Glyph.prototype.getContours = function () { 38721 var this$1 = this; 38722 if (this.points === undefined) { 38723 return []; 38724 } 38725 var contours = [ 38726 ]; 38727 var currentContour = [ 38728 ]; 38729 for (var i = 0; i < this.points.length; i += 1) { 38730 var pt = this$1.points[i]; 38731 currentContour.push(pt); 38732 if (pt.lastPointOfContour) { 38733 contours.push(currentContour); 38734 currentContour = [ 38735 ]; 38736 } 38737 } 38738 check.argument(currentContour.length === 0, 'There are still points left in the current contour.'); 38739 return contours; 38740 }; 38741 /**
38742 * Calculate the xMin/yMin/xMax/yMax/lsb/rsb for a Glyph. 38743 * @return {Object} 38744 */ 38745 Glyph.prototype.getMetrics = function () { 38746 var commands = this.path.commands; 38747 var xCoords = [ 38748 ]; 38749 var yCoords = [ 38750 ]; 38751 for (var i = 0; i < commands.length; i += 1) { 38752 var cmd = commands[i]; 38753 if (cmd.type !== 'Z') { 38754 xCoords.push(cmd.x); 38755 yCoords.push(cmd.y); 38756 } 38757 if (cmd.type === 'Q' || cmd.type === 'C') { 38758 xCoords.push(cmd.x1); 38759 yCoords.push(cmd.y1); 38760 } 38761 if (cmd.type === 'C') { 38762 xCoords.push(cmd.x2); 38763 yCoords.push(cmd.y2); 38764 } 38765 } 38766 var metrics = { 38767 xMin: Math.min.apply(null, xCoords), 38768 yMin: Math.min.apply(null, yCoords), 38769 xMax: Math.max.apply(null, xCoords), 38770 yMax: Math.max.apply(null, yCoords), 38771 leftSideBearing: this.leftSideBearing 38772 }; 38773 if (!isFinite(metrics.xMin)) { 38774 metrics.xMin = 0; 38775 } 38776 if (!isFinite(metrics.xMax)) { 38777 metrics.xMax = this.advanceWidth; 38778 } 38779 if (!isFinite(metrics.yMin)) { 38780 metrics.yMin = 0; 38781 } 38782 if (!isFinite(metrics.yMax)) { 38783 metrics.yMax = 0; 38784 } 38785 metrics.rightSideBearing = this.advanceWidth - metrics.leftSideBearing - (metrics.xMax - metrics.xMin); 38786 return metrics; 38787 }; 38788 /** 38789 * Draw the glyph on the given context. 38790 * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. 38791 * @param {number} [x=0] - Horizontal position of the beginning of the text. 38792 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 38793 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 38794 * @param {Object=} options - xScale, yScale to stretch the glyph. 38795 */ 38796 Glyph.prototype.draw = function (ctx, x, y, fontSize, options) { 38797 this.getPath(x, y, fontSize, options).draw(ctx); 38798 }; 38799 /** 38800 * Draw the points of the glyph. 38801 * On-curve points will be drawn in blue, off-curve points will be drawn in red. 38802 * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. 38803 * @param {number} [x=0] - Horizontal position of the beginning of the text. 38804 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 38805 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 38806 */ 38807 Glyph.prototype.drawPoints = function (ctx, x, y, fontSize) { 38808 function drawCircles(l, x, y, scale) { 38809 var PI_SQ = Math.PI * 2; 38810 ctx.beginPath(); 38811 for (var j = 0; j < l.length; j += 1) { 38812 ctx.moveTo(x + l[j].x * scale, y + l[j].y * scale); 38813 ctx.arc(x + l[j].x * scale, y + l[j].y * scale, 2, 0, PI_SQ, false); 38814 } 38815 ctx.closePath(); 38816 ctx.fill(); 38817 } 38818 x = x !== undefined ? x : 0; 38819 y = y !== undefined ? y : 0; 38820 fontSize = fontSize !== undefined ? fontSize : 24; 38821 var scale = 1 / this.path.unitsPerEm * fontSize; 38822 var blueCircles = [ 38823 ]; 38824 var redCircles = [ 38825 ]; 38826 var path = this.path; 38827 for (var i = 0; i < path.commands.length; i += 1) { 38828 var cmd = path.commands[i]; 38829 if (cmd.x !== undefined) { 38830 blueCircles.push({ 38831 x: cmd.x, 38832 y: - cmd.y 38833 }); 38834 } 38835 if (cmd.x1 !== undefined) { 38836 redCircles.push({ 38837 x: cmd.x1, 38838 y: - cmd.y1 38839 }); 38840 } 38841 if (cmd.x2 !== undefined) { 38842 redCircles.push({ 38843 x: cmd.x2, 38844 y: - cmd.y2 38845 }); 38846 } 38847 } 38848 ctx.fillStyle = 'blue'; 38849 drawCircles(blueCircles, x, y, scale); 38850 ctx.fillStyle = 'red'; 38851 drawCircles(redCircles, x, y, scale); 38852 }; 38853 /** 38854 * Draw lines indicating important font measurements. 38855 * Black lines indicate the origin of the coordinate system (point 0,0). 38856 * Blue lines indicate the glyph bounding box. 38857 * Green line indicates the advance width of the glyph.
38858 * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. 38859 * @param {number} [x=0] - Horizontal position of the beginning of the text. 38860 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 38861 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 38862 */ 38863 Glyph.prototype.drawMetrics = function (ctx, x, y, fontSize) { 38864 var scale; 38865 x = x !== undefined ? x : 0; 38866 y = y !== undefined ? y : 0; 38867 fontSize = fontSize !== undefined ? fontSize : 24; 38868 scale = 1 / this.path.unitsPerEm * fontSize; 38869 ctx.lineWidth = 1; // Draw the origin 38870 ctx.strokeStyle = 'black'; 38871 draw.line(ctx, x, - 10000, x, 10000); 38872 draw.line(ctx, - 10000, y, 10000, y); // This code is here due to memory optimization: by not using 38873 // defaults in the constructor, we save a notable amount of memory. 38874 var xMin = this.xMin || 0; 38875 var yMin = this.yMin || 0; 38876 var xMax = this.xMax || 0; 38877 var yMax = this.yMax || 0; 38878 var advanceWidth = this.advanceWidth || 0; // Draw the glyph box 38879 ctx.strokeStyle = 'blue'; 38880 draw.line(ctx, x + xMin * scale, - 10000, x + xMin * scale, 10000); 38881 draw.line(ctx, x + xMax * scale, - 10000, x + xMax * scale, 10000); 38882 draw.line(ctx, - 10000, y + - yMin * scale, 10000, y + - yMin * scale); 38883 draw.line(ctx, - 10000, y + - yMax * scale, 10000, y + - yMax * scale); // Draw the advance width 38884 ctx.strokeStyle = 'green'; 38885 draw.line(ctx, x + advanceWidth * scale, - 10000, x + advanceWidth * scale, 10000); 38886 }; // The GlyphSet object 38887 // Define a property on the glyph that depends on the path being loaded. 38888 function defineDependentProperty(glyph, externalName, internalName) { 38889 Object.defineProperty(glyph, externalName, { 38890 get: function () { 38891 // Request the path property to make sure the path is loaded. 38892 glyph.path; // jshint ignore:line 38893 return glyph[internalName]; 38894 }, 38895 set: function (newValue) { 38896 glyph[internalName] = newValue; 38897 }, 38898 enumerable: true, 38899 configurable: true 38900 }); 38901 } /** 38902 * A GlyphSet represents all glyphs available in the font, but modelled using 38903 * a deferred glyph loader, for retrieving glyphs only once they are absolutely 38904 * necessary, to keep the memory footprint down. 38905 * @exports opentype.GlyphSet 38906 * @class 38907 * @param {opentype.Font} 38908 * @param {Array} 38909 */ 38910 38911 function GlyphSet(font, glyphs) { 38912 var this$1 = this; 38913 this.font = font; 38914 this.glyphs = { 38915 }; 38916 if (Array.isArray(glyphs)) { 38917 for (var i = 0; i < glyphs.length; i++) { 38918 this$1.glyphs[i] = glyphs[i]; 38919 } 38920 } 38921 this.length = glyphs && glyphs.length || 0; 38922 } /** 38923 * @param {number} index 38924 * @return {opentype.Glyph} 38925 */ 38926 38927 GlyphSet.prototype.get = function (index) { 38928 if (typeof this.glyphs[index] === 'function') { 38929 this.glyphs[index] = this.glyphs[index](); 38930 } 38931 return this.glyphs[index]; 38932 }; 38933 /** 38934 * @param {number} index 38935 * @param {Object} 38936 */ 38937 GlyphSet.prototype.push = function (index, loader) { 38938 this.glyphs[index] = loader; 38939 this.length++; 38940 }; 38941 /** 38942 * @alias opentype.glyphLoader 38943 * @param {opentype.Font} font 38944 * @param {number} index 38945 * @return {opentype.Glyph} 38946 */ 38947 function glyphLoader(font, index) { 38948 return new Glyph({ 38949 index: index, 38950 font: font 38951 }); 38952 } /** 38953 * Generate a stub glyph that can be filled with all metadata *except* 38954 * the "points" and "path" properties, which must be loaded only once 38955 * the glyph's path is actually requested for text shaping. 38956 * @alias opentype.ttfGlyphLoader 38957 * @param {opentype.Font} font 38958 * @param {number} index 38959 * @param {Function} parseGlyph 38960 * @param {Object} data 38961 * @param {number} position 38962 * @param {Function} buildPath 38963 * @return {opentype.Glyph} 38964 */ 38965 38966 function ttfGlyphLoader(font, index, parseGlyph, data, position, buildPath) { 38967 return function () { 38968 var glyph = new Glyph({ 38969 index: index, 38970 font: font 38971 }); 38972 glyph.path = function () { 38973 parseGlyph(glyph, data, position); 38974 var path = buildPath(font.glyphs, glyph); 38975 path.unitsPerEm = font.unitsPerEm; 38976 return path; 38977 };
38978 defineDependentProperty(glyph, 'xMin', '_xMin'); 38979 defineDependentProperty(glyph, 'xMax', '_xMax'); 38980 defineDependentProperty(glyph, 'yMin', '_yMin'); 38981 defineDependentProperty(glyph, 'yMax', '_yMax'); 38982 return glyph; 38983 }; 38984 } /** 38985 * @alias opentype.cffGlyphLoader 38986 * @param {opentype.Font} font 38987 * @param {number} index 38988 * @param {Function} parseCFFCharstring 38989 * @param {string} charstring 38990 * @return {opentype.Glyph} 38991 */ 38992 38993 function cffGlyphLoader(font, index, parseCFFCharstring, charstring) { 38994 return function () { 38995 var glyph = new Glyph({ 38996 index: index, 38997 font: font 38998 }); 38999 glyph.path = function () { 39000 var path = parseCFFCharstring(font, glyph, charstring); 39001 path.unitsPerEm = font.unitsPerEm; 39002 return path; 39003 }; 39004 return glyph; 39005 }; 39006 } 39007 var glyphset = { 39008 GlyphSet: GlyphSet, 39009 glyphLoader: glyphLoader, 39010 ttfGlyphLoader: ttfGlyphLoader, 39011 cffGlyphLoader: cffGlyphLoader 39012 }; // The `CFF` table contains the glyph outlines in PostScript format. 39013 // Custom equals function that can also check lists. 39014 function equals(a, b) { 39015 if (a === b) { 39016 return true; 39017 } else if (Array.isArray(a) && Array.isArray(b)) { 39018 if (a.length !== b.length) { 39019 return false; 39020 } 39021 for (var i = 0; i < a.length; i += 1) { 39022 if (!equals(a[i], b[i])) { 39023 return false; 39024 } 39025 } 39026 return true; 39027 } else { 39028 return false; 39029 } 39030 } // Subroutines are encoded using the negative half of the number space. 39031 // See type 2 chapter 4.7 "Subroutine operators". 39032 39033 function calcCFFSubroutineBias(subrs) { 39034 var bias; 39035 if (subrs.length < 1240) { 39036 bias = 107; 39037 } else if (subrs.length < 33900) { 39038 bias = 1131; 39039 } else { 39040 bias = 32768; 39041 } 39042 return bias; 39043 } // Parse a `CFF` INDEX array. 39044 // An index array consists of a list of offsets, then a list of objects at those offsets. 39045 39046 function parseCFFIndex(data, start, conversionFn) { 39047 var offsets = [ 39048 ]; 39049 var objects = [ 39050 ]; 39051 var count = parse.getCard16(data, start); 39052 var objectOffset; 39053 var endOffset; 39054 if (count !== 0) { 39055 var offsetSize = parse.getByte(data, start + 2); 39056 objectOffset = start + (count + 1) * offsetSize + 2; 39057 var pos = start + 3; 39058 for (var i = 0; i < count + 1; i += 1) { 39059 offsets.push(parse.getOffset(data, pos, offsetSize)); 39060 pos += offsetSize; 39061 } // The total size of the index array is 4 header bytes + the value of the last offset. 39062 39063 endOffset = objectOffset + offsets[count]; 39064 } else { 39065 endOffset = start + 2; 39066 } 39067 for (var i$1 = 0; i$1 < offsets.length - 1; i$1 += 1) { 39068 var value = parse.getBytes(data, objectOffset + offsets[i$1], objectOffset + offsets[i$1 + 1]); 39069 if (conversionFn) { 39070 value = conversionFn(value); 39071 } 39072 objects.push(value); 39073 } 39074 return { 39075 objects: objects, 39076 startOffset: start, 39077 endOffset: endOffset 39078 }; 39079 } // Parse a `CFF` DICT real value. 39080 39081 function parseFloatOperand(parser) { 39082 var s = ''; 39083 var eof = 15; 39084 var lookup = [ 39085 '0', 39086 '1', 39087 '2', 39088 '3', 39089 '4', 39090 '5', 39091 '6', 39092 '7', 39093 '8', 39094 '9', 39095 '.', 39096 'E', 39097 'E-', 39098 null,
vendor: 38,646 bytes, lines 39099-40080
39099 '-' 39100 ]; 39101 while (true) { 39102 var b = parser.parseByte(); 39103 var n1 = b >> 4; 39104 var n2 = b & 15; 39105 if (n1 === eof) { 39106 break; 39107 } 39108 s += lookup[n1]; 39109 if (n2 === eof) { 39110 break; 39111 } 39112 s += lookup[n2]; 39113 } 39114 return parseFloat(s); 39115 } // Parse a `CFF` DICT operand. 39116 39117 function parseOperand(parser, b0) { 39118 var b1; 39119 var b2; 39120 var b3; 39121 var b4; 39122 if (b0 === 28) { 39123 b1 = parser.parseByte(); 39124 b2 = parser.parseByte(); 39125 return b1 << 8 | b2; 39126 } 39127 if (b0 === 29) { 39128 b1 = parser.parseByte(); 39129 b2 = parser.parseByte(); 39130 b3 = parser.parseByte(); 39131 b4 = parser.parseByte(); 39132 return b1 << 24 | b2 << 16 | b3 << 8 | b4; 39133 } 39134 if (b0 === 30) { 39135 return parseFloatOperand(parser); 39136 } 39137 if (b0 >= 32 && b0 <= 246) { 39138 return b0 - 139; 39139 } 39140 if (b0 >= 247 && b0 <= 250) { 39141 b1 = parser.parseByte(); 39142 return (b0 - 247) * 256 + b1 + 108; 39143 } 39144 if (b0 >= 251 && b0 <= 254) { 39145 b1 = parser.parseByte(); 39146 return - (b0 - 251) * 256 - b1 - 108; 39147 } 39148 throw new Error('Invalid b0 ' + b0); 39149 } // Convert the entries returned by `parseDict` to a proper dictionary. 39150 // If a value is a list of one, it is unpacked. 39151 39152 function entriesToObject(entries) { 39153 var o = { 39154 }; 39155 for (var i = 0; i < entries.length; i += 1) { 39156 var key = entries[i][0]; 39157 var values = entries[i][1]; 39158 var value = void 0; 39159 if (values.length === 1) { 39160 value = values[0]; 39161 } else { 39162 value = values; 39163 } 39164 if (o.hasOwnProperty(key) && !isNaN(o[key])) { 39165 throw new Error('Object ' + o + ' already has key ' + key); 39166 } 39167 o[key] = value; 39168 } 39169 return o; 39170 } // Parse a `CFF` DICT object. 39171 // A dictionary contains key-value pairs in a compact tokenized format. 39172 39173 function parseCFFDict(data, start, size) { 39174 start = start !== undefined ? start : 0; 39175 var parser = new parse.Parser(data, start); 39176 var entries = [ 39177 ]; 39178 var operands = [ 39179 ]; 39180 size = size !== undefined ? size : data.length; 39181 while (parser.relativeOffset < size) { 39182 var op = parser.parseByte(); // The first byte for each dict item distinguishes between operator (key) and operand (value). 39183 // Values <= 21 are operators. 39184 if (op <= 21) { 39185 // Two-byte operators have an initial escape byte of 12. 39186 if (op === 12) { 39187 op = 1200 + parser.parseByte(); 39188 } 39189 entries.push([op, 39190 operands]); 39191 operands = [ 39192 ]; 39193 } else { 39194 // Since the operands (values) come before the operators (keys), we store all operands in a list 39195 // until we encounter an operator. 39196 operands.push(parseOperand(parser, op)); 39197 } 39198 } 39199 return entriesToObject(entries); 39200 } // Given a String Index (SID), return the value of the string. 39201 // Strings below index 392 are standard CFF strings and are not encoded in the font. 39202 39203 function getCFFString(strings, index) { 39204 if (index <= 390) { 39205 index = cffStandardStrings[index]; 39206 } else { 39207 index = strings[index - 391]; 39208 } 39209 return index; 39210 } // Interpret a dictionary and return a new dictionary with readable keys and values for missing entries. 39211 // This function takes `meta` which is a list of objects containing `operand`, `name` and `default`. 39212 39213 function interpretDict(dict, meta, strings) { 39214 var newDict = { 39215 }; 39216 var value; // Because we also want to include missing values, we start out from the meta list 39217 // and lookup values in the dict. 39218 for (var i = 0; i < meta.length; i += 1) { 39219 var m = meta[i]; 39220 if (Array.isArray(m.type)) { 39221 var values = [ 39222 ]; 39223 values.length = m.type.length; 39224 for (var j = 0; j < m.type.length; j++) { 39225 value = dict[m.op] !== undefined ? dict[m.op][j] : undefined; 39226 if (value === undefined) { 39227 value = m.value !== undefined && m.value[j] !== undefined ? m.value[j] : null; 39228 } 39229 if (m.type[j] === 'SID') { 39230 value = getCFFString(strings, value); 39231 } 39232 values[j] = value; 39233 } 39234 newDict[m.name] = values; 39235 } else { 39236 value = dict[m.op]; 39237 if (value === undefined) { 39238 value = m.value !== undefined ? m.value : null; 39239 } 39240 if (m.type === 'SID') { 39241 value = getCFFString(strings, value); 39242 } 39243 newDict[m.name] = value; 39244 } 39245 } 39246 return newDict; 39247 } // Parse the CFF header. 39248 39249 function parseCFFHeader(data, start) { 39250 var header = { 39251 }; 39252 header.formatMajor = parse.getCard8(data, start); 39253 header.formatMinor = parse.getCard8(data, start + 1); 39254 header.size = parse.getCard8(data, start + 2); 39255 header.offsetSize = parse.getCard8(data, start + 3); 39256 header.startOffset = start; 39257 header.endOffset = start + 4; 39258 return header; 39259 } 39260 var TOP_DICT_META = [ 39261 { 39262 name: 'version', 39263 op: 0, 39264 type: 'SID' 39265 }, 39266 { 39267 name: 'notice', 39268 op: 1, 39269 type: 'SID' 39270 }, 39271 { 39272 name: 'copyright', 39273 op: 1200, 39274 type: 'SID' 39275 }, 39276 { 39277 name: 'fullName', 39278 op: 2, 39279 type: 'SID' 39280 }, 39281 { 39282 name: 'familyName', 39283 op: 3, 39284 type: 'SID' 39285 }, 39286 { 39287 name: 'weight', 39288 op: 4, 39289 type: 'SID' 39290 }, 39291 { 39292 name: 'isFixedPitch', 39293 op: 1201, 39294 type: 'number', 39295 value: 0 39296 }, 39297 { 39298 name: 'italicAngle', 39299 op: 1202, 39300 type: 'number', 39301 value: 0 39302 }, 39303 { 39304 name: 'underlinePosition', 39305 op: 1203, 39306 type: 'number', 39307 value: - 100 39308 }, 39309 { 39310 name: 'underlineThickness', 39311 op: 1204, 39312 type: 'number', 39313 value: 50 39314 }, 39315 { 39316 name: 'paintType', 39317 op: 1205, 39318 type: 'number', 39319 value: 0 39320 }, 39321 { 39322 name: 'charstringType', 39323 op: 1206, 39324 type: 'number', 39325 value: 2 39326 }, 39327 { 39328 name: 'fontMatrix', 39329 op: 1207, 39330 type: [ 39331 'real', 39332 'real', 39333 'real', 39334 'real', 39335 'real', 39336 'real' 39337 ], 39338 value: [ 39339 0.001, 39340 0, 39341 0, 39342 0.001, 39343 0, 39344 0 39345 ] 39346 }, 39347 { 39348 name: 'uniqueId', 39349 op: 13, 39350 type: 'number' 39351 }, 39352 { 39353 name: 'fontBBox', 39354 op: 5, 39355 type: [ 39356 'number', 39357 'number', 39358 'number', 39359 'number' 39360 ], 39361 value: [ 39362 0, 39363 0, 39364 0, 39365 0 39366 ] 39367 }, 39368 { 39369 name: 'strokeWidth', 39370 op: 1208, 39371 type: 'number', 39372 value: 0 39373 }, 39374 { 39375 name: 'xuid', 39376 op: 14, 39377 type: [ 39378 ], 39379 value: null 39380 }, 39381 { 39382 name: 'charset', 39383 op: 15, 39384 type: 'offset', 39385 value: 0 39386 }, 39387 { 39388 name: 'encoding', 39389 op: 16, 39390 type: 'offset', 39391 value: 0 39392 }, 39393 { 39394 name: 'charStrings', 39395 op: 17, 39396 type: 'offset', 39397 value: 0 39398 }, 39399 { 39400 name: 'private', 39401 op: 18, 39402 type: [ 39403 'number', 39404 'offset' 39405 ], 39406 value: [ 39407 0, 39408 0 39409 ] 39410 }, 39411 { 39412 name: 'ros', 39413 op: 1230, 39414 type: [ 39415 'SID', 39416 'SID', 39417 'number' 39418 ] 39419 }, 39420 { 39421 name: 'cidFontVersion', 39422 op: 1231, 39423 type: 'number', 39424 value: 0 39425 }, 39426 { 39427 name: 'cidFontRevision', 39428 op: 1232, 39429 type: 'number', 39430 value: 0 39431 }, 39432 { 39433 name: 'cidFontType', 39434 op: 1233, 39435 type: 'number', 39436 value: 0 39437 }, 39438 { 39439 name: 'cidCount', 39440 op: 1234, 39441 type: 'number', 39442 value: 8720 39443 }, 39444 { 39445 name: 'uidBase', 39446 op: 1235, 39447 type: 'number' 39448 }, 39449 { 39450 name: 'fdArray', 39451 op: 1236, 39452 type: 'offset' 39453 }, 39454 { 39455 name: 'fdSelect', 39456 op: 1237, 39457 type: 'offset' 39458 }, 39459 { 39460 name: 'fontName', 39461 op: 1238, 39462 type: 'SID' 39463 } 39464 ]; 39465 var PRIVATE_DICT_META = [ 39466 { 39467 name: 'subrs', 39468 op: 19, 39469 type: 'offset', 39470 value: 0 39471 }, 39472 { 39473 name: 'defaultWidthX', 39474 op: 20, 39475 type: 'number', 39476 value: 0 39477 }, 39478 { 39479 name: 'nominalWidthX', 39480 op: 21, 39481 type: 'number', 39482 value: 0 39483 } 39484 ]; // Parse the CFF top dictionary. A CFF table can contain multiple fonts, each with their own top dictionary. 39485 // The top dictionary contains the essential metadata for the font, together with the private dictionary. 39486 function parseCFFTopDict(data, strings) { 39487 var dict = parseCFFDict(data, 0, data.byteLength); 39488 return interpretDict(dict, TOP_DICT_META, strings); 39489 } // Parse the CFF private dictionary. We don't fully parse out all the values, only the ones we need. 39490 39491 function parseCFFPrivateDict(data, start, size, strings) { 39492 var dict = parseCFFDict(data, start, size); 39493 return interpretDict(dict, PRIVATE_DICT_META, strings); 39494 } // Returns a list of "Top DICT"s found using an INDEX list. 39495 // Used to read both the usual high-level Top DICTs and also the FDArray 39496 // discovered inside CID-keyed fonts. When a Top DICT has a reference to 39497 // a Private DICT that is read and saved into the Top DICT. 39498 // 39499 // In addition to the expected/optional values as outlined in TOP_DICT_META 39500 // the following values might be saved into the Top DICT. 39501 // 39502 // _subrs [] array of local CFF subroutines from Private DICT 39503 // _subrsBias bias value computed from number of subroutines 39504 // (see calcCFFSubroutineBias() and parseCFFCharstring()) 39505 // _defaultWidthX default widths for CFF characters 39506 // _nominalWidthX bias added to width embedded within glyph description 39507 // 39508 // _privateDict saved copy of parsed Private DICT from Top DICT 39509 39510 function gatherCFFTopDicts(data, start, cffIndex, strings) { 39511 var topDictArray = [ 39512 ]; 39513 for (var iTopDict = 0; iTopDict < cffIndex.length; iTopDict += 1) { 39514 var topDictData = new DataView(new Uint8Array(cffIndex[iTopDict]).buffer); 39515 var topDict = parseCFFTopDict(topDictData, strings); 39516 topDict._subrs = [ 39517 ]; 39518 topDict._subrsBias = 0; 39519 var privateSize = topDict.private[0]; 39520 var privateOffset = topDict.private[1]; 39521 if (privateSize !== 0 && privateOffset !== 0) { 39522 var privateDict = parseCFFPrivateDict(data, privateOffset + start, privateSize, strings); 39523 topDict._defaultWidthX = privateDict.defaultWidthX; 39524 topDict._nominalWidthX = privateDict.nominalWidthX; 39525 if (privateDict.subrs !== 0) { 39526 var subrOffset = privateOffset + privateDict.subrs; 39527 var subrIndex = parseCFFIndex(data, subrOffset + start); 39528 topDict._subrs = subrIndex.objects; 39529 topDict._subrsBias = calcCFFSubroutineBias(topDict._subrs); 39530 } 39531 topDict._privateDict = privateDict; 39532 } 39533 topDictArray.push(topDict); 39534 } 39535 return topDictArray; 39536 } // Parse the CFF charset table, which contains internal names for all the glyphs. 39537 // This function will return a list of glyph names. 39538 // See Adobe TN #5176 chapter 13, "Charsets". 39539 39540 function parseCFFCharset(data, start, nGlyphs, strings) { 39541 var sid; 39542 var count; 39543 var parser = new parse.Parser(data, start); // The .notdef glyph is not included, so subtract 1. 39544 nGlyphs -= 1; 39545 var charset = [ 39546 '.notdef' 39547 ]; 39548 var format = parser.parseCard8(); 39549 if (format === 0) { 39550 for (var i = 0; i < nGlyphs; i += 1) { 39551 sid = parser.parseSID(); 39552 charset.push(getCFFString(strings, sid)); 39553 } 39554 } else if (format === 1) { 39555 while (charset.length <= nGlyphs) { 39556 sid = parser.parseSID(); 39557 count = parser.parseCard8(); 39558 for (var i$1 = 0; i$1 <= count; i$1 += 1) { 39559 charset.push(getCFFString(strings, sid)); 39560 sid += 1; 39561 } 39562 } 39563 } else if (format === 2) { 39564 while (charset.length <= nGlyphs) { 39565 sid = parser.parseSID(); 39566 count = parser.parseCard16(); 39567 for (var i$2 = 0; i$2 <= count; i$2 += 1) { 39568 charset.push(getCFFString(strings, sid)); 39569 sid += 1; 39570 } 39571 } 39572 } else { 39573 throw new Error('Unknown charset format ' + format); 39574 } 39575 return charset; 39576 } // Parse the CFF encoding data. Only one encoding can be specified per font. 39577 // See Adobe TN #5176 chapter 12, "Encodings". 39578 39579 function parseCFFEncoding(data, start, charset) { 39580 var code; 39581 var enc = { 39582 }; 39583 var parser = new parse.Parser(data, start); 39584 var format = parser.parseCard8(); 39585 if (format === 0) { 39586 var nCodes = parser.parseCard8(); 39587 for (var i = 0; i < nCodes; i += 1) { 39588 code = parser.parseCard8(); 39589 enc[code] = i; 39590 } 39591 } else if (format === 1) { 39592 var nRanges = parser.parseCard8(); 39593 code = 1; 39594 for (var i$1 = 0; i$1 < nRanges; i$1 += 1) { 39595 var first = parser.parseCard8(); 39596 var nLeft = parser.parseCard8(); 39597 for (var j = first; j <= first + nLeft; j += 1) { 39598 enc[j] = code; 39599 code += 1; 39600 } 39601 } 39602 } else { 39603 throw new Error('Unknown encoding format ' + format); 39604 } 39605 return new CffEncoding(enc, charset); 39606 } // Take in charstring code and return a Glyph object. 39607 // The encoding is described in the Type 2 Charstring Format 39608 // https://www.microsoft.com/typography/OTSPEC/charstr2.htm 39609 39610 function parseCFFCharstring(font, glyph, code) { 39611 var c1x; 39612 var c1y; 39613 var c2x; 39614 var c2y; 39615 var p = new Path(); 39616 var stack = [ 39617 ]; 39618 var nStems = 0; 39619 var haveWidth = false; 39620 var open = false; 39621 var x = 0; 39622 var y = 0; 39623 var subrs; 39624 var subrsBias; 39625 var defaultWidthX; 39626 var nominalWidthX; 39627 if (font.isCIDFont) { 39628 var fdIndex = font.tables.cff.topDict._fdSelect[glyph.index]; 39629 var fdDict = font.tables.cff.topDict._fdArray[fdIndex]; 39630 subrs = fdDict._subrs; 39631 subrsBias = fdDict._subrsBias; 39632 defaultWidthX = fdDict._defaultWidthX; 39633 nominalWidthX = fdDict._nominalWidthX; 39634 } else { 39635 subrs = font.tables.cff.topDict._subrs; 39636 subrsBias = font.tables.cff.topDict._subrsBias; 39637 defaultWidthX = font.tables.cff.topDict._defaultWidthX; 39638 nominalWidthX = font.tables.cff.topDict._nominalWidthX; 39639 } 39640 var width = defaultWidthX; 39641 function newContour(x, y) { 39642 if (open) { 39643 p.closePath(); 39644 } 39645 p.moveTo(x, y); 39646 open = true; 39647 } 39648 function parseStems() { 39649 var hasWidthArg; // The number of stem operators on the stack is always even. 39650 // If the value is uneven, that means a width is specified. 39651 hasWidthArg = stack.length % 2 !== 0; 39652 if (hasWidthArg && !haveWidth) { 39653 width = stack.shift() + nominalWidthX; 39654 } 39655 nStems += stack.length >> 1; 39656 stack.length = 0; 39657 haveWidth = true; 39658 } 39659 function parse$$1(code) { 39660 var b1; 39661 var b2; 39662 var b3; 39663 var b4; 39664 var codeIndex; 39665 var subrCode; 39666 var jpx; 39667 var jpy; 39668 var c3x; 39669 var c3y; 39670 var c4x; 39671 var c4y; 39672 var i = 0; 39673 while (i < code.length) { 39674 var v = code[i]; 39675 i += 1; 39676 switch (v) { 39677 case 1: 39678 // hstem 39679 parseStems(); 39680 break; 39681 case 3: 39682 // vstem 39683 parseStems(); 39684 break; 39685 case 4: 39686 // vmoveto 39687 if (stack.length > 1 && !haveWidth) { 39688 width = stack.shift() + nominalWidthX; 39689 haveWidth = true; 39690 } 39691 y += stack.pop(); 39692 newContour(x, y); 39693 break; 39694 case 5: 39695 // rlineto 39696 while (stack.length > 0) { 39697 x += stack.shift(); 39698 y += stack.shift(); 39699 p.lineTo(x, y); 39700 } 39701 break; 39702 case 6: 39703 // hlineto 39704 while (stack.length > 0) { 39705 x += stack.shift(); 39706 p.lineTo(x, y); 39707 if (stack.length === 0) { 39708 break; 39709 } 39710 y += stack.shift(); 39711 p.lineTo(x, y); 39712 } 39713 break; 39714 case 7: 39715 // vlineto 39716 while (stack.length > 0) { 39717 y += stack.shift(); 39718 p.lineTo(x, y); 39719 if (stack.length === 0) { 39720 break; 39721 } 39722 x += stack.shift(); 39723 p.lineTo(x, y); 39724 } 39725 break; 39726 case 8: 39727 // rrcurveto 39728 while (stack.length > 0) { 39729 c1x = x + stack.shift(); 39730 c1y = y + stack.shift(); 39731 c2x = c1x + stack.shift(); 39732 c2y = c1y + stack.shift(); 39733 x = c2x + stack.shift(); 39734 y = c2y + stack.shift(); 39735 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39736 } 39737 break; 39738 case 10: 39739 // callsubr 39740 codeIndex = stack.pop() + subrsBias; 39741 subrCode = subrs[codeIndex]; 39742 if (subrCode) { 39743 parse$$1(subrCode); 39744 } 39745 break; 39746 case 11: 39747 // return 39748 return; 39749 case 12: 39750 // flex operators 39751 v = code[i]; 39752 i += 1; 39753 switch (v) { 39754 case 35: 39755 // flex 39756 // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 dx6 dy6 fd flex (12 35) |- 39757 c1x = x + stack.shift(); // dx1 39758 c1y = y + stack.shift(); // dy1 39759 c2x = c1x + stack.shift(); // dx2 39760 c2y = c1y + stack.shift(); // dy2 39761 jpx = c2x + stack.shift(); // dx3 39762 jpy = c2y + stack.shift(); // dy3 39763 c3x = jpx + stack.shift(); // dx4 39764 c3y = jpy + stack.shift(); // dy4 39765 c4x = c3x + stack.shift(); // dx5 39766 c4y = c3y + stack.shift(); // dy5 39767 x = c4x + stack.shift(); // dx6 39768 y = c4y + stack.shift(); // dy6 39769 stack.shift(); // flex depth 39770 p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); 39771 p.curveTo(c3x, c3y, c4x, c4y, x, y); 39772 break; 39773 case 34: 39774 // hflex 39775 // |- dx1 dx2 dy2 dx3 dx4 dx5 dx6 hflex (12 34) |- 39776 c1x = x + stack.shift(); // dx1 39777 c1y = y; // dy1 39778 c2x = c1x + stack.shift(); // dx2 39779 c2y = c1y + stack.shift(); // dy2 39780 jpx = c2x + stack.shift(); // dx3 39781 jpy = c2y; // dy3 39782 c3x = jpx + stack.shift(); // dx4 39783 c3y = c2y; // dy4 39784 c4x = c3x + stack.shift(); // dx5 39785 c4y = y; // dy5 39786 x = c4x + stack.shift(); // dx6 39787 p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); 39788 p.curveTo(c3x, c3y, c4x, c4y, x, y); 39789 break; 39790 case 36: 39791 // hflex1 39792 // |- dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6 hflex1 (12 36) |- 39793 c1x = x + stack.shift(); // dx1 39794 c1y = y + stack.shift(); // dy1 39795 c2x = c1x + stack.shift(); // dx2 39796 c2y = c1y + stack.shift(); // dy2 39797 jpx = c2x + stack.shift(); // dx3 39798 jpy = c2y; // dy3 39799 c3x = jpx + stack.shift(); // dx4 39800 c3y = c2y; // dy4 39801 c4x = c3x + stack.shift(); // dx5 39802 c4y = c3y + stack.shift(); // dy5 39803 x = c4x + stack.shift(); // dx6 39804 p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); 39805 p.curveTo(c3x, c3y, c4x, c4y, x, y); 39806 break; 39807 case 37: 39808 // flex1 39809 // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 d6 flex1 (12 37) |- 39810 c1x = x + stack.shift(); // dx1 39811 c1y = y + stack.shift(); // dy1 39812 c2x = c1x + stack.shift(); // dx2 39813 c2y = c1y + stack.shift(); // dy2 39814 jpx = c2x + stack.shift(); // dx3 39815 jpy = c2y + stack.shift(); // dy3 39816 c3x = jpx + stack.shift(); // dx4 39817 c3y = jpy + stack.shift(); // dy4 39818 c4x = c3x + stack.shift(); // dx5 39819 c4y = c3y + stack.shift(); // dy5 39820 if (Math.abs(c4x - x) > Math.abs(c4y - y)) { 39821 x = c4x + stack.shift(); 39822 } else { 39823 y = c4y + stack.shift(); 39824 } 39825 p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); 39826 p.curveTo(c3x, c3y, c4x, c4y, x, y); 39827 break; 39828 default: 39829 console.log('Glyph ' + glyph.index + ': unknown operator ' + 1200 + v); 39830 stack.length = 0; 39831 } 39832 break; 39833 case 14: 39834 // endchar 39835 if (stack.length > 0 && !haveWidth) { 39836 width = stack.shift() + nominalWidthX; 39837 haveWidth = true; 39838 } 39839 if (open) { 39840 p.closePath(); 39841 open = false; 39842 } 39843 break; 39844 case 18: 39845 // hstemhm 39846 parseStems(); 39847 break; 39848 case 19: // hintmask 39849 case 20: 39850 // cntrmask 39851 parseStems(); 39852 i += nStems + 7 >> 3; 39853 break; 39854 case 21: 39855 // rmoveto 39856 if (stack.length > 2 && !haveWidth) { 39857 width = stack.shift() + nominalWidthX; 39858 haveWidth = true; 39859 } 39860 y += stack.pop(); 39861 x += stack.pop(); 39862 newContour(x, y); 39863 break; 39864 case 22: 39865 // hmoveto 39866 if (stack.length > 1 && !haveWidth) { 39867 width = stack.shift() + nominalWidthX; 39868 haveWidth = true; 39869 } 39870 x += stack.pop(); 39871 newContour(x, y); 39872 break; 39873 case 23: 39874 // vstemhm 39875 parseStems(); 39876 break; 39877 case 24: 39878 // rcurveline 39879 while (stack.length > 2) { 39880 c1x = x + stack.shift(); 39881 c1y = y + stack.shift(); 39882 c2x = c1x + stack.shift(); 39883 c2y = c1y + stack.shift(); 39884 x = c2x + stack.shift(); 39885 y = c2y + stack.shift(); 39886 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39887 } 39888 x += stack.shift(); 39889 y += stack.shift(); 39890 p.lineTo(x, y); 39891 break; 39892 case 25: 39893 // rlinecurve 39894 while (stack.length > 6) { 39895 x += stack.shift(); 39896 y += stack.shift(); 39897 p.lineTo(x, y); 39898 } 39899 c1x = x + stack.shift(); 39900 c1y = y + stack.shift(); 39901 c2x = c1x + stack.shift(); 39902 c2y = c1y + stack.shift(); 39903 x = c2x + stack.shift(); 39904 y = c2y + stack.shift(); 39905 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39906 break; 39907 case 26: 39908 // vvcurveto 39909 if (stack.length % 2) { 39910 x += stack.shift(); 39911 } 39912 while (stack.length > 0) { 39913 c1x = x; 39914 c1y = y + stack.shift(); 39915 c2x = c1x + stack.shift(); 39916 c2y = c1y + stack.shift(); 39917 x = c2x; 39918 y = c2y + stack.shift(); 39919 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39920 } 39921 break; 39922 case 27: 39923 // hhcurveto 39924 if (stack.length % 2) { 39925 y += stack.shift(); 39926 } 39927 while (stack.length > 0) { 39928 c1x = x + stack.shift(); 39929 c1y = y; 39930 c2x = c1x + stack.shift(); 39931 c2y = c1y + stack.shift(); 39932 x = c2x + stack.shift(); 39933 y = c2y; 39934 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39935 } 39936 break; 39937 case 28: 39938 // shortint 39939 b1 = code[i]; 39940 b2 = code[i + 1]; 39941 stack.push((b1 << 24 | b2 << 16) >> 16); 39942 i += 2; 39943 break; 39944 case 29: 39945 // callgsubr 39946 codeIndex = stack.pop() + font.gsubrsBias; 39947 subrCode = font.gsubrs[codeIndex]; 39948 if (subrCode) { 39949 parse$$1(subrCode); 39950 } 39951 break; 39952 case 30: 39953 // vhcurveto 39954 while (stack.length > 0) { 39955 c1x = x; 39956 c1y = y + stack.shift(); 39957 c2x = c1x + stack.shift(); 39958 c2y = c1y + stack.shift(); 39959 x = c2x + stack.shift(); 39960 y = c2y + (stack.length === 1 ? stack.shift() : 0); 39961 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39962 if (stack.length === 0) { 39963 break; 39964 } 39965 c1x = x + stack.shift(); 39966 c1y = y; 39967 c2x = c1x + stack.shift(); 39968 c2y = c1y + stack.shift(); 39969 y = c2y + stack.shift(); 39970 x = c2x + (stack.length === 1 ? stack.shift() : 0); 39971 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39972 } 39973 break; 39974 case 31: 39975 // hvcurveto 39976 while (stack.length > 0) { 39977 c1x = x + stack.shift(); 39978 c1y = y; 39979 c2x = c1x + stack.shift(); 39980 c2y = c1y + stack.shift(); 39981 y = c2y + stack.shift(); 39982 x = c2x + (stack.length === 1 ? stack.shift() : 0); 39983 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39984 if (stack.length === 0) { 39985 break; 39986 } 39987 c1x = x; 39988 c1y = y + stack.shift(); 39989 c2x = c1x + stack.shift(); 39990 c2y = c1y + stack.shift(); 39991 x = c2x + stack.shift(); 39992 y = c2y + (stack.length === 1 ? stack.shift() : 0); 39993 p.curveTo(c1x, c1y, c2x, c2y, x, y); 39994 } 39995 break; 39996 default: 39997 if (v < 32) { 39998 console.log('Glyph ' + glyph.index + ': unknown operator ' + v); 39999 } else if (v < 247) { 40000 stack.push(v - 139); 40001 } else if (v < 251) { 40002 b1 = code[i]; 40003 i += 1; 40004 stack.push((v - 247) * 256 + b1 + 108); 40005 } else if (v < 255) { 40006 b1 = code[i]; 40007 i += 1; 40008 stack.push( - (v - 251) * 256 - b1 - 108); 40009 } else { 40010 b1 = code[i]; 40011 b2 = code[i + 1]; 40012 b3 = code[i + 2]; 40013 b4 = code[i + 3]; 40014 i += 4; 40015 stack.push((b1 << 24 | b2 << 16 | b3 << 8 | b4) / 65536); 40016 } 40017 } 40018 } 40019 } 40020 parse$$1(code); 40021 glyph.advanceWidth = width; 40022 return p; 40023 } 40024 function parseCFFFDSelect(data, start, nGlyphs, fdArrayCount) { 40025 var fdSelect = [ 40026 ]; 40027 var fdIndex; 40028 var parser = new parse.Parser(data, start); 40029 var format = parser.parseCard8(); 40030 if (format === 0) { 40031 // Simple list of nGlyphs elements 40032 for (var iGid = 0; iGid < nGlyphs; iGid++) { 40033 fdIndex = parser.parseCard8(); 40034 if (fdIndex >= fdArrayCount) { 40035 throw new Error('CFF table CID Font FDSelect has bad FD index value ' + fdIndex + ' (FD count ' + fdArrayCount + ')'); 40036 } 40037 fdSelect.push(fdIndex); 40038 } 40039 } else if (format === 3) { 40040 // Ranges 40041 var nRanges = parser.parseCard16(); 40042 var first = parser.parseCard16(); 40043 if (first !== 0) { 40044 throw new Error('CFF Table CID Font FDSelect format 3 range has bad initial GID ' + first); 40045 } 40046 var next; 40047 for (var iRange = 0; iRange < nRanges; iRange++) { 40048 fdIndex = parser.parseCard8(); 40049 next = parser.parseCard16(); 40050 if (fdIndex >= fdArrayCount) { 40051 throw new Error('CFF table CID Font FDSelect has bad FD index value ' + fdIndex + ' (FD count ' + fdArrayCount + ')'); 40052 } 40053 if (next > nGlyphs) { 40054 throw new Error('CFF Table CID Font FDSelect format 3 range has bad GID ' + next); 40055 } 40056 for (; first < next; first++) { 40057 fdSelect.push(fdIndex); 40058 } 40059 first = next; 40060 } 40061 if (next !== nGlyphs) { 40062 throw new Error('CFF Table CID Font FDSelect format 3 range has bad final GID ' + next); 40063 } 40064 } else { 40065 throw new Error('CFF Table CID Font FDSelect table has unsupported format ' + format); 40066 } 40067 return fdSelect; 40068 } // Parse the `CFF` table, which contains the glyph outlines in PostScript format. 40069 40070 function parseCFFTable(data, start, font) { 40071 font.tables.cff = { 40072 }; 40073 var header = parseCFFHeader(data, start); 40074 var nameIndex = parseCFFIndex(data, header.endOffset, parse.bytesToString); 40075 var topDictIndex = parseCFFIndex(data, nameIndex.endOffset); 40076 var stringIndex = parseCFFIndex(data, topDictIndex.endOffset, parse.bytesToString); 40077 var globalSubrIndex = parseCFFIndex(data, stringIndex.endOffset); 40078 font.gsubrs = globalSubrIndex.objects; 40079 font.gsubrsBias = calcCFFSubroutineBias(font.gsubrs); 40080 var topDictArray = gatherCFFTopDicts(data, start, topDictIndex.objects, str
40080ingIndex.objects); 40081 if (topDictArray.length !== 1) { 40082 throw new Error('CFF table has too many fonts in \'FontSet\' - count of fonts NameIndex.length = ' + topDictArray.length); 40083 } 40084 var topDict = topDictArray[0]; 40085 font.tables.cff.topDict = topDict; 40086 if (topDict._privateDict) { 40087 font.defaultWidthX = topDict._privateDict.defaultWidthX; 40088 font.nominalWidthX = topDict._privateDict.nominalWidthX; 40089 } 40090 if (topDict.ros[0] !== undefined && topDict.ros[1] !== undefined) { 40091 font.isCIDFont = true; 40092 } 40093 if (font.isCIDFont) { 40094 var fdArrayOffset = topDict.fdArray; 40095 var fdSelectOffset = topDict.fdSelect; 40096 if (fdArrayOffset === 0 || fdSelectOffset === 0) { 40097 throw new Error('Font is marked as a CID font, but FDArray and/or FDSelect information is missing'); 40098 } 40099 fdArrayOffset += start; 40100 var fdArrayIndex = parseCFFIndex(data, fdArrayOffset); 40101 var fdArray = gatherCFFTopDicts(data, start, fdArrayIndex.objects, stringIndex.objects); 40102 topDict._fdArray = fdArray; 40103 fdSelectOffset += start; 40104 topDict._fdSelect = parseCFFFDSelect(data, fdSelectOffset, font.numGlyphs, fdArray.length); 40105 } 40106 var privateDictOffset = start + topDict.private[1]; 40107 var privateDict = parseCFFPrivateDict(data, privateDictOffset, topDict.private[0], stringIndex.objects); 40108 font.defaultWidthX = privateDict.defaultWidthX; 40109 font.nominalWidthX = privateDict.nominalWidthX; 40110 if (privateDict.subrs !== 0) { 40111 var subrOffset = privateDictOffset + privateDict.subrs; 40112 var subrIndex = parseCFFIndex(data, subrOffset); 40113 font.subrs = subrIndex.objects; 40114 font.subrsBias = calcCFFSubroutineBias(font.subrs); 40115 } else { 40116 font.subrs = [ 40117 ]; 40118 font.subrsBias = 0; 40119 } // Offsets in the top dict are relative to the beginning of the CFF data, so add the CFF start offset. 40120 40121 var charStringsIndex = parseCFFIndex(data, start + topDict.charStrings); 40122 font.nGlyphs = charStringsIndex.objects.length; 40123 var charset = parseCFFCharset(data, start + topDict.charset, font.nGlyphs, stringIndex.objects); 40124 if (topDict.encoding === 0) { 40125 // Standard encoding 40126 font.cffEncoding = new CffEncoding(cffStandardEncoding, charset); 40127 } else if (topDict.encoding === 1) { 40128 // Expert encoding 40129 font.cffEncoding = new CffEncoding(cffExpertEncoding, charset); 40130 } else { 40131 font.cffEncoding = parseCFFEncoding(data, start + topDict.encoding, charset); 40132 } // Prefer the CMAP encoding to the CFF encoding. 40133 40134 font.encoding = font.encoding || font.cffEncoding; 40135 font.glyphs = new glyphset.GlyphSet(font); 40136 for (var i = 0; i < font.nGlyphs; i += 1) { 40137 var charString = charStringsIndex.objects[i]; 40138 font.glyphs.push(i, glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString)); 40139 } 40140 } // Convert a string to a String ID (SID). 40141 // The list of strings is modified in place. 40142 40143 function encodeString(s, strings) { 40144 var sid; // Is the string in the CFF standard strings? 40145 var i = cffStandardStrings.indexOf(s); 40146 if (i >= 0) { 40147 sid = i; 40148 } // Is the string already in the string index? 40149 40150 i = strings.indexOf(s); 40151 if (i >= 0) { 40152 sid = i + cffStandardStrings.length; 40153 } else { 40154 sid = cffStandardStrings.length + strings.length; 40155 strings.push(s); 40156 } 40157 return sid; 40158 } 40159 function makeHeader() { 40160 return new table.Record('Header', [ 40161 { 40162 name: 'major', 40163 type: 'Card8', 40164 value: 1 40165 }, 40166 { 40167 name: 'minor', 40168 type: 'Card8', 40169 value: 0 40170 }, 40171 { 40172 name: 'hdrSize', 40173 type: 'Card8', 40174 value: 4 40175 }, 40176 { 40177 name: 'major', 40178 type: 'Card8', 40179 value: 1 40180 } 40181 ]); 40182 } 40183 function makeNameIndex(fontNames) { 40184 var t = new table.Record('Name INDEX', [ 40185 { 40186 name: 'names', 40187 type: 'INDEX', 40188 value: [ 40189 ] 40190 } 40191 ]); 40192 t.names = [ 40193 ]; 40194 for (var i = 0; i < fontNames.length; i += 1) { 40195 t.names.push({ 40196 name: 'name_' + i, 40197 type: 'NAME', 40198 value: fontNames[i] 40199 }); 40200 } 40201 return t; 40202 } // Given a dictionary's metadata, create a DICT structure. 40203 40204 function makeDict(meta, attrs, strings) { 40205 var m = { 40206 }; 40207 for (var i = 0; i < meta.length; i += 1) { 40208 var entry = meta[i]; 40209 var value = attrs[entry.name]; 40210 if (value !== undefined && !equals(value, entry.value)) { 40211 if (entry.type === 'SID') { 40212 value = encodeString(value, strings); 40213 } 40214 m[entry.op] = { 40215 name: entry.name, 40216 type: entry.type, 40217 value: value 40218 }; 40219 } 40220 } 40221 return m; 40222 } // The Top DICT houses the global font attributes. 40223 40224 function makeTopDict(attrs, strings) { 40225 var t = new table.Record('Top DICT', [ 40226 { 40227 name: 'dict', 40228 type: 'DICT', 40229 value: { 40230 } 40231 } 40232 ]); 40233 t.dict = makeDict(TOP_DICT_META, attrs, strings); 40234 return t; 40235 } 40236 function makeTopDictIndex(topDict) { 40237 var t = new table.Record('Top DICT INDEX', [ 40238 { 40239 name: 'topDicts', 40240 type: 'INDEX', 40241 value: [ 40242 ] 40243 } 40244 ]); 40245 t.topDicts = [ 40246 { 40247 name: 'topDict_0', 40248 type: 'TABLE', 40249 value: topDict 40250 } 40251 ]; 40252 return t; 40253 } 40254 function makeStringIndex(strings) { 40255 var t = new table.Record('String INDEX', [ 40256 { 40257 name: 'strings', 40258 type: 'INDEX', 40259 value: [ 40260 ] 40261 } 40262 ]); 40263 t.strings = [ 40264 ]; 40265 for (var i = 0; i < strings.length; i += 1) { 40266 t.strings.push({ 40267 name: 'string_' + i, 40268 type: 'STRING', 40269 value: strings[i] 40270 }); 40271 } 40272 return t; 40273 } 40274 function makeGlobalSubrIndex() { 40275 // Currently we don't use subroutines. 40276 return new table.Record('Global Subr INDEX', [ 40277 { 40278 name: 'subrs', 40279 type: 'INDEX', 40280 value: [ 40281 ] 40282 } 40283 ]); 40284 }
40285 function makeCharsets(glyphNames, strings) { 40286 var t = new table.Record('Charsets', [ 40287 { 40288 name: 'format', 40289 type: 'Card8', 40290 value: 0 40291 } 40292 ]); 40293 for (var i = 0; i < glyphNames.length; i += 1) { 40294 var glyphName = glyphNames[i]; 40295 var glyphSID = encodeString(glyphName, strings); 40296 t.fields.push({ 40297 name: 'glyph_' + i, 40298 type: 'SID', 40299 value: glyphSID 40300 }); 40301 } 40302 return t; 40303 } 40304 function glyphToOps(glyph) { 40305 var ops = [ 40306 ]; 40307 var path = glyph.path; 40308 ops.push({ 40309 name: 'width', 40310 type: 'NUMBER', 40311 value: glyph.advanceWidth 40312 }); 40313 var x = 0; 40314 var y = 0; 40315 for (var i = 0; i < path.commands.length; i += 1) { 40316 var dx = void 0; 40317 var dy = void 0; 40318 var cmd = path.commands[i]; 40319 if (cmd.type === 'Q') { 40320 // CFF only supports bézier curves, so convert the quad to a bézier. 40321 var _13 = 1 / 3; 40322 var _23 = 2 / 3; // We're going to create a new command so we don't change the original path. 40323 cmd = { 40324 type: 'C', 40325 x: cmd.x, 40326 y: cmd.y, 40327 x1: _13 * x + _23 * cmd.x1, 40328 y1: _13 * y + _23 * cmd.y1, 40329 x2: _13 * cmd.x + _23 * cmd.x1, 40330 y2: _13 * cmd.y + _23 * cmd.y1 40331 }; 40332 } 40333 if (cmd.type === 'M') { 40334 dx = Math.round(cmd.x - x); 40335 dy = Math.round(cmd.y - y); 40336 ops.push({ 40337 name: 'dx', 40338 type: 'NUMBER', 40339 value: dx 40340 }); 40341 ops.push({ 40342 name: 'dy', 40343 type: 'NUMBER', 40344 value: dy 40345 }); 40346 ops.push({ 40347 name: 'rmoveto', 40348 type: 'OP', 40349 value: 21 40350 }); 40351 x = Math.round(cmd.x); 40352 y = Math.round(cmd.y); 40353 } else if (cmd.type === 'L') { 40354 dx = Math.round(cmd.x - x); 40355 dy = Math.round(cmd.y - y); 40356 ops.push({ 40357 name: 'dx', 40358 type: 'NUMBER', 40359 value: dx 40360 }); 40361 ops.push({ 40362 name: 'dy', 40363 type: 'NUMBER', 40364 value: dy 40365 }); 40366 ops.push({ 40367 name: 'rlineto', 40368 type: 'OP', 40369 value: 5 40370 }); 40371 x = Math.round(cmd.x); 40372 y = Math.round(cmd.y); 40373 } else if (cmd.type === 'C') { 40374 var dx1 = Math.round(cmd.x1 - x); 40375 var dy1 = Math.round(cmd.y1 - y); 40376 var dx2 = Math.round(cmd.x2 - cmd.x1); 40377 var dy2 = Math.round(cmd.y2 - cmd.y1); 40378 dx = Math.round(cmd.x - cmd.x2); 40379 dy = Math.round(cmd.y - cmd.y2); 40380 ops.push({ 40381 name: 'dx1', 40382 type: 'NUMBER', 40383 value: dx1 40384 }); 40385 ops.push({ 40386 name: 'dy1', 40387 type: 'NUMBER', 40388 value: dy1 40389 }); 40390 ops.push({ 40391 name: 'dx2', 40392 type: 'NUMBER', 40393 value: dx2 40394 }); 40395 ops.push({ 40396 name: 'dy2', 40397 type: 'NUMBER', 40398 value: dy2 40399 }); 40400 ops.push({ 40401 name: 'dx', 40402 type: 'NUMBER', 40403 value: dx 40404 }); 40405 ops.push({ 40406 name: 'dy', 40407 type: 'NUMBER', 40408 value: dy 40409 }); 40410 ops.push({ 40411 name: 'rrcurveto', 40412 type: 'OP', 40413 value: 8 40414 }); 40415 x = Math.round(cmd.x); 40416 y = Math.round(cmd.y); 40417 } // Contours are closed automatically. 40418 40419 } 40420 ops.push({ 40421 name: 'endchar', 40422 type: 'OP', 40423 value: 14 40424 }); 40425 return ops; 40426 } 40427 function makeCharStringsIndex(glyphs) { 40428 var t = new table.Record('CharStrings INDEX', [ 40429 { 40430 name: 'charStrings', 40431 type: 'INDEX', 40432 value: [ 40433 ] 40434 } 40435 ]); 40436 for (var i = 0; i < glyphs.length; i += 1) { 40437 var glyph = glyphs.get(i); 40438 var ops = glyphToOps(glyph); 40439 t.charStrings.push({ 40440 name: glyph.name, 40441 type: 'CHARSTRING', 40442 value: ops 40443 }); 40444 } 40445 return t; 40446 } 40447 function makePrivateDict(attrs, strings) { 40448 var t = new table.Record('Private DICT', [ 40449 { 40450 name: 'dict', 40451 type: 'DICT', 40452 value: { 40453 } 40454 } 40455 ]); 40456 t.dict = makeDict(PRIVATE_DICT_META, attrs, strings); 40457 return t; 40458 } 40459 function makeCFFTable(glyphs, options) { 40460 var t = new table.Table('CFF ', [ 40461 { 40462 name: 'header', 40463 type: 'RECORD' 40464 }, 40465 { 40466 name: 'nameIndex', 40467 type: 'RECORD' 40468 }, 40469 { 40470 name: 'topDictIndex', 40471 type: 'RECORD' 40472 }, 40473 { 40474 name: 'stringIndex', 40475 type: 'RECORD' 40476 }, 40477 { 40478 name: 'globalSubrIndex', 40479 type: 'RECORD' 40480 }, 40481 { 40482 name: 'charsets', 40483 type: 'RECORD' 40484 }, 40485 { 40486 name: 'charStringsIndex', 40487 type: 'RECORD' 40488 }, 40489 { 40490 name: 'privateDict', 40491 type: 'RECORD' 40492 } 40493 ]); 40494 var fontScale = 1 / options.unitsPerEm; // We use non-zero values for the offsets so that the DICT encodes them. 40495 // This is important because the size of the Top DICT plays a role in offset calculation, 40496 // and the size shouldn't change after we've written correct offsets. 40497 var attrs = { 40498 version: options.version, 40499 fullName: options.fullName, 40500 familyName: options.familyName, 40501 weight: options.weightName, 40502 fontBBox: options.fontBBox || [ 40503 0, 40504 0, 40505 0, 40506 0 40507 ], 40508 fontMatrix: [ 40509 fontScale, 40510 0, 40511 0, 40512 fontScale, 40513 0, 40514 0 40515 ], 40516 charset: 999, 40517 encoding: 0, 40518 charStrings: 999, 40519 private: [ 40520 0, 40521 999 40522 ] 40523 }; 40524 var privateAttrs = { 40525 }; 40526 var glyphNames = [ 40527 ]; 40528 var glyph; // Skip first glyph (.notdef) 40529 for (var i = 1; i < glyphs.length; i += 1) { 40530 glyph = glyphs.get(i); 40531 glyphNames.push(glyph.name); 40532 } 40533 var strings = [ 40534 ]; 40535 t.header = makeHeader(); 40536 t.nameIndex = makeNameIndex([options.postScriptName]); 40537 var topDict = makeTopDict(attrs, strings); 40538 t.topDictIndex = makeTopDictIndex(topDict); 40539 t.globalSubrIndex = makeGlobalSubrIndex();
40540 t.charsets = makeCharsets(glyphNames, strings); 40541 t.charStringsIndex = makeCharStringsIndex(glyphs); 40542 t.privateDict = makePrivateDict(privateAttrs, strings); // Needs to come at the end, to encode all custom strings used in the font. 40543 t.stringIndex = makeStringIndex(strings); 40544 var startOffset = t.header.sizeOf() + t.nameIndex.sizeOf() + t.topDictIndex.sizeOf() + t.stringIndex.sizeOf() + t.globalSubrIndex.sizeOf(); 40545 attrs.charset = startOffset; // We use the CFF standard encoding; proper encoding will be handled in cmap. 40546 attrs.encoding = 0; 40547 attrs.charStrings = attrs.charset + t.charsets.sizeOf(); 40548 attrs.private[1] = attrs.charStrings + t.charStringsIndex.sizeOf(); // Recreate the Top DICT INDEX with the correct offsets. 40549 topDict = makeTopDict(attrs, strings); 40550 t.topDictIndex = makeTopDictIndex(topDict); 40551 return t; 40552 } 40553 var cff = { 40554 parse: parseCFFTable, 40555 make: makeCFFTable 40556 }; // The `head` table contains global information about the font. 40557 // Parse the header `head` table 40558 function parseHeadTable(data, start) { 40559 var head = { 40560 }; 40561 var p = new parse.Parser(data, start); 40562 head.version = p.parseVersion(); 40563 head.fontRevision = Math.round(p.parseFixed() * 1000) / 1000; 40564 head.checkSumAdjustment = p.parseULong(); 40565 head.magicNumber = p.parseULong(); 40566 check.argument(head.magicNumber === 1594834165, 'Font header has wrong magic number.'); 40567 head.flags = p.parseUShort(); 40568 head.unitsPerEm = p.parseUShort(); 40569 head.created = p.parseLongDateTime(); 40570 head.modified = p.parseLongDateTime(); 40571 head.xMin = p.parseShort(); 40572 head.yMin = p.parseShort(); 40573 head.xMax = p.parseShort(); 40574 head.yMax = p.parseShort(); 40575 head.macStyle = p.parseUShort(); 40576 head.lowestRecPPEM = p.parseUShort(); 40577 head.fontDirectionHint = p.parseShort(); 40578 head.indexToLocFormat = p.parseShort(); 40579 head.glyphDataFormat = p.parseShort(); 40580 return head; 40581 } 40582 function makeHeadTable(options) { 40583 // Apple Mac timestamp epoch is 01/01/1904 not 01/01/1970 40584 var timestamp = Math.round(new Date().getTime() / 1000) + 2082844800; 40585 var createdTimestamp = timestamp; 40586 if (options.createdTimestamp) { 40587 createdTimestamp = options.createdTimestamp + 2082844800; 40588 } 40589 return new table.Table('head', [ 40590 { 40591 name: 'version', 40592 type: 'FIXED', 40593 value: 65536 40594 }, 40595 { 40596 name: 'fontRevision', 40597 type: 'FIXED', 40598 value: 65536 40599 }, 40600 { 40601 name: 'checkSumAdjustment', 40602 type: 'ULONG', 40603 value: 0 40604 }, 40605 { 40606 name: 'magicNumber', 40607 type: 'ULONG', 40608 value: 1594834165 40609 }, 40610 { 40611 name: 'flags', 40612 type: 'USHORT', 40613 value: 0 40614 }, 40615 { 40616 name: 'unitsPerEm', 40617 type: 'USHORT', 40618 value: 1000 40619 }, 40620 { 40621 name: 'created', 40622 type: 'LONGDATETIME', 40623 value: createdTimestamp 40624 }, 40625 { 40626 name: 'modified', 40627 type: 'LONGDATETIME', 40628 value: timestamp 40629 }, 40630 { 40631 name: 'xMin', 40632 type: 'SHORT', 40633 value: 0 40634 }, 40635 { 40636 name: 'yMin', 40637 type: 'SHORT', 40638 value: 0 40639 }, 40640 { 40641 name: 'xMax', 40642 type: 'SHORT', 40643 value: 0 40644 }, 40645 { 40646 name: 'yMax', 40647 type: 'SHORT', 40648 value: 0 40649 }, 40650 { 40651 name: 'macStyle', 40652 type: 'USHORT', 40653 value: 0 40654 }, 40655 { 40656 name: 'lowestRecPPEM', 40657 type: 'USHORT', 40658 value: 0 40659 }, 40660 { 40661 name: 'fontDirectionHint', 40662 type: 'SHORT', 40663 value: 2 40664 }, 40665 { 40666 name: 'indexToLocFormat', 40667 type: 'SHORT', 40668 value: 0 40669 }, 40670 { 40671 name: 'glyphDataFormat', 40672 type: 'SHORT', 40673 value: 0 40674 } 40675 ], options); 40676 } 40677 var head = { 40678 parse: parseHeadTable, 40679 make: makeHeadTable 40680 }; // The `hhea` table contains information for horizontal layout. 40681 // Parse the horizontal header `hhea` table 40682 function parseHheaTable(data, start) { 40683 var hhea = { 40684 }; 40685 var p = new parse.Parser(data, start); 40686 hhea.version = p.parseVersion(); 40687 hhea.ascender = p.parseShort(); 40688 hhea.descender = p.parseShort(); 40689 hhea.lineGap = p.parseShort(); 40690 hhea.advanceWidthMax = p.parseUShort(); 40691 hhea.minLeftSideBearing = p.parseShort(); 40692 hhea.minRightSideBearing = p.parseShort(); 40693 hhea.xMaxExtent = p.parseShort(); 40694 hhea.caretSlopeRise = p.parseShort(); 40695 hhea.caretSlopeRun = p.parseShort(); 40696 hhea.caretOffset = p.parseShort(); 40697 p.relativeOffset += 8; 40698 hhea.metricDataFormat = p.parseShort(); 40699 hhea.numberOfHMetrics = p.parseUShort(); 40700 return hhea; 40701 } 40702 function makeHheaTable(options) { 40703 return new table.Table('hhea', [ 40704 { 40705 name: 'version', 40706 type: 'FIXED', 40707 value: 65536 40708 }, 40709 { 40710 name: 'ascender', 40711 type: 'FWORD', 40712 value: 0 40713 }, 40714 { 40715 name: 'descender', 40716 type: 'FWORD', 40717 value: 0 40718 }, 40719 { 40720 name: 'lineGap', 40721 type: 'FWORD', 40722 value: 0 40723 }, 40724 { 40725 name: 'advanceWidthMax', 40726 type: 'UFWORD', 40727 value: 0 40728 }, 40729 { 40730 name: 'minLeftSideBearing', 40731 type: 'FWORD', 40732 value: 0 40733 }, 40734 { 40735 name: 'minRightSideBearing', 40736 type: 'FWORD', 40737 value: 0 40738 }, 40739 { 40740 name: 'xMaxExtent', 40741 type: 'FWORD', 40742 value: 0 40743 }, 40744 { 40745 name: 'caretSlopeRise', 40746 type: 'SHORT', 40747 value: 1 40748 }, 40749 { 40750 name: 'caretSlopeRun', 40751 type: 'SHORT', 40752 value: 0 40753 }, 40754 { 40755 name: 'caretOffset', 40756 type: 'SHORT', 40757 value: 0 40758 }, 40759 { 40760 name: 'reserved1', 40761 type: 'SHORT', 40762 value: 0 40763 }, 40764 { 40765 name: 'reserved2', 40766 type: 'SHORT', 40767 value: 0 40768 }, 40769 { 40770 name: 'reserved3', 40771 type: 'SHORT', 40772 value: 0 40773 }, 40774 { 40775 name: 'reserved4', 40776 type: 'SHORT', 40777 value: 0 40778 }, 40779 { 40780 name: 'metricDataFormat', 40781 type: 'SHORT', 40782 value: 0 40783 }, 40784 { 40785 name: 'numberOfHMetrics', 40786 type: 'USHORT', 40787 value: 0 40788 } 40789 ], options); 40790 } 40791 var hhea = { 40792 parse: parseHheaTable, 40793 make: makeHheaTable 40794 }; // The `hmtx` table contains the horizontal metrics for all glyphs. 40795 // Parse the `hmtx` table, which contains the horizontal metrics for all glyphs. 40796 // This function augments the glyph array, adding the advanceWidth and leftSideBearing to each glyph. 40797 function parseHmtxTable(data, start, numMetrics, numGlyphs, glyphs) { 40798 var advanceWidth; 40799 var leftSideBearing; 40800 var p = new parse.Parser(data, start); 40801 for (var i = 0; i < numGlyphs; i += 1) { 40802 // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs. 40803 if (i < numMetrics) { 40804 advanceWidth = p.parseUShort(); 40805 leftSideBearing = p.parseShort(); 40806 } 40807 var glyph = glyphs.get(i); 40808 glyph.advanceWidth = advanceWidth; 40809 glyph.leftSideBearing = leftSideBearing; 40810 } 40811 } 40812 function makeHmtxTable(glyphs) { 40813 var t = new table.Table('hmtx', [ 40814 ]); 40815 for (var i = 0; i < glyphs.length; i += 1) { 40816 var glyph = glyphs.get(i); 40817 var advanceWidth = glyph.advanceWidth || 0; 40818 var leftSideBearing = glyph.leftSideBearing || 0; 40819 t.fields.push({ 40820 name: 'advanceWidth_' + i, 40821 type: 'USHORT', 40822 value: advanceWidth 40823 }); 40824 t.fields.push({ 40825 name: 'leftSideBearing_' + i, 40826 type: 'SHORT', 40827 value: leftSideBearing 40828 }); 40829 } 40830 return t; 40831 } 40832 var hmtx = { 40833 parse: parseHmtxTable, 40834 make: makeHmtxTable 40835 }; // The `ltag` table stores IETF BCP-47 language tags. It allows supporting 40836 function makeLtagTable(tags) { 40837 var result = new table.Table('ltag', [ 40838 { 40839 name: 'version', 40840 type: 'ULONG', 40841 value: 1 40842 }, 40843 { 40844 name: 'flags', 40845 type: 'ULONG', 40846 value: 0 40847 }, 40848 { 40849 name: 'numTags', 40850 type: 'ULONG', 40851 value: tags.length 40852 } 40853 ]); 40854 var stringPool = ''; 40855 var stringPoolOffset = 12 + tags.length * 4; 40856 for (var i = 0; i < tags.length; ++i) { 40857 var pos = stringPool.indexOf(tags[i]); 40858 if (pos < 0) { 40859 pos = stringPool.length;
vendor: 8,232 bytes, lines 40860-41110
40860 stringPool += tags[i]; 40861 } 40862 result.fields.push({ 40863 name: 'offset ' + i, 40864 type: 'USHORT', 40865 value: stringPoolOffset + pos 40866 }); 40867 result.fields.push({ 40868 name: 'length ' + i, 40869 type: 'USHORT', 40870 value: tags[i].length 40871 }); 40872 } 40873 result.fields.push({ 40874 name: 'stringPool', 40875 type: 'CHARARRAY', 40876 value: stringPool 40877 }); 40878 return result; 40879 } 40880 function parseLtagTable(data, start) { 40881 var p = new parse.Parser(data, start); 40882 var tableVersion = p.parseULong(); 40883 check.argument(tableVersion === 1, 'Unsupported ltag table version.'); // The 'ltag' specification does not define any flags; skip the field. 40884 p.skip('uLong', 1); 40885 var numTags = p.parseULong(); 40886 var tags = [ 40887 ]; 40888 for (var i = 0; i < numTags; i++) { 40889 var tag = ''; 40890 var offset = start + p.parseUShort(); 40891 var length = p.parseUShort(); 40892 for (var j = offset; j < offset + length; ++j) { 40893 tag += String.fromCharCode(data.getInt8(j)); 40894 } 40895 tags.push(tag); 40896 } 40897 return tags; 40898 } 40899 var ltag = { 40900 make: makeLtagTable, 40901 parse: parseLtagTable 40902 }; // The `maxp` table establishes the memory requirements for the font. 40903 // Parse the maximum profile `maxp` table. 40904 function parseMaxpTable(data, start) { 40905 var maxp = { 40906 }; 40907 var p = new parse.Parser(data, start); 40908 maxp.version = p.parseVersion(); 40909 maxp.numGlyphs = p.parseUShort(); 40910 if (maxp.version === 1) { 40911 maxp.maxPoints = p.parseUShort(); 40912 maxp.maxContours = p.parseUShort(); 40913 maxp.maxCompositePoints = p.parseUShort(); 40914 maxp.maxCompositeContours = p.parseUShort(); 40915 maxp.maxZones = p.parseUShort(); 40916 maxp.maxTwilightPoints = p.parseUShort(); 40917 maxp.maxStorage = p.parseUShort(); 40918 maxp.maxFunctionDefs = p.parseUShort(); 40919 maxp.maxInstructionDefs = p.parseUShort(); 40920 maxp.maxStackElements = p.parseUShort(); 40921 maxp.maxSizeOfInstructions = p.parseUShort(); 40922 maxp.maxComponentElements = p.parseUShort(); 40923 maxp.maxComponentDepth = p.parseUShort(); 40924 } 40925 return maxp; 40926 } 40927 function makeMaxpTable(numGlyphs) { 40928 return new table.Table('maxp', [ 40929 { 40930 name: 'version', 40931 type: 'FIXED', 40932 value: 20480 40933 }, 40934 { 40935 name: 'numGlyphs', 40936 type: 'USHORT', 40937 value: numGlyphs 40938 } 40939 ]); 40940 } 40941 var maxp = { 40942 parse: parseMaxpTable, 40943 make: makeMaxpTable 40944 }; // The `name` naming table. 40945 // NameIDs for the name table. 40946 var nameTableNames = [ 40947 'copyright', // 0 40948 'fontFamily', // 1 40949 'fontSubfamily', // 2 40950 'uniqueID', // 3 40951 'fullName', // 4 40952 'version', // 5 40953 'postScriptName', // 6 40954 'trademark', // 7 40955 'manufacturer', // 8 40956 'designer', // 9 40957 'description', // 10 40958 'manufacturerURL', // 11 40959 'designerURL', // 12 40960 'license', // 13 40961 'licenseURL', // 14 40962 'reserved', // 15 40963 'preferredFamily', // 16 40964 'preferredSubfamily', // 17 40965 'compatibleFullName', // 18 40966 'sampleText', // 19 40967 'postScriptFindFontName', // 20 40968 'wwsFamily', // 21 40969 'wwsSubfamily' // 22 40970 ]; 40971 var macLanguages = { 40972 0: 'en', 40973 1: 'fr', 40974 2: 'de', 40975 3: 'it', 40976 4: 'nl', 40977 5: 'sv', 40978 6: 'es', 40979 7: 'da', 40980 8: 'pt', 40981 9: 'no', 40982 10: 'he', 40983 11: 'ja', 40984 12: 'ar', 40985 13: 'fi', 40986 14: 'el', 40987 15: 'is', 40988 16: 'mt', 40989 17: 'tr', 40990 18: 'hr', 40991 19: 'zh-Hant', 40992 20: 'ur', 40993 21: 'hi', 40994 22: 'th', 40995 23: 'ko', 40996 24: 'lt', 40997 25: 'pl', 40998 26: 'hu', 40999 27: 'es', 41000 28: 'lv', 41001 29: 'se', 41002 30: 'fo', 41003 31: 'fa', 41004 32: 'ru', 41005 33: 'zh', 41006 34: 'nl-BE', 41007 35: 'ga', 41008 36: 'sq', 41009 37: 'ro', 41010 38: 'cz', 41011 39: 'sk', 41012 40: 'si', 41013 41: 'yi', 41014 42: 'sr', 41015 43: 'mk', 41016 44: 'bg', 41017 45: 'uk', 41018 46: 'be', 41019 47: 'uz', 41020 48: 'kk', 41021 49: 'az-Cyrl', 41022 50: 'az-Arab', 41023 51: 'hy', 41024 52: 'ka', 41025 53: 'mo', 41026 54: 'ky', 41027 55: 'tg', 41028 56: 'tk', 41029 57: 'mn-CN', 41030 58: 'mn', 41031 59: 'ps', 41032 60: 'ks', 41033 61: 'ku', 41034 62: 'sd', 41035 63: 'bo', 41036 64: 'ne', 41037 65: 'sa', 41038 66: 'mr', 41039 67: 'bn', 41040 68: 'as', 41041 69: 'gu', 41042 70: 'pa', 41043 71: 'or', 41044 72: 'ml', 41045 73: 'kn', 41046 74: 'ta', 41047 75: 'te', 41048 76: 'si', 41049 77: 'my', 41050 78: 'km', 41051 79: 'lo', 41052 80: 'vi', 41053 81: 'id', 41054 82: 'tl', 41055 83: 'ms', 41056 84: 'ms-Arab', 41057 85: 'am', 41058 86: 'ti', 41059 87: 'om', 41060 88: 'so', 41061 89: 'sw', 41062 90: 'rw', 41063 91: 'rn', 41064 92: 'ny', 41065 93: 'mg', 41066 94: 'eo', 41067 128: 'cy', 41068 129: 'eu', 41069 130: 'ca', 41070 131: 'la', 41071 132: 'qu', 41072 133: 'gn', 41073 134: 'ay', 41074 135: 'tt', 41075 136: 'ug', 41076 137: 'dz', 41077 138: 'jv', 41078 139: 'su', 41079 140: 'gl', 41080 141: 'af', 41081 142: 'br', 41082 143: 'iu', 41083 144: 'gd', 41084 145: 'gv', 41085 146: 'ga', 41086 147: 'to', 41087 148: 'el-polyton', 41088 149: 'kl', 41089 150: 'az', 41090 151: 'nn' 41091 }; // MacOS language ID â MacOS script ID 41092 // 41093 // Note that the script ID is not sufficient to determine what encoding 41094 // to use in TrueType files. For some languages, MacOS used a modification 41095 // of a mainstream script. For example, an Icelandic name would be stored 41096 // with smRoman in the TrueType naming table, but the actual encoding 41097 // is a special Icelandic version of the normal Macintosh Roman encoding. 41098 // As another example, Inuktitut uses an 8-bit encoding for Canadian Aboriginal 41099 // Syllables but MacOS had run out of available script codes, so this was 41100 // done as a (pretty radical) "modification" of Ethiopic. 41101 // 41102 // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt 41103 var macLanguageToScript = { 41104 0: 0, 41105 // langEnglish â smRoman 41106 1: 0, 41107 // langFrench â smRoman 41108 2: 0, 41109 // langGerman â smRoman 41110 3: 0,
41111 // langItalian â smRoman 41112 4: 0, 41113 // langDutch â smRoman 41114 5: 0, 41115 // langSwedish â smRoman 41116 6: 0, 41117 // langSpanish â smRoman 41118 7: 0, 41119 // langDanish â smRoman 41120 8: 0, 41121 // langPortuguese â smRoman 41122 9: 0, 41123 // langNorwegian â smRoman 41124 10: 5, 41125 // langHebrew â smHebrew 41126 11: 1, 41127 // langJapanese â smJapanese 41128 12: 4, 41129 // langArabic â smArabic 41130 13: 0, 41131 // langFinnish â smRoman 41132 14: 6, 41133 // langGreek â smGreek 41134 15: 0, 41135 // langIcelandic â smRoman (modified) 41136 16: 0, 41137 // langMaltese â smRoman 41138 17: 0, 41139 // langTurkish â smRoman (modified) 41140 18: 0, 41141 // langCroatian â smRoman (modified) 41142 19: 2, 41143 // langTradChinese â smTradChinese 41144 20: 4, 41145 // langUrdu â smArabic 41146 21: 9, 41147 // langHindi â smDevanagari 41148 22: 21, 41149 // langThai â smThai 41150 23: 3, 41151 // langKorean â smKorean 41152 24: 29, 41153 // langLithuanian â smCentralEuroRoman 41154 25: 29, 41155 // langPolish â smCentralEuroRoman 41156 26: 29, 41157 // langHungarian â smCentralEuroRoman 41158 27: 29, 41159 // langEstonian â smCentralEuroRoman 41160 28: 29, 41161 // langLatvian â smCentralEuroRoman 41162 29: 0, 41163 // langSami â smRoman 41164 30: 0, 41165 // langFaroese â smRoman (modified) 41166 31: 4, 41167 // langFarsi â smArabic (modified) 41168 32: 7, 41169 // langRussian â smCyrillic 41170 33: 25, 41171 // langSimpChinese â smSimpChinese 41172 34: 0, 41173 // langFlemish â smRoman 41174 35: 0, 41175 // langIrishGaelic â smRoman (modified) 41176 36: 0, 41177 // langAlbanian â smRoman 41178 37: 0, 41179 // langRomanian â smRoman (modified) 41180 38: 29, 41181 // langCzech â smCentralEuroRoman 41182 39: 29, 41183 // langSlovak â smCentralEuroRoman 41184 40: 0, 41185 // langSlovenian â smRoman (modified) 41186 41: 5, 41187 // langYiddish â smHebrew 41188 42: 7, 41189 // langSerbian â smCyrillic 41190 43: 7, 41191 // langMacedonian â smCyrillic 41192 44: 7, 41193 // langBulgarian â smCyrillic 41194 45: 7, 41195 // langUkrainian â smCyrillic (modified) 41196 46: 7, 41197 // langByelorussian â smCyrillic 41198 47: 7, 41199 // langUzbek â smCyrillic 41200 48: 7, 41201 // langKazakh â smCyrillic 41202 49: 7, 41203 // langAzerbaijani â smCyrillic 41204 50: 4, 41205 // langAzerbaijanAr â smArabic 41206 51: 24, 41207 // langArmenian â smArmenian 41208 52: 23, 41209 // langGeorgian â smGeorgian 41210 53: 7, 41211 // langMoldavian â smCyrillic 41212 54: 7, 41213 // langKirghiz â smCyrillic 41214 55: 7, 41215 // langTajiki â smCyrillic 41216 56: 7, 41217 // langTurkmen â smCyrillic 41218 57: 27, 41219 // langMongolian â smMongolian 41220 58: 7, 41221 // langMongolianCyr â smCyrillic 41222 59: 4, 41223 // langPashto â smArabic 41224 60: 4, 41225 // langKurdish â smArabic 41226 61: 4, 41227 // langKashmiri â smArabic 41228 62: 4, 41229 // langSindhi â smArabic 41230 63: 26, 41231 // langTibetan â smTibetan 41232 64: 9, 41233 // langNepali â smDevanagari 41234 65: 9, 41235 // langSanskrit â smDevanagari 41236 66: 9, 41237 // langMarathi â smDevanagari 41238 67: 13, 41239 // langBengali â smBengali 41240 68: 13, 41241 // langAssamese â smBengali 41242 69: 11, 41243 // langGujarati â smGujarati 41244 70: 10, 41245 // langPunjabi â smGurmukhi 41246 71: 12, 41247 // langOriya â smOriya 41248 72: 17, 41249 // langMalayalam â smMalayalam 41250 73: 16, 41251 // langKannada â smKannada 41252 74: 14, 41253 // langTamil â smTamil 41254 75: 15, 41255 // langTelugu â smTelugu 41256 76: 18,
41257 // langSinhalese â smSinhalese 41258 77: 19, 41259 // langBurmese â smBurmese 41260 78: 20, 41261 // langKhmer â smKhmer 41262 79: 22, 41263 // langLao â smLao 41264 80: 30, 41265 // langVietnamese â smVietnamese 41266 81: 0, 41267 // langIndonesian â smRoman 41268 82: 0, 41269 // langTagalog â smRoman 41270 83: 0, 41271 // langMalayRoman â smRoman 41272 84: 4, 41273 // langMalayArabic â smArabic 41274 85: 28, 41275 // langAmharic â smEthiopic 41276 86: 28, 41277 // langTigrinya â smEthiopic 41278 87: 28, 41279 // langOromo â smEthiopic 41280 88: 0, 41281 // langSomali â smRoman 41282 89: 0, 41283 // langSwahili â smRoman 41284 90: 0, 41285 // langKinyarwanda â smRoman 41286 91: 0, 41287 // langRundi â smRoman 41288 92: 0, 41289 // langNyanja â smRoman 41290 93: 0, 41291 // langMalagasy â smRoman 41292 94: 0, 41293 // langEsperanto â smRoman 41294 128: 0, 41295 // langWelsh â smRoman (modified) 41296 129: 0, 41297 // langBasque â smRoman 41298 130: 0, 41299 // langCatalan â smRoman 41300 131: 0, 41301 // langLatin â smRoman 41302 132: 0, 41303 // langQuechua â smRoman 41304 133: 0, 41305 // langGuarani â smRoman 41306 134: 0, 41307 // langAymara â smRoman 41308 135: 7, 41309 // langTatar â smCyrillic 41310 136: 4, 41311 // langUighur â smArabic 41312 137: 26, 41313 // langDzongkha â smTibetan 41314 138: 0, 41315 // langJavaneseRom â smRoman 41316 139: 0, 41317 // langSundaneseRom â smRoman 41318 140: 0, 41319 // langGalician â smRoman 41320 141: 0, 41321 // langAfrikaans â smRoman 41322 142: 0, 41323 // langBreton â smRoman (modified) 41324 143: 28, 41325 // langInuktitut â smEthiopic (modified) 41326 144: 0, 41327 // langScottishGaelic â smRoman (modified) 41328 145: 0, 41329 // langManxGaelic â smRoman (modified) 41330 146: 0, 41331 // langIrishGaelicScript â smRoman (modified) 41332 147: 0, 41333 // langTongan â smRoman 41334 148: 6, 41335 // langGreekAncient â smRoman 41336 149: 0, 41337 // langGreenlandic â smRoman 41338 150: 0, 41339 // langAzerbaijanRoman â smRoman 41340 151: 0 // langNynorsk â smRoman 41341 }; // While Microsoft indicates a region/country for all its language 41342 // IDs, we omit the region code if it's equal to the "most likely 41343 // region subtag" according to Unicode CLDR. For scripts, we omit 41344 // the subtag if it is equal to the Suppress-Script entry in the 41345 // IANA language subtag registry for IETF BCP 47. 41346 // 41347 // For example, Microsoft states that its language code 0x041A is 41348 // Croatian in Croatia. We transform this to the BCP 47 language code 'hr' 41349 // and not 'hr-HR' because Croatia is the default country for Croatian, 41350 // according to Unicode CLDR. As another example, Microsoft states 41351 // that 0x101A is Croatian (Latin) in Bosnia-Herzegovina. We transform 41352 // this to 'hr-BA' and not 'hr-Latn-BA' because Latin is the default script 41353 // for the Croatian language, according to IANA. 41354 // 41355 // http://www.unicode.org/cldr/charts/latest/supplemental/likely_subtags.html 41356 // http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry 41357 var windowsLanguages = { 41358 1078: 'af', 41359 1052: 'sq', 41360 1156: 'gsw', 41361 1118: 'am', 41362 5121: 'ar-DZ', 41363 15361: 'ar-BH', 41364 3073: 'ar', 41365 2049: 'ar-IQ', 41366 11265: 'ar-JO', 41367 13313: 'ar-KW', 41368 12289: 'ar-LB', 41369 4097: 'ar-LY', 41370 6145: 'ary', 41371 8193: 'ar-OM', 41372 16385: 'ar-QA', 41373 1025: 'ar-SA', 41374 10241: 'ar-SY', 41375 7169: 'aeb', 41376 14337: 'ar-AE', 41377 9217: 'ar-YE', 41378 1067: 'hy', 41379 1101: 'as', 41380 2092: 'az-Cyrl', 41381 1068: 'az', 41382 1133: 'ba', 41383 1069: 'eu', 41384 1059: 'be', 41385 2117: 'bn', 41386 1093: 'bn-IN', 41387 8218: 'bs-Cyrl', 41388 5146: 'bs', 41389 1150: 'br', 41390 1026: 'bg', 41391 1027: 'ca', 41392 3076: 'zh-HK', 41393 5124: 'zh-MO', 41394 2052: 'zh', 41395 4100: 'zh-SG', 41396 1028: 'zh-TW', 41397 1155: 'co', 41398 1050: 'hr', 41399 4122: 'hr-BA', 41400 1029: 'cs', 41401 1030: 'da', 41402 1164: 'prs', 41403 1125: 'dv', 41404 2067: 'nl-BE', 41405 1043: 'nl', 41406 3081: 'en-AU', 41407 10249: 'en-BZ', 41408 4105: 'en-CA', 41409 9225: 'en-029', 41410 16393: 'en-IN', 41411 6153: 'en-IE', 41412 8201: 'en-JM', 41413 17417: 'en-MY', 41414 5129: 'en-NZ', 41415 13321: 'en-PH', 41416 18441: 'en-SG', 41417 7177: 'en-ZA', 41418 11273: 'en-TT', 41419 2057: 'en-GB', 41420 1033: 'en', 41421 12297: 'en-ZW', 41422 1061: 'et', 41423 1080: 'fo', 41424 1124: 'fil', 41425 1035: 'fi', 41426 2060: 'fr-BE', 41427 3084: 'fr-CA', 41428 1036: 'fr', 41429 5132: 'fr-LU', 41430 6156: 'fr-MC', 41431 4108: 'fr-CH', 41432 1122: 'fy', 41433 1110: 'gl', 41434 1079: 'ka', 41435 3079: 'de-AT', 41436 1031: 'de', 41437 5127: 'de-LI', 41438 4103: 'de-LU', 41439 2055: 'de-CH', 41440 1032: 'el', 41441 1135: 'kl', 41442 1095: 'gu', 41443 1128: 'ha', 41444 1037: 'he', 41445 1081: 'hi', 41446 1038: 'hu', 41447 1039: 'is', 41448 1136: 'ig', 41449 1057: 'id', 41450 1117: 'iu', 41451 2141: 'iu-Latn', 41452 2108: 'ga', 41453 1076: 'xh', 41454 1077: 'zu', 41455 1040: 'it', 41456 2064: 'it-CH', 41457 1041: 'ja', 41458 1099: 'kn', 41459 1087: 'kk', 41460 1107: 'km', 41461 1158: 'quc', 41462 1159: 'rw', 41463 1089: 'sw', 41464 1111: 'kok', 41465 1042: 'ko', 41466 1088: 'ky', 41467 1108: 'lo', 41468 1062: 'lv', 41469 1063: 'lt', 41470 2094: 'dsb', 41471 1134: 'lb', 41472 1071: 'mk', 41473 2110: 'ms-BN', 41474 1086: 'ms', 41475 1100: 'ml', 41476 1082: 'mt', 41477 1153: 'mi', 41478 1146: 'arn', 41479 1102: 'mr', 41480 1148: 'moh', 41481 1104: 'mn', 41482 2128: 'mn-CN', 41483 1121: 'ne', 41484 1044: 'nb',
41485 2068: 'nn', 41486 1154: 'oc', 41487 1096: 'or', 41488 1123: 'ps', 41489 1045: 'pl', 41490 1046: 'pt', 41491 2070: 'pt-PT', 41492 1094: 'pa', 41493 1131: 'qu-BO', 41494 2155: 'qu-EC', 41495 3179: 'qu', 41496 1048: 'ro', 41497 1047: 'rm', 41498 1049: 'ru', 41499 9275: 'smn', 41500 4155: 'smj-NO', 41501 5179: 'smj', 41502 3131: 'se-FI', 41503 1083: 'se', 41504 2107: 'se-SE', 41505 8251: 'sms', 41506 6203: 'sma-NO', 41507 7227: 'sms', 41508 1103: 'sa', 41509 7194: 'sr-Cyrl-BA', 41510 3098: 'sr', 41511 6170: 'sr-Latn-BA', 41512 2074: 'sr-Latn', 41513 1132: 'nso', 41514 1074: 'tn', 41515 1115: 'si', 41516 1051: 'sk', 41517 1060: 'sl', 41518 11274: 'es-AR', 41519 16394: 'es-BO', 41520 13322: 'es-CL', 41521 9226: 'es-CO', 41522 5130: 'es-CR', 41523 7178: 'es-DO', 41524 12298: 'es-EC', 41525 17418: 'es-SV', 41526 4106: 'es-GT', 41527 18442: 'es-HN', 41528 2058: 'es-MX', 41529 19466: 'es-NI', 41530 6154: 'es-PA', 41531 15370: 'es-PY', 41532 10250: 'es-PE', 41533 20490: 'es-PR', 41534 // Microsoft has defined two different language codes for 41535 // âSpanish with modern sortingâ and âSpanish with traditional 41536 // sortingâ. This makes sense for collation APIs, and it would be 41537 // possible to express this in BCP 47 language tags via Unicode 41538 // extensions (eg., es-u-co-trad is Spanish with traditional 41539 // sorting). However, for storing names in fonts, the distinction 41540 // does not make sense, so we give âesâ in both cases. 41541 3082: 'es', 41542 1034: 'es', 41543 21514: 'es-US', 41544 14346: 'es-UY', 41545 8202: 'es-VE', 41546 2077: 'sv-FI', 41547 1053: 'sv', 41548 1114: 'syr', 41549 1064: 'tg', 41550 2143: 'tzm', 41551 1097: 'ta', 41552 1092: 'tt', 41553 1098: 'te', 41554 1054: 'th', 41555 1105: 'bo', 41556 1055: 'tr', 41557 1090: 'tk', 41558 1152: 'ug', 41559 1058: 'uk', 41560 1070: 'hsb', 41561 1056: 'ur', 41562 2115: 'uz-Cyrl', 41563 1091: 'uz', 41564 1066: 'vi', 41565 1106: 'cy', 41566 1160: 'wo', 41567 1157: 'sah', 41568 1144: 'ii', 41569 1130: 'yo' 41570 }; // Returns a IETF BCP 47 language code, for example 'zh-Hant' 41571 // for 'Chinese in the traditional script'. 41572 function getLanguageCode(platformID, languageID, ltag) { 41573 switch (platformID) { 41574 case 0: 41575 // Unicode 41576 if (languageID === 65535) { 41577 return 'und'; 41578 } else if (ltag) { 41579 return ltag[languageID]; 41580 } 41581 break; 41582 case 1: 41583 // Macintosh 41584 return macLanguages[languageID]; 41585 case 3:
41586 // Windows 41587 return windowsLanguages[languageID]; 41588 } 41589 return undefined; 41590 } 41591 var utf16 = 'utf-16'; // MacOS script ID â encoding. This table stores the default case, 41592 // which can be overridden by macLanguageEncodings. 41593 var macScriptEncodings = { 41594 0: 'macintosh', 41595 // smRoman 41596 1: 'x-mac-japanese', 41597 // smJapanese 41598 2: 'x-mac-chinesetrad', 41599 // smTradChinese 41600 3: 'x-mac-korean', 41601 // smKorean 41602 6: 'x-mac-greek', 41603 // smGreek 41604 7: 'x-mac-cyrillic', 41605 // smCyrillic 41606 9: 'x-mac-devanagai', 41607 // smDevanagari 41608 10: 'x-mac-gurmukhi', 41609 // smGurmukhi 41610 11: 'x-mac-gujarati', 41611 // smGujarati 41612 12: 'x-mac-oriya', 41613 // smOriya 41614 13: 'x-mac-bengali', 41615 // smBengali 41616 14: 'x-mac-tamil', 41617 // smTamil 41618 15: 'x-mac-telugu', 41619 // smTelugu 41620 16: 'x-mac-kannada', 41621 // smKannada 41622 17: 'x-mac-malayalam', 41623 // smMalayalam 41624 18: 'x-mac-sinhalese', 41625 // smSinhalese 41626 19: 'x-mac-burmese', 41627 // smBurmese 41628 20: 'x-mac-khmer', 41629 // smKhmer 41630 21: 'x-mac-thai', 41631 // smThai 41632 22: 'x-mac-lao', 41633 // smLao 41634 23: 'x-mac-georgian', 41635 // smGeorgian 41636 24: 'x-mac-armenian', 41637 // smArmenian 41638 25: 'x-mac-chinesesimp', 41639 // smSimpChinese 41640 26: 'x-mac-tibetan', 41641 // smTibetan 41642 27: 'x-mac-mongolian', 41643 // smMongolian 41644 28: 'x-mac-ethiopic', 41645 // smEthiopic 41646 29: 'x-mac-ce', 41647 // smCentralEuroRoman 41648 30: 'x-mac-vietnamese', 41649 // smVietnamese 41650 31: 'x-mac-extarabic' // smExtArabic 41651 }; // MacOS language ID â encoding. This table stores the exceptional 41652 // cases, which override macScriptEncodings. For writing MacOS naming 41653 // tables, we need to emit a MacOS script ID. Therefore, we cannot 41654 // merge macScriptEncodings into macLanguageEncodings. 41655 // 41656 // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt 41657 var macLanguageEncodings = { 41658 15: 'x-mac-icelandic', 41659 // langIcelandic 41660 17: 'x-mac-turkish', 41661 // langTurkish 41662 18: 'x-mac-croatian', 41663 // langCroatian 41664 24: 'x-mac-ce', 41665 // langLithuanian 41666 25: 'x-mac-ce', 41667 // langPolish 41668 26: 'x-mac-ce', 41669 // langHungarian 41670 27: 'x-mac-ce', 41671 // langEstonian 41672 28: 'x-mac-ce', 41673 // langLatvian 41674 30: 'x-mac-icelandic', 41675 // langFaroese 41676 37: 'x-mac-romanian', 41677 // langRomanian 41678 38: 'x-mac-ce', 41679 // langCzech 41680 39: 'x-mac-ce', 41681 // langSlovak 41682 40: 'x-mac-ce', 41683 // langSlovenian 41684 143: 'x-mac-inuit', 41685 // langInuktitut 41686 146: 'x-mac-gaelic' // langIrishGaelicScript 41687 }; 41688 function getEncoding(platformID, encodingID, languageID) { 41689 switch (platformID) { 41690 case 0: 41691 // Unicode 41692 return utf16; 41693 case 1: 41694 // Apple Macintosh 41695 return macLanguageEncodings[languageID] || macScriptEncodings[encodingID]; 41696 case 3: 41697 // Microsoft Windows 41698 if (encodingID === 1 || encodingID === 10) { 41699 return utf16; 41700 } 41701 break; 41702 } 41703 return undefined; 41704 } // Parse the naming `name` table. 41705 // FIXME: Format 1 additional fields are not supported yet. 41706 // ltag is the content of the `ltag' table, such as ['en', 'zh-Hans', 'de-CH-1904']. 41707 41708 function parseNameTable(data, start, ltag) { 41709 var name = { 41710 }; 41711 var p = new parse.Parser(data, start); 41712 var format = p.parseUShort(); 41713 var count = p.parseUShort(); 41714 var stringOffset = p.offset + p.parseUShort(); 41715 for (var i = 0; i < count; i++) { 41716 var platformID = p.parseUShort(); 41717 var encodingID = p.parseUShort(); 41718 var languageID = p.parseUShort(); 41719 var nameID = p.parseUShort(); 41720 var property = nameTableNames[nameID] || nameID; 41721 var byteLength = p.parseUShort(); 41722 var offset = p.parseUShort(); 41723 var language = getLanguageCode(platformID, languageID, ltag); 41724 var encoding = getEncoding(platformID, encodingID, languageID); 41725 if (encoding !== undefined && language !== undefined) { 41726 var text = void 0; 41727 if (encoding === utf16) { 41728 text = decode.UTF16(data, stringOffset + offset, byteLength); 41729 } else { 41730 text = decode.MACSTRING(data, stringOffset + offset, byteLength, encoding); 41731 } 41732 if (text) { 41733 var translations = name[property]; 41734 if (translations === undefined) { 41735 translations = name[property] = { 41736 }; 41737 } 41738 translations[language] = text; 41739 } 41740 } 41741 } 41742 var langTagCount = 0; 41743 if (format === 1) { 41744 // FIXME: Also handle Microsoft's 'name' table 1. 41745 langTagCount = p.parseUShort(); 41746 } 41747 return name; 41748 } // {23: 'foo'} â {'foo': 23} 41749 // ['bar', 'baz'] â {'bar': 0, 'baz': 1} 41750 41751 function reverseDict(dict) { 41752 var result = { 41753 }; 41754 for (var key in dict) { 41755 result[dict[key]] = parseInt(key); 41756 } 41757 return result; 41758 } 41759 function makeNameRecord(platformID, encodingID, languageID, nameID, length, offset) { 41760 return new table.Record('NameRecord', [ 41761 { 41762 name: 'platformID', 41763 type: 'USHORT', 41764 value: platformID 41765 }, 41766 { 41767 name: 'encodingID', 41768 type: 'USHORT', 41769 value: encodingID 41770 }, 41771 { 41772 name: 'languageID', 41773 type: 'USHORT', 41774 value: languageID 41775 }, 41776 { 41777 name: 'nameID', 41778 type: 'USHORT', 41779 value: nameID 41780 }, 41781 { 41782 name: 'length', 41783 type: 'USHORT', 41784 value: length 41785 }, 41786 { 41787 name: 'offset', 41788 type: 'USHORT', 41789 value: offset 41790 } 41791 ]); 41792 } // Finds the position of needle in haystack, or -1 if not there. 41793 // Like String.indexOf(), but for arrays. 41794 41795 function findSubArray(needle, haystack) { 41796 var needleLength = needle.length; 41797 var limit = haystack.length - needleLength + 1; 41798 loop: for (var pos = 0; pos < limit; pos++) { 41799 for (; pos < limit; pos++) { 41800 for (var k = 0; k < needleLength; k++) { 41801 if (haystack[pos + k] !== needle[k]) { 41802 continue loop; 41803 } 41804 } 41805 return pos; 41806 } 41807 } 41808 return - 1; 41809 } 41810 function addStringToPool(s, pool) { 41811 var offset = findSubArray(s, pool); 41812 if (offset < 0) { 41813 offset = pool.length; 41814 var i = 0; 41815 var len = s.length; 41816 for (; i < len; ++i) { 41817 pool.push(s[i]); 41818 } 41819 } 41820 return offset; 41821 } 41822 function makeNameTable(names, ltag) { 41823 var nameID; 41824 var nameIDs = [ 41825 ]; 41826 var namesWithNumericKeys = { 41827 }; 41828 var nameTableIds = reverseDict(nameTableNames); 41829 for (var key in names) {
41830 var id = nameTableIds[key]; 41831 if (id === undefined) { 41832 id = key; 41833 } 41834 nameID = parseInt(id); 41835 if (isNaN(nameID)) { 41836 throw new Error('Name table entry "' + key + '" does not exist, see nameTableNames for complete list.'); 41837 } 41838 namesWithNumericKeys[nameID] = names[key]; 41839 nameIDs.push(nameID); 41840 } 41841 var macLanguageIds = reverseDict(macLanguages); 41842 var windowsLanguageIds = reverseDict(windowsLanguages); 41843 var nameRecords = [ 41844 ]; 41845 var stringPool = [ 41846 ]; 41847 for (var i = 0; i < nameIDs.length; i++) { 41848 nameID = nameIDs[i]; 41849 var translations = namesWithNumericKeys[nameID]; 41850 for (var lang in translations) { 41851 var text = translations[lang]; // For MacOS, we try to emit the name in the form that was introduced 41852 // in the initial version of the TrueType spec (in the late 1980s). 41853 // However, this can fail for various reasons: the requested BCP 47 41854 // language code might not have an old-style Mac equivalent; 41855 // we might not have a codec for the needed character encoding; 41856 // or the name might contain characters that cannot be expressed 41857 // in the old-style Macintosh encoding. In case of failure, we emit 41858 // the name in a more modern fashion (Unicode encoding with BCP 47 41859 // language tags) that is recognized by MacOS 10.5, released in 2009. 41860 // If fonts were only read by operating systems, we could simply 41861 // emit all names in the modern form; this would be much easier. 41862 // However, there are many applications and libraries that read 41863 // 'name' tables directly, and these will usually only recognize 41864 // the ancient form (silently skipping the unrecognized names). 41865 var macPlatform = 1; // Macintosh 41866 var macLanguage = macLanguageIds[lang]; 41867 var macScript = macLanguageToScript[macLanguage]; 41868 var macEncoding = getEncoding(macPlatform, macScript, macLanguage); 41869 var macName = encode.MACSTRING(text, macEncoding); 41870 if (macName === undefined) { 41871 macPlatform = 0; // Unicode 41872 macLanguage = ltag.indexOf(lang); 41873 if (macLanguage < 0) { 41874 macLanguage = ltag.length; 41875 ltag.push(lang); 41876 } 41877 macScript = 4; // Unicode 2.0 and later 41878 macName = encode.UTF16(text); 41879 } 41880 var macNameOffset = addStringToPool(macName, stringPool); 41881 nameRecords.push(makeNameRecord(macPlatform, macScript, macLanguage, nameID, macName.length, macNameOffset)); 41882 var winLanguage = windowsLanguageIds[lang]; 41883 if (winLanguage !== undefined) { 41884 var winName = encode.UTF16(text); 41885 var winNameOffset = addStringToPool(winName, stringPool); 41886 nameRecords.push(makeNameRecord(3, 1, winLanguage, nameID, winName.length, winNameOffset)); 41887 } 41888 } 41889 } 41890 nameRecords.sort(function (a, b) { 41891 return a.platformID - b.platformID || a.encodingID - b.encodingID || a.languageID - b.languageID || a.nameID - b.nameID; 41892 }); 41893 var t = new table.Table('name', [ 41894 { 41895 name: 'format', 41896 type: 'USHORT', 41897 value: 0 41898 }, 41899 { 41900 name: 'count', 41901 type: 'USHORT', 41902 value: nameRecords.length 41903 }, 41904 { 41905 name: 'stringOffset', 41906 type: 'USHORT', 41907 value: 6 + nameRecords.length * 12 41908 } 41909 ]); 41910 for (var r = 0; r < nameRecords.length; r++) { 41911 t.fields.push({ 41912 name: 'record_' + r, 41913 type: 'RECORD', 41914 value: nameRecords[r] 41915 }); 41916 } 41917 t.fields.push({ 41918 name: 'strings', 41919 type: 'LITERAL', 41920 value: stringPool 41921 }); 41922 return t; 41923 } 41924 var _name = { 41925 parse: parseNameTable, 41926 make: makeNameTable 41927 }; // The `OS/2` table contains metrics required in OpenType fonts. 41928 var unicodeRanges = [ 41929 { 41930 begin: 0, 41931 end: 127 41932 }, // Basic Latin 41933 { 41934 begin: 128, 41935 end: 255 41936 }, // Latin-1 Supplement 41937 { 41938 begin: 256, 41939 end: 383 41940 }, // Latin Extended-A 41941 { 41942 begin: 384, 41943 end: 591 41944 }, // Latin Extended-B 41945 { 41946 begin: 592, 41947 end: 687 41948 }, // IPA Extensions 41949 { 41950 begin: 688, 41951 end: 767 41952 }, // Spacing Modifier Letters 41953 { 41954 begin: 768, 41955 end: 879 41956 }, // Combining Diacritical Marks 41957 { 41958 begin: 880, 41959 end: 1023 41960 }, // Greek and Coptic 41961 { 41962 begin: 11392, 41963 end: 11519 41964 }, // Coptic 41965 { 41966 begin: 1024, 41967 end: 1279 41968 }, // Cyrillic 41969 { 41970 begin: 1328, 41971 end: 1423 41972 }, // Armenian 41973 { 41974 begin: 1424, 41975 end: 1535 41976 }, // Hebrew 41977 { 41978 begin: 42240, 41979 end: 42559 41980 }, // Vai 41981 { 41982 begin: 1536, 41983 end: 1791 41984 }, // Arabic 41985 { 41986 begin: 1984, 41987 end: 2047 41988 }, // NKo 41989 { 41990 begin: 2304, 41991 end: 2431 41992 }, // Devanagari 41993 { 41994 begin: 2432, 41995 end: 2559 41996 }, // Bengali 41997 { 41998 begin: 2560, 41999 end: 2687 42000 }, // Gurmukhi 42001 { 42002 begin: 2688, 42003 end: 2815 42004 }, // Gujarati 42005 { 42006 begin: 2816, 42007 end: 2943 42008 }, // Oriya 42009 { 42010 begin: 2944, 42011 end: 3071 42012 }, // Tamil 42013 { 42014 begin: 3072, 42015 end: 3199 42016 }, // Telugu 42017 { 42018 begin: 3200, 42019 end: 3327 42020 }, // Kannada 42021 { 42022 begin: 3328, 42023 end: 3455 42024 }, // Malayalam 42025 { 42026 begin: 3584, 42027 end: 3711 42028 }, // Thai 42029 { 42030 begin: 3712, 42031 end: 3839 42032 }, // Lao 42033 { 42034 begin: 4256, 42035 end: 4351 42036 }, // Georgian 42037 { 42038 begin: 6912, 42039 end: 7039 42040 }, // Balinese 42041 { 42042 begin: 4352, 42043 end: 4607 42044 }, // Hangul Jamo 42045 { 42046 begin: 7680, 42047 end: 7935 42048 }, // Latin Extended Additional 42049 { 42050 begin: 7936, 42051 end: 8191 42052 }, // Greek Extended 42053 { 42054 begin: 8192, 42055 end: 8303 42056 }, // General Punctuation 42057 { 42058 begin: 8304, 42059 end: 8351 42060 }, // Superscripts And Subscripts 42061 { 42062 begin: 8352, 42063 end: 8399 42064 }, // Currency Symbol 42065 { 42066 begin: 8400, 42067 end: 8447 42068 }, // Combining Diacritical Marks For Symbols 42069 { 42070 begin: 8448, 42071 end: 8527 42072 }, // Letterlike Symbols 42073 { 42074 begin: 8528, 42075 end: 8591 42076 }, // Number Forms 42077 { 42078 begin: 8592, 42079 end: 8703 42080 }, // Arrows 42081 { 42082 begin: 8704, 42083 end: 8959 42084 }, // Mathematical Operators 42085 { 42086 begin: 8960, 42087 end: 9215 42088 }, // Miscellaneous Technical 42089 { 42090 begin: 9216, 42091 end: 9279 42092 }, // Control Pictures 42093 { 42094 begin: 9280, 42095 end: 9311 42096 }, // Optical Character Recognition 42097 { 42098 begin: 9312, 42099 end: 9471 42100 }, // Enclosed Alphanumerics 42101 { 42102 begin: 9472, 42103 end: 9599 42104 }, // Box Drawing 42105 { 42106 begin: 9600, 42107 end: 9631 42108 }, // Block Elements 42109 { 42110 begin: 9632, 42111 end: 9727 42112 }, // Geometric Shapes 42113 { 42114 begin: 9728, 42115 end: 9983 42116 }, // Miscellaneous Symbols 42117 { 42118 begin: 9984, 42119 end: 10175 42120 }, // Dingbats 42121 { 42122 begin: 12288, 42123 end: 12351 42124 }, // CJK Symbols And Punctuation 42125 { 42126 begin: 12352, 42127 end: 12447 42128 }, // Hiragana 42129 { 42130 begin: 12448, 42131 end: 12543 42132 }, // Katakana 42133 { 42134 begin: 12544, 42135 end: 12591 42136 }, // Bopomofo 42137 { 42138 begin: 12592,
42139 end: 12687 42140 }, // Hangul Compatibility Jamo 42141 { 42142 begin: 43072, 42143 end: 43135 42144 }, // Phags-pa 42145 { 42146 begin: 12800, 42147 end: 13055 42148 }, // Enclosed CJK Letters And Months 42149 { 42150 begin: 13056, 42151 end: 13311 42152 }, // CJK Compatibility 42153 { 42154 begin: 44032, 42155 end: 55215 42156 }, // Hangul Syllables 42157 { 42158 begin: 55296, 42159 end: 57343 42160 }, // Non-Plane 0 * 42161 { 42162 begin: 67840, 42163 end: 67871 42164 }, // Phoenicia 42165 { 42166 begin: 19968, 42167 end: 40959 42168 }, // CJK Unified Ideographs 42169 { 42170 begin: 57344, 42171 end: 63743 42172 }, // Private Use Area (plane 0) 42173 { 42174 begin: 12736, 42175 end: 12783 42176 }, // CJK Strokes 42177 { 42178 begin: 64256, 42179 end: 64335 42180 }, // Alphabetic Presentation Forms 42181 { 42182 begin: 64336, 42183 end: 65023 42184 }, // Arabic Presentation Forms-A 42185 { 42186 begin: 65056, 42187 end: 65071 42188 }, // Combining Half Marks 42189 { 42190 begin: 65040, 42191 end: 65055 42192 }, // Vertical Forms 42193 { 42194 begin: 65104, 42195 end: 65135 42196 }, // Small Form Variants 42197 { 42198 begin: 65136, 42199 end: 65279 42200 }, // Arabic Presentation Forms-B 42201 { 42202 begin: 65280, 42203 end: 65519 42204 }, // Halfwidth And Fullwidth Forms 42205 { 42206 begin: 65520, 42207 end: 65535 42208 }, // Specials 42209 { 42210 begin: 3840, 42211 end: 4095 42212 }, // Tibetan 42213 { 42214 begin: 1792, 42215 end: 1871 42216 }, // Syriac 42217 { 42218 begin: 1920, 42219 end: 1983 42220 }, // Thaana 42221 { 42222 begin: 3456, 42223 end: 3583 42224 }, // Sinhala 42225 { 42226 begin: 4096, 42227 end: 4255 42228 }, // Myanmar 42229 { 42230 begin: 4608, 42231 end: 4991 42232 }, // Ethiopic 42233 { 42234 begin: 5024, 42235 end: 5119 42236 }, // Cherokee 42237 { 42238 begin: 5120, 42239 end: 5759 42240 }, // Unified Canadian Aboriginal Syllabics 42241 { 42242 begin: 5760, 42243 end: 5791 42244 }, // Ogham 42245 { 42246 begin: 5792, 42247 end: 5887 42248 }, // Runic 42249 { 42250 begin: 6016, 42251 end: 6143 42252 }, // Khmer 42253 { 42254 begin: 6144, 42255 end: 6319 42256 }, // Mongolian 42257 { 42258 begin: 10240, 42259 end: 10495 42260 }, // Braille Patterns 42261 { 42262 begin: 40960, 42263 end: 42127 42264 }, // Yi Syllables 42265 { 42266 begin: 5888, 42267 end: 5919 42268 }, // Tagalog 42269 { 42270 begin: 66304, 42271 end: 66351 42272 }, // Old Italic 42273 { 42274 begin: 66352, 42275 end: 66383 42276 }, // Gothic 42277 { 42278 begin: 66560, 42279 end: 66639 42280 }, // Deseret 42281 { 42282 begin: 118784, 42283 end: 119039 42284 }, // Byzantine Musical Symbols 42285 { 42286 begin: 119808, 42287 end: 120831 42288 }, // Mathematical Alphanumeric Symbols 42289 { 42290 begin: 1044480, 42291 end: 1048573 42292 }, // Private Use (plane 15) 42293 { 42294 begin: 65024, 42295 end: 65039 42296 }, // Variation Selectors 42297 { 42298 begin: 917504, 42299 end: 917631 42300 }, // Tags 42301 { 42302 begin: 6400, 42303 end: 6479 42304 }, // Limbu 42305 { 42306 begin: 6480, 42307 end: 6527 42308 }, // Tai Le 42309 { 42310 begin: 6528, 42311 end: 6623 42312 }, // New Tai Lue 42313 { 42314 begin: 6656, 42315 end: 6687 42316 }, // Buginese 42317 { 42318 begin: 11264, 42319 end: 11359 42320 }, // Glagolitic 42321 { 42322 begin: 11568, 42323 end: 11647 42324 }, // Tifinagh 42325 { 42326 begin: 19904, 42327 end: 19967 42328 }, // Yijing Hexagram Symbols 42329 { 42330 begin: 43008, 42331 end: 43055 42332 }, // Syloti Nagri 42333 { 42334 begin: 65536, 42335 end: 65663 42336 }, // Linear B Syllabary 42337 { 42338 begin: 65856, 42339 end: 65935 42340 }, // Ancient Greek Numbers 42341 { 42342 begin: 66432, 42343 end: 66463 42344 }, // Ugaritic 42345 { 42346 begin: 66464, 42347 end: 66527 42348 }, // Old Persian 42349 { 42350 begin: 66640, 42351 end: 66687 42352 }, // Shavian 42353 { 42354 begin: 66688, 42355 end: 66735 42356 }, // Osmanya 42357 { 42358 begin: 67584, 42359 end: 67647 42360 }, // Cypriot Syllabary 42361 { 42362 begin: 68096, 42363 end: 68191 42364 }, // Kharoshthi 42365 { 42366 begin: 119552, 42367 end: 119647 42368 }, // Tai Xuan Jing Symbols 42369 { 42370 begin: 73728, 42371 end: 74751 42372 }, // Cuneiform 42373 { 42374 begin: 119648, 42375 end: 119679 42376 }, // Counting Rod Numerals 42377 { 42378 begin: 7040, 42379 end: 7103 42380 }, // Sundanese 42381 { 42382 begin: 7168, 42383 end: 7247 42384 }, // Lepcha 42385 { 42386 begin: 7248, 42387 end: 7295 42388 }, // Ol Chiki 42389 { 42390 begin: 43136, 42391 end: 43231 42392 }, // Saurashtra 42393 { 42394 begin: 43264, 42395 end: 43311 42396 }, // Kayah Li 42397 { 42398 begin: 43312, 42399 end: 43359 42400 }, // Rejang 42401 { 42402 begin: 43520, 42403 end: 43615 42404 }, // Cham 42405 { 42406 begin: 65936, 42407 end: 65999 42408 }, // Ancient Symbols 42409 { 42410 begin: 66000, 42411 end: 66047 42412 }, // Phaistos Disc 42413 { 42414 begin: 66208, 42415 end: 66271 42416 }, // Carian 42417 { 42418 begin: 127024, 42419 end: 127135 42420 } // Domino Tiles 42421 42422 ]; 42423 function getUnicodeRange(unicode) { 42424 for (var i = 0; i < unicodeRanges.length; i += 1) { 42425 var range = unicodeRanges[i]; 42426 if (unicode >= range.begin && unicode < range.end) { 42427 return i; 42428 } 42429 } 42430 return - 1; 42431 } // Parse the OS/2 and Windows metrics `OS/2` table 42432 42433 function parseOS2Table(data, start) { 42434 var os2 = { 42435 }; 42436 var p = new parse.Parser(data, start); 42437 os2.version = p.parseUShort(); 42438 os2.xAvgCharWidth = p.parseShort(); 42439 os2.usWeightClass = p.parseUShort(); 42440 os2.usWidthClass = p.parseUShort(); 42441 os2.fsType = p.parseUShort(); 42442 os2.ySubscriptXSize = p.parseShort(); 42443 os2.ySubscriptYSize = p.parseShort(); 42444 os2.ySubscriptXOffset = p.parseShort(); 42445 os2.ySubscriptYOffset = p.parseShort(); 42446 os2.ySuperscriptXSize = p.parseShort(); 42447 os2.ySuperscriptYSize = p.parseShort(); 42448 os2.ySuperscriptXOffset = p.parseShort(); 42449 os2.ySuperscriptYOffset = p.parseShort(); 42450 os2.yStrikeoutSize = p.parseShort(); 42451 os2.yStrikeoutPosition = p.parseShort(); 42452 os2.sFamilyClass = p.parseShort(); 42453 os2.panose = [ 42454 ]; 42455 for (var i = 0; i < 10; i++) { 42456 os2.panose[i] = p.parseByte(); 42457 } 42458 os2.ulUnicodeRange1 = p.parseULong(); 42459 os2.ulUnicodeRange2 = p.parseULong(); 42460 os2.ulUnicodeRange3 = p.parseULong(); 42461 os2.ulUnicodeRange4 = p.parseULong(); 42462 os2.achVendID = String.fromCharCode(p.parseByte(), p.parseByte(), p.parseByte(), p.parseByte()); 42463 os2.fsSelection = p.parseUShort(); 42464 os2.usFirstCharIndex = p.parseUShort(); 42465 os2.usLastCharIndex = p.parseUShort(); 42466 os2.sTypoAscender = p.parseShort(); 42467 os2.sTypoDescender = p.parseShort(); 42468 os2.sTypoLineGap = p.parseShort(); 42469 os2.usWinAscent = p.parseUShort(); 42470 os2.usWinDescent = p.parseUShort();
42471 if (os2.version >= 1) { 42472 os2.ulCodePageRange1 = p.parseULong(); 42473 os2.ulCodePageRange2 = p.parseULong(); 42474 } 42475 if (os2.version >= 2) { 42476 os2.sxHeight = p.parseShort(); 42477 os2.sCapHeight = p.parseShort(); 42478 os2.usDefaultChar = p.parseUShort(); 42479 os2.usBreakChar = p.parseUShort(); 42480 os2.usMaxContent = p.parseUShort(); 42481 } 42482 return os2; 42483 } 42484 function makeOS2Table(options) { 42485 return new table.Table('OS/2', [ 42486 { 42487 name: 'version', 42488 type: 'USHORT', 42489 value: 3 42490 }, 42491 { 42492 name: 'xAvgCharWidth', 42493 type: 'SHORT', 42494 value: 0 42495 }, 42496 { 42497 name: 'usWeightClass', 42498 type: 'USHORT', 42499 value: 0 42500 }, 42501 { 42502 name: 'usWidthClass', 42503 type: 'USHORT', 42504 value: 0 42505 }, 42506 { 42507 name: 'fsType', 42508 type: 'USHORT', 42509 value: 0 42510 }, 42511 { 42512 name: 'ySubscriptXSize', 42513 type: 'SHORT', 42514 value: 650 42515 }, 42516 { 42517 name: 'ySubscriptYSize', 42518 type: 'SHORT', 42519 value: 699 42520 }, 42521 { 42522 name: 'ySubscriptXOffset', 42523 type: 'SHORT', 42524 value: 0 42525 }, 42526 { 42527 name: 'ySubscriptYOffset', 42528 type: 'SHORT', 42529 value: 140 42530 }, 42531 { 42532 name: 'ySuperscriptXSize', 42533 type: 'SHORT', 42534 value: 650 42535 }, 42536 { 42537 name: 'ySuperscriptYSize', 42538 type: 'SHORT', 42539 value: 699 42540 }, 42541 { 42542 name: 'ySuperscriptXOffset', 42543 type: 'SHORT', 42544 value: 0 42545 }, 42546 { 42547 name: 'ySuperscriptYOffset', 42548 type: 'SHORT', 42549 value: 479 42550 }, 42551 { 42552 name: 'yStrikeoutSize', 42553 type: 'SHORT', 42554 value: 49 42555 }, 42556 { 42557 name: 'yStrikeoutPosition', 42558 type: 'SHORT', 42559 value: 258 42560 }, 42561 { 42562 name: 'sFamilyClass', 42563 type: 'SHORT', 42564 value: 0 42565 }, 42566 { 42567 name: 'bFamilyType', 42568 type: 'BYTE', 42569 value: 0 42570 }, 42571 { 42572 name: 'bSerifStyle', 42573 type: 'BYTE', 42574 value: 0 42575 }, 42576 { 42577 name: 'bWeight', 42578 type: 'BYTE', 42579 value: 0 42580 }, 42581 { 42582 name: 'bProportion', 42583 type: 'BYTE', 42584 value: 0 42585 }, 42586 { 42587 name: 'bContrast', 42588 type: 'BYTE', 42589 value: 0 42590 }, 42591 { 42592 name: 'bStrokeVariation', 42593 type: 'BYTE', 42594 value: 0 42595 }, 42596 { 42597 name: 'bArmStyle', 42598 type: 'BYTE', 42599 value: 0 42600 }, 42601 { 42602 name: 'bLetterform', 42603 type: 'BYTE', 42604 value: 0 42605 }, 42606 { 42607 name: 'bMidline', 42608 type: 'BYTE', 42609 value: 0 42610 }, 42611 { 42612 name: 'bXHeight', 42613 type: 'BYTE', 42614 value: 0 42615 }, 42616 { 42617 name: 'ulUnicodeRange1', 42618 type: 'ULONG', 42619 value: 0 42620 }, 42621 { 42622 name: 'ulUnicodeRange2', 42623 type: 'ULONG', 42624 value: 0 42625 }, 42626 { 42627 name: 'ulUnicodeRange3', 42628 type: 'ULONG', 42629 value: 0 42630 }, 42631 { 42632 name: 'ulUnicodeRange4', 42633 type: 'ULONG', 42634 value: 0 42635 }, 42636 {
vendor: 18,466 bytes, lines 42637-43079
42637 name: 'achVendID', 42638 type: 'CHARARRAY', 42639 value: 'XXXX' 42640 }, 42641 { 42642 name: 'fsSelection', 42643 type: 'USHORT', 42644 value: 0 42645 }, 42646 { 42647 name: 'usFirstCharIndex', 42648 type: 'USHORT', 42649 value: 0 42650 }, 42651 { 42652 name: 'usLastCharIndex', 42653 type: 'USHORT', 42654 value: 0 42655 }, 42656 { 42657 name: 'sTypoAscender', 42658 type: 'SHORT', 42659 value: 0 42660 }, 42661 { 42662 name: 'sTypoDescender', 42663 type: 'SHORT', 42664 value: 0 42665 }, 42666 { 42667 name: 'sTypoLineGap', 42668 type: 'SHORT', 42669 value: 0 42670 }, 42671 { 42672 name: 'usWinAscent', 42673 type: 'USHORT', 42674 value: 0 42675 }, 42676 { 42677 name: 'usWinDescent', 42678 type: 'USHORT', 42679 value: 0 42680 }, 42681 { 42682 name: 'ulCodePageRange1', 42683 type: 'ULONG', 42684 value: 0 42685 }, 42686 { 42687 name: 'ulCodePageRange2', 42688 type: 'ULONG', 42689 value: 0 42690 }, 42691 { 42692 name: 'sxHeight', 42693 type: 'SHORT', 42694 value: 0 42695 }, 42696 { 42697 name: 'sCapHeight', 42698 type: 'SHORT', 42699 value: 0 42700 }, 42701 { 42702 name: 'usDefaultChar', 42703 type: 'USHORT', 42704 value: 0 42705 }, 42706 { 42707 name: 'usBreakChar', 42708 type: 'USHORT', 42709 value: 0 42710 }, 42711 { 42712 name: 'usMaxContext', 42713 type: 'USHORT', 42714 value: 0 42715 } 42716 ], options); 42717 } 42718 var os2 = { 42719 parse: parseOS2Table, 42720 make: makeOS2Table, 42721 unicodeRanges: unicodeRanges, 42722 getUnicodeRange: getUnicodeRange 42723 }; // The `post` table stores additional PostScript information, such as glyph names. 42724 // Parse the PostScript `post` table 42725 function parsePostTable(data, start) { 42726 var post = { 42727 }; 42728 var p = new parse.Parser(data, start); 42729 post.version = p.parseVersion(); 42730 post.italicAngle = p.parseFixed(); 42731 post.underlinePosition = p.parseShort(); 42732 post.underlineThickness = p.parseShort(); 42733 post.isFixedPitch = p.parseULong(); 42734 post.minMemType42 = p.parseULong(); 42735 post.maxMemType42 = p.parseULong(); 42736 post.minMemType1 = p.parseULong(); 42737 post.maxMemType1 = p.parseULong(); 42738 switch (post.version) { 42739 case 1: 42740 post.names = standardNames.slice(); 42741 break; 42742 case 2: 42743 post.numberOfGlyphs = p.parseUShort(); 42744 post.glyphNameIndex = new Array(post.numberOfGlyphs); 42745 for (var i = 0; i < post.numberOfGlyphs; i++) { 42746 post.glyphNameIndex[i] = p.parseUShort(); 42747 } 42748 post.names = [ 42749 ]; 42750 for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) { 42751 if (post.glyphNameIndex[i$1] >= standardNames.length) { 42752 var nameLength = p.parseChar(); 42753 post.names.push(p.parseString(nameLength)); 42754 } 42755 } 42756 break; 42757 case 2.5: 42758 post.numberOfGlyphs = p.parseUShort(); 42759 post.offset = new Array(post.numberOfGlyphs); 42760 for (var i$2 = 0; i$2 < post.numberOfGlyphs; i$2++) { 42761 post.offset[i$2] = p.parseChar(); 42762 } 42763 break; 42764 } 42765 return post; 42766 } 42767 function makePostTable() { 42768 return new table.Table('post', [ 42769 { 42770 name: 'version', 42771 type: 'FIXED', 42772 value: 196608 42773 }, 42774 { 42775 name: 'italicAngle', 42776 type: 'FIXED', 42777 value: 0 42778 }, 42779 { 42780 name: 'underlinePosition', 42781 type: 'FWORD', 42782 value: 0 42783 }, 42784 { 42785 name: 'underlineThickness', 42786 type: 'FWORD', 42787 value: 0 42788 }, 42789 { 42790 name: 'isFixedPitch', 42791 type: 'ULONG', 42792 value: 0 42793 }, 42794 { 42795 name: 'minMemType42', 42796 type: 'ULONG', 42797 value: 0 42798 }, 42799 { 42800 name: 'maxMemType42', 42801 type: 'ULONG', 42802 value: 0 42803 }, 42804 { 42805 name: 'minMemType1', 42806 type: 'ULONG', 42807 value: 0 42808 }, 42809 { 42810 name: 'maxMemType1', 42811 type: 'ULONG', 42812 value: 0 42813 } 42814 ]); 42815 } 42816 var post = { 42817 parse: parsePostTable, 42818 make: makePostTable 42819 }; // The `GSUB` table contains ligatures, among other things. 42820 var subtableParsers = new Array(9); // subtableParsers[0] is unused 42821 // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#SS 42822 subtableParsers[1] = function parseLookup1() { 42823 var start = this.offset + this.relativeOffset; 42824 var substFormat = this.parseUShort(); 42825 if (substFormat === 1) { 42826 return { 42827 substFormat: 1, 42828 coverage: this.parsePointer(Parser.coverage), 42829 deltaGlyphId: this.parseUShort() 42830 }; 42831 } else if (substFormat === 2) { 42832 return { 42833 substFormat: 2, 42834 coverage: this.parsePointer(Parser.coverage), 42835 substitute: this.parseOffset16List() 42836 }; 42837 } 42838 check.assert(false, '0x' + start.toString(16) + ': lookup type 1 format must be 1 or 2.'); 42839 }; // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#MS 42840 subtableParsers[2] = function parseLookup2() { 42841 var substFormat = this.parseUShort(); 42842 check.argument(substFormat === 1, 'GSUB Multiple Substitution Subtable identifier-format must be 1'); 42843 return { 42844 substFormat: substFormat, 42845 coverage: this.parsePointer(Parser.coverage), 42846 sequences: this.parseListOfLists() 42847 }; 42848 }; // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#AS 42849 subtableParsers[3] = function parseLookup3() { 42850 var substFormat = this.parseUShort(); 42851 check.argument(substFormat === 1, 'GSUB Alternate Substitution Subtable identifier-format must be 1'); 42852 return { 42853 substFormat: substFormat, 42854 coverage: this.parsePointer(Parser.coverage), 42855 alternateSets: this.parseListOfLists() 42856 }; 42857 }; // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#LS 42858 subtableParsers[4] = function parseLookup4() { 42859 var substFormat = this.parseUShort(); 42860 check.argument(substFormat === 1, 'GSUB ligature table identifier-format must be 1'); 42861 return { 42862 substFormat: substFormat, 42863 coverage: this.parsePointer(Parser.coverage), 42864 ligatureSets: this.parseListOfLists(function () { 42865 return { 42866 ligGlyph: this.parseUShort(), 42867 components: this.parseUShortList(this.parseUShort() - 1) 42868 }; 42869 }) 42870 }; 42871 }; 42872 var lookupRecordDesc = { 42873 sequenceIndex: Parser.uShort, 42874 lookupListIndex: Parser.uShort 42875 }; // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CSF 42876 subtableParsers[5] = function parseLookup5() { 42877 var start = this.offset + this.relativeOffset; 42878 var substFormat = this.parseUShort(); 42879 if (substFormat === 1) { 42880 return { 42881 substFormat: substFormat, 42882 coverage: this.parsePointer(Parser.coverage), 42883 ruleSets: this.parseListOfLists(function () { 42884 var glyphCount = this.parseUShort(); 42885 var substCount = this.parseUShort(); 42886 return { 42887 input: this.parseUShortList(glyphCount - 1), 42888 lookupRecords: this.parseRecordList(substCount, lookupRecordDesc) 42889 }; 42890 }) 42891 }; 42892 } else if (substFormat === 2) { 42893 return { 42894 substFormat: substFormat, 42895 coverage: this.parsePointer(Parser.coverage), 42896 classDef: this.parsePointer(Parser.classDef), 42897 classSets: this.parseListOfLists(function () { 42898 var glyphCount = this.parseUShort(); 42899 var substCount = this.parseUShort(); 42900 return { 42901 classes: this.parseUShortList(glyphCount - 1), 42902 lookupRecords: this.parseRecordList(substCount, lookupRecordDesc) 42903 }; 42904 }) 42905 }; 42906 } else if (substFormat === 3) { 42907 var glyphCount = this.parseUShort(); 42908 var substCount = this.parseUShort(); 42909 return { 42910 substFormat: substFormat, 42911 coverages: this.parseList(glyphCount, Parser.pointer(Parser.coverage)), 42912 lookupRecords: this.parseRecordList(substCount, lookupRecordDesc) 42913 }; 42914 } 42915 check.assert(false, '0x' + start.toString(16) + ': lookup type 5 format must be 1, 2 or 3.'); 42916 }; // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CC 42917 subtableParsers[6] = function parseLookup6() { 42918 var start = this.offset + this.relativeOffset; 42919 var substFormat = this.parseUShort(); 42920 if (substFormat === 1) { 42921 return { 42922 substFormat: 1, 42923 coverage: this.parsePointer(Parser.coverage), 42924 chainRuleSets: this.parseListOfLists(function () { 42925 return { 42926 backtrack: this.parseUShortList(), 42927 input: this.parseUShortList(this.parseShort() - 1), 42928 lookahead: this.parseUShortList(), 42929 lookupRecords: this.parseRecordList(lookupRecordDesc) 42930 }; 42931 }) 42932 }; 42933 } else if (substFormat === 2) { 42934 return { 42935 substFormat: 2, 42936 coverage: this.parsePointer(Parser.coverage), 42937 backtrackClassDef: this.parsePointer(Parser.classDef), 42938 inputClassDef: this.parsePointer(Parser.classDef), 42939 lookaheadClassDef: this.parsePointer(Parser.classDef), 42940 chainClassSet: this.parseListOfLists(function () { 42941 return { 42942 backtrack: this.parseUShortList(), 42943 input: this.parseUShortList(this.parseShort() - 1), 42944 lookahead: this.parseUShortList(), 42945 lookupRecords: this.parseRecordList(lookupRecordDesc) 42946 }; 42947 }) 42948 }; 42949 } else if (substFormat === 3) { 42950 return { 42951 substFormat: 3, 42952 backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)), 42953 inputCoverage: this.parseList(Parser.pointer(Parser.coverage)), 42954 lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)), 42955 lookupRecords: this.parseRecordList(lookupRecordDesc) 42956 }; 42957 } 42958 check.assert(false, '0x' + start.toString(16) + ': lookup type 6 format must be 1, 2 or 3.'); 42959 }; // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#ES 42960 subtableParsers[7] = function parseLookup7() { 42961 // Extension Substitution subtable 42962 var substFormat = this.parseUShort(); 42963 check.argument(substFormat === 1, 'GSUB Extension Substitution subtable identifier-format must be 1'); 42964 var extensionLookupType = this.parseUShort(); 42965 var extensionParser = new Parser(this.data, this.offset + this.parseULong()); 42966 return { 42967 substFormat: 1, 42968 lookupType: extensionLookupType, 42969 extension: subtableParsers[extensionLookupType].call(extensionParser) 42970 }; 42971 }; // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#RCCS 42972 subtableParsers[8] = function parseLookup8() { 42973 var substFormat = this.parseUShort(); 42974 check.argument(substFormat === 1, 'GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1'); 42975 return { 42976 substFormat: substFormat, 42977 coverage: this.parsePointer(Parser.coverage), 42978 backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)), 42979 lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)), 42980 substitutes: this.parseUShortList() 42981 }; 42982 }; // https://www.microsoft.com/typography/OTSPEC/gsub.htm 42983 function parseGsubTable(data, start) { 42984 start = start || 0; 42985 var p = new Parser(data, start); 42986 var tableVersion = p.parseVersion(1); 42987 check.argument(tableVersion === 1 || tableVersion === 1.1, 'Unsupported GSUB table version.'); 42988 if (tableVersion === 1) { 42989 return { 42990 version: tableVersion, 42991 scripts: p.parseScriptList(), 42992 features: p.parseFeatureList(), 42993 lookups: p.parseLookupList(subtableParsers) 42994 }; 42995 } else { 42996 return { 42997 version: tableVersion, 42998 scripts: p.parseScriptList(), 42999 features: p.parseFeatureList(), 43000 lookups: p.parseLookupList(subtableParsers), 43001 variations: p.parseFeatureVariationsList() 43002 }; 43003 } 43004 } // GSUB Writing ////////////////////////////////////////////// 43005 43006 var subtableMakers = new Array(9); 43007 subtableMakers[1] = function makeLookup1(subtable) { 43008 if (subtable.substFormat === 1) { 43009 return new table.Table('substitutionTable', [ 43010 { 43011 name: 'substFormat', 43012 type: 'USHORT', 43013 value: 1 43014 }, 43015 { 43016 name: 'coverage', 43017 type: 'TABLE', 43018 value: new table.Coverage(subtable.coverage) 43019 }, 43020 { 43021 name: 'deltaGlyphID', 43022 type: 'USHORT', 43023 value: subtable.deltaGlyphId 43024 } 43025 ]); 43026 } else { 43027 return new table.Table('substitutionTable', [ 43028 { 43029 name: 'substFormat', 43030 type: 'USHORT', 43031 value: 2 43032 }, 43033 { 43034 name: 'coverage', 43035 type: 'TABLE', 43036 value: new table.Coverage(subtable.coverage) 43037 } 43038 ].concat(table.ushortList('substitute', subtable.substitute))); 43039 } 43040 check.fail('Lookup type 1 substFormat must be 1 or 2.'); 43041 }; 43042 subtableMakers[3] = function makeLookup3(subtable) { 43043 check.assert(subtable.substFormat === 1, 'Lookup type 3 substFormat must be 1.'); 43044 return new table.Table('substitutionTable', [ 43045 { 43046 name: 'substFormat', 43047 type: 'USHORT', 43048 value: 1 43049 }, 43050 { 43051 name: 'coverage', 43052 type: 'TABLE', 43053 value: new table.Coverage(subtable.coverage) 43054 } 43055 ].concat(table.tableList('altSet', subtable.alternateSets, function (alternateSet) { 43056 return new table.Table('alternateSetTable', table.ushortList('alternate', alternateSet)); 43057 }))); 43058 }; 43059 subtableMakers[4] = function makeLookup4(subtable) { 43060 check.assert(subtable.substFormat === 1, 'Lookup type 4 substFormat must be 1.'); 43061 return new table.Table('substitutionTable', [ 43062 { 43063 name: 'substFormat', 43064 type: 'USHORT', 43065 value: 1 43066 }, 43067 { 43068 name: 'coverage', 43069 type: 'TABLE', 43070 value: new table.Coverage(subtable.coverage) 43071 } 43072 ].concat(table.tableList('ligSet', subtable.ligatureSets, function (ligatureSet) { 43073 return new table.Table('ligatureSetTable', table.tableList('ligature', ligatureSet, function (ligature) { 43074 return new table.Table('ligatureTable', [ 43075 { 43076 name: 'ligGlyph', 43077 type: 'USHORT', 43078 value: ligature.ligGlyph 43079 }
43080 ].concat(table.ushortList('component', ligature.components, ligature.components.length + 1))); 43081 })); 43082 }))); 43083 }; 43084 function makeGsubTable(gsub) { 43085 return new table.Table('GSUB', [ 43086 { 43087 name: 'version', 43088 type: 'ULONG', 43089 value: 65536 43090 }, 43091 { 43092 name: 'scripts', 43093 type: 'TABLE', 43094 value: new table.ScriptList(gsub.scripts) 43095 }, 43096 { 43097 name: 'features', 43098 type: 'TABLE', 43099 value: new table.FeatureList(gsub.features) 43100 }, 43101 { 43102 name: 'lookups', 43103 type: 'TABLE', 43104 value: new table.LookupList(gsub.lookups, subtableMakers) 43105 } 43106 ]); 43107 } 43108 var gsub = { 43109 parse: parseGsubTable, 43110 make: makeGsubTable 43111 }; // The `GPOS` table contains kerning pairs, among other things. 43112 // Parse the metadata `meta` table. 43113 // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html 43114 function parseMetaTable(data, start) { 43115 var p = new parse.Parser(data, start); 43116 var tableVersion = p.parseULong(); 43117 check.argument(tableVersion === 1, 'Unsupported META table version.'); 43118 p.parseULong(); // flags - currently unused and set to 0 43119 p.parseULong(); // tableOffset 43120 var numDataMaps = p.parseULong(); 43121 var tags = { 43122 }; 43123 for (var i = 0; i < numDataMaps; i++) { 43124 var tag = p.parseTag(); 43125 var dataOffset = p.parseULong(); 43126 var dataLength = p.parseULong(); 43127 var text = decode.UTF8(data, start + dataOffset, dataLength); 43128 tags[tag] = text; 43129 } 43130 return tags; 43131 } 43132 function makeMetaTable(tags) { 43133 var numTags = Object.keys(tags).length; 43134 var stringPool = ''; 43135 var stringPoolOffset = 16 + numTags * 12; 43136 var result = new table.Table('meta', [ 43137 { 43138 name: 'version', 43139 type: 'ULONG', 43140 value: 1 43141 }, 43142 { 43143 name: 'flags', 43144 type: 'ULONG', 43145 value: 0 43146 }, 43147 { 43148 name: 'offset', 43149 type: 'ULONG', 43150 value: stringPoolOffset 43151 }, 43152 { 43153 name: 'numTags', 43154 type: 'ULONG', 43155 value: numTags 43156 } 43157 ]); 43158 for (var tag in tags) { 43159 var pos = stringPool.length; 43160 stringPool += tags[tag]; 43161 result.fields.push({ 43162 name: 'tag ' + tag, 43163 type: 'TAG', 43164 value: tag 43165 }); 43166 result.fields.push({ 43167 name: 'offset ' + tag, 43168 type: 'ULONG', 43169 value: stringPoolOffset + pos 43170 }); 43171 result.fields.push({ 43172 name: 'length ' + tag, 43173 type: 'ULONG', 43174 value: tags[tag].length 43175 }); 43176 } 43177 result.fields.push({ 43178 name: 'stringPool', 43179 type: 'CHARARRAY', 43180 value: stringPool 43181 }); 43182 return result; 43183 } 43184 var meta = { 43185 parse: parseMetaTable, 43186 make: makeMetaTable 43187 }; // The `sfnt` wrapper provides organization for the tables in the font. 43188 function log2(v) { 43189 return Math.log(v) / Math.log(2) | 0; 43190 } 43191 function computeCheckSum(bytes) { 43192 while (bytes.length % 4 !== 0) { 43193 bytes.push(0); 43194 } 43195 var sum = 0; 43196 for (var i = 0; i < bytes.length; i += 4) { 43197 sum += (bytes[i] << 24) + (bytes[i + 1] << 16) + (bytes[i + 2] << 8) + bytes[i + 3]; 43198 } 43199 sum %= Math.pow(2, 32); 43200 return sum; 43201 } 43202 function makeTableRecord(tag, checkSum, offset, length) { 43203 return new table.Record('Table Record', [ 43204 { 43205 name: 'tag', 43206 type: 'TAG', 43207 value: tag !== undefined ? tag : '' 43208 }, 43209 { 43210 name: 'checkSum', 43211 type: 'ULONG', 43212 value: checkSum !== undefined ? checkSum : 0 43213 }, 43214 { 43215 name: 'offset', 43216 type: 'ULONG', 43217 value: offset !== undefined ? offset : 0 43218 }, 43219 { 43220 name: 'length', 43221 type: 'ULONG', 43222 value: length !== undefined ? length : 0 43223 } 43224 ]); 43225 } 43226 function makeSfntTable(tables) { 43227 var sfnt = new table.Table('sfnt', [ 43228 { 43229 name: 'version', 43230 type: 'TAG', 43231 value: 'OTTO' 43232 }, 43233 { 43234 name: 'numTables', 43235 type: 'USHORT', 43236 value: 0 43237 }, 43238 {
43239 name: 'searchRange', 43240 type: 'USHORT', 43241 value: 0 43242 }, 43243 { 43244 name: 'entrySelector', 43245 type: 'USHORT', 43246 value: 0 43247 }, 43248 { 43249 name: 'rangeShift', 43250 type: 'USHORT', 43251 value: 0 43252 } 43253 ]); 43254 sfnt.tables = tables; 43255 sfnt.numTables = tables.length; 43256 var highestPowerOf2 = Math.pow(2, log2(sfnt.numTables)); 43257 sfnt.searchRange = 16 * highestPowerOf2; 43258 sfnt.entrySelector = log2(highestPowerOf2); 43259 sfnt.rangeShift = sfnt.numTables * 16 - sfnt.searchRange; 43260 var recordFields = [ 43261 ]; 43262 var tableFields = [ 43263 ]; 43264 var offset = sfnt.sizeOf() + makeTableRecord().sizeOf() * sfnt.numTables; 43265 while (offset % 4 !== 0) { 43266 offset += 1; 43267 tableFields.push({ 43268 name: 'padding', 43269 type: 'BYTE', 43270 value: 0 43271 }); 43272 } 43273 for (var i = 0; i < tables.length; i += 1) { 43274 var t = tables[i]; 43275 check.argument(t.tableName.length === 4, 'Table name' + t.tableName + ' is invalid.'); 43276 var tableLength = t.sizeOf(); 43277 var tableRecord = makeTableRecord(t.tableName, computeCheckSum(t.encode()), offset, tableLength); 43278 recordFields.push({ 43279 name: tableRecord.tag + ' Table Record', 43280 type: 'RECORD', 43281 value: tableRecord 43282 }); 43283 tableFields.push({ 43284 name: t.tableName + ' table', 43285 type: 'RECORD', 43286 value: t 43287 }); 43288 offset += tableLength; 43289 check.argument(!isNaN(offset), 'Something went wrong calculating the offset.'); 43290 while (offset % 4 !== 0) { 43291 offset += 1; 43292 tableFields.push({ 43293 name: 'padding', 43294 type: 'BYTE', 43295 value: 0 43296 }); 43297 } 43298 } // Table records need to be sorted alphabetically. 43299 43300 recordFields.sort(function (r1, r2) { 43301 if (r1.value.tag > r2.value.tag) { 43302 return 1; 43303 } else { 43304 return - 1; 43305 } 43306 }); 43307 sfnt.fields = sfnt.fields.concat(recordFields); 43308 sfnt.fields = sfnt.fields.concat(tableFields); 43309 return sfnt; 43310 } // Get the metrics for a character. If the string has more than one character 43311 // this function returns metrics for the first available character. 43312 // You can provide optional fallback metrics if no characters are available. 43313 43314 function metricsForChar(font, chars, notFoundMetrics) { 43315 for (var i = 0; i < chars.length; i += 1) { 43316 var glyphIndex = font.charToGlyphIndex(chars[i]); 43317 if (glyphIndex > 0) { 43318 var glyph = font.glyphs.get(glyphIndex); 43319 return glyph.getMetrics(); 43320 } 43321 } 43322 return notFoundMetrics; 43323 } 43324 function average(vs) { 43325 var sum = 0; 43326 for (var i = 0; i < vs.length; i += 1) { 43327 sum += vs[i]; 43328 } 43329 return sum / vs.length; 43330 } // Convert the font object to a SFNT data structure. 43331 // This structure contains all the necessary tables and metadata to create a binary OTF file. 43332 43333 function fontToSfntTable(font) { 43334 var xMins = [ 43335 ]; 43336 var yMins = [ 43337 ]; 43338 var xMaxs = [ 43339 ]; 43340 var yMaxs = [ 43341 ]; 43342 var advanceWidths = [ 43343 ]; 43344 var leftSideBearings = [ 43345 ]; 43346 var rightSideBearings = [ 43347 ]; 43348 var firstCharIndex; 43349 var lastCharIndex = 0; 43350 var ulUnicodeRange1 = 0; 43351 var ulUnicodeRange2 = 0; 43352 var ulUnicodeRange3 = 0; 43353 var ulUnicodeRange4 = 0; 43354 for (var i = 0; i < font.glyphs.length; i += 1) { 43355 var glyph = font.glyphs.get(i); 43356 var unicode = glyph.unicode | 0; 43357 if (isNaN(glyph.advanceWidth)) { 43358 throw new Error('Glyph ' + glyph.name + ' (' + i + '): advanceWidth is not a number.'); 43359 } 43360 if (firstCharIndex > unicode || firstCharIndex === undefined) { 43361 // ignore .notdef char 43362 if (unicode > 0) { 43363 firstCharIndex = unicode; 43364 } 43365 } 43366 if (lastCharIndex < unicode) { 43367 lastCharIndex = unicode; 43368 } 43369 var position = os2.getUnicodeRange(unicode); 43370 if (position < 32) { 43371 ulUnicodeRange1 |= 1 << position; 43372 } else if (position < 64) { 43373 ulUnicodeRange2 |= 1 << position - 32; 43374 } else if (position < 96) { 43375 ulUnicodeRange3 |= 1 << position - 64; 43376 } else if (position < 123) { 43377 ulUnicodeRange4 |= 1 << position - 96; 43378 } else { 43379 throw new Error('Unicode ranges bits > 123 are reserved for internal usage'); 43380 } // Skip non-important characters. 43381 43382 if (glyph.name === '.notdef') { 43383 continue; 43384 } 43385 var metrics = glyph.getMetrics(); 43386 xMins.push(metrics.xMin); 43387 yMins.push(metrics.yMin); 43388 xMaxs.push(metrics.xMax);
43389 yMaxs.push(metrics.yMax); 43390 leftSideBearings.push(metrics.leftSideBearing); 43391 rightSideBearings.push(metrics.rightSideBearing); 43392 advanceWidths.push(glyph.advanceWidth); 43393 } 43394 var globals = { 43395 xMin: Math.min.apply(null, xMins), 43396 yMin: Math.min.apply(null, yMins), 43397 xMax: Math.max.apply(null, xMaxs), 43398 yMax: Math.max.apply(null, yMaxs), 43399 advanceWidthMax: Math.max.apply(null, advanceWidths), 43400 advanceWidthAvg: average(advanceWidths), 43401 minLeftSideBearing: Math.min.apply(null, leftSideBearings), 43402 maxLeftSideBearing: Math.max.apply(null, leftSideBearings), 43403 minRightSideBearing: Math.min.apply(null, rightSideBearings) 43404 }; 43405 globals.ascender = font.ascender; 43406 globals.descender = font.descender; 43407 var headTable = head.make({ 43408 flags: 3, 43409 // 00000011 (baseline for font at y=0; left sidebearing point at x=0) 43410 unitsPerEm: font.unitsPerEm, 43411 xMin: globals.xMin, 43412 yMin: globals.yMin, 43413 xMax: globals.xMax, 43414 yMax: globals.yMax, 43415 lowestRecPPEM: 3, 43416 createdTimestamp: font.createdTimestamp 43417 }); 43418 var hheaTable = hhea.make({ 43419 ascender: globals.ascender, 43420 descender: globals.descender, 43421 advanceWidthMax: globals.advanceWidthMax, 43422 minLeftSideBearing: globals.minLeftSideBearing, 43423 minRightSideBearing: globals.minRightSideBearing, 43424 xMaxExtent: globals.maxLeftSideBearing + (globals.xMax - globals.xMin), 43425 numberOfHMetrics: font.glyphs.length 43426 }); 43427 var maxpTable = maxp.make(font.glyphs.length); 43428 var os2Table = os2.make({ 43429 xAvgCharWidth: Math.round(globals.advanceWidthAvg), 43430 usWeightClass: font.tables.os2.usWeightClass, 43431 usWidthClass: font.tables.os2.usWidthClass, 43432 usFirstCharIndex: firstCharIndex, 43433 usLastCharIndex: lastCharIndex, 43434 ulUnicodeRange1: ulUnicodeRange1, 43435 ulUnicodeRange2: ulUnicodeRange2, 43436 ulUnicodeRange3: ulUnicodeRange3, 43437 ulUnicodeRange4: ulUnicodeRange4, 43438 fsSelection: font.tables.os2.fsSelection, 43439 // REGULAR 43440 // See http://typophile.com/node/13081 for more info on vertical metrics. 43441 // We get metrics for typical characters (such as "x" for xHeight). 43442 // We provide some fallback characters if characters are unavailable: their 43443 // ordering was chosen experimentally. 43444 sTypoAscender: globals.ascender, 43445 sTypoDescender: globals.descender, 43446 sTypoLineGap: 0, 43447 usWinAscent: globals.yMax, 43448 usWinDescent: Math.abs(globals.yMin), 43449 ulCodePageRange1: 1, 43450 // FIXME: hard-code Latin 1 support for now 43451 sxHeight: metricsForChar(font, 'xyvw', { 43452 yMax: Math.round(globals.ascender / 2) 43453 }).yMax, 43454 sCapHeight: metricsForChar(font, 'HIKLEFJMNTZBDPRAGOQSUVWXY', globals).yMax, 43455 usDefaultChar: font.hasChar(' ') ? 32 : 0, 43456 // Use space as the default character, if available. 43457 usBreakChar: font.hasChar(' ') ? 32 : 0 // Use space as the break character, if available. 43458 }); 43459 var hmtxTable = hmtx.make(font.glyphs); 43460 var cmapTable = cmap.make(font.glyphs); 43461 var englishFamilyName = font.getEnglishName('fontFamily'); 43462 var englishStyleName = font.getEnglishName('fontSubfamily'); 43463 var englishFullName = englishFamilyName + ' ' + englishStyleName; 43464 var postScriptName = font.getEnglishName('postScriptName'); 43465 if (!postScriptName) { 43466 postScriptName = englishFamilyName.replace(/\s/g, '') + '-' + englishStyleName; 43467 } 43468 var names = { 43469 }; 43470 for (var n in font.names) { 43471 names[n] = font.names[n]; 43472 } 43473 if (!names.uniqueID) { 43474 names.uniqueID = { 43475 en: font.getEnglishName('manufacturer') + ':' + englishFullName 43476 }; 43477 } 43478 if (!names.postScriptName) { 43479 names.postScriptName = { 43480 en: postScriptName 43481 }; 43482 } 43483 if (!names.preferredFamily) { 43484 names.preferredFamily = font.names.fontFamily; 43485 } 43486 if (!names.preferredSubfamily) { 43487 names.preferredSubfamily = font.names.fontSubfam
43487ily; 43488 } 43489 var languageTags = [ 43490 ]; 43491 var nameTable = _name.make(names, languageTags); 43492 var ltagTable = languageTags.length > 0 ? ltag.make(languageTags) : undefined; 43493 var postTable = post.make(); 43494 var cffTable = cff.make(font.glyphs, { 43495 version: font.getEnglishName('version'), 43496 fullName: englishFullName, 43497 familyName: englishFamilyName, 43498 weightName: englishStyleName, 43499 postScriptName: postScriptName, 43500 unitsPerEm: font.unitsPerEm, 43501 fontBBox: [ 43502 0, 43503 globals.yMin, 43504 globals.ascender, 43505 globals.advanceWidthMax 43506 ] 43507 }); 43508 var metaTable = font.metas && Object.keys(font.metas).length > 0 ? meta.make(font.metas) : undefined; // The order does not matter because makeSfntTable() will sort them. 43509 var tables = [ 43510 headTable, 43511 hheaTable, 43512 maxpTable, 43513 os2Table, 43514 nameTable, 43515 cmapTable, 43516 postTable, 43517 cffTable, 43518 hmtxTable 43519 ]; 43520 if (ltagTable) { 43521 tables.push(ltagTable); 43522 } // Optional tables 43523 43524 if (font.tables.gsub) { 43525 tables.push(gsub.make(font.tables.gsub)); 43526 } 43527 if (metaTable) { 43528 tables.push(metaTable); 43529 } 43530 var sfntTable = makeSfntTable(tables); // Compute the font's checkSum and store it in head.checkSumAdjustment. 43531 var bytes = sfntTable.encode(); 43532 var checkSum = computeCheckSum(bytes); 43533 var tableFields = sfntTable.fields; 43534 var checkSumAdjusted = false; 43535 for (var i$1 = 0; i$1 < tableFields.length; i$1 += 1) { 43536 if (tableFields[i$1].name === 'head table') { 43537 tableFields[i$1].value.checkSumAdjustment = 2981146554 - checkSum; 43538 checkSumAdjusted = true; 43539 break; 43540 } 43541 } 43542 if (!checkSumAdjusted) { 43543 throw new Error('Could not find head table with checkSum to adjust.'); 43544 } 43545 return sfntTable; 43546 } 43547 var sfnt = { 43548 make: makeSfntTable, 43549 fontToTable: fontToSfntTable, 43550 computeCheckSum: computeCheckSum 43551 }; // The Layout object is the prototype of Substitution objects, and provides 43552 function searchTag(arr, tag) { 43553 /* jshint bitwise: false */ 43554 var imin = 0; 43555 var imax = arr.length - 1; 43556 while (imin <= imax) { 43557 var imid = imin + imax >>> 1; 43558 var val = arr[imid].tag; 43559 if (val === tag) { 43560 return imid; 43561 } else if (val < tag) { 43562 imin = imid + 1; 43563 } else { 43564 imax = imid - 1; 43565 } 43566 } // Not found: return -1-insertion point 43567 43568 return - imin - 1; 43569 } 43570 function binSearch(arr, value) { 43571 /* jshint bitwise: false */ 43572 var imin = 0; 43573 var imax = arr.length - 1; 43574 while (imin <= imax) { 43575 var imid = imin + imax >>> 1; 43576 var val = arr[imid]; 43577 if (val === value) { 43578 return imid; 43579 } else if (val < value) { 43580 imin = imid + 1; 43581 } else { 43582 imax = imid - 1; 43583 } 43584 } // Not found: return -1-insertion point 43585 43586 return - imin - 1; 43587 } // binary search in a list of ranges (coverage, class definition) 43588 43589 function searchRange(ranges, value) { 43590 // jshint bitwise: false 43591 var range; 43592 var imin = 0; 43593 var imax = ranges.length - 1; 43594 while (imin <= imax) { 43595 var imid = imin + imax >>> 1; 43596 range = ranges[imid]; 43597 var start = range.start; 43598 if (start === value) { 43599 return range; 43600 } else if (start < value) { 43601 imin = imid + 1; 43602 } else { 43603 imax = imid - 1; 43604 } 43605 } 43606 if (imin > 0) { 43607 range = ranges[imin - 1]; 43608 if (value > range.end) { 43609 return 0; 43610 } 43611 return range; 43612 } 43613 } /**
vendor: 9,022 bytes, lines 43614-43840
43614 * @exports opentype.Layout 43615 * @class 43616 */ 43617 43618 function Layout(font, tableName) { 43619 this.font = font; 43620 this.tableName = tableName; 43621 } 43622 Layout.prototype = { 43623 /** 43624 * Binary search an object by "tag" property 43625 * @instance 43626 * @function searchTag 43627 * @memberof opentype.Layout 43628 * @param {Array} arr 43629 * @param {string} tag 43630 * @return {number} 43631 */ 43632 searchTag: searchTag, 43633 /** 43634 * Binary search in a list of numbers 43635 * @instance 43636 * @function binSearch 43637 * @memberof opentype.Layout 43638 * @param {Array} arr 43639 * @param {number} value 43640 * @return {number} 43641 */ 43642 binSearch: binSearch, 43643 /** 43644 * Get or create the Layout table (GSUB, GPOS etc). 43645 * @param {boolean} create - Whether to create a new one. 43646 * @return {Object} The GSUB or GPOS table. 43647 */ 43648 getTable: function (create) { 43649 var layout = this.font.tables[this.tableName]; 43650 if (!layout && create) { 43651 layout = this.font.tables[this.tableName] = this.createDefaultTable(); 43652 } 43653 return layout; 43654 }, 43655 /** 43656 * Returns all scripts in the substitution table. 43657 * @instance 43658 * @return {Array} 43659 */ 43660 getScriptNames: function () { 43661 var layout = this.getTable(); 43662 if (!layout) { 43663 return []; 43664 } 43665 return layout.scripts.map(function (script) { 43666 return script.tag; 43667 }); 43668 }, 43669 /** 43670 * Returns the best bet for a script name. 43671 * Returns 'DFLT' if it exists. 43672 * If not, returns 'latn' if it exists. 43673 * If neither exist, returns undefined. 43674 */ 43675 getDefaultScriptName: function () { 43676 var layout = this.getTable(); 43677 if (!layout) { 43678 return; 43679 } 43680 var hasLatn = false; 43681 for (var i = 0; i < layout.scripts.length; i++) { 43682 var name = layout.scripts[i].tag; 43683 if (name === 'DFLT') { 43684 return name; 43685 } 43686 if (name === 'latn') { 43687 hasLatn = true; 43688 } 43689 } 43690 if (hasLatn) { 43691 return 'latn'; 43692 } 43693 }, 43694 /** 43695 * Returns all LangSysRecords in the given script. 43696 * @instance 43697 * @param {string} [script='DFLT'] 43698 * @param {boolean} create - forces the creation of this script table if it doesn't exist. 43699 * @return {Object} An object with tag and script properties. 43700 */ 43701 getScriptTable: function (script, create) { 43702 var layout = this.getTable(create); 43703 if (layout) { 43704 script = script || 'DFLT'; 43705 var scripts = layout.scripts; 43706 var pos = searchTag(layout.scripts, script); 43707 if (pos >= 0) { 43708 return scripts[pos].script; 43709 } else if (create) { 43710 var scr = { 43711 tag: script, 43712 script: { 43713 defaultLangSys: { 43714 reserved: 0, 43715 reqFeatureIndex: 65535, 43716 featureIndexes: [ 43717 ] 43718 }, 43719 langSysRecords: [ 43720 ] 43721 } 43722 }; 43723 scripts.splice( - 1 - pos, 0, scr); 43724 return scr.script; 43725 } 43726 } 43727 }, 43728 /** 43729 * Returns a language system table 43730 * @instance 43731 * @param {string} [script='DFLT'] 43732 * @param {string} [language='dlft'] 43733 * @param {boolean} create - forces the creation of this langSysTable if it doesn't exist. 43734 * @return {Object} 43735 */ 43736 getLangSysTable: function (script, language, create) { 43737 var scriptTable = this.getScriptTable(script, create); 43738 if (scriptTable) { 43739 if (!language || language === 'dflt' || language === 'DFLT') { 43740 return scriptTable.defaultLangSys; 43741 } 43742 var pos = searchTag(scriptTable.langSysRecords, language); 43743 if (pos >= 0) { 43744 return scriptTable.langSysRecords[pos].langSys; 43745 } else if (create) { 43746 var langSysRecord = { 43747 tag: language, 43748 langSys: { 43749 reserved: 0, 43750 reqFeatureIndex: 65535, 43751 featureIndexes: [ 43752 ] 43753 } 43754 }; 43755 scriptTable.langSysRecords.splice( - 1 - pos, 0, langSysRecord); 43756 return langSysRecord.langSys; 43757 } 43758 } 43759 }, 43760 /** 43761 * Get a specific feature table. 43762 * @instance 43763 * @param {string} [script='DFLT'] 43764 * @param {string} [language='dlft'] 43765 * @param {string} feature - One of the codes listed at https://www.microsoft.com/typography/OTSPEC/featurelist.htm 43766 * @param {boolean} create - forces the creation of the feature table if it doesn't exist. 43767 * @return {Object} 43768 */ 43769 getFeatureTable: function (script, language, feature, create) { 43770 var langSysTable = this.getLangSysTable(script, language, create); 43771 if (langSysTable) { 43772 var featureRecord; 43773 var featIndexes = langSysTable.featureIndexes; 43774 var allFeatures = this.font.tables[this.tableName].features; // The FeatureIndex array of indices is in arbitrary order, 43775 // even if allFeatures is sorted alphabetically by feature tag. 43776 for (var i = 0; i < featIndexes.length; i++) { 43777 featureRecord = allFeatures[featIndexes[i]]; 43778 if (featureRecord.tag === feature) { 43779 return featureRecord.feature; 43780 } 43781 } 43782 if (create) { 43783 var index = allFeatures.length; // Automatic ordering of features would require to shift feature indexes in the script list. 43784 check.assert(index === 0 || feature >= allFeatures[index - 1].tag, 'Features must be added in alphabetical order.'); 43785 featureRecord = { 43786 tag: feature, 43787 feature: { 43788 params: 0, 43789 lookupListIndexes: [ 43790 ] 43791 } 43792 }; 43793 allFeatures.push(featureRecord); 43794 featIndexes.push(index); 43795 return featureRecord.feature; 43796 } 43797 } 43798 }, 43799 /** 43800 * Get the lookup tables of a given type for a script/language/feature. 43801 * @instance 43802 * @param {string} [script='DFLT'] 43803 * @param {string} [language='dlft'] 43804 * @param {string} feature - 4-letter feature code 43805 * @param {number} lookupType - 1 to 9 43806 * @param {boolean} create - forces the creation of the lookup table if it doesn't exist, with no subtables. 43807 * @return {Object[]} 43808 */ 43809 getLookupTables: function (script, language, feature, lookupType, create) { 43810 var featureTable = this.getFeatureTable(script, language, feature, create); 43811 var tables = [ 43812 ]; 43813 if (featureTable) { 43814 var lookupTable; 43815 var lookupListIndexes = featureTable.lookupListIndexes; 43816 var allLookups = this.font.tables[this.tableName].lookups; // lookupListIndexes are in no particular order, so use naive search. 43817 for (var i = 0; i < lookupListIndexes.length; i++) { 43818 lookupTable = allLookups[lookupListIndexes[i]]; 43819 if (lookupTable.lookupType === lookupType) { 43820 tables.push(lookupTable); 43821 } 43822 } 43823 if (tables.length === 0 && create) { 43824 lookupTable = { 43825 lookupType: lookupType, 43826 lookupFlag: 0, 43827 subtables: [ 43828 ], 43829 markFilteringSet: undefined 43830 }; 43831 var index = allLookups.length; 43832 allLookups.push(lookupTable); 43833 lookupListIndexes.push(index); 43834 return [lookupTable]; 43835 } 43836 } 43837 return tables; 43838 }, 43839 /** 43840 * Find a glyph in a class definition table
43841 * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table 43842 * @param {object} classDefTable - an OpenType Layout class definition table 43843 * @param {number} glyphIndex - the index of the glyph to find 43844 * @returns {number} -1 if not found 43845 */ 43846 getGlyphClass: function (classDefTable, glyphIndex) { 43847 switch (classDefTable.format) { 43848 case 1: 43849 if (classDefTable.startGlyph <= glyphIndex && glyphIndex < classDefTable.startGlyph + classDefTable.classes.length) { 43850 return classDefTable.classes[glyphIndex - classDefTable.startGlyph]; 43851 } 43852 return 0; 43853 case 2: 43854 var range = searchRange(classDefTable.ranges, glyphIndex); 43855 return range ? range.classId : 0; 43856 } 43857 }, 43858 /** 43859 * Find a glyph in a coverage table 43860 * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-table 43861 * @param {object} coverageTable - an OpenType Layout coverage table 43862 * @param {number} glyphIndex - the index of the glyph to find 43863 * @returns {number} -1 if not found 43864 */ 43865 getCoverageIndex: function (coverageTable, glyphIndex) { 43866 switch (coverageTable.format) { 43867 case 1: 43868 var index = binSearch(coverageTable.glyphs, glyphIndex); 43869 return index >= 0 ? index : - 1; 43870 case 2: 43871 var range = searchRange(coverageTable.ranges, glyphIndex); 43872 return range ? range.index + glyphIndex - range.start : - 1; 43873 } 43874 }, 43875 /** 43876 * Returns the list of glyph indexes of a coverage table. 43877 * Format 1: the list is stored raw 43878 * Format 2: compact list as range records. 43879 * @instance 43880 * @param {Object} coverageTable 43881 * @return {Array} 43882 */ 43883 expandCoverage: function (coverageTable) { 43884 if (coverageTable.format === 1) { 43885 return coverageTable.glyphs; 43886 } else { 43887 var glyphs = [ 43888 ]; 43889 var ranges = coverageTable.ranges; 43890 for (var i = 0; i < ranges.length; i++) { 43891 var range = ranges[i]; 43892 var start = range.start; 43893 var end = range.end; 43894 for (var j = start; j <= end; j++) { 43895 glyphs.push(j); 43896 } 43897 } 43898 return glyphs; 43899 } 43900 } 43901 }; // The Position object provides utility methods to manipulate 43902 /** 43903 * @exports opentype.Position 43904 * @class 43905 * @extends opentype.Layout 43906 * @param {opentype.Font} 43907 * @constructor 43908 */ 43909 function Position(font) { 43910 Layout.call(this, font, 'gpos'); 43911 } 43912 Position.prototype = Layout.prototype; 43913 /** 43914 * Init some data for faster and easier access later. 43915 */ 43916 Position.prototype.init = function () { 43917 var script = this.getDefaultScriptName(); 43918 this.defaultKerningTables = this.getKerningTables(script); 43919 }; 43920 /** 43921 * Find a glyph pair in a list of lookup tables of type 2 and retrieve the xAdvance kerning value. 43922 * 43923 * @param {integer} leftIndex - left glyph index 43924 * @param {integer} rightIndex - right glyph index 43925 * @returns {integer} 43926 */ 43927 Position.prototype.getKerningValue = function (kerningLookups, leftIndex, rightIndex) { 43928 var this$1 = this; 43929 for (var i = 0; i < kerningLookups.length; i++) { 43930 var subtables = kerningLookups[i].subtables; 43931 for (var j = 0; j < subtables.length; j++) { 43932 var subtable = subtables[j]; 43933 var covIndex = this$1.getCoverageIndex(subtable.coverage, leftIndex); 43934 if (covIndex < 0) { 43935 continue; 43936 } 43937 switch (subtable.posFormat) { 43938 case 1: 43939 // Search Pair Adjustment Positioning Format 1 43940 var pairSet = subtable.pairSets[covIndex]; 43941 for (var k = 0; k < pairSet.length; k++) { 43942 var pair = pairSet[k]; 43943 if (pair.secondGlyph === rightIndex) { 43944 return pair.value1 && pair.value1.xAdvance || 0; 43945 } 43946 } 43947 break; 43948 // left glyph found, not right glyph - try next subtable 43949 case 2: 43950 // Search Pair Adjustment Positioning Format 2 43951 var class1 = this$1.getGlyphClass(subtable.classDef1, leftIndex); 43952 var class2 = this$1.getGlyphClass(subtable.classDef2, rightIndex); 43953 var pair$1 = subtable.classRecords[class1][class2]; 43954 return pair$1.value1 && pair$1.value1.xAdvance || 0; 43955 } 43956 } 43957 } 43958 return 0; 43959 }; 43960 /** 43961 * List all kerning lookup tables. 43962 * 43963 * @param {string} [script='DFLT'] - use font.position.getDefaultScriptName() for a better default value 43964 * @param {string} [language='dflt'] 43965 * @return {object[]} The list of kerning lookup tables (may be empty), or undefined if there is no GPOS table (and we should use the kern table) 43966 */ 43967 Position.prototype.getKerningTables = function (script, language) { 43968 if (this.font.tables.gpos) { 43969 return this.getLookupTables(script, language, 'kern', 2); 43970 } 43971 }; // The Substitution object provides utility methods to manipulate 43972 /** 43973 * @exports opentype.Substitution 43974 * @class
vendor: 108,820 bytes, lines 43975-46934
43975 * @extends opentype.Layout 43976 * @param {opentype.Font} 43977 * @constructor 43978 */ 43979 function Substitution(font) { 43980 Layout.call(this, font, 'gsub'); 43981 } // Check if 2 arrays of primitives are equal. 43982 43983 function arraysEqual(ar1, ar2) { 43984 var n = ar1.length; 43985 if (n !== ar2.length) { 43986 return false; 43987 } 43988 for (var i = 0; i < n; i++) { 43989 if (ar1[i] !== ar2[i]) { 43990 return false; 43991 } 43992 } 43993 return true; 43994 } // Find the first subtable of a lookup table in a particular format. 43995 43996 function getSubstFormat(lookupTable, format, defaultSubtable) { 43997 var subtables = lookupTable.subtables; 43998 for (var i = 0; i < subtables.length; i++) { 43999 var subtable = subtables[i]; 44000 if (subtable.substFormat === format) { 44001 return subtable; 44002 } 44003 } 44004 if (defaultSubtable) { 44005 subtables.push(defaultSubtable); 44006 return defaultSubtable; 44007 } 44008 return undefined; 44009 } 44010 Substitution.prototype = Layout.prototype; 44011 /** 44012 * Create a default GSUB table. 44013 * @return {Object} gsub - The GSUB table. 44014 */ 44015 Substitution.prototype.createDefaultTable = function () { 44016 // Generate a default empty GSUB table with just a DFLT script and dflt lang sys. 44017 return { 44018 version: 1, 44019 scripts: [ 44020 { 44021 tag: 'DFLT', 44022 script: { 44023 defaultLangSys: { 44024 reserved: 0, 44025 reqFeatureIndex: 65535, 44026 featureIndexes: [ 44027 ] 44028 }, 44029 langSysRecords: [ 44030 ] 44031 } 44032 } 44033 ], 44034 features: [ 44035 ], 44036 lookups: [ 44037 ] 44038 }; 44039 }; 44040 /** 44041 * List all single substitutions (lookup type 1) for a given script, language, and feature. 44042 * @param {string} [script='DFLT'] 44043 * @param {string} [language='dflt'] 44044 * @param {string} feature - 4-character feature name ('aalt', 'salt', 'ss01'...) 44045 * @return {Array} substitutions - The list of substitutions. 44046 */ 44047 Substitution.prototype.getSingle = function (feature, script, language) { 44048 var this$1 = this; 44049 var substitutions = [ 44050 ]; 44051 var lookupTables = this.getLookupTables(script, language, feature, 1); 44052 for (var idx = 0; idx < lookupTables.length; idx++) { 44053 var subtables = lookupTables[idx].subtables; 44054 for (var i = 0; i < subtables.length; i++) { 44055 var subtable = subtables[i]; 44056 var glyphs = this$1.expandCoverage(subtable.coverage); 44057 var j = void 0; 44058 if (subtable.substFormat === 1) { 44059 var delta = subtable.deltaGlyphId; 44060 for (j = 0; j < glyphs.length; j++) { 44061 var glyph = glyphs[j]; 44062 substitutions.push({ 44063 sub: glyph, 44064 by: glyph + delta 44065 }); 44066 } 44067 } else { 44068 var substitute = subtable.substitute; 44069 for (j = 0; j < glyphs.length; j++) { 44070 substitutions.push({ 44071 sub: glyphs[j], 44072 by: substitute[j] 44073 }); 44074 } 44075 } 44076 } 44077 } 44078 return substitutions; 44079 }; 44080 /** 44081 * List all alternates (lookup type 3) for a given script, language, and feature. 44082 * @param {string} [script='DFLT'] 44083 * @param {string} [language='dflt'] 44084 * @param {string} feature - 4-character feature name ('aalt', 'salt'...) 44085 * @return {Array} alternates - The list of alternates 44086 */ 44087 Substitution.prototype.getAlternates = function (feature, script, language) { 44088 var this$1 = this; 44089 var alternates = [ 44090 ]; 44091 var lookupTables = this.getLookupTables(script, language, feature, 3); 44092 for (var idx = 0; idx < lookupTables.length; idx++) { 44093 var subtables = lookupTables[idx].subtables; 44094 for (var i = 0; i < subtables.length; i++) { 44095 var subtable = subtables[i]; 44096 var glyphs = this$1.expandCoverage(subtable.coverage); 44097 var alternateSets = subtable.alternateSets; 44098 for (var j = 0; j < glyphs.length; j++) { 44099 alternates.push({ 44100 sub: glyphs[j], 44101 by: alternateSets[j] 44102 }); 44103 } 44104 } 44105 } 44106 return alternates; 44107 }; 44108 /** 44109 * List all ligatures (lookup type 4) for a given script, language, and feature. 44110 * The result is an array of ligature objects like { sub: [ids], by: id } 44111 * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) 44112 * @param {string} [script='DFLT'] 44113 * @param {string} [language='dflt'] 44114 * @return {Array} ligatures - The list of ligatures. 44115 */ 44116 Substitution.prototype.getLigatures = function (feature, script, language) { 44117 var this$1 = this; 44118 var ligatures = [ 44119 ]; 44120 var lookupTables = this.getLookupTables(script, language, feature, 4); 44121 for (var idx = 0; idx < lookupTables.length; idx++) { 44122 var subtables = lookupTables[idx].subtables; 44123 for (var i = 0; i < subtables.length; i++) { 44124 var subtable = subtables[i]; 44125 var glyphs = this$1.expandCoverage(subtable.coverage); 44126 var ligatureSets = subtable.ligatureSets; 44127 for (var j = 0; j < glyphs.length; j++) { 44128 var startGlyph = glyphs[j]; 44129 var ligSet = ligatureSets[j]; 44130 for (var k = 0; k < ligSet.length; k++) { 44131 var lig = ligSet[k]; 44132 ligatures.push({ 44133 sub: [ 44134 startGlyph 44135 ].concat(lig.components), 44136 by: lig.ligGlyph 44137 }); 44138 } 44139 } 44140 } 44141 } 44142 return ligatures; 44143 }; 44144 /** 44145 * Add or modify a single substitution (lookup type 1) 44146 * Format 2, more flexible, is always used. 44147 * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) 44148 * @param {Object} substitution - { sub: id, delta: number } for format 1 or { sub: id, by: id } for format 2. 44149 * @param {string} [script='DFLT'] 44150 * @param {string} [language='dflt'] 44151 */ 44152 Substitution.prototype.addSingle = function (feature, substitution, script, language) { 44153 var lookupTable = this.getLookupTables(script, language, feature, 1, true) [0]; 44154 var subtable = getSubstFormat(lookupTable, 2, { 44155 // lookup type 1 subtable, format 2, coverage format 1 44156 substFormat: 2, 44157 coverage: { 44158 format: 1, 44159 glyphs: [ 44160 ] 44161 }, 44162 substitute: [ 44163 ] 44164 }); 44165 check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format); 44166 var coverageGlyph = substitution.sub; 44167 var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph); 44168 if (pos < 0) { 44169 pos = - 1 - pos; 44170 subtable.coverage.glyphs.splice(pos, 0, coverageGlyph); 44171 subtable.substitute.splice(pos, 0, 0); 44172 } 44173 subtable.substitute[pos] = substitution.by; 44174 }; 44175 /** 44176 * Add or modify an alternate substitution (lookup type 1) 44177 * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) 44178 * @param {Object} substitution - { sub: id, by: [ids] } 44179 * @param {string} [script='DFLT'] 44180 * @param {string} [language='dflt'] 44181 */ 44182 Substitution.prototype.addAlternate = function (feature, substitution, script, language) { 44183 var lookupTable = this.getLookupTables(script, language, feature, 3, true) [0]; 44184 var subtable = getSubstFormat(lookupTable, 1, { 44185 // lookup type 3 subtable, format 1, coverage format 1 44186 substFormat: 1, 44187 coverage: { 44188 format: 1, 44189 glyphs: [ 44190 ] 44191 }, 44192 alternateSets: [ 44193 ] 44194 }); 44195 check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format); 44196 var coverageGlyph = substitution.sub; 44197 var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph); 44198 if (pos < 0) { 44199 pos = - 1 - pos; 44200 subtable.coverage.glyphs.splice(pos, 0, coverageGlyph); 44201 subtable.alternateSets.splice(pos, 0, 0); 44202 } 44203 subtable.alternateSets[pos] = substitution.by; 44204 }; 44205 /** 44206 * Add a ligature (lookup type 4) 44207 * Ligatures with more components must be stored ahead of those with fewer components in order to be found 44208 * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) 44209 * @param {Object} ligature - { sub: [ids], by: id } 44210 * @param {string} [script='DFLT'] 44211 * @param {string} [language='dflt'] 44212 */ 44213 Substitution.prototype.addLigature = function (feature, ligature, script, language) { 44214 var lookupTable = this.getLookupTables(script, language, feature, 4, true) [0]; 44215 var subtable = lookupTable.subtables[0]; 44216 if (!subtable) { 44217 subtable = { 44218 // lookup type 4 subtable, format 1, coverage format 1 44219 substFormat: 1, 44220 coverage: { 44221 format: 1, 44222 glyphs: [ 44223 ] 44224 }, 44225 ligatureSets: [ 44226 ] 44227 }; 44228 lookupTable.subtables[0] = subtable; 44229 } 44230 check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format); 44231 var coverageGlyph = ligature.sub[0]; 44232 var ligComponents = ligature.sub.slice(1); 44233 var ligatureTable = { 44234 ligGlyph: ligature.by, 44235 components: ligComponents 44236 }; 44237 var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph); 44238 if (pos >= 0) { 44239 // ligatureSet already exists 44240 var ligatureSet = subtable.ligatureSets[pos]; 44241 for (var i = 0; i < ligatureSet.length; i++) { 44242 // If ligature already exists, return. 44243 if (arraysEqual(ligatureSet[i].components, ligComponents)) { 44244 return; 44245 } 44246 } // ligature does not exist: add it. 44247 44248 ligatureSet.push(ligatureTable); 44249 } else { 44250 // Create a new ligatureSet and add coverage for the first glyph. 44251 pos = - 1 - pos; 44252 subtable.coverage.glyphs.splice(pos, 0, coverageGlyph); 44253 subtable.ligatureSets.splice(pos, 0, [ 44254 ligatureTable 44255 ]); 44256 } 44257 }; 44258 /** 44259 * List all feature data for a given script and language. 44260 * @param {string} feature - 4-letter feature name 44261 * @param {string} [script='DFLT'] 44262 * @param {string} [language='dflt'] 44263 * @return {Array} substitutions - The list of substitutions. 44264 */ 44265 Substitution.prototype.getFeature = function (feature, script, language) { 44266 if (/ss\d\d/.test(feature)) { 44267 // ss01 - ss20 44268 return this.getSingle(feature, script, language); 44269 } 44270 switch (feature) { 44271 case 'aalt': 44272 case 'salt': 44273 return this.getSingle(feature, script, language).concat(this.getAlternates(feature, script, language)); 44274 case 'dlig': 44275 case 'liga': 44276 case 'rlig': 44277 return this.getLigatures(feature, script, language); 44278 } 44279 return undefined; 44280 }; 44281 /** 44282 * Add a substitution to a feature for a given script and language. 44283 * @param {string} feature - 4-letter feature name 44284 * @param {Object} sub - the substitution to add (an object like { sub: id or [ids], by: id or [ids] }) 44285 * @param {string} [script='DFLT'] 44286 * @param {string} [language='dflt'] 44287 */ 44288 Substitution.prototype.add = function (feature, sub, script, language) { 44289 if (/ss\d\d/.test(feature)) { 44290 // ss01 - ss20 44291 return this.addSingle(feature, sub, script, language); 44292 } 44293 switch (feature) { 44294 case 'aalt': 44295 case 'salt': 44296 if (typeof sub.by === 'number') { 44297 return this.addSingle(feature, sub, script, language); 44298 } 44299 return this.addAlternate(feature, sub, script, language); 44300 case 'dlig': 44301 case 'liga': 44302 case 'rlig': 44303 return this.addLigature(feature, sub, script, language); 44304 } 44305 return undefined; 44306 }; 44307 function isBrowser() { 44308 return typeof window !== 'undefined'; 44309 } 44310 function nodeBufferToArrayBuffer(buffer) { 44311 var ab = new ArrayBuffer(buffer.length); 44312 var view = new Uint8Array(ab); 44313 for (var i = 0; i < buffer.length; ++i) { 44314 view[i] = buffer[i]; 44315 } 44316 return ab; 44317 } 44318 function arrayBufferToNodeBuffer(ab) { 44319 var buffer = new Buffer(ab.byteLength); 44320 var view = new Uint8Array(ab); 44321 for (var i = 0; i < buffer.length; ++i) { 44322 buffer[i] = view[i]; 44323 } 44324 return buffer; 44325 } 44326 function checkArgument(expression, message) { 44327 if (!expression) { 44328 throw message; 44329 } 44330 } // The `glyf` table describes the glyphs in TrueType outline format. 44331 // Parse the coordinate data for a glyph. 44332 44333 function parseGlyphCoordinate(p, flag, previousValue, shortVectorBitMask, sameBitMask) { 44334 var v; 44335 if ((flag & shortVectorBitMask) > 0) { 44336 // The coordinate is 1 byte long. 44337 v = p.parseByte(); // The `same` bit is re-used for short values to signify the sign of the value. 44338 if ((flag & sameBitMask) === 0) { 44339 v = - v; 44340 } 44341 v = previousValue + v; 44342 } else { 44343 // The coordinate is 2 bytes long. 44344 // If the `same` bit is set, the coordinate is the same as the previous coordinate. 44345 if ((flag & sameBitMask) > 0) { 44346 v = previousValue; 44347 } else { 44348 // Parse the coordinate as a signed 16-bit delta value. 44349 v = previousValue + p.parseShort(); 44350 } 44351 } 44352 return v; 44353 } // Parse a TrueType glyph. 44354 44355 function parseGlyph(glyph, data, start) { 44356 var p = new parse.Parser(data, start); 44357 glyph.numberOfContours = p.parseShort(); 44358 glyph._xMin = p.parseShort(); 44359 glyph._yMin = p.parseShort(); 44360 glyph._xMax = p.parseShort(); 44361 glyph._yMax = p.parseShort(); 44362 var flags; 44363 var flag; 44364 if (glyph.numberOfContours > 0) { 44365 // This glyph is not a composite. 44366 var endPointIndices = glyph.endPointIndices = [ 44367 ]; 44368 for (var i = 0; i < glyph.numberOfContours; i += 1) { 44369 endPointIndices.push(p.parseUShort()); 44370 } 44371 glyph.instructionLength = p.parseUShort(); 44372 glyph.instructions = [ 44373 ]; 44374 for (var i$1 = 0; i$1 < glyph.instructionLength; i$1 += 1) { 44375 glyph.instructions.push(p.parseByte()); 44376 } 44377 var numberOfCoordinates = endPointIndices[endPointIndices.length - 1] + 1; 44378 flags = [ 44379 ]; 44380 for (var i$2 = 0; i$2 < numberOfCoordinates; i$2 += 1) { 44381 flag = p.parseByte(); 44382 flags.push(flag); // If bit 3 is set, we repeat this flag n times, where n is the next byte. 44383 if ((flag & 8) > 0) { 44384 var repeatCount = p.parseByte(); 44385 for (var j = 0; j < repeatCount; j += 1) { 44386 flags.push(flag); 44387 i$2 += 1; 44388 } 44389 } 44390 } 44391 check.argument(flags.length === numberOfCoordinates, 'Bad flags.'); 44392 if (endPointIndices.length > 0) { 44393 var points = [ 44394 ]; 44395 var point; // X/Y coordinates are relative to the previous point, except for the first point which is relative to 0,0. 44396 if (numberOfCoordinates > 0) { 44397 for (var i$3 = 0; i$3 < numberOfCoordinates; i$3 += 1) { 44398 flag = flags[i$3]; 44399 point = { 44400 }; 44401 point.onCurve = !!(flag & 1); 44402 point.lastPointOfContour = endPointIndices.indexOf(i$3) >= 0; 44403 points.push(point); 44404 } 44405 var px = 0; 44406 for (var i$4 = 0; i$4 < numberOfCoordinates; i$4 += 1) { 44407 flag = flags[i$4]; 44408 point = points[i$4]; 44409 point.x = parseGlyphCoordinate(p, flag, px, 2, 16); 44410 px = point.x; 44411 } 44412 var py = 0; 44413 for (var i$5 = 0; i$5 < numberOfCoordinates; i$5 += 1) { 44414 flag = flags[i$5]; 44415 point = points[i$5]; 44416 point.y = parseGlyphCoordinate(p, flag, py, 4, 32); 44417 py = point.y; 44418 } 44419 } 44420 glyph.points = points; 44421 } else { 44422 glyph.points = [ 44423 ]; 44424 } 44425 } else if (glyph.numberOfContours === 0) { 44426 glyph.points = [ 44427 ]; 44428 } else { 44429 glyph.isComposite = true; 44430 glyph.points = [ 44431 ]; 44432 glyph.components = [ 44433 ]; 44434 var moreComponents = true; 44435 while (moreComponents) { 44436 flags = p.parseUShort(); 44437 var component = { 44438 glyphIndex: p.parseUShort(), 44439 xScale: 1, 44440 scale01: 0, 44441 scale10: 0, 44442 yScale: 1, 44443 dx: 0, 44444 dy: 0 44445 }; 44446 if ((flags & 1) > 0) { 44447 // The arguments are words 44448 if ((flags & 2) > 0) { 44449 // values are offset 44450 component.dx = p.parseShort(); 44451 component.dy = p.parseShort(); 44452 } else { 44453 // values are matched points 44454 component.matchedPoints = [ 44455 p.parseUShort(), 44456 p.parseUShort() 44457 ]; 44458 } 44459 } else { 44460 // The arguments are bytes 44461 if ((flags & 2) > 0) { 44462 // values are offset 44463 component.dx = p.parseChar(); 44464 component.dy = p.parseChar(); 44465 } else { 44466 // values are matched points 44467 component.matchedPoints = [ 44468 p.parseByte(), 44469 p.parseByte() 44470 ]; 44471 } 44472 } 44473 if ((flags & 8) > 0) { 44474 // We have a scale 44475 component.xScale = component.yScale = p.parseF2Dot14(); 44476 } else if ((flags & 64) > 0) { 44477 // We have an X / Y scale 44478 component.xScale = p.parseF2Dot14(); 44479 component.yScale = p.parseF2Dot14(); 44480 } else if ((flags & 128) > 0) { 44481 // We have a 2x2 transformation 44482 component.xScale = p.parseF2Dot14(); 44483 component.scale01 = p.parseF2Dot14(); 44484 component.scale10 = p.parseF2Dot14(); 44485 component.yScale = p.parseF2Dot14(); 44486 } 44487 glyph.components.push(component); 44488 moreComponents = !!(flags & 32); 44489 } 44490 if (flags & 256) { 44491 // We have instructions 44492 glyph.instructionLength = p.parseUShort(); 44493 glyph.instructions = [ 44494 ]; 44495 for (var i$6 = 0; i$6 < glyph.instructionLength; i$6 += 1) { 44496 glyph.instructions.push(p.parseByte()); 44497 } 44498 } 44499 } 44500 } // Transform an array of points and return a new array. 44501 44502 function transformPoints(points, transform) { 44503 var newPoints = [ 44504 ]; 44505 for (var i = 0; i < points.length; i += 1) { 44506 var pt = points[i]; 44507 var newPt = { 44508 x: transform.xScale * pt.x + transform.scale01 * pt.y + transform.dx, 44509 y: transform.scale10 * pt.x + transform.yScale * pt.y + transform.dy, 44510 onCurve: pt.onCurve, 44511 lastPointOfContour: pt.lastPointOfContour 44512 }; 44513 newPoints.push(newPt); 44514 } 44515 return newPoints; 44516 } 44517 function getContours(points) { 44518 var contours = [ 44519 ]; 44520 var currentContour = [ 44521 ]; 44522 for (var i = 0; i < points.length; i += 1) { 44523 var pt = points[i]; 44524 currentContour.push(pt); 44525 if (pt.lastPointOfContour) { 44526 contours.push(currentContour); 44527 currentContour = [ 44528 ]; 44529 } 44530 } 44531 check.argument(currentContour.length === 0, 'There are still points left in the current contour.'); 44532 return contours; 44533 } // Convert the TrueType glyph outline to a Path. 44534 44535 function getPath(points) { 44536 var p = new Path(); 44537 if (!points) { 44538 return p; 44539 } 44540 var contours = getContours(points); 44541 for (var contourIndex = 0; contourIndex < contours.length; ++contourIndex) { 44542 var contour = contours[contourIndex]; 44543 var prev = null; 44544 var curr = contour[contour.length - 1]; 44545 var next = contour[0]; 44546 if (curr.onCurve) { 44547 p.moveTo(curr.x, curr.y); 44548 } else { 44549 if (next.onCurve) { 44550 p.moveTo(next.x, next.y); 44551 } else { 44552 // If both first and last points are off-curve, start at their middle. 44553 var start = { 44554 x: (curr.x + next.x) * 0.5, 44555 y: (curr.y + next.y) * 0.5 44556 }; 44557 p.moveTo(start.x, start.y); 44558 } 44559 } 44560 for (var i = 0; i < contour.length; ++i) { 44561 prev = curr; 44562 curr = next; 44563 next = contour[(i + 1) % contour.length]; 44564 if (curr.onCurve) { 44565 // This is a straight line. 44566 p.lineTo(curr.x, curr.y); 44567 } else { 44568 var prev2 = prev; 44569 var next2 = next; 44570 if (!prev.onCurve) { 44571 prev2 = { 44572 x: (curr.x + prev.x) * 0.5, 44573 y: (curr.y + prev.y) * 0.5 44574 }; 44575 } 44576 if (!next.onCurve) { 44577 next2 = { 44578 x: (curr.x + next.x) * 0.5, 44579 y: (curr.y + next.y) * 0.5 44580 }; 44581 } 44582 p.quadraticCurveTo(curr.x, curr.y, next2.x, next2.y); 44583 } 44584 } 44585 p.closePath(); 44586 } 44587 return p; 44588 } 44589 function buildPath(glyphs, glyph) { 44590 if (glyph.isComposite) { 44591 for (var j = 0; j < glyph.components.length; j += 1) { 44592 var component = glyph.components[j]; 44593 var componentGlyph = glyphs.get(component.glyphIndex); // Force the ttfGlyphLoader to parse the glyph. 44594 componentGlyph.getPath(); 44595 if (componentGlyph.points) { 44596 var transformedPoints = void 0; 44597 if (component.matchedPoints === undefined) { 44598 // component positioned by offset 44599 transformedPoints = transformPoints(componentGlyph.points, component); 44600 } else { 44601 // component positioned by matched points 44602 if (component.matchedPoints[0] > glyph.points.length - 1 || component.matchedPoints[1] > componentGlyph.points.length - 1) { 44603 throw Error('Matched points out of range in ' + glyph.name); 44604 } 44605 var firstPt = glyph.points[component.matchedPoints[0]]; 44606 var secondPt = componentGlyph.points[component.matchedPoints[1]]; 44607 var transform = { 44608 xScale: component.xScale, 44609 scale01: component.scale01, 44610 scale10: component.scale10, 44611 yScale: component.yScale, 44612 dx: 0, 44613 dy: 0 44614 }; 44615 secondPt = transformPoints([secondPt], transform) [0]; 44616 transform.dx = firstPt.x - secondPt.x; 44617 transform.dy = firstPt.y - secondPt.y; 44618 transformedPoints = transformPoints(componentGlyph.points, transform); 44619 } 44620 glyph.points = glyph.points.concat(transformedPoints); 44621 } 44622 } 44623 } 44624 return getPath(glyph.points); 44625 } // Parse all the glyphs according to the offsets from the `loca` table. 44626 44627 function parseGlyfTable(data, start, loca, font) { 44628 var glyphs = new glyphset.GlyphSet(font); // The last element of the loca table is invalid. 44629 for (var i = 0; i < loca.length - 1; i += 1) { 44630 var offset = loca[i]; 44631 var nextOffset = loca[i + 1]; 44632 if (offset !== nextOffset) { 44633 glyphs.push(i, glyphset.ttfGlyphLoader(font, i, parseGlyph, data, start + offset, buildPath)); 44634 } else { 44635 glyphs.push(i, glyphset.glyphLoader(font, i)); 44636 } 44637 } 44638 return glyphs; 44639 } 44640 var glyf = { 44641 getPath: getPath, 44642 parse: parseGlyfTable 44643 }; 44644 /* A TrueType font hinting interpreter. 44645 * 44646 * (c) 2017 Axel Kittenberger 44647 * 44648 * This interpreter has been implemented according to this documentation: 44649 * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html 44650 * 44651 * According to the documentation F24DOT6 values are used for pixels. 44652 * That means calculation is 1/64 pixel accurate and uses integer operations. 44653 * However, Javascript has floating point operations by default and only 44654 * those are available. One could make a case to simulate the 1/64 accuracy 44655 * exactly by truncating after every division operation 44656 * (for example with << 0) to get pixel exactly results as other TrueType 44657 * implementations. It may make sense since some fonts are pixel optimized 44658 * by hand using DELTAP instructions. The current implementation doesn't 44659 * and rather uses full floating point precision. 44660 * 44661 * xScale, yScale and rotation is currently ignored. 44662 * 44663 * A few non-trivial instructions are missing as I didn't encounter yet 44664 * a font that used them to test a possible implementation. 44665 * 44666 * Some fonts seem to use undocumented features regarding the twilight zone. 44667 * Only some of them are implemented as they were encountered. 44668 * 44669 * The exports.DEBUG statements are removed on the minified distribution file. 44670 */ 44671 var instructionTable; 44672 var exec; 44673 var execGlyph; 44674 var execComponent; 44675 /* 44676 * Creates a hinting object. 44677 * 44678 * There ought to be exactly one 44679 * for each truetype font that is used for hinting. 44680 */ 44681 function Hinting(font) { 44682 // the font this hinting object is for 44683 this.font = font; 44684 this.getCommands = function (hPoints) { 44685 return glyf.getPath(hPoints).commands; 44686 }; // cached states 44687 this._fpgmState = this._prepState = undefined; // errorState 44688 // 0 ... all okay 44689 // 1 ... had an error in a glyf, 44690 // continue working but stop spamming 44691 // the console 44692 // 2 ... error at prep, stop hinting at this ppem 44693 // 3 ... error at fpeg, stop hinting for this font at all 44694 this._errorState = 0; 44695 } /* 44696 * Not rounding. 44697 */ 44698 44699 function roundOff(v) { 44700 return v; 44701 } /* 44702 * Rounding to grid. 44703 */ 44704 44705 function roundToGrid(v) { 44706 //Rounding in TT is supposed to "symmetrical around zero" 44707 return Math.sign(v) * Math.round(Math.abs(v)); 44708 } /* 44709 * Rounding to double grid. 44710 */ 44711 44712 function roundToDoubleGrid(v) { 44713 return Math.sign(v) * Math.round(Math.abs(v * 2)) / 2; 44714 } /* 44715 * Rounding to half grid. 44716 */ 44717 44718 function roundToHalfGrid(v) { 44719 return Math.sign(v) * (Math.round(Math.abs(v) + 0.5) - 0.5); 44720 } /* 44721 * Rounding to up to grid. 44722 */ 44723 44724 function roundUpToGrid(v) { 44725 return Math.sign(v) * Math.ceil(Math.abs(v)); 44726 } /* 44727 * Rounding to down to grid. 44728 */ 44729 44730 function roundDownToGrid(v) { 44731 return Math.sign(v) * Math.floor(Math.abs(v)); 44732 } /* 44733 * Super rounding. 44734 */ 44735 44736 var roundSuper = function (v) { 44737 var period = this.srPeriod; 44738 var phase = this.srPhase; 44739 var threshold = this.srThreshold; 44740 var sign = 1; 44741 if (v < 0) { 44742 v = - v; 44743 sign = - 1; 44744 } 44745 v += threshold - phase; 44746 v = Math.trunc(v / period) * period; 44747 v += phase; // according to http://xgridfit.sourceforge.net/round.html 44748 if (v < 0) { 44749 return phase * sign; 44750 } 44751 return v * sign; 44752 }; 44753 /* 44754 * Unit vector of x-axis. 44755 */ 44756 var xUnitVector = { 44757 x: 1, 44758 y: 0, 44759 axis: 'x', 44760 // Gets the projected distance between two points. 44761 // o1/o2 ... if true, respective original position is used. 44762 distance: function (p1, p2, o1, o2) { 44763 return (o1 ? p1.xo : p1.x) - (o2 ? p2.xo : p2.x); 44764 }, 44765 // Moves point p so the moved position has the same relative 44766 // position to the moved positions of rp1 and rp2 than the 44767 // original positions had. 44768 // 44769 // See APPENDIX on INTERPOLATE at the bottom of this file. 44770 interpolate: function (p, rp1, rp2, pv) { 44771 var do1; 44772 var do2; 44773 var doa1; 44774 var doa2; 44775 var dm1; 44776 var dm2; 44777 var dt; 44778 if (!pv || pv === this) { 44779 do1 = p.xo - rp1.xo; 44780 do2 = p.xo - rp2.xo; 44781 dm1 = rp1.x - rp1.xo; 44782 dm2 = rp2.x - rp2.xo; 44783 doa1 = Math.abs(do1); 44784 doa2 = Math.abs(do2); 44785 dt = doa1 + doa2; 44786 if (dt === 0) { 44787 p.x = p.xo + (dm1 + dm2) / 2; 44788 return; 44789 } 44790 p.x = p.xo + (dm1 * doa2 + dm2 * doa1) / dt; 44791 return; 44792 } 44793 do1 = pv.distance(p, rp1, true, true); 44794 do2 = pv.distance(p, rp2, true, true); 44795 dm1 = pv.distance(rp1, rp1, false, true); 44796 dm2 = pv.distance(rp2, rp2, false, true); 44797 doa1 = Math.abs(do1); 44798 doa2 = Math.abs(do2); 44799 dt = doa1 + doa2; 44800 if (dt === 0) { 44801 xUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true); 44802 return; 44803 } 44804 xUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true); 44805 }, 44806 // Slope of line normal to this 44807 normalSlope: Number.NEGATIVE_INFINITY, 44808 // Sets the point 'p' relative to point 'rp' 44809 // by the distance 'd'. 44810 // 44811 // See APPENDIX on SETRELATIVE at the bottom of this file. 44812 // 44813 // p ... point to set 44814 // rp ... reference point 44815 // d ... distance on projection vector 44816 // pv ... projection vector (undefined = this) 44817 // org ... if true, uses the original position of rp as reference. 44818 setRelative: function (p, rp, d, pv, org) { 44819 if (!pv || pv === this) { 44820 p.x = (org ? rp.xo : rp.x) + d; 44821 return; 44822 } 44823 var rpx = org ? rp.xo : rp.x; 44824 var rpy = org ? rp.yo : rp.y; 44825 var rpdx = rpx + d * pv.x; 44826 var rpdy = rpy + d * pv.y; 44827 p.x = rpdx + (p.y - rpdy) / pv.normalSlope; 44828 }, 44829 // Slope of vector line. 44830 slope: 0, 44831 // Touches the point p. 44832 touch: function (p) { 44833 p.xTouched = true; 44834 }, 44835 // Tests if a point p is touched. 44836 touched: function (p) { 44837 return p.xTouched; 44838 }, 44839 // Untouches the point p. 44840 untouch: function (p) { 44841 p.xTouched = false; 44842 } 44843 }; 44844 /* 44845 * Unit vector of y-axis. 44846 */ 44847 var yUnitVector = { 44848 x: 0, 44849 y: 1, 44850 axis: 'y', 44851 // Gets the projected distance between two points. 44852 // o1/o2 ... if true, respective original position is used. 44853 distance: function (p1, p2, o1, o2) { 44854 return (o1 ? p1.yo : p1.y) - (o2 ? p2.yo : p2.y); 44855 }, 44856 // Moves point p so the moved position has the same relative 44857 // position to the moved positions of rp1 and rp2 than the 44858 // original positions had. 44859 // 44860 // See APPENDIX on INTERPOLATE at the bottom of this file. 44861 interpolate: function (p, rp1, rp2, pv) { 44862 var do1; 44863 var do2; 44864 var doa1; 44865 var doa2; 44866 var dm1; 44867 var dm2; 44868 var dt; 44869 if (!pv || pv === this) { 44870 do1 = p.yo - rp1.yo; 44871 do2 = p.yo - rp2.yo; 44872 dm1 = rp1.y - rp1.yo; 44873 dm2 = rp2.y - rp2.yo; 44874 doa1 = Math.abs(do1); 44875 doa2 = Math.abs(do2); 44876 dt = doa1 + doa2; 44877 if (dt === 0) { 44878 p.y = p.yo + (dm1 + dm2) / 2; 44879 return; 44880 } 44881 p.y = p.yo + (dm1 * doa2 + dm2 * doa1) / dt; 44882 return; 44883 } 44884 do1 = pv.distance(p, rp1, true, true); 44885 do2 = pv.distance(p, rp2, true, true); 44886 dm1 = pv.distance(rp1, rp1, false, true); 44887 dm2 = pv.distance(rp2, rp2, false, true); 44888 doa1 = Math.abs(do1); 44889 doa2 = Math.abs(do2); 44890 dt = doa1 + doa2; 44891 if (dt === 0) { 44892 yUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true); 44893 return; 44894 } 44895 yUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true); 44896 }, 44897 // Slope of line normal to this. 44898 normalSlope: 0, 44899 // Sets the point 'p' relative to point 'rp' 44900 // by the distance 'd' 44901 // 44902 // See APPENDIX on SETRELATIVE at the bottom of this file. 44903 // 44904 // p ... point to set 44905 // rp ... reference point 44906 // d ... distance on projection vector 44907 // pv ... projection vector (undefined = this) 44908 // org ... if true, uses the original position of rp as reference. 44909 setRelative: function (p, rp, d, pv, org) { 44910 if (!pv || pv === this) { 44911 p.y = (org ? rp.yo : rp.y) + d; 44912 return; 44913 } 44914 var rpx = org ? rp.xo : rp.x; 44915 var rpy = org ? rp.yo : rp.y; 44916 var rpdx = rpx + d * pv.x; 44917 var rpdy = rpy + d * pv.y; 44918 p.y = rpdy + pv.normalSlope * (p.x - rpdx); 44919 }, 44920 // Slope of vector line. 44921 slope: Number.POSITIVE_INFINITY, 44922 // Touches the point p. 44923 touch: function (p) { 44924 p.yTouched = true; 44925 }, 44926 // Tests if a point p is touched. 44927 touched: function (p) { 44928 return p.yTouched; 44929 }, 44930 // Untouches the point p. 44931 untouch: function (p) { 44932 p.yTouched = false; 44933 } 44934 }; 44935 Object.freeze(xUnitVector); 44936 Object.freeze(yUnitVector); 44937 /* 44938 * Creates a unit vector that is not x- or y-axis. 44939 */ 44940 function UnitVector(x, y) { 44941 this.x = x; 44942 this.y = y; 44943 this.axis = undefined; 44944 this.slope = y / x; 44945 this.normalSlope = - x / y; 44946 Object.freeze(this); 44947 } /* 44948 * Gets the projected distance between two points. 44949 * o1/o2 ... if true, respective original position is used. 44950 */ 44951 44952 UnitVector.prototype.distance = function (p1, p2, o1, o2) { 44953 return this.x * xUnitVector.distance(p1, p2, o1, o2) + this.y * yUnitVector.distance(p1, p2, o1, o2); 44954 }; 44955 /* 44956 * Moves point p so the moved position has the same relative 44957 * position to the moved positions of rp1 and rp2 than the 44958 * original positions had. 44959 * 44960 * See APPENDIX on INTERPOLATE at the bottom of this file. 44961 */ 44962 UnitVector.prototype.interpolate = function (p, rp1, rp2, pv) { 44963 var dm1; 44964 var dm2; 44965 var do1; 44966 var do2; 44967 var doa1; 44968 var doa2; 44969 var dt; 44970 do1 = pv.distance(p, rp1, true, true); 44971 do2 = pv.distance(p, rp2, true, true); 44972 dm1 = pv.distance(rp1, rp1, false, true); 44973 dm2 = pv.distance(rp2, rp2, false, true); 44974 doa1 = Math.abs(do1); 44975 doa2 = Math.abs(do2); 44976 dt = doa1 + doa2; 44977 if (dt === 0) { 44978 this.setRelative(p, p, (dm1 + dm2) / 2, pv, true); 44979 return; 44980 } 44981 this.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true); 44982 }; 44983 /* 44984 * Sets the point 'p' relative to point 'rp' 44985 * by the distance 'd' 44986 * 44987 * See APPENDIX on SETRELATIVE at the bottom of this file. 44988 * 44989 * p ... point to set 44990 * rp ... reference point 44991 * d ... distance on projection vector 44992 * pv ... projection vector (undefined = this) 44993 * org ... if true, uses the original position of rp as reference. 44994 */ 44995 UnitVector.prototype.setRelative = function (p, rp, d, pv, org) { 44996 pv = pv || this; 44997 var rpx = org ? rp.xo : rp.x; 44998 var rpy = org ? rp.yo : rp.y; 44999 var rpdx = rpx + d * pv.x; 45000 var rpdy = rpy + d * pv.y; 45001 var pvns = pv.normalSlope; 45002 var fvs = this.slope; 45003 var px = p.x; 45004 var py = p.y; 45005 p.x = (fvs * px - pvns * rpdx + rpdy - py) / (fvs - pvns); 45006 p.y = fvs * (p.x - px) + py; 45007 }; 45008 /* 45009 * Touches the point p. 45010 */ 45011 UnitVector.prototype.touch = function (p) { 45012 p.xTouched = true; 45013 p.yTouched = true; 45014 }; 45015 /* 45016 * Returns a unit vector with x/y coordinates. 45017 */ 45018 function getUnitVector(x, y) { 45019 var d = Math.sqrt(x * x + y * y); 45020 x /= d; 45021 y /= d; 45022 if (x === 1 && y === 0) { 45023 return xUnitVector; 45024 } else if (x === 0 && y === 1) { 45025 return yUnitVector; 45026 } else { 45027 return new UnitVector(x, y); 45028 } 45029 } /* 45030 * Creates a point in the hinting engine. 45031 */ 45032 45033 function HPoint(x, y, lastPointOfContour, onCurve) { 45034 this.x = this.xo = Math.round(x * 64) / 64; // hinted x value and original x-value 45035 this.y = this.yo = Math.round(y * 64) / 64; // hinted y value and original y-value 45036 this.lastPointOfContour = lastPointOfContour; 45037 this.onCurve = onCurve; 45038 this.prevPointOnContour = undefined; 45039 this.nextPointOnContour = undefined; 45040 this.xTouched = false; 45041 this.yTouched = false; 45042 Object.preventExtensions(this); 45043 } /* 45044 * Returns the next touched point on the contour. 45045 * 45046 * v ... unit vector to test touch axis. 45047 */ 45048 45049 HPoint.prototype.nextTouched = function (v) { 45050 var p = this.nextPointOnContour; 45051 while (!v.touched(p) && p !== this) { 45052 p = p.nextPointOnContour; 45053 } 45054 return p; 45055 }; 45056 /* 45057 * Returns the previous touched point on the contour 45058 * 45059 * v ... unit vector to test touch axis. 45060 */ 45061 HPoint.prototype.prevTouched = function (v) { 45062 var p = this.prevPointOnContour; 45063 while (!v.touched(p) && p !== this) { 45064 p = p.prevPointOnContour; 45065 } 45066 return p; 45067 }; 45068 /* 45069 * The zero point. 45070 */ 45071 var HPZero = Object.freeze(new HPoint(0, 0)); 45072 /* 45073 * The default state of the interpreter. 45074 * 45075 * Note: Freezing the defaultState and then deriving from it 45076 * makes the V8 Javascript engine going awkward, 45077 * so this is avoided, albeit the defaultState shouldn't 45078 * ever change. 45079 */ 45080 var defaultState = { 45081 cvCutIn: 17 / 16, 45082 // control value cut in 45083 deltaBase: 9, 45084 deltaShift: 0.125, 45085 loop: 1, 45086 // loops some instructions 45087 minDis: 1, 45088 // minimum distance 45089 autoFlip: true 45090 }; 45091 /* 45092 * The current state of the interpreter. 45093 * 45094 * env ... 'fpgm' or 'prep' or 'glyf' 45095 * prog ... the program 45096 */ 45097 function State(env, prog) { 45098 this.env = env; 45099 this.stack = [ 45100 ]; 45101 this.prog = prog; 45102 switch (env) { 45103 case 'glyf': 45104 this.zp0 = this.zp1 = this.zp2 = 1; 45105 this.rp0 = this.rp1 = this.rp2 = 0; 45106 /* fall through */ 45107 case 'prep': 45108 this.fv = this.pv = this.dpv = xUnitVector; 45109 this.round = roundToGrid; 45110 } 45111 } /* 45112 * Executes a glyph program. 45113 * 45114 * This does the hinting for each glyph. 45115 * 45116 * Returns an array of moved points. 45117 * 45118 * glyph: the glyph to hint 45119 * ppem: the size the glyph is rendered for 45120 */ 45121 45122 Hinting.prototype.exec = function (glyph, ppem) { 45123 if (typeof ppem !== 'number') { 45124 throw new Error('Point size is not a number!'); 45125 } // Received a fatal error, don't do any hinting anymore. 45126 45127 if (this._errorState > 2) { 45128 return; 45129 } 45130 var font = this.font; 45131 var prepState = this._prepState; 45132 if (!prepState || prepState.ppem !== ppem) { 45133 var fpgmState = this._fpgmState; 45134 if (!fpgmState) { 45135 // Executes the fpgm state. 45136 // This is used by fonts to define functions. 45137 State.prototype = defaultState; 45138 fpgmState = this._fpgmState = new State('fpgm', font.tables.fpgm); 45139 fpgmState.funcs = [ 45140 ]; 45141 fpgmState.font = font; 45142 if (exports.DEBUG) { 45143 console.log('---EXEC FPGM---'); 45144 fpgmState.step = - 1; 45145 } 45146 try { 45147 exec(fpgmState); 45148 } catch (e) { 45149 console.log('Hinting error in FPGM:' + e); 45150 this._errorState = 3; 45151 return; 45152 } 45153 } // Executes the prep program for this ppem setting. 45154 // This is used by fonts to set cvt values 45155 // depending on to be rendered font size. 45156 45157 State.prototype = fpgmState; 45158 prepState = this._prepState = new State('prep', font.tables.prep); 45159 prepState.ppem = ppem; // Creates a copy of the cvt table 45160 // and scales it to the current ppem setting. 45161 var oCvt = font.tables.cvt; 45162 if (oCvt) { 45163 var cvt = prepState.cvt = new Array(oCvt.length); 45164 var scale = ppem / font.unitsPerEm; 45165 for (var c = 0; c < oCvt.length; c++) { 45166 cvt[c] = oCvt[c] * scale; 45167 } 45168 } else { 45169 prepState.cvt = [ 45170 ]; 45171 } 45172 if (exports.DEBUG) { 45173 console.log('---EXEC PREP---'); 45174 prepState.step = - 1; 45175 } 45176 try { 45177 exec(prepState); 45178 } catch (e) { 45179 if (this._errorState < 2) { 45180 console.log('Hinting error in PREP:' + e); 45181 } 45182 this._errorState = 2; 45183 } 45184 } 45185 if (this._errorState > 1) { 45186 return; 45187 } 45188 try { 45189 return execGlyph(glyph, prepState); 45190 } catch (e) { 45191 if (this._errorState < 1) { 45192 console.log('Hinting error:' + e); 45193 console.log('Note: further hinting errors are silenced'); 45194 } 45195 this._errorState = 1; 45196 return undefined; 45197 } 45198 }; 45199 /* 45200 * Executes the hinting program for a glyph. 45201 */ 45202 execGlyph = function (glyph, prepState) { 45203 // original point positions 45204 var xScale = prepState.ppem / prepState.font.unitsPerEm; 45205 var yScale = xScale; 45206 var components = glyph.components; 45207 var contours; 45208 var gZone; 45209 var state; 45210 State.prototype = prepState; 45211 if (!components) { 45212 state = new State('glyf', glyph.instructions); 45213 if (exports.DEBUG) { 45214 console.log('---EXEC GLYPH---'); 45215 state.step = - 1; 45216 } 45217 execComponent(glyph, state, xScale, yScale); 45218 gZone = state.gZone; 45219 } else { 45220 var font = prepState.font; 45221 gZone = [ 45222 ]; 45223 contours = [ 45224 ]; 45225 for (var i = 0; i < components.length; i++) { 45226 var c = components[i]; 45227 var cg = font.glyphs.get(c.glyphIndex); 45228 state = new State('glyf', cg.instructions); 45229 if (exports.DEBUG) { 45230 console.log('---EXEC COMP ' + i + '---'); 45231 state.step = - 1; 45232 } 45233 execComponent(cg, state, xScale, yScale); // appends the computed points to the result array 45234 // post processes the component points 45235 var dx = Math.round(c.dx * xScale); 45236 var dy = Math.round(c.dy * yScale); 45237 var gz = state.gZone; 45238 var cc = state.contours; 45239 for (var pi = 0; pi < gz.length; pi++) { 45240 var p = gz[pi]; 45241 p.xTouched = p.yTouched = false; 45242 p.xo = p.x = p.x + dx; 45243 p.yo = p.y = p.y + dy; 45244 } 45245 var gLen = gZone.length; 45246 gZone.push.apply(gZone, gz); 45247 for (var j = 0; j < cc.length; j++) { 45248 contours.push(cc[j] + gLen); 45249 } 45250 } 45251 if (glyph.instructions && !state.inhibitGridFit) { 45252 // the composite has instructions on its own 45253 state = new State('glyf', glyph.instructions); 45254 state.gZone = state.z0 = state.z1 = state.z2 = gZone; 45255 state.contours = contours; // note: HPZero cannot be used here, since 45256 // the point might be modified 45257 gZone.push(new HPoint(0, 0), new HPoint(Math.round(glyph.advanceWidth * xScale), 0)); 45258 if (exports.DEBUG) { 45259 console.log('---EXEC COMPOSITE---'); 45260 state.step = - 1; 45261 } 45262 exec(state); 45263 gZone.length -= 2; 45264 } 45265 } 45266 return gZone; 45267 }; 45268 /* 45269 * Executes the hinting program for a component of a multi-component glyph 45270 * or of the glyph itself for a non-component glyph. 45271 */ 45272 execComponent = function (glyph, state, xScale, yScale) { 45273 var points = glyph.points || [ 45274 ]; 45275 var pLen = points.length; 45276 var gZone = state.gZone = state.z0 = state.z1 = state.z2 = [ 45277 ]; 45278 var contours = state.contours = [ 45279 ]; // Scales the original points and 45280 // makes copies for the hinted points. 45281 var cp; // current point 45282 for (var i = 0; i < pLen; i++) { 45283 cp = points[i]; 45284 gZone[i] = new HPoint(cp.x * xScale, cp.y * yScale, cp.lastPointOfContour, cp.onCurve); 45285 } // Chain links the contours. 45286 45287 var sp; // start point 45288 var np; // next point 45289 for (var i$1 = 0; i$1 < pLen; i$1++) { 45290 cp = gZone[i$1]; 45291 if (!sp) { 45292 sp = cp; 45293 contours.push(i$1); 45294 } 45295 if (cp.lastPointOfContour) { 45296 cp.nextPointOnContour = sp; 45297 sp.prevPointOnContour = cp; 45298 sp = undefined; 45299 } else { 45300 np = gZone[i$1 + 1]; 45301 cp.nextPointOnContour = np; 45302 np.prevPointOnContour = cp; 45303 } 45304 } 45305 if (state.inhibitGridFit) { 45306 return; 45307 } 45308 if (exports.DEBUG) { 45309 console.log('PROCESSING GLYPH', state.stack); 45310 for (var i$2 = 0; i$2 < pLen; i$2++) { 45311 console.log(i$2, gZone[i$2].x, gZone[i$2].y); 45312 } 45313 } 45314 gZone.push(new HPoint(0, 0), new HPoint(Math.round(glyph.advanceWidth * xScale), 0)); 45315 exec(state); // Removes the extra points. 45316 gZone.length -= 2; 45317 if (exports.DEBUG) { 45318 console.log('FINISHED GLYPH', state.stack); 45319 for (var i$3 = 0; i$3 < pLen; i$3++) { 45320 console.log(i$3, gZone[i$3].x, gZone[i$3].y); 45321 } 45322 } 45323 }; 45324 /* 45325 * Executes the program loaded in state. 45326 */ 45327 exec = function (state) { 45328 var prog = state.prog; 45329 if (!prog) { 45330 return; 45331 } 45332 var pLen = prog.length; 45333 var ins; 45334 for (state.ip = 0; state.ip < pLen; state.ip++) { 45335 if (exports.DEBUG) { 45336 state.step++; 45337 } 45338 ins = instructionTable[prog[state.ip]]; 45339 if (!ins) { 45340 throw new Error('unknown instruction: 0x' + Number(prog[state.ip]).toString(16)); 45341 } 45342 ins(state); // very extensive debugging for each step 45343 /* 45344 if (exports.DEBUG) { 45345 var da; 45346 if (state.gZone) { 45347 da = []; 45348 for (let i = 0; i < state.gZone.length; i++) 45349 { 45350 da.push(i + ' ' + 45351 state.gZone[i].x * 64 + ' ' + 45352 state.gZone[i].y * 64 + ' ' + 45353 (state.gZone[i].xTouched ? 'x' : '') + 45354 (state.gZone[i].yTouched ? 'y' : '') 45355 ); 45356 } 45357 console.log('GZ', da); 45358 } 45359 if (state.tZone) { 45360 da = []; 45361 for (let i = 0; i < state.tZone.length; i++) { 45362 da.push(i + ' ' + 45363 state.tZone[i].x * 64 + ' ' + 45364 state.tZone[i].y * 64 + ' ' + 45365 (state.tZone[i].xTouched ? 'x' : '') + 45366 (state.tZone[i].yTouched ? 'y' : '') 45367 ); 45368 } 45369 console.log('TZ', da); 45370 } 45371 if (state.stack.length > 10) { 45372 console.log( 45373 state.stack.length, 45374 '...', state.stack.slice(state.stack.length - 10) 45375 ); 45376 } else { 45377 console.log(state.stack.length, state.stack); 45378 } 45379 } 45380 */ 45381 } 45382 }; 45383 /* 45384 * Initializes the twilight zone. 45385 * 45386 * This is only done if a SZPx instruction 45387 * refers to the twilight zone. 45388 */ 45389 function initTZone(state) { 45390 var tZone = state.tZone = new Array(state.gZone.length); // no idea if this is actually correct... 45391 for (var i = 0; i < tZone.length; i++) { 45392 tZone[i] = new HPoint(0, 0); 45393 } 45394 } /* 45395 * Skips the instruction pointer ahead over an IF/ELSE block. 45396 * handleElse .. if true breaks on matching ELSE 45397 */ 45398 45399 function skip(state, handleElse) { 45400 var prog = state.prog; 45401 var ip = state.ip; 45402 var nesting = 1; 45403 var ins; 45404 do { 45405 ins = prog[++ip]; 45406 if (ins === 88) // IF 45407 { 45408 nesting++; 45409 } else if (ins === 89) // EIF 45410 { 45411 nesting--; 45412 } else if (ins === 64) // NPUSHB 45413 { 45414 ip += prog[ip + 1] + 1; 45415 } else if (ins === 65) // NPUSHW 45416 { 45417 ip += 2 * prog[ip + 1] + 1; 45418 } else if (ins >= 176 && ins <= 183) // PUSHB 45419 { 45420 ip += ins - 176 + 1; 45421 } else if (ins >= 184 && ins <= 191) // PUSHW 45422 { 45423 ip += (ins - 184 + 1) * 2; 45424 } else if (handleElse && nesting === 1 && ins === 27) // ELSE 45425 { 45426 break; 45427 } 45428 } while (nesting > 0); 45429 state.ip = ip; 45430 } /*----------------------------------------------------------* 45431 * And then a lot of instructions... * 45432 *----------------------------------------------------------*/ 45433 // SVTCA[a] Set freedom and projection Vectors To Coordinate Axis 45434 // 0x00-0x01 45435 45436 function SVTCA(v, state) { 45437 if (exports.DEBUG) { 45438 console.log(state.step, 'SVTCA[' + v.axis + ']'); 45439 } 45440 state.fv = state.pv = state.dpv = v; 45441 } // SPVTCA[a] Set Projection Vector to Coordinate Axis 45442 // 0x02-0x03 45443 45444 function SPVTCA(v, state) { 45445 if (exports.DEBUG) { 45446 console.log(state.step, 'SPVTCA[' + v.axis + ']'); 45447 } 45448 state.pv = state.dpv = v; 45449 } // SFVTCA[a] Set Freedom Vector to Coordinate Axis 45450 // 0x04-0x05 45451 45452 function SFVTCA(v, state) { 45453 if (exports.DEBUG) { 45454 console.log(state.step, 'SFVTCA[' + v.axis + ']'); 45455 } 45456 state.fv = v; 45457 } // SPVTL[a] Set Projection Vector To Line 45458 // 0x06-0x07 45459 45460 function SPVTL(a, state) { 45461 var stack = state.stack; 45462 var p2i = stack.pop(); 45463 var p1i = stack.pop(); 45464 var p2 = state.z2[p2i]; 45465 var p1 = state.z1[p1i]; 45466 if (exports.DEBUG) { 45467 console.log('SPVTL[' + a + ']', p2i, p1i); 45468 } 45469 var dx; 45470 var dy; 45471 if (!a) { 45472 dx = p1.x - p2.x; 45473 dy = p1.y - p2.y; 45474 } else { 45475 dx = p2.y - p1.y; 45476 dy = p1.x - p2.x; 45477 } 45478 state.pv = state.dpv = getUnitVector(dx, dy); 45479 } // SFVTL[a] Set Freedom Vector To Line 45480 // 0x08-0x09 45481 45482 function SFVTL(a, state) { 45483 var stack = state.stack; 45484 var p2i = stack.pop(); 45485 var p1i = stack.pop(); 45486 var p2 = state.z2[p2i]; 45487 var p1 = state.z1[p1i]; 45488 if (exports.DEBUG) { 45489 console.log('SFVTL[' + a + ']', p2i, p1i); 45490 } 45491 var dx; 45492 var dy; 45493 if (!a) { 45494 dx = p1.x - p2.x; 45495 dy = p1.y - p2.y; 45496 } else { 45497 dx = p2.y - p1.y; 45498 dy = p1.x - p2.x; 45499 } 45500 state.fv = getUnitVector(dx, dy); 45501 } // SPVFS[] Set Projection Vector From Stack 45502 // 0x0A 45503 45504 function SPVFS(state) { 45505 var stack = state.stack; 45506 var y = stack.pop(); 45507 var x = stack.pop(); 45508 if (exports.DEBUG) { 45509 console.log(state.step, 'SPVFS[]', y, x); 45510 } 45511 state.pv = state.dpv = getUnitVector(x, y); 45512 } // SFVFS[] Set Freedom Vector From Stack 45513 // 0x0B 45514 45515 function SFVFS(state) { 45516 var stack = state.stack; 45517 var y = stack.pop(); 45518 var x = stack.pop(); 45519 if (exports.DEBUG) { 45520 console.log(state.step, 'SPVFS[]', y, x); 45521 } 45522 state.fv = getUnitVector(x, y); 45523 } // GPV[] Get Projection Vector 45524 // 0x0C 45525 45526 function GPV(state) { 45527 var stack = state.stack; 45528 var pv = state.pv; 45529 if (exports.DEBUG) { 45530 console.log(state.step, 'GPV[]'); 45531 } 45532 stack.push(pv.x * 16384); 45533 stack.push(pv.y * 16384); 45534 } // GFV[] Get Freedom Vector 45535 // 0x0C 45536 45537 function GFV(state) { 45538 var stack = state.stack; 45539 var fv = state.fv; 45540 if (exports.DEBUG) { 45541 console.log(state.step, 'GFV[]'); 45542 } 45543 stack.push(fv.x * 16384); 45544 stack.push(fv.y * 16384); 45545 } // SFVTPV[] Set Freedom Vector To Projection Vector 45546 // 0x0E 45547 45548 function SFVTPV(state) { 45549 state.fv = state.pv; 45550 if (exports.DEBUG) { 45551 console.log(state.step, 'SFVTPV[]'); 45552 } 45553 } // ISECT[] moves point p to the InterSECTion of two lines 45554 // 0x0F 45555 45556 function ISECT(state) { 45557 var stack = state.stack; 45558 var pa0i = stack.pop(); 45559 var pa1i = stack.pop(); 45560 var pb0i = stack.pop(); 45561 var pb1i = stack.pop(); 45562 var pi = stack.pop(); 45563 var z0 = state.z0; 45564 var z1 = state.z1; 45565 var pa0 = z0[pa0i]; 45566 var pa1 = z0[pa1i]; 45567 var pb0 = z1[pb0i]; 45568 var pb1 = z1[pb1i]; 45569 var p = state.z2[pi]; 45570 if (exports.DEBUG) { 45571 console.log('ISECT[], ', pa0i, pa1i, pb0i, pb1i, pi); 45572 } // math from 45573 // en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line 45574 45575 var x1 = pa0.x; 45576 var y1 = pa0.y; 45577 var x2 = pa1.x; 45578 var y2 = pa1.y; 45579 var x3 = pb0.x; 45580 var y3 = pb0.y; 45581 var x4 = pb1.x; 45582 var y4 = pb1.y; 45583 var div = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); 45584 var f1 = x1 * y2 - y1 * x2; 45585 var f2 = x3 * y4 - y3 * x4; 45586 p.x = (f1 * (x3 - x4) - f2 * (x1 - x2)) / div; 45587 p.y = (f1 * (y3 - y4) - f2 * (y1 - y2)) / div; 45588 } // SRP0[] Set Reference Point 0 45589 // 0x10 45590 45591 function SRP0(state) { 45592 state.rp0 = state.stack.pop(); 45593 if (exports.DEBUG) { 45594 console.log(state.step, 'SRP0[]', state.rp0); 45595 } 45596 } // SRP1[] Set Reference Point 1 45597 // 0x11 45598 45599 function SRP1(state) { 45600 state.rp1 = state.stack.pop(); 45601 if (exports.DEBUG) { 45602 console.log(state.step, 'SRP1[]', state.rp1); 45603 } 45604 } // SRP1[] Set Reference Point 2 45605 // 0x12 45606 45607 function SRP2(state) { 45608 state.rp2 = state.stack.pop(); 45609 if (exports.DEBUG) { 45610 console.log(state.step, 'SRP2[]', state.rp2); 45611 } 45612 } // SZP0[] Set Zone Pointer 0 45613 // 0x13 45614 45615 function SZP0(state) { 45616 var n = state.stack.pop(); 45617 if (exports.DEBUG) { 45618 console.log(state.step, 'SZP0[]', n); 45619 } 45620 state.zp0 = n; 45621 switch (n) { 45622 case 0: 45623 if (!state.tZone) { 45624 initTZone(state); 45625 } 45626 state.z0 = state.tZone; 45627 break; 45628 case 1: 45629 state.z0 = state.gZone; 45630 break; 45631 default: 45632 throw new Error('Invalid zone pointer'); 45633 } 45634 } // SZP1[] Set Zone Pointer 1 45635 // 0x14 45636 45637 function SZP1(state) { 45638 var n = state.stack.pop(); 45639 if (exports.DEBUG) { 45640 console.log(state.step, 'SZP1[]', n); 45641 } 45642 state.zp1 = n; 45643 switch (n) { 45644 case 0: 45645 if (!state.tZone) { 45646 initTZone(state); 45647 } 45648 state.z1 = state.tZone; 45649 break; 45650 case 1: 45651 state.z1 = state.gZone; 45652 break; 45653 default: 45654 throw new Error('Invalid zone pointer'); 45655 } 45656 } // SZP2[] Set Zone Pointer 2 45657 // 0x15 45658 45659 function SZP2(state) { 45660 var n = state.stack.pop(); 45661 if (exports.DEBUG) { 45662 console.log(state.step, 'SZP2[]', n); 45663 } 45664 state.zp2 = n; 45665 switch (n) { 45666 case 0: 45667 if (!state.tZone) { 45668 initTZone(state); 45669 } 45670 state.z2 = state.tZone; 45671 break; 45672 case 1: 45673 state.z2 = state.gZone; 45674 break; 45675 default: 45676 throw new Error('Invalid zone pointer'); 45677 } 45678 } // SZPS[] Set Zone PointerS 45679 // 0x16 45680 45681 function SZPS(state) { 45682 var n = state.stack.pop(); 45683 if (exports.DEBUG) { 45684 console.log(state.step, 'SZPS[]', n); 45685 } 45686 state.zp0 = state.zp1 = state.zp2 = n; 45687 switch (n) { 45688 case 0: 45689 if (!state.tZone) { 45690 initTZone(state); 45691 } 45692 state.z0 = state.z1 = state.z2 = state.tZone; 45693 break; 45694 case 1: 45695 state.z0 = state.z1 = state.z2 = state.gZone; 45696 break; 45697 default: 45698 throw new Error('Invalid zone pointer'); 45699 } 45700 } // SLOOP[] Set LOOP variable 45701 // 0x17 45702 45703 function SLOOP(state) { 45704 state.loop = state.stack.pop(); 45705 if (exports.DEBUG) { 45706 console.log(state.step, 'SLOOP[]', state.loop); 45707 } 45708 } // RTG[] Round To Grid 45709 // 0x18 45710 45711 function RTG(state) { 45712 if (exports.DEBUG) { 45713 console.log(state.step, 'RTG[]'); 45714 } 45715 state.round = roundToGrid; 45716 } // RTHG[] Round To Half Grid 45717 // 0x19 45718 45719 function RTHG(state) { 45720 if (exports.DEBUG) { 45721 console.log(state.step, 'RTHG[]'); 45722 } 45723 state.round = roundToHalfGrid; 45724 } // SMD[] Set Minimum Distance 45725 // 0x1A 45726 45727 function SMD(state) { 45728 var d = state.stack.pop(); 45729 if (exports.DEBUG) { 45730 console.log(state.step, 'SMD[]', d); 45731 } 45732 state.minDis = d / 64; 45733 } // ELSE[] ELSE clause 45734 // 0x1B 45735 45736 function ELSE(state) { 45737 // This instruction has been reached by executing a then branch 45738 // so it just skips ahead until matching EIF. 45739 // 45740 // In case the IF was negative the IF[] instruction already 45741 // skipped forward over the ELSE[] 45742 if (exports.DEBUG) { 45743 console.log(state.step, 'ELSE[]'); 45744 } 45745 skip(state, false); 45746 } // JMPR[] JuMP Relative 45747 // 0x1C 45748 45749 function JMPR(state) { 45750 var o = state.stack.pop(); 45751 if (exports.DEBUG) { 45752 console.log(state.step, 'JMPR[]', o); 45753 } // A jump by 1 would do nothing. 45754 45755 state.ip += o - 1; 45756 } // SCVTCI[] Set Control Value Table Cut-In 45757 // 0x1D 45758 45759 function SCVTCI(state) { 45760 var n = state.stack.pop(); 45761 if (exports.DEBUG) { 45762 console.log(state.step, 'SCVTCI[]', n); 45763 } 45764 state.cvCutIn = n / 64; 45765 } // DUP[] DUPlicate top stack element 45766 // 0x20 45767 45768 function DUP(state) { 45769 var stack = state.stack; 45770 if (exports.DEBUG) { 45771 console.log(state.step, 'DUP[]'); 45772 } 45773 stack.push(stack[stack.length - 1]); 45774 } // POP[] POP top stack element 45775 // 0x21 45776 45777 function POP(state) { 45778 if (exports.DEBUG) { 45779 console.log(state.step, 'POP[]'); 45780 } 45781 state.stack.pop(); 45782 } // CLEAR[] CLEAR the stack 45783 // 0x22 45784 45785 function CLEAR(state) { 45786 if (exports.DEBUG) { 45787 console.log(state.step, 'CLEAR[]'); 45788 } 45789 state.stack.length = 0; 45790 } // SWAP[] SWAP the top two elements on the stack 45791 // 0x23 45792 45793 function SWAP(state) { 45794 var stack = state.stack; 45795 var a = stack.pop(); 45796 var b = stack.pop(); 45797 if (exports.DEBUG) { 45798 console.log(state.step, 'SWAP[]'); 45799 } 45800 stack.push(a); 45801 stack.push(b); 45802 } // DEPTH[] DEPTH of the stack 45803 // 0x24 45804 45805 function DEPTH(state) { 45806 var stack = state.stack; 45807 if (exports.DEBUG) { 45808 console.log(state.step, 'DEPTH[]'); 45809 } 45810 stack.push(stack.length); 45811 } // LOOPCALL[] LOOPCALL function 45812 // 0x2A 45813 45814 function LOOPCALL(state) { 45815 var stack = state.stack; 45816 var fn = stack.pop(); 45817 var c = stack.pop(); 45818 if (exports.DEBUG) { 45819 console.log(state.step, 'LOOPCALL[]', fn, c); 45820 } // saves callers program 45821 45822 var cip = state.ip; 45823 var cprog = state.prog; 45824 state.prog = state.funcs[fn]; // executes the function 45825 for (var i = 0; i < c; i++) { 45826 exec(state); 45827 if (exports.DEBUG) { 45828 console.log(++state.step, i + 1 < c ? 'next loopcall' : 'done loopcall', i); 45829 } 45830 } // restores the callers program 45831 45832 state.ip = cip; 45833 state.prog = cprog; 45834 } // CALL[] CALL function 45835 // 0x2B 45836 45837 function CALL(state) { 45838 var fn = state.stack.pop(); 45839 if (exports.DEBUG) { 45840 console.log(state.step, 'CALL[]', fn); 45841 } // saves callers program 45842 45843 var cip = state.ip; 45844 var cprog = state.prog; 45845 state.prog = state.funcs[fn]; // executes the function 45846 exec(state); // restores the callers program 45847 state.ip = cip; 45848 state.prog = cprog; 45849 if (exports.DEBUG) { 45850 console.log(++state.step, 'returning from', fn); 45851 } 45852 } // CINDEX[] Copy the INDEXed element to the top of the stack 45853 // 0x25 45854 45855 function CINDEX(state) { 45856 var stack = state.stack; 45857 var k = stack.pop(); 45858 if (exports.DEBUG) { 45859 console.log(state.step, 'CINDEX[]', k); 45860 } // In case of k == 1, it copies the last element after popping 45861 // thus stack.length - k. 45862 45863 stack.push(stack[stack.length - k]); 45864 } // MINDEX[] Move the INDEXed element to the top of the stack 45865 // 0x26 45866 45867 function MINDEX(state) { 45868 var stack = state.stack; 45869 var k = stack.pop(); 45870 if (exports.DEBUG) { 45871 console.log(state.step, 'MINDEX[]', k); 45872 } 45873 stack.push(stack.splice(stack.length - k, 1) [0]); 45874 } // FDEF[] Function DEFinition 45875 // 0x2C 45876 45877 function FDEF(state) { 45878 if (state.env !== 'fpgm') { 45879 throw new Error('FDEF not allowed here'); 45880 } 45881 var stack = state.stack; 45882 var prog = state.prog; 45883 var ip = state.ip; 45884 var fn = stack.pop(); 45885 var ipBegin = ip; 45886 if (exports.DEBUG) { 45887 console.log(state.step, 'FDEF[]', fn); 45888 } 45889 while (prog[++ip] !== 45) { 45890 } 45891 state.ip = ip; 45892 state.funcs[fn] = prog.slice(ipBegin + 1, ip); 45893 } // MDAP[a] Move Direct Absolute Point 45894 // 0x2E-0x2F 45895 45896 function MDAP(round, state) { 45897 var pi = state.stack.pop(); 45898 var p = state.z0[pi]; 45899 var fv = state.fv; 45900 var pv = state.pv; 45901 if (exports.DEBUG) { 45902 console.log(state.step, 'MDAP[' + round + ']', pi); 45903 } 45904 var d = pv.distance(p, HPZero); 45905 if (round) { 45906 d = state.round(d); 45907 } 45908 fv.setRelative(p, HPZero, d, pv); 45909 fv.touch(p); 45910 state.rp0 = state.rp1 = pi; 45911 } // IUP[a] Interpolate Untouched Points through the outline 45912 // 0x30 45913 45914 function IUP(v, state) { 45915 var z2 = state.z2; 45916 var pLen = z2.length - 2; 45917 var cp; 45918 var pp; 45919 var np; 45920 if (exports.DEBUG) { 45921 console.log(state.step, 'IUP[' + v.axis + ']'); 45922 } 45923 for (var i = 0; i < pLen; i++) { 45924 cp = z2[i]; // current point 45925 // if this point has been touched go on 45926 if (v.touched(cp)) { 45927 continue; 45928 } 45929 pp = cp.prevTouched(v); // no point on the contour has been touched? 45930 if (pp === cp) { 45931 continue; 45932 } 45933 np = cp.nextTouched(v); 45934 if (pp === np) { 45935 // only one point on the contour has been touched 45936 // so simply moves the point like that 45937 v.setRelative(cp, cp, v.distance(pp, pp, false, true), v, true); 45938 } 45939 v.interpolate(cp, pp, np, v); 45940 } 45941 } // SHP[] SHift Point using reference point 45942 // 0x32-0x33 45943 45944 function SHP(a, state) { 45945 var stack = state.stack; 45946 var rpi = a ? state.rp1 : state.rp2; 45947 var rp = (a ? state.z0 : state.z1) [rpi]; 45948 var fv = state.fv; 45949 var pv = state.pv; 45950 var loop = state.loop; 45951 var z2 = state.z2; 45952 while (loop--) { 45953 var pi = stack.pop(); 45954 var p = z2[pi]; 45955 var d = pv.distance(rp, rp, false, true); 45956 fv.setRelative(p, p, d, pv); 45957 fv.touch(p); 45958 if (exports.DEBUG) { 45959 console.log(state.step, (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + 'SHP[' + (a ? 'rp1' : 'rp2') + ']', pi); 45960 } 45961 } 45962 state.loop = 1; 45963 } // SHC[] SHift Contour using reference point 45964 // 0x36-0x37 45965 45966 function SHC(a, state) { 45967 var stack = state.stack; 45968 var rpi = a ? state.rp1 : state.rp2; 45969 var rp = (a ? state.z0 : state.z1) [rpi]; 45970 var fv = state.fv; 45971 var pv = state.pv; 45972 var ci = stack.pop(); 45973 var sp = state.z2[state.contours[ci]]; 45974 var p = sp; 45975 if (exports.DEBUG) { 45976 console.log(state.step, 'SHC[' + a + ']', ci); 45977 } 45978 var d = pv.distance(rp, rp, false, true); 45979 do { 45980 if (p !== rp) { 45981 fv.setRelative(p, p, d, pv); 45982 } 45983 p = p.nextPointOnContour; 45984 } while (p !== sp); 45985 } // SHZ[] SHift Zone using reference point 45986 // 0x36-0x37 45987 45988 function SHZ(a, state) { 45989 var stack = state.stack; 45990 var rpi = a ? state.rp1 : state.rp2; 45991 var rp = (a ? state.z0 : state.z1) [rpi]; 45992 var fv = state.fv; 45993 var pv = state.pv; 45994 var e = stack.pop(); 45995 if (exports.DEBUG) { 45996 console.log(state.step, 'SHZ[' + a + ']', e); 45997 } 45998 var z; 45999 switch (e) { 46000 case 0: 46001 z = state.tZone; 46002 break; 46003 case 1: 46004 z = state.gZone; 46005 break; 46006 default: 46007 throw new Error('Invalid zone'); 46008 } 46009 var p; 46010 var d = pv.distance(rp, rp, false, true); 46011 var pLen = z.length - 2; 46012 for (var i = 0; i < pLen; i++) { 46013 p = z[i]; 46014 fv.setRelative(p, p, d, pv); //if (p !== rp) fv.setRelative(p, p, d, pv); 46015 } 46016 } // SHPIX[] SHift point by a PIXel amount 46017 // 0x38 46018 46019 function SHPIX(state) { 46020 var stack = state.stack; 46021 var loop = state.loop; 46022 var fv = state.fv; 46023 var d = stack.pop() / 64; 46024 var z2 = state.z2; 46025 while (loop--) { 46026 var pi = stack.pop(); 46027 var p = z2[pi]; 46028 if (exports.DEBUG) { 46029 console.log(state.step, (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + 'SHPIX[]', pi, d); 46030 } 46031 fv.setRelative(p, p, d); 46032 fv.touch(p); 46033 } 46034 state.loop = 1; 46035 } // IP[] Interpolate Point 46036 // 0x39 46037 46038 function IP(state) { 46039 var stack = state.stack; 46040 var rp1i = state.rp1; 46041 var rp2i = state.rp2; 46042 var loop = state.loop; 46043 var rp1 = state.z0[rp1i]; 46044 var rp2 = state.z1[rp2i]; 46045 var fv = state.fv; 46046 var pv = state.dpv; 46047 var z2 = state.z2; 46048 while (loop--) { 46049 var pi = stack.pop(); 46050 var p = z2[pi]; 46051 if (exports.DEBUG) { 46052 console.log(state.step, (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + 'IP[]', pi, rp1i, '<->', rp2i); 46053 } 46054 fv.interpolate(p, rp1, rp2, pv); 46055 fv.touch(p); 46056 } 46057 state.loop = 1; 46058 } // MSIRP[a] Move Stack Indirect Relative Point 46059 // 0x3A-0x3B 46060 46061 function MSIRP(a, state) { 46062 var stack = state.stack; 46063 var d = stack.pop() / 64; 46064 var pi = stack.pop(); 46065 var p = state.z1[pi]; 46066 var rp0 = state.z0[state.rp0]; 46067 var fv = state.fv; 46068 var pv = state.pv; 46069 fv.setRelative(p, rp0, d, pv); 46070 fv.touch(p); 46071 if (exports.DEBUG) { 46072 console.log(state.step, 'MSIRP[' + a + ']', d, pi); 46073 } 46074 state.rp1 = state.rp0; 46075 state.rp2 = pi; 46076 if (a) { 46077 state.rp0 = pi; 46078 } 46079 } // ALIGNRP[] Align to reference point. 46080 // 0x3C 46081 46082 function ALIGNRP(state) { 46083 var stack = state.stack; 46084 var rp0i = state.rp0; 46085 var rp0 = state.z0[rp0i]; 46086 var loop = state.loop; 46087 var fv = state.fv; 46088 var pv = state.pv; 46089 var z1 = state.z1; 46090 while (loop--) { 46091 var pi = stack.pop(); 46092 var p = z1[pi]; 46093 if (exports.DEBUG) { 46094 console.log(state.step, (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + 'ALIGNRP[]', pi); 46095 } 46096 fv.setRelative(p, rp0, 0, pv); 46097 fv.touch(p); 46098 } 46099 state.loop = 1; 46100 } // RTG[] Round To Double Grid 46101 // 0x3D 46102 46103 function RTDG(state) { 46104 if (exports.DEBUG) { 46105 console.log(state.step, 'RTDG[]'); 46106 } 46107 state.round = roundToDoubleGrid; 46108 } // MIAP[a] Move Indirect Absolute Point 46109 // 0x3E-0x3F 46110 46111 function MIAP(round, state) { 46112 var stack = state.stack; 46113 var n = stack.pop(); 46114 var pi = stack.pop(); 46115 var p = state.z0[pi]; 46116 var fv = state.fv; 46117 var pv = state.pv; 46118 var cv = state.cvt[n]; 46119 if (exports.DEBUG) { 46120 console.log(state.step, 'MIAP[' + round + ']', n, '(', cv, ')', pi); 46121 } 46122 var d = pv.distance(p, HPZero); 46123 if (round) { 46124 if (Math.abs(d - cv) < state.cvCutIn) { 46125 d = cv; 46126 } 46127 d = state.round(d); 46128 } 46129 fv.setRelative(p, HPZero, d, pv); 46130 if (state.zp0 === 0) { 46131 p.xo = p.x; 46132 p.yo = p.y; 46133 } 46134 fv.touch(p); 46135 state.rp0 = state.rp1 = pi; 46136 } // NPUSB[] PUSH N Bytes 46137 // 0x40 46138 46139 function NPUSHB(state) { 46140 var prog = state.prog; 46141 var ip = state.ip; 46142 var stack = state.stack; 46143 var n = prog[++ip]; 46144 if (exports.DEBUG) { 46145 console.log(state.step, 'NPUSHB[]', n); 46146 } 46147 for (var i = 0; i < n; i++) { 46148 stack.push(prog[++ip]); 46149 } 46150 state.ip = ip; 46151 } // NPUSHW[] PUSH N Words 46152 // 0x41 46153 46154 function NPUSHW(state) { 46155 var ip = state.ip; 46156 var prog = state.prog; 46157 var stack = state.stack; 46158 var n = prog[++ip]; 46159 if (exports.DEBUG) { 46160 console.log(state.step, 'NPUSHW[]', n); 46161 } 46162 for (var i = 0; i < n; i++) { 46163 var w = prog[++ip] << 8 | prog[++ip]; 46164 if (w & 32768) { 46165 w = - ((w ^ 65535) + 1); 46166 } 46167 stack.push(w); 46168 } 46169 state.ip = ip; 46170 } // WS[] Write Store 46171 // 0x42 46172 46173 function WS(state) { 46174 var stack = state.stack; 46175 var store = state.store; 46176 if (!store) { 46177 store = state.store = [ 46178 ]; 46179 } 46180 var v = stack.pop(); 46181 var l = stack.pop(); 46182 if (exports.DEBUG) { 46183 console.log(state.step, 'WS', v, l); 46184 } 46185 store[l] = v; 46186 } // RS[] Read Store 46187 // 0x43 46188 46189 function RS(state) { 46190 var stack = state.stack; 46191 var store = state.store; 46192 var l = stack.pop(); 46193 if (exports.DEBUG) { 46194 console.log(state.step, 'RS', l); 46195 } 46196 var v = store && store[l] || 0; 46197 stack.push(v); 46198 } // WCVTP[] Write Control Value Table in Pixel units 46199 // 0x44 46200 46201 function WCVTP(state) { 46202 var stack = state.stack; 46203 var v = stack.pop(); 46204 var l = stack.pop(); 46205 if (exports.DEBUG) { 46206 console.log(state.step, 'WCVTP', v, l); 46207 } 46208 state.cvt[l] = v / 64; 46209 } // RCVT[] Read Control Value Table entry 46210 // 0x45 46211 46212 function RCVT(state) { 46213 var stack = state.stack; 46214 var cvte = stack.pop(); 46215 if (exports.DEBUG) { 46216 console.log(state.step, 'RCVT', cvte); 46217 } 46218 stack.push(state.cvt[cvte] * 64); 46219 } // GC[] Get Coordinate projected onto the projection vector 46220 // 0x46-0x47 46221 46222 function GC(a, state) { 46223 var stack = state.stack; 46224 var pi = stack.pop(); 46225 var p = state.z2[pi]; 46226 if (exports.DEBUG) { 46227 console.log(state.step, 'GC[' + a + ']', pi); 46228 } 46229 stack.push(state.dpv.distance(p, HPZero, a, false) * 64); 46230 } // MD[a] Measure Distance 46231 // 0x49-0x4A 46232 46233 function MD(a, state) { 46234 var stack = state.stack; 46235 var pi2 = stack.pop(); 46236 var pi1 = stack.pop(); 46237 var p2 = state.z1[pi2]; 46238 var p1 = state.z0[pi1]; 46239 var d = state.dpv.distance(p1, p2, a, a); 46240 if (exports.DEBUG) { 46241 console.log(state.step, 'MD[' + a + ']', pi2, pi1, '->', d); 46242 } 46243 state.stack.push(Math.round(d * 64)); 46244 } // MPPEM[] Measure Pixels Per EM 46245 // 0x4B 46246 46247 function MPPEM(state) { 46248 if (exports.DEBUG) { 46249 console.log(state.step, 'MPPEM[]'); 46250 } 46251 state.stack.push(state.ppem); 46252 } // FLIPON[] set the auto FLIP Boolean to ON 46253 // 0x4D 46254 46255 function FLIPON(state) { 46256 if (exports.DEBUG) { 46257 console.log(state.step, 'FLIPON[]'); 46258 } 46259 state.autoFlip = true; 46260 } // LT[] Less Than 46261 // 0x50 46262 46263 function LT(state) { 46264 var stack = state.stack; 46265 var e2 = stack.pop(); 46266 var e1 = stack.pop(); 46267 if (exports.DEBUG) { 46268 console.log(state.step, 'LT[]', e2, e1); 46269 } 46270 stack.push(e1 < e2 ? 1 : 0); 46271 } // LTEQ[] Less Than or EQual 46272 // 0x53 46273 46274 function LTEQ(state) { 46275 var stack = state.stack; 46276 var e2 = stack.pop(); 46277 var e1 = stack.pop(); 46278 if (exports.DEBUG) { 46279 console.log(state.step, 'LTEQ[]', e2, e1); 46280 } 46281 stack.push(e1 <= e2 ? 1 : 0); 46282 } // GTEQ[] Greater Than 46283 // 0x52 46284 46285 function GT(state) { 46286 var stack = state.stack; 46287 var e2 = stack.pop(); 46288 var e1 = stack.pop(); 46289 if (exports.DEBUG) { 46290 console.log(state.step, 'GT[]', e2, e1); 46291 } 46292 stack.push(e1 > e2 ? 1 : 0); 46293 } // GTEQ[] Greater Than or EQual 46294 // 0x53 46295 46296 function GTEQ(state) { 46297 var stack = state.stack; 46298 var e2 = stack.pop(); 46299 var e1 = stack.pop(); 46300 if (exports.DEBUG) { 46301 console.log(state.step, 'GTEQ[]', e2, e1); 46302 } 46303 stack.push(e1 >= e2 ? 1 : 0); 46304 } // EQ[] EQual 46305 // 0x54 46306 46307 function EQ(state) { 46308 var stack = state.stack; 46309 var e2 = stack.pop(); 46310 var e1 = stack.pop(); 46311 if (exports.DEBUG) { 46312 console.log(state.step, 'EQ[]', e2, e1); 46313 } 46314 stack.push(e2 === e1 ? 1 : 0); 46315 } // NEQ[] Not EQual 46316 // 0x55 46317 46318 function NEQ(state) { 46319 var stack = state.stack; 46320 var e2 = stack.pop(); 46321 var e1 = stack.pop(); 46322 if (exports.DEBUG) { 46323 console.log(state.step, 'NEQ[]', e2, e1); 46324 } 46325 stack.push(e2 !== e1 ? 1 : 0); 46326 } // ODD[] ODD 46327 // 0x56 46328 46329 function ODD(state) { 46330 var stack = state.stack; 46331 var n = stack.pop(); 46332 if (exports.DEBUG) { 46333 console.log(state.step, 'ODD[]', n); 46334 } 46335 stack.push(Math.trunc(n) % 2 ? 1 : 0); 46336 } // EVEN[] EVEN 46337 // 0x57 46338 46339 function EVEN(state) { 46340 var stack = state.stack; 46341 var n = stack.pop(); 46342 if (exports.DEBUG) { 46343 console.log(state.step, 'EVEN[]', n); 46344 } 46345 stack.push(Math.trunc(n) % 2 ? 0 : 1); 46346 } // IF[] IF test 46347 // 0x58 46348 46349 function IF(state) { 46350 var test = state.stack.pop(); 46351 if (exports.DEBUG) { 46352 console.log(state.step, 'IF[]', test); 46353 } // if test is true it just continues 46354 // if not the ip is skipped until matching ELSE or EIF 46355 46356 if (!test) { 46357 skip(state, true); 46358 if (exports.DEBUG) { 46359 console.log(state.step, 'EIF[]'); 46360 } 46361 } 46362 } // EIF[] End IF 46363 // 0x59 46364 46365 function EIF(state) { 46366 // this can be reached normally when 46367 // executing an else branch. 46368 // -> just ignore it 46369 if (exports.DEBUG) { 46370 console.log(state.step, 'EIF[]'); 46371 } 46372 } // AND[] logical AND 46373 // 0x5A 46374 46375 function AND(state) { 46376 var stack = state.stack; 46377 var e2 = stack.pop(); 46378 var e1 = stack.pop(); 46379 if (exports.DEBUG) { 46380 console.log(state.step, 'AND[]', e2, e1); 46381 } 46382 stack.push(e2 && e1 ? 1 : 0); 46383 } // OR[] logical OR 46384 // 0x5B 46385 46386 function OR(state) { 46387 var stack = state.stack; 46388 var e2 = stack.pop(); 46389 var e1 = stack.pop(); 46390 if (exports.DEBUG) { 46391 console.log(state.step, 'OR[]', e2, e1); 46392 } 46393 stack.push(e2 || e1 ? 1 : 0); 46394 } // NOT[] logical NOT 46395 // 0x5C 46396 46397 function NOT(state) { 46398 var stack = state.stack; 46399 var e = stack.pop(); 46400 if (exports.DEBUG) { 46401 console.log(state.step, 'NOT[]', e); 46402 } 46403 stack.push(e ? 0 : 1); 46404 } // DELTAP1[] DELTA exception P1 46405 // DELTAP2[] DELTA exception P2 46406 // DELTAP3[] DELTA exception P3 46407 // 0x5D, 0x71, 0x72 46408 46409 function DELTAP123(b, state) { 46410 var stack = state.stack; 46411 var n = stack.pop(); 46412 var fv = state.fv; 46413 var pv = state.pv; 46414 var ppem = state.ppem; 46415 var base = state.deltaBase + (b - 1) * 16; 46416 var ds = state.deltaShift; 46417 var z0 = state.z0; 46418 if (exports.DEBUG) { 46419 console.log(state.step, 'DELTAP[' + b + ']', n, stack); 46420 } 46421 for (var i = 0; i < n; i++) { 46422 var pi = stack.pop(); 46423 var arg = stack.pop(); 46424 var appem = base + ((arg & 240) >> 4); 46425 if (appem !== ppem) { 46426 continue; 46427 } 46428 var mag = (arg & 15) - 8; 46429 if (mag >= 0) { 46430 mag++; 46431 } 46432 if (exports.DEBUG) { 46433 console.log(state.step, 'DELTAPFIX', pi, 'by', mag * ds); 46434 } 46435 var p = z0[pi]; 46436 fv.setRelative(p, p, mag * ds, pv); 46437 } 46438 } // SDB[] Set Delta Base in the graphics state 46439 // 0x5E 46440 46441 function SDB(state) { 46442 var stack = state.stack; 46443 var n = stack.pop(); 46444 if (exports.DEBUG) { 46445 console.log(state.step, 'SDB[]', n); 46446 } 46447 state.deltaBase = n; 46448 } // SDS[] Set Delta Shift in the graphics state 46449 // 0x5F 46450 46451 function SDS(state) { 46452 var stack = state.stack; 46453 var n = stack.pop(); 46454 if (exports.DEBUG) { 46455 console.log(state.step, 'SDS[]', n); 46456 } 46457 state.deltaShift = Math.pow(0.5, n); 46458 } // ADD[] ADD 46459 // 0x60 46460 46461 function ADD(state) { 46462 var stack = state.stack; 46463 var n2 = stack.pop(); 46464 var n1 = stack.pop(); 46465 if (exports.DEBUG) { 46466 console.log(state.step, 'ADD[]', n2, n1); 46467 } 46468 stack.push(n1 + n2); 46469 } // SUB[] SUB 46470 // 0x61 46471 46472 function SUB(state) { 46473 var stack = state.stack; 46474 var n2 = stack.pop(); 46475 var n1 = stack.pop(); 46476 if (exports.DEBUG) { 46477 console.log(state.step, 'SUB[]', n2, n1); 46478 } 46479 stack.push(n1 - n2); 46480 } // DIV[] DIV 46481 // 0x62 46482 46483 function DIV(state) { 46484 var stack = state.stack; 46485 var n2 = stack.pop(); 46486 var n1 = stack.pop(); 46487 if (exports.DEBUG) { 46488 console.log(state.step, 'DIV[]', n2, n1); 46489 } 46490 stack.push(n1 * 64 / n2); 46491 } // MUL[] MUL 46492 // 0x63 46493 46494 function MUL(state) { 46495 var stack = state.stack; 46496 var n2 = stack.pop(); 46497 var n1 = stack.pop(); 46498 if (exports.DEBUG) { 46499 console.log(state.step, 'MUL[]', n2, n1); 46500 } 46501 stack.push(n1 * n2 / 64); 46502 } // ABS[] ABSolute value 46503 // 0x64 46504 46505 function ABS(state) { 46506 var stack = state.stack; 46507 var n = stack.pop(); 46508 if (exports.DEBUG) { 46509 console.log(state.step, 'ABS[]', n); 46510 } 46511 stack.push(Math.abs(n)); 46512 } // NEG[] NEGate 46513 // 0x65 46514 46515 function NEG(state) { 46516 var stack = state.stack; 46517 var n = stack.pop(); 46518 if (exports.DEBUG) { 46519 console.log(state.step, 'NEG[]', n); 46520 } 46521 stack.push( - n); 46522 } // FLOOR[] FLOOR 46523 // 0x66 46524 46525 function FLOOR(state) { 46526 var stack = state.stack; 46527 var n = stack.pop(); 46528 if (exports.DEBUG) { 46529 console.log(state.step, 'FLOOR[]', n); 46530 } 46531 stack.push(Math.floor(n / 64) * 64); 46532 } // CEILING[] CEILING 46533 // 0x67 46534 46535 function CEILING(state) { 46536 var stack = state.stack; 46537 var n = stack.pop(); 46538 if (exports.DEBUG) { 46539 console.log(state.step, 'CEILING[]', n); 46540 } 46541 stack.push(Math.ceil(n / 64) * 64); 46542 } // ROUND[ab] ROUND value 46543 // 0x68-0x6B 46544 46545 function ROUND(dt, state) { 46546 var stack = state.stack; 46547 var n = stack.pop(); 46548 if (exports.DEBUG) { 46549 console.log(state.step, 'ROUND[]'); 46550 } 46551 stack.push(state.round(n / 64) * 64); 46552 } // WCVTF[] Write Control Value Table in Funits 46553 // 0x70 46554 46555 function WCVTF(state) { 46556 var stack = state.stack; 46557 var v = stack.pop(); 46558 var l = stack.pop(); 46559 if (exports.DEBUG) { 46560 console.log(state.step, 'WCVTF[]', v, l); 46561 } 46562 state.cvt[l] = v * state.ppem / state.font.unitsPerEm; 46563 } // DELTAC1[] DELTA exception C1 46564 // DELTAC2[] DELTA exception C2 46565 // DELTAC3[] DELTA exception C3 46566 // 0x73, 0x74, 0x75 46567 46568 function DELTAC123(b, state) { 46569 var stack = state.stack; 46570 var n = stack.pop(); 46571 var ppem = state.ppem; 46572 var base = state.deltaBase + (b - 1) * 16; 46573 var ds = state.deltaShift; 46574 if (exports.DEBUG) { 46575 console.log(state.step, 'DELTAC[' + b + ']', n, stack); 46576 } 46577 for (var i = 0; i < n; i++) { 46578 var c = stack.pop(); 46579 var arg = stack.pop(); 46580 var appem = base + ((arg & 240) >> 4); 46581 if (appem !== ppem) { 46582 continue; 46583 } 46584 var mag = (arg & 15) - 8; 46585 if (mag >= 0) { 46586 mag++; 46587 } 46588 var delta = mag * ds; 46589 if (exports.DEBUG) { 46590 console.log(state.step, 'DELTACFIX', c, 'by', delta); 46591 } 46592 state.cvt[c] += delta; 46593 } 46594 } // SROUND[] Super ROUND 46595 // 0x76 46596 46597 function SROUND(state) { 46598 var n = state.stack.pop(); 46599 if (exports.DEBUG) { 46600 console.log(state.step, 'SROUND[]', n); 46601 } 46602 state.round = roundSuper; 46603 var period; 46604 switch (n & 192) { 46605 case 0: 46606 period = 0.5; 46607 break; 46608 case 64: 46609 period = 1; 46610 break; 46611 case 128: 46612 period = 2; 46613 break; 46614 default: 46615 throw new Error('invalid SROUND value'); 46616 } 46617 state.srPeriod = period; 46618 switch (n & 48) { 46619 case 0: 46620 state.srPhase = 0; 46621 break; 46622 case 16: 46623 state.srPhase = 0.25 * period; 46624 break; 46625 case 32: 46626 state.srPhase = 0.5 * period; 46627 break; 46628 case 48: 46629 state.srPhase = 0.75 * period; 46630 break; 46631 default: 46632 throw new Error('invalid SROUND value'); 46633 } 46634 n &= 15; 46635 if (n === 0) { 46636 state.srThreshold = 0; 46637 } else { 46638 state.srThreshold = (n / 8 - 0.5) * period; 46639 } 46640 } // S45ROUND[] Super ROUND 45 degrees 46641 // 0x77 46642 46643 function S45ROUND(state) { 46644 var n = state.stack.pop(); 46645 if (exports.DEBUG) { 46646 console.log(state.step, 'S45ROUND[]', n); 46647 } 46648 state.round = roundSuper; 46649 var period; 46650 switch (n & 192) { 46651 case 0: 46652 period = Math.sqrt(2) / 2; 46653 break; 46654 case 64: 46655 period = Math.sqrt(2); 46656 break; 46657 case 128: 46658 period = 2 * Math.sqrt(2); 46659 break; 46660 default: 46661 throw new Error('invalid S45ROUND value'); 46662 } 46663 state.srPeriod = period; 46664 switch (n & 48) { 46665 case 0: 46666 state.srPhase = 0; 46667 break; 46668 case 16: 46669 state.srPhase = 0.25 * period; 46670 break; 46671 case 32: 46672 state.srPhase = 0.5 * period; 46673 break; 46674 case 48: 46675 state.srPhase = 0.75 * period; 46676 break; 46677 default: 46678 throw new Error('invalid S45ROUND value'); 46679 } 46680 n &= 15; 46681 if (n === 0) { 46682 state.srThreshold = 0; 46683 } else { 46684 state.srThreshold = (n / 8 - 0.5) * period; 46685 } 46686 } // ROFF[] Round Off 46687 // 0x7A 46688 46689 function ROFF(state) { 46690 if (exports.DEBUG) { 46691 console.log(state.step, 'ROFF[]'); 46692 } 46693 state.round = roundOff; 46694 } // RUTG[] Round Up To Grid 46695 // 0x7C 46696 46697 function RUTG(state) { 46698 if (exports.DEBUG) { 46699 console.log(state.step, 'RUTG[]'); 46700 } 46701 state.round = roundUpToGrid; 46702 } // RDTG[] Round Down To Grid 46703 // 0x7D 46704 46705 function RDTG(state) { 46706 if (exports.DEBUG) { 46707 console.log(state.step, 'RDTG[]'); 46708 } 46709 state.round = roundDownToGrid; 46710 } // SCANCTRL[] SCAN conversion ConTRoL 46711 // 0x85 46712 46713 function SCANCTRL(state) { 46714 var n = state.stack.pop(); // ignored by opentype.js 46715 if (exports.DEBUG) { 46716 console.log(state.step, 'SCANCTRL[]', n); 46717 } 46718 } // SDPVTL[a] Set Dual Projection Vector To Line 46719 // 0x86-0x87 46720 46721 function SDPVTL(a, state) { 46722 var stack = state.stack; 46723 var p2i = stack.pop(); 46724 var p1i = stack.pop(); 46725 var p2 = state.z2[p2i]; 46726 var p1 = state.z1[p1i]; 46727 if (exports.DEBUG) { 46728 console.log(state.step, 'SDPVTL[' + a + ']', p2i, p1i); 46729 } 46730 var dx; 46731 var dy; 46732 if (!a) { 46733 dx = p1.x - p2.x; 46734 dy = p1.y - p2.y; 46735 } else { 46736 dx = p2.y - p1.y; 46737 dy = p1.x - p2.x; 46738 } 46739 state.dpv = getUnitVector(dx, dy); 46740 } // GETINFO[] GET INFOrmation 46741 // 0x88 46742 46743 function GETINFO(state) { 46744 var stack = state.stack; 46745 var sel = stack.pop(); 46746 var r = 0; 46747 if (exports.DEBUG) { 46748 console.log(state.step, 'GETINFO[]', sel); 46749 } // v35 as in no subpixel hinting 46750 46751 if (sel & 1) { 46752 r = 35; 46753 } // TODO rotation and stretch currently not supported 46754 // and thus those GETINFO are always 0. 46755 // opentype.js is always gray scaling 46756 46757 if (sel & 32) { 46758 r |= 4096; 46759 } 46760 stack.push(r); 46761 } // ROLL[] ROLL the top three stack elements 46762 // 0x8A 46763 46764 function ROLL(state) { 46765 var stack = state.stack; 46766 var a = stack.pop(); 46767 var b = stack.pop(); 46768 var c = stack.pop(); 46769 if (exports.DEBUG) { 46770 console.log(state.step, 'ROLL[]'); 46771 } 46772 stack.push(b); 46773 stack.push(a); 46774 stack.push(c); 46775 } // MAX[] MAXimum of top two stack elements 46776 // 0x8B 46777 46778 function MAX(state) { 46779 var stack = state.stack; 46780 var e2 = stack.pop(); 46781 var e1 = stack.pop(); 46782 if (exports.DEBUG) { 46783 console.log(state.step, 'MAX[]', e2, e1); 46784 } 46785 stack.push(Math.max(e1, e2)); 46786 } // MIN[] MINimum of top two stack elements 46787 // 0x8C 46788 46789 function MIN(state) { 46790 var stack = state.stack; 46791 var e2 = stack.pop(); 46792 var e1 = stack.pop(); 46793 if (exports.DEBUG) { 46794 console.log(state.step, 'MIN[]', e2, e1); 46795 } 46796 stack.push(Math.min(e1, e2)); 46797 } // SCANTYPE[] SCANTYPE 46798 // 0x8D 46799 46800 function SCANTYPE(state) { 46801 var n = state.stack.pop(); // ignored by opentype.js 46802 if (exports.DEBUG) { 46803 console.log(state.step, 'SCANTYPE[]', n); 46804 } 46805 } // INSTCTRL[] INSTCTRL 46806 // 0x8D 46807 46808 function INSTCTRL(state) { 46809 var s = state.stack.pop(); 46810 var v = state.stack.pop(); 46811 if (exports.DEBUG) { 46812 console.log(state.step, 'INSTCTRL[]', s, v); 46813 } 46814 switch (s) { 46815 case 1: 46816 state.inhibitGridFit = !!v; 46817 return; 46818 case 2: 46819 state.ignoreCvt = !!v; 46820 return; 46821 default: 46822 throw new Error('invalid INSTCTRL[] selector'); 46823 } 46824 } // PUSHB[abc] PUSH Bytes 46825 // 0xB0-0xB7 46826 46827 function PUSHB(n, state) { 46828 var stack = state.stack; 46829 var prog = state.prog; 46830 var ip = state.ip; 46831 if (exports.DEBUG) { 46832 console.log(state.step, 'PUSHB[' + n + ']'); 46833 } 46834 for (var i = 0; i < n; i++) { 46835 stack.push(prog[++ip]); 46836 } 46837 state.ip = ip; 46838 } // PUSHW[abc] PUSH Words 46839 // 0xB8-0xBF 46840 46841 function PUSHW(n, state) { 46842 var ip = state.ip; 46843 var prog = state.prog; 46844 var stack = state.stack; 46845 if (exports.DEBUG) { 46846 console.log(state.ip, 'PUSHW[' + n + ']'); 46847 } 46848 for (var i = 0; i < n; i++) { 46849 var w = prog[++ip] << 8 | prog[++ip]; 46850 if (w & 32768) { 46851 w = - ((w ^ 65535) + 1); 46852 } 46853 stack.push(w); 46854 } 46855 state.ip = ip; 46856 } // MDRP[abcde] Move Direct Relative Point 46857 // 0xD0-0xEF 46858 // (if indirect is 0) 46859 // 46860 // and 46861 // 46862 // MIRP[abcde] Move Indirect Relative Point 46863 // 0xE0-0xFF 46864 // (if indirect is 1) 46865 46866 function MDRP_MIRP(indirect, setRp0, keepD, ro, dt, state) { 46867 var stack = state.stack; 46868 var cvte = indirect && stack.pop(); 46869 var pi = stack.pop(); 46870 var rp0i = state.rp0; 46871 var rp = state.z0[rp0i]; 46872 var p = state.z1[pi]; 46873 var md = state.minDis; 46874 var fv = state.fv; 46875 var pv = state.dpv; 46876 var od; // original distance 46877 var d; // moving distance 46878 var sign; // sign of distance 46879 var cv; 46880 d = od = pv.distance(p, rp, true, true); 46881 sign = d >= 0 ? 1 : - 1; // Math.sign would be 0 in case of 0 46882 // TODO consider autoFlip 46883 d = Math.abs(d); 46884 if (indirect) { 46885 cv = state.cvt[cvte]; 46886 if (ro && Math.abs(d - cv) < state.cvCutIn) { 46887 d = cv; 46888 } 46889 } 46890 if (keepD && d < md) { 46891 d = md; 46892 } 46893 if (ro) { 46894 d = state.round(d); 46895 } 46896 fv.setRelative(p, rp, sign * d, pv); 46897 fv.touch(p); 46898 if (exports.DEBUG) { 46899 console.log(state.step, (indirect ? 'MIRP[' : 'MDRP[') + (setRp0 ? 'M' : 'm') + (keepD ? '>' : '_') + (ro ? 'R' : '_') + (dt === 0 ? 'Gr' : dt === 1 ? 'Bl' : dt === 2 ? 'Wh' : '') + ']', indirect ? cvte + '(' + state.cvt[cvte] + ',' + cv + ')' : '', pi, '(d =', od, '->', sign * d, ')'); 46900 } 46901 state.rp1 = state.rp0; 46902 state.rp2 = pi; 46903 if (setRp0) { 46904 state.rp0 = pi; 46905 } 46906 } /* 46907 * The instruction table. 46908 */ 46909 46910 instructionTable = [ 46911 /* 0x00 */ 46912 SVTCA.bind(undefined, yUnitVector), 46913 /* 0x01 */ 46914 SVTCA.bind(undefined, xUnitVector), 46915 /* 0x02 */ 46916 SPVTCA.bind(undefined, yUnitVector), 46917 /* 0x03 */ 46918 SPVTCA.bind(undefined, xUnitVector), 46919 /* 0x04 */ 46920 SFVTCA.bind(undefined, yUnitVector), 46921 /* 0x05 */ 46922 SFVTCA.bind(undefined, xUnitVector), 46923 /* 0x06 */ 46924 SPVTL.bind(undefined, 0), 46925 /* 0x07 */ 46926 SPVTL.bind(undefined, 1), 46927 /* 0x08 */ 46928 SFVTL.bind(undefined, 0), 46929 /* 0x09 */ 46930 SFVTL.bind(undefined, 1), 46931 /* 0x0A */ 46932 SPVFS, 46933 /* 0x0B */ 46934 SFVFS,
46935 /* 0x0C */ 46936 GPV, 46937 /* 0x0D */ 46938 GFV, 46939 /* 0x0E */ 46940 SFVTPV, 46941 /* 0x0F */ 46942 ISECT, 46943 /* 0x10 */ 46944 SRP0, 46945 /* 0x11 */ 46946 SRP1, 46947 /* 0x12 */ 46948 SRP2, 46949 /* 0x13 */ 46950 SZP0, 46951 /* 0x14 */ 46952 SZP1, 46953 /* 0x15 */ 46954 SZP2, 46955 /* 0x16 */ 46956 SZPS, 46957 /* 0x17 */ 46958 SLOOP, 46959 /* 0x18 */ 46960 RTG, 46961 /* 0x19 */ 46962 RTHG, 46963 /* 0x1A */ 46964 SMD, 46965 /* 0x1B */ 46966 ELSE, 46967 /* 0x1C */ 46968 JMPR, 46969 /* 0x1D */ 46970 SCVTCI, 46971 /* 0x1E */ 46972 undefined, // TODO SSWCI 46973 /* 0x1F */ 46974 undefined, // TODO SSW 46975 /* 0x20 */ 46976 DUP, 46977 /* 0x21 */ 46978 POP, 46979 /* 0x22 */ 46980 CLEAR, 46981 /* 0x23 */ 46982 SWAP, 46983 /* 0x24 */ 46984 DEPTH, 46985 /* 0x25 */ 46986 CINDEX, 46987 /* 0x26 */ 46988 MINDEX, 46989 /* 0x27 */ 46990 undefined, // TODO ALIGNPTS 46991 /* 0x28 */ 46992 undefined, 46993 /* 0x29 */ 46994 undefined, // TODO UTP 46995 /* 0x2A */ 46996 LOOPCALL, 46997 /* 0x2B */ 46998 CALL, 46999 /* 0x2C */ 47000 FDEF, 47001 /* 0x2D */ 47002 undefined, // ENDF (eaten by FDEF) 47003 /* 0x2E */ 47004 MDAP.bind(undefined, 0), 47005 /* 0x2F */ 47006 MDAP.bind(undefined, 1), 47007 /* 0x30 */ 47008 IUP.bind(undefined, yUnitVector), 47009 /* 0x31 */ 47010 IUP.bind(undefined, xUnitVector), 47011 /* 0x32 */ 47012 SHP.bind(undefined, 0), 47013 /* 0x33 */ 47014 SHP.bind(undefined, 1), 47015 /* 0x34 */ 47016 SHC.bind(undefined, 0), 47017 /* 0x35 */ 47018 SHC.bind(undefined, 1), 47019 /* 0x36 */ 47020 SHZ.bind(undefined, 0), 47021 /* 0x37 */ 47022 SHZ.bind(undefined, 1), 47023 /* 0x38 */ 47024 SHPIX, 47025 /* 0x39 */ 47026 IP, 47027 /* 0x3A */ 47028 MSIRP.bind(undefined, 0), 47029 /* 0x3B */ 47030 MSIRP.bind(undefined, 1), 47031 /* 0x3C */ 47032 ALIGNRP, 47033 /* 0x3D */ 47034 RTDG, 47035 /* 0x3E */ 47036 MIAP.bind(undefined, 0), 47037 /* 0x3F */ 47038 MIAP.bind(undefined, 1), 47039 /* 0x40 */ 47040 NPUSHB, 47041 /* 0x41 */ 47042 NPUSHW, 47043 /* 0x42 */ 47044 WS, 47045 /* 0x43 */ 47046 RS, 47047 /* 0x44 */ 47048 WCVTP, 47049 /* 0x45 */ 47050 RCVT, 47051 /* 0x46 */ 47052 GC.bind(undefined, 0), 47053 /* 0x47 */ 47054 GC.bind(undefined, 1), 47055 /* 0x48 */ 47056 undefined, // TODO SCFS 47057 /* 0x49 */ 47058 MD.bind(undefined, 0), 47059 /* 0x4A */ 47060 MD.bind(undefined, 1), 47061 /* 0x4B */ 47062 MPPEM, 47063 /* 0x4C */ 47064 undefined, // TODO MPS 47065 /* 0x4D */ 47066 FLIPON, 47067 /* 0x4E */ 47068 undefined, // TODO FLIPOFF 47069 /* 0x4F */ 47070 undefined, // TODO DEBUG 47071 /* 0x50 */ 47072 LT, 47073 /* 0x51 */ 47074 LTEQ, 47075 /* 0x52 */ 47076 GT, 47077 /* 0x53 */ 47078 GTEQ, 47079 /* 0x54 */ 47080 EQ, 47081 /* 0x55 */ 47082 NEQ, 47083 /* 0x56 */ 47084 ODD, 47085 /* 0x57 */ 47086 EVEN, 47087 /* 0x58 */ 47088 IF, 47089 /* 0x59 */ 47090 EIF, 47091 /* 0x5A */ 47092 AND, 47093 /* 0x5B */ 47094 OR, 47095 /* 0x5C */ 47096 NOT, 47097 /* 0x5D */ 47098 DELTAP123.bind(undefined, 1), 47099 /* 0x5E */ 47100 SDB, 47101 /* 0x5F */ 47102 SDS, 47103 /* 0x60 */ 47104 ADD, 47105 /* 0x61 */ 47106 SUB, 47107 /* 0x62 */ 47108 DIV, 47109 /* 0x63 */ 47110 MUL, 47111 /* 0x64 */ 47112 ABS, 47113 /* 0x65 */ 47114 NEG, 47115 /* 0x66 */ 47116 FLOOR, 47117 /* 0x67 */ 47118 CEILING, 47119 /* 0x68 */ 47120 ROUND.bind(undefined, 0), 47121 /* 0x69 */ 47122 ROUND.bind(undefined, 1), 47123 /* 0x6A */ 47124 ROUND.bind(undefined, 2), 47125 /* 0x6B */ 47126 ROUND.bind(undefined, 3), 47127 /* 0x6C */ 47128 undefined, // TODO NROUND[ab] 47129 /* 0x6D */ 47130 undefined, // TODO NROUND[ab] 47131 /* 0x6E */ 47132 undefined, // TODO NROUND[ab] 47133 /* 0x6F */ 47134 undefined, // TODO NROUND[ab] 47135 /* 0x70 */ 47136 WCVTF, 47137 /* 0x71 */ 47138 DELTAP123.bind(undefined, 2), 47139 /* 0x72 */ 47140 DELTAP123.bind(undefined, 3), 47141 /* 0x73 */ 47142 DELTAC123.bind(undefined, 1), 47143 /* 0x74 */ 47144 DELTAC123.bind(undefined, 2), 47145 /* 0x75 */ 47146 DELTAC123.bind(undefined, 3), 47147 /* 0x76 */ 47148 SROUND, 47149 /* 0x77 */ 47150 S45ROUND, 47151 /* 0x78 */ 47152 undefined, // TODO JROT[] 47153 /* 0x79 */ 47154 undefined, // TODO JROF[] 47155 /* 0x7A */ 47156 ROFF, 47157 /* 0x7B */ 47158 undefined, 47159 /* 0x7C */ 47160 RUTG, 47161 /* 0x7D */ 47162 RDTG, 47163 /* 0x7E */ 47164 POP, // actually SANGW, supposed to do only a pop though 47165 /* 0x7F */ 47166 POP, // actually AA, supposed to do only a pop though 47167 /* 0x80 */ 47168 undefined, // TODO FLIPPT 47169 /* 0x81 */ 47170 undefined, // TODO FLIPRGON 47171 /* 0x82 */ 47172 undefined, // TODO FLIPRGOFF 47173 /* 0x83 */ 47174 undefined, 47175 /* 0x84 */ 47176 undefined, 47177 /* 0x85 */ 47178 SCANCTRL, 47179 /* 0x86 */ 47180 SDPVTL.bind(undefined, 0), 47181 /* 0x87 */ 47182 SDPVTL.bind(undefined, 1), 47183 /* 0x88 */ 47184 GETINFO, 47185 /* 0x89 */ 47186 undefined, // TODO IDEF 47187 /* 0x8A */ 47188 ROLL, 47189 /* 0x8B */ 47190 MAX, 47191 /* 0x8C */ 47192 MIN, 47193 /* 0x8D */ 47194 SCANTYPE, 47195 /* 0x8E */ 47196 INSTCTRL, 47197 /* 0x8F */ 47198 undefined, 47199 /* 0x90 */ 47200 undefined, 47201 /* 0x91 */ 47202 undefined, 47203 /* 0x92 */ 47204 undefined, 47205 /* 0x93 */ 47206 undefined, 47207 /* 0x94 */ 47208 undefined, 47209 /* 0x95 */ 47210 undefined, 47211 /* 0x96 */ 47212 undefined, 47213 /* 0x97 */ 47214 undefined, 47215 /* 0x98 */ 47216 undefined, 47217 /* 0x99 */ 47218 undefined, 47219 /* 0x9A */ 47220 undefined, 47221 /* 0x9B */ 47222 undefined, 47223 /* 0x9C */ 47224 undefined, 47225 /* 0x9D */ 47226 undefined, 47227 /* 0x9E */ 47228 undefined, 47229 /* 0x9F */ 47230 undefined, 47231 /* 0xA0 */ 47232 undefined, 47233 /* 0xA1 */ 47234 undefined, 47235 /* 0xA2 */ 47236 undefined, 47237 /* 0xA3 */ 47238 undefined, 47239 /* 0xA4 */ 47240 undefined, 47241 /* 0xA5 */ 47242 undefined, 47243 /* 0xA6 */ 47244 undefined, 47245 /* 0xA7 */ 47246 undefined, 47247 /* 0xA8 */ 47248 undefined, 47249 /* 0xA9 */ 47250 undefined, 47251 /* 0xAA */ 47252 undefined, 47253 /* 0xAB */ 47254 undefined, 47255 /* 0xAC */ 47256 undefined, 47257 /* 0xAD */ 47258 undefined, 47259 /* 0xAE */ 47260 undefined, 47261 /* 0xAF */ 47262 undefined, 47263 /* 0xB0 */ 47264 PUSHB.bind(undefined, 1), 47265 /* 0xB1 */ 47266 PUSHB.bind(undefined, 2), 47267 /* 0xB2 */ 47268 PUSHB.bind(undefined, 3), 47269 /* 0xB3 */ 47270 PUSHB.bind(undefined, 4), 47271 /* 0xB4 */ 47272 PUSHB.bind(undefined, 5), 47273 /* 0xB5 */ 47274 PUSHB.bind(undefined, 6), 47275 /* 0xB6 */ 47276 PUSHB.bind(undefined, 7), 47277 /* 0xB7 */ 47278 PUSHB.bind(undefined, 8), 47279 /* 0xB8 */ 47280 PUSHW.bind(undefined, 1), 47281 /* 0xB9 */ 47282 PUSHW.bind(undefined, 2), 47283 /* 0xBA */ 47284 PUSHW.bind(undefined, 3), 47285 /* 0xBB */ 47286 PUSHW.bind(undefined, 4), 47287 /* 0xBC */ 47288 PUSHW.bind(undefined, 5), 47289 /* 0xBD */ 47290 PUSHW.bind(undefined, 6), 47291 /* 0xBE */ 47292 PUSHW.bind(undefined, 7), 47293 /* 0xBF */ 47294 PUSHW.bind(undefined, 8), 47295 /* 0xC0 */ 47296 MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 0), 47297 /* 0xC1 */ 47298 MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 1), 47299 /* 0xC2 */ 47300 MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 2), 47301 /* 0xC3 */ 47302 MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 3), 47303 /* 0xC4 */ 47304 MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 0), 47305 /* 0xC5 */ 47306 MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 1), 47307 /* 0xC6 */ 47308 MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 2), 47309 /* 0xC7 */ 47310 MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 3), 47311 /* 0xC8 */ 47312 MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 0), 47313 /* 0xC9 */ 47314 MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 1), 47315 /* 0xCA */ 47316 MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 2), 47317 /* 0xCB */ 47318 MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 3), 47319 /* 0xCC */ 47320 MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 0), 47321 /* 0xCD */ 47322 MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 1), 47323 /* 0xCE */ 47324 MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 2), 47325 /* 0xCF */ 47326 MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 3), 47327 /* 0xD0 */ 47328 MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 0), 47329 /* 0xD1 */ 47330 MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 1), 47331 /* 0xD2 */ 47332 MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 2), 47333 /* 0xD3 */ 47334 MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 3), 47335 /* 0xD4 */ 47336 MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 0), 47337 /* 0xD5 */ 47338 MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 1), 47339 /* 0xD6 */ 47340 MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 2), 47341 /* 0xD7 */ 47342 MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 3), 47343 /* 0xD8 */ 47344 MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 0), 47345 /* 0xD9 */ 47346 MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 1), 47347 /* 0xDA */ 47348 MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 2), 47349 /* 0xDB */ 47350 MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 3), 47351 /* 0xDC */ 47352 MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 0), 47353 /* 0xDD */ 47354 MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 1), 47355 /* 0xDE */ 47356 MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 2), 47357 /* 0xDF */ 47358 MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 3), 47359 /* 0xE0 */ 47360 MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 0), 47361 /* 0xE1 */ 47362 MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 1), 47363 /* 0xE2 */ 47364 MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 2), 47365 /* 0xE3 */ 47366 MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 3), 47367 /* 0xE4 */ 47368 MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 0), 47369 /* 0xE5 */ 47370 MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 1), 47371 /* 0xE6 */ 47372 MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 2), 47373 /* 0xE7 */ 47374 MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 3), 47375 /* 0xE8 */ 47376 MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 0), 47377 /* 0xE9 */ 47378 MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 1), 47379 /* 0xEA */ 47380 MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 2), 47381 /* 0xEB */ 47382 MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 3), 47383 /* 0xEC */ 47384 MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 0), 47385 /* 0xED */ 47386 MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 1), 47387 /* 0xEE */ 47388 MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 2), 47389 /* 0xEF */ 47390 MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 3), 47391 /* 0xF0 */ 47392 MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 0), 47393 /* 0xF1 */ 47394 MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 1), 47395 /* 0xF2 */ 47396 MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 2), 47397 /* 0xF3 */ 47398 MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 3), 47399 /* 0xF4 */ 47400 MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 0), 47401 /* 0xF5 */ 47402 MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 1), 47403 /* 0xF6 */ 47404 MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 2), 47405 /* 0xF7 */ 47406 MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 3), 47407 /* 0xF8 */ 47408 MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 0), 47409 /* 0xF9 */ 47410 MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 1), 47411 /* 0xFA */ 47412 MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 2), 47413 /* 0xFB */ 47414 MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 3), 47415 /* 0xFC */ 47416 MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 0), 47417 /* 0xFD */ 47418 MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 1), 47419 /* 0xFE */ 47420 MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 2), 47421 /* 0xFF */ 47422 MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 3) 47423 ]; 47424 /***************************** 47425 Mathematical Considerations 47426 ****************************** 47427 fv ... refers to freedom vector 47428 pv ... refers to projection vector 47429 rp ... refers to reference point 47430 p ... refers to to point being operated on 47431 d ... refers to distance 47432 SETRELATIVE: 47433 ============ 47434 case freedom vector == x-axis: 47435 ------------------------------ 47436 (pv) 47437 .-' 47438 rpd .-' 47439 .-* 47440 d .-'90°' 47441 .-' ' 47442 .-' ' 47443 *-' ' b 47444 rp ' 47445 ' 47446 ' 47447 p *----------*-------------- (fv) 47448 pm 47449 rpdx = rpx + d * pv.x 47450 rpdy = rpy + d * pv.y 47451 equation of line b 47452 y - rpdy = pvns * (x- rpdx) 47453 y = p.y 47454 x = rpdx + ( p.y - rpdy ) / pvns 47455 47456 case freedom vector == y-axis: 47457 ------------------------------ 47458 * pm 47459 |\ 47460 | \ 47461 | \ 47462 | \ 47463 | \ 47464 | \ 47465 | \ 47466 | \ 47467 | \ 47468 | \ b 47469 | \ 47470 | \ 47471 | \ .-' (pv) 47472 | 90° \.-' 47473 | .-'* rpd 47474 | .-' 47475 * *-' d 47476 p rp 47477 rpdx = rpx + d * pv.x 47478 rpdy = rpy + d * pv.y 47479 equation of line b: 47480 pvns ... normal slope to pv 47481 y - rpdy = pvns * (x -
47481 rpdx) 47482 x = p.x 47483 y = rpdy + pvns * (p.x - rpdx) 47484 47485 generic case: 47486 ------------- 47487 47488 .'(fv) 47489 .' 47490 .* pm 47491 .' ! 47492 .' . 47493 .' ! 47494 .' . b 47495 .' ! 47496 * . 47497 p ! 47498 90° . ... (pv) 47499 ...-*-''' 47500 ...---''' rpd 47501 ...---''' d 47502 *--''' 47503 rp 47504 rpdx = rpx + d * pv.x 47505 rpdy = rpy + d * pv.y 47506 equation of line b: 47507 pvns... normal slope to pv 47508 y - rpdy = pvns * (x - rpdx) 47509 equation of freedom vector line: 47510 fvs ... slope of freedom vector (=fy/fx) 47511 y - py = fvs * (x - px) 47512 47513 on pm both equations are true for same x/y 47514 y - rpdy = pvns * (x - rpdx) 47515 y - py = fvs * (x - px) 47516 form to y and set equal: 47517 pvns * (x - rpdx) + rpdy = fvs * (
47517x - px) + py 47518 expand: 47519 pvns * x - pvns * rpdx + rpdy = fvs * x - fvs * px + py 47520 switch: 47521 fvs * x - fvs * px + py = pvns * x - pvns * rpdx + rpdy 47522 solve for x: 47523 fvs * x - pvns * x = fvs * px - pvns * rpdx - py + rpdy 47524 47525 fvs * px - pvns * rpdx + rpdy - py 47526 x = ----------------------------------- 47527 fvs - pvns 47528 and: 47529 y = fvs * (x - px) + py 47530 47531 INTERPOLATE: 47532 ============ 47533 Examples of point interpolation. 47534 The weight of the movement of the reference point gets bigger 47535 the further the other reference point is away, thus the safest 47536 option (that is avoiding 0/0 divisions) is to weight the 47537 original distance of the other point by the sum of both distances. 47538 If the sum of both distances is 0, then move the point by the 47539 arithmetic average of the movement of both reference points. 47540 47541 47542 (+6) 47543 rp1o *---->*rp1 47544 . . (+12) 47545 . . rp2o *---------->* rp2 47546 . . . . 47547 . . . . 47548 . 10 20 . . 47549 |.........|...................| . 47550 . . . 47551 . . (+8) . 47552 po *------>*p . 47553 . . . 47554 . 12 . 24 . 47555 |...........|.......................| 47556 36 47557 47558 ------- 47559 47560 (+10) 47561 rp1o *-------->*rp1 47562 . . (-10) 47563 . . rp2 *<---------* rpo2 47564 . . . . 47565 . . . . 47566 . 10 . 30 . . 47567 |.........|.............................| 47568 . . 47569 . (+5) . 47570 po *--->* p . 47571 . . . 47572 . . 20 . 47573 |....|..............| 47574 5 15 47575 47576 ------- 47577 47578 (+10) 47579 rp1o *-------->*rp1 47580 . . 47581 . . 47582 rp2o *-------->*rp2 47583 47584 (+10) 47585 po *-------->* p 47586 ------- 47587 47588 (+10) 47589 rp1o *-------->*rp1 47590 . . 47591 . .(+30) 47592 rp2o *---------------------------->*rp2 47593 47594 (+25) 47595 po *----------------------->* p 47596 47597 vim: set ts=4 sw=4 expandtab: 47598 *****/ 47599 // The Font object 47600 // This code is based on Array.from implementation for strings in https://github.com/mathiasbynens/Array.from 47601 var arrayFromString = Array.from || function (s) { 47602 return s.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || [ 47603 ]; 47604 }; 47605 /** 47606 * @typedef FontOptions 47607 * @type Object 47608 * @property {Boolean} empty - whether to create a new empty font 47609 * @property {string} familyName 47610 * @property {string} styleName 47611 * @property {string=} fullName 47612 * @property {string=} postScriptName 47613 * @property {string=} designer 47614 * @property {string=} designerURL 47615 * @property {string=} manufacturer 47616 * @property {string=} manufacturerURL 47617 * @property {string=} license 47618 * @property {string=} licenseURL 47619 * @property {string=} version 47620 * @property {string=} description 47621 * @property {string=} copyright 47622 * @property {string=} trademark 47623 * @property {Number} unitsPerEm 47624 * @property {Number} ascender 47625 * @property {Number} descender 47626 * @property {Number} createdTimestamp 47627 * @property {string=} weightClass 47628 * @property {string=} widthClass 47629 * @property {string=} fsSelection 47630 */ 47631 /** 47632 * A Font represents a loaded OpenType font file. 47633 * It contains a set of glyphs and methods to draw text on a drawing context, 47634 * or to get a path representing the text. 47635 * @exports opentype.Font 47636 * @class 47637 * @param {FontOptions} 47638 * @constructor 47639 */ 47640 function Font(options) { 47641 options = options || { 47642 }; 47643 if (!options.empty) { 47644 // Check that we've provided the minimum set of names. 47645 checkArgument(options.familyName, 'When creating a new Font object, familyName is required.'); 47646 checkArgument(options.styleName, 'When creating a new Font object, styleName is required.'); 47647 checkArgument(options.unitsPerEm, 'When creating a new Font object, unitsPerEm is required.'); 47648 checkArgument(options.ascender, 'When creating a new Font object, ascender is required.'); 47649 checkArgument(options.descender, 'When creating a new Font object, descender is required.'); 47650 checkArgument(options.descender < 0, 'Descender should be negative (e.g. -512).'); // OS X will complain if the names are empty, so we put a single space everywhere by default. 47651 this.names = { 47652 fontFamily: {
47653 en: options.familyName || ' ' 47654 }, 47655 fontSubfamily: { 47656 en: options.styleName || ' ' 47657 }, 47658 fullName: { 47659 en: options.fullName || options.familyName + ' ' + options.styleName 47660 }, 47661 // postScriptName may not contain any whitespace 47662 postScriptName: { 47663 en: options.postScriptName || (options.familyName + options.styleName).replace(/\s/g, '') 47664 }, 47665 designer: { 47666 en: options.designer || ' ' 47667 }, 47668 designerURL: { 47669 en: options.designerURL || ' ' 47670 }, 47671 manufacturer: { 47672 en: options.manufacturer || ' ' 47673 }, 47674 manufacturerURL: { 47675 en: options.manufacturerURL || ' ' 47676 }, 47677 license: { 47678 en: options.license || ' ' 47679 }, 47680 licenseURL: { 47681 en: options.licenseURL || ' ' 47682 }, 47683 version: { 47684 en: options.version || 'Version 0.1' 47685 }, 47686 description: { 47687 en: options.description || ' ' 47688 }, 47689 copyright: { 47690 en: options.copyright || ' ' 47691 }, 47692 trademark: { 47693 en: options.trademark || ' ' 47694 } 47695 }; 47696 this.unitsPerEm = options.unitsPerEm || 1000; 47697 this.ascender = options.ascender; 47698 this.descender = options.descender; 47699 this.createdTimestamp = options.createdTimestamp; 47700 this.tables = { 47701 os2: { 47702 usWeightClass: options.weightClass || this.usWeightClasses.MEDIUM, 47703 usWidthClass: options.widthClass || this.usWidthClasses.MEDIUM, 47704 fsSelection: options.fsSelection || this.fsSelectionValues.REGULAR 47705 } 47706 }; 47707 } 47708 this.supported = true; // Deprecated: parseBuffer will throw an error if font is not supported. 47709 this.glyphs = new glyphset.GlyphSet(this, options.glyphs || [ 47710 ]); 47711 this.encoding = new DefaultEncoding(this); 47712 this.position = new Position(this); 47713 this.substitution = new Substitution(this); 47714 this.tables = this.tables || { 47715 }; 47716 Object.defineProperty(this, 'hinting', { 47717 get: function () { 47718 if (this._hinting) { 47719 return this._hinting; 47720 } 47721 if (this.outlinesFormat === 'truetype') { 47722 return this._hinting = new Hinting(this); 47723 } 47724 } 47725 }); 47726 } /** 47727 * Check if the font has a glyph for the given character. 47728 * @param {string} 47729 * @return {Boolean} 47730 */ 47731 47732 Font.prototype.hasChar = function (c) { 47733 return this.encoding.charToGlyphIndex(c) !== null; 47734 }; 47735 /** 47736 * Convert the given character to a single glyph index. 47737 * Note that this function assumes that there is a one-to-one mapping between 47738 * the given character and a glyph; for complex scripts this might not be the case. 47739 * @param {string} 47740 * @return {Number} 47741 */ 47742 Font.prototype.charToGlyphIndex = function (s) { 47743 return this.encoding.charToGlyphIndex(s); 47744 }; 47745 /** 47746 * Convert the given character to a single Glyph object. 47747 * Note that this function assumes that there is a one-to-one mapping between 47748 * the given character and a glyph; for complex scripts this might not be the case. 47749 * @param {string} 47750 * @return {opentype.Glyph} 47751 */ 47752 Font.prototype.charToGlyph = function (c) { 47753 var glyphIndex = this.charToGlyphIndex(c); 47754 var glyph = this.glyphs.get(glyphIndex); 47755 if (!glyph) { 47756 // .notdef 47757 glyph = this.glyphs.get(0); 47758 } 47759 return glyph; 47760 }; 47761 /** 47762 * Convert the given text to a list of Glyph objects. 47763 * Note that there is no strict one-to-one mapping between characters and 47764 * glyphs, so the list of returned glyphs can be larger or smaller than the 47765 * length of the given string. 47766 * @param {string} 47767 * @param {GlyphRenderOptions} [options] 47768 * @return {opentype.Glyph[]} 47769 */ 47770 Font.prototype.stringToGlyphs = function (s, options) { 47771 var this$1 = this; 47772 options = options || this.defaultRenderOptions; // Get glyph indexes 47773 var chars = arrayFromString(s); 47774 var indexes = [ 47775 ]; 47776 for (var i = 0; i < chars.length; i += 1) { 47777 var c = chars[i]; 47778 indexes.push(this$1.charToGlyphIndex(c)); 47779 } 47780 var length = indexes.length; // Apply substitutions on glyph indexes 47781 if (options.features) { 47782 var script = options.script || this.substitution.getDefaultScriptName(); 47783 var manyToOne = [ 47784 ]; 47785 if (options.features.liga) { 47786 manyToOne = manyToOne.concat(this.substitution.getFeature('liga', script, options.language)); 47787 } 47788 if (options.features.rlig) { 47789 manyToOne = manyToOne.concat(this.substitution.getFeature('rlig', script, options.language)); 47790 } 47791 for (var i$1 = 0; i$1 < length; i$1 += 1) { 47792 for (var j = 0; j < manyToOne.length; j++) { 47793 var ligature = manyToOne[j]; 47794 var components = ligature.sub; 47795 var compCount = components.length; 47796 var k = 0; 47797 while (k < compCount && components[k] === indexes[i$1 + k]) { 47798 k++; 47799 } 47800 if (k === compCount) { 47801 indexes.splice(i$1, compCount, ligature.by); 47802 length = length - compCount + 1; 47803 } 47804 } 47805 } 47806 } // convert glyph indexes to glyph objects 47807 47808 var glyphs = new Array(length); 47809 var notdef = this.glyphs.get(0); 47810 for (var i$2 = 0; i$2 < length; i$2 += 1) { 47811 glyphs[i$2] = this$1.glyphs.get(indexes[i$2]) || notdef; 47812 } 47813 return glyphs; 47814 }; 47815 /** 47816 * @param {string} 47817 * @return {Number} 47818 */ 47819 Font.prototype.nameToGlyphIndex = function (name) { 47820 return this.glyphNames.nameToGlyphIndex(name); 47821 }; 47822 /** 47823 * @param {string} 47824 * @return {opentype.Glyph} 47825 */ 47826 Font.prototype.nameToGlyph = function (name) { 47827 var glyphIndex = this.nameToGlyphIndex(name); 47828 var glyph = this.glyphs.get(glyphIndex); 47829 if (!glyph) { 47830 // .notdef 47831 glyph = this.glyphs.get(0); 47832 } 47833 return glyph; 47834 }; 47835 /** 47836 * @param {Number} 47837 * @return {String} 47838 */ 47839 Font.prototype.glyphIndexToName = function (gid) { 47840 if (!this.glyphNames.glyphIndexToName) { 47841 return ''; 47842 } 47843 return this.glyphNames.glyphIndexToName(gid); 47844 }; 47845 /** 47846 * Retrieve the value of the kerning pair between the left glyph (or its index) 47847 * and the right glyph (or its index). If no kerning pair is found, return 0. 47848 * The kerning value gets added to the advance width when calculating the spacing 47849 * between glyphs. 47850 * For GPOS kerning, this method uses the default script and language, which covers 47851 * most use cases. To have greater control, use font.position.getKerningValue . 47852 * @param {opentype.Glyph} leftGlyph 47853 * @param {opentype.Glyph} rightGlyph 47854 * @return {Number} 47855 */ 47856 Font.prototype.getKerningValue = function (leftGlyph, rightGlyph) { 47857 leftGlyph = leftGlyph.index || leftGlyph; 47858 rightGlyph = rightGlyph.index || rightGlyph; 47859 var gposKerning = this.position.defaultKerningTables; 47860 if (gposKerning) { 47861 return this.position.getKerningValue(gposKerning, leftGlyph, rightGlyph); 47862 } // "kern" table 47863 47864 return this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0; 47865 }; 47866 /** 47867 * @typedef GlyphRenderOptions 47868 * @type Object 47869 * @property {string} [script] - script used to determine which features to apply. By default, 'DFLT' or 'latn' is used. 47870 * See https://www.microsoft.com/typography/otspec/scripttags.htm 47871 * @property {string} [language='dflt'] - language system used to determine which features to apply. 47872 * See https://www.microsoft.com/typography/developers/opentype/languagetags.aspx 47873 * @property {boolean} [kerning=true] - whether to include kerning values 47874 * @property {object} [features] - OpenType Layout feature tags. Used to enable or disable the features of the given script/language system. 47875 * See https://www.microsoft.com/typography/otspec/featuretags.htm 47876 */ 47877 Font.prototype.defaultRenderOptions = { 47878 kerning: true, 47879 features: { 47880 liga: true, 47881 rlig: true 47882 } 47883 }; 47884 /** 47885 * Helper function that invokes the given callback for each glyph in the given text. 47886 * The callback gets `(glyph, x, y, fontSize, options)`.* @param {string} text 47887 * @param {string} text - The text to apply. 47888 * @param {number} [x=0] - Horizontal position of the beginning of the text. 47889 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 47890 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 47891 * @param {GlyphRenderOptions=} options 47892 * @param {Function} callback 47893 */ 47894 Font.prototype.forEachGlyph = function (text, x, y, fontSize, options, callback) { 47895 var this$1 = this; 47896 x = x !== undefined ? x : 0; 47897 y = y !== undefined ? y : 0; 47898 fontSize = fontSize !== undefined ? fontSize : 72; 47899 options = options || this.defaultRenderOptions; 47900 var fontScale = 1 / this.unitsPerEm * fontSize; 47901 var glyphs = this.stringToGlyphs(text, options); 47902 var kerningLookups; 47903 if (options.kerning) { 47904 var script = options.script || this.position.getDefaultScriptName(); 47905 kerningLookups = this.position.getKerningTables(script, options.language); 47906 } 47907 for (var i = 0; i < glyphs.length; i += 1) { 47908 var glyph = glyphs[i]; 47909 callback.call(this$1, glyph, x, y, fontSize, options); 47910 if (glyph.advanceWidth) { 47911 x += glyph.advanceWidth * fontScale; 47912 } 47913 if (options.kerning && i < glyphs.length - 1) { 47914 // We should apply position adjustment lookups in a more generic way. 47915 // Here we only use the xAdvance value. 47916 var kerningValue = kerningLookups ? this$1.position.getKerningValue(kerningLookups, glyph.index, glyphs[i + 1].index) : this$1.getKerningValue(glyph, glyphs[i + 1]); 47917 x += kerningValue * fontScale; 47918 } 47919 if (options.letterSpacing) { 47920 x += options.letterSpacing * fontSize; 47921 } else if (options.tracking) { 47922 x += options.tracking / 1000 * fontSize; 47923 } 47924 } 47925 return x; 47926 }; 47927 /** 47928 * Create a Path object that represents the given text. 47929 * @param {string} text - The text to create. 47930 * @param {number} [x=0] - Horizontal position of the beginning of the text. 47931 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 47932 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 47933 * @param {GlyphRenderOptions=} options 47934 * @return {opentype.Path} 47935 */ 47936 Font.prototype.getPath = function (text, x, y, fontSize, options) { 47937 var fullPath = new Path(); 47938 this.forEachGlyph(text, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { 47939 var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this); 47940 fullPath.extend(glyphPath); 47941 }); 47942 return fullPath; 47943 }; 47944 /** 47945 * Create an array of Path objects that represent the glyphs of a given text. 47946 * @param {string} text - The text to create. 47947 * @param {number} [x=0] - Horizontal position of the beginning of the text. 47948 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 47949 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 47950 * @param {GlyphRenderOptions=} options 47951 * @return {opentype.Path[]} 47952 */ 47953 Font.prototype.getPaths = function (text, x, y, fontSize, options) { 47954 var glyphPaths = [ 47955 ]; 47956 this.forEachGlyph(text, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { 47957 var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this); 47958 glyphPaths.push(glyphPath); 47959 }); 47960 return glyphPaths; 47961 }; 47962 /** 47963 * Returns the advance width of a text. 47964 * 47965 * This is something different than Path.getBoundingBox() as for example a 47966 * suffixed whitespace increases the advanceWidth but not the bounding box 47967 * or an overhanging letter like a calligraphic 'f' might have a quite larger 47968 * bounding box than its advance width. 47969 * 47970 * This corresponds to canvas2dContext.measureText(text).width 47971 * 47972 * @param {string} text - The text to create. 47973 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 47974 * @param {GlyphRenderOptions=} options 47975 * @return advance width 47976 */ 47977 Font.prototype.getAdvanceWidth = function (text, fontSize, options) { 47978 return this.forEachGlyph(text, 0, 0, fontSize, options, function () { 47979 }); 47980 }; 47981 /** 47982 * Draw the text on the given drawing context.
47983 * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. 47984 * @param {string} text - The text to create. 47985 * @param {number} [x=0] - Horizontal position of the beginning of the text. 47986 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 47987 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 47988 * @param {GlyphRenderOptions=} options 47989 */ 47990 Font.prototype.draw = function (ctx, text, x, y, fontSize, options) { 47991 this.getPath(text, x, y, fontSize, options).draw(ctx); 47992 }; 47993 /** 47994 * Draw the points of all glyphs in the text. 47995 * On-curve points will be drawn in blue, off-curve points will be drawn in red. 47996 * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. 47997 * @param {string} text - The text to create. 47998 * @param {number} [x=0] - Horizontal position of the beginning of the text. 47999 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 48000 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 48001 * @param {GlyphRenderOptions=} options 48002 */ 48003 Font.prototype.drawPoints = function (ctx, text, x, y, fontSize, options) { 48004 this.forEachGlyph(text, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { 48005 glyph.drawPoints(ctx, gX, gY, gFontSize); 48006 }); 48007 }; 48008 /** 48009 * Draw lines indicating important font measurements for all glyphs in the text. 48010 * Black lines indicate the origin of the coordinate system (point 0,0). 48011 * Blue lines indicate the glyph bounding box. 48012 * Green line indicates the advance width of the glyph. 48013 * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. 48014 * @param {string} text - The text to create. 48015 * @param {number} [x=0] - Horizontal position of the beginning of the text. 48016 * @param {number} [y=0] - Vertical position of the *baseline* of the text. 48017 * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. 48018 * @param {GlyphRenderOptions=} options 48019 */ 48020 Font.prototype.drawMetrics = function (ctx, text, x, y, fontSize, options) { 48021 this.forEachGlyph(text, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { 48022 glyph.drawMetrics(ctx, gX, gY, gFontSize); 48023 }); 48024 }; 48025 /** 48026 * @param {string} 48027 * @return {string} 48028 */ 48029 Font.prototype.getEnglishName = function (name) { 48030 var translations = this.names[name]; 48031 if (translations) { 48032 return translations.en; 48033 } 48034 }; 48035 /** 48036 * Validate 48037 */ 48038 Font.prototype.validate = function () { 48039 var _this = this; 48040 function assert(predicate, message) { 48041 } 48042 function assertNamePresent(name) { 48043 var englishName = _this.getEnglishName(name); 48044 assert(englishName && englishName.trim().length > 0, 'No English ' + name + ' specified.'); 48045 } // Identification information 48046 48047 assertNamePresent('fontFamily'); 48048 assertNamePresent('weightName'); 48049 assertNamePresent('manufacturer'); 48050 assertNamePresent('copyright'); 48051 assertNamePresent('version'); // Dimension information 48052 assert(this.unitsPerEm > 0, 'No unitsPerEm specified.'); 48053 }; 48054 /** 48055 * Convert the font object to a SFNT data structure. 48056 * This structure contains all the necessary tables and metadata to create a binary OTF file. 48057 * @return {opentype.Table} 48058 */ 48059 Font.prototype.toTables = function () { 48060 return sfnt.fontToTable(this); 48061 }; 48062 /** 48063 * @deprecated Font.toBuffer is deprecated. Use Font.toArrayBuffer instead. 48064 */ 48065 Font.prototype.toBuffer = function () { 48066 console.warn('Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.'); 48067 return this.toArrayBuffer(); 48068 }; 48069 /** 48070 * Converts a `opentype.Font` into an `ArrayBuffer` 48071 * @return {ArrayBuffer} 48072 */ 48073 Font.prototype.toArrayBuffer = function () { 48074 var sfntTable = this.toTables(); 48075 var bytes = sfntTable.encode(); 48076 var buffer = new ArrayBuffer(bytes.length); 48077 var intArray = new Uint8Array(buffer); 48078 for (var i = 0; i < bytes.length; i++) { 48079 intArray[i] = bytes[i]; 48080 } 48081 return buffer; 48082 }; 48083 /** 48084 * Initiate a download of the OpenType font. 48085 */ 48086 Font.prototype.download = function (fileName) { 48087 var familyName = this.getEnglishName('fontFamily');
48088 var styleName = this.getEnglishName('fontSubfamily'); 48089 fileName = fileName || familyName.replace(/\s/g, '') + '-' + styleName + '.otf'; 48090 var arrayBuffer = this.toArrayBuffer(); 48091 if (isBrowser()) { 48092 window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 48093 window.requestFileSystem(window.TEMPORARY, arrayBuffer.byteLength, function (fs) { 48094 fs.root.getFile(fileName, { 48095 create: true 48096 }, function (fileEntry) { 48097 fileEntry.createWriter(function (writer) { 48098 var dataView = new DataView(arrayBuffer); 48099 var blob = new Blob([dataView], { 48100 type: 'font/opentype' 48101 }); 48102 writer.write(blob); 48103 writer.addEventListener('writeend', function () { 48104 // Navigating to the file will download it. 48105 location.href = fileEntry.toURL(); 48106 }, false); 48107 }); 48108 }); 48109 }, function (err) { 48110 throw new Error(err.name + ': ' + err.message); 48111 }); 48112 } else { 48113 var fs = _dereq_('fs'); 48114 var buffer = arrayBufferToNodeBuffer(arrayBuffer); 48115 fs.writeFileSync(fileName, buffer); 48116 } 48117 }; 48118 /** 48119 * @private 48120 */ 48121 Font.prototype.fsSelectionValues = { 48122 ITALIC: 1, 48123 //1 48124 UNDERSCORE: 2, 48125 //2 48126 NEGATIVE: 4, 48127 //4 48128 OUTLINED: 8, 48129 //8 48130 STRIKEOUT: 16, 48131 //16 48132 BOLD: 32, 48133 //32 48134 REGULAR: 64, 48135 //64 48136 USER_TYPO_METRICS: 128, 48137 //128 48138 WWS: 256, 48139 //256 48140 OBLIQUE: 512 //512 48141 }; 48142 /** 48143 * @private 48144 */ 48145 Font.prototype.usWidthClasses = { 48146 ULTRA_CONDENSED: 1, 48147 EXTRA_CONDENSED: 2, 48148 CONDENSED: 3, 48149 SEMI_CONDENSED: 4, 48150 MEDIUM: 5, 48151 SEMI_EXPANDED: 6, 48152 EXPANDED: 7, 48153 EXTRA_EXPANDED: 8, 48154 ULTRA_EXPANDED: 9 48155 }; 48156 /** 48157 * @private 48158 */ 48159 Font.prototype.usWeightClasses = { 48160 THIN: 100, 48161 EXTRA_LIGHT: 200, 48162 LIGHT: 300, 48163 NORMAL: 400, 48164 MEDIUM: 500, 48165 SEMI_BOLD: 600, 48166 BOLD: 700, 48167 EXTRA_BOLD: 800, 48168 BLACK: 900 48169 }; // The `fvar` table stores font variation axes and instances. 48170 function addName(name, names) { 48171 var nameString = JSON.stringify(name); 48172 var nameID = 256; 48173 for (var nameKey in names) { 48174 var n = parseInt(nameKey); 48175 if (!n || n < 256) { 48176 continue; 48177 } 48178 if (JSON.stringify(names[nameKey]) === nameString) { 48179 return n; 48180 } 48181 if (nameID <= n) { 48182 nameID = n + 1; 48183 } 48184 } 48185 names[nameID] = name; 48186 return nameID; 48187 } 48188 function makeFvarAxis(n, axis, names) { 48189 var nameID = addName(axis.name, names); 48190 return [{ 48191 name: 'tag_' + n, 48192 type: 'TAG', 48193 value: axis.tag 48194 }, 48195 { 48196 name: 'minValue_' + n, 48197 type: 'FIXED', 48198 value: axis.minValue << 16 48199 }, 48200 { 48201 name: 'defaultValue_' + n, 48202 type: 'FIXED', 48203 value: axis.defaultValue << 16 48204 }, 48205 { 48206 name: 'maxValue_' + n, 48207 type: 'FIXED', 48208 value: axis.maxValue << 16 48209 }, 48210 { 48211 name: 'flags_' + n, 48212 type: 'USHORT', 48213 value: 0 48214 }, 48215 { 48216 name: 'nameID_' + n, 48217 type: 'USHORT', 48218 value: nameID 48219 } 48220 ]; 48221 } 48222 function parseFvarAxis(data, start, names) { 48223 var axis = { 48224 }; 48225 var p = new parse.Parser(data, start); 48226 axis.tag = p.parseTag(); 48227 axis.minValue = p.parseFixed(); 48228 axis.defaultValue = p.parseFixed(); 48229 axis.maxValue = p.parseFixed();
48230 p.skip('uShort', 1); // reserved for flags; no values defined 48231 axis.name = names[p.parseUShort()] || { 48232 }; 48233 return axis; 48234 } 48235 function makeFvarInstance(n, inst, axes, names) { 48236 var nameID = addName(inst.name, names); 48237 var fields = [ 48238 { 48239 name: 'nameID_' + n, 48240 type: 'USHORT', 48241 value: nameID 48242 }, 48243 { 48244 name: 'flags_' + n, 48245 type: 'USHORT', 48246 value: 0 48247 } 48248 ]; 48249 for (var i = 0; i < axes.length; ++i) { 48250 var axisTag = axes[i].tag; 48251 fields.push({ 48252 name: 'axis_' + n + ' ' + axisTag, 48253 type: 'FIXED', 48254 value: inst.coordinates[axisTag] << 16 48255 }); 48256 } 48257 return fields; 48258 } 48259 function parseFvarInstance(data, start, axes, names) { 48260 var inst = { 48261 }; 48262 var p = new parse.Parser(data, start); 48263 inst.name = names[p.parseUShort()] || { 48264 };
48265 p.skip('uShort', 1); // reserved for flags; no values defined 48266 inst.coordinates = { 48267 }; 48268 for (var i = 0; i < axes.length; ++i) { 48269 inst.coordinates[axes[i].tag] = p.parseFixed(); 48270 } 48271 return inst; 48272 } 48273 function makeFvarTable(fvar, names) { 48274 var result = new table.Table('fvar', [ 48275 { 48276 name: 'version', 48277 type: 'ULONG', 48278 value: 65536 48279 }, 48280 { 48281 name: 'offsetToData', 48282 type: 'USHORT', 48283 value: 0 48284 }, 48285 { 48286 name: 'countSizePairs', 48287 type: 'USHORT', 48288 value: 2 48289 }, 48290 { 48291 name: 'axisCount', 48292 type: 'USHORT', 48293 value: fvar.axes.length 48294 }, 48295 { 48296 name: 'axisSize', 48297 type: 'USHORT', 48298 value: 20 48299 }, 48300 { 48301 name: 'instanceCount', 48302 type: 'USHORT', 48303 value: fvar.instances.length 48304 }, 48305 { 48306 name: 'instanceSize', 48307 type: 'USHORT', 48308 value: 4 + fvar.axes.length * 4 48309 } 48310 ]); 48311 result.offsetToData = result.sizeOf(); 48312 for (var i = 0; i < fvar.axes.length; i++) { 48313 result.fields = result.fields.concat(makeFvarAxis(i, fvar.axes[i], names)); 48314 } 48315 for (var j = 0; j < fvar.instances.length; j++) { 48316 result.fields = result.fields.concat(makeFvarInstance(j, fvar.instances[j], fvar.axes, names)); 48317 } 48318 return result; 48319 } 48320 function parseFvarTable(data, start, names) { 48321 var p = new parse.Parser(data, start); 48322 var tableVersion = p.parseULong(); 48323 check.argument(tableVersion === 65536, 'Unsupported fvar table version.'); 48324 var offsetToData = p.parseOffset16(); // Skip countSizePairs.
vendor: 4,986 bytes, lines 48325-48434
48325 p.skip('uShort', 1); 48326 var axisCount = p.parseUShort(); 48327 var axisSize = p.parseUShort(); 48328 var instanceCount = p.parseUShort(); 48329 var instanceSize = p.parseUShort(); 48330 var axes = [ 48331 ]; 48332 for (var i = 0; i < axisCount; i++) { 48333 axes.push(parseFvarAxis(data, start + offsetToData + i * axisSize, names)); 48334 } 48335 var instances = [ 48336 ]; 48337 var instanceStart = start + offsetToData + axisCount * axisSize; 48338 for (var j = 0; j < instanceCount; j++) { 48339 instances.push(parseFvarInstance(data, instanceStart + j * instanceSize, axes, names)); 48340 } 48341 return { 48342 axes: axes, 48343 instances: instances 48344 }; 48345 } 48346 var fvar = { 48347 make: makeFvarTable, 48348 parse: parseFvarTable 48349 }; // The `GPOS` table contains kerning pairs, among other things. 48350 var subtableParsers$1 = new Array(10); // subtableParsers[0] is unused 48351 // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable 48352 // this = Parser instance 48353 subtableParsers$1[1] = function parseLookup1() { 48354 var start = this.offset + this.relativeOffset; 48355 var posformat = this.parseUShort(); 48356 if (posformat === 1) { 48357 return { 48358 posFormat: 1, 48359 coverage: this.parsePointer(Parser.coverage), 48360 value: this.parseValueRecord() 48361 }; 48362 } else if (posformat === 2) { 48363 return { 48364 posFormat: 2, 48365 coverage: this.parsePointer(Parser.coverage), 48366 values: this.parseValueRecordList() 48367 }; 48368 } 48369 check.assert(false, '0x' + start.toString(16) + ': GPOS lookup type 1 format must be 1 or 2.'); 48370 }; // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-2-pair-adjustment-positioning-subtable 48371 subtableParsers$1[2] = function parseLookup2() { 48372 var start = this.offset + this.relativeOffset; 48373 var posFormat = this.parseUShort(); 48374 check.assert(posFormat === 1 || posFormat === 2, '0x' + start.toString(16) + ': GPOS lookup type 2 format must be 1 or 2.'); 48375 var coverage = this.parsePointer(Parser.coverage); 48376 var valueFormat1 = this.parseUShort(); 48377 var valueFormat2 = this.parseUShort(); 48378 if (posFormat === 1) { 48379 // Adjustments for Glyph Pairs 48380 return { 48381 posFormat: posFormat, 48382 coverage: coverage, 48383 valueFormat1: valueFormat1, 48384 valueFormat2: valueFormat2, 48385 pairSets: this.parseList(Parser.pointer(Parser.list(function () { 48386 return { 48387 // pairValueRecord 48388 secondGlyph: this.parseUShort(), 48389 value1: this.parseValueRecord(valueFormat1), 48390 value2: this.parseValueRecord(valueFormat2) 48391 }; 48392 }))) 48393 }; 48394 } else if (posFormat === 2) { 48395 var classDef1 = this.parsePointer(Parser.classDef); 48396 var classDef2 = this.parsePointer(Parser.classDef); 48397 var class1Count = this.parseUShort(); 48398 var class2Count = this.parseUShort(); 48399 return { 48400 // Class Pair Adjustment 48401 posFormat: posFormat, 48402 coverage: coverage, 48403 valueFormat1: valueFormat1, 48404 valueFormat2: valueFormat2, 48405 classDef1: classDef1, 48406 classDef2: classDef2, 48407 class1Count: class1Count, 48408 class2Count: class2Count, 48409 classRecords: this.parseList(class1Count, Parser.list(class2Count, function () { 48410 return { 48411 value1: this.parseValueRecord(valueFormat1), 48412 value2: this.parseValueRecord(valueFormat2) 48413 }; 48414 })) 48415 }; 48416 } 48417 }; 48418 subtableParsers$1[3] = function parseLookup3() { 48419 return { 48420 error: 'GPOS Lookup 3 not supported' 48421 }; 48422 }; 48423 subtableParsers$1[4] = function parseLookup4() { 48424 return { 48425 error: 'GPOS Lookup 4 not supported' 48426 }; 48427 }; 48428 subtableParsers$1[5] = function parseLookup5() { 48429 return { 48430 error: 'GPOS Lookup 5 not supported' 48431 }; 48432 }; 48433 subtableParsers$1[6] = function parseLookup6() { 48434 return {
48435 error: 'GPOS Lookup 6 not supported' 48436 }; 48437 }; 48438 subtableParsers$1[7] = function parseLookup7() { 48439 return { 48440 error: 'GPOS Lookup 7 not supported' 48441 }; 48442 }; 48443 subtableParsers$1[8] = function parseLookup8() { 48444 return { 48445 error: 'GPOS Lookup 8 not supported' 48446 }; 48447 }; 48448 subtableParsers$1[9] = function parseLookup9() { 48449 return { 48450 error: 'GPOS Lookup 9 not supported' 48451 }; 48452 }; // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos 48453 function parseGposTable(data, start) { 48454 start = start || 0; 48455 var p = new Parser(data, start); 48456 var tableVersion = p.parseVersion(1); 48457 check.argument(tableVersion === 1 || tableVersion === 1.1, 'Unsupported GPOS table version ' + tableVersion); 48458 if (tableVersion === 1) { 48459 return { 48460 version: tableVersion, 48461 scripts: p.parseScriptList(), 48462 features: p.parseFeatureList(), 48463 lookups: p.parseLookupList(subtableParsers$1) 48464 }; 48465 } else { 48466 return { 48467 version: tableVersion, 48468 scripts: p.parseScriptList(), 48469 features: p.parseFeatureList(), 48470 lookups: p.parseLookupList(subtableParsers$1), 48471 variations: p.parseFeatureVariationsList() 48472 }; 48473 } 48474 } // GPOS Writing ////////////////////////////////////////////// 48475 // NOT SUPPORTED 48476 48477 var subtableMakers$1 = new Array(10); 48478 function makeGposTable(gpos) { 48479 return new table.Table('GPOS', [ 48480 { 48481 name: 'version', 48482 type: 'ULONG', 48483 value: 65536 48484 }, 48485 { 48486 name: 'scripts', 48487 type: 'TABLE', 48488 value: new table.ScriptList(gpos.scripts) 48489 }, 48490 { 48491 name: 'features', 48492 type: 'TABLE', 48493 value: new table.FeatureList(gpos.features) 48494 }, 48495 { 48496 name: 'lookups', 48497 type: 'TABLE', 48498 value: new table.LookupList(gpos.lookups, subtableMakers$1) 48499 } 48500 ]); 48501 } 48502 var gpos = { 48503 parse: parseGposTable, 48504 make: makeGposTable 48505 }; // The `kern` table contains kerning pairs. 48506 function parseWindowsKernTable(p) { 48507 var pairs = { 48508 }; // Skip nTables. 48509 p.skip('uShort'); 48510 var subtableVersion = p.parseUShort(); 48511 check.argument(subtableVersion === 0, 'Unsupported kern sub-table version.'); // Skip subtableLength, subtableCoverage 48512 p.skip('uShort', 2); 48513 var nPairs = p.parseUShort(); // Skip searchRange, entrySelector, rangeShift. 48514 p.skip('uShort', 3); 48515 for (var i = 0; i < nPairs; i += 1) { 48516 var leftIndex = p.parseUShort(); 48517 var rightIndex = p.parseUShort(); 48518 var value = p.parseShort(); 48519 pairs[leftIndex + ',' + rightIndex] = value; 48520 } 48521 return pairs; 48522 } 48523 function parseMacKernTable(p) { 48524 var pairs = { 48525 }; // The Mac kern table stores the version as a fixed (32 bits) but we only loaded the first 16 bits. 48526 // Skip the rest. 48527 p.skip('uShort'); 48528 var nTables = p.parseULong(); //check.argument(nTables === 1, 'Only 1 subtable is supported (got ' + nTables + ').'); 48529 if (nTables > 1) { 48530 console.warn('Only the first kern subtable is supported.'); 48531 } 48532 p.skip('uLong'); 48533 var coverage = p.parseUShort(); 48534 var subtableVersion = coverage & 255; 48535 p.skip('uShort'); 48536 if (subtableVersion === 0) { 48537 var nPairs = p.parseUShort();
48537 // Skip searchRange, entrySelector, rangeShift. 48538 p.skip('uShort', 3); 48539 for (var i = 0; i < nPairs; i += 1) { 48540 var leftIndex = p.parseUShort(); 48541 var rightIndex = p.parseUShort(); 48542 var value = p.parseShort(); 48543 pairs[leftIndex + ',' + rightIndex] = value; 48544 } 48545 } 48546 return pairs; 48547 } // Parse the `kern` table which contains kerning pairs. 48548 48549 function parseKernTable(data, start) { 48550 var p = new parse.Parser(data, start); 48551 var tableVersion = p.parseUShort(); 48552 if (tableVersion === 0) { 48553 return parseWindowsKernTable(p); 48554 } else if (tableVersion === 1) { 48555 return parseMacKernTable(p); 48556 } else { 48557 throw new Error('Unsupported kern table version (' + tableVersion + ').'); 48558 } 48559 } 48560 var kern = { 48561 parse: parseKernTable 48562 }; // The `loca` table stores the offsets to the locations of the glyphs in the font. 48563 // Parse the `loca` table. This table stores the offsets to the locations of the glyphs in the font, 48564 // relative to the beginning of the glyphData table. 48565 // The number of glyphs stored in the `loca` table is specified in the `maxp` table (under numGlyphs) 48566 // The loca table has two versions: a short version where offsets are stored as uShorts, and a long 48567 // version where offsets are stored as uLongs. The `head` table specifies which version to use 48568 // (under indexToLocFormat). 48569 function parseLocaTable(data, start, numGlyphs, shortVersion) { 48570 var p = new parse.Parser(data, start); 48571 var parseFn = shortVersion ? p.parseUShort : p.parseULong; // There is an extra entry after the last index element to compute the length of the last glyph. 48572 // That's why we use numGlyphs + 1. 48573 var glyphOffsets = [ 48574 ]; 48575 for (var i = 0; i < numGlyphs + 1; i += 1) { 48576 var glyphOffset = parseFn.call(p); 48577 if (shortVersion) { 48578 // The short table version stores the actual offset divided by 2. 48579 glyphOffset *= 2; 48580 } 48581 glyphOffsets.push(glyphOffset); 48582 } 48583 return glyphOffsets; 48584 } 48585 var loca = { 48586 parse: parseLocaTable 48587 }; // opentype.js 48588 /** 48589 * The opentype library. 48590 * @namespace opentype 48591 */ 48592 // File loaders ///////////////////////////////////////////////////////// 48593 /** 48594 * Loads a font from a file. The callback throws an error message as the first parameter if it fails 48595 * and the font as an ArrayBuffer in the second parameter if it succeeds. 48596 * @param {string} path - The path of the file 48597 * @param {Function} callback - The function to call when the font load completes 48598 */ 48599 function loadFromFile(path, callback) { 48600 var fs = _dereq_('fs'); 48601 fs.readFile(path, function (err, buffer) { 48602 if (err) { 48603 return callback(err.message); 48604 } 48605 callback(null, nodeBufferToArrayBuffer(buffer)); 48606 }); 48607 } /** 48608 * Loads a font from a URL. The callback throws an error message as the first parameter if it fails 48609 * and the font as an ArrayBuffer in the second parameter if it succeeds. 48610 * @param {string} url - The URL of the font file. 48611 * @param {Function} callback - The function to call when the font load completes 48612 */ 48613 48614 function loadFromUrl(url, callback) { 48615 var request = new XMLHttpRequest(); 48616 request.open('get', url, true); 48617 request.responseType = 'arraybuffer'; 48618 request.onload = function () { 48619 if (request.response) { 48620 return callback(null, request.response); 48621 } else { 48622 return callback('Font could not be loaded: ' + request.statusText); 48623 } 48624 }; 48625 request.onerror = function () { 48626 callback('Font could not be loaded'); 48627 }; 48628 request.send(); 48629 } // Table Directory Entries ////////////////////////////////////////////// 48630 /**
vendor: 10,186 bytes, lines 48631-48866
48631 * Parses OpenType table entries. 48632 * @param {DataView} 48633 * @param {Number} 48634 * @return {Object[]} 48635 */ 48636 48637 function parseOpenTypeTableEntries(data, numTables) { 48638 var tableEntries = [ 48639 ]; 48640 var p = 12; 48641 for (var i = 0; i < numTables; i += 1) { 48642 var tag = parse.getTag(data, p); 48643 var checksum = parse.getULong(data, p + 4); 48644 var offset = parse.getULong(data, p + 8); 48645 var length = parse.getULong(data, p + 12); 48646 tableEntries.push({ 48647 tag: tag, 48648 checksum: checksum, 48649 offset: offset, 48650 length: length, 48651 compression: false 48652 }); 48653 p += 16; 48654 } 48655 return tableEntries; 48656 } /** 48657 * Parses WOFF table entries. 48658 * @param {DataView} 48659 * @param {Number} 48660 * @return {Object[]} 48661 */ 48662 48663 function parseWOFFTableEntries(data, numTables) { 48664 var tableEntries = [ 48665 ]; 48666 var p = 44; // offset to the first table directory entry. 48667 for (var i = 0; i < numTables; i += 1) { 48668 var tag = parse.getTag(data, p); 48669 var offset = parse.getULong(data, p + 4); 48670 var compLength = parse.getULong(data, p + 8); 48671 var origLength = parse.getULong(data, p + 12); 48672 var compression = void 0; 48673 if (compLength < origLength) { 48674 compression = 'WOFF'; 48675 } else { 48676 compression = false; 48677 } 48678 tableEntries.push({ 48679 tag: tag, 48680 offset: offset, 48681 compression: compression, 48682 compressedLength: compLength, 48683 length: origLength 48684 }); 48685 p += 20; 48686 } 48687 return tableEntries; 48688 } /** 48689 * @typedef TableData 48690 * @type Object 48691 * @property {DataView} data - The DataView 48692 * @property {number} offset - The data offset. 48693 */ 48694 /** 48695 * @param {DataView} 48696 * @param {Object} 48697 * @return {TableData} 48698 */ 48699 48700 function uncompressTable(data, tableEntry) { 48701 if (tableEntry.compression === 'WOFF') { 48702 var inBuffer = new Uint8Array(data.buffer, tableEntry.offset + 2, tableEntry.compressedLength - 2); 48703 var outBuffer = new Uint8Array(tableEntry.length); 48704 tinyInflate(inBuffer, outBuffer); 48705 if (outBuffer.byteLength !== tableEntry.length) { 48706 throw new Error('Decompression error: ' + tableEntry.tag + ' decompressed length doesn\'t match recorded length'); 48707 } 48708 var view = new DataView(outBuffer.buffer, 0); 48709 return { 48710 data: view, 48711 offset: 0 48712 }; 48713 } else { 48714 return { 48715 data: data, 48716 offset: tableEntry.offset 48717 }; 48718 } 48719 } // Public API /////////////////////////////////////////////////////////// 48720 /** 48721 * Parse the OpenType file data (as an ArrayBuffer) and return a Font object. 48722 * Throws an error if the font could not be parsed. 48723 * @param {ArrayBuffer} 48724 * @return {opentype.Font} 48725 */ 48726 48727 function parseBuffer(buffer) { 48728 var indexToLocFormat; 48729 var ltagTable; // Since the constructor can also be called to create new fonts from scratch, we indicate this 48730 // should be an empty font that we'll fill with our own data. 48731 var font = new Font({ 48732 empty: true 48733 }); // OpenType fonts use big endian byte ordering. 48734 // We can't rely on typed array view types, because they operate with the endianness of the host computer. 48735 // Instead we use DataViews where we can specify endianness. 48736 var data = new DataView(buffer, 0); 48737 var numTables; 48738 var tableEntries = [ 48739 ]; 48740 var signature = parse.getTag(data, 0); 48741 if (signature === String.fromCharCode(0, 1, 0, 0) || signature === 'true' || signature === 'typ1') { 48742 font.outlinesFormat = 'truetype'; 48743 numTables = parse.getUShort(data, 4); 48744 tableEntries = parseOpenTypeTableEntries(data, numTables); 48745 } else if (signature === 'OTTO') { 48746 font.outlinesFormat = 'cff'; 48747 numTables = parse.getUShort(data, 4); 48748 tableEntries = parseOpenTypeTableEntries(data, numTables); 48749 } else if (signature === 'wOFF') { 48750 var flavor = parse.getTag(data, 4); 48751 if (flavor === String.fromCharCode(0, 1, 0, 0)) { 48752 font.outlinesFormat = 'truetype'; 48753 } else if (flavor === 'OTTO') { 48754 font.outlinesFormat = 'cff'; 48755 } else { 48756 throw new Error('Unsupported OpenType flavor ' + signature); 48757 } 48758 numTables = parse.getUShort(data, 12); 48759 tableEntries = parseWOFFTableEntries(data, numTables); 48760 } else { 48761 throw new Error('Unsupported OpenType signature ' + signature); 48762 } 48763 var cffTableEntry; 48764 var fvarTableEntry; 48765 var glyfTableEntry; 48766 var gposTableEntry; 48767 var gsubTableEntry; 48768 var hmtxTableEntry; 48769 var kernTableEntry; 48770 var locaTableEntry; 48771 var nameTableEntry; 48772 var metaTableEntry; 48773 var p; 48774 for (var i = 0; i < numTables; i += 1) { 48775 var tableEntry = tableEntries[i]; 48776 var table = void 0; 48777 switch (tableEntry.tag) { 48778 case 'cmap': 48779 table = uncompressTable(data, tableEntry); 48780 font.tables.cmap = cmap.parse(table.data, table.offset); 48781 font.encoding = new CmapEncoding(font.tables.cmap); 48782 break; 48783 case 'cvt ': 48784 table = uncompressTable(data, tableEntry); 48785 p = new parse.Parser(table.data, table.offset); 48786 font.tables.cvt = p.parseShortList(tableEntry.length / 2); 48787 break; 48788 case 'fvar': 48789 fvarTableEntry = tableEntry; 48790 break; 48791 case 'fpgm': 48792 table = uncompressTable(data, tableEntry); 48793 p = new parse.Parser(table.data, table.offset); 48794 font.tables.fpgm = p.parseByteList(tableEntry.length); 48795 break; 48796 case 'head': 48797 table = uncompressTable(data, tableEntry); 48798 font.tables.head = head.parse(table.data, table.offset); 48799 font.unitsPerEm = font.tables.head.unitsPerEm; 48800 indexToLocFormat = font.tables.head.indexToLocFormat; 48801 break; 48802 case 'hhea': 48803 table = uncompressTable(data, tableEntry); 48804 font.tables.hhea = hhea.parse(table.data, table.offset); 48805 font.ascender = font.tables.hhea.ascender; 48806 font.descender = font.tables.hhea.descender; 48807 font.numberOfHMetrics = font.tables.hhea.numberOfHMetrics; 48808 break; 48809 case 'hmtx': 48810 hmtxTableEntry = tableEntry; 48811 break; 48812 case 'ltag': 48813 table = uncompressTable(data, tableEntry); 48814 ltagTable = ltag.parse(table.data, table.offset); 48815 break; 48816 case 'maxp': 48817 table = uncompressTable(data, tableEntry); 48818 font.tables.maxp = maxp.parse(table.data, table.offset); 48819 font.numGlyphs = font.tables.maxp.numGlyphs; 48820 break; 48821 case 'name': 48822 nameTableEntry = tableEntry; 48823 break; 48824 case 'OS/2': 48825 table = uncompressTable(data, tableEntry); 48826 font.tables.os2 = os2.parse(table.data, table.offset); 48827 break; 48828 case 'post': 48829 table = uncompressTable(data, tableEntry); 48830 font.tables.post = post.parse(table.data, table.offset); 48831 font.glyphNames = new GlyphNames(font.tables.post); 48832 break; 48833 case 'prep': 48834 table = uncompressTable(data, tableEntry); 48835 p = new parse.Parser(table.data, table.offset); 48836 font.tables.prep = p.parseByteList(tableEntry.length); 48837 break; 48838 case 'glyf': 48839 glyfTableEntry = tableEntry; 48840 break; 48841 case 'loca': 48842 locaTableEntry = tableEntry; 48843 break; 48844 case 'CFF ': 48845 cffTableEntry = tableEntry; 48846 break; 48847 case 'kern': 48848 kernTableEntry = tableEntry; 48849 break; 48850 case 'GPOS': 48851 gposTableEntry = tableEntry; 48852 break; 48853 case 'GSUB': 48854 gsubTableEntry = tableEntry; 48855 break; 48856 case 'meta': 48857 metaTableEntry = tableEntry; 48858 break; 48859 } 48860 } 48861 var nameTable = uncompressTable(data, nameTableEntry); 48862 font.tables.name = _name.parse(nameTable.data, nameTable.offset, ltagTable); 48863 font.names = font.tables.name; 48864 if (glyfTableEntry && locaTableEntry) { 48865 var shortVersion = indexToLocFormat === 0; 48866 var locaTable = uncompressTable(data, locaTableEntry
48866); 48867 var locaOffsets = loca.parse(locaTable.data, locaTable.offset, font.numGlyphs, shortVersion); 48868 var glyfTable = uncompressTable(data, glyfTableEntry); 48869 font.glyphs = glyf.parse(glyfTable.data, glyfTable.offset, locaOffsets, font); 48870 } else if (cffTableEntry) { 48871 var cffTable = uncompressTable(data, cffTableEntry); 48872 cff.parse(cffTable.data, cffTable.offset, font); 48873 } else { 48874 throw new Error('Font doesn\'t contain TrueType or CFF outlines.'); 48875 } 48876 var hmtxTable = uncompressTable(data, hmtxTableEntry); 48877 hmtx.parse(hmtxTable.data, hmtxTable.offset, font.numberOfHMetrics, font.numGlyphs, font.glyphs); 48878 addGlyphNames(font); 48879 if (kernTableEntry) { 48880 var kernTable = uncompressTable(data, kernTableEntry); 48881 font.kerningPairs = kern.parse(kernTable.data, kernTable.offset); 48882 } else { 48883 font.kerningPairs = { 48884 }; 48885 } 48886 if (gposTableEntry) { 48887 var gposTable = uncompressTable(data, gposTableEntry); 48888 font.tables.gpos = gpos.parse(gposTable.data, gposTable.offset); 48889 font.position.init(); 48890 } 48891 if (gsubTableEntry) { 48892 var gsubTable = uncompressTable(data, gsubTableEntry); 48893 font.tables.gsub = gsub.parse(gsubTable.data, gsubTable.offset); 48894 } 48895 if (fvarTableEntry) { 48896 var fvarTable = uncompressTable(data, fvarTableEntry); 48897 font.tables.fvar = fvar.parse(fvarTable.data, fvarTable.offset, font.names); 48898 } 48899 if (metaTableEntry) { 48900 var metaTable = uncompressTable(data, metaTableEntry); 48901 font.tables.meta = meta.parse(metaTable.data, metaTable.offset); 48902 font.metas = font.tables.meta; 48903 } 48904 return font; 48905 } /** 48906 * Asynchronously load the font from a URL or a filesystem. When done, call the callback 48907 * with two arguments `(err, font)`. The `err` will be null on success, 48908 * the `font` is a Font object. 48909 * We use the node.js callback convention so that 48910 * opentype.js can integrate with frameworks like async.js. 48911 * @alias opentype.load 48912 * @param {string} url - The URL of the font to load. 48913 * @param {Function} callback - The callback. 48914 */ 48915 48916 function load(url, callback) { 48917 var isNode$$1 = typeof window === 'undefined'; 48918 var loadFn = isNode$$1 ? loadFromFile : loadFromUrl; 48919 loadFn(url, function (err, arrayBuffer) { 48920 if (err) { 48921 return callback(err); 48922 } 48923 var font; 48924 try { 48925 font = parseBuffer(arrayBuffer); 48926 } catch (e) { 48927 return callback(e, null); 48928 } 48929 return callback(null, font); 48930 }); 48931 } /** 48932 * Synchronously load the font from a URL or file. 48933 * When done, returns the font object or throws an error. 48934 * @alias opentype.loadSync 48935 * @param {string} url - The URL of the font to load. 48936 * @return {opentype.Font} 48937 */ 48938 48939 function loadSync(url) { 48940 var fs = _dereq_('fs'); 48941 var buffer = fs.readFileSync(url); 48942 return parseBuffer(nodeBufferToArrayBuffer(buffer)); 48943 } 48944 exports.Font = Font; 48945 exports.Glyph = Glyph; 48946 exports.Path = Path; 48947 exports.BoundingBox = BoundingBox; 48948 exports._parse = parse; 48949 exports.parse = parseBuffer; 48950 exports.load = load; 48951 exports.loadSync = loadSync; 48952 Object.defineProperty(exports, '__esModule', { 48953 value: true 48954 }); 48955 }); 48956 }).call(this, _dereq_('buffer').Buffer) 48957 }, 48958 { 48959 'buffer': 22, 48960 'fs': 21 48961 } 48962 ], 48963 264: [
vendor: 5,455 bytes, lines 48964-49078
48964 function (_dereq_, module, exports) { 48965 (function (process) { 48966 // .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1, 48967 // backported and transplited with Babel, with backwards-compat fixes 48968 // Copyright Joyent, Inc. and other Node contributors. 48969 // 48970 // Permission is hereby granted, free of charge, to any person obtaining a 48971 // copy of this software and associated documentation files (the 48972 // "Software"), to deal in the Software without restriction, including 48973 // without limitation the rights to use, copy, modify, merge, publish, 48974 // distribute, sublicense, and/or sell copies of the Software, and to permit 48975 // persons to whom the Software is furnished to do so, subject to the 48976 // following conditions: 48977 // 48978 // The above copyright notice and this permission notice shall be included 48979 // in all copies or substantial portions of the Software. 48980 // 48981 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 48982 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 48983 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 48984 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 48985 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 48986 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 48987 // USE OR OTHER DEALINGS IN THE SOFTWARE. 48988 // resolves . and .. elements in a path array with directory names there 48989 // must be no slashes, empty elements, or device names (c:\) in the array 48990 // (so also no leading and trailing slashes - it does not distinguish 48991 // relative and absolute paths) 48992 function normalizeArray(parts, allowAboveRoot) { 48993 // if the path tries to go above the root, `up` ends up > 0 48994 var up = 0; 48995 for (var i = parts.length - 1; i >= 0; i--) { 48996 var last = parts[i]; 48997 if (last === '.') { 48998 parts.splice(i, 1); 48999 } else if (last === '..') { 49000 parts.splice(i, 1); 49001 up++; 49002 } else if (up) { 49003 parts.splice(i, 1); 49004 up--; 49005 } 49006 } // if the path is allowed to go above the root, restore leading ..s 49007 49008 if (allowAboveRoot) { 49009 for (; up--; up) { 49010 parts.unshift('..'); 49011 } 49012 } 49013 return parts; 49014 } // path.resolve([from ...], to) 49015 // posix version 49016 49017 exports.resolve = function () { 49018 var resolvedPath = '', 49019 resolvedAbsolute = false; 49020 for (var i = arguments.length - 1; i >= - 1 && !resolvedAbsolute; i--) { 49021 var path = i >= 0 ? arguments[i] : process.cwd(); // Skip empty and invalid entries 49022 if (typeof path !== 'string') { 49023 throw new TypeError('Arguments to path.resolve must be strings'); 49024 } else if (!path) { 49025 continue; 49026 } 49027 resolvedPath = path + '/' + resolvedPath; 49028 resolvedAbsolute = path.charAt(0) === '/'; 49029 } // At this point the path should be resolved to a full absolute path, but 49030 // handle relative paths to be safe (might happen when process.cwd() fails) 49031 // Normalize the path 49032 49033 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function (p) { 49034 return !!p; 49035 }), !resolvedAbsolute).join('/'); 49036 return (resolvedAbsolute ? '/' : '') + resolvedPath || '.'; 49037 }; // path.normalize(path) 49038 // posix version 49039 exports.normalize = function (path) { 49040 var isAbsolute = exports.isAbsolute(path), 49041 trailingSlash = substr(path, - 1) === '/'; // Normalize the path 49042 path = normalizeArray(filter(path.split('/'), function (p) { 49043 return !!p; 49044 }), !isAbsolute).join('/'); 49045 if (!path && !isAbsolute) { 49046 path = '.'; 49047 } 49048 if (path && trailingSlash) { 49049 path += '/'; 49050 } 49051 return (isAbsolute ? '/' : '') + path; 49052 }; // posix version 49053 exports.isAbsolute = function (path) { 49054 return path.charAt(0) === '/'; 49055 }; // posix version 49056 exports.join = function () { 49057 var paths = Array.prototype.slice.call(arguments, 0); 49058 return exports.normalize(filter(paths, function (p, index) { 49059 if (typeof p !== 'string') { 49060 throw new TypeError('Arguments to path.join must be strings'); 49061 } 49062 return p; 49063 }).join('/')); 49064 }; // path.relative(from, to) 49065 // posix version 49066 exports.relative = function (from, to) { 49067 from = exports.resolve(from).substr(1); 49068 to = exports.resolve(to).substr(1); 49069 function trim(arr) { 49070 var start = 0; 49071 for (; start < arr.length; start++) { 49072 if (arr[start] !== '') break; 49073 } 49074 var end = arr.length - 1; 49075 for (; end >= 0; end--) { 49076 if (arr[end] !== '') break; 49077 } 49078 if (start > end) return [];
vendor: 4,254 bytes, lines 49079-49187
49079 return arr.slice(start, end - start + 1); 49080 } 49081 var fromParts = trim(from.split('/')); 49082 var toParts = trim(to.split('/')); 49083 var length = Math.min(fromParts.length, toParts.length); 49084 var samePartsLength = length; 49085 for (var i = 0; i < length; i++) { 49086 if (fromParts[i] !== toParts[i]) { 49087 samePartsLength = i; 49088 break; 49089 } 49090 } 49091 var outputParts = [ 49092 ]; 49093 for (var i = samePartsLength; i < fromParts.length; i++) { 49094 outputParts.push('..'); 49095 } 49096 outputParts = outputParts.concat(toParts.slice(samePartsLength)); 49097 return outputParts.join('/'); 49098 }; 49099 exports.sep = '/'; 49100 exports.delimiter = ':'; 49101 exports.dirname = function (path) { 49102 if (typeof path !== 'string') path = path + ''; 49103 if (path.length === 0) return '.'; 49104 var code = path.charCodeAt(0); 49105 var hasRoot = code === 47 /*/*/ 49106 ; 49107 var end = - 1; 49108 var matchedSlash = true; 49109 for (var i = path.length - 1; i >= 1; --i) { 49110 code = path.charCodeAt(i); 49111 if (code === 47 /*/*/ 49112 ) { 49113 if (!matchedSlash) { 49114 end = i; 49115 break; 49116 } 49117 } else { 49118 // We saw the first non-path separator 49119 matchedSlash = false; 49120 } 49121 } 49122 if (end === - 1) return hasRoot ? '/' : '.'; 49123 if (hasRoot && end === 1) { 49124 // return '//'; 49125 // Backwards-compat fix: 49126 return '/'; 49127 } 49128 return path.slice(0, end); 49129 }; 49130 function basename(path) { 49131 if (typeof path !== 'string') path = path + ''; 49132 var start = 0; 49133 var end = - 1; 49134 var matchedSlash = true; 49135 var i; 49136 for (i = path.length - 1; i >= 0; --i) { 49137 if (path.charCodeAt(i) === 47 /*/*/ 49138 ) { 49139 // If we reached a path separator that was not part of a set of path 49140 // separators at the end of the string, stop now 49141 if (!matchedSlash) { 49142 start = i + 1; 49143 break; 49144 } 49145 } else if (end === - 1) { 49146 // We saw the first non-path separator, mark this as the end of our 49147 // path component 49148 matchedSlash = false; 49149 end = i + 1; 49150 } 49151 } 49152 if (end === - 1) return ''; 49153 return path.slice(start, end); 49154 } // Uses a mixed approach for backwards-compatibility, as ext behavior changed 49155 // in new Node.js versions, so only basename() above is backported here 49156 49157 exports.basename = function (path, ext) { 49158 var f = basename(path); 49159 if (ext && f.substr( - 1 * ext.length) === ext) { 49160 f = f.substr(0, f.length - ext.length); 49161 } 49162 return f; 49163 }; 49164 exports.extname = function (path) { 49165 if (typeof path !== 'string') path = path + ''; 49166 var startDot = - 1; 49167 var startPart = 0; 49168 var end = - 1; 49169 var matchedSlash = true; // Track the state of characters (if any) we see before our first dot and 49170 // after any path separator we find 49171 var preDotState = 0; 49172 for (var i = path.length - 1; i >= 0; --i) { 49173 var code = path.charCodeAt(i); 49174 if (code === 47 /*/*/ 49175 ) { 49176 // If we reached a path separator that was not part of a set of path 49177 // separators at the end of the string, stop now 49178 if (!matchedSlash) { 49179 startPart = i + 1; 49180 break; 49181 } 49182 continue; 49183 } 49184 if (end === - 1) { 49185 // We saw the first non-path separator, mark this as the end of our 49186 // extension 49187 matchedSlash = false;
vendor: 5,450 bytes, lines 49188-49315
49188 end = i + 1; 49189 } 49190 if (code === 46 /*.*/ 49191 ) { 49192 // If this is our first dot, mark it as the start of our extension 49193 if (startDot === - 1) startDot = i; 49194 else if (preDotState !== 1) preDotState = 1; 49195 } else if (startDot !== - 1) { 49196 // We saw a non-dot and non-path separator before our dot, so we should 49197 // have a good chance at having a non-empty extension 49198 preDotState = - 1; 49199 } 49200 } 49201 if (startDot === - 1 || end === - 1 || // We saw a non-dot character immediately before the dot 49202 preDotState === 0 || // The (right-most) trimmed path component is exactly '..' 49203 preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { 49204 return ''; 49205 } 49206 return path.slice(startDot, end); 49207 }; 49208 function filter(xs, f) { 49209 if (xs.filter) return xs.filter(f); 49210 var res = [ 49211 ]; 49212 for (var i = 0; i < xs.length; i++) { 49213 if (f(xs[i], i, xs)) res.push(xs[i]); 49214 } 49215 return res; 49216 } // String.prototype.substr - negative index don't work in IE8 49217 49218 var substr = 'ab'.substr( - 1) === 'b' ? function (str, start, len) { 49219 return str.substr(start, len); 49220 } 49221 : function (str, start, len) { 49222 if (start < 0) start = str.length + start; 49223 return str.substr(start, len); 49224 }; 49225 }).call(this, _dereq_('_process')) 49226 }, 49227 { 49228 '_process': 265 49229 } 49230 ], 49231 265: [ 49232 function (_dereq_, module, exports) { 49233 // shim for using process in browser 49234 var process = module.exports = { 49235 }; // cached from whatever global is present so that test runners that stub it 49236 // don't break things. But we need to wrap it in a try catch in case it is 49237 // wrapped in strict mode code which doesn't define any globals. It's inside a 49238 // function because try/catches deoptimize in certain engines. 49239 var cachedSetTimeout; 49240 var cachedClearTimeout; 49241 function defaultSetTimout() { 49242 throw new Error('setTimeout has not been defined'); 49243 } 49244 function defaultClearTimeout() { 49245 throw new Error('clearTimeout has not been defined'); 49246 }(function () { 49247 try { 49248 if (typeof setTimeout === 'function') { 49249 cachedSetTimeout = setTimeout; 49250 } else { 49251 cachedSetTimeout = defaultSetTimout; 49252 } 49253 } catch (e) { 49254 cachedSetTimeout = defaultSetTimout; 49255 } 49256 try { 49257 if (typeof clearTimeout === 'function') { 49258 cachedClearTimeout = clearTimeout; 49259 } else { 49260 cachedClearTimeout = defaultClearTimeout; 49261 } 49262 } catch (e) { 49263 cachedClearTimeout = defaultClearTimeout; 49264 } 49265 }) (); 49266 function runTimeout(fun) { 49267 if (cachedSetTimeout === setTimeout) { 49268 //normal enviroments in sane situations 49269 return setTimeout(fun, 0); 49270 } // if setTimeout wasn't available but was latter defined 49271 49272 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { 49273 cachedSetTimeout = setTimeout; 49274 return setTimeout(fun, 0); 49275 } 49276 try { 49277 // when when somebody has screwed with setTimeout but no I.E. maddness 49278 return cachedSetTimeout(fun, 0); 49279 } catch (e) { 49280 try { 49281 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 49282 return cachedSetTimeout.call(null, fun, 0); 49283 } catch (e) { 49284 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error 49285 return cachedSetTimeout.call(this, fun, 0); 49286 } 49287 } 49288 } 49289 function runClearTimeout(marker) { 49290 if (cachedClearTimeout === clearTimeout) { 49291 //normal enviroments in sane situations 49292 return clearTimeout(marker); 49293 } // if clearTimeout wasn't available but was latter defined 49294 49295 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { 49296 cachedClearTimeout = clearTimeout; 49297 return clearTimeout(marker); 49298 } 49299 try { 49300 // when when somebody has screwed with setTimeout but no I.E. maddness 49301 return cachedClearTimeout(marker); 49302 } catch (e) { 49303 try { 49304 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 49305 return cachedClearTimeout.call(null, marker); 49306 } catch (e) { 49307 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. 49308 // Some versions of I.E. have different rules for clearTimeout vs setTimeout 49309 return cachedClearTimeout.call(this, marker); 49310 } 49311 } 49312 } 49313 var queue = [ 49314 ]; 49315 var draining = false;
vendor: 4,355 bytes, lines 49316-49442
49316 var currentQueue; 49317 var queueIndex = - 1; 49318 function cleanUpNextTick() { 49319 if (!draining || !currentQueue) { 49320 return; 49321 } 49322 draining = false; 49323 if (currentQueue.length) { 49324 queue = currentQueue.concat(queue); 49325 } else { 49326 queueIndex = - 1; 49327 } 49328 if (queue.length) { 49329 drainQueue(); 49330 } 49331 } 49332 function drainQueue() { 49333 if (draining) { 49334 return; 49335 } 49336 var timeout = runTimeout(cleanUpNextTick); 49337 draining = true; 49338 var len = queue.length; 49339 while (len) { 49340 currentQueue = queue; 49341 queue = [ 49342 ]; 49343 while (++queueIndex < len) { 49344 if (currentQueue) { 49345 currentQueue[queueIndex].run(); 49346 } 49347 } 49348 queueIndex = - 1; 49349 len = queue.length; 49350 } 49351 currentQueue = null; 49352 draining = false; 49353 runClearTimeout(timeout); 49354 } 49355 process.nextTick = function (fun) { 49356 var args = new Array(arguments.length - 1); 49357 if (arguments.length > 1) { 49358 for (var i = 1; i < arguments.length; i++) { 49359 args[i - 1] = arguments[i]; 49360 } 49361 } 49362 queue.push(new Item(fun, args)); 49363 if (queue.length === 1 && !draining) { 49364 runTimeout(drainQueue); 49365 } 49366 }; // v8 likes predictible objects 49367 function Item(fun, array) { 49368 this.fun = fun; 49369 this.array = array; 49370 } 49371 Item.prototype.run = function () { 49372 this.fun.apply(null, this.array); 49373 }; 49374 process.title = 'browser'; 49375 process.browser = true; 49376 process.env = { 49377 }; 49378 process.argv = [ 49379 ]; 49380 process.version = ''; // empty string to avoid regexp issues 49381 process.versions = { 49382 }; 49383 function noop() { 49384 } 49385 process.on = noop; 49386 process.addListener = noop; 49387 process.once = noop; 49388 process.off = noop; 49389 process.removeListener = noop; 49390 process.removeAllListeners = noop; 49391 process.emit = noop; 49392 process.prependListener = noop; 49393 process.prependOnceListener = noop; 49394 process.listeners = function (name) { 49395 return []; 49396 }; 49397 process.binding = function (name) { 49398 throw new Error('process.binding is not supported'); 49399 }; 49400 process.cwd = function () { 49401 return '/'; 49402 }; 49403 process.chdir = function (dir) { 49404 throw new Error('process.chdir is not supported'); 49405 }; 49406 process.umask = function () { 49407 return 0; 49408 }; 49409 }, 49410 { 49411 } 49412 ], 49413 266: [ 49414 function (_dereq_, module, exports) { 49415 /** 49416 * Copyright (c) 2014-present, Facebook, Inc. 49417 * 49418 * This source code is licensed under the MIT license found in the 49419 * LICENSE file in the root directory of this source tree. 49420 */ 49421 var runtime = function (exports) { 49422 'use strict'; 49423 var Op = Object.prototype; 49424 var hasOwn = Op.hasOwnProperty; 49425 var undefined; // More compressible than void 0. 49426 var $Symbol = typeof Symbol === 'function' ? Symbol : { 49427 }; 49428 var iteratorSymbol = $Symbol.iterator || '@@iterator'; 49429 var asyncIteratorSymbol = $Symbol.asyncIterator || '@@asyncIterator'; 49430 var toStringTagSymbol = $Symbol.toStringTag || '@@toStringTag'; 49431 function wrap(innerFn, outerFn, self, tryLocsList) { 49432 // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. 49433 var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; 49434 var generator = Object.create(protoGenerator.prototype); 49435 var context = new Context(tryLocsList || [ 49436 ]); // The ._invoke method unifies the implementations of the .next, 49437 // .throw, and .return methods. 49438 generator._invoke = makeInvokeMethod(innerFn, self, context); 49439 return generator; 49440 } 49441 exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion 49442 // record like context.tryEntries[i].completion. This interface could
vendor: 17,076 bytes, lines 49443-49790
49443 // have been (and was previously) designed to take a closure to be 49444 // invoked without arguments, but in all the cases we care about we 49445 // already have an existing method we want to call, so there's no need 49446 // to create a new function object. We can even get away with assuming 49447 // the method takes exactly one argument, since that happens to be true 49448 // in every case, so we don't have to touch the arguments object. The 49449 // only additional allocation required is the completion record, which 49450 // has a stable shape and so hopefully should be cheap to allocate. 49451 function tryCatch(fn, obj, arg) { 49452 try { 49453 return { 49454 type: 'normal', 49455 arg: fn.call(obj, arg) 49456 }; 49457 } catch (err) { 49458 return { 49459 type: 'throw', 49460 arg: err 49461 }; 49462 } 49463 } 49464 var GenStateSuspendedStart = 'suspendedStart'; 49465 var GenStateSuspendedYield = 'suspendedYield'; 49466 var GenStateExecuting = 'executing'; 49467 var GenStateCompleted = 'completed'; // Returning this object from the innerFn has the same effect as 49468 // breaking out of the dispatch switch statement. 49469 var ContinueSentinel = { 49470 }; // Dummy constructor functions that we use as the .constructor and 49471 // .constructor.prototype properties for functions that return Generator 49472 // objects. For full spec compliance, you may wish to configure your 49473 // minifier not to mangle the names of these two functions. 49474 function Generator() { 49475 } 49476 function GeneratorFunction() { 49477 } 49478 function GeneratorFunctionPrototype() { 49479 } // This is a polyfill for %IteratorPrototype% for environments that 49480 // don't natively support it. 49481 49482 var IteratorPrototype = { 49483 }; 49484 IteratorPrototype[iteratorSymbol] = function () { 49485 return this; 49486 }; 49487 var getProto = Object.getPrototypeOf; 49488 var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); 49489 if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { 49490 // This environment has a native %IteratorPrototype%; use it instead 49491 // of the polyfill. 49492 IteratorPrototype = NativeIteratorPrototype; 49493 } 49494 var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); 49495 GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; 49496 GeneratorFunctionPrototype.constructor = GeneratorFunction; 49497 GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = 'GeneratorFunction'; // Helper for defining the .next, .throw, and .return methods of the 49498 // Iterator interface in terms of a single ._invoke method. 49499 function defineIteratorMethods(prototype) { 49500 [ 49501 'next', 49502 'throw', 49503 'return' 49504 ].forEach(function (method) { 49505 prototype[method] = function (arg) { 49506 return this._invoke(method, arg); 49507 }; 49508 }); 49509 } 49510 exports.isGeneratorFunction = function (genFun) { 49511 var ctor = typeof genFun === 'function' && genFun.constructor; 49512 return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can 49513 // do is to check its .name property. 49514 (ctor.displayName || ctor.name) === 'GeneratorFunction' : false; 49515 }; 49516 exports.mark = function (genFun) { 49517 if (Object.setPrototypeOf) { 49518 Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); 49519 } else { 49520 genFun.__proto__ = GeneratorFunctionPrototype; 49521 if (!(toStringTagSymbol in genFun)) { 49522 genFun[toStringTagSymbol] = 'GeneratorFunction'; 49523 } 49524 } 49525 genFun.prototype = Object.create(Gp); 49526 return genFun; 49527 }; // Within the body of any async function, `await x` is transformed to 49528 // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test 49529 // `hasOwn.call(value, "__await")` to determine if the yielded value is 49530 // meant to be awaited. 49531 exports.awrap = function (arg) { 49532 return { 49533 __await: arg 49534 }; 49535 }; 49536 function AsyncIterator(generator) { 49537 function invoke(method, arg, resolve, reject) { 49538 var record = tryCatch(generator[method], generator, arg); 49539 if (record.type === 'throw') { 49540 reject(record.arg); 49541 } else { 49542 var result = record.arg; 49543 var value = result.value; 49544 if (value && typeof value === 'object' && hasOwn.call(value, '__await')) { 49545 return Promise.resolve(value.__await).then(function (value) { 49546 invoke('next', value, resolve, reject); 49547 }, function (err) { 49548 invoke('throw', err, resolve, reject); 49549 }); 49550 } 49551 return Promise.resolve(value).then(function (unwrapped) { 49552 // When a yielded Promise is resolved, its final value becomes 49553 // the .value of the Promise<{value,done}> result for the 49554 // current iteration. 49555 result.value = unwrapped; 49556 resolve(result); 49557 }, function (error) { 49558 // If a rejected Promise was yielded, throw the rejection back 49559 // into the async generator function so it can be handled there. 49560 return invoke('throw', error, resolve, reject); 49561 }); 49562 } 49563 } 49564 var previousPromise; 49565 function enqueue(method, arg) { 49566 function callInvokeWithMethodAndArg() { 49567 return new Promise(function (resolve, reject) { 49568 invoke(method, arg, resolve, reject); 49569 }); 49570 } 49571 return previousPromise = // If enqueue has been called before, then we want to wait until 49572 // all previous Promises have been resolved before calling invoke, 49573 // so that results are always delivered in the correct order. If 49574 // enqueue has not been called before, then it is important to 49575 // call invoke immediately, without waiting on a callback to fire, 49576 // so that the async generator function has the opportunity to do 49577 // any necessary setup in a predictable way. This predictability 49578 // is why the Promise constructor synchronously invokes its 49579 // executor callback, and why async functions synchronously 49580 // execute code before the first await. Since we implement simple 49581 // async functions in terms of async generators, it is especially 49582 // important to get this right, even though it requires care. 49583 previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later 49584 // invocations of the iterator. 49585 callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); 49586 } // Define the unified helper method that is used to implement .next, 49587 // .throw, and .return (see defineIteratorMethods). 49588 49589 this._invoke = enqueue; 49590 } 49591 defineIteratorMethods(AsyncIterator.prototype); 49592 AsyncIterator.prototype[asyncIteratorSymbol] = function () { 49593 return this; 49594 }; 49595 exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of 49596 // AsyncIterator objects; they just return a Promise for the value of 49597 // the final result produced by the iterator. 49598 exports.async = function (innerFn, outerFn, self, tryLocsList) { 49599 var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList)); 49600 return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator. 49601 : iter.next().then(function (result) { 49602 return result.done ? result.value : iter.next(); 49603 }); 49604 }; 49605 function makeInvokeMethod(innerFn, self, context) { 49606 var state = GenStateSuspendedStart; 49607 return function invoke(method, arg) { 49608 if (state === GenStateExecuting) { 49609 throw new Error('Generator is already running'); 49610 } 49611 if (state === GenStateCompleted) { 49612 if (method === 'throw') { 49613 throw arg; 49614 } // Be forgiving, per 25.3.3.3.3 of the spec: 49615 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume 49616 49617 return doneResult(); 49618 } 49619 context.method = method; 49620 context.arg = arg; 49621 while (true) { 49622 var delegate = context.delegate; 49623 if (delegate) { 49624 var delegateResult = maybeInvokeDelegate(delegate, context); 49625 if (delegateResult) { 49626 if (delegateResult === ContinueSentinel) continue; 49627 return delegateResult; 49628 } 49629 } 49630 if (context.method === 'next') { 49631 // Setting context._sent for legacy support of Babel's 49632 // function.sent implementation. 49633 context.sent = context._sent = context.arg; 49634 } else if (context.method === 'throw') { 49635 if (state === GenStateSuspendedStart) { 49636 state = GenStateCompleted; 49637 throw context.arg; 49638 } 49639 context.dispatchException(context.arg); 49640 } else if (context.method === 'return') { 49641 context.abrupt('return', context.arg); 49642 } 49643 state = GenStateExecuting; 49644 var record = tryCatch(innerFn, self, context); 49645 if (record.type === 'normal') { 49646 // If an exception is thrown from innerFn, we leave state === 49647 // GenStateExecuting and loop back for another invocation. 49648 state = context.done ? GenStateCompleted : GenStateSuspendedYield; 49649 if (record.arg === ContinueSentinel) { 49650 continue; 49651 } 49652 return { 49653 value: record.arg, 49654 done: context.done 49655 }; 49656 } else if (record.type === 'throw') { 49657 state = GenStateCompleted; // Dispatch the exception by looping back around to the 49658 // context.dispatchException(context.arg) call above. 49659 context.method = 'throw'; 49660 context.arg = record.arg; 49661 } 49662 } 49663 }; 49664 } // Call delegate.iterator[context.method](context.arg) and handle the 49665 // result, either by returning a { value, done } result from the 49666 // delegate iterator, or by modifying context.method and context.arg, 49667 // setting context.delegate to null, and returning the ContinueSentinel. 49668 49669 function maybeInvokeDelegate(delegate, context) { 49670 var method = delegate.iterator[context.method]; 49671 if (method === undefined) { 49672 // A .throw or .return when the delegate iterator has no .throw 49673 // method always terminates the yield* loop. 49674 context.delegate = null; 49675 if (context.method === 'throw') { 49676 // Note: ["return"] must be used for ES3 parsing compatibility. 49677 if (delegate.iterator['return']) { 49678 // If the delegate iterator has a return method, give it a 49679 // chance to clean up. 49680 context.method = 'return'; 49681 context.arg = undefined; 49682 maybeInvokeDelegate(delegate, context); 49683 if (context.method === 'throw') { 49684 // If maybeInvokeDelegate(context) changed context.method from 49685 // "return" to "throw", let that override the TypeError below. 49686 return ContinueSentinel; 49687 } 49688 } 49689 context.method = 'throw'; 49690 context.arg = new TypeError('The iterator does not provide a \'throw\' method'); 49691 } 49692 return ContinueSentinel; 49693 } 49694 var record = tryCatch(method, delegate.iterator, context.arg); 49695 if (record.type === 'throw') { 49696 context.method = 'throw'; 49697 context.arg = record.arg; 49698 context.delegate = null; 49699 return ContinueSentinel; 49700 } 49701 var info = record.arg; 49702 if (!info) { 49703 context.method = 'throw'; 49704 context.arg = new TypeError('iterator result is not an object'); 49705 context.delegate = null; 49706 return ContinueSentinel; 49707 } 49708 if (info.done) { 49709 // Assign the result of the finished delegate to the temporary 49710 // variable specified by delegate.resultName (see delegateYield). 49711 context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield). 49712 context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the 49713 // exception, let the outer generator proceed normally. If 49714 // context.method was "next", forget context.arg since it has been 49715 // "consumed" by the delegate iterator. If context.method was 49716 // "return", allow the original .return call to continue in the 49717 // outer generator. 49718 if (context.method !== 'return') { 49719 context.method = 'next'; 49720 context.arg = undefined; 49721 } 49722 } else { 49723 // Re-yield the result returned by the delegate method. 49724 return info; 49725 } // The delegate iterator is finished, so forget it and continue with 49726 // the outer generator. 49727 49728 context.delegate = null; 49729 return ContinueSentinel; 49730 } // Define Generator.prototype.{next,throw,return} in terms of the 49731 // unified ._invoke helper method. 49732 49733 defineIteratorMethods(Gp); 49734 Gp[toStringTagSymbol] = 'Generator'; // A Generator should always return itself as the iterator object when the 49735 // @@iterator function is called on it. Some browsers' implementations of the 49736 // iterator prototype chain incorrectly implement this, causing the Generator 49737 // object to not be returned from this call. This ensures that doesn't happen. 49738 // See https://github.com/facebook/regenerator/issues/274 for more details. 49739 Gp[iteratorSymbol] = function () { 49740 return this; 49741 }; 49742 Gp.toString = function () { 49743 return '[object Generator]'; 49744 }; 49745 function pushTryEntry(locs) { 49746 var entry = { 49747 tryLoc: locs[0] 49748 }; 49749 if (1 in locs) { 49750 entry.catchLoc = locs[1]; 49751 } 49752 if (2 in locs) { 49753 entry.finallyLoc = locs[2]; 49754 entry.afterLoc = locs[3]; 49755 } 49756 this.tryEntries.push(entry); 49757 } 49758 function resetTryEntry(entry) { 49759 var record = entry.completion || { 49760 }; 49761 record.type = 'normal'; 49762 delete record.arg; 49763 entry.completion = record; 49764 } 49765 function Context(tryLocsList) { 49766 // The root entry object (effectively a try statement without a catch 49767 // or a finally block) gives us a place to store values thrown from 49768 // locations where there is no enclosing try statement. 49769 this.tryEntries = [ 49770 { 49771 tryLoc: 'root' 49772 } 49773 ]; 49774 tryLocsList.forEach(pushTryEntry, this); 49775 this.reset(true); 49776 } 49777 exports.keys = function (object) { 49778 var keys = [ 49779 ]; 49780 for (var key in object) { 49781 keys.push(key); 49782 } 49783 keys.reverse(); // Rather than returning an object with a next method, we keep 49784 // things simple and return the next function itself. 49785 return function next() { 49786 while (keys.length) { 49787 var key = keys.pop(); 49788 if (key in object) { 49789 next.value = key; 49790 next.done = false;
vendor: 5,472 bytes, lines 49791-49926
49791 return next; 49792 } 49793 } // To avoid creating an additional object, we just hang the .value 49794 // and .done properties off the next function object itself. This 49795 // also ensures that the minifier will not anonymize the function. 49796 49797 next.done = true; 49798 return next; 49799 }; 49800 }; 49801 function values(iterable) { 49802 if (iterable) { 49803 var iteratorMethod = iterable[iteratorSymbol]; 49804 if (iteratorMethod) { 49805 return iteratorMethod.call(iterable); 49806 } 49807 if (typeof iterable.next === 'function') { 49808 return iterable; 49809 } 49810 if (!isNaN(iterable.length)) { 49811 var i = - 1, 49812 next = function next() { 49813 while (++i < iterable.length) { 49814 if (hasOwn.call(iterable, i)) { 49815 next.value = iterable[i]; 49816 next.done = false; 49817 return next; 49818 } 49819 } 49820 next.value = undefined; 49821 next.done = true; 49822 return next; 49823 }; 49824 return next.next = next; 49825 } 49826 } // Return an iterator with no values. 49827 49828 return { 49829 next: doneResult 49830 }; 49831 } 49832 exports.values = values; 49833 function doneResult() { 49834 return { 49835 value: undefined, 49836 done: true 49837 }; 49838 } 49839 Context.prototype = { 49840 constructor: Context, 49841 reset: function (skipTempReset) { 49842 this.prev = 0; 49843 this.next = 0; // Resetting context._sent for legacy support of Babel's 49844 // function.sent implementation. 49845 this.sent = this._sent = undefined; 49846 this.done = false; 49847 this.delegate = null; 49848 this.method = 'next'; 49849 this.arg = undefined; 49850 this.tryEntries.forEach(resetTryEntry); 49851 if (!skipTempReset) { 49852 for (var name in this) { 49853 // Not sure about the optimal order of these conditions: 49854 if (name.charAt(0) === 't' && hasOwn.call(this, name) && !isNaN( + name.slice(1))) { 49855 this[name] = undefined; 49856 } 49857 } 49858 } 49859 }, 49860 stop: function () { 49861 this.done = true; 49862 var rootEntry = this.tryEntries[0]; 49863 var rootRecord = rootEntry.completion; 49864 if (rootRecord.type === 'throw') { 49865 throw rootRecord.arg; 49866 } 49867 return this.rval; 49868 }, 49869 dispatchException: function (exception) { 49870 if (this.done) { 49871 throw exception; 49872 } 49873 var context = this; 49874 function handle(loc, caught) { 49875 record.type = 'throw'; 49876 record.arg = exception; 49877 context.next = loc; 49878 if (caught) { 49879 // If the dispatched exception was caught by a catch block, 49880 // then let that catch block handle the exception normally. 49881 context.method = 'next'; 49882 context.arg = undefined; 49883 } 49884 return !!caught; 49885 } 49886 for (var i = this.tryEntries.length - 1; i >= 0; --i) { 49887 var entry = this.tryEntries[i]; 49888 var record = entry.completion; 49889 if (entry.tryLoc === 'root') { 49890 // Exception thrown outside of any try block that could handle 49891 // it, so set the completion value of the entire function to 49892 // throw the exception. 49893 return handle('end'); 49894 } 49895 if (entry.tryLoc <= this.prev) { 49896 var hasCatch = hasOwn.call(entry, 'catchLoc'); 49897 var hasFinally = hasOwn.call(entry, 'finallyLoc'); 49898 if (hasCatch && hasFinally) { 49899 if (this.prev < entry.catchLoc) { 49900 return handle(entry.catchLoc, true); 49901 } else if (this.prev < entry.finallyLoc) { 49902 return handle(entry.finallyLoc); 49903 } 49904 } else if (hasCatch) { 49905 if (this.prev < entry.catchLoc) { 49906 return handle(entry.catchLoc, true); 49907 } 49908 } else if (hasFinally) { 49909 if (this.prev < entry.finallyLoc) { 49910 return handle(entry.finallyLoc); 49911 } 49912 } else { 49913 throw new Error('try statement without catch or finally'); 49914 } 49915 } 49916 } 49917 }, 49918 abrupt: function (type, arg) { 49919 for (var i = this.tryEntries.length - 1; i >= 0; --i) { 49920 var entry = this.tryEntries[i]; 49921 if (entry.tryLoc <= this.prev && hasOwn.call(entry, 'finallyLoc') && this.prev < entry.finallyLoc) { 49922 var finallyEntry = entry; 49923 break; 49924 } 49925 } 49926 if (finallyEntry && (type === 'break' || type === 'continue') && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
vendor: 4,207 bytes, lines 49927-50016
49927 // Ignore the finally entry if control is not jumping to a 49928 // location outside the try/catch block. 49929 finallyEntry = null; 49930 } 49931 var record = finallyEntry ? finallyEntry.completion : { 49932 }; 49933 record.type = type; 49934 record.arg = arg; 49935 if (finallyEntry) { 49936 this.method = 'next'; 49937 this.next = finallyEntry.finallyLoc; 49938 return ContinueSentinel; 49939 } 49940 return this.complete(record); 49941 }, 49942 complete: function (record, afterLoc) { 49943 if (record.type === 'throw') { 49944 throw record.arg; 49945 } 49946 if (record.type === 'break' || record.type === 'continue') { 49947 this.next = record.arg; 49948 } else if (record.type === 'return') { 49949 this.rval = this.arg = record.arg; 49950 this.method = 'return'; 49951 this.next = 'end'; 49952 } else if (record.type === 'normal' && afterLoc) { 49953 this.next = afterLoc; 49954 } 49955 return ContinueSentinel; 49956 }, 49957 finish: function (finallyLoc) { 49958 for (var i = this.tryEntries.length - 1; i >= 0; --i) { 49959 var entry = this.tryEntries[i]; 49960 if (entry.finallyLoc === finallyLoc) { 49961 this.complete(entry.completion, entry.afterLoc); 49962 resetTryEntry(entry); 49963 return ContinueSentinel; 49964 } 49965 } 49966 }, 49967 'catch': function (tryLoc) { 49968 for (var i = this.tryEntries.length - 1; i >= 0; --i) { 49969 var entry = this.tryEntries[i]; 49970 if (entry.tryLoc === tryLoc) { 49971 var record = entry.completion; 49972 if (record.type === 'throw') { 49973 var thrown = record.arg; 49974 resetTryEntry(entry); 49975 } 49976 return thrown; 49977 } 49978 } // The context.catch method must only be called with a location 49979 // argument that corresponds to a known catch block. 49980 49981 throw new Error('illegal catch attempt'); 49982 }, 49983 delegateYield: function (iterable, resultName, nextLoc) { 49984 this.delegate = { 49985 iterator: values(iterable), 49986 resultName: resultName, 49987 nextLoc: nextLoc 49988 }; 49989 if (this.method === 'next') { 49990 // Deliberately forget the last sent value so that we don't 49991 // accidentally pass it on to the delegate. 49992 this.arg = undefined; 49993 } 49994 return ContinueSentinel; 49995 } 49996 }; // Regardless of whether this script is executing as a CommonJS module 49997 // or not, return the runtime object so that we can declare the variable 49998 // regeneratorRuntime in the outer scope, which allows this module to be 49999 // injected easily by `bin/regenerator --include-runtime script.js`. 50000 return exports; 50001 }( // If this script is executing as a CommonJS module, use module.exports 50002 // as the regeneratorRuntime namespace. Otherwise create a new empty 50003 // object. Either way, the resulting object will be used to initialize 50004 // the regeneratorRuntime variable at the top of this file. 50005 typeof module === 'object' ? module.exports : { 50006 }); 50007 try { 50008 regeneratorRuntime = runtime; 50009 } catch (accidentalStrictMode) { 50010 // This module should not be running in strict mode, so the above 50011 // assignment should always work unless something is misconfigured. Just 50012 // in case runtime.js accidentally runs in strict mode, we can escape 50013 // strict mode using a global Function call. This could conceivably fail 50014 // if a Content Security Policy forbids using Function, but in that case 50015 // the proper solution is to fix the accidental strict mode problem. If 50016 // you've misconfigured your bundler to force strict mode and applied a
vendor: 6,947 bytes, lines 50017-50215
50017 // CSP to forbid Function, and you're not willing to fix either of those 50018 // problems, please detail your unique predicament in a GitHub issue. 50019 Function('r', 'regeneratorRuntime = r') (runtime); 50020 } 50021 }, 50022 { 50023 } 50024 ], 50025 267: [ 50026 function (_dereq_, module, exports) { 50027 (function (self) { 50028 'use strict'; 50029 if (self.fetch) { 50030 return; 50031 } 50032 var support = { 50033 searchParams: 'URLSearchParams' in self, 50034 iterable: 'Symbol' in self && 'iterator' in Symbol, 50035 blob: 'FileReader' in self && 'Blob' in self && function () { 50036 try { 50037 new Blob(); 50038 return true; 50039 } catch (e) { 50040 return false; 50041 } 50042 }(), 50043 formData: 'FormData' in self, 50044 arrayBuffer: 'ArrayBuffer' in self 50045 }; 50046 if (support.arrayBuffer) { 50047 var viewClasses = [ 50048 '[object Int8Array]', 50049 '[object Uint8Array]', 50050 '[object Uint8ClampedArray]', 50051 '[object Int16Array]', 50052 '[object Uint16Array]', 50053 '[object Int32Array]', 50054 '[object Uint32Array]', 50055 '[object Float32Array]', 50056 '[object Float64Array]' 50057 ]; 50058 var isDataView = function (obj) { 50059 return obj && DataView.prototype.isPrototypeOf(obj); 50060 }; 50061 var isArrayBufferView = ArrayBuffer.isView || function (obj) { 50062 return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > - 1; 50063 }; 50064 } 50065 function normalizeName(name) { 50066 if (typeof name !== 'string') { 50067 name = String(name); 50068 } 50069 if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { 50070 throw new TypeError('Invalid character in header field name'); 50071 } 50072 return name.toLowerCase(); 50073 } 50074 function normalizeValue(value) { 50075 if (typeof value !== 'string') { 50076 value = String(value); 50077 } 50078 return value; 50079 } // Build a destructive iterator for the value list 50080 50081 function iteratorFor(items) { 50082 var iterator = { 50083 next: function () { 50084 var value = items.shift(); 50085 return { 50086 done: value === undefined, 50087 value: value 50088 }; 50089 } 50090 }; 50091 if (support.iterable) { 50092 iterator[Symbol.iterator] = function () { 50093 return iterator; 50094 }; 50095 } 50096 return iterator; 50097 } 50098 function Headers(headers) { 50099 this.map = { 50100 }; 50101 if (headers instanceof Headers) { 50102 headers.forEach(function (value, name) { 50103 this.append(name, value); 50104 }, this); 50105 } else if (Array.isArray(headers)) { 50106 headers.forEach(function (header) { 50107 this.append(header[0], header[1]); 50108 }, this); 50109 } else if (headers) { 50110 Object.getOwnPropertyNames(headers).forEach(function (name) { 50111 this.append(name, headers[name]); 50112 }, this); 50113 } 50114 } 50115 Headers.prototype.append = function (name, value) { 50116 name = normalizeName(name); 50117 value = normalizeValue(value); 50118 var oldValue = this.map[name]; 50119 this.map[name] = oldValue ? oldValue + ',' + value : value; 50120 }; 50121 Headers.prototype['delete'] = function (name) { 50122 delete this.map[normalizeName(name)]; 50123 }; 50124 Headers.prototype.get = function (name) { 50125 name = normalizeName(name); 50126 return this.has(name) ? this.map[name] : null; 50127 }; 50128 Headers.prototype.has = function (name) { 50129 return this.map.hasOwnProperty(normalizeName(name)); 50130 }; 50131 Headers.prototype.set = function (name, value) { 50132 this.map[normalizeName(name)] = normalizeValue(value); 50133 }; 50134 Headers.prototype.forEach = function (callback, thisArg) { 50135 for (var name in this.map) { 50136 if (this.map.hasOwnProperty(name)) { 50137 callback.call(thisArg, this.map[name], name, this); 50138 } 50139 } 50140 }; 50141 Headers.prototype.keys = function () { 50142 var items = [ 50143 ]; 50144 this.forEach(function (value, name) { 50145 items.push(name); 50146 }); 50147 return iteratorFor(items); 50148 }; 50149 Headers.prototype.values = function () { 50150 var items = [ 50151 ]; 50152 this.forEach(function (value) { 50153 items.push(value); 50154 }); 50155 return iteratorFor(items); 50156 }; 50157 Headers.prototype.entries = function () { 50158 var items = [ 50159 ]; 50160 this.forEach(function (value, name) { 50161 items.push([name, 50162 value]); 50163 }); 50164 return iteratorFor(items); 50165 }; 50166 if (support.iterable) { 50167 Headers.prototype[Symbol.iterator] = Headers.prototype.entries; 50168 } 50169 function consumed(body) { 50170 if (body.bodyUsed) { 50171 return Promise.reject(new TypeError('Already read')); 50172 } 50173 body.bodyUsed = true; 50174 } 50175 function fileReaderReady(reader) { 50176 return new Promise(function (resolve, reject) { 50177 reader.onload = function () { 50178 resolve(reader.result); 50179 }; 50180 reader.onerror = function () { 50181 reject(reader.error); 50182 }; 50183 }); 50184 } 50185 function readBlobAsArrayBuffer(blob) { 50186 var reader = new FileReader(); 50187 var promise = fileReaderReady(reader); 50188 reader.readAsArrayBuffer(blob); 50189 return promise; 50190 } 50191 function readBlobAsText(blob) { 50192 var reader = new FileReader(); 50193 var promise = fileReaderReady(reader); 50194 reader.readAsText(blob); 50195 return promise; 50196 } 50197 function readArrayBufferAsText(buf) { 50198 var view = new Uint8Array(buf); 50199 var chars = new Array(view.length); 50200 for (var i = 0; i < view.length; i++) { 50201 chars[i] = String.fromCharCode(view[i]); 50202 } 50203 return chars.join(''); 50204 } 50205 function bufferClone(buf) { 50206 if (buf.slice) { 50207 return buf.slice(0); 50208 } else { 50209 var view = new Uint8Array(buf.byteLength); 50210 view.set(new Uint8Array(buf)); 50211 return view.buffer; 50212 } 50213 } 50214 function Body() { 50215 this.bodyUsed = false;
vendor: 4,067 bytes, lines 50216-50307
50216 this._initBody = function (body) { 50217 this._bodyInit = body; 50218 if (!body) { 50219 this._bodyText = ''; 50220 } else if (typeof body === 'string') { 50221 this._bodyText = body; 50222 } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { 50223 this._bodyBlob = body; 50224 } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { 50225 this._bodyFormData = body; 50226 } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { 50227 this._bodyText = body.toString(); 50228 } else if (support.arrayBuffer && support.blob && isDataView(body)) { 50229 this._bodyArrayBuffer = bufferClone(body.buffer); // IE 10-11 can't handle a DataView body. 50230 this._bodyInit = new Blob([this._bodyArrayBuffer]); 50231 } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) { 50232 this._bodyArrayBuffer = bufferClone(body); 50233 } else { 50234 throw new Error('unsupported BodyInit type'); 50235 } 50236 if (!this.headers.get('content-type')) { 50237 if (typeof body === 'string') { 50238 this.headers.set('content-type', 'text/plain;charset=UTF-8'); 50239 } else if (this._bodyBlob && this._bodyBlob.type) { 50240 this.headers.set('content-type', this._bodyBlob.type); 50241 } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { 50242 this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); 50243 } 50244 } 50245 }; 50246 if (support.blob) { 50247 this.blob = function () { 50248 var rejected = consumed(this); 50249 if (rejected) { 50250 return rejected; 50251 } 50252 if (this._bodyBlob) { 50253 return Promise.resolve(this._bodyBlob); 50254 } else if (this._bodyArrayBuffer) { 50255 return Promise.resolve(new Blob([this._bodyArrayBuffer])); 50256 } else if (this._bodyFormData) { 50257 throw new Error('could not read FormData body as blob'); 50258 } else { 50259 return Promise.resolve(new Blob([this._bodyText])); 50260 } 50261 }; 50262 this.arrayBuffer = function () { 50263 if (this._bodyArrayBuffer) { 50264 return consumed(this) || Promise.resolve(this._bodyArrayBuffer); 50265 } else { 50266 return this.blob().then(readBlobAsArrayBuffer); 50267 } 50268 }; 50269 } 50270 this.text = function () { 50271 var rejected = consumed(this); 50272 if (rejected) { 50273 return rejected; 50274 } 50275 if (this._bodyBlob) { 50276 return readBlobAsText(this._bodyBlob); 50277 } else if (this._bodyArrayBuffer) { 50278 return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer)); 50279 } else if (this._bodyFormData) { 50280 throw new Error('could not read FormData body as text'); 50281 } else { 50282 return Promise.resolve(this._bodyText); 50283 } 50284 }; 50285 if (support.formData) { 50286 this.formData = function () { 50287 return this.text().then(decode); 50288 }; 50289 } 50290 this.json = function () { 50291 return this.text().then(JSON.parse); 50292 }; 50293 return this; 50294 } // HTTP methods whose capitalization should be normalized 50295 50296 var methods = [ 50297 'DELETE', 50298 'GET', 50299 'HEAD', 50300 'OPTIONS', 50301 'POST', 50302 'PUT' 50303 ]; 50304 function normalizeMethod(method) { 50305 var upcased = method.toUpperCase(); 50306 return methods.indexOf(upcased) > - 1 ? upcased : method; 50307 }
vendor: 4,557 bytes, lines 50308-50426
50308 function Request(input, options) { 50309 options = options || { 50310 }; 50311 var body = options.body; 50312 if (input instanceof Request) { 50313 if (input.bodyUsed) { 50314 throw new TypeError('Already read'); 50315 } 50316 this.url = input.url; 50317 this.credentials = input.credentials; 50318 if (!options.headers) { 50319 this.headers = new Headers(input.headers); 50320 } 50321 this.method = input.method; 50322 this.mode = input.mode; 50323 if (!body && input._bodyInit != null) { 50324 body = input._bodyInit; 50325 input.bodyUsed = true; 50326 } 50327 } else { 50328 this.url = String(input); 50329 } 50330 this.credentials = options.credentials || this.credentials || 'omit'; 50331 if (options.headers || !this.headers) { 50332 this.headers = new Headers(options.headers); 50333 } 50334 this.method = normalizeMethod(options.method || this.method || 'GET'); 50335 this.mode = options.mode || this.mode || null; 50336 this.referrer = null; 50337 if ((this.method === 'GET' || this.method === 'HEAD') && body) { 50338 throw new TypeError('Body not allowed for GET or HEAD requests'); 50339 } 50340 this._initBody(body); 50341 } 50342 Request.prototype.clone = function () { 50343 return new Request(this, { 50344 body: this._bodyInit 50345 }); 50346 }; 50347 function decode(body) { 50348 var form = new FormData(); 50349 body.trim().split('&').forEach(function (bytes) { 50350 if (bytes) { 50351 var split = bytes.split('='); 50352 var name = split.shift().replace(/\+/g, ' '); 50353 var value = split.join('=').replace(/\+/g, ' '); 50354 form.append(decodeURIComponent(name), decodeURIComponent(value)); 50355 } 50356 }); 50357 return form; 50358 } 50359 function parseHeaders(rawHeaders) { 50360 var headers = new Headers(); // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space 50361 // https://tools.ietf.org/html/rfc7230#section-3.2 50362 var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); 50363 preProcessedHeaders.split(/\r?\n/).forEach(function (line) { 50364 var parts = line.split(':'); 50365 var key = parts.shift().trim(); 50366 if (key) { 50367 var value = parts.join(':').trim(); 50368 headers.append(key, value); 50369 } 50370 }); 50371 return headers; 50372 } 50373 Body.call(Request.prototype); 50374 function Response(bodyInit, options) { 50375 if (!options) { 50376 options = { 50377 }; 50378 } 50379 this.type = 'default'; 50380 this.status = options.status === undefined ? 200 : options.status; 50381 this.ok = this.status >= 200 && this.status < 300; 50382 this.statusText = 'statusText' in options ? options.statusText : 'OK'; 50383 this.headers = new Headers(options.headers); 50384 this.url = options.url || ''; 50385 this._initBody(bodyInit); 50386 } 50387 Body.call(Response.prototype); 50388 Response.prototype.clone = function () { 50389 return new Response(this._bodyInit, { 50390 status: this.status, 50391 statusText: this.statusText, 50392 headers: new Headers(this.headers), 50393 url: this.url 50394 }); 50395 }; 50396 Response.error = function () { 50397 var response = new Response(null, { 50398 status: 0, 50399 statusText: '' 50400 }); 50401 response.type = 'error'; 50402 return response; 50403 }; 50404 var redirectStatuses = [ 50405 301, 50406 302, 50407 303, 50408 307, 50409 308 50410 ]; 50411 Response.redirect = function (url, status) { 50412 if (redirectStatuses.indexOf(status) === - 1) { 50413 throw new RangeError('Invalid status code'); 50414 } 50415 return new Response(null, { 50416 status: status, 50417 headers: { 50418 location: url 50419 } 50420 }); 50421 }; 50422 self.Headers = Headers; 50423 self.Request = Request; 50424 self.Response = Response; 50425 self.fetch = function (input, init) { 50426 return new Promise(function (resolve, reject) {
50427 var request = new Request(input, init); 50428 var xhr = new XMLHttpRequest(); 50429 xhr.onload = function () { 50430 var options = { 50431 status: xhr.status, 50432 statusText: xhr.statusText, 50433 headers: parseHeaders(xhr.getAllResponseHeaders() || '') 50434 }; 50435 options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); 50436 var body = 'response' in xhr ? xhr.response : xhr.responseText; 50437 resolve(new Response(body, options)); 50438 }; 50439 xhr.onerror = function () { 50440 reject(new TypeError('Network request failed')); 50441 }; 50442 xhr.ontimeout = function () { 50443 reject(new TypeError('Network request failed')); 50444 }; 50445 xhr.open(request.method, request.url, true); 50446 if (request.credentials === 'include') { 50447 xhr.withCredentials = true; 50448 } else if (request.credentials === 'omit') { 50449 xhr.withCredentials = false; 50450 } 50451 if ('responseType' in xhr && support.blob) { 50452 xhr.responseType = 'blob'; 50453 } 50454 request.headers.forEach(function (value, name) { 50455 xhr.setRequestHeader(name, value); 50456 }); 50457 xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit); 50458 }); 50459 }; 50460 self.fetch.polyfill = true; 50461 }) (typeof self !== 'undefined' ? self : this); 50462 }, 50463 { 50464 } 50465 ], 50466 268: [ 50467 function (_dereq_, module, exports) { 50468 'use strict'; 50469 _dereq_('core-js/modules/es.function.name'); 50470 _dereq_('core-js/modules/es.object.to-string'); 50471 _dereq_('core-js/modules/es.regexp.exec'); 50472 _dereq_('core-js/modules/es.regexp.to-string'); 50473 _dereq_('core-js/modules/es.string.split'); 50474 _dereq_('core-js/modules/es.function.name'); 50475 _dereq_('core-js/modules/es.object.to-string'); 50476 _dereq_('core-js/modules/es.regexp.exec'); 50477 _dereq_('core-js/modules/es.regexp.to-string'); 50478 _dereq_('core-js/modules/es.string.split'); 50479 Object.defineProperty(exports, '__esModule', { 50480 value: true 50481 }); 50482 exports.default = void 0; 50483 var _main = _interopRequireDefault(_dereq_('../core/main')); 50484 var _color_conversion = _interopRequireDefault(_dereq_('../color/color_conversion')); 50485 function _interopRequireDefault(obj) { 50486 return obj && obj.__esModule ? obj : { 50487 default: 50488 obj 50489 }; 50490 } /** 50491 * @module Environment 50492 * @submodule Environment 50493 * @for p5 50494 * @requires core 50495 */ 50496 //stores the original hsb values 50497 50498 var originalHSB; //stores values for color name exceptions 50499 var colorExceptions = [ 50500 { 50501 h: 0, 50502 s: 0, 50503 b: 0.8275, 50504 name: 'gray' 50505 }, 50506 { 50507 h: 0, 50508 s: 0, 50509 b: 0.8627, 50510 name: 'gray' 50511 }, 50512 { 50513 h: 0, 50514 s: 0, 50515 b: 0.7529, 50516 name: 'gray' 50517 }, 50518 { 50519 h: 0.0167, 50520 s: 0.1176, 50521 b: 1, 50522 name: 'light pink' 50523 } 50524 ]; //stores values for color names 50525 var colorLookUp = [ 50526 { 50527 h: 0, 50528 s: 0, 50529 b: 0, 50530 name: 'black' 50531 }, 50532 { 50533 h: 0, 50534 s: 0, 50535 b: 0.5, 50536 name: 'gray' 50537 }, 50538 { 50539 h: 0, 50540 s: 0, 50541 b: 1, 50542 name: 'white' 50543 }, 50544 { 50545 h: 0, 50546 s: 0.5, 50547 b: 0.5, 50548 name: 'dark maroon' 50549 }, 50550 { 50551 h: 0, 50552 s: 0.5, 50553 b: 1, 50554 name: 'salmon pink' 50555 }, 50556 { 50557 h: 0, 50558 s: 1, 50559 b: 0, 50560 name: 'black' 50561 }, 50562 { 50563 h: 0, 50564 s: 1, 50565 b: 0.5, 50566 name: 'dark red' 50567 }, 50568 { 50569 h: 0, 50570 s: 1, 50571 b: 1, 50572 name: 'red' 50573 }, 50574 { 50575 h: 5, 50576 s: 0, 50577 b: 1, 50578 name: 'very light peach' 50579 }, 50580 { 50581 h: 5, 50582 s: 0.5, 50583 b: 0.5, 50584 name: 'brown' 50585 }, 50586 { 50587 h: 5, 50588 s: 0.5, 50589 b: 1, 50590 name: 'peach' 50591 }, 50592 { 50593 h: 5, 50594 s: 1, 50595 b: 0.5, 50596 name: 'brick red' 50597 }, 50598 { 50599 h: 5, 50600 s: 1, 50601 b: 1, 50602 name: 'crimson' 50603 }, 50604 { 50605 h: 10, 50606 s: 0, 50607 b: 1, 50608 name: 'light peach' 50609 }, 50610 { 50611 h: 10, 50612 s: 0.5, 50613 b: 0.5, 50614 name: 'brown' 50615 }, 50616 { 50617 h: 10, 50618 s: 0.5, 50619 b: 1, 50620 name: 'light orange' 50621 }, 50622 { 50623 h: 10, 50624 s: 1, 50625 b: 0.5, 50626 name: 'brown' 50627 }, 50628 { 50629 h: 10, 50630 s: 1, 50631 b: 1, 50632 name: 'orange' 50633 }, 50634 { 50635 h: 15, 50636 s: 0, 50637 b: 1, 50638 name: 'very light yellow' 50639 }, 50640 { 50641 h: 15, 50642 s: 0.5, 50643 b: 0.5, 50644 name: 'olive green' 50645 }, 50646 { 50647 h: 15, 50648 s: 0.5, 50649 b: 1, 50650 name: 'light yellow' 50651 }, 50652 { 50653 h: 15, 50654 s: 1, 50655 b: 0, 50656 name: 'dark olive green' 50657 }, 50658 { 50659 h: 15, 50660 s: 1, 50661 b: 0.5, 50662 name: 'olive green' 50663 }, 50664 { 50665 h: 15, 50666 s: 1, 50667 b: 1, 50668 name: 'yellow' 50669 }, 50670 { 50671 h: 20, 50672 s: 0, 50673 b: 1, 50674 name: 'very light yellow' 50675 }, 50676 { 50677 h: 20, 50678 s: 0.5, 50679 b: 0.5, 50680 name: 'olive green' 50681 }, 50682 { 50683 h: 20, 50684 s: 0.5, 50685 b: 1, 50686 name: 'light yellow green' 50687 }, 50688 { 50689 h: 20, 50690 s: 1, 50691 b: 0, 50692 name: 'dark olive green' 50693 }, 50694 { 50695 h: 20, 50696 s: 1, 50697 b: 0.5, 50698 name: 'dark yellow green' 50699 }, 50700 { 50701 h: 20, 50702 s: 1, 50703 b: 1, 50704 name: 'yellow green' 50705 }, 50706 { 50707 h: 25, 50708 s: 0.5, 50709 b: 0.5, 50710 name: 'dark yellow green' 50711 }, 50712 { 50713 h: 25, 50714 s: 0.5, 50715 b: 1, 50716 name: 'light green' 50717 }, 50718 { 50719 h: 25, 50720 s: 1, 50721 b: 0.5, 50722 name: 'dark green' 50723 }, 50724 { 50725 h: 25, 50726 s: 1, 50727 b: 1, 50728 name: 'green' 50729 }, 50730 { 50731 h: 30, 50732 s: 0.5, 50733 b: 1, 50734 name: 'light green' 50735 }, 50736 { 50737 h: 30, 50738 s: 1, 50739 b: 0.5, 50740 name: 'dark green' 50741 }, 50742 { 50743 h: 30, 50744 s: 1, 50745 b: 1, 50746 name: 'green' 50747 }, 50748 { 50749 h: 35, 50750 s: 0, 50751 b: 0.5, 50752 name: 'light green' 50753 }, 50754 { 50755 h: 35, 50756 s: 0, 50757 b: 1, 50758 name: 'very light green' 50759 }, 50760 { 50761 h: 35, 50762 s: 0.5, 50763 b: 0.5, 50764 name: 'dark green' 50765 }, 50766 { 50767 h: 35, 50768 s: 0.5, 50769 b: 1, 50770 name: 'light green' 50771 }, 50772 { 50773 h: 35, 50774 s: 1, 50775 b: 0, 50776 name: 'very dark green' 50777 }, 50778 { 50779 h: 35, 50780 s: 1, 50781 b: 0.5, 50782 name: 'dark green' 50783 }, 50784 { 50785 h: 35, 50786 s: 1, 50787 b: 1, 50788 name: 'green' 50789 }, 50790 { 50791 h: 40, 50792 s: 0, 50793 b: 1, 50794 name: 'very light green' 50795 }, 50796 { 50797 h: 40, 50798 s: 0.5, 50799 b: 0.5, 50800 name: 'dark green' 50801 }, 50802 { 50803 h: 40, 50804 s: 0.5, 50805 b: 1, 50806 name: 'light green' 50807 }, 50808 { 50809 h: 40, 50810 s: 1, 50811 b: 0.5, 50812 name: 'dark green' 50813 }, 50814 { 50815 h: 40, 50816 s: 1, 50817 b: 1, 50818 name: 'green' 50819 }, 50820 { 50821 h: 45, 50822 s: 0.5, 50823 b: 1, 50824 name: 'light turquoise' 50825 }, 50826 { 50827 h: 45, 50828 s: 1, 50829 b: 0.5, 50830 name: 'dark turquoise' 50831 }, 50832 { 50833 h: 45, 50834 s: 1, 50835 b: 1, 50836 name: 'turquoise' 50837 }, 50838 { 50839 h: 50, 50840 s: 0, 50841 b: 1, 50842 name: 'light sky blue' 50843 }, 50844 { 50845 h: 50, 50846 s: 0.5, 50847 b: 0.5, 50848 name: 'dark cyan' 50849 }, 50850 { 50851 h: 50, 50852 s: 0.5, 50853 b: 1, 50854 name: 'light cyan' 50855 }, 50856 { 50857 h: 50, 50858 s: 1, 50859 b: 0.5, 50860 name: 'dark cyan' 50861 }, 50862 { 50863 h: 50, 50864 s: 1, 50865 b: 1, 50866 name: 'cyan' 50867 }, 50868 { 50869 h: 55, 50870 s: 0, 50871 b: 1, 50872 name: 'light sky blue' 50873 }, 50874 { 50875 h: 55, 50876 s: 0.5, 50877 b: 1, 50878 name: 'light sky blue' 50879 }, 50880 { 50881 h: 55, 50882 s: 1, 50883 b: 0.5, 50884 name: 'dark blue' 50885 }, 50886 { 50887 h: 55, 50888 s: 1, 50889 b: 1, 50890 name: 'sky blue' 50891 }, 50892 { 50893 h: 60, 50894 s: 0, 50895 b: 0.5, 50896 name: 'gray' 50897 }, 50898 { 50899 h: 60, 50900 s: 0, 50901 b: 1, 50902 name: 'very light blue' 50903 }, 50904 { 50905 h: 60, 50906 s: 0.5, 50907 b: 0.5, 50908 name: 'blue' 50909 }, 50910 { 50911 h: 60, 50912 s: 0.5, 50913 b: 1, 50914 name: 'light blue' 50915 }, 50916 { 50917 h: 60, 50918 s: 1, 50919 b: 0.5, 50920 name: 'navy blue' 50921 }, 50922 { 50923 h: 60, 50924 s: 1, 50925 b: 1, 50926 name: 'blue' 50927 }, 50928 { 50929 h: 65, 50930 s: 0, 50931 b: 1, 50932 name: 'lavender' 50933 }, 50934 { 50935 h: 65, 50936 s: 0.5, 50937 b: 0.5, 50938 name: 'navy blue' 50939 }, 50940 { 50941 h: 65, 50942 s: 0.5, 50943 b: 1, 50944 name: 'light purple' 50945 }, 50946 { 50947 h: 65, 50948 s: 1, 50949 b: 0.5, 50950 name: 'dark navy blue' 50951 }, 50952 { 50953 h: 65, 50954 s: 1, 50955 b: 1, 50956 name: 'blue' 50957 }, 50958 { 50959 h: 70, 50960 s: 0, 50961 b: 1, 50962 name: 'lavender' 50963 }, 50964 { 50965 h: 70, 50966 s: 0.5, 50967 b: 0.5, 50968 name: 'navy blue' 50969 }, 50970 { 50971 h: 70, 50972 s: 0.5, 50973 b: 1, 50974 name: 'lavender blue' 50975 }, 50976 { 50977 h: 70, 50978 s: 1, 50979 b: 0.5, 50980 name: 'dark navy blue' 50981 }, 50982 { 50983 h: 70, 50984 s: 1, 50985 b: 1, 50986 name: 'blue' 50987 }, 50988 { 50989 h: 75, 50990 s: 0.5, 50991 b: 1, 50992 name: 'lavender' 50993 }, 50994 { 50995 h: 75, 50996 s: 1, 50997 b: 0.5, 50998 name: 'dark purple' 50999 }, 51000 { 51001 h: 75, 51002 s: 1, 51003 b: 1, 51004 name: 'purple' 51005 }, 51006 { 51007 h: 80, 51008 s: 0.5, 51009 b: 1, 51010 name: 'pinkish purple' 51011 }, 51012 { 51013 h: 80, 51014 s: 1, 51015 b: 0.5, 51016 name: 'dark purple' 51017 }, 51018 { 51019 h: 80, 51020 s: 1, 51021 b: 1, 51022 name: 'purple' 51023 }, 51024 { 51025 h: 85, 51026 s: 0, 51027 b: 1, 51028 name: 'light pink' 51029 }, 51030 { 51031 h: 85, 51032 s: 0.5, 51033 b: 0.5, 51034 name: 'purple' 51035 }, 51036 { 51037 h: 85, 51038 s: 0.5, 51039 b: 1, 51040 name: 'light fuchsia' 51041 }, 51042 { 51043 h: 85, 51044 s: 1, 51045 b: 0.5, 51046 name: 'dark fuchsia' 51047 }, 51048 { 51049 h: 85, 51050 s: 1, 51051 b: 1, 51052 name: 'fuchsia' 51053 }, 51054 { 51055 h: 90, 51056 s: 0.5, 51057 b: 0.5, 51058 name: 'dark fuchsia' 51059 }, 51060 { 51061 h: 90, 51062 s: 0.5, 51063 b: 1, 51064 name: 'hot pink' 51065 }, 51066 { 51067 h: 90, 51068 s: 1, 51069 b: 0.5, 51070 name: 'dark fuchsia' 51071 }, 51072 { 51073 h: 90, 51074 s: 1, 51075 b: 1, 51076 name: 'fuchsia' 51077 }, 51078 { 51079 h: 95, 51080 s: 0, 51081 b: 1, 51082 name: 'pink' 51083 }, 51084 { 51085 h: 95, 51086 s: 0.5, 51087 b: 1, 51088 name: 'light pink' 51089 }, 51090 { 51091 h: 95, 51092 s: 1, 51093 b: 0.5, 51094 name: 'dark magenta' 51095 }, 51096 { 51097 h: 95, 51098 s: 1, 51099 b: 1, 51100 name: 'magenta' 51101 } 51102 ]; //returns text with color name 51103 function _calculateColor(hsb) { 51104 var colortext; //round hue 51105 if (hsb[0] !== 0) { 51106 hsb[0] = Math.round(hsb[0] * 100); 51107 var hue = hsb[0].toString().split(''); 51108 var last = hue.length - 1; 51109 hue[last] = parseInt(hue[last]); //if last digit of hue is < 2.5 make it 0 51110 if (hue[last] < 2.5) { 51111 hue[last] = 0; //if last digit of hue is >= 2.5 and less than 7.5 make it 5 51112 } else if (hue[last] >= 2.5 && hue[last] < 7.5) { 51113 hue[last] = 5; 51114 } //if hue only has two digits 51115 51116 if (hue.length === 2) { 51117 hue[0] = parseInt(hue[0]); //if last is greater than 7.5 51118 if (hue[last] >= 7.5) { 51119 //add one to the tens 51120 hue[last] = 0; 51121 hue[0] = hue[0] + 1; 51122 } 51123 hsb[0] = hue[0] * 10 + hue[1]; 51124 } else { 51125 if (hue[last] >= 7.5) { 51126 hsb[0] = 10; 51127 } else { 51128 hsb[0] = hue[last]; 51129 } 51130 } 51131 } //map brightness from 0 to 1 51132 51133 hsb[2] = hsb[2] / 255; //round saturation and brightness 51134 for (var i = hsb.length - 1; i >= 1; i--) { 51135 if (hsb[i] <= 0.25) { 51136 hsb[i] = 0; 51137 } else if (hsb[i] > 0.25 && hsb[i] < 0.75) { 51138 hsb[i] = 0.5; 51139 } else { 51140 hsb[i] = 1; 51141 } 51142 } //after rounding, if the values are hue 0, saturation 0 and brightness 1 51143 //look at color exceptions which includes several tones from white to gray 51144 51145 if (hsb[0] === 0 && hsb[1] === 0 && hsb[2] === 1) { 51146 //round original hsb values 51147 for (var _i = 2; _i >= 0; _i--) { 51148 originalHSB[_i] = Math.round(originalHSB[_i] * 10000) / 10000; 51149 } //compare with the values in the colorExceptions array 51150 51151 for (var e = 0; e < colorExceptions.length; e++) { 51152 if (colorExceptions[e].h === originalHSB[0] && colorExceptions[e].s === originalHSB[1] && colorExceptions[e].b === originalHSB[2]) { 51153
51153 colortext = colorExceptions[e].name; 51154 break; 51155 } else { 51156 //if there is no match return white 51157 colortext = 'white'; 51158 } 51159 } 51160 } else { 51161 //otherwise, compare with values in colorLookUp 51162 for (var _i2 = 0; _i2 < colorLookUp.length; _i2++) { 51163 if (colorLookUp[_i2].h === hsb[0] && colorLookUp[_i2].s === hsb[1] && colorLookUp[_i2].b === hsb[2]) { 51164 colortext = colorLookUp[_i2].name; 51165 break; 51166 } 51167 } 51168 } 51169 return colortext; 51170 } //gets rgba and returs a color name 51171 51172 _main.default.prototype._rgbColorName = function (arg) { 51173 //conversts rgba to hsb 51174 var hsb = _color_conversion.default._rgbaToHSBA(arg); //stores hsb in global variable 51175 originalHSB = hsb; //calculate color name 51176 return _calculateColor([hsb[0], 51177 hsb[1], 51178 hsb[2]]); 51179 }; 51180 var _default = _main.default; 51181 exports.default = _default; 51182 }, 51183 { 51184 '../color/color_conversion': 274, 51185 '../core/main': 290, 51186 'core-js/modules/es.function.name': 183, 51187 'core-js/modules/es.object.to-string': 195, 51188 'core-js/modules/es.regexp.exec': 199, 51189 'core-js/modules/es.regexp.to-string': 200, 51190 'core-js/modules/es.string.split': 209 51191 } 51192 ], 51193 269: [ 51194 function (_dereq_, module, exports) { 51195 'use strict'; 51196 _dereq_('core-js/modules/es.array.concat'); 51197 _dereq_('core-js/modules/es.regexp.exec'); 51198 _dereq_('core-js/modules/es.string.ends-with'); 51199 _dereq_('core-js/modules/es.string.replace'); 51200 _dereq_('core-js/modules/es.array.concat'); 51201 _dereq_('core-js/modules/es.regexp.exec'); 51202 _dereq_('core-js/modules/es.string.ends-with'); 51203 _dereq_('core-js/modules/es.string.replace'); 51204 Object.defineProperty(exports, '__esModule', { 51205 value: true 51206 }); 51207 exports.default = void 0; 51208 var _main = _interopRequireDefault(_dereq_('../core/main')); 51209 function _interopRequireDefault(obj) { 51210 return obj && obj.__esModule ? obj : { 51211 default: 51212 obj 51213 }; 51214 } /** 51215 * @module Environment 51216 * @submodule Environment 51217 * @for p5 51218 * @requires core 51219 */ 51220 51221 var descContainer = '_Description'; //Fallback container 51222 var fallbackDescId = '_fallbackDesc'; //Fallback description 51223 var fallbackTableId = '_fallbackTable'; //Fallback Table 51224 var fallbackTableElId = '_fte_'; //Fallback Table Element 51225 var labelContainer = '_Label'; //Label container 51226 var labelDescId = '_labelDesc'; //Label description 51227 var labelTableId = '_labelTable'; //Label Table 51228 var labelTableElId = '_lte_'; //Label Table Element 51229 /** 51230 * Creates a screen reader accessible description for the canvas. 51231 * The first parameter should be a string with a description of the canvas. 51232 * The second parameter is optional. If specified, it determines how the 51233 * description is displayed. 51234 * 51235 * <code class="language-javascript">describe(text, LABEL)</code> displays 51236 * the description to all users as a <a 51237 * href="https://en.wikipedia.org/wiki/Museum_label" target="_blank"> 51238 * tombstone or exhibit label/caption</a> in a div 51239 * adjacent to the canvas. You can style it as you wish in your CSS. 51240 * 51241 * <code class="language-javascript">describe(text, FALLBACK)</code> makes the 51242 * description accessible to screen-reader users only, in 51243 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank"> 51244 * a sub DOM inside the canvas element</a>. If a second parameter is not 51245 * specified, by default, the description will only be available to 51246 * screen-reader users. 51247 * 51248 * @method describe 51249 * @param {String} text description of the canvas 51250 * @param {Constant} [display] either LABEL or FALLBACK 51251 * 51252 * @example 51253 * <div> 51254 * <code> 51255 * describe('pink square with red heart in the bottom right corner'); 51256 * background('pink'); 51257 * fill('red'); 51258 * noStroke(); 51259 * ellipse(67, 67, 20, 20); 51260 * ellipse(83, 67, 20, 20); 51261 * triangle(91, 73, 75, 95, 59, 73); 51262 * </code> 51263 * </div> 51264 * 51265 * <div> 51266 * <code> 51267 * let x = 0; 51268 * function draw() { 51269 * if (x > 100) { 51270 * x = 0; 51271 * } 51272 * background(220); 51273 * fill(0, 255, 0); 51274 * ellipse(x, 50, 40, 40); 51275 * x = x + 0.1; 51276 * describe('green circle at x pos ' + round(x) + ' moving to the right'); 51277 * } 51278 * </code> 51279 * </div> 51280 * 51281 */ 51282 _main.default.prototype.describe = function (text, display) { 51283 _main.default._validateParameters('describe', arguments); 51284 if (typeof text !== 'string') { 51285 return; 51286 } 51287 var cnvId = this.canvas.id; //calls function that adds punctuation for better screen reading 51288 text = _descriptionText(text); //if there is no dummyDOM 51289 if (!this.dummyDOM) { 51290 this.dummyDOM = document.getElementById(cnvId).parentNode; 51291 } 51292 if (!this.descriptions) { 51293 this.descriptions = { 51294 }; 51295 } //check if html structure for description is ready 51296 51297 if (this.descriptions.fallback) { 51298 //check if text is different from current description 51299 if (this.descriptions.fallback.innerHTML !== text) { 51300 //update description 51301 this.descriptions.fallback.innerHTML = text; 51302 } 51303 } else { 51304 //create fallback html structure 51305 this._describeHTML('fallback', text); 51306 } //if display is LABEL 51307 51308 if (display === this.LABEL) { 51309 //check if html structure for label is ready 51310 if (this.descriptions.label) { 51311 //check if text is different from current label 51312 if (this.descriptions.label.innerHTML !== text) { 51313 //update label description 51314 this.descriptions.label.innerHTML = text; 51315 } 51316 } else { 51317 //create label html structure 51318 this._describeHTML('label', text); 51319 } 51320 } 51321 }; 51322 /** 51323 * This function creates a screen-reader accessible 51324 * description for elements âshapes or groups of shapes that create 51325 * meaning togetherâ in the canvas. The first paramater should 51326 * be the name of the element. The second parameter should be a string 51327 * with a description of the element. The third parameter is optional. 51328 * If specified, it determines how the element description is displayed. 51329 * 51330 * <code class="language-javascript">describeElement(name, text, LABEL)</code> 51331 * displays the element description to all users as a 51332 * <a href="https://en.wikipedia.org/wiki/Museum_label" target="_blank"> 51333 * tombstone or exhibit label/caption</a> in a div 51334 * adjacent to the canvas. You can style it as you wish in your CSS. 51335 * 51336 * <code class="language-javascript">describeElement(name, text, FALLBACK)</code> 51337 * makes the element description accessible to screen-reader users 51338 * only, in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank"> 51339 * a sub DOM inside the canvas element</a>. If a second parameter is not 51340 * specified, by default, the element description will only be available 51341 * to screen-reader users. 51342 * 51343 * @method describeElement 51344 * @param {String} name name of the element 51345 * @param {String} text description of the element 51346 * @param {Constant} [display] either LABEL or FALLBACK 51347 * 51348 * @example 51349 * <div> 51350 * <code> 51351 * describe('Heart and yellow circle over pink background'); 51352 * noStroke(); 51353 * background('pink'); 51354 * describeElement('Circle', 'Yellow circle in the top left corner'); 51355 * fill('yellow'); 51356 * ellipse(25, 25, 40, 40); 51357 * describeElement('Heart', 'red heart in the bottom right corner'); 51358 * fill('red'); 51359 * ellipse(66.6, 66.6, 20, 20); 51360 * ellipse(83.2, 66.6, 20, 20); 51361 * triangle(91.2, 72.6, 75, 95, 58.6, 72.6); 51362 * </code> 51363 * </div> 51364 */ 51365 _main.default.prototype.describeElement = function (name, text, display) { 51366 _main.default._validateParameters('describeElement', arguments); 51367 if (typeof text !== 'string' || typeof name !== 'string') { 51368 return; 51369 } 51370 var cnvId = this.canvas.id; //calls function that adds punctuation for better screen reading 51371 text = _descriptionText(text); //calls function that adds punctuation for better screen reading 51372 var elementName = _elementName(name); //remove any special characters from name to use it as html id 51373 name = name.replace(/[^a-zA-Z0-9]/g, ''); //store element description 51374 var inner = '<th scope="row">'.concat(elementName, '</th><td>').concat(text, '</td>'); //if there is no dummyDOM 51375 if (!this.dummyDOM) { 51376 this.dummyDOM = document.getElementById(cnvId).parentNode; 51377 } 51378 if (!this.descriptions) { 51379 this.descriptions = { 51380 fallbackElements: { 51381 } 51382 }; 51383 } else if (!this.descriptions.fallbackElements) { 51384 this.descriptions.fallbackElements = { 51385 }; 51386 } //check if html structure for element description is ready 51387 51388 if (this.descriptions.fallbackElements[name]) { 51389 //if current element description is not the same as inner 51390 if (this.descriptions.fallbackElements[name].innerHTML !== inner) { 51391 //update element description 51392 this.descriptions.fallbackElements[name].innerHTML = inner; 51393 } 51394 } else { 51395 //create fallback html structure 51396 this._describeElementHTML('fallback', name, inner); 51397 } //if display is LABEL 51398 51399 if (display === this.LABEL) { 51400 if (!this.descriptions.labelElements) { 51401 this.descriptions.labelElements = { 51402 }; 51403 } //if html structure for label element description is ready 51404 51405 if (this.descriptions.labelElements[name]) { 51406 //if label element description is different 51407 if (this.descriptions.labelElements[name].innerHTML !== inner) { 51408 //update label element description 51409 this.descriptions.labelElements[name].innerHTML = inner; 51410 } 51411 } else { 51412 //create label element html structure 51413 this._describeElementHTML('label', name, inner); 51414 } 51415 } 51416 }; 51417 /* 51418 * 51419 * Helper functions for describe() and describeElement(). 51420 * 51421 */ 51422 // check that text is not LABEL or FALLBACK and ensure text ends with punctuation mark 51423 function _descriptionText(text) { 51424 if (text === 'label' || text === 'fallback') { 51425 throw new Error('description should not be LABEL or FALLBACK'); 51426 } //if string does not end with '.' 51427 51428 if (!text.endsWith('.') && !text.endsWith(';') && !text.endsWith(',') && !text.endsWith('?') && !text.endsWith('!')) { 51429 //add '.' to the end of string 51430 text = text + '.'; 51431 } 51432 return text; 51433 } /* 51434 * Helper functions for describe() 51435 */ 51436 //creates HTML structure for canvas descriptions 51437 51438 _main.default.prototype._describeHTML = function (type, text) { 51439 var cnvId = this.canvas.id; 51440 if (type === 'fallback') { 51441 //if there is no description container 51442 if (!this.dummyDOM.querySelector('#'.concat(cnvId + descContainer))) { 51443 //if there are no accessible outputs (see textOutput() and gridOutput()) 51444 var html = '<div id="'.concat(cnvId).concat(descContainer, '" role="region" aria-label="Canvas Description"><p id="').concat(cnvId).concat(fallbackDescId, '"></p></div>'); 51445 if (!this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutput'))) { 51446 //create description container + <p> for fallback description 51447 this.dummyDOM.querySelector('#'.concat(cnvId)).innerHTML = html; 51448 } else { 51449 //create description container + <p> for fallback description before outputs 51450 this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutput')).insertAdjacentHTML('beforebegin', html); 51451 } 51452 } else { 51453 //if describeElement() has already created the container and added a table of elements 51454 //create fallback description <p> before the table 51455 this.dummyDOM.querySelector('#' + cnvId + fallbackTableId).insertAdjacentHTML('beforebegin', '<p id="'.concat(cnvId + fallbackDescId, '"></p>')); 51456 } //if the container for the description exists 51457 51458 this.descriptions.fallback = this.dummyDOM.querySelector('#'.concat(cnvId).concat(fallbackDescId)); 51459 this.descriptions.fallback.innerHTML = text; 51460 return; 51461 } else if (type === 'label') { 51462 //if there is no label container 51463 if (!this.dummyDOM.querySelector('#'.concat(cnvId + labelContainer))) { 51464 var _html = '<div id="'.concat(cnvId).concat(labelContainer, '" class="p5Label"><p id="').concat(cnvId).concat(labelDescId, '"></p></div>'); //if there are no accessible outputs (see textOutput() and gridOutput()) 51465 if (!this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutputLabel'))) { 51466 //create label container + <p> for label description 51467 this.dummyDOM.querySelector('#' + cnvId).insertAdjacentHTML('afterend', _html); 51468 } else { 51469 //create label container + <p> for label description before outputs 51470 this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutputLabel')).insertAdjacentHTML('beforebegin', _html); 51471 } 51472 } else if (this.dummyDOM.querySelector('#'.concat(cnvId + labelTableId))) { 51473 //if describeElement() has already created the container and added a table of elements 51474 //create label description <p> before the table 51475 this.dummyDOM.querySelector('#'.concat(cnvId + labelTableId)).insertAdjacentHTML('beforebegin', '<p id="'.concat(cnvId).concat(labelDescId, '"></p>')); 51476 } 51477 this.descriptions.label = this.dummyDOM.querySelector('#' + cnvId + labelDescId
51477); 51478 this.descriptions.label.innerHTML = text; 51479 return; 51480 } 51481 }; 51482 /* 51483 * Helper functions for describeElement(). 51484 */ 51485 //check that name is not LABEL or FALLBACK and ensure text ends with colon 51486 function _elementName(name) { 51487 if (name === 'label' || name === 'fallback') { 51488 throw new Error('element name should not be LABEL or FALLBACK'); 51489 } //check if last character of string n is '.', ';', or ',' 51490 51491 if (name.endsWith('.') || name.endsWith(';') || name.endsWith(',')) { 51492 //replace last character with ':' 51493 name = name.replace(/.$/, ':'); 51494 } else if (!name.endsWith(':')) { 51495 //if string n does not end with ':' 51496 //add ':'' at the end of string 51497 name = name + ':'; 51498 } 51499 return name; 51500 } //creates HTML structure for element descriptions 51501 51502 _main.default.prototype._describeElementHTML = function (type, name, text) { 51503 var cnvId = this.canvas.id; 51504 if (type === 'fallback') { 51505 //if there is no description container 51506 if (!this.dummyDOM.querySelector('#'.concat(cnvId + descContainer))) { 51507 //if there are no accessible outputs (see textOutput() and gridOutput()) 51508 var html = '<div id="'.concat(cnvId).concat(descContainer, '" role="region" aria-label="Canvas Description"><table id="').concat(cnvId).concat(fallbackTableId, '"><caption>Canvas elements and their descriptions</caption></table></div>'); 51509 if (!this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutput'))) { 51510 //create container + table for element descriptions 51511 this.dummyDOM.querySelector('#' + cnvId).innerHTML = html; 51512 } else { 51513 //create container + table for element descriptions before outputs 51514 this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutput')).insertAdjacentHTML('beforebegin', html); 51515 } 51516 } else if (!this.dummyDOM.querySelector('#' + cnvId + fallbackTableId)) { 51517 //if describe() has already created the container and added a description 51518 //and there is no table create fallback table for element description after 51519 //fallback description 51520 this.dummyDOM.querySelector('#' + cnvId + fallbackDescId).insertAdjacentHTML('afterend', '<table id="'.concat(cnvId).concat(fallbackTableId, '"><caption>Canvas elements and their descriptions</caption></table>')); 51521 } //create a table row for the element 51522 51523 var tableRow = document.createElement('tr'); 51524 tableRow.id = cnvId + fallbackTableElId + name; 51525 this.dummyDOM.querySelector('#' + cnvId + fallbackTableId).appendChild(tableRow); //update element description 51526 this.descriptions.fallbackElements[name] = this.dummyDOM.querySelector('#'.concat(cnvId).concat(fallbackTableElId).concat(name)); 51527 this.descriptions.fallbackElements[name].innerHTML = text; 51528 return; 51529 } else if (type === 'label') { 51530 //If display is LABEL creates a div adjacent to the canvas element with 51531 //a table, a row header cell with the name of the elements, 51532 //and adds the description of the element in adjecent cell. 51533 //if there is no label description container 51534 if (!this.dummyDOM.querySelector('#'.concat(cnvId + labelContainer))) { 51535 //if there are no accessible outputs (see textOutput() and gridOutput()) 51536 var _html2 = '<div id="'.concat(cnvId).concat(labelContainer, '" class="p5Label"><table id="').concat(cnvId).concat(labelTableId, '"></table></div>'); 51537 if (!this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutputLabel'))) { 51538 //create container + table for element descriptions 51539 this.dummyDOM.querySelector('#' + cnvId).insertAdjacentHTML('afterend', _html2); 51540 } else { 51541 //create container + table for element descriptions before outputs 51542 this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutputLabel')).insertAdjacentHTML('beforebegin', _html2); 51543 } 51544 } else if (!this.dummyDOM.querySelector('#'.concat(cnvId + labelTableId))) { 51545 //if describe() has already created the label container and added a description 51546 //and there is no table create label table for element description after 51547 //label description 51548 this.dummyDOM.querySelector('#' + cnvId + labelDescId
51548).insertAdjacentHTML('afterend', '<table id="'.concat(cnvId + labelTableId, '"></table>')); 51549 } //create a table row for the element label description 51550 51551 var _tableRow = document.createElement('tr'); 51552 _tableRow.id = cnvId + labelTableElId + name; 51553 this.dummyDOM.querySelector('#' + cnvId + labelTableId).appendChild(_tableRow); //update element label description 51554 this.descriptions.labelElements[name] = this.dummyDOM.querySelector('#'.concat(cnvId).concat(labelTableElId).concat(name)); 51555 this.descriptions.labelElements[name].innerHTML = text; 51556 } 51557 }; 51558 var _default = _main.default; 51559 exports.default = _default; 51560 }, 51561 { 51562 '../core/main': 290, 51563 'core-js/modules/es.array.concat': 167, 51564 'core-js/modules/es.regexp.exec': 199, 51565 'core-js/modules/es.string.ends-with': 202, 51566 'core-js/modules/es.string.replace': 207 51567 } 51568 ], 51569 270: [ 51570 function (_dereq_, module, exports) { 51571 'use strict'; 51572 _dereq_('core-js/modules/es.array.concat'); 51573 _dereq_('core-js/modules/es.array.map'); 51574 _dereq_('core-js/modules/es.array.concat'); 51575 _dereq_('core-js/modules/es.array.map'); 51576 Object.defineProperty(exports, '__esModule', { 51577 value: true 51578 }); 51579 exports.default = void 0; 51580 var _main = _interopRequireDefault(_dereq_('../core/main')); 51581 function _interopRequireDefault(obj) { 51582 return obj && obj.__esModule ? obj : { 51583 default: 51584 obj 51585 }; 51586 } /** 51587 * @module Environment 51588 * @submodule Environment 51589 * @for p5 51590 * @requires core 51591 */ 51592 //the functions in this file support updating the grid output 51593 //updates gridOutput 51594 51595 _main.default.prototype._updateGridOutput = function (idT) { 51596 //if html structure is not there yet 51597 if (!this.dummyDOM.querySelector('#'.concat(idT, '_summary'))) { 51598 return; 51599 } 51600 var current = this._accessibleOutputs[idT]; //create shape details list 51601 var innerShapeDetails = _gridShapeDetails(idT, this.ingredients.shapes); //create summary 51602 var innerSummary = _gridSummary(innerShapeDetails.numShapes, this.ingredients.colors.background, this.width, this.height); //create grid map 51603 var innerMap = _gridMap(idT, this.ingredients.shapes); //if it is different from current summary 51604 if (innerSummary !== current.summary.innerHTML) { 51605 //update 51606 current.summary.innerHTML = innerSummary; 51607 } //if it is different from current map 51608 51609 if (innerMap !== current.map.innerHTML) { 51610 //update 51611 current.map.innerHTML = innerMap; 51612 } //if it is different from current shape details 51613 51614 if (innerShapeDetails.details !== current.shapeDetails.innerHTML) { 51615 //update 51616 current.shapeDetails.innerHTML = innerShapeDetails.details; 51617 } 51618 this._accessibleOutputs[idT] = current; 51619 }; //creates spatial grid that maps the location of shapes 51620 function _gridMap(idT, ingredients) { 51621 var shapeNumber = 0; 51622 var table = ''; //create an array of arrays 10*10 of empty cells 51623 var cells = Array.apply(null, Array(10)).map(function () { 51624 }); 51625 for (var r in cells) { 51626 cells[r] = Array.apply(null, Array(10)).map(function () { 51627 }); 51628 } 51629 for (var x in ingredients) { 51630 for (var y in ingredients[x]) { 51631 var fill = void 0; 51632 if (x !== 'line') { 51633 fill = '<a href="#'.concat(idT, 'shape').concat(shapeNumber, '">').concat(ingredients[x][y].color, ' ').concat(x, '</a>'); 51634 } else { 51635 fill = '<a href="#'.concat(idT, 'shape').concat(shapeNumber, '">').concat(ingredients[x][y].color, ' ').concat(x, ' midpoint</a>'); 51636 } //if empty cell of location of shape is undefined 51637 51638 if (!cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX]) { 51639 //fill it with shape info 51640 cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] = fill; //if a shape is already in that location 51641 } else { 51642 //add it 51643 cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] = cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] + ' ' + fill; 51644 } 51645 shapeNumber++; 51646 } 51647 } //make table based on array 51648 51649 for (var _r in cells) { 51650 var row = '<tr>'; 51651 for (var c in cells[_r]) { 51652 row = row + '<td>'; 51653 if (cells[_r][c] !== undefined) { 51654 row = row + cells[_r][c]; 51655 } 51656 row = row + '</td>'; 51657 } 51658 table = table + row + '</tr>'; 51659 } 51660 return table; 51661 } //creates grid summary 51662 51663 function _gridSummary(numShapes, background, width, height) { 51664 var text = ''.concat(background, ' canvas, ').concat(width, ' by ').concat(height, ' pixels, contains ').concat(numShapes[0]); 51665 if (numShapes[0] === 1) { 51666 text = ''.concat(text, ' shape: ').concat(numShapes[1]); 51667 } else { 51668 text = ''.concat(text, ' shapes: ').concat(numShapes[1]); 51669 } 51670 return text; 51671 } //creates list of shapes 51672 51673 function _gridShapeDetails(idT, ingredients) { 51674 var shapeDetails = ''; 51675 var shapes = ''; 51676 var totalShapes = 0; //goes trhough every shape type in ingredients 51677 for (var x in ingredients) { 51678 var shapeNum = 0; 51679 for (var y in ingredients[x]) { 51680 //it creates a line in a list 51681 var line = '<li id="'.concat(idT, 'shape').concat(totalShapes, '">').concat(ingredients[x][y].color, ' ').concat(x, ','); 51682 if (x === 'line') { 51683 line = line + ' location = '.concat(ingredients[x][y].pos, ', length = ').concat(ingredients[x][y].length, ' pixels'); 51684 } else { 51685 line = line + ' location = '.concat(ingredients[x][y].pos); 51686 if (x !== 'point') { 51687 line = line + ', area = '.concat(ingredients[x][y].area, ' %'); 51688 } 51689 line = line + '</li>'; 51690 } 51691 shapeDetails = shapeDetails + line; 51692 shapeNum++; 51693 totalShapes++; 51694 } 51695 if (shapeNum > 1) {
51696 shapes = ''.concat(shapes, ' ').concat(shapeNum, ' ').concat(x, 's'); 51697 } else { 51698 shapes = ''.concat(shapes, ' ').concat(shapeNum, ' ').concat(x); 51699 } 51700 } 51701 return { 51702 numShapes: [ 51703 totalShapes, 51704 shapes 51705 ], 51706 details: shapeDetails 51707 }; 51708 } 51709 var _default = _main.default; 51710 exports.default = _default; 51711 }, 51712 { 51713 '../core/main': 290, 51714 'core-js/modules/es.array.concat': 167, 51715 'core-js/modules/es.array.map': 179 51716 } 51717 ], 51718 271: [ 51719 function (_dereq_, module, exports) { 51720 'use strict'; 51721 _dereq_('core-js/modules/es.array.concat'); 51722 _dereq_('core-js/modules/es.array.fill'); 51723 _dereq_('core-js/modules/es.array.map'); 51724 _dereq_('core-js/modules/es.number.to-fixed'); 51725 _dereq_('core-js/modules/es.array.concat'); 51726 _dereq_('core-js/modules/es.array.fill'); 51727 _dereq_('core-js/modules/es.array.map'); 51728 _dereq_('core-js/modules/es.number.to-fixed'); 51729 Object.defineProperty(exports, '__esModule', { 51730 value: true 51731 }); 51732 exports.default = void 0; 51733 var _main = _interopRequireDefault(_dereq_('../core/main')); 51734 function _interopRequireDefault(obj) { 51735 return obj && obj.__esModule ? obj : { 51736 default: 51737 obj 51738 }; 51739 } /** 51740 * @module Environment 51741 * @submodule Environment 51742 * @for p5 51743 * @requires core 51744 */ 51745 /** 51746 * <code class="language-javascript">textOutput()</code> creates a screenreader 51747 * accessible output that describes the shapes present on the canvas. 51748 * The general description of the canvas includes canvas size, 51749 * canvas color, and number of elements in the canvas 51750 * (example: 'Your output is a, 400 by 400 pixels, lavender blue 51751 * canvas containing the following 4 shapes:'). This description 51752 * is followed by a list of shapes where the color, position, and area 51753 * of each shape are described (example: "orange ellipse at top left 51754 * covering 1% of the canvas"). Each element can be selected to get 51755 * more details. A table of elements is also provided. In this table, 51756 * shape, color, location, coordinates and area are described 51757 * (example: "orange ellipse location=top left area=2"). 51758 * 51759 * <code class="language-javascript">textOutput()</code> and <code class="language-javascript">textOutput(FALLBACK)</code> 51760 * make the output available in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank"> 51761 * a sub DOM inside the canvas element</a> which is accessible to screen readers. 51762 * <code class="language-javascript">textOutput(LABEL)</code> creates an 51763 * additional div with the output adjacent to the canvas, this is useful 51764 * for non-screen reader users that might want to display the output outside 51765 * of the canvas' sub DOM as they code. However, using LABEL will create 51766 * unnecessary redundancy for screen reader users. We recommend using LABEL 51767 * only as part of the development process of a sketch and removing it before 51768 * publishing or sharing with screen reader users. 51769 * 51770 * @method textOutput 51771 * @param {Constant} [display] either FALLBACK or LABEL 51772 * 51773 * @example 51774 * <div> 51775 * <code> 51776 * textOutput(); 51777 * background(148, 196, 0); 51778 * fill(255, 0, 0); 51779 * ellipse(20, 20, 20, 20); 51780 * fill(0, 0, 255); 51781 * rect(50, 50, 50, 50); 51782 * </code> 51783 * </div> 51784 * 51785 * 51786 * <div> 51787 * <code> 51788 * let x = 0; 51789 * function draw() { 51790 * textOutput(); 51791 * background(148, 196, 0); 51792 * fill(255, 0, 0); 51793 * ellipse(x, 20, 20, 20); 51794 * fill(0, 0, 255); 51795 * rect(50, 50, 50, 50); 51796 * ellipse(20, 20, 20, 20); 51797 * x += 0.1; 51798 * } 51799 * </code> 51800 * </div> 51801 * 51802 */ 51803 51804 _main.default.prototype.textOutput = function (display) { 51805 _main.default._validateParameters('textOutput', arguments); //if textOutput is already true 51806 if (this._accessibleOutputs.text) { 51807 return; 51808 } else { 51809 //make textOutput true 51810 this._accessibleOutputs.text = true; //create output for fallback 51811 this._createOutput('textOutput', 'Fallback'); 51812 if (display === this.LABEL) { 51813 //make textOutput label true 51814 this._accessibleOutputs.textLabel = true; //create output for label 51815 this._createOutput('textOutput', 'Label'); 51816 } 51817 } 51818 }; 51819 /** 51820 * <code class="language-javascript">gridOutput()</code> lays out the 51821 * content of the canvas in the form of a grid (html table) based 51822 * on the spatial location of each shape. A brief 51823 * description of the canvas is available before the table output. 51824 * This description includes: color of the background, size of the canvas, 51825 * number of objects, and object types (example: "lavender blue canvas is 51826 * 200 by 200 and contains 4 objects - 3 ellipses 1 rectangle"). The grid
51827 * describes the content spatially, each element is placed on a cell of the 51828 * table depending on its position. Within each cell an element the color 51829 * and type of shape of that element are available (example: "orange ellipse"). 51830 * These descriptions can be selected individually to get more details. 51831 * A list of elements where shape, color, location, and area are described 51832 * (example: "orange ellipse location=top left area=1%") is also available. 51833 * 51834 * <code class="language-javascript">gridOutput()</code> and <code class="language-javascript">gridOutput(FALLBACK)</code> 51835 * make the output available in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank"> 51836 * a sub DOM inside the canvas element</a> which is accessible to screen readers. 51837 * <code class="language-javascript">gridOutput(LABEL)</code> creates an 51838 * additional div with the output adjacent to the canvas, this is useful 51839 * for non-screen reader users that might want to display the output outside 51840 * of the canvas' sub DOM as they code. However, using LABEL will create 51841 * unnecessary redundancy for screen reader users. We recommend using LABEL 51842 * only as part of the development process of a sketch and removing it before 51843 * publishing or sharing with screen reader users. 51844 * 51845 * @method gridOutput 51846 * @param {Constant} [display] either FALLBACK or LABEL 51847 * 51848 * @example 51849 * <div> 51850 * <code> 51851 * gridOutput(); 51852 * background(148, 196, 0); 51853 * fill(255, 0, 0); 51854 * ellipse(20, 20, 20, 20); 51855 * fill(0, 0, 255); 51856 * rect(50, 50, 50, 50); 51857 * </code> 51858 * </div> 51859 * 51860 * 51861 * <div> 51862 * <code> 51863 * let x = 0; 51864 * function draw() { 51865 * gridOutput(); 51866 * background(148, 196, 0); 51867 * fill(255, 0, 0); 51868 * ellipse(x, 20, 20, 20); 51869 * fill(0, 0, 255); 51870 * rect(50, 50, 50, 50); 51871 * ellipse(20, 20, 20, 20); 51872 * x += 0.1; 51873 * } 51874 * </code> 51875 * </div> 51876 * 51877 */ 51878 _main.default.prototype.gridOutput = function (display) { 51879 _main.default._validateParameters('gridOutput', arguments); //if gridOutput is already true 51880 if (this._accessibleOutputs.grid) { 51881 return; 51882 } else { 51883 //make gridOutput true 51884 this._accessibleOutputs.grid = true; //create output for fallback 51885 this._createOutput('gridOutput', 'Fallback'); 51886 if (display === this.LABEL) { 51887 //make gridOutput label true 51888 this._accessibleOutputs.gridLabel = true; //create output for label 51889 this._createOutput('gridOutput', 'Label'); 51890 } 51891 } 51892 }; //helper function returns true when accessible outputs are true 51893 _main.default.prototype._addAccsOutput = function () { 51894 //if there are no accessible outputs create object with all false 51895 if (!this._accessibleOutputs) { 51896 this._accessibleOutputs = { 51897 text: false, 51898 grid: false, 51899 textLabel: false, 51900 gridLabel: false 51901 }; 51902 } 51903 return this._accessibleOutputs.grid || this._accessibleOutputs.text; 51904 }; //helper function that creates html structure for accessible outputs 51905 _main.default.prototype._createOutput = function (type, display) { 51906 var cnvId = this.canvas.id; //if there are no ingredients create object. this object stores data for the outputs 51907 if (!this.ingredients) { 51908 this.ingredients = { 51909 shapes: { 51910 }, 51911 colors: { 51912 background: 'white', 51913 fill: 'white', 51914 stroke: 'black' 51915 }, 51916 pShapes: '' 51917 }; 51918 } //if there is no dummyDOM create it 51919 51920 if (!this.dummyDOM) { 51921 this.dummyDOM = document.getElementById(cnvId).parentNode; 51922 } 51923 var cIdT, 51924 container, 51925 inner; 51926 var query = ''; 51927 if (display === 'Fallback') { 51928 cIdT = cnvId + type; 51929 container = cnvId + 'accessibleOutput'; 51930 if (!this.dummyDOM.querySelector('#'.concat(container))) { 51931 //if there is no canvas description (see describe() and describeElement()) 51932 if (!this.dummyDOM.querySelector('#'.concat(cnvId, '_Description'))) { 51933 //create html structure inside of canvas 51934 this.dummyDOM.querySelector('#'.concat(cnvId)).innerHTML = '<div id="'.concat(container, '" role="region" aria-label="Canvas Outputs"></div>'); 51935 } else { 51936 //create html structure after canvas description container 51937 this.dummyDOM.querySelector('#'.concat(cnvId, '_Description')).insertAdjacentHTML('afterend', '<div id="'.concat(container, '" role="region" aria-label="Canvas Outputs"></div>')); 51938 } 51939 } 51940 } else if (display === 'Label') { 51941 query = display; 51942 cIdT = cnvId + type + display; 51943 container = cnvId + 'accessibleOutput' + display; 51944 if (!this.dummyDOM.querySelector('#'.concat(container))) { 51945 //if there is no canvas description label (see describe() and describeElement()) 51946 if (!this.dummyDOM.querySelector('#'.concat(cnvId, '_Label'))) { 51947 //create html structure adjacent to canvas 51948 this.dummyDOM.querySelector('#'.concat(cnvId)).insertAdjacentHTML('afterend', '<div id="'.concat(container, '"></div>')); 51949 } else { 51950 //create html structure after canvas label 51951 this.dummyDOM.querySelector('#'.concat(cnvId, '_Label')).insertAdjacentHTML('afterend', '<div id="'.concat(container, '"></div>')); 51952 } 51953 } 51954 } //create an object to store the latest output. this object is used in _updateTextOutput() and _updateGridOutput() 51955 51956 this._accessibleOutputs[cIdT] = { 51957 }; 51958 if (type === 'textOutput') { 51959 query = '#'.concat(cnvId, 'gridOutput').concat(query); //query is used to check if gridOutput already exists 51960 inner = '<div id="'.concat(cIdT, '">Text Output<div id="').concat(cIdT, 'Summary" aria-label="text output summary"><p id="').concat(cIdT, '_summary"></p><ul id="').concat(cIdT, '_list"></ul></div><table id="').concat(cIdT, '_shapeDetails" summary="text output shape details"></table></div>'); //if gridOutput already exists 51961 if (this.dummyDOM.querySelector(query)) { 51962 //create textOutput before gridOutput 51963 this.dummyDOM.querySelector(query).insertAdjacentHTML('beforebegin', inner); 51964 } else { 51965 //create output inside of container 51966 this.dummyDOM.querySelector('#'.concat(container)).innerHTML = inner; 51967 } //store output html elements 51968 51969 this._accessibleOutputs[cIdT].list = this.dummyDOM.querySelector('#'.concat(cIdT, '_list')); 51970 } else if (type === 'gridOutput') { 51971 query = '#'.concat(cnvId, 'textOutput').concat(query); //query is used to check if textOutput already exists 51972 inner = '<div id="'.concat(cIdT, '">Grid Output<p id="').concat(cIdT, '_summary" aria-label="grid output summary"><table id="').concat(cIdT, '_map" summary="grid output content"></table><ul id="').concat(cIdT, '_shapeDetails" aria-label="grid output shape details"></ul></div>'); //if textOutput already exists 51973 if (this.dummyDOM.querySelector(query)) { 51974 //create gridOutput after textOutput 51975 this.dummyDOM.querySelector(query).insertAdjacentHTML('afterend', inner); 51976 } else { 51977 //create output inside of container 51978 this.dummyDOM.querySelector('#'.concat(container)).innerHTML = inner; 51979 } //store output html elements 51980 51981 this._accessibleOutputs[cIdT].map = this.dummyDOM.querySelector('#'.concat(cIdT, '_map')); 51982 } 51983 this._accessibleOutputs[cIdT].shapeDetails = this.dummyDOM.querySelector('#'.concat(cIdT, '_shapeDetails')); 51984 this._accessibleOutputs[cIdT].summary = this.dummyDOM.querySelector('#'.concat(cIdT, '_summary')); 51985 }; //this function is called at the end of setup and draw if using 51986 //accessibleOutputs and calls update functions of outputs 51987 _main.default.prototype._updateAccsOutput = function () { 51988 var cnvId = this.canvas.id; //if the shapes are not the same as before 51989 if (JSON.stringify(this.ingredients.shapes) !== this.ingredients.pShapes) {
51990 //save current shapes as string in pShapes 51991 this.ingredients.pShapes = JSON.stringify(this.ingredients.shapes); 51992 if (this._accessibleOutputs.text) { 51993 this._updateTextOutput(cnvId + 'textOutput'); 51994 } 51995 if (this._accessibleOutputs.grid) { 51996 this._updateGridOutput(cnvId + 'gridOutput'); 51997 } 51998 if (this._accessibleOutputs.textLabel) { 51999 this._updateTextOutput(cnvId + 'textOutputLabel'); 52000 } 52001 if (this._accessibleOutputs.gridLabel) { 52002 this._updateGridOutput(cnvId + 'gridOutputLabel'); 52003 } 52004 } 52005 }; //helper function that resets all ingredients when background is called 52006 //and saves background color name 52007 _main.default.prototype._accsBackground = function (args) { 52008 //save current shapes as string in pShapes 52009 this.ingredients.pShapes = JSON.stringify(this.ingredients.shapes); //empty shapes JSON 52010 this.ingredients.shapes = { 52011 }; //update background different 52012 if (this.ingredients.colors.backgroundRGBA !== args) { 52013 this.ingredients.colors.backgroundRGBA = args; 52014 this.ingredients.colors.background = this._rgbColorName(args); 52015 } 52016 }; //helper function that gets fill and stroke of shapes 52017 _main.default.prototype._accsCanvasColors = function (f, args) { 52018 if (f === 'fill') { 52019 //update fill different 52020 if (this.ingredients.colors.fillRGBA !== args) { 52021 this.ingredients.colors.fillRGBA = args; 52022 this.ingredients.colors.fill = this._rgbColorName(args); 52023 } 52024 } else if (f === 'stroke') { 52025 //update stroke if different 52026 if (this.ingredients.colors.strokeRGBA !== args) { 52027 this.ingredients.colors.strokeRGBA = args; 52028 this.ingredients.colors.stroke = this._rgbColorName(args); 52029 } 52030 } 52031 }; //builds ingredients.shapes used for building outputs 52032 _main.default.prototype._accsOutput = function (f, args) { 52033 if (f === 'ellipse' && args[2] === args[3]) { 52034 f = 'circle'; 52035 } else if (f === 'rectangle' && args[2] === args[3]) { 52036 f = 'square'; 52037 } 52038 var include = { 52039 }; 52040 var add = true; 52041 var middle = _getMiddle(f, args); 52042 if (f === 'line') { 52043 //make color stroke 52044 include.color = this.ingredients.colors.stroke; //get lenght 52045 include.length = Math.round(this.dist(args[0], args[1], args[2], args[3])); //get position of end points 52046 var p1 = _getPos([args[0], 52047 [ 52048 1 52049 ]], this.width, this.height); 52050 var p2 = _getPos([args[2], 52051 [ 52052 3 52053 ]], this.width, this.height); 52054 include.loc = _canvasLocator(middle, this.width, this.height); 52055 if (p1 === p2) { 52056 include.pos = 'at '.concat(p1); 52057 } else { 52058 include.pos = 'from '.concat(p1, ' to ').concat(p2); 52059 } 52060 } else { 52061 if (f === 'point') { 52062 //make color stroke 52063 include.color = this.ingredients.colors.stroke; 52064 } else { 52065 //make color fill 52066 include.color = this.ingredients.colors.fill; //get area of shape 52067 include.area = _getArea(f, args, this.width, this.height); 52068 } //get middle of shapes 52069 //calculate position using middle of shape 52070 52071 include.pos = _getPos(middle, this.width, this.height); //calculate location using middle of shape 52072 include.loc = _canvasLocator(middle, this.width, this.height); 52073 } //if it is the first time this shape is created 52074 52075 if (!this.ingredients.shapes[f]) { 52076 this.ingredients.shapes[f] = [ 52077 include 52078 ]; //if other shapes of this type have been created 52079 } else if (this.ingredients.shapes[f] !== [include]) { 52080 //for every shape of this type 52081 for (var y in this.ingredients.shapes[f]) { 52082 //compare it with current shape and if it already exists make add false 52083 if (JSON.stringify(this.ingredients.shapes[f][y]) === JSON.stringify(include)) { 52084 add = false;
52085 } 52086 } //add shape by pushing it to the end 52087 52088 if (add === true) { 52089 this.ingredients.shapes[f].push(include); 52090 } 52091 } 52092 }; //gets middle point / centroid of shape 52093 function _getMiddle(f, args) { 52094 var x, 52095 y; 52096 if (f === 'rectangle' || f === 'ellipse' || f === 'arc' || f === 'circle' || f === 'square') { 52097 x = Math.round(args[0] + args[2] / 2); 52098 y = Math.round(args[1] + args[3] / 2); 52099 } else if (f === 'triangle') { 52100 x = (args[0] + args[2] + args[4]) / 3; 52101 y = (args[1] + args[3] + args[5]) / 3; 52102 } else if (f === 'quadrilateral') { 52103 x = (args[0] + args[2] + args[4] + args[6]) / 4; 52104 y = (args[1] + args[3] + args[5] + args[7]) / 4; 52105 } else if (f === 'line') { 52106 x = (args[0] + args[2]) / 2; 52107 y = (args[1] + args[3]) / 2; 52108 } else { 52109 x = args[0]; 52110 y = args[1]; 52111 } 52112 return [x, 52113 y]; 52114 } //gets position of shape in the canvas 52115 52116 function _getPos(args, canvasWidth, canvasHeight) { 52117 if (args[0] < 0.4 * canvasWidth) { 52118 if (args[1] < 0.4 * canvasHeight) { 52119 return 'top left'; 52120 } else if (args[1] > 0.6 * canvasHeight) { 52121 return 'bottom left'; 52122 } else { 52123 return 'mid left'; 52124 } 52125 } else if (args[0] > 0.6 * canvasWidth) { 52126 if (args[1] < 0.4 * canvasHeight) { 52127 return 'top right'; 52128 } else if (args[1] > 0.6 * canvasHeight) { 52129 return 'bottom right'; 52130 } else { 52131 return 'mid right'; 52132 } 52133 } else { 52134 if (args[1] < 0.4 * canvasHeight) { 52135 return 'top middle'; 52136 } else if (args[1] > 0.6 * canvasHeight) { 52137 return 'bottom middle'; 52138 } else { 52139 return 'middle'; 52140 } 52141 } 52142 } //locates shape in a 10*10 grid 52143 52144 function _canvasLocator(args, canvasWidth, canvasHeight) { 52145 var noRows = 10; 52146 var noCols = 10; 52147 var locX = Math.floor(args[0] / canvasWidth * noRows); 52148 var locY = Math.floor(args[1] / canvasHeight * noCols); 52149 if (locX === noRows) { 52150 locX = locX - 1; 52151 } 52152 if (locY === noCols) { 52153 locY = locY - 1; 52154 } 52155 return { 52156 locX: locX, 52157 locY: locY 52158 }; 52159 } //calculates area of shape 52160 52161 function _getArea(objectType, shapeArgs, canvasWidth, canvasHeight) { 52162 var objectArea = 0; 52163 if (objectType === 'arc') { 52164 // area of full ellipse = PI * horizontal radius * vertical radius. 52165 // therefore, area of arc = difference bet. arc's start and end radians * horizontal radius * vertical radius. 52166 // the below expression is adjusted for negative values and differences in arc's start and end radians over PI*2 52167 var arcSizeInRadians = ((shapeArgs[5] - shapeArgs[4]) % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2); 52168 objectArea = arcSizeInRadians * shapeArgs[2] * shapeArgs[3] / 8; 52169 if (shapeArgs[6] === 'open' || shapeArgs[6] === 'chord') { 52170 // when the arc's mode is OPEN or CHORD, we need to account for the area of the triangle that is formed to close the arc 52171 // (Ax( By â Cy) + Bx(Cy â Ay) + Cx(Ay â By ) )/2 52172 var Ax = shapeArgs[0]; 52173 var Ay = shapeArgs[1]; 52174 var Bx = shapeArgs[0] + shapeArgs[2] / 2 * Math.cos(shapeArgs[4]).toFixed(2); 52175 var By = shapeArgs[1] + shapeArgs[3] / 2 * Math.sin(shapeArgs[4]).toFixed(2); 52176 var Cx = shapeArgs[0] + shapeArgs[2] / 2 * Math.cos(shapeArgs[5]).toFixed(2); 52177 var Cy = shapeArgs[1] + shapeArgs[3] / 2 * Math.sin(shapeArgs[5]).toFixed(2); 52178 var areaOfExtraTriangle = Math.abs(Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By)) / 2; 52179 if (arcSizeInRadians > Math.PI) { 52180 objectArea = objectArea + areaOfExtraTriangle; 52181 } else { 52182 objectArea = objectArea - areaOfExtraTriangle; 52183 } 52184 } 52185 } else if (objectType === 'ellipse' || objectType === 'circle') { 52186 objectArea = 3.14 * shapeArgs[2] / 2 * shapeArgs[3] / 2; 52187 } else if (objectType === 'line') { 52188 objectArea = 0; 52189 } else if (objectType === 'point') { 52190 objectArea = 0; 52191 } else if (objectType === 'quadrilateral') { 52192 // ((x4+x1)*(y4-y1)+(x1+x2)*(y1-y2)+(x2+x3)*(y2-y3)+(x3+x4)*(y3-y4))/2 52193 objectArea = Math.abs((shapeArgs[6] + shapeArgs[0]) * (shapeArgs[7] - shapeArgs[1]) + (shapeArgs[0] + shapeArgs[2]) * (shapeArgs[1] - shapeArgs[3]) + (shapeArgs[2] + shapeArgs[4]) * (shapeArgs[3] - shapeArgs[5]) + (shapeArgs[4] + shapeArgs[6]) * (shapeArgs[5] - shapeArgs[7])) / 2; 52194 } else if (objectType === 'rectangle' || objectType === 'square') { 52195 objectArea = shapeArgs[2] * shapeArgs[3]; 52196 } else if (objectType === 'triangle') { 52197 objectArea = Math.abs(shapeArgs[0] * (shapeArgs[3] - shapeArgs[5]) + shapeArgs[2] * (shapeArgs[5] - shapeArgs[1]) + shapeArgs[4] * (shapeArgs[1] - shapeArgs[3])) / 2; // (Ax( By â Cy) + Bx(Cy â Ay) + Cx(Ay â By ))/2 52198 } 52199 return Math.round(objectArea * 100 / (canvasWidth * canvasHeight)); 52200 } 52201 var _default = _main.default; 52202 exports.default = _default; 52203 }, 52204 { 52205 '../core/main': 290,
52206 'core-js/modules/es.array.concat': 167, 52207 'core-js/modules/es.array.fill': 170, 52208 'core-js/modules/es.array.map': 179, 52209 'core-js/modules/es.number.to-fixed': 189 52210 } 52211 ], 52212 272: [ 52213 function (_dereq_, module, exports) { 52214 'use strict'; 52215 _dereq_('core-js/modules/es.array.concat'); 52216 _dereq_('core-js/modules/es.array.concat'); 52217 Object.defineProperty(exports, '__esModule', { 52218 value: true 52219 }); 52220 exports.default = void 0; 52221 var _main = _interopRequireDefault(_dereq_('../core/main')); 52222 function _interopRequireDefault(obj) { 52223 return obj && obj.__esModule ? obj : { 52224 default: 52225 obj 52226 }; 52227 } /** 52228 * @module Environment 52229 * @submodule Environment 52230 * @for p5 52231 * @requires core 52232 */ 52233 //the functions in this file support updating the text output 52234 //updates textOutput 52235 52236 _main.default.prototype._updateTextOutput = function (idT) { 52237 //if html structure is not there yet 52238 if (!this.dummyDOM.querySelector('#'.concat(idT, '_summary'))) { 52239 return; 52240 } 52241 var current = this._accessibleOutputs[idT]; //create shape list 52242 var innerList = _shapeList(idT, this.ingredients.shapes); //create output summary 52243 var innerSummary = _textSummary(innerList.numShapes, this.ingredients.colors.background, this.width, this.height); //create shape details 52244 var innerShapeDetails = _shapeDetails(idT, this.ingredients.shapes); //if it is different from current summary 52245 if (innerSummary !== current.summary.innerHTML) { 52246 //update 52247 current.summary.innerHTML = innerSummary; 52248 } //if it is different from current shape list 52249 52250 if (innerList.listShapes !== current.list.innerHTML) { 52251 //update 52252 current.list.innerHTML = innerList.listShapes; 52253 } //if it is different from current shape details 52254 52255 if (innerShapeDetails !== current.shapeDetails.innerHTML) { 52256 //update 52257 current.shapeDetails.innerHTML = innerShapeDetails; 52258 } 52259 this._accessibleOutputs[idT] = current; 52260 }; //Builds textOutput summary 52261 function _textSummary(numShapes, background, width, height) { 52262 var text = 'Your output is a, '.concat(width, ' by ').concat(height, ' pixels, ').concat(background, ' canvas containing the following'); 52263 if (numShapes === 1) { 52264 text = ''.concat(text, ' shape:'); 52265 } else { 52266 text = ''.concat(text, ' ').concat(numShapes, ' shapes:'); 52267 } 52268 return text; 52269 } //Builds textOutput table with shape details 52270 52271 function _shapeDetails(idT, ingredients) { 52272 var shapeDetails = ''; 52273 var shapeNumber = 0; //goes trhough every shape type in ingredients 52274 for (var x in ingredients) { 52275 //and for every shape 52276 for (var y in ingredients[x]) { 52277 //it creates a table row 52278 var row = '<tr id="'.concat(idT, 'shape').concat(shapeNumber, '"><th>').concat(ingredients[x][y].color, ' ').concat(x, '</th>'); 52279 if (x === 'line') { 52280 row = row + '<td>location = '.concat(ingredients[x][y].pos, '</td><td>length = ').concat(ingredients[x][y].length, ' pixels</td></tr>'); 52281 } else { 52282 row = row + '<td>location = '.concat(ingredients[x][y].pos, '</td>'); 52283 if (x !== 'point') { 52284 row = row + '<td> area = '.concat(ingredients[x][y].area, '%</td>'); 52285 } 52286 row = row + '</tr>'; 52287 } 52288 shapeDetails = shapeDetails + row; 52289 shapeNumber++; 52290 } 52291 } 52292 return shapeDetails; 52293 } //Builds textOutput shape list 52294 52295 function _shapeList(idT, ingredients) { 52296 var shapeList = ''; 52297 var shapeNumber = 0; //goes trhough every shape type in ingredients 52298 for (var x in ingredients) { 52299 for (var y in ingredients[x]) { 52300 //it creates a line in a list 52301 var _line = '<li><a href="#'.concat(idT, 'shape').concat(shapeNumber, '">').concat(ingredients[x][y].color, ' ').concat(x, '</a>'); 52302 if (x === 'line') { 52303 _line = _line + ', '.concat(ingredients[x][y].pos, ', ').concat(ingredients[x][y].length, ' pixels long.</li>'); 52304 } else { 52305 _line = _line + ', at '.concat(ingredients[x][y].pos); 52306 if (x !== 'point') { 52307 _line = _line + ', covering '.concat(ingredients[x][y].area, '% of the canvas'); 52308 } 52309 _line = _line + '.</li>'; 52310 } 52311 shapeList = shapeList + _line; 52312 shapeNumber++; 52313 } 52314 } 52315 return { 52316 numShapes: shapeNumber, 52317 listShapes: shapeList 52318 }; 52319 } 52320 var _default = _main.default; 52321 exports.default = _default; 52322 }, 52323 { 52324 '../core/main': 290,
52325 'core-js/modules/es.array.concat': 167 52326 } 52327 ], 52328 273: [ 52329 function (_dereq_, module, exports) { 52330 'use strict'; 52331 var _main = _interopRequireDefault(_dereq_('./core/main')); 52332 _dereq_('./core/constants'); 52333 _dereq_('./core/environment'); 52334 _dereq_('./core/friendly_errors/stacktrace'); 52335 _dereq_('./core/friendly_errors/validate_params'); 52336 _dereq_('./core/friendly_errors/file_errors'); 52337 _dereq_('./core/friendly_errors/fes_core'); 52338 _dereq_('./core/friendly_errors/sketch_reader'); 52339 _dereq_('./core/helpers'); 52340 _dereq_('./core/legacy'); 52341 _dereq_('./core/preload'); 52342 _dereq_('./core/p5.Element'); 52343 _dereq_('./core/p5.Graphics'); 52344 _dereq_('./core/p5.Renderer'); 52345 _dereq_('./core/p5.Renderer2D'); 52346 _dereq_('./core/rendering'); 52347 _dereq_('./core/shim'); 52348 _dereq_('./core/structure'); 52349 _dereq_('./core/transform'); 52350 _dereq_('./core/shape/2d_primitives'); 52351 _dereq_('./core/shape/attributes'); 52352 _dereq_('./core/shape/curves'); 52353 _dereq_('./core/shape/vertex'); 52354 _dereq_('./accessibility/outputs'); 52355 _dereq_('./accessibility/textOutput'); 52356 _dereq_('./accessibility/gridOutput'); 52357 _dereq_('./accessibility/color_namer'); 52358 _dereq_('./color/color_conversion'); 52359 _dereq_('./color/creating_reading'); 52360 _dereq_('./color/p5.Color'); 52361 _dereq_('./color/setting'); 52362 _dereq_('./data/p5.TypedDict'); 52363 _dereq_('./data/local_storage.js'); 52364 _dereq_('./dom/dom'); 52365 _dereq_('./accessibility/describe'); 52366 _dereq_('./events/acceleration'); 52367 _dereq_('./events/keyboard'); 52368 _dereq_('./events/mouse'); 52369 _dereq_('./events/touch'); 52370 _dereq_('./image/filters'); 52371 _dereq_('./image/image'); 52372 _dereq_('./image/loading_displaying'); 52373 _dereq_('./image/p5.Image'); 52374 _dereq_('./image/pixels'); 52375 _dereq_('./io/files'); 52376 _dereq_('./io/p5.Table'); 52377 _dereq_('./io/p5.TableRow'); 52378 _dereq_('./io/p5.XML'); 52379 _dereq_('./math/calculation'); 52380 _dereq_('./math/math'); 52381 _dereq_('./math/noise'); 52382 _dereq_('./math/p5.Vector'); 52383 _dereq_('./math/random'); 52384 _dereq_('./math/trigonometry'); 52385 _dereq_('./typography/attributes'); 52386 _dereq_('./typography/loading_displaying'); 52387 _dereq_('./typography/p5.Font'); 52388 _dereq_('./utilities/array_functions'); 52389 _dereq_('./utilities/conversion'); 52390 _dereq_('./utilities/string_functions'); 52391 _dereq_('./utilities/time_date'); 52392 _dereq_('./webgl/3d_primitives'); 52393 _dereq_('./webgl/interaction'); 52394 _dereq_('./webgl/light'); 52395 _dereq_('./webgl/loading'); 52396 _dereq_('./webgl/material'); 52397 _dereq_('./webgl/p5.Camera'); 52398 _dereq_('./webgl/p5.Geometry'); 52399 _dereq_('./webgl/p5.Matrix'); 52400 _dereq_('./webgl/p5.RendererGL.Immediate'); 52401 _dereq_('./webgl/p5.RendererGL'); 52402 _dereq_('./webgl/p5.RendererGL.Retained'); 52403 _dereq_('./webgl/p5.Shader'); 52404 _dereq_('./webgl/p5.RenderBuffer'); 52405 _dereq_('./webgl/p5.Texture'); 52406 _dereq_('./webgl/text'); 52407 _dereq_('./core/init'); 52408 function _interopRequireDefault(obj) { 52409 return obj && obj.__esModule ? obj : { 52410 default: 52411 obj 52412 }; 52413 } // core 52414 //accessibility 52415 // color 52416 // data 52417 // DOM 52418 // accessibility 52419 // events 52420 // image 52421 // io 52422 // math 52423 // typography 52424 // utilities 52425 // webgl 52426 52427 module.exports = _main.default; 52428 }, 52429 { 52430 './accessibility/color_namer': 268, 52431 './accessibility/describe': 269, 52432 './accessibility/gridOutput': 270, 52433 './accessibility/outputs': 271, 52434 './accessibility/textOutput': 272, 52435 './color/color_conversion': 274, 52436 './color/creating_reading': 275, 52437 './color/p5.Color': 276, 52438 './color/setting': 277, 52439 './core/constants': 278, 52440 './core/environment': 279, 52441 './core/friendly_errors/fes_core': 281, 52442 './core/friendly_errors/file_errors': 282, 52443 './core/friendly_errors/sketch_reader': 283, 52444 './core/friendly_errors/stacktrace': 284, 52445 './core/friendly_errors/validate_params': 285, 52446 './core/helpers': 286, 52447 './core/init': 287, 52448 './core/legacy': 289, 52449 './core/main': 290, 52450 './core/p5.Element': 291, 52451 './core/p5.Graphics': 292, 52452 './core/p5.Renderer': 293, 52453 './core/p5.Renderer2D': 294, 52454 './core/preload': 295, 52455 './core/rendering': 296, 52456 './core/shape/2d_primitives': 297, 52457 './core/shape/attributes': 298, 52458 './core/shape/curves': 299, 52459 './core/shape/vertex': 300, 52460 './core/shim': 301, 52461 './core/structure': 302, 52462 './core/transform': 303, 52463 './data/local_storage.js': 304, 52464 './data/p5.TypedDict': 305, 52465 './dom/dom': 306, 52466 './events/acceleration': 307, 52467 './events/keyboard': 308, 52468 './events/mouse': 309, 52469 './events/touch': 310, 52470 './image/filters': 311, 52471 './image/image': 312, 52472 './image/loading_displaying': 313, 52473 './image/p5.Image': 314, 52474 './image/pixels': 315, 52475 './io/files': 316, 52476 './io/p5.Table': 317, 52477 './io/p5.TableRow': 318, 52478 './io/p5.XML': 319, 52479 './math/calculation': 320, 52480 './math/math': 321, 52481 './math/noise': 322, 52482 './math/p5.Vector': 323, 52483 './math/random': 324, 52484 './math/trigonometry': 325, 52485 './typography/attributes': 326, 52486 './typography/loading_displaying': 327,
52487 './typography/p5.Font': 328, 52488 './utilities/array_functions': 329, 52489 './utilities/conversion': 330, 52490 './utilities/string_functions': 331, 52491 './utilities/time_date': 332, 52492 './webgl/3d_primitives': 333, 52493 './webgl/interaction': 334, 52494 './webgl/light': 335, 52495 './webgl/loading': 336, 52496 './webgl/material': 337, 52497 './webgl/p5.Camera': 338, 52498 './webgl/p5.Geometry': 339, 52499 './webgl/p5.Matrix': 340, 52500 './webgl/p5.RenderBuffer': 341, 52501 './webgl/p5.RendererGL': 344, 52502 './webgl/p5.RendererGL.Immediate': 342, 52503 './webgl/p5.RendererGL.Retained': 343, 52504 './webgl/p5.Shader': 345, 52505 './webgl/p5.Texture': 346, 52506 './webgl/text': 347 52507 } 52508 ], 52509 274: [ 52510 function (_dereq_, module, exports) { 52511 'use strict'; 52512 Object.defineProperty(exports, '__esModule', { 52513 value: true 52514 }); 52515 exports.default = void 0; 52516 var _main = _interopRequireDefault(_dereq_('../core/main')); 52517 function _interopRequireDefault(obj) { 52518 return obj && obj.__esModule ? obj : { 52519 default: 52520 obj 52521 }; 52522 } /** 52523 * @module Color 52524 * @submodule Color Conversion 52525 * @for p5 52526 * @requires core 52527 */ 52528 /** 52529 * Conversions adapted from <http://www.easyrgb.com/en/math.php>. 52530 * 52531 * In these functions, hue is always in the range [0, 1], just like all other 52532 * components are in the range [0, 1]. 'Brightness' and 'value' are used 52533 * interchangeably. 52534 */ 52535 52536 _main.default.ColorConversion = { 52537 }; 52538 /** 52539 * Convert an HSBA array to HSLA. 52540 */ 52541 _main.default.ColorConversion._hsbaToHSLA = function (hsba) { 52542 var hue = hsba[0]; 52543 var sat = hsba[1]; 52544 var val = hsba[2]; // Calculate lightness. 52545 var li = (2 - sat) * val / 2; // Convert saturation. 52546 if (li !== 0) { 52547 if (li === 1) { 52548 sat = 0; 52549 } else if (li < 0.5) { 52550 sat = sat / (2 - sat); 52551 } else { 52552 sat = sat * val / (2 - li * 2); 52553 } 52554 } // Hue and alpha stay the same. 52555 52556 return [hue, 52557 sat, 52558 li, 52559 hsba[3]]; 52560 }; 52561 /** 52562 * Convert an HSBA array to RGBA. 52563 */ 52564 _main.default.ColorConversion._hsbaToRGBA = function (hsba) { 52565 var hue = hsba[0] * 6; // We will split hue into 6 sectors. 52566 var sat = hsba[1]; 52567 var val = hsba[2]; 52568 var RGBA = [ 52569 ]; 52570 if (sat === 0) { 52571 RGBA = [ 52572 val, 52573 val, 52574 val, 52575 hsba[3] 52576 ]; // Return early if grayscale. 52577 } else { 52578 var sector = Math.floor(hue); 52579 var tint1 = val * (1 - sat); 52580 var tint2 = val * (1 - sat * (hue - sector)); 52581 var tint3 = val * (1 - sat * (1 + sector - hue)); 52582 var red, 52583 green, 52584 blue; 52585 if (sector === 1) { 52586 // Yellow to green. 52587 red = tint2; 52588 green = val; 52589 blue = tint1; 52590 } else if (sector === 2) { 52591 // Green to cyan. 52592 red = tint1; 52593 green = val; 52594 blue = tint3; 52595 } else if (sector === 3) { 52596 // Cyan to blue. 52597 red = tint1; 52598 green = tint2; 52599 blue = val; 52600 } else if (sector === 4) { 52601 // Blue to magenta. 52602 red = tint3; 52603 green = tint1; 52604 blue = val; 52605 } else if (sector === 5) { 52606 // Magenta to red. 52607 red = val; 52608 green = tint1; 52609 blue = tint2; 52610 } else { 52611 // Red to yellow (sector could be 0 or 6). 52612 red = val; 52613 green = tint3; 52614 blue = tint1; 52615 } 52616 RGBA = [ 52617 red, 52618 green, 52619 blue, 52620 hsba[3] 52621 ]; 52622 } 52623 return RGBA; 52624 }; 52625 /** 52626 * Convert an HSLA array to HSBA. 52627 */ 52628 _main.default.ColorConversion._hslaToHSBA = function (hsla) { 52629 var hue = hsla[0]; 52630 var sat = hsla[1]; 52631 var li = hsla[2]; // Calculate brightness. 52632 var val; 52633 if (li < 0.5) { 52634 val = (1 + sat) * li; 52635 } else { 52636 val = li + sat - li * sat; 52637 } // Convert saturation. 52638 52639 sat = 2 * (val - li) / val; // Hue and alpha stay the same. 52640 return [hue, 52641 sat, 52642 val, 52643 hsla[3]]; 52644 }; 52645 /** 52646 * Convert an HSLA array to RGBA. 52647 * 52648 * We need to change basis from HSLA to something that can be more easily be 52649 * projected onto RGBA. We will choose hue and brightness as our first two 52650 * components, and pick a convenient third one ('zest') so that we don't need 52651 * to calculate formal HSBA saturation. 52652 */ 52653 _main.default.ColorConversion._hslaToRGBA = function (hsla) { 52654 var hue = hsla[0] * 6; // We will split hue into 6 sectors. 52655 var sat = hsla[1]; 52656 var li = hsla[2]; 52657 var RGBA = [ 52658 ]; 52659 if (sat === 0) { 52660 RGBA = [ 52661 li, 52662 li, 52663 li, 52664 hsla[3] 52665 ]; // Return early if grayscale. 52666 } else { 52667 // Calculate brightness. 52668 var val; 52669 if (li < 0.5) { 52670 val = (1 + sat) * li; 52671 } else { 52672 val = li + sat - li * sat; 52673 } // Define zest. 52674 52675 var zest = 2 * li - val; // Implement projection (project onto green by default). 52676 var hzvToRGB = function hzvToRGB(hue, zest, val) { 52677 if (hue < 0) { 52678 // Hue must wrap to allow projection onto red and blue. 52679 hue += 6; 52680 } else if (hue >= 6) { 52681 hue -= 6; 52682 } 52683 if (hue < 1) { 52684 // Red to yellow (increasing green). 52685 return zest + (val - zest) * hue; 52686 } else if (hue < 3) { 52687 // Yellow to cyan (greatest green). 52688 return val; 52689 } else if (hue < 4) { 52690 // Cyan to blue (decreasing green). 52691 return zest + (val - zest) * (4 - hue); 52692 } else { 52693 // Blue to red (least green). 52694 return zest; 52695 } 52696 }; // Perform projections, offsetting hue as necessary. 52697 RGBA = [ 52698 hzvToRGB(hue + 2, zest, val), 52699 hzvToRGB(hue, zest, val), 52700 hzvToRGB(hue - 2, zest, val), 52701 hsla[3] 52702 ]; 52703 } 52704 return RGBA; 52705 }; 52706 /** 52707 * Convert an RGBA array to HSBA. 52708 */ 52709 _main.default.ColorConversion._rgbaToHSBA = function (rgba) { 52710 var red = rgba[0]; 52711 var green = rgba[1]; 52712 var blue = rgba[2]; 52713 var val = Math.max(red, green, blue); 52714 var chroma = val - Math.min(red, green, blue); 52715 var hue, 52716 sat; 52717 if (chroma === 0) { 52718 // Return early if grayscale. 52719 hue = 0; 52720 sat = 0; 52721 } else { 52722 sat = chroma / val; 52723 if (red === val) { 52724 // Magenta to yellow. 52725 hue = (green - blue) / chroma; 52726 } else if (green === val) { 52727 // Yellow to cyan. 52728 hue = 2 + (blue - red) / chroma; 52729 } else if (blue === val) { 52730 // Cyan to magenta. 52731 hue = 4 + (red - green) / chroma; 52732 } 52733 if (hue < 0) { 52734 // Confine hue to the interval [0, 1). 52735 hue += 6; 52736 } else if (hue >= 6) { 52737 hue -= 6; 52738 } 52739 } 52740 return [hue / 6, 52741 sat, 52742 val, 52743 rgba[3]]; 52744 }; 52745 /** 52746 * Convert an RGBA array to HSLA. 52747 */ 52748 _main.default.ColorConversion._rgbaToHSLA = function (rgba) { 52749 var red = rgba[0]; 52750 var green = rgba[1]; 52751 var blue = rgba[2]; 52752 var val = Math.max(red, green, blue); 52753 var min = Math.min(red, green, blue); 52754 var li = val + min; // We will halve this later. 52755 var chroma = val - min; 52756 var hue, 52757 sat; 52758 if (chroma === 0) { 52759 // Return early if grayscale. 52760 hue = 0; 52761 sat = 0; 52762 } else { 52763 if (li < 1) { 52764 sat = chroma / li; 52765 } else { 52766 sat = chroma / (2 - li); 52767 } 52768 if (red === val) { 52769 // Magenta to yellow. 52770 hue = (green - blue) / chroma; 52771 } else if (green === val) { 52772 // Yellow to cyan. 52773 hue = 2 + (blue - red) / chroma; 52774 } else if (blue === val) { 52775 // Cyan to magenta. 52776 hue = 4 + (red - green) / chroma; 52777 } 52778 if (hue < 0) { 52779 // Confine hue to the interval [0, 1). 52780 hue += 6; 52781 } else if (hue >= 6) { 52782 hue -= 6; 52783 } 52784 } 52785 return [hue / 6, 52786 sat, 52787 li / 2, 52788 rgba[3]]; 52789 }; 52790 var _default = _main.default.ColorConversion; 52791 exports.default = _default; 52792 }, 52793 { 52794 '../core/main': 290 52795 } 52796 ], 52797 275: [
52798 function (_dereq_, module, exports) { 52799 'use strict'; 52800 _dereq_('core-js/modules/es.symbol'); 52801 _dereq_('core-js/modules/es.symbol.description'); 52802 _dereq_('core-js/modules/es.symbol.iterator'); 52803 _dereq_('core-js/modules/es.array.iterator'); 52804 _dereq_('core-js/modules/es.array.map'); 52805 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 52806 _dereq_('core-js/modules/es.object.to-string'); 52807 _dereq_('core-js/modules/es.string.iterator'); 52808 _dereq_('core-js/modules/es.weak-map'); 52809 _dereq_('core-js/modules/web.dom-collections.iterator'); 52810 function _typeof2(obj) { 52811 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 52812 _typeof2 = function _typeof2(obj) { 52813 return typeof obj; 52814 }; 52815 } else { 52816 _typeof2 = function _typeof2(obj) { 52817 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 52818 }; 52819 } 52820 return _typeof2(obj); 52821 } 52822 function _typeof(obj) { 52823 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 52824 _typeof = function _typeof(obj) { 52825 return _typeof2(obj); 52826 }; 52827 } else { 52828 _typeof = function _typeof(obj) { 52829 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 52830 }; 52831 } 52832 return _typeof(obj); 52833 } 52834 _dereq_('core-js/modules/es.array.map'); 52835 Object.defineProperty(exports, '__esModule', { 52836 value: true 52837 }); 52838 exports.default = void 0; 52839 var _main = _interopRequireDefault(_dereq_('../core/main')); 52840 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 52841 _dereq_('./p5.Color'); 52842 _dereq_('../core/friendly_errors/validate_params'); 52843 _dereq_('../core/friendly_errors/file_errors'); 52844 _dereq_('../core/friendly_errors/fes_core'); 52845 function _getRequireWildcardCache() { 52846 if (typeof WeakMap !== 'function') return null; 52847 var cache = new WeakMap(); 52848 _getRequireWildcardCache = function _getRequireWildcardCache() { 52849 return cache; 52850 }; 52851 return cache; 52852 } 52853 function _interopRequireWildcard(obj) { 52854 if (obj && obj.__esModule) { 52855 return obj; 52856 } 52857 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 52858 return { 52859 default: 52860 obj 52861 }; 52862 } 52863 var cache = _getRequireWildcardCache(); 52864 if (cache && cache.has(obj)) { 52865 return cache.get(obj); 52866 } 52867 var newObj = { 52868 }; 52869 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 52870 for (var key in obj) { 52871 if (Object.prototype.hasOwnProperty.call(obj, key)) { 52872 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 52873 if (desc && (desc.get || desc.set)) { 52874 Object.defineProperty(newObj, key, desc); 52875 } else { 52876 newObj[key] = obj[key]; 52877 } 52878 } 52879 } 52880 newObj.default = obj; 52881 if (cache) { 52882 cache.set(obj, newObj); 52883 } 52884 return newObj; 52885 } 52886 function _interopRequireDefault(obj) { 52887 return obj && obj.__esModule ? obj : { 52888 default: 52889 obj 52890 }; 52891 } /** 52892 * @module Color 52893 * @submodule Creating & Reading 52894 * @for p5 52895 * @requires core 52896 * @requires constants 52897 */ 52898 /** 52899 * Extracts the alpha value from a color or pixel array. 52900 * 52901 * @method alpha 52902 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 52903 * or CSS color 52904 * @return {Number} the alpha value 52905 * 52906 * @example 52907 * <div> 52908 * <code> 52909 * noStroke(); 52910 * let c = color(0, 126, 255, 102); 52911 * fill(c); 52912 * rect(15, 15, 35, 70); 52913 * let value = alpha(c); // Sets 'value' to 102 52914 * fill(value); 52915 * rect(50, 15, 35, 70); 52916 * describe('Left half of canvas light blue and right half light charcoal grey.'); 52917 * </code> 52918 * </div> 52919 */ 52920 52921 _main.default.prototype.alpha = function (c) { 52922 _main.default._validateParameters('alpha', arguments); 52923 return this.color(c)._getAlpha(); 52924 }; 52925 /** 52926 * Extracts the blue value from a color or pixel array. 52927 * 52928 * @method blue 52929 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 52930 * or CSS color 52931 * @return {Number} the blue value 52932 * @example 52933 * <div> 52934 * <code> 52935 * let c = color(175, 100, 220); 52936 * fill(c); 52937 * rect(15, 20, 35, 60); // Draw left rectangle 52938 * let blueValue = blue(c); 52939 * fill(0, 0, blueValue); 52940 * rect(50, 20, 35, 60); // Draw right rectangle 52941 * describe('Left half of canvas light purple and right half a royal blue.'); 52942 * </code> 52943 * </div> 52944 * 52945 */ 52946 _main.default.prototype.blue = function (c) { 52947 _main.default._validateParameters('blue', arguments); 52948 return this.color(c)._getBlue(); 52949 }; 52950 /** 52951 * Extracts the HSB brightness value from a color or pixel array. 52952 * 52953 * @method brightness 52954 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 52955 * or CSS color 52956 * @return {Number} the brightness value 52957 * 52958 * @example 52959 * <div> 52960 * <code> 52961 * noStroke(); 52962 * colorMode(HSB, 255); 52963 * let c = color(0, 126, 255); 52964 * fill(c); 52965 * rect(15, 20, 35, 60); 52966 * let value = brightness(c); // Sets 'value' to 255 52967 * fill(value); 52968 * rect(50, 20, 35, 60); 52969 * describe(`Left half of canvas salmon pink and the right half with its 52970 * brightness colored white.`); 52971 * </code> 52972 * </div> 52973 * 52974 * <div> 52975 * <code> 52976 * noStroke(); 52977 * colorMode(HSB, 255); 52978 * let c = color('hsb(60, 100%, 50%)'); 52979 * fill(c); 52980 * rect(15, 20, 35, 60); 52981 * let value = brightness(c); // A 'value' of 50% is 127.5 52982 * fill(value); 52983 * rect(50, 20, 35, 60); 52984 * describe(`Left half of canvas olive colored and the right half with its 52985 * brightness color gray.`); 52986 * </code> 52987 * </div> 52988 */ 52989 _main.default.prototype.brightness = function (c) { 52990 _main.default._validateParameters('brightness', arguments); 52991 return this.color(c)._getBrightness(); 52992 }; 52993 /** 52994 * Creates colors for storing in variables of the color datatype. The 52995 * parameters are interpreted as RGB or HSB values depending on the 52996 * current <a href="#/p5/colorMode">colorMode()</a>. The default mode is RGB values from 0 to 255 52997 * and, therefore, the function call color(255, 204, 0) will return a 52998 * bright yellow color. 52999 *
53000 * Note that if only one value is provided to <a href="#/p5/color">color()</a>, it will be interpreted 53001 * as a grayscale value. Add a second value, and it will be used for alpha 53002 * transparency. When three values are specified, they are interpreted as 53003 * either RGB or HSB values. Adding a fourth value applies alpha 53004 * transparency. 53005 * 53006 * If a single string argument is provided, RGB, RGBA and Hex CSS color 53007 * strings and all named color strings are supported. In this case, an alpha 53008 * number value as a second argument is not supported, the RGBA form should be 53009 * used. 53010 * 53011 * @method color 53012 * @param {Number} gray number specifying value between white and black. 53013 * @param {Number} [alpha] alpha value relative to current color range 53014 * (default is 0-255) 53015 * @return {p5.Color} resulting color 53016 * 53017 * @example 53018 * <div> 53019 * <code> 53020 * let c = color(255, 204, 0); 53021 * fill(c); 53022 * noStroke(); 53023 * rect(30, 20, 55, 55); 53024 * describe(`Yellow rect in middle right of canvas, 53025 * with 55 pixel width and height.`); 53026 * </code> 53027 * </div> 53028 * 53029 * <div> 53030 * <code> 53031 * let c = color(255, 204, 0); 53032 * fill(c); 53033 * noStroke(); 53034 * ellipse(25, 25, 80, 80); // Draw left circle 53035 * // Using only one value generates a grayscale value. 53036 * c = color(65); 53037 * fill(c); 53038 * ellipse(75, 75, 80, 80); 53039 * describe(`Yellow ellipse in top left of canvas, black ellipse in bottom 53040 * right, both 80Ã80.`); 53041 * </code> 53042 * </div> 53043 * 53044 * <div> 53045 * <code> 53046 * // You can use named SVG & CSS colors 53047 * let c = color('magenta'); 53048 * fill(c); 53049 * noStroke(); 53050 * rect(20, 20, 60, 60); 53051 * describe('Bright fuchsia rect in middle of canvas, 60 pixel width and height.'); 53052 * </code> 53053 * </div> 53054 * 53055 * <div> 53056 * <code> 53057 * // Example of hex color codes 53058 * noStroke(); 53059 * let c = color('#0f0'); 53060 * fill(c); 53061 * rect(0, 10, 45, 80); 53062 * c = color('#00ff00'); 53063 * fill(c); 53064 * rect(55, 10, 45, 80); 53065 * describe('Two bright green rects on opposite sides of the canvas, both 45Ã80.'); 53066 * </code> 53067 * </div> 53068 * 53069 * <div> 53070 * <code> 53071 * // RGB and RGBA color strings are also supported 53072 * // these all set to the same color (solid blue) 53073 * let c; 53074 * noStroke(); 53075 * c = color('rgb(0,0,255)'); 53076 * fill(c); 53077 * rect(10, 10, 35, 35); // Draw rectangle 53078 * c = color('rgb(0%, 0%, 100%)'); 53079 * fill(c); 53080 * rect(55, 10, 35, 35); // Draw rectangle 53081 * c = color('rgba(0, 0, 255, 1)'); 53082 * fill(c); 53083 * rect(10, 55, 35, 35); // Draw rectangle 53084 * c = color('rgba(0%, 0%, 100%, 1)'); 53085 * fill(c); 53086 * rect(55, 55, 35, 35); // Draw rectangle 53087 * describe('Four blue rects in each corner of the canvas, each are 35Ã35.'); 53088 * </code> 53089 * </div> 53090 * 53091 * <div> 53092 * <code> 53093 * // HSL color can also be specified by value 53094 * let c = color('hsl(160, 100%, 50%)'); 53095 * noStroke(); 53096 * fill(c); 53097 * rect(0, 10, 45, 80); // Draw rectangle 53098 * c = color('hsla(160, 100%, 50%, 0.5)'); 53099 * fill(c); 53100 * rect(55, 10, 45, 80); // Draw rectangle 53101 * describe(`Bright sea green rect on left and darker rect on right of canvas, 53102 * both 45Ã80.`); 53103 * </code> 53104 * </div> 53105 * 53106 * <div> 53107 * <code> 53108 * // HSB color can also be specified 53109 * let c = color('hsb(160, 100%, 50%)'); 53110 * noStroke(); 53111 * fill(c); 53112 * rect(0, 10, 45, 80); // Draw rectangle 53113 * c = color('hsba(160, 100%, 50%, 0.5)'); 53114 * fill(c); 53115 * rect(55, 10, 45, 80); // Draw rectangle 53116 * describe(`Dark green rect on left and lighter green rect on right of canvas, 53117 * both 45Ã80.`); 53118 * </code> 53119 * </div> 53120 * 53121 * <div> 53122 * <code> 53123 * noStroke(); 53124 * let c = color(50, 55, 100); 53125 * fill(c); 53126 * rect(0, 10, 45, 80); // Draw left rect 53127 * colorMode(HSB, 100); 53128 * c = color(50, 55, 100); 53129 * fill(c); 53130 * rect(55, 10, 45, 80); 53131 * describe(`Dark blue rect on left and light teal rect on right of canvas, 53132 * both 45Ã80.`); 53133 * </code> 53134 * </div> 53135 */ 53136 /** 53137 * @method color 53138 * @param {Number} v1 red or hue value relative to 53139 * the current color range 53140 * @param {Number} v2 green or saturation value 53141 * relative to the current color range 53142 * @param {Number} v3 blue or brightness value 53143 * relative to the current color range 53144 * @param {Number} [alpha] 53145 * @return {p5.Color} 53146 */ 53147 /** 53148 * @method color 53149 * @param {String} value a color string 53150 * @return {p5.Color} 53151 */ 53152 /** 53153 * @method color 53154 * @param {Number[]} values an array containing the red,green,blue & 53155 * and alpha components of the color 53156 * @return {p5.Color} 53157 */ 53158 /** 53159 * @method color 53160 * @param {p5.Color} color 53161 * @return {p5.Color} 53162 */ 53163 _main.default.prototype.color = function () { 53164 _main.default._validateParameters('color', arguments); 53165 if (arguments[0] instanceof _main.default.Color) { 53166 return arguments[0];
53166 // Do nothing if argument is already a color object. 53167 } 53168 var args = arguments[0] instanceof Array ? arguments[0] : arguments; 53169 return new _main.default.Color(this, args); 53170 }; 53171 /** 53172 * Extracts the green value from a color or pixel array. 53173 * 53174 * @method green 53175 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 53176 * or CSS color 53177 * @return {Number} the green value 53178 * @example 53179 * <div> 53180 * <code> 53181 * let c = color(20, 75, 200); // Define color 'c' 53182 * fill(c); // Use color variable 'c' as fill color 53183 * rect(15, 20, 35, 60); // Draw left rectangle 53184 * 53185 * let greenValue = green(c); // Get green in 'c' 53186 * print(greenValue); // Print "75.0" 53187 * fill(0, greenValue, 0); // Use 'greenValue' in new fill 53188 * rect(50, 20, 35, 60); // Draw right rectangle 53189 * describe(`blue rect on left and green on right, both with black outlines 53190 * & 35Ã60.`); 53191 * </code> 53192 * </div> 53193 */ 53194 _main.default.prototype.green = function (c) { 53195 _main.default._validateParameters('green', arguments); 53196 return this.color(c)._getGreen(); 53197 }; 53198 /** 53199 * Extracts the hue value from a color or pixel array. 53200 * 53201 * Hue exists in both HSB and HSL. This function will return the 53202 * HSB-normalized hue when supplied with an HSB color object (or when supplied 53203 * with a pixel array while the color mode is HSB), but will default to the 53204 * HSL-normalized hue otherwise. (The values will only be different if the 53205 * maximum hue setting for each system is different.) 53206 * 53207 * @method hue 53208 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 53209 * or CSS color 53210 * @return {Number} the hue 53211 * @example 53212 * <div> 53213 * <code> 53214 * noStroke(); 53215 * colorMode(HSB, 255); 53216 * let c = color(0, 126, 255); 53217 * fill(c); 53218 * rect(15, 20, 35, 60); 53219 * let value = hue(c); // Sets 'value' to "0" 53220 * fill(value); 53221 * rect(50, 20, 35, 60); 53222 * describe('salmon pink rect on left and black on right, both 35Ã60.'); 53223 * </code> 53224 * </div> 53225 * 53226 */ 53227 _main.default.prototype.hue = function (c) { 53228 _main.default._validateParameters('hue', arguments); 53229 return this.color(c)._getHue(); 53230 }; 53231 /** 53232 * Blends two colors to find a third color somewhere between them. The amt 53233 * parameter is the amount to interpolate between the two values where 0.0 53234 * is equal to the first color, 0.1 is very near the first color, 0.5 is halfway 53235 * in between, etc. An amount below 0 will be treated as 0. Likewise, amounts 53236 * above 1 will be capped at 1. This is different from the behavior of <a href="#/p5/lerp">lerp()</a>, 53237 * but necessary because otherwise numbers outside the range will produce 53238 * strange and unexpected colors. 53239 * 53240 * The way that colors are interpolated depends on the current color mode. 53241 * 53242 * @method lerpColor 53243 * @param {p5.Color} c1 interpolate from this color 53244 * @param {p5.Color} c2 interpolate to this color 53245 * @param {Number} amt number between 0 and 1 53246 * @return {p5.Color} interpolated color 53247 * 53248 * @example 53249 * <div> 53250 * <code> 53251 * colorMode(RGB); 53252 * stroke(255); 53253 * background(51); 53254 * let from = color(218, 165, 32); 53255 * let to = color(72, 61, 139); 53256 * colorMode(RGB); // Try changing to HSB. 53257 * let interA = lerpColor(from, to, 0.33); 53258 * let interB = lerpColor(from, to, 0.66); 53259 * fill(from); 53260 * rect(10, 20, 20, 60); 53261 * fill(interA); 53262 * rect(30, 20, 20, 60); 53263 * fill(interB); 53264 * rect(50, 20, 20, 60); 53265 * fill(to); 53266 * rect(70, 20, 20, 60); 53267 * describe(`4 rects one tan, brown, brownish purple, purple, with white 53268 * outlines & 20Ã60`); 53269 * </code> 53270 * </div> 53271 */ 53272 _main.default.prototype.lerpColor = function (c1, c2, amt) { 53273 _main.default._validateParameters('lerpColor', arguments); 53274 var mode = this._colorMode; 53275 var maxes = this._colorMaxes; 53276 var l0, 53277 l1, 53278 l2, 53279 l3; 53280 var fromArray, 53281 toArray; 53282 if (mode === constants.RGB) { 53283 fromArray = c1.levels.map(function (level) { 53284 return level / 255; 53285 }); 53286 toArray = c2.levels.map(function (level) { 53287 return level / 255; 53288 }); 53289 } else if (mode === constants.HSB) { 53290 c1._getBrightness(); // Cache hsba so it definitely exists. 53291 c2._getBrightness(); 53292 fromArray = c1.hsba; 53293 toArray = c2.hsba; 53294 } else if (mode === constants.HSL) { 53295 c1._getLightness();
53295 // Cache hsla so it definitely exists. 53296 c2._getLightness(); 53297 fromArray = c1.hsla; 53298 toArray = c2.hsla; 53299 } else { 53300 throw new Error(''.concat(mode, 'cannot be used for interpolation.')); 53301 } // Prevent extrapolation. 53302 53303 amt = Math.max(Math.min(amt, 1), 0); // Define lerp here itself if user isn't using math module. 53304 // Maintains the definition as found in math/calculation.js 53305 if (typeof this.lerp === 'undefined') { 53306 this.lerp = function (start, stop, amt) { 53307 return amt * (stop - start) + start; 53308 }; 53309 } // Perform interpolation. 53310 53311 l0 = this.lerp(fromArray[0], toArray[0], amt); 53312 l1 = this.lerp(fromArray[1], toArray[1], amt); 53313 l2 = this.lerp(fromArray[2], toArray[2], amt); 53314 l3 = this.lerp(fromArray[3], toArray[3], amt); // Scale components. 53315 l0 *= maxes[mode][0]; 53316 l1 *= maxes[mode][1]; 53317 l2 *= maxes[mode][2]; 53318 l3 *= maxes[mode][3]; 53319 return this.color(l0, l1, l2, l3); 53320 }; 53321 /** 53322 * Extracts the HSL lightness value from a color or pixel array. 53323 * 53324 * @method lightness 53325 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 53326 * or CSS color 53327 * @return {Number} the lightness 53328 * 53329 * @example 53330 * <div> 53331 * <code> 53332 * noStroke(); 53333 * colorMode(HSL); 53334 * let c = color(156, 100, 50, 1); 53335 * fill(c); 53336 * rect(15, 20, 35, 60); 53337 * let value = lightness(c); // Sets 'value' to 50 53338 * fill(value); 53339 * rect(50, 20, 35, 60); 53340 * describe(`light pastel green rect on left and dark grey rect on right, 53341 * both 35Ã60.`); 53342 * </code> 53343 * </div> 53344 */ 53345 _main.default.prototype.lightness = function (c) { 53346 _main.default._validateParameters('lightness', arguments); 53347 return this.color(c)._getLightness(); 53348 }; 53349 /** 53350 * Extracts the red value from a color or pixel array. 53351 * 53352 * @method red 53353 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 53354 * or CSS color 53355 * @return {Number} the red value 53356 * @example 53357 * <div> 53358 * <code> 53359 * let c = color(255, 204, 0); // Define color 'c' 53360 * fill(c); // Use color variable 'c' as fill color 53361 * rect(15, 20, 35, 60); // Draw left rectangle 53362 * 53363 * let redValue = red(c); // Get red in 'c' 53364 * print(redValue); // Print "255.0" 53365 * fill(redValue, 0, 0); // Use 'redValue' in new fill 53366 * rect(50, 20, 35, 60); // Draw right rectangle 53367 * describe(`yellow rect on left and red rect on right, both with black 53368 * outlines and 35Ã60.`); 53369 * </code> 53370 * </div> 53371 * 53372 * <div class="norender"> 53373 * <code> 53374 * colorMode(RGB, 255); // Sets the range for red, green, and blue to 255 53375 * let c = color(127, 255, 0); 53376 * colorMode(RGB, 1); // Sets the range for red, green, and blue to 1 53377 * let myColor = red(c); 53378 * print(myColor); // 0.4980392156862745 53379 * describe('grey canvas'); 53380 * </code> 53381 * </div> 53382 */ 53383 _main.default.prototype.red = function (c) { 53384 _main.default._validateParameters('red', arguments); 53385 return this.color(c)._getRed(); 53386 }; 53387 /** 53388 * Extracts the saturation value from a color or pixel array. 53389 * 53390 * Saturation is scaled differently in HSB and HSL. This function will return 53391 * the HSB saturation when supplied with an HSB color object (or when supplied 53392 * with a pixel array while the color mode is HSB), but will default to the 53393 * HSL saturation otherwise. 53394 * 53395 * @method saturation 53396 * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components, 53397 * or CSS color 53398 * @return {Number} the saturation value 53399 * @example 53400 * <div> 53401 * <code> 53402 * noStroke(); 53403 * colorMode(HSB, 255); 53404 * let c = color(0, 126, 255); 53405 * fill(c); 53406 * rect(15, 20, 35, 60); 53407 * let value = saturation(c); // Sets 'value' to 126 53408 * fill(value); 53409 * rect(50, 20, 35, 60); 53410 * describe('deep pink rect on left and grey rect on right, both 35Ã60.'); 53411 * </code> 53412 * </div> 53413 */ 53414 _main.default.prototype.saturation = function (c) { 53415 _main.default._validateParameters('saturation', arguments); 53416 return this.color(c)._getSaturation(); 53417 }; 53418 var _default = _main.default; 53419 exports.default = _default; 53420 }, 53421 { 53422 '../core/constants': 278, 53423 '../core/friendly_errors/fes_core': 281, 53424 '../core/friendly_errors/file_errors': 282, 53425 '../core/friendly_errors/validate_params': 285, 53426 '../core/main': 290, 53427 './p5.Color': 276, 53428 'core-js/modules/es.array.iterator': 176, 53429 'core-js/modules/es.array.map': 179, 53430 'core-js/modules/es.object.get-own-property-descriptor': 191, 53431 'core-js/modules/es.object.to-string': 195, 53432 'core-js/modules/es.string.iterator': 204, 53433 'core-js/modules/es.symbol': 214, 53434 'core-js/modules/es.symbol.description': 212, 53435 'core-js/modules/es.symbol.iterator': 213, 53436 'core-js/modules/es.weak-map': 246, 53437 'core-js/modules/web.dom-collections.iterator': 248 53438 } 53439 ], 53440 276: [
53441 function (_dereq_, module, exports) { 53442 'use strict'; 53443 _dereq_('core-js/modules/es.symbol'); 53444 _dereq_('core-js/modules/es.symbol.description'); 53445 _dereq_('core-js/modules/es.symbol.iterator'); 53446 _dereq_('core-js/modules/es.array.iterator'); 53447 _dereq_('core-js/modules/es.array.join'); 53448 _dereq_('core-js/modules/es.array.map'); 53449 _dereq_('core-js/modules/es.array.slice'); 53450 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 53451 _dereq_('core-js/modules/es.object.to-string'); 53452 _dereq_('core-js/modules/es.regexp.constructor'); 53453 _dereq_('core-js/modules/es.regexp.exec'); 53454 _dereq_('core-js/modules/es.regexp.to-string'); 53455 _dereq_('core-js/modules/es.string.iterator'); 53456 _dereq_('core-js/modules/es.string.trim'); 53457 _dereq_('core-js/modules/es.weak-map'); 53458 _dereq_('core-js/modules/web.dom-collections.iterator'); 53459 function _typeof2(obj) { 53460 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 53461 _typeof2 = function _typeof2(obj) { 53462 return typeof obj; 53463 }; 53464 } else { 53465 _typeof2 = function _typeof2(obj) { 53466 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 53467 }; 53468 } 53469 return _typeof2(obj); 53470 } 53471 function _typeof(obj) { 53472 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 53473 _typeof = function _typeof(obj) { 53474 return _typeof2(obj); 53475 }; 53476 } else { 53477 _typeof = function _typeof(obj) { 53478 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 53479 }; 53480 } 53481 return _typeof(obj); 53482 } 53483 _dereq_('core-js/modules/es.array.join'); 53484 _dereq_('core-js/modules/es.array.map'); 53485 _dereq_('core-js/modules/es.array.slice'); 53486 _dereq_('core-js/modules/es.object.to-string'); 53487 _dereq_('core-js/modules/es.regexp.constructor'); 53488 _dereq_('core-js/modules/es.regexp.exec'); 53489 _dereq_('core-js/modules/es.regexp.to-string'); 53490 _dereq_('core-js/modules/es.string.trim'); 53491 Object.defineProperty(exports, '__esModule', { 53492 value: true 53493 }); 53494 exports.default = void 0; 53495 var _main = _interopRequireDefault(_dereq_('../core/main')); 53496 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 53497 var _color_conversion = _interopRequireDefault(_dereq_('./color_conversion')); 53498 function _getRequireWildcardCache() { 53499 if (typeof WeakMap !== 'function') return null; 53500 var cache = new WeakMap(); 53501 _getRequireWildcardCache = function _getRequireWildcardCache() { 53502 return cache; 53503 }; 53504 return cache; 53505 } 53506 function _interopRequireWildcard(obj) { 53507 if (obj && obj.__esModule) { 53508 return obj; 53509 } 53510 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 53511 return { 53512 default: 53513 obj 53514 }; 53515 } 53516 var cache = _getRequireWildcardCache(); 53517 if (cache && cache.has(obj)) { 53518 return cache.get(obj); 53519 } 53520 var newObj = { 53521 }; 53522 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 53523 for (var key in obj) { 53524 if (Object.prototype.hasOwnProperty.call(obj, key)) { 53525 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 53526 if (desc && (desc.get || desc.set)) { 53527 Object.defineProperty(newObj, key, desc); 53528 } else { 53529 newObj[key] = obj[key]; 53530 } 53531 } 53532 } 53533 newObj.default = obj; 53534 if (cache) { 53535 cache.set(obj, newObj); 53536 } 53537 return newObj; 53538 } 53539 function _interopRequireDefault(obj) { 53540 return obj && obj.__esModule ? obj : { 53541 default: 53542 obj 53543 }; 53544 } /** 53545 * @module Color 53546 * @submodule Creating & Reading 53547 * @for p5 53548 * @requires core 53549 * @requires constants 53550 * @requires color_conversion 53551 */ 53552 /** 53553 * Each color stores the color mode and level maxes that were applied at the 53554 * time of its construction. These are used to interpret the input arguments 53555 * (at construction and later for that instance of color) and to format the 53556 * output e.g. when <a href="#/p5/saturation">saturation()</a> is requested. 53557 * 53558 * Internally, we store an array representing the ideal RGBA values in floating 53559 * point form, normalized from 0 to 1. From this we calculate the closest 53560 * screen color (RGBA levels from 0 to 255) and expose this to the renderer. 53561 * 53562 * We also cache normalized, floating-point components of the color in various 53563 * representations as they are calculated. This is done to prevent repeating a 53564 * conversion that has already been performed. 53565 * 53566 * @class p5.Color 53567 * @constructor 53568 */ 53569 53570 _main.default.Color = function (pInst, vals) { 53571 // Record color mode and maxes at time of construction. 53572 this._storeModeAndMaxes(pInst._colorMode, pInst._colorMaxes); // Calculate normalized RGBA values. 53573 if (this.mode !== constants.RGB && this.mode !== constants.HSL && this.mode !== constants.HSB) {
53574 throw new Error(''.concat(this.mode, ' is an invalid colorMode.')); 53575 } else { 53576 this._array = _main.default.Color._parseInputs.apply(this, vals); 53577 } // Expose closest screen color. 53578 53579 this._calculateLevels(); 53580 return this; 53581 }; 53582 /** 53583 * This method returns the color formatted as a string. This can be useful 53584 * for debugging, or for using p5.js with other libraries. 53585 * 53586 * @method toString 53587 * @param {String} [format] How the color string will be formatted. 53588 * Leaving this empty formats the string as rgba(r, g, b, a). 53589 * '#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color codes. 53590 * 'rgb' 'hsb' and 'hsl' return the color formatted in the specified color mode. 53591 * 'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels. 53592 * 'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as percentages. 53593 * @return {String} the formatted string 53594 * 53595 * @example 53596 * <div> 53597 * <code> 53598 * createCanvas(200, 100); 53599 * let myColor; 53600 * stroke(255); 53601 * myColor = color(100, 100, 250); 53602 * fill(myColor); 53603 * rotate(HALF_PI); 53604 * text(myColor.toString(), 0, -5); 53605 * text(myColor.toString('#rrggbb'), 0, -30); 53606 * text(myColor.toString('rgba%'), 0, -55); 53607 * describe('A canvas with 3 text representation of their color.'); 53608 * </code> 53609 * </div> 53610 * 53611 * <div> 53612 * <code> 53613 * let myColor = color(100, 130, 250); 53614 * text(myColor.toString('#rrggbb'), 25, 25); 53615 * </code> 53616 * </div> 53617 */ 53618 _main.default.Color.prototype.toString = function (format) { 53619 var a = this.levels; 53620 var f = this._array; 53621 var alpha = f[3]; // String representation uses normalized alpha 53622 switch (format) { 53623 case '#rrggbb': 53624 return '#'.concat(a[0] < 16 ? '0'.concat(a[0].toString(16)) : a[0].toString(16), a[1] < 16 ? '0'.concat(a[1].toString(16)) : a[1].toString(16), a[2] < 16 ? '0'.concat(a[2].toString(16)) : a[2].toString(16)); 53625 case '#rrggbbaa': 53626 return '#'.concat(a[0] < 16 ? '0'.concat(a[0].toString(16)) : a[0].toString(16), a[1] < 16 ? '0'.concat(a[1].toString(16)) : a[1].toString(16), a[2] < 16 ? '0'.concat(a[2].toString(16)) : a[2].toString(16), a[3] < 16 ? '0'.concat(a[3].toString(16)) : a[3].toString(16)); 53627 case '#rgb': 53628 return '#'.concat(Math.round(f[0] * 15).toString(16), Math.round(f[1] * 15).toString(16), Math.round(f[2] * 15).toString(16)); 53629 case '#rgba': 53630 return '#'.concat(Math.round(f[0] * 15).toString(16), Math.round(f[1] * 15).toString(16), Math.round(f[2] * 15).toString(16), Math.round(f[3] * 15).toString(16)); 53631 case 'rgb': 53632 return 'rgb('.concat(a[0], ', ', a[1], ', ', a[2], ')'); 53633 case 'rgb%': 53634 return 'rgb('.concat((100 * f[0]).toPrecision(3), '%, ', (100 * f[1]).toPrecision(3), '%, ', (100 * f[2]).toPrecision(3), '%)'); 53635 case 'rgba%': 53636 return 'rgba('.concat((100 * f[0]).toPrecision(3), '%, ', (100 * f[1]).toPrecision(3), '%, ', (100 * f[2]).toPrecision(3), '%, ', (100 * f[3]).toPrecision(3), '%)'); 53637 case 'hsb': 53638 case 'hsv': 53639 if (!this.hsba) this.hsba = _color_conversion.default._rgbaToHSBA(this._array); 53640 return 'hsb('.concat(this.hsba[0] * this.maxes[constants.HSB][0], ', ', this.hsba[1] * this.maxes[constants.HSB][1], ', ', this.hsba[2] * this.maxes[constants.HSB][2], ')'); 53641 case 'hsb%': 53642 case 'hsv%': 53643 if (!this.hsba) this.hsba = _color_conversion.default._rgbaToHSBA(this._array); 53644 return 'hsb('.concat((100 * this.hsba[0]).toPrecision(3), '%, ', (100 * this.hsba[1]).toPrecision(3), '%, ', (100 * this.hsba[2]).toPrecision(3), '%)'); 53645 case 'hsba': 53646 case 'hsva': 53647 if (!this.hsba) this.hsba = _color_conversion.default._rgbaToHSBA(this._array); 53648 return 'hsba('.concat(this.hsba[0] * this.maxes[constants.HSB][0], ', ', this.hsba[1] * this.maxes[constants.HSB][1], ', ', this.hsba[2] * this.maxes[constants.HSB][2], ', ', alpha, ')'); 53649 case 'hsba%': 53650 case 'hsva%': 53651 if (!this.hsba) this.hsba = _color_conversion.default._rgbaToHSBA(this._array); 53652 return 'hsba('.concat((100 * this.hsba[0]).toPrecision(3), '%, ', (100 * this.hsba[1]).toPrecision(3), '%, ', (100 * this.hsba[2]).toPrecision(3), '%, ', (100 * alpha).toPrecision(3), '%)'); 53653 case 'hsl': 53654 if (!this.hsla) this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
53655 return 'hsl('.concat(this.hsla[0] * this.maxes[constants.HSL][0], ', ', this.hsla[1] * this.maxes[constants.HSL][1], ', ', this.hsla[2] * this.maxes[constants.HSL][2], ')'); 53656 case 'hsl%': 53657 if (!this.hsla) this.hsla = _color_conversion.default._rgbaToHSLA(this._array); 53658 return 'hsl('.concat((100 * this.hsla[0]).toPrecision(3), '%, ', (100 * this.hsla[1]).toPrecision(3), '%, ', (100 * this.hsla[2]).toPrecision(3), '%)'); 53659 case 'hsla': 53660 if (!this.hsla) this.hsla = _color_conversion.default._rgbaToHSLA(this._array); 53661 return 'hsla('.concat(this.hsla[0] * this.maxes[constants.HSL][0], ', ', this.hsla[1] * this.maxes[constants.HSL][1], ', ', this.hsla[2] * this.maxes[constants.HSL][2], ', ', alpha, ')'); 53662 case 'hsla%': 53663 if (!this.hsla) this.hsla = _color_conversion.default._rgbaToHSLA(this._array); 53664 return 'hsl('.concat((100 * this.hsla[0]).toPrecision(3), '%, ', (100 * this.hsla[1]).toPrecision(3), '%, ', (100 * this.hsla[2]).toPrecision(3), '%, ', (100 * alpha).toPrecision(3), '%)'); 53665 case 'rgba': 53666 default: 53667 return 'rgba('.concat(a[0], ',', a[1], ',', a[2], ',', alpha, ')'); 53668 } 53669 }; 53670 /** 53671 * The setRed method sets the red component of a color. 53672 * The range depends on your color mode, in the default RGB mode it's between 0 and 255. 53673 * @method setRed 53674 * @param {Number} red the new red value 53675 * @example 53676 * <div> 53677 * <code> 53678 * let backgroundColor; 53679 * 53680 * function setup() { 53681 * backgroundColor = color(100, 50, 150); 53682 * } 53683 * 53684 * function draw() { 53685 * backgroundColor.setRed(128 + 128 * sin(millis() / 1000)); 53686 * background(backgroundColor);
53687 * describe('canvas with gradually changing background color'); 53688 * } 53689 * </code> 53690 * </div> 53691 */ 53692 _main.default.Color.prototype.setRed = function (new_red) { 53693 this._array[0] = new_red / this.maxes[constants.RGB][0]; 53694 this._calculateLevels(); 53695 }; 53696 /** 53697 * The setGreen method sets the green component of a color. 53698 * The range depends on your color mode, in the default RGB mode it's between 0 and 255. 53699 * @method setGreen 53700 * @param {Number} green the new green value 53701 * @example 53702 * <div> 53703 * <code> 53704 * let backgroundColor = color(100, 50, 150); 53705 * function draw() { 53706 * backgroundColor.setGreen(128 + 128 * sin(millis() / 1000)); 53707 * background(backgroundColor); 53708 * describe('canvas with gradually changing background color'); 53709 * } 53710 * </code> 53711 * </div> 53712 * 53713 **/ 53714 _main.default.Color.prototype.setGreen = function (new_green) { 53715 this._array[1] = new_green / this.maxes[constants.RGB][1]; 53716 this._calculateLevels(); 53717 }; 53718 /** 53719 * The setBlue method sets the blue component of a color. 53720 * The range depends on your color mode, in the default RGB mode it's between 0 and 255. 53721 * @method setBlue 53722 * @param {Number} blue the new blue value 53723 * @example 53724 * <div> 53725 * <code> 53726 * let backgroundColor = color(100, 50, 150); 53727 * function draw() { 53728 * backgroundColor.setBlue(128 + 128 * sin(millis() / 1000)); 53729 * background(backgroundColor);
53730 * describe('canvas with gradually changing background color'); 53731 * } 53732 * </code> 53733 * </div> 53734 * 53735 **/ 53736 _main.default.Color.prototype.setBlue = function (new_blue) { 53737 this._array[2] = new_blue / this.maxes[constants.RGB][2]; 53738 this._calculateLevels(); 53739 }; 53740 /** 53741 * The setAlpha method sets the transparency (alpha) value of a color. 53742 * The range depends on your color mode, in the default RGB mode it's between 0 and 255. 53743 * @method setAlpha 53744 * @param {Number} alpha the new alpha value 53745 * @example 53746 * <div> 53747 * <code> 53748 * function draw() { 53749 * clear(); 53750 * background(200); 53751 * squareColor = color(100, 50, 100); 53752 * squareColor.setAlpha(128 + 128 * sin(millis() / 1000)); 53753 * fill(squareColor); 53754 * rect(13, 13, width - 26, height - 26); 53755 * describe('a square with gradually changing opacity on a gray background'); 53756 * } 53757 * </code> 53758 * </div> 53759 **/ 53760 _main.default.Color.prototype.setAlpha = function (new_alpha) { 53761 this._array[3] = new_alpha / this.maxes[this.mode][3]; 53762 this._calculateLevels(); 53763 }; // calculates and stores the closest screen levels 53764 _main.default.Color.prototype._calculateLevels = function () { 53765 var array = this._array; // (loop backwards for performance) 53766 var levels = this.levels = new Array(array.length); 53767 for (var i = array.length - 1; i >= 0; --i) { 53768 levels[i] = Math.round(array[i] * 255); 53769 } // Clear cached HSL/HSB values 53770 53771 this.hsla = null; 53772 this.hsba = null; 53773 }; 53774 _main.default.Color.prototype._getAlpha = function () { 53775 return this._array[3] * this.maxes[this.mode][3]; 53776 }; // stores the color mode and maxes in this instance of Color 53777 // for later use (by _parseInputs()) 53778 _main.default.Color.prototype._storeModeAndMaxes = function (new_mode, new_maxes) { 53779 this.mode = new_mode; 53780 this.maxes = new_maxes; 53781 }; 53782 _main.default.Color.prototype._getMode = function () { 53783 return this.mode; 53784 }; 53785 _main.default.Color.prototype._getMaxes = function () { 53786 return this.maxes; 53787 }; 53788 _main.default.Color.prototype._getBlue = function () { 53789 return this._array[2] * this.maxes[constants.RGB][2]; 53790 }; 53791 _main.default.Color.prototype._getBrightness = function () { 53792 if (!this.hsba) { 53793 this.hsba = _color_conversion.default._rgbaToHSBA(this._array); 53794 } 53795 return this.hsba[2] * this.maxes[constants.HSB][2]; 53796 }; 53797 _main.default.Color.prototype._getGreen = function () { 53798 return this._array[1] * this.maxes[constants.RGB][1]; 53799 }; 53800 /** 53801 * Hue is the same in HSB and HSL, but the maximum value may be different. 53802 * This function will return the HSB-normalized saturation when supplied with 53803 * an HSB color object, but will default to the HSL-normalized saturation 53804 * otherwise. 53805 */ 53806 _main.default.Color.prototype._getHue = function () { 53807 if (this.mode === constants.HSB) { 53808 if (!this.hsba) { 53809 this.hsba = _color_conversion.default._rgbaToHSBA(this._array); 53810 } 53811 return this.hsba[0] * this.maxes[constants.HSB][0]; 53812 } else { 53813 if (!this.hsla) { 53814 this.hsla = _color_conversion.default._rgbaToHSLA(this._array); 53815 } 53816 return this.hsla[0] * this.maxes[constants.HSL][0]; 53817 } 53818 }; 53819 _main.default.Color.prototype._getLightness = function () { 53820 if (!this.hsla) { 53821 this.hsla = _color_conversion.default._rgbaToHSLA(this._array); 53822 } 53823 return this.hsla[2] * this.maxes[constants.HSL][2]; 53824 }; 53825 _main.default.Color.prototype._getRed = function () { 53826 return this._array[0] * this.maxes[constants.RGB][0]; 53827 }; 53828 /** 53829 * Saturation is scaled differently in HSB and HSL. This function will return 53830 * the HSB saturation when supplied with an HSB color object, but will default 53831 * to the HSL saturation otherwise. 53832 */ 53833 _main.default.Color.prototype._getSaturation = function () { 53834 if (this.mode === constants.HSB) { 53835 if (!this.hsba) { 53836 this.hsba = _color_conversion.default._rgbaToHSBA(this._array); 53837 }
53838 return this.hsba[1] * this.maxes[constants.HSB][1]; 53839 } else { 53840 if (!this.hsla) { 53841 this.hsla = _color_conversion.default._rgbaToHSLA(this._array); 53842 } 53843 return this.hsla[1] * this.maxes[constants.HSL][1]; 53844 } 53845 }; 53846 /** 53847 * CSS named colors. 53848 */ 53849 var namedColors = { 53850 aliceblue: '#f0f8ff', 53851 antiquewhite: '#faebd7', 53852 aqua: '#00ffff', 53853 aquamarine: '#7fffd4', 53854 azure: '#f0ffff', 53855 beige: '#f5f5dc', 53856 bisque: '#ffe4c4', 53857 black: '#000000', 53858 blanchedalmond: '#ffebcd', 53859 blue: '#0000ff', 53860 blueviolet: '#8a2be2', 53861 brown: '#a52a2a', 53862 burlywood: '#deb887', 53863 cadetblue: '#5f9ea0', 53864 chartreuse: '#7fff00', 53865 chocolate: '#d2691e', 53866 coral: '#ff7f50', 53867 cornflowerblue: '#6495ed', 53868 cornsilk: '#fff8dc', 53869 crimson: '#dc143c', 53870 cyan: '#00ffff', 53871 darkblue: '#00008b', 53872 darkcyan: '#008b8b', 53873 darkgoldenrod: '#b8860b', 53874 darkgray: '#a9a9a9', 53875 darkgreen: '#006400', 53876 darkgrey: '#a9a9a9', 53877 darkkhaki: '#bdb76b', 53878 darkmagenta: '#8b008b', 53879 darkolivegreen: '#556b2f', 53880 darkorange: '#ff8c00', 53881 darkorchid: '#9932cc', 53882 darkred: '#8b0000', 53883 darksalmon: '#e9967a', 53884 darkseagreen: '#8fbc8f', 53885 darkslateblue: '#483d8b', 53886 darkslategray: '#2f4f4f', 53887 darkslategrey: '#2f4f4f', 53888 darkturquoise: '#00ced1', 53889 darkviolet: '#9400d3', 53890 deeppink: '#ff1493', 53891 deepskyblue: '#00bfff', 53892 dimgray: '#696969', 53893 dimgrey: '#696969', 53894 dodgerblue: '#1e90ff', 53895 firebrick: '#b22222', 53896 floralwhite: '#fffaf0', 53897 forestgreen: '#228b22', 53898 fuchsia: '#ff00ff', 53899 gainsboro: '#dcdcdc', 53900 ghostwhite: '#f8f8ff', 53901 gold: '#ffd700', 53902 goldenrod: '#daa520', 53903 gray: '#808080', 53904 green: '#008000', 53905 greenyellow: '#adff2f', 53906 grey: '#808080', 53907 honeydew: '#f0fff0', 53908 hotpink: '#ff69b4', 53909 indianred: '#cd5c5c', 53910 indigo: '#4b0082', 53911 ivory: '#fffff0', 53912 khaki: '#f0e68c', 53913 lavender: '#e6e6fa', 53914 lavenderblush: '#fff0f5', 53915 lawngreen: '#7cfc00', 53916 lemonchiffon: '#fffacd', 53917 lightblue: '#add8e6', 53918 lightcoral: '#f08080', 53919 lightcyan: '#e0ffff', 53920 lightgoldenrodyellow: '#fafad2', 53921 lightgray: '#d3d3d3', 53922 lightgreen: '#90ee90', 53923 lightgrey: '#d3d3d3', 53924 lightpink: '#ffb6c1', 53925 lightsalmon: '#ffa07a', 53926 lightseagreen: '#20b2aa', 53927 lightskyblue: '#87cefa', 53928 lightslategray: '#778899', 53929 lightslategrey: '#778899', 53930 lightsteelblue: '#b0c4de', 53931 lightyellow: '#ffffe0', 53932 lime: '#00ff00', 53933 limegreen: '#32cd32', 53934 linen: '#faf0e6', 53935 magenta: '#ff00ff', 53936 maroon: '#800000', 53937 mediumaquamarine: '#66cdaa', 53938 mediumblue: '#0000cd', 53939 mediumorchid: '#ba55d3', 53940 mediumpurple: '#9370db', 53941 mediumseagreen: '#3cb371', 53942 mediumslateblue: '#7b68ee', 53943 mediumspringgreen: '#00fa9a', 53944 mediumturquoise: '#48d1cc', 53945 mediumvioletred: '#c71585', 53946 midnightblue: '#191970', 53947 mintcream: '#f5fffa', 53948 mistyrose: '#ffe4e1', 53949 moccasin: '#ffe4b5', 53950 navajowhite: '#ffdead', 53951 navy: '#000080', 53952 oldlace: '#fdf5e6', 53953 olive: '#808000', 53954 olivedrab: '#6b8e23', 53955 orange: '#ffa500', 53956 orangered: '#ff4500', 53957 orchid: '#da70d6', 53958 palegoldenrod: '#eee8aa', 53959 palegreen: '#98fb98', 53960 paleturquoise: '#afeeee', 53961 palevioletred: '#db7093', 53962 papayawhip: '#ffefd5', 53963 peachpuff: '#ffdab9', 53964 peru: '#cd853f', 53965 pink: '#ffc0cb', 53966 plum: '#dda0dd', 53967 powderblue: '#b0e0e6', 53968 purple: '#800080', 53969 rebeccapurple: '#663399', 53970 red: '#ff0000', 53971 rosybrown: '#bc8f8f', 53972 royalblue: '#4169e1', 53973 saddlebrown: '#8b4513', 53974 salmon: '#fa8072', 53975 sandybrown: '#f4a460', 53976 seagreen: '#2e8b57', 53977 seashell: '#fff5ee', 53978 sienna: '#a0522d', 53979 silver: '#c0c0c0', 53980 skyblue: '#87ceeb', 53981 slateblue: '#6a5acd', 53982 slategray: '#708090', 53983 slategrey: '#708090', 53984 snow: '#fffafa', 53985 springgreen: '#00ff7f', 53986 steelblue: '#4682b4', 53987 tan: '#d2b48c', 53988 teal: '#008080', 53989 thistle: '#d8bfd8', 53990 tomato: '#ff6347', 53991 turquoise: '#40e0d0', 53992 violet: '#ee82ee', 53993 wheat: '#f5deb3', 53994 white: '#ffffff', 53995 whitesmoke: '#f5f5f5', 53996 yellow: '#ffff00', 53997 yellowgreen: '#9acd32' 53998 }; 53999 /** 54000 * These regular expressions are used to build up the patterns for matching 54001 * viable CSS color strings: fragmenting the regexes in this way increases the 54002 * legibility and comprehensibility of the code. 54003 *
54004 * Note that RGB values of .9 are not parsed by IE, but are supported here for 54005 * color string consistency. 54006 */ 54007 var WHITESPACE = /\s*/; // Match zero or more whitespace characters. 54008 var INTEGER = /(\d{1,3})/; // Match integers: 79, 255, etc. 54009 var DECIMAL = /((?:\d+(?:\.\d+)?)|(?:\.\d+))/; // Match 129.6, 79, .9, etc. 54010 var PERCENT = new RegExp(''.concat(DECIMAL.source, '%')); // Match 12.9%, 79%, .9%, etc. 54011 /** 54012 * Full color string patterns. The capture groups are necessary. 54013 */ 54014 var colorPatterns = { 54015 // Match colors in format #XXX, e.g. #416. 54016 HEX3: /^#([a-f0-9])([a-f0-9])([a-f0-9])$/i, 54017 // Match colors in format #XXXX, e.g. #5123. 54018 HEX4: /^#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])$/i, 54019 // Match colors in format #XXXXXX, e.g. #b4d455. 54020 HEX6: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i, 54021 // Match colors in format #XXXXXXXX, e.g. #b4d45535. 54022 HEX8: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i, 54023 // Match colors in format rgb(R, G, B), e.g. rgb(255, 0, 128). 54024 RGB: new RegExp(['^rgb\\(', 54025 INTEGER.source, 54026 ',', 54027 INTEGER.source, 54028 ',', 54029 INTEGER.source, 54030 '\\)$'].join(WHITESPACE.source), 'i'), 54031 // Match colors in format rgb(R%, G%, B%), e.g. rgb(100%, 0%, 28.9%). 54032 RGB_PERCENT: new RegExp(['^rgb\\(', 54033 PERCENT.source, 54034 ',', 54035 PERCENT.source, 54036 ',', 54037 PERCENT.source, 54038 '\\)$'].join(WHITESPACE.source), 'i'), 54039 // Match colors in format rgb(R, G, B, A), e.g. rgb(255, 0, 128, 0.25). 54040 RGBA: new RegExp(['^rgba\\(', 54041 INTEGER.source, 54042 ',', 54043 INTEGER.source, 54044 ',', 54045 INTEGER.source, 54046 ',', 54047 DECIMAL.source, 54048 '\\)$'].join(WHITESPACE.source), 'i'), 54049 // Match colors in format rgb(R%, G%, B%, A), e.g. rgb(100%, 0%, 28.9%, 0.5). 54050 RGBA_PERCENT: new RegExp(['^rgba\\(', 54051 PERCENT.source, 54052 ',', 54053 PERCENT.source, 54054 ',', 54055 PERCENT.source, 54056 ',', 54057 DECIMAL.source, 54058 '\\)$'].join(WHITESPACE.source), 'i'), 54059 // Match colors in format hsla(H, S%, L%), e.g. hsl(100, 40%, 28.9%). 54060 HSL: new RegExp(['^hsl\\(', 54061 INTEGER.source, 54062 ',', 54063 PERCENT.source, 54064 ',', 54065 PERCENT.source, 54066 '\\)$'].join(WHITESPACE.source), 'i'), 54067 // Match colors in format hsla(H, S%, L%, A), e.g. hsla(100, 40%, 28.9%, 0.5). 54068 HSLA: new RegExp(['^hsla\\(', 54069 INTEGER.source, 54070 ',', 54071 PERCENT.source, 54072 ',', 54073 PERCENT.source, 54074 ',', 54075 DECIMAL.source, 54076 '\\)$'].join(WHITESPACE.source), 'i'), 54077 // Match colors in format hsb(H, S%, B%), e.g. hsb(100, 40%, 28.9%). 54078 HSB: new RegExp(['^hsb\\(', 54079 INTEGER.source, 54080 ',', 54081 PERCENT.source, 54082 ',', 54083 PERCENT.source, 54084 '\\)$'].join(WHITESPACE.source), 'i'), 54085 // Match colors in format hsba(H, S%, B%, A), e.g. hsba(100, 40%, 28.9%, 0.5). 54086 HSBA: new RegExp(['^hsba\\(', 54087 INTEGER.source, 54088 ',', 54089 PERCENT.source, 54090 ',', 54091 PERCENT.source, 54092 ',', 54093 DECIMAL.source, 54094 '\\)$'].join(WHITESPACE.source), 'i') 54095 }; 54096 /** 54097 * For a number of different inputs, returns a color formatted as [r, g, b, a] 54098 * arrays, with each component normalized between 0 and 1. 54099 * 54100 * @private 54101 * @param {Array} [...args] An 'array-like' object that represents a list of 54102 * arguments 54103 * @return {Number[]} a color formatted as [r, g, b, a] 54104 * Example: 54105 * input ==> output 54106 * g ==> [g, g, g, 255] 54107 * g,a ==> [g, g, g, a] 54108 * r, g, b ==> [r, g, b, 255] 54109 * r, g, b, a ==> [r, g, b, a] 54110 * [g] ==> [g, g, g, 255] 54111 * [g, a] ==> [g, g, g, a] 54112 * [r, g, b] ==> [r, g, b, 255] 54113 * [r, g, b, a] ==> [r, g, b, a] 54114 * @example 54115 * <div> 54116 * <code> 54117 * // todo 54118 * // 54119 * // describe(''); 54120 * </code> 54121 * </div> 54122 */ 54123 _main.default.Color._parseInputs = function (r, g, b, a) { 54124 var numArgs = arguments.length; 54125 var mode = this.mode; 54126 var maxes = this.maxes[mode]; 54127 var results = [ 54128 ]; 54129 var i; 54130 if (numArgs >= 3) { 54131 // Argument is a list of component values. 54132 results[0] = r / maxes[0]; 54133 results[1] = g / maxes[1]; 54134 results[2] = b / maxes[2]; // Alpha may be undefined, so default it to 100%. 54135 if (typeof a === 'number') { 54136 results[3] = a / maxes[3]; 54137 } else { 54138 results[3] = 1; 54139 } // Constrain components to the range [0,1]. 54140 // (loop backwards for performance) 54141 54142 for (i = results.length - 1; i >= 0; --i) { 54143 var result = results[i]; 54144 if (result < 0) { 54145 results[i] = 0; 54146 } else if (result > 1) { 54147 results[i] = 1; 54148 } 54149 } // Convert to RGBA and return. 54150 54151 if (mode === constants.HSL) { 54152 return _color_conversion.default._hslaToRGBA(results); 54153 } else if (mode === constants.HSB) { 54154 return _color_conversion.default._hsbaToRGBA(results); 54155 } else { 54156 return results; 54157 } 54158 } else if (numArgs === 1 && typeof r === 'string') { 54159 var str = r.trim().toLowerCase(); // Return if string is a named colour. 54160 if (namedColors[str]) { 54161 return _main.default.Color._parseInputs.call(this, namedColors[str]); 54162 } // Try RGBA pattern matching. 54163 54164 if (colorPatterns.HEX3.test(str)) { 54165 // #rgb 54166 results = colorPatterns.HEX3.exec(str).slice(1).map(function (color) {
54167 return parseInt(color + color, 16) / 255; 54168 }); 54169 results[3] = 1; 54170 return results; 54171 } else if (colorPatterns.HEX6.test(str)) { 54172 // #rrggbb 54173 results = colorPatterns.HEX6.exec(str).slice(1).map(function (color) { 54174 return parseInt(color, 16) / 255; 54175 }); 54176 results[3] = 1; 54177 return results; 54178 } else if (colorPatterns.HEX4.test(str)) { 54179 // #rgba 54180 results = colorPatterns.HEX4.exec(str).slice(1).map(function (color) { 54181 return parseInt(color + color, 16) / 255; 54182 }); 54183 return results; 54184 } else if (colorPatterns.HEX8.test(str)) { 54185 // #rrggbbaa 54186 results = colorPatterns.HEX8.exec(str).slice(1).map(function (color) { 54187 return parseInt(color, 16) / 255; 54188 }); 54189 return results; 54190 } else if (colorPatterns.RGB.test(str)) { 54191 // rgb(R,G,B) 54192 results = colorPatterns.RGB.exec(str).slice(1).map(function (color) { 54193 return color / 255; 54194 }); 54195 results[3] = 1; 54196 return results; 54197 } else if (colorPatterns.RGB_PERCENT.test(str)) { 54198 // rgb(R%,G%,B%) 54199 results = colorPatterns.RGB_PERCENT.exec(str).slice(1).map(function (color) { 54200 return parseFloat(color) / 100; 54201 }); 54202 results[3] = 1; 54203 return results; 54204 } else if (colorPatterns.RGBA.test(str)) { 54205 // rgba(R,G,B,A) 54206 results = colorPatterns.RGBA.exec(str).slice(1).map(function (color, idx) { 54207 if (idx === 3) { 54208 return parseFloat(color); 54209 } 54210 return color / 255; 54211 }); 54212 return results; 54213 } else if (colorPatterns.RGBA_PERCENT.test(str)) { 54214 // rgba(R%,G%,B%,A%) 54215 results = colorPatterns.RGBA_PERCENT.exec(str).slice(1).map(function (color, idx) { 54216 if (idx === 3) { 54217 return parseFloat(color); 54218 } 54219 return parseFloat(color) / 100; 54220 }); 54221 return results; 54222 } // Try HSLA pattern matching. 54223 54224 if (colorPatterns.HSL.test(str)) { 54225 // hsl(H,S,L) 54226 results = colorPatterns.HSL.exec(str).slice(1).map(function (color, idx) { 54227 if (idx === 0) { 54228 return parseInt(color, 10) / 360; 54229 } 54230 return parseInt(color, 10) / 100; 54231 }); 54232 results[3] = 1; 54233 } else if (colorPatterns.HSLA.test(str)) { 54234 // hsla(H,S,L,A) 54235 results = colorPatterns.HSLA.exec(str).slice(1).map(function (color, idx) { 54236 if (idx === 0) { 54237 return parseInt(color, 10) / 360; 54238 } else if (idx === 3) { 54239 return parseFloat(color); 54240 } 54241 return parseInt(color, 10) / 100; 54242 }); 54243 } 54244 results = results.map(function (value) { 54245 return Math.max(Math.min(value, 1), 0); 54246 }); 54247 if (results.length) { 54248 return _color_conversion.default._hslaToRGBA(results); 54249 } // Try HSBA pattern matching. 54250 54251 if (colorPatterns.HSB.test(str)) { 54252 // hsb(H,S,B) 54253 results = colorPatterns.HSB.exec(str).slice(1).map(function (color, idx) { 54254 if (idx === 0) { 54255 return parseInt(color, 10) / 360; 54256 } 54257 return parseInt(color, 10) / 100; 54258 }); 54259 results[3] = 1; 54260 } else if (colorPatterns.HSBA.test(str)) { 54261 // hsba(H,S,B,A) 54262 results = colorPatterns.HSBA.exec(str).slice(1).map(function (color, idx) { 54263 if (idx === 0) { 54264 return parseInt(color, 10) / 360; 54265 } else if (idx === 3) { 54266 return parseFloat(color); 54267 } 54268 return parseInt(color, 10) / 100; 54269 }); 54270 } 54271 if (results.length) { 54272 // (loop backwards for performance) 54273 for (i = results.length - 1; i >= 0; --i) { 54274 results[i] = Math.max(Math.min(results[i], 1), 0); 54275 } 54276 return _color_conversion.default._hsbaToRGBA(results); 54277 } // Input did not match any CSS color pattern: default to white. 54278 54279 results = [ 54280 1, 54281 1, 54282 1, 54283 1 54284 ]; 54285 } else if ((numArgs === 1 || numArgs === 2) && typeof r === 'number') { 54286 // 'Grayscale' mode. 54287 /** 54288 * For HSB and HSL, interpret the gray level as a brightness/lightness 54289 * value (they are equivalent when chroma is zero). For RGB, normalize the 54290 * gray level according to the blue maximum. 54291 */ 54292 results[0] = r / maxes[2]; 54293 results[1] = r / maxes[2]; 54294 results[2] = r / maxes[2]; // Alpha may be undefined, so default it to 100%. 54295 if (typeof g === 'number') { 54296 results[3] = g / maxes[3]; 54297 } else { 54298 results[3] = 1; 54299 } // Constrain components to the range [0,1]. 54300 54301 results = results.map(function (value) {
54302 return Math.max(Math.min(value, 1), 0); 54303 }); 54304 } else { 54305 throw new Error(''.concat(arguments, 'is not a valid color representation.')); 54306 } 54307 return results; 54308 }; 54309 var _default = _main.default.Color; 54310 exports.default = _default; 54311 }, 54312 { 54313 '../core/constants': 278, 54314 '../core/main': 290, 54315 './color_conversion': 274, 54316 'core-js/modules/es.array.iterator': 176, 54317 'core-js/modules/es.array.join': 177, 54318 'core-js/modules/es.array.map': 179, 54319 'core-js/modules/es.array.slice': 180, 54320 'core-js/modules/es.object.get-own-property-descriptor': 191, 54321 'core-js/modules/es.object.to-string': 195, 54322 'core-js/modules/es.regexp.constructor': 198, 54323 'core-js/modules/es.regexp.exec': 199, 54324 'core-js/modules/es.regexp.to-string': 200, 54325 'core-js/modules/es.string.iterator': 204, 54326 'core-js/modules/es.string.trim': 211, 54327 'core-js/modules/es.symbol': 214, 54328 'core-js/modules/es.symbol.description': 212, 54329 'core-js/modules/es.symbol.iterator': 213, 54330 'core-js/modules/es.weak-map': 246, 54331 'core-js/modules/web.dom-collections.iterator': 248 54332 } 54333 ], 54334 277: [ 54335 function (_dereq_, module, exports) { 54336 'use strict'; 54337 _dereq_('core-js/modules/es.symbol'); 54338 _dereq_('core-js/modules/es.symbol.description'); 54339 _dereq_('core-js/modules/es.symbol.iterator'); 54340 _dereq_('core-js/modules/es.array.fill'); 54341 _dereq_('core-js/modules/es.array.iterator'); 54342 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 54343 _dereq_('core-js/modules/es.object.to-string'); 54344 _dereq_('core-js/modules/es.string.iterator'); 54345 _dereq_('core-js/modules/es.weak-map'); 54346 _dereq_('core-js/modules/web.dom-collections.iterator'); 54347 function _typeof2(obj) { 54348 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 54349 _typeof2 = function _typeof2(obj) { 54350 return typeof obj; 54351 }; 54352 } else { 54353 _typeof2 = function _typeof2(obj) { 54354 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 54355 }; 54356 } 54357 return _typeof2(obj); 54358 } 54359 function _typeof(obj) { 54360 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 54361 _typeof = function _typeof(obj) { 54362 return _typeof2(obj); 54363 }; 54364 } else { 54365 _typeof = function _typeof(obj) { 54366 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 54367 }; 54368 } 54369 return _typeof(obj); 54370 } 54371 _dereq_('core-js/modules/es.array.fill'); 54372 Object.defineProperty(exports, '__esModule', { 54373 value: true 54374 }); 54375 exports.default = void 0; 54376 var _main = _interopRequireDefault(_dereq_('../core/main')); 54377 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 54378 _dereq_('./p5.Color'); 54379 function _getRequireWildcardCache() { 54380 if (typeof WeakMap !== 'function') return null; 54381 var cache = new WeakMap(); 54382 _getRequireWildcardCache = function _getRequireWildcardCache() { 54383 return cache; 54384 }; 54385 return cache; 54386 } 54387 function _interopRequireWildcard(obj) { 54388 if (obj && obj.__esModule) { 54389 return obj; 54390 } 54391 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 54392 return { 54393 default: 54394 obj 54395 }; 54396 } 54397 var cache = _getRequireWildcardCache(); 54398 if (cache && cache.has(obj)) { 54399 return cache.get(obj); 54400 } 54401 var newObj = { 54402 }; 54403 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 54404 for (var key in obj) { 54405 if (Object.prototype.hasOwnProperty.call(obj, key)) { 54406 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 54407 if (desc && (desc.get || desc.set)) { 54408 Object.defineProperty(newObj, key, desc); 54409 } else { 54410 newObj[key] = obj[key]; 54411 } 54412 } 54413 } 54414 newObj.default = obj; 54415 if (cache) { 54416 cache.set(obj, newObj); 54417 } 54418 return newObj; 54419 } 54420 function _interopRequireDefault(obj) { 54421 return obj && obj.__esModule ? obj : { 54422 default: 54423 obj 54424 }; 54425 } /** 54426 * @module Color 54427 * @submodule Setting 54428 * @for p5 54429 * @requires core 54430 * @requires constants 54431 */ 54432 /** 54433 * The <a href="#/p5/background">background()</a> function sets the color used 54434 * for the background of the p5.js canvas. The default background is transparent. 54435 * This function is typically used within <a href="#/p5/draw">draw()</a> to clear 54436 * the display window at the beginning of each frame, but it can be used inside 54437 * <a href="#/p5/setup">setup()</a> to set the background on the first frame of 54438 * animation or if the background need only be set once. 54439 * 54440 * The color is either specified in terms of the RGB, HSB, or HSL color depending 54441 * on the current <a href="#/p5/colorMode">
54441colorMode</a>. (The default color space 54442 * is RGB, with each value in the range from 0 to 255). The alpha range by default 54443 * is also 0 to 255.<br><br> 54444 * 54445 * If a single string argument is provided, RGB, RGBA and Hex CSS color strings 54446 * and all named color strings are supported. In this case, an alpha number 54447 * value as a second argument is not supported, the RGBA form should be used. 54448 * 54449 * A <a href="#/p5.Color">p5.Color</a> object can also be provided to set the background color. 54450 * 54451 * A <a href="#/p5.Image">p5.Image</a> can also be provided to set the background image. 54452 * 54453 * @method background 54454 * @param {p5.Color} color any value created by the <a href="#/p5/color">color()</a> function 54455 * @chainable 54456 * 54457 * @example 54458 * <div> 54459 * <code> 54460 * // Grayscale integer value 54461 * background(51); 54462 * describe('canvas with darkest charcoal grey background'); 54463 * </code> 54464 * </div> 54465 * 54466 * <div> 54467 * <code> 54468 * // R, G & B integer values 54469 * background(255, 204, 0); 54470 * describe('canvas with yellow background'); 54471 * </code> 54472 * </div> 54473 * 54474 * <div> 54475 * <code> 54476 * // H, S & B integer values 54477 * colorMode(HSB); 54478 * background(255, 204, 100); 54479 * describe('canvas with royal blue background'); 54480 * </code> 54481 * </div> 54482 * 54483 * <div> 54484 * <code> 54485 * // Named SVG/CSS color string 54486 * background('red'); 54487 * describe('canvas with red background'); 54488 * </code> 54489 * </div> 54490 * 54491 * <div> 54492 * <code> 54493 * // three-digit hexadecimal RGB notation 54494 * background('#fae'); 54495 * describe('canvas with pink background'); 54496 * </code> 54497 * </div> 54498 * 54499 * <div> 54500 * <code> 54501 * // six-digit hexadecimal RGB notation 54502 * background('#222222'); 54503 * describe('canvas with black background'); 54504 * </code> 54505 * </div> 54506 * 54507 * <div> 54508 * <code> 54509 * // integer RGB notation 54510 * background('rgb(0,255,0)'); 54511 * describe('canvas with bright green background'); 54512 * </code> 54513 * </div> 54514 * 54515 * <div> 54516 * <code> 54517 * // integer RGBA notation 54518 * background('rgba(0,255,0, 0.25)'); 54519 * describe('canvas with soft green background'); 54520 * </code> 54521 * </div> 54522 * 54523 * <div> 54524 * <code> 54525 * // percentage RGB notation 54526 * background('rgb(100%,0%,10%)'); 54527 * describe('canvas with red background'); 54528 * </code> 54529 * </div> 54530 * 54531 * <div> 54532 * <code> 54533 * // percentage RGBA notation 54534 * background('rgba(100%,0%,100%,0.5)'); 54535 * describe('canvas with light purple background'); 54536 * </code> 54537 * </div> 54538 * 54539 * <div> 54540 * <code> 54541 * // p5 Color object 54542 * background(color(0, 0, 255)); 54543 * describe('canvas with blue background'); 54544 * </code> 54545 * </div> 54546 * 54547 */ 54548 /** 54549 * @method background 54550 * @param {String} colorstring color string, possible formats include: integer 54551 * rgb() or rgba(), percentage rgb() or rgba(), 54552 * 3-digit hex, 6-digit hex 54553 * @param {Number} [a] opacity of the background relative to current 54554 * color range (default is 0-255) 54555 * @chainable 54556 */ 54557 /** 54558 * @method background 54559 * @param {Number} gray specifies a value between white and black 54560 * @param {Number} [a] 54561 * @chainable 54562 */ 54563 /** 54564 * @method background 54565 * @param {Number} v1 red or hue value (depending on the current color 54566 * mode) 54567 * @param {Number} v2 green or saturation value (depending on the current 54568 * color mode) 54569 * @param {Number} v3 blue or brightness value (depending on the current 54570 * color mode) 54571 * @param {Number} [a] 54572 * @chainable 54573 */ 54574 /** 54575 * @method background 54576 * @param {Number[]} values an array containing the red, green, blue 54577 * and alpha components of the color 54578 * @chainable 54579 */ 54580 /** 54581 * @method background 54582 * @param {p5.Image} image image created with <a href="#/p5/loadImage">loadImage()</a> or <a href="#/p5/createImage">createImage()</a>, 54583 * to set as background 54584 * (must be same size as the sketch window) 54585 * @param {Number} [a] 54586 * @chainable 54587 */ 54588 54589 _main.default.prototype.background = function () { 54590 var _this$_renderer; 54591 (_this$_renderer = this._renderer).background.apply(_this$_renderer, arguments); 54592 return this; 54593 }; 54594 /** 54595 * Clears the pixels within a buffer. This function only clears the canvas. 54596 * It will not clear objects created by createX() methods such as 54597 * <a href="#/p5/createVideo">createVideo()</a> or <a href="#/p5/createDiv">createDiv()</a>. 54598 * Unlike the main graphics context, pixels in additional graphics areas created 54599 * with <a href="#/p5/createGraphics">createGraphics()</a> can be entirely 54600 * or partially transparent. This function clears everything to make all of 54601 * the pixels 100% transparent. 54602 *
54603 * Note: In WebGL mode, this function can be passed normalized RGBA color values in 54604 * order to clear the screen to a specific color. In addition to color, it will also 54605 * clear the depth buffer. If you are not using the webGL renderer 54606 * these color values will have no effect. 54607 * 54608 * @method clear 54609 * @chainable 54610 * @example 54611 * <div> 54612 * <code> 54613 * // Clear the screen on mouse press. 54614 * function draw() { 54615 * ellipse(mouseX, mouseY, 20, 20); 54616 * describe(`small white ellipses are continually drawn at mouseâs x and y 54617 * coordinates.`); 54618 * } 54619 * function mousePressed() { 54620 * clear(); 54621 * background(128); 54622 * describe( 54623 * 'canvas is cleared, small white ellipse is drawn at mouse X and mouse Y' 54624 * ); 54625 * } 54626 * </code> 54627 * </div> 54628 * 54629 * @param {Number} r normalized red val. 54630 * @param {Number} g normalized green val. 54631 * @param {Number} b normalized blue val. 54632 * @param {Number} a normalized alpha val. 54633 */ 54634 _main.default.prototype.clear = function () { 54635 var _r = (arguments.length <= 0 ? undefined : arguments[0]) || 0; 54636 var _g = (arguments.length <= 1 ? undefined : arguments[1]) || 0; 54637 var _b = (arguments.length <= 2 ? undefined : arguments[2]) || 0; 54638 var _a = (arguments.length <= 3 ? undefined : arguments[3]) || 0; 54639 this._renderer.clear(_r, _g, _b, _a); 54640 return this; 54641 }; 54642 /** 54643 * <a href="#/p5/colorMode">colorMode()</a> changes the way p5.js interprets 54644 * color data. By default, the parameters for <a href="#/p5/fill">fill()</a>, 54645 * <a href="#/p5/stroke">stroke()</a>, <a href="#/p5/background">background()</a>, 54646 * and <a href="#/p5/color">color()</a> are defined by values between 0 and 255 54647 * using the RGB color model. This is equivalent to setting colorMode(RGB, 255). 54648 * Setting colorMode(HSB) lets you use the HSB system instead. By default, this 54649 * is colorMode(HSB, 360, 100, 100, 1). You can also use HSL. 54650 *
54651 * Note: existing color objects remember the mode that they were created in, 54652 * so you can change modes as you like without affecting their appearance. 54653 * 54654 * @method colorMode 54655 * @param {Constant} mode either RGB, HSB or HSL, corresponding to 54656 * Red/Green/Blue and Hue/Saturation/Brightness 54657 * (or Lightness) 54658 * @param {Number} [max] range for all values 54659 * @chainable 54660 * 54661 * @example 54662 * <div> 54663 * <code> 54664 * noStroke(); 54665 * colorMode(RGB, 100); 54666 * for (let i = 0; i < 100; i++) { 54667 * for (let j = 0; j < 100; j++) { 54668 * stroke(i, j, 0); 54669 * point(i, j); 54670 * } 54671 * } 54672 * describe( 54673 * 'Green to red gradient from bottom left to top right with shading from top left' 54674 * ); 54675 * </code> 54676 * </div> 54677 * 54678 * <div> 54679 * <code> 54680 * noStroke(); 54681 * colorMode(HSB, 100); 54682 * for (let i = 0; i < 100; i++) { 54683 * for (let j = 0; j < 100; j++) { 54684 * stroke(i, j, 100); 54685 * point(i, j); 54686 * } 54687 * } 54688 * describe(`Rainbow gradient from left to right. 54689 * Brightness increasing to white at top.`); 54690 * </code> 54691 * </div> 54692 * 54693 * <div> 54694 * <code> 54695 * colorMode(RGB, 255); 54696 * let c = color(127, 255, 0); 54697 * colorMode(RGB, 1); 54698 * let myColor = c._getRed(); 54699 * text(myColor, 10, 10, 80, 80); 54700 * describe('value of color red 0.4980... written on canvas'); 54701 * </code> 54702 * </div> 54703 * 54704 * <div> 54705 * <code> 54706 * noFill(); 54707 * colorMode(RGB, 255, 255, 255, 1); 54708 * background(255); 54709 * strokeWeight(4); 54710 * stroke(255, 0, 10, 0.3); 54711 * ellipse(40, 40, 50, 50); 54712 * ellipse(50, 50, 40, 40); 54713 * describe('two translucent pink ellipse outlines at middle left and at center'); 54714 * </code> 54715 * </div> 54716 * 54717 */ 54718 /** 54719 * @method colorMode 54720 * @param {Constant} mode 54721 * @param {Number} max1 range for the red or hue depending on the 54722 * current color mode 54723 * @param {Number} max2 range for the green or saturation depending 54724 * on the current color mode 54725 * @param {Number} max3 range for the blue or brightness/lightness 54726 * depending on the current color mode 54727 * @param {Number} [maxA] range for the alpha 54728 * @chainable 54729 */ 54730 _main.default.prototype.colorMode = function (mode, max1, max2, max3, maxA) { 54731 _main.default._validateParameters('colorMode', arguments); 54732 if (mode === constants.RGB || mode === constants.HSB || mode === constants.HSL) { 54733 // Set color mode. 54734 this._colorMode = mode; // Set color maxes. 54735 var maxes = this._colorMaxes[mode]; 54736 if (arguments.length === 2) { 54737 maxes[0] = max1; // Red 54738 maxes[1] = max1; // Green 54739 maxes[2] = max1; // Blue 54740 maxes[3] = max1; // Alpha 54741 } else if (arguments.length === 4) { 54742 maxes[0] = max1; // Red 54743 maxes[1] = max2; // Green 54744 maxes[2] = max3; // Blue 54745 } else if (arguments.length === 5) { 54746 maxes[0] = max1; // Red 54747 maxes[1] = max2; // Green 54748 maxes[2] = max3; // Blue 54749 maxes[3] = maxA; // Alpha 54750 } 54751 } 54752 return this; 54753 }; 54754 /** 54755 * Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), 54756 * all shapes drawn after the fill command will be filled with the color orange. 54757 * This color is either specified in terms of the RGB or HSB color depending on 54758 * the current <a href="#/p5/colorMode">colorMode()</a>. (The default color space 54759 * is RGB, with each value in the range from 0 to 255). The alpha range by default 54760 * is also 0 to 255. 54761 * 54762 * If a single string argument is provided, RGB, RGBA and Hex CSS color strings 54763 * and all named color strings are supported. In this case, an alpha number 54764 * value as a second argument is not supported, the RGBA form should be used. 54765 * 54766 * A <a href="#/p5.Color">p5.Color</a> object can also be provided to set the fill color. 54767 * 54768 * @method fill 54769 * @param {Number} v1 red or hue value relative to 54770 * the current color range 54771 * @param {Number} v2 green or saturation value 54772 * relative to the current color range 54773 * @param {Number} v3 blue or brightness value 54774 * relative to the current color range 54775 * @param {Number} [alpha] 54776 * @chainable 54777 * @example 54778 * <div> 54779 * <code> 54780 * // Grayscale integer value 54781 * fill(51); 54782 * rect(20, 20, 60, 60); 54783 * describe('dark charcoal grey rect with black outline in center of canvas'); 54784 * </code> 54785 * </div> 54786 * 54787 * <div> 54788 * <code> 54789 * // R, G & B integer values 54790 * fill(255, 204, 0); 54791 * rect(20, 20, 60, 60); 54792 * describe('yellow rect with black outline in center of canvas'); 54793 * </code> 54794 * </div> 54795 * 54796 * <div> 54797 * <code> 54798 * // H, S & B integer values 54799 * colorMode(HSB); 54800 * fill(255, 204, 100); 54801 * rect(20, 20, 60, 60); 54802 * describe('royal blue rect with black outline in center of canvas'); 54803 * </code> 54804 * </div> 54805 * 54806 * <div> 54807 * <code> 54808 * // Named SVG/CSS color string 54809 * fill('red'); 54810 * rect(20, 20, 60, 60); 54811 * describe('red rect with black outline in center of canvas'); 54812 * </code> 54813 * </div> 54814 * 54815 * <div> 54816 * <code> 54817 * // three-digit hexadecimal RGB notation 54818 * fill('#fae'); 54819 * rect(20, 20, 60, 60); 54820 * describe('pink rect with black outline in center of canvas'); 54821 * </code> 54822 * </div> 54823 * 54824 * <div> 54825 * <code> 54826 * // six-digit hexadecimal RGB notation 54827 * fill('#222222'); 54828 * rect(20, 20, 60, 60); 54829 * describe('black rect with black outline in center of canvas'); 54830 * </code> 54831 * </div> 54832 * 54833 * <div> 54834 * <code> 54835 * // integer RGB notation 54836 * fill('rgb(0,255,0)'); 54837 * rect(20, 20, 60, 60); 54838 * describe('bright green rect with black outline in center of canvas'); 54839 * </code> 54840 * </div> 54841 * 54842 * <div> 54843 * <code> 54844 * // integer RGBA notation 54845 * fill('rgba(0,255,0, 0.25)'); 54846 * rect(20, 20, 60, 60); 54847 * describe('soft green rect with black outline in center of canvas'); 54848 * </code> 54849 * </div> 54850 * 54851 * <div> 54852 * <code> 54853 * // percentage RGB notation 54854 * fill('rgb(100%,0%,10%)'); 54855 * rect(20, 20, 60, 60); 54856 * describe('red rect with black outline in center of canvas'); 54857 * </code> 54858 * </div> 54859 * 54860 * <div> 54861 * <code> 54862 * // percentage RGBA notation 54863 * fill('rgba(100%,0%,100%,0.5)'); 54864 * rect(20, 20, 60, 60); 54865 * describe('dark fuchsia rect with black outline in center of canvas'); 54866 * </code> 54867 * </div> 54868 * 54869 * <div> 54870 * <code> 54871 * // p5 Color object 54872 * fill(color(0, 0, 255)); 54873 * rect(20, 20, 60, 60); 54874 * describe('blue rect with black outline in center of canvas'); 54875 * </code> 54876 * </div> 54877 */ 54878 /** 54879 * @method fill 54880 * @param {String} value a color string 54881 * @chainable 54882 */ 54883 /** 54884 * @method fill 54885 * @param {Number} gray a gray value 54886 * @param {Number} [alpha] 54887 * @chainable 54888 */ 54889 /** 54890 * @method fill 54891 * @param {Number[]} values an array containing the red,green,blue & 54892 * and alpha components of the color 54893 * @chainable 54894 */ 54895 /** 54896 * @method fill 54897 * @param {p5.Color} color the fill color 54898 * @chainable 54899 */ 54900 _main.default.prototype.fill = function () { 54901 var _this$_renderer2; 54902 this._renderer._setProperty('_fillSet', true); 54903 this._renderer._setProperty('_doFill', true); 54904 (_this$_renderer2 = this._renderer).fill.apply(_this$_renderer2, arguments); 54905 return this; 54906 }; 54907 /** 54908 * Disables filling geometry. If both <a href="#/p5/noStroke">noStroke()</a> and <a href="#/p5/noFill">noFill()</a> are called, 54909 * nothing will be drawn to the screen. 54910 * 54911 * @method noFill 54912 * @chainable 54913 * @example 54914 * <div> 54915 * <code> 54916 * rect(15, 10, 55, 55); 54917 * noFill(); 54918 * rect(20, 20, 60, 60); 54919 * describe(`White rect at top middle and noFill rect center, 54920 * both with black outlines.`); 54921 * </code> 54922 * </div> 54923 * 54924 * <div modernizr='webgl'> 54925 * <code> 54926 * function setup() { 54927 * createCanvas(100, 100, WEBGL); 54928 * } 54929 * 54930 * function draw() { 54931 * background(0); 54932 * noFill(); 54933 * stroke(100, 100, 240); 54934 * rotateX(frameCount * 0.01); 54935 * rotateY(frameCount * 0.01); 54936 * box(45, 45, 45); 54937 * describe('black canvas with purple cube wireframe spinning'); 54938 * } 54939 * </code> 54940 * </div> 54941 */ 54942 _main.default.prototype.noFill = function () { 54943 this._renderer._setProperty('_doFill', false); 54944 return this; 54945 }; 54946 /** 54947 * Disables drawing the stroke (outline). If both <a href="#/p5/noStroke">noStroke()</a> and <a href="#/p5/noFill">noFill()</a> 54948 * are called, nothing will be drawn to the screen. 54949 * 54950 * @method noStroke 54951 * @chainable 54952 * @example 54953 * <div> 54954 * <code> 54955 * noStroke(); 54956 * rect(20, 20, 60, 60); 54957 * describe('White rect at center; no outline.'); 54958 * </code> 54959 * </div> 54960 * 54961 * <div modernizr='webgl'> 54962 * <code> 54963 * function setup() { 54964 * createCanvas(100, 100, WEBGL); 54965 * } 54966 * 54967 * function draw() { 54968 * background(0); 54969 * noStroke(); 54970 * fill(240, 150, 150); 54971 * rotateX(frameCount * 0.01); 54972 * rotateY(frameCount * 0.01); 54973 * box(45, 45, 45); 54974 * describe('black canvas with pink cube spinning'); 54975 * } 54976 * </code> 54977 * </div> 54978 */ 54979 _main.default.prototype.noStroke = function () { 54980 this._renderer._setProperty('_doStroke', false); 54981 return this; 54982 }; 54983 /** 54984 * Sets the color used to draw lines and borders around shapes. This color 54985 * is either specified in terms of the RGB or HSB color depending on the 54986 * current <a href="#/p5/colorMode">colorMode()</a> (the default color space 54987 * is RGB, with each value in the range from 0 to 255). The alpha range by 54988 * default is also 0 to 255. 54989 *
54990 * If a single string argument is provided, RGB, RGBA and Hex CSS color 54991 * strings and all named color strings are supported. In this case, an alpha 54992 * number value as a second argument is not supported, the RGBA form should be 54993 * used. 54994 * 54995 * A <a href="#/p5.Color">p5.Color</a> object can also be provided to set the stroke color. 54996 * 54997 * @method stroke 54998 * @param {Number} v1 red or hue value relative to 54999 * the current color range 55000 * @param {Number} v2 green or saturation value 55001 * relative to the current color range 55002 * @param {Number} v3 blue or brightness value 55003 * relative to the current color range 55004 * @param {Number} [alpha] 55005 * @chainable 55006 * 55007 * @example 55008 * <div> 55009 * <code> 55010 * // Grayscale integer value 55011 * strokeWeight(4); 55012 * stroke(51); 55013 * rect(20, 20, 60, 60); 55014 * describe('White rect at center with dark charcoal grey outline.'); 55015 * </code> 55016 * </div> 55017 * 55018 * <div> 55019 * <code> 55020 * // R, G & B integer values 55021 * stroke(255, 204, 0); 55022 * strokeWeight(4); 55023 * rect(20, 20, 60, 60); 55024 * describe('White rect at center with yellow outline.'); 55025 * </code> 55026 * </div> 55027 * 55028 * <div> 55029 * <code> 55030 * // H, S & B integer values 55031 * colorMode(HSB); 55032 * strokeWeight(4); 55033 * stroke(255, 204, 100); 55034 * rect(20, 20, 60, 60); 55035 * describe('White rect at center with royal blue outline.'); 55036 * </code> 55037 * </div> 55038 * 55039 * <div> 55040 * <code> 55041 * // Named SVG/CSS color string 55042 * stroke('red'); 55043 * strokeWeight(4); 55044 * rect(20, 20, 60, 60); 55045 * describe('White rect at center with red outline.'); 55046 * </code> 55047 * </div> 55048 * 55049 * <div> 55050 * <code> 55051 * // three-digit hexadecimal RGB notation 55052 * stroke('#fae'); 55053 * strokeWeight(4); 55054 * rect(20, 20, 60, 60); 55055 * describe('White rect at center with pink outline.'); 55056 * </code> 55057 * </div> 55058 * 55059 * <div> 55060 * <code> 55061 * // six-digit hexadecimal RGB notation 55062 * stroke('#222222'); 55063 * strokeWeight(4); 55064 * rect(20, 20, 60, 60); 55065 * describe('White rect at center with black outline.'); 55066 * </code> 55067 * </div> 55068 * 55069 * <div> 55070 * <code> 55071 * // integer RGB notation 55072 * stroke('rgb(0,255,0)'); 55073 * strokeWeight(4); 55074 * rect(20, 20, 60, 60); 55075 * describe('White rect at center with bright green outline.'); 55076 * </code> 55077 * </div> 55078 * 55079 * <div> 55080 * <code> 55081 * // integer RGBA notation 55082 * stroke('rgba(0,255,0,0.25)'); 55083 * strokeWeight(4); 55084 * rect(20, 20, 60, 60); 55085 * describe('White rect at center with soft green outline.'); 55086 * </code> 55087 * </div> 55088 * 55089 * <div> 55090 * <code> 55091 * // percentage RGB notation 55092 * stroke('rgb(100%,0%,10%)'); 55093 * strokeWeight(4); 55094 * rect(20, 20, 60, 60); 55095 * describe('White rect at center with red outline.'); 55096 * </code> 55097 * </div> 55098 * 55099 * <div> 55100 * <code> 55101 * // percentage RGBA notation 55102 * stroke('rgba(100%,0%,100%,0.5)'); 55103 * strokeWeight(4); 55104 * rect(20, 20, 60, 60); 55105 * describe('White rect at center with dark fuchsia outline.'); 55106 * </code> 55107 * </div> 55108 * 55109 * <div> 55110 * <code> 55111 * // p5 Color object 55112 * stroke(color(0, 0, 255)); 55113 * strokeWeight(4); 55114 * rect(20, 20, 60, 60); 55115 * describe('White rect at center with blue outline.'); 55116 * </code> 55117 * </div> 55118 */ 55119 /** 55120 * @method stroke 55121 * @param {String} value a color string 55122 * @chainable 55123 */ 55124 /** 55125 * @method stroke 55126 * @param {Number} gray a gray value 55127 * @param {Number} [alpha] 55128 * @chainable 55129 */ 55130 /** 55131 * @method stroke 55132 * @param {Number[]} values an array containing the red,green,blue & 55133 * and alpha components of the color 55134 * @chainable 55135 */ 55136 /** 55137 * @method stroke 55138 * @param {p5.Color} color the stroke color 55139 * @chainable 55140 */ 55141 _main.default.prototype.stroke = function () { 55142 var _this$_renderer3; 55143 this._renderer._setProperty('_strokeSet', true); 55144 this._renderer._setProperty('_doStroke', true); 55145 (_this$_renderer3 = this._renderer).stroke.apply(_this$_renderer3, arguments); 55146 return this; 55147 }; 55148 /** 55149 * All drawing that follows <a href="#/p5/erase">erase()</a> will subtract from 55150 * the canvas. Erased areas will reveal the web page underneath the canvas. Erasing 55151 * can be canceled with <a href="#/p5/noErase">noErase()</a>. 55152 * 55153 * Drawing done with <a href="#/p5/image">image()</a> and <a href="#/p5/background"> 55154 * background()</a> in between <a href="#/p5/erase">erase()</a> and 55155 * <a href="#/p5/noErase">noErase()</a> will not erase the canvas but works as usual. 55156 * 55157 * @method erase 55158 * @param {Number} [strengthFill] A number (0-255) for the strength of erasing for a shape's fill. 55159 * This will default to 255 when no argument is given, which 55160 * is full strength. 55161 * @param {Number} [strengthStroke] A number (0-255) for the strength of erasing for a shape's stroke. 55162 * This will default to 255 when no argument is given, which 55163 * is full strength. 55164 * 55165 * @chainable 55166 * @example 55167 * <div> 55168 * <code> 55169 * background(100, 100, 250); 55170 * fill(250, 100, 100); 55171 * rect(20, 20, 60, 60); 55172 * erase(); 55173 * ellipse(25, 30, 30); 55174 * noErase(); 55175 * describe(`60Ã60 centered pink rect, purple background. 55176 * Elliptical area in top-left of rect is erased white.`); 55177 * </code> 55178 * </div> 55179 * 55180 * <div> 55181 * <code> 55182 * background(150, 250, 150); 55183 * fill(100, 100, 250); 55184 * rect(20, 20, 60, 60); 55185 * strokeWeight(5); 55186 * erase(150, 255); 55187 * triangle(50, 10, 70, 50, 90, 10); 55188 * noErase(); 55189 * describe(`60Ã60 centered purple rect, mint green background. 55190 * Triangle in top-right is partially erased with fully erased outline.`); 55191 * </code> 55192 * </div> 55193 * 55194 * <div> 55195 * <code> 55196 * function setup() { 55197 * smooth(); 55198 * createCanvas(100, 100, WEBGL); 55199 * // Make a <p> element and put it behind the canvas 55200 * let p = createP('I am a dom element'); 55201 * p.center(); 55202 * p.style('font-size', '20px'); 55203 * p.style('text-align', 'center'); 55204 * p.style('z-index', '-9999'); 55205 * } 55206 * 55207 * function draw() { 55208 * background(250, 250, 150); 55209 * fill(15, 195, 185); 55210 * noStroke(); 55211 * sphere(30); 55212 * erase(); 55213 * rotateY(frameCount * 0.02); 55214 * translate(0, 0, 40); 55215 * torus(15, 5); 55216 * noErase(); 55217 * describe(`60Ã60 centered teal sphere, yellow background. 55218 * Torus rotating around sphere erases to reveal black text underneath.`); 55219 * } 55220 * </code> 55221 * </div> 55222 */ 55223 _main.default.prototype.erase = function () { 55224 var opacityFill = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 255; 55225 var opacityStroke = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 255; 55226 this._renderer.erase(opacityFill, opacityStroke); 55227 return this; 55228 }; 55229 /** 55230 * Ends erasing that was started with <a href="#/p5/erase">erase()</a>. 55231 * The <a href="#/p5/fill">fill()</a>, <a href="#/p5/stroke">stroke()</a>, and 55232 * <a href="#/p5/blendMode">blendMode()</a> settings will return to what they were 55233 * prior to calling <a href="#/p5/erase">erase()</a>. 55234 * 55235 * @method noErase 55236 * @chainable 55237 * @example 55238 * <div> 55239 * <code> 55240 * background(235, 145, 15); 55241 * noStroke(); 55242 * fill(30, 45, 220); 55243 * rect(30, 10, 10, 80); 55244 * erase(); 55245 * ellipse(50, 50, 60); 55246 * noErase(); 55247 * rect(70, 10, 10, 80); 55248 * describe(`Orange background, with two tall blue rectangles. 55249 * A centered ellipse erased the first blue rect but not the second.`); 55250 * </code> 55251 * </div> 55252 */ 55253 _main.default.prototype.noErase = function () { 55254 this._renderer.noErase(); 55255 return this; 55256 }; 55257 var _default = _main.default; 55258 exports.default = _default; 55259 }, 55260 { 55261 '../core/constants': 278, 55262 '../core/main': 290, 55263 './p5.Color': 276, 55264 'core-js/modules/es.array.fill': 170, 55265 'core-js/modules/es.array.iterator': 176, 55266 'core-js/modules/es.object.get-own-property-descriptor': 191, 55267 'core-js/modules/es.object.to-string': 195, 55268 'core-js/modules/es.string.iterator': 204, 55269 'core-js/modules/es.symbol': 214, 55270 'core-js/modules/es.symbol.description': 212, 55271 'core-js/modules/es.symbol.iterator': 213, 55272 'core-js/modules/es.weak-map': 246, 55273 'core-js/modules/web.dom-collections.iterator': 248 55274 } 55275 ], 55276 278: [
55277 function (_dereq_, module, exports) { 55278 'use strict'; 55279 Object.defineProperty(exports, '__esModule', { 55280 value: true 55281 }); 55282 exports.BEZIER = exports.QUADRATIC = exports.LINEAR = exports._CTX_MIDDLE = exports._DEFAULT_LEADMULT = exports._DEFAULT_TEXT_FILL = exports.WORD = exports.CHAR = exports.BOLDITALIC = exports.BOLD = exports.ITALIC = exports.NORMAL = exports.BLUR = exports.ERODE = exports.DILATE = exports.POSTERIZE = exports.INVERT = exports.OPAQUE = exports.GRAY = exports.THRESHOLD = exports.BURN = exports.DODGE = exports.SOFT_LIGHT = exports.HARD_LIGHT = exports.OVERLAY = exports.REPLACE = exports.SCREEN = exports.MULTIPLY = exports.EXCLUSION = exports.SUBTRACT = exports.DIFFERENCE = exports.LIGHTEST = exports.DARKEST = exports.ADD = exports.REMOVE = exports.BLEND = exports.UP_ARROW = exports.TAB = exports.SHIFT = exports.RIGHT_ARROW = exports.RETURN = exports.OPTION = exports.LEFT_ARROW = exports.ESCAPE = exports.ENTER = exports.DOWN_ARROW = exports.DELETE = exports.CONTROL = exports.BACKSPACE = exports.ALT = exports.AUTO = exports.HSL = exports.HSB = exports.RGB = exports.MITER = exports.BEVEL = exports.ROUND = exp
55282orts.SQUARE = exports.PROJECT = exports.PIE = exports.CHORD = exports.OPEN = exports.CLOSE = exports.TESS = exports.QUAD_STRIP = exports.QUADS = exports.TRIANGLE_STRIP = exports.TRIANGLE_FAN = exports.TRIANGLES = exports.LINE_LOOP = exports.LINE_STRIP = exports.LINES = exports.POINTS = exports.BASELINE = exports.BOTTOM = exports.TOP = exports.CENTER = exports.LEFT = exports.RIGHT = exports.RADIUS = exports.CORNERS = exports.CORNER = exports.RAD_TO_DEG = exports.DEG_TO_RAD = exports.RADIANS = exports.DEGREES = exports.TWO_PI = exports.TAU = exports.QUARTER_PI = exports.PI = exports.HALF_PI = exports.WAIT = exports.TEXT = exports.MOVE = exports.HAND = exports.CROSS = exports.ARROW = exports.WEBGL = exports.P2D = exports.VERSION = void 0; 55283 exports.COVER = exports.CONTAIN = exports.FALLBACK = exports.LABEL = exports.AXES = exports.GRID = exports._DEFAULT_FILL = exports._DEFAULT_STROKE = exports.PORTRAIT = exports.LANDSCAPE = exports.MIRROR = exports.CLAMP = exports.REPEAT = exports.NEAREST = exports.IMAGE = exports.IMMEDIATE = exports.TEXTURE = exports.FILL = exports.STROKE = exports.CURVE = void 0; 55284 /** 55285 * @module Constants 55286 * @submodule Constants 55287 * @for p5 55288 */ 55289 var _PI = Math.PI; 55290 /** 55291 * Version of this p5.js. 55292 * @property {String} VERSION 55293 * @final 55294 */ 55295 var VERSION = '1.6.0'; // GRAPHICS RENDERER 55296 /** 55297 * The default, two-dimensional renderer. 55298 * @property {String} P2D 55299 * @final 55300 */ 55301 exports.VERSION = VERSION; 55302 var P2D = 'p2d'; 55303 /** 55304 * One of the two render modes in p5.js: P2D (default renderer) and WEBGL 55305 * Enables 3D render by introducing the third dimension: Z 55306 * @property {String} WEBGL 55307 * @final 55308 */ 55309 exports.P2D = P2D; 55310 var WEBGL = 'webgl'; // ENVIRONMENT 55311 /** 55312 * @property {String} ARROW 55313 * @final 55314 */ 55315 exports.WEBGL = WEBGL; 55316 var ARROW = 'default'; 55317 /** 55318 * @property {String} CROSS 55319 * @final 55320 */ 55321 exports.ARROW = ARROW; 55322 var CROSS = 'crosshair'; 55323 /** 55324 * @property {String} HAND 55325 * @final 55326 */ 55327 exports.CROSS = CROSS; 55328 var HAND = 'pointer'; 55329 /** 55330 * @property {String} MOVE 55331 * @final 55332 */ 55333 exports.HAND = HAND; 55334 var MOVE = 'move'; 55335 /** 55336 * @property {String} TEXT 55337 * @final 55338 */ 55339 exports.MOVE = MOVE; 55340 var TEXT = 'text'; 55341 /** 55342 * @property {String} WAIT 55343 * @final 55344 */ 55345 exports.TEXT = TEXT; 55346 var WAIT = 'wait'; // TRIGONOMETRY 55347 /** 55348 * HALF_PI is a mathematical constant with the value 55349 * 1.57079632679489661923. It is half the ratio of the 55350 * circumference of a circle to its diameter. It is useful in 55351 * combination with the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>. 55352 * 55353 * @property {Number} HALF_PI 55354 * @final 55355 * 55356 * @example 55357 * <div><code> 55358 * arc(50, 50, 80, 80, 0, HALF_PI); 55359 * </code></div> 55360 * 55361 * @alt 55362 * 80Ã80 white quarter-circle with curve toward bottom right of canvas. 55363 */ 55364 exports.WAIT = WAIT; 55365 var HALF_PI = _PI / 2; 55366 /** 55367 * PI is a mathematical constant with the value 55368 * 3.14159265358979323846. It is the ratio of the circumference 55369 * of a circle to its diameter. It is useful in combination with 55370 * the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>. 55371 * 55372 * @property {Number} PI 55373 * @final 55374 * 55375 * @example 55376 * <div><code> 55377 * arc(50, 50, 80, 80, 0, PI); 55378 * </code></div> 55379 * 55380 * @alt 55381 * white half-circle with curve toward bottom of canvas. 55382 */ 55383 exports.HALF_PI = HALF_PI; 55384 var PI = _PI; 55385 /** 55386 * QUARTER_PI is a mathematical constant with the value 0.7853982. 55387 * It is one quarter the ratio of the circumference of a circle to 55388 * its diameter. It is useful in combination with the trigonometric 55389 * functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>. 55390 * 55391 * @property {Number} QUARTER_PI 55392 * @final 55393 * 55394 * @example 55395 * <div><code> 55396 * arc(50, 50, 80, 80, 0, QUARTER_PI); 55397 * </code></div> 55398 * 55399 * @alt 55400 * white eighth-circle rotated about 40 degrees with curve bottom right canvas. 55401 */ 55402 exports.PI = PI; 55403 var QUARTER_PI = _PI / 4; 55404 /** 55405 * TAU is an alias for TWO_PI, a mathematical constant with the 55406 * value 6.28318530717958647693. It is twice the ratio of the 55407 * circumference of a circle to its diameter. It is useful in 55408 * combination with the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>. 55409 * 55410 * @property {Number} TAU 55411 * @final 55412 * 55413 * @example 55414 * <div><code> 55415 * arc(50, 50, 80, 80, 0, TAU); 55416 * </code></div> 55417 * 55418 * @alt 55419 * 80Ã80 white ellipse shape in center of canvas. 55420 */
55421 exports.QUARTER_PI = QUARTER_PI; 55422 var TAU = _PI * 2; 55423 /** 55424 * TWO_PI is a mathematical constant with the value 55425 * 6.28318530717958647693. It is twice the ratio of the 55426 * circumference of a circle to its diameter. It is useful in 55427 * combination with the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>. 55428 * 55429 * @property {Number} TWO_PI 55430 * @final 55431 * 55432 * @example 55433 * <div><code> 55434 * arc(50, 50, 80, 80, 0, TWO_PI); 55435 * </code></div> 55436 * 55437 * @alt 55438 * 80Ã80 white ellipse shape in center of canvas. 55439 */ 55440 exports.TAU = TAU; 55441 var TWO_PI = _PI * 2; 55442 /** 55443 * Constant to be used with the <a href="#/p5/angleMode">angleMode()</a> function, to set the mode in 55444 * which p5.js interprets and calculates angles (either DEGREES or RADIANS). 55445 * @property {String} DEGREES 55446 * @final 55447 * 55448 * @example 55449 * <div class='norender'><code> 55450 * function setup() { 55451 * angleMode(DEGREES); 55452 * } 55453 * </code></div> 55454 */ 55455 exports.TWO_PI = TWO_PI; 55456 var DEGREES = 'degrees'; 55457 /** 55458 * Constant to be used with the <a href="#/p5/angleMode">angleMode()</a> function, to set the mode 55459 * in which p5.js interprets and calculates angles (either RADIANS or DEGREES). 55460 * @property {String} RADIANS 55461 * @final 55462 * 55463 * @example 55464 * <div class='norender'><code> 55465 * function setup() { 55466 * angleMode(RADIANS); 55467 * } 55468 * </code></div> 55469 */ 55470 exports.DEGREES = DEGREES; 55471 var RADIANS = 'radians'; 55472 exports.RADIANS = RADIANS; 55473 var DEG_TO_RAD = _PI / 180; 55474 exports.DEG_TO_RAD = DEG_TO_RAD; 55475 var RAD_TO_DEG = 180 / _PI; // SHAPE 55476 /** 55477 * @property {String} CORNER 55478 * @final 55479 */ 55480 exports.RAD_TO_DEG = RAD_TO_DEG; 55481 var CORNER = 'corner'; 55482 /** 55483 * @property {String} CORNERS 55484 * @final 55485 */ 55486 exports.CORNER = CORNER; 55487 var CORNERS = 'corners'; 55488 /** 55489 * @property {String} RADIUS 55490 * @final 55491 */ 55492 exports.CORNERS = CORNERS; 55493 var RADIUS = 'radius'; 55494 /** 55495 * @property {String} RIGHT 55496 * @final 55497 */ 55498 exports.RADIUS = RADIUS; 55499 var RIGHT = 'right'; 55500 /** 55501 * @property {String} LEFT 55502 * @final 55503 */ 55504 exports.RIGHT = RIGHT; 55505 var LEFT = 'left'; 55506 /** 55507 * @property {String} CENTER 55508 * @final 55509 */ 55510 exports.LEFT = LEFT; 55511 var CENTER = 'center'; 55512 /** 55513 * @property {String} TOP 55514 * @final 55515 */ 55516 exports.CENTER = CENTER; 55517 var TOP = 'top'; 55518 /** 55519 * @property {String} BOTTOM 55520 * @final 55521 */ 55522 exports.TOP = TOP; 55523 var BOTTOM = 'bottom'; 55524 /** 55525 * @property {String} BASELINE 55526 * @final 55527 * @default alphabetic 55528 */ 55529 exports.BOTTOM = BOTTOM; 55530 var BASELINE = 'alphabetic'; 55531 /** 55532 * @property {Number} POINTS 55533 * @final 55534 * @default 0x0000 55535 */ 55536 exports.BASELINE = BASELINE; 55537 var POINTS = 0; 55538 /** 55539 * @property {Number} LINES 55540 * @final 55541 * @default 0x0001 55542 */ 55543 exports.POINTS = POINTS; 55544 var LINES = 1; 55545 /** 55546 * @property {Number} LINE_STRIP 55547 * @final 55548 * @default 0x0003 55549 */ 55550 exports.LINES = LINES; 55551 var LINE_STRIP = 3; 55552 /** 55553 * @property {Number} LINE_LOOP 55554 * @final 55555 * @default 0x0002 55556 */ 55557 exports.LINE_STRIP = LINE_STRIP; 55558 var LINE_LOOP = 2; 55559 /** 55560 * @property {Number} TRIANGLES 55561 * @final 55562 * @default 0x0004 55563 */ 55564 exports.LINE_LOOP = LINE_LOOP; 55565 var TRIANGLES = 4; 55566 /** 55567 * @property {Number} TRIANGLE_FAN 55568 * @final 55569 * @default 0x0006 55570 */ 55571 exports.TRIANGLES = TRIANGLES; 55572 var TRIANGLE_FAN = 6; 55573 /** 55574 * @property {Number} TRIANGLE_STRIP 55575 * @final 55576 * @default 0x0005 55577 */ 55578 exports.TRIANGLE_FAN = TRIANGLE_FAN; 55579 var TRIANGLE_STRIP = 5; 55580 /** 55581 * @property {String} QUADS 55582 * @final 55583 */ 55584 exports.TRIANGLE_STRIP = TRIANGLE_STRIP; 55585 var QUADS = 'quads'; 55586 /** 55587 * @property {String} QUAD_STRIP 55588 * @final 55589 * @default quad_strip 55590 */ 55591 exports.QUADS = QUADS; 55592 var QUAD_STRIP = 'quad_strip'; 55593 /** 55594 * @property {String} TESS 55595 * @final 55596 * @default tess 55597 */ 55598 exports.QUAD_STRIP = QUAD_STRIP; 55599 var TESS = 'tess'; 55600 /** 55601 * @property {String} CLOSE 55602 * @final 55603 */ 55604 exports.TESS = TESS; 55605 var CLOSE = 'close'; 55606 /** 55607 * @property {String} OPEN 55608 * @final 55609 */ 55610 exports.CLOSE = CLOSE; 55611 var OPEN = 'open'; 55612 /** 55613 * @property {String} CHORD 55614 * @final 55615 */ 55616 exports.OPEN = OPEN; 55617 var CHORD = 'chord'; 55618 /** 55619 * @property {String} PIE 55620 * @final 55621 */ 55622 exports.CHORD = CHORD; 55623 var PIE = 'pie'; 55624 /** 55625 * @property {String} PROJECT 55626 * @final 55627 * @default square 55628 */ 55629 exports.PIE = PIE; 55630 var PROJECT = 'square'; // PEND: careful this is counterintuitive 55631 /** 55632 * @property {String} SQUARE 55633 * @final 55634 * @default butt 55635 */ 55636 exports.PROJECT = PROJECT; 55637 var SQUARE = 'butt'; 55638 /** 55639 * @property {String} ROUND 55640 * @final 55641 */ 55642 exports.SQUARE = SQUARE; 55643 var ROUND = 'round'; 55644 /** 55645 * @property {String} BEVEL 55646 * @final 55647 */ 55648 exports.ROUND = ROUND; 55649 var BEVEL = 'bevel'; 55650 /** 55651 * @property {String} MITER 55652 * @final 55653 */ 55654 exports.BEVEL = BEVEL; 55655 var MITER = 'miter'; // COLOR 55656 /** 55657 * @property {String} RGB 55658 * @final 55659 */ 55660 exports.MITER = MITER; 55661 var RGB = 'rgb'; 55662 /** 55663 * HSB (hue, saturation, brightness) is a type of color model. 55664 * You can learn more about it at 55665 * <a href="https://learnui.design/blog/the-hsb-color-system-practicioners-primer.html">HSB</a>. 55666 * 55667 * @property {String} HSB 55668 * @final 55669 */ 55670 exports.RGB = RGB; 55671 var HSB = 'hsb'; 55672 /** 55673 * @property {String} HSL 55674 * @final 55675 */ 55676 exports.HSB = HSB; 55677 var HSL = 'hsl'; // DOM EXTENSION 55678 /** 55679 * AUTO allows us to automatically set the width or height of an element (but not both), 55680 * based on the current height and width of the element. Only one parameter can 55681 * be passed to the <a href="/#/p5.Element/size">size</a> function as AUTO, at a time. 55682 * 55683 * @property {String} AUTO 55684 * @final 55685 */ 55686 exports.HSL = HSL; 55687 var AUTO = 'auto'; 55688 /** 55689 * @property {Number} ALT 55690 * @final 55691 */ 55692 // INPUT 55693 exports.AUTO = AUTO; 55694 var ALT = 18; 55695 /** 55696 * @property {Number} BACKSPACE 55697 * @final 55698 */ 55699 exports.ALT = ALT; 55700 var BACKSPACE = 8; 55701 /** 55702 * @property {Number} CONTROL 55703 * @final 55704 */ 55705 exports.BACKSPACE = BACKSPACE; 55706 var CONTROL = 17; 55707 /** 55708 * @property {Number} DELETE 55709 * @final 55710 */ 55711 exports.CONTROL = CONTROL; 55712 var DELETE = 46; 55713 /** 55714 * @property {Number} DOWN_ARROW 55715 * @final 55716 */ 55717 exports.DELETE = DELETE; 55718 var DOWN_ARROW = 40; 55719 /** 55720 * @property {Number} ENTER 55721 * @final 55722 */ 55723 exports.DOWN_ARROW = DOWN_ARROW; 55724 var ENTER = 13; 55725 /** 55726 * @property {Number} ESCAPE 55727 * @final 55728 */
55729 exports.ENTER = ENTER; 55730 var ESCAPE = 27; 55731 /** 55732 * @property {Number} LEFT_ARROW 55733 * @final 55734 */ 55735 exports.ESCAPE = ESCAPE; 55736 var LEFT_ARROW = 37; 55737 /** 55738 * @property {Number} OPTION 55739 * @final 55740 */ 55741 exports.LEFT_ARROW = LEFT_ARROW; 55742 var OPTION = 18; 55743 /** 55744 * @property {Number} RETURN 55745 * @final 55746 */ 55747 exports.OPTION = OPTION; 55748 var RETURN = 13; 55749 /** 55750 * @property {Number} RIGHT_ARROW 55751 * @final 55752 */ 55753 exports.RETURN = RETURN; 55754 var RIGHT_ARROW = 39; 55755 /** 55756 * @property {Number} SHIFT 55757 * @final 55758 */ 55759 exports.RIGHT_ARROW = RIGHT_ARROW; 55760 var SHIFT = 16; 55761 /** 55762 * @property {Number} TAB 55763 * @final 55764 */ 55765 exports.SHIFT = SHIFT; 55766 var TAB = 9; 55767 /** 55768 * @property {Number} UP_ARROW 55769 * @final 55770 */ 55771 exports.TAB = TAB; 55772 var UP_ARROW = 38; // RENDERING 55773 /** 55774 * @property {String} BLEND 55775 * @final 55776 * @default source-over 55777 */ 55778 exports.UP_ARROW = UP_ARROW; 55779 var BLEND = 'source-over'; 55780 /** 55781 * @property {String} REMOVE 55782 * @final 55783 * @default destination-out 55784 */ 55785 exports.BLEND = BLEND; 55786 var REMOVE = 'destination-out'; 55787 /** 55788 * @property {String} ADD 55789 * @final 55790 * @default lighter 55791 */ 55792 exports.REMOVE = REMOVE; 55793 var ADD = 'lighter'; //ADD: 'add', // 55794 //SUBTRACT: 'subtract', // 55795 /** 55796 * @property {String} DARKEST 55797 * @final 55798 */ 55799 exports.ADD = ADD; 55800 var DARKEST = 'darken'; 55801 /** 55802 * @property {String} LIGHTEST 55803 * @final 55804 * @default lighten 55805 */ 55806 exports.DARKEST = DARKEST; 55807 var LIGHTEST = 'lighten'; 55808 /** 55809 * @property {String} DIFFERENCE 55810 * @final 55811 */ 55812 exports.LIGHTEST = LIGHTEST; 55813 var DIFFERENCE = 'difference'; 55814 /** 55815 * @property {String} SUBTRACT 55816 * @final 55817 */ 55818 exports.DIFFERENCE = DIFFERENCE; 55819 var SUBTRACT = 'subtract'; 55820 /** 55821 * @property {String} EXCLUSION 55822 * @final 55823 */ 55824 exports.SUBTRACT = SUBTRACT; 55825 var EXCLUSION = 'exclusion'; 55826 /** 55827 * @property {String} MULTIPLY 55828 * @final 55829 */ 55830 exports.EXCLUSION = EXCLUSION; 55831 var MULTIPLY = 'multiply'; 55832 /** 55833 * @property {String} SCREEN 55834 * @final 55835 */ 55836 exports.MULTIPLY = MULTIPLY; 55837 var SCREEN = 'screen'; 55838 /** 55839 * @property {String} REPLACE 55840 * @final 55841 * @default copy 55842 */ 55843 exports.SCREEN = SCREEN; 55844 var REPLACE = 'copy'; 55845 /** 55846 * @property {String} OVERLAY 55847 * @final 55848 */ 55849 exports.REPLACE = REPLACE; 55850 var OVERLAY = 'overlay'; 55851 /** 55852 * @property {String} HARD_LIGHT 55853 * @final 55854 */ 55855 exports.OVERLAY = OVERLAY; 55856 var HARD_LIGHT = 'hard-light'; 55857 /** 55858 * @property {String} SOFT_LIGHT 55859 * @final 55860 */ 55861 exports.HARD_LIGHT = HARD_LIGHT; 55862 var SOFT_LIGHT = 'soft-light'; 55863 /** 55864 * @property {String} DODGE 55865 * @final 55866 * @default color-dodge 55867 */ 55868 exports.SOFT_LIGHT = SOFT_LIGHT; 55869 var DODGE = 'color-dodge'; 55870 /** 55871 * @property {String} BURN 55872 * @final 55873 * @default color-burn 55874 */ 55875 exports.DODGE = DODGE; 55876 var BURN = 'color-burn'; // FILTERS 55877 /** 55878 * @property {String} THRESHOLD 55879 * @final 55880 */ 55881 exports.BURN = BURN; 55882 var THRESHOLD = 'threshold'; 55883 /** 55884 * @property {String} GRAY 55885 * @final 55886 */ 55887 exports.THRESHOLD = THRESHOLD; 55888 var GRAY = 'gray'; 55889 /** 55890 * @property {String} OPAQUE 55891 * @final 55892 */ 55893 exports.GRAY = GRAY; 55894 var OPAQUE = 'opaque'; 55895 /** 55896 * @property {String} INVERT 55897 * @final 55898 */ 55899 exports.OPAQUE = OPAQUE; 55900 var INVERT = 'invert'; 55901 /** 55902 * @property {String} POSTERIZE 55903 * @final 55904 */ 55905 exports.INVERT = INVERT; 55906 var POSTERIZE = 'posterize'; 55907 /** 55908 * @property {String} DILATE 55909 * @final 55910 */ 55911 exports.POSTERIZE = POSTERIZE; 55912 var DILATE = 'dilate'; 55913 /** 55914 * @property {String} ERODE 55915 * @final 55916 */ 55917 exports.DILATE = DILATE; 55918 var ERODE = 'erode'; 55919 /** 55920 * @property {String} BLUR 55921 * @final 55922 */ 55923 exports.ERODE = ERODE; 55924 var BLUR = 'blur'; // TYPOGRAPHY 55925 /** 55926 * @property {String} NORMAL 55927 * @final 55928 */ 55929 exports.BLUR = BLUR; 55930 var NORMAL = 'normal'; 55931 /** 55932 * @property {String} ITALIC 55933 * @final 55934 */ 55935 exports.NORMAL = NORMAL; 55936 var ITALIC = 'italic'; 55937 /** 55938 * @property {String} BOLD 55939 * @final 55940 */ 55941 exports.ITALIC = ITALIC; 55942 var BOLD = 'bold'; 55943 /** 55944 * @property {String} BOLDITALIC 55945 * @final 55946 */ 55947 exports.BOLD = BOLD; 55948 var BOLDITALIC = 'bold italic'; 55949 /** 55950 * @property {String} CHAR 55951 * @final 55952 */ 55953 exports.BOLDITALIC = BOLDITALIC; 55954 var CHAR = 'CHAR'; 55955 /** 55956 * @property {String} WORD 55957 * @final 55958 */ 55959 exports.CHAR = CHAR; 55960 var WORD = 'WORD'; // TYPOGRAPHY-INTERNAL 55961 exports.WORD = WORD; 55962 var _DEFAULT_TEXT_FILL = '#000000'; 55963 exports._DEFAULT_TEXT_FILL = _DEFAULT_TEXT_FILL; 55964 var _DEFAULT_LEADMULT = 1.25; 55965 exports._DEFAULT_LEADMULT = _DEFAULT_LEADMULT; 55966 var _CTX_MIDDLE = 'middle'; // VERTICES 55967 /** 55968 * @property {String} LINEAR 55969 * @final 55970 */ 55971 exports._CTX_MIDDLE = _CTX_MIDDLE; 55972 var LINEAR = 'linear'; 55973 /** 55974 * @property {String} QUADRATIC 55975 * @final 55976 */ 55977 exports.LINEAR = LINEAR; 55978 var QUADRATIC = 'quadratic'; 55979 /** 55980 * @property {String} BEZIER 55981 * @final 55982 */ 55983 exports.QUADRATIC = QUADRATIC; 55984 var BEZIER = 'bezier'; 55985 /** 55986 * @property {String} CURVE 55987 * @final 55988 */ 55989 exports.BEZIER = BEZIER; 55990 var CURVE = 'curve'; // WEBGL DRAWMODES 55991 /** 55992 * @property {String} STROKE 55993 * @final 55994 */ 55995 exports.CURVE = CURVE; 55996 var STROKE = 'stroke'; 55997 /** 55998 * @property {String} FILL 55999 * @final 56000 */ 56001 exports.STROKE = STROKE; 56002 var FILL = 'fill'; 56003 /** 56004 * @property {String} TEXTURE 56005 * @final 56006 */ 56007 exports.FILL = FILL; 56008 var TEXTURE = 'texture'; 56009 /** 56010 * @property {String} IMMEDIATE 56011 * @final 56012 */ 56013 exports.TEXTURE = TEXTURE; 56014 var IMMEDIATE = 'immediate'; // WEBGL TEXTURE MODE 56015 // NORMAL already exists for typography 56016 /** 56017 * @property {String} IMAGE 56018 * @final 56019 */ 56020 exports.IMMEDIATE = IMMEDIATE; 56021 var IMAGE = 'image'; // WEBGL TEXTURE WRAP AND FILTERING 56022 // LINEAR already exists above 56023 /** 56024 * @property {String} NEAREST 56025 * @final 56026 */ 56027 exports.IMAGE = IMAGE; 56028 var NEAREST = 'nearest'; 56029 /** 56030 * @property {String} REPEAT 56031 * @final 56032 */ 56033 exports.NEAREST = NEAREST; 56034 var REPEAT = 'repeat'; 56035 /** 56036 * @property {String} CLAMP 56037 * @final 56038 */ 56039 exports.REPEAT = REPEAT; 56040 var CLAMP = 'clamp'; 56041 /** 56042 * @property {String} MIRROR 56043 * @final 56044 */ 56045 exports.CLAMP = CLAMP; 56046 var MIRROR = 'mirror'; // DEVICE-ORIENTATION 56047 /** 56048 * @property {String} LANDSCAPE 56049 * @final 56050 */ 56051 exports.MIRROR = MIRROR; 56052 var LANDSCAPE = 'landscape'; 56053 /** 56054 * @property {String} PORTRAIT 56055 * @final 56056 */ 56057 exports.LANDSCAPE = LANDSCAPE; 56058 var PORTRAIT = 'portrait'; // DEFAULTS 56059 exports.PORTRAIT = PORTRAIT; 56060 var _DEFAULT_STROKE = '#000000'; 56061 exports._DEFAULT_STROKE = _DEFAULT_STROKE; 56062 var _DEFAULT_FILL = '#FFFFFF'; 56063 /** 56064 * @property {String} GRID 56065 * @final 56066 */ 56067 exports._DEFAULT_FILL = _DEFAULT_FILL; 56068 var GRID = 'grid'; 56069 /** 56070 * @property {String} AXES 56071 * @final 56072 */ 56073 exports.GRID = GRID; 56074 var AXES = 'axes'; 56075 /** 56076 * @property {String} LABEL 56077 * @final 56078 */ 56079 exports.AXES = AXES; 56080 var LABEL = 'label'; 56081 /** 56082 * @property {String} FALLBACK 56083 * @final 56084 */ 56085 exports.LABEL = LABEL; 56086 var FALLBACK = 'fallback'; 56087 /** 56088 * @property {String} CONTAIN 56089 * @final 56090 */ 56091 exports.FALLBACK = FALLBACK; 56092 var CONTAIN = 'contain'; 56093 /** 56094 * @property {String} COVER 56095 * @final 56096 */ 56097 exports.CONTAIN = CONTAIN; 56098 var COVER = 'cover'; 56099 exports.COVER = COVER; 56100 }, 56101 { 56102 } 56103 ], 56104 279: [
56105 function (_dereq_, module, exports) { 56106 'use strict'; 56107 _dereq_('core-js/modules/es.symbol'); 56108 _dereq_('core-js/modules/es.symbol.description'); 56109 _dereq_('core-js/modules/es.symbol.iterator'); 56110 _dereq_('core-js/modules/es.array.concat'); 56111 _dereq_('core-js/modules/es.array.filter'); 56112 _dereq_('core-js/modules/es.array.includes'); 56113 _dereq_('core-js/modules/es.array.iterator'); 56114 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 56115 _dereq_('core-js/modules/es.object.to-string'); 56116 _dereq_('core-js/modules/es.regexp.exec'); 56117 _dereq_('core-js/modules/es.string.includes'); 56118 _dereq_('core-js/modules/es.string.iterator'); 56119 _dereq_('core-js/modules/es.string.search'); 56120 _dereq_('core-js/modules/es.string.split'); 56121 _dereq_('core-js/modules/es.weak-map'); 56122 _dereq_('core-js/modules/web.dom-collections.iterator'); 56123 function _typeof2(obj) { 56124 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 56125 _typeof2 = function _typeof2(obj) { 56126 return typeof obj; 56127 }; 56128 } else { 56129 _typeof2 = function _typeof2(obj) { 56130 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 56131 }; 56132 } 56133 return _typeof2(obj); 56134 } 56135 function _typeof(obj) { 56136 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 56137 _typeof = function _typeof(obj) { 56138 return _typeof2(obj); 56139 }; 56140 } else { 56141 _typeof = function _typeof(obj) { 56142 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 56143 }; 56144 } 56145 return _typeof(obj); 56146 } 56147 _dereq_('core-js/modules/es.array.concat'); 56148 _dereq_('core-js/modules/es.array.filter'); 56149 _dereq_('core-js/modules/es.array.includes'); 56150 _dereq_('core-js/modules/es.regexp.exec'); 56151 _dereq_('core-js/modules/es.string.includes'); 56152 _dereq_('core-js/modules/es.string.search'); 56153 _dereq_('core-js/modules/es.string.split'); 56154 Object.defineProperty(exports, '__esModule', { 56155 value: true 56156 }); 56157 exports.default = void 0; 56158 var _main = _interopRequireDefault(_dereq_('./main')); 56159 var C = _interopRequireWildcard(_dereq_('./constants')); 56160 function _getRequireWildcardCache() { 56161 if (typeof WeakMap !== 'function') return null; 56162 var cache = new WeakMap(); 56163 _getRequireWildcardCache = function _getRequireWildcardCache() { 56164 return cache; 56165 }; 56166 return cache; 56167 } 56168 function _interopRequireWildcard(obj) { 56169 if (obj && obj.__esModule) { 56170 return obj; 56171 } 56172 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 56173 return { 56174 default: 56175 obj 56176 }; 56177 } 56178 var cache = _getRequireWildcardCache(); 56179 if (cache && cache.has(obj)) { 56180 return cache.get(obj); 56181 } 56182 var newObj = { 56183 }; 56184 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 56185 for (var key in obj) { 56186 if (Object.prototype.hasOwnProperty.call(obj, key)) { 56187 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 56188 if (desc && (desc.get || desc.set)) { 56189 Object.defineProperty(newObj, key, desc); 56190 } else { 56191 newObj[key] = obj[key]; 56192 } 56193 } 56194 } 56195 newObj.default = obj; 56196 if (cache) { 56197 cache.set(obj, newObj); 56198 } 56199 return newObj; 56200 } 56201 function _interopRequireDefault(obj) { 56202 return obj && obj.__esModule ? obj : { 56203 default: 56204 obj 56205 }; 56206 } /** 56207 * @module Environment 56208 * @submodule Environment 56209 * @for p5 56210 * @requires core 56211 * @requires constants 56212 */ 56213 56214 var standardCursors = [ 56215 C.ARROW, 56216 C.CROSS, 56217 C.HAND, 56218 C.MOVE, 56219 C.TEXT, 56220 C.WAIT 56221 ]; 56222 _main.default.prototype._frameRate = 0; 56223 _main.default.prototype._lastFrameTime = window.performance.now(); 56224 _main.default.prototype._targetFrameRate = 60; 56225 var _windowPrint = window.print; 56226 /** 56227 * The <a href="#/p5/print">print()</a> function writes to the console area of 56228 * your browser. This function is often helpful for looking at the data a program 56229 * is producing. This function creates a new line of text for each call to 56230 * the function. Individual elements can be separated with quotes ("") and joined 56231 * with the addition operator (+). 56232 *
56233 * Note that calling print() without any arguments invokes the window.print() 56234 * function which opens the browser's print dialog. To print a blank line 56235 * to console you can write print('\n'). 56236 * 56237 * @method print 56238 * @param {Any} contents any combination of Number, String, Object, Boolean, 56239 * Array to print 56240 * @example 56241 * <div><code class='norender'> 56242 * let x = 10; 56243 * print('The value of x is ' + x); 56244 * // prints "The value of x is 10" 56245 * </code></div> 56246 * 56247 * @alt 56248 * default grey canvas 56249 */ 56250 _main.default.prototype.print = function () { 56251 if (!arguments.length) { 56252 _windowPrint(); 56253 } else { 56254 var _console; 56255 (_console = console).log.apply(_console, arguments); 56256 } 56257 }; 56258 /** 56259 * The system variable <a href="#/p5/frameCount">frameCount</a> contains the 56260 * number of frames that have been displayed since the program started. Inside 56261 * <a href="#/p5/setup">setup()</a> the value is 0, after the first iteration 56262 * of <a href="#/p5/draw">draw()</a> it is 1, etc. 56263 * 56264 * @property {Integer} frameCount 56265 * @readOnly 56266 * @example 56267 * <div><code> 56268 * function setup() { 56269 * frameRate(30); 56270 * textSize(30); 56271 * textAlign(CENTER); 56272 * } 56273 * 56274 * function draw() { 56275 * background(200); 56276 * text(frameCount, width / 2, height / 2); 56277 * } 56278 * </code></div> 56279 * 56280 * @alt 56281 * numbers rapidly counting upward with frame count set to 30. 56282 */ 56283 _main.default.prototype.frameCount = 0; 56284 /** 56285 * The system variable <a href="#/p5/deltaTime">deltaTime</a> contains the time 56286 * difference between the beginning of the previous frame and the beginning 56287 * of the current frame in milliseconds. 56288 * 56289 * This variable is useful for creating time sensitive animation or physics 56290 * calculation that should stay constant regardless of frame rate. 56291 * 56292 * @property {Integer} deltaTime 56293 * @readOnly 56294 * @example 56295 * <div><code> 56296 * let rectX = 0; 56297 * let fr = 30; //starting FPS 56298 * let clr; 56299 * 56300 * function setup() { 56301 * background(200); 56302 * frameRate(fr); // Attempt to refresh at starting FPS 56303 * clr = color(255, 0, 0); 56304 * } 56305 * 56306 * function draw() { 56307 * background(200); 56308 * rectX = rectX + 1 * (deltaTime / 50); // Move Rectangle in relation to deltaTime 56309 * 56310 * if (rectX >= width) { 56311 * // If you go off screen. 56312 * if (fr === 30) { 56313 * clr = color(0, 0, 255); 56314 * fr = 10; 56315 * frameRate(fr); // make frameRate 10 FPS 56316 * } else { 56317 * clr = color(255, 0, 0); 56318 * fr = 30; 56319 * frameRate(fr); // make frameRate 30 FPS 56320 * } 56321 * rectX = 0; 56322 * } 56323 * fill(clr); 56324 * rect(rectX, 40, 20, 20); 56325 * } 56326 * </code></div> 56327 * 56328 * @alt 56329 * red rect moves left to right, followed by blue rect moving at the same speed 56330 * with a lower frame rate. Loops. 56331 */ 56332 _main.default.prototype.deltaTime = 0; 56333 /** 56334 * Confirms if the window a p5.js program is in is "focused," meaning that 56335 * the sketch will accept mouse or keyboard input. This variable is 56336 * "true" if the window is focused and "false" if not. 56337 * 56338 * @property {Boolean} focused 56339 * @readOnly 56340 * @example 56341 * <div><code> 56342 * // To demonstrate, put two windows side by side. 56343 * // Click on the window that the p5 sketch isn't in! 56344 * function draw() { 56345 * background(200); 56346 * noStroke(); 56347 * fill(0, 200, 0); 56348 * ellipse(25, 25, 50, 50); 56349 * 56350 * if (!focused) { 56351 // or "if (focused === false)" 56352 * stroke(200, 0, 0); 56353 * line(0, 0, 100, 100); 56354 * line(100, 0, 0, 100); 56355 * } 56356 * } 56357 * </code></div> 56358 * 56359 * @alt 56360 * green 50Ã50 ellipse at top left. Red X covers canvas when page focus changes 56361 */ 56362 _main.default.prototype.focused = document.hasFocus(); 56363 /** 56364 * Sets the cursor to a predefined symbol or an image, or makes it visible 56365 * if already hidden. If you are trying to set an image as the cursor, the 56366 * recommended size is 16Ã16 or 32Ã32 pixels. The values for parameters x and y 56367 * must be less than the dimensions of the image. 56368 * 56369 * @method cursor 56370 * @param {String|Constant} type Built-In: either ARROW, CROSS, HAND, MOVE, TEXT and WAIT 56371 * Native CSS properties: 'grab', 'progress', 'cell' etc. 56372 * External: path for cursor's images 56373 * (Allowed File extensions: .cur, .gif, .jpg, .jpeg, .png) 56374 * For more information on Native CSS cursors and url visit: 56375 * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor 56376 * @param {Number} [x] the horizontal active spot of the cursor (must be less than 32) 56377 * @param {Number} [y] the vertical active spot of the cursor (must be less than 32) 56378 * @example 56379 * <div><code> 56380 * // Move the mouse across the quadrants 56381 * // to see the cursor change 56382 * function draw() { 56383 * line(width / 2, 0, width / 2, height); 56384 * line(0, height / 2, width, height / 2); 56385 * if (mouseX < 50 && mouseY < 50) { 56386 * cursor(CROSS); 56387 * } else if (mouseX > 50 && mouseY < 50) { 56388 * cursor('progress'); 56389 * } else if (mouseX > 50 && mouseY > 50) { 56390 * cursor('https://avatars0.githubusercontent.com/u/1617169?s=16'); 56391 * } else { 56392 * cursor('grab'); 56393 * } 56394 * } 56395 * </code></div> 56396 * 56397 * @alt 56398 * canvas is divided into four quadrants. cursor on first is a cross, second is a progress, 56399 * third is a custom cursor using path to the cursor and fourth is a grab. 56400 */ 56401 _main.default.prototype.cursor = function (type, x, y) { 56402 var cursor = 'auto'; 56403 var canvas = this._curElement.elt; 56404 if (standardCursors.includes(type)) { 56405 // Standard css cursor 56406 cursor = type; 56407 } else if (typeof type === 'string') { 56408 var coords = ''; 56409 if (x && y && typeof x === 'number' && typeof y === 'number') { 56410 // Note that x and y values must be unit-less positive integers < 32 56411 // https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
56412 coords = ''.concat(x, ' ').concat(y); 56413 } 56414 if (type.substring(0, 7) === 'http://' || type.substring(0, 8) === 'https://') { 56415 // Image (absolute url) 56416 cursor = 'url('.concat(type, ') ').concat(coords, ', auto'); 56417 } else if (/\.(cur|jpg|jpeg|gif|png|CUR|JPG|JPEG|GIF|PNG)$/.test(type)) { 56418 // Image file (relative path) - Separated for performance reasons 56419 cursor = 'url('.concat(type, ') ').concat(coords, ', auto'); 56420 } else { 56421 // Any valid string for the css cursor property 56422 cursor = type; 56423 } 56424 } 56425 canvas.style.cursor = cursor; 56426 }; 56427 /** 56428 * Specifies the number of frames to be displayed every second. For example, 56429 * the function call frameRate(30) will attempt to refresh 30 times a second. 56430 * If the processor is not fast enough to maintain the specified rate, the 56431 * frame rate will not be achieved. Setting the frame rate within 56432 * <a href="#/p5/setup">setup()</a> is recommended. The default frame rate is 56433 * based on the frame rate of the display (here also called "refresh rate"), 56434 * which is set to 60 frames per second on most computers. A frame rate of 24 56435 * frames per second (usual for movies) or above will be enough for smooth 56436 * animations. This is the same as setFrameRate(val). 56437 * 56438 * Calling <a href="#/p5/frameRate">frameRate()</a> with no arguments returns 56439 * the current framerate. The draw function must run at least once before it will 56440 * return a value. This is the same as <a href="#/p5/getFrameRate">getFrameRate()</a>. 56441 * 56442 * Calling <a href="#/p5/frameRate">frameRate()</a> with arguments that are not 56443 * of the type Number or are non-positive also returns current framerate. 56444 * 56445 * @method frameRate 56446 * @param {Number} fps number of frames to be displayed every second 56447 * @chainable 56448 * 56449 * @example 56450 * 56451 * <div><code> 56452 * let rectX = 0; 56453 * let fr = 30; //starting FPS 56454 * let clr; 56455 * 56456 * function setup() { 56457 * background(200); 56458 * frameRate(fr); // Attempt to refresh at starting FPS 56459 * clr = color(255, 0, 0); 56460 * } 56461 * 56462 * function draw() { 56463 * background(200); 56464 * rectX += 1; // Move Rectangle 56465 * 56466 * if (rectX >= width) { 56467 // If you go off screen. 56468 * if (fr === 30) { 56469 * clr = color(0, 0, 255); 56470 * fr = 10; 56471 * frameRate(fr); // make frameRate 10 FPS 56472 * } else { 56473 * clr = color(255, 0, 0); 56474 * fr = 30; 56475 * frameRate(fr); // make frameRate 30 FPS 56476 * } 56477 * rectX = 0; 56478 * } 56479 * fill(clr); 56480 * rect(rectX, 40, 20, 20); 56481 * } 56482 * </code></div> 56483 * 56484 * @alt 56485 * blue rect moves left to right, followed by red rect moving faster. Loops. 56486 */ 56487 /** 56488 * @method frameRate 56489 * @return {Number} current frameRate 56490 */ 56491 _main.default.prototype.frameRate = function (fps) { 56492 _main.default._validateParameters('frameRate', arguments); 56493 if (typeof fps !== 'number' || fps < 0) { 56494 return this._frameRate; 56495 } else { 56496 this._setProperty('_targetFrameRate', fps); 56497 if (fps === 0) { 56498 this._setProperty('_frameRate', fps); 56499 } 56500 return this; 56501 } 56502 }; 56503 /** 56504 * Returns the current framerate. 56505 * 56506 * @private 56507 * @return {Number} current frameRate 56508 */ 56509 _main.default.prototype.getFrameRate = function () { 56510 return this.frameRate(); 56511 }; 56512 /** 56513 * Specifies the number of frames to be displayed every second. For example, 56514 * the function call frameRate(30) will attempt to refresh 30 times a second. 56515 * If the processor is not fast enough to maintain the specified rate, the 56516 * frame rate will not be achieved. Setting the frame rate within <a href="#/p5/setup">setup()</a> is 56517 * recommended. The default rate is 60 frames per second. 56518 * 56519 * Calling <a href="#/p5/frameRate">frameRate()</a> with no arguments returns the current framerate. 56520 * 56521 * @private 56522 * @param {Number} [fps] number of frames to be displayed every second 56523 */ 56524 _main.default.prototype.setFrameRate = function (fps) { 56525 return this.frameRate(fps); 56526 }; 56527 /** 56528 * Returns _targetFrameRate variable. The default _targetFrameRate is set to 60. 56529 * This could be changed by calling frameRate() and setting it to the desired 56530 * value. When getTargetFrameRate() is called, it should return the value that was set. 56531 * @method getTargetFrameRate 56532 * @return {Number} _targetFrameRate 56533 * @example 56534 * <div><code> 56535 * function draw() { 56536 * frameRate(20); 56537 * text(getTargetFrameRate(), width / 2, height / 2); 56538 * } 56539 * </code></div> 56540 */ 56541 _main.default.prototype.getTargetFrameRate = function () { 56542 return this._targetFrameRate; 56543 }; 56544 /** 56545 * Hides the cursor from view. 56546 * 56547 * @method noCursor 56548 * @example 56549 * <div><code> 56550 * function setup() { 56551 * noCursor(); 56552 * } 56553 * 56554 * function draw() { 56555 * background(200); 56556 * ellipse(mouseX, mouseY, 10, 10); 56557 * } 56558 * </code></div> 56559 * 56560 * @alt 56561 * cursor becomes 10Ã10 white ellipse the moves with mouse x and y. 56562 */ 56563 _main.default.prototype.noCursor = function () { 56564 this._curElement.elt.style.cursor = 'none'; 56565 }; 56566 /** 56567 * System variable that stores the width of the screen display according to The 56568 * default <a href="#/p5/pixelDensity">pixelDensity</a>. This is used to run a 56569 * full-screen program on any display size. To return actual screen size, 56570 * multiply this by pixelDensity. 56571 * 56572 * @property {Number} displayWidth 56573 * @readOnly 56574 * @example 56575 * <div class="norender"><code> 56576 * createCanvas(displayWidth, displayHeight); 56577 * </code></div> 56578 * 56579 * @alt 56580 * This example does not render anything. 56581 */ 56582 _main.default.prototype.displayWidth = screen.width; 56583 /** 56584 * System variable that stores the height of the screen display according to The 56585 * default <a href="#/p5/pixelDensity">pixelDensity</a>. This is used to run a 56586 * full-screen program on any display size. To return actual screen size, 56587 * multiply this by pixelDensity. 56588 * 56589 * @property {Number} displayHeight 56590 * @readOnly 56591 * @example 56592 * <div class="norender"><code> 56593 * createCanvas(displayWidth, displayHeight); 56594 * </code></div> 56595 * 56596 * @alt 56597 * This example does not render anything. 56598 */ 56599 _main.default.prototype.displayHeight = screen.height; 56600 /** 56601 * System variable that stores the width of the inner window, it maps to 56602 * window.innerWidth. 56603 * 56604 * @property {Number} windowWidth 56605 * @readOnly 56606 * @example 56607 * <div class="norender"><code> 56608 * createCanvas(windowWidth, windowHeight); 56609 * </code></div> 56610 * 56611 * @alt 56612 * This example does not render anything. 56613 */ 56614 _main.default.prototype.windowWidth = getWindowWidth(); 56615 /** 56616 * System variable that stores the height of the inner window, it maps to 56617 * window.innerHeight. 56618 * 56619 * @property {Number} windowHeight 56620 * @readOnly 56621 * @example 56622 * <div class="norender"><code> 56623 * createCanvas(windowWidth, windowHeight); 56624 * </code></div> 56625 * 56626 * @alt 56627 * This example does not render anything. 56628 */ 56629 _main.default.prototype.windowHeight = getWindowHeight(); 56630 /** 56631 * The <a href="#/p5/windowResized">windowResized()</a> function is called once 56632 * every time the browser window is resized. This is a good place to resize the 56633 * canvas or do any other adjustments to accommodate the new window size. 56634 * 56635 * @method windowResized 56636 * @param {Object} [event] optional Event callback argument. 56637 * @example 56638 * <div class="norender"><code> 56639 * function setup() { 56640 * createCanvas(windowWidth, windowHeight); 56641 * } 56642 * 56643 * function draw() { 56644 * background(0, 100, 200); 56645 * } 56646 * 56647 * function windowResized() { 56648 * resizeCanvas(windowWidth, windowHeight); 56649 * } 56650 * </code></div> 56651 * @alt 56652 * This example does not render anything. 56653 */ 56654 _main.default.prototype._onresize = function (e) { 56655 this._setProperty('windowWidth', getWindowWidth()); 56656 this._setProperty('windowHeight', getWindowHeight()); 56657 var context = this._isGlobal ? window : this; 56658 var executeDefault; 56659 if (typeof context.windowResized === 'function') { 56660 executeDefault = context.windowResized(e); 56661 if (executeDefault !== undefined && !executeDefault) { 56662 e.preventDefault(); 56663 } 56664 } 56665 }; 56666 function getWindowWidth() { 56667 return window.innerWidth || document.documentElement && document.documentElement.clientWidth || document.body && document.body.clientWidth || 0; 56668 } 56669 function getWindowHeight() { 56670 return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body && document.body.clientHeight || 0; 56671 } /** 56672 * System variable that stores the width of the drawing canvas. This value 56673 * is set by the first parameter of the <a href="#/p5/createCanvas">createCanvas()</a> function. 56674 * For example, the function call createCanvas(320, 240) sets the width 56675 * variable to the value 320. The value of width defaults to 100 if 56676 * <a href="#/p5/createCanvas">createCanvas()</a> is not used in a program. 56677 * 56678 * @property {Number} width 56679 * @readOnly 56680 */ 56681 56682 _main.default.prototype.width = 0; 56683 /** 56684 * System variable that stores the height of the drawing canvas. This value 56685 * is set by the second parameter of the <a href="#/p5/createCanvas">createCanvas()</a> function. For 56686 * example, the function call createCanvas(320, 240) sets the height 56687 * variable to the value 240. The value of height defaults to 100 if 56688 * <a href="#/p5/createCanvas">createCanvas()</a> is not used in a program. 56689 * 56690 * @property {Number} height 56691 * @readOnly 56692 */ 56693 _main.default.prototype.height = 0; 56694 /** 56695 * If argument is given, sets the sketch to fullscreen or not based on the 56696 * value of the argument. If no argument is given, returns the current 56697 * fullscreen state. Note that due to browser restrictions this can only 56698 * be called on user input, for example, on mouse press like the example 56699 * below. 56700 * 56701 * @method fullscreen 56702 * @param {Boolean} [val] whether the sketch should be in fullscreen mode 56703 * or not 56704 * @return {Boolean} current fullscreen state 56705 * @example 56706 * <div> 56707 * <code> 56708 * // Clicking in the box toggles fullscreen on and off. 56709 * function setup() { 56710 * background(200); 56711 * } 56712 * function mousePressed() { 56713 * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) { 56714 * let fs = fullscreen(); 56715 * fullscreen(!fs); 56716 * } 56717 * } 56718 * </code> 56719 * </div> 56720 * 56721 * @alt 56722 * This example does not render anything. 56723 */ 56724 _main.default.prototype.fullscreen = function (val) { 56725 _main.default._validateParameters('fullscreen', arguments); // no arguments, return fullscreen or not 56726 if (typeof val === 'undefined') { 56727 return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement; 56728 } else { 56729 // otherwise set to fullscreen or not 56730 if (val) { 56731 launchFullscreen(document.documentElement); 56732 } else { 56733 exitFullscreen(); 56734 } 56735 } 56736 }; 56737 /** 56738 * Sets the pixel scaling for high pixel density displays. By default 56739 * pixel density is set to match display density, call pixelDensity(1) 56740 * to turn this off. Calling <a href="#/p5/pixelDensity">pixelDensity()</a> with no arguments returns 56741 * the current pixel density of the sketch. 56742 * 56743 * @method pixelDensity 56744 * @param {Number} val whether or how much the sketch should scale 56745 * @chainable 56746 * @example 56747 * <div> 56748 * <code> 56749 * function setup() { 56750 * pixelDensity(1); 56751 * createCanvas(100, 100); 56752 * background(200); 56753 * ellipse(width / 2, height / 2, 50, 50); 56754 * } 56755 * </code> 56756 * </div> 56757 * 56758 * <div> 56759 * <code> 56760 * function setup() { 56761 * pixelDensity(3.0); 56762 * createCanvas(100, 100); 56763 * background(200); 56764 * ellipse(width / 2, height / 2, 50, 50); 56765 * } 56766 * </code> 56767 * </div> 56768 * 56769 * @alt 56770 * fuzzy 50Ã50 white ellipse with black outline in center of canvas. 56771 * sharp 50Ã50 white ellipse with black outline in center of canvas. 56772 */ 56773 /** 56774 * @method pixelDensity 56775 * @returns {Number} current pixel density of the sketch 56776 */ 56777 _main.default.prototype.pixelDensity = function (val) { 56778 _main.default._validateParameters('pixelDensity', arguments); 56779 var returnValue; 56780 if (typeof val === 'number') { 56781 if (val !== this._pixelDensity) { 56782 this._pixelDensity = val; 56783 } 56784 returnValue = this; 56785 this.resizeCanvas(this.width, this.height, true); // as a side effect, it will clear the canvas 56786 } else { 56787 returnValue = this._pixelDensity; 56788 } 56789 return returnValue; 56790 }; 56791 /** 56792 * Returns the pixel density of the current display the sketch is running on. 56793 * 56794 * @method displayDensity 56795 * @returns {Number} current pixel density of the display 56796 * @example 56797 * <div> 56798 * <code> 56799 * function setup() { 56800 * let density = displayDensity(); 56801 * pixelDensity(density); 56802 * createCanvas(100, 100); 56803 * background(200); 56804 * ellipse(width / 2, height / 2, 50, 50); 56805 * } 56806 * </code> 56807 * </div> 56808 * 56809 * @alt 56810 * 50Ã50 white ellipse with black outline in center of canvas. 56811 */ 56812 _main.default.prototype.displayDensity = function () { 56813 return window.devicePixelRatio; 56814 }; 56815 function launchFullscreen(element) { 56816 var enabled = document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled; 56817 if (!enabled) { 56818 throw new Error('Fullscreen not enabled in this browser.'); 56819 } 56820 if (element.requestFullscreen) { 56821 element.requestFullscreen(); 56822 } else if (element.mozRequestFullScreen) { 56823 element.mozRequestFullScreen(); 56824 } else if (element.webkitRequestFullscreen) { 56825 element.webkitRequestFullscreen(); 56826 } else if (element.msRequestFullscreen) { 56827 element.msRequestFullscreen(); 56828 } 56829 } 56830 function exitFullscreen() { 56831 if (document.exitFullscreen) { 56832 document.exitFullscreen(); 56833 } else if (document.mozCancelFullScreen) { 56834 document.mozCancelFullScreen(); 56835 } else if (document.webkitExitFullscreen) { 56836 document.webkitExitFullscreen(); 56837 } else if (document.msExitFullscreen) { 56838 document.msExitFullscreen(); 56839 } 56840 } /** 56841 * Gets the current URL. Note: when using the 56842 * p5 Editor, this will return an empty object because the sketch 56843 * is embedded in an iframe. It will work correctly if you view the 56844 * sketch using the editor's present or share URLs. 56845 * @method getURL 56846 * @return {String} url 56847 * @example 56848 * <div> 56849 * <code> 56850 * let url; 56851 * let x = 100; 56852 * 56853 * function setup() { 56854 * fill(0); 56855 * noStroke();
56856 * url = getURL(); 56857 * } 56858 * 56859 * function draw() { 56860 * background(200); 56861 * text(url, x, height / 2); 56862 * x--; 56863 * } 56864 * </code> 56865 * </div> 56866 * 56867 * @alt 56868 * current url (http://p5js.org/reference/#/p5/getURL) moves right to left. 56869 */ 56870 56871 _main.default.prototype.getURL = function () { 56872 return location.href; 56873 }; 56874 /** 56875 * Gets the current URL path as an array. Note: when using the 56876 * p5 Editor, this will return an empty object because the sketch 56877 * is embedded in an iframe. It will work correctly if you view the 56878 * sketch using the editor's present or share URLs. 56879 * @method getURLPath 56880 * @return {String[]} path components 56881 * @example 56882 * <div class='norender'><code> 56883 * function setup() { 56884 * let urlPath = getURLPath(); 56885 * for (let i = 0; i < urlPath.length; i++) { 56886 * text(urlPath[i], 10, i * 20 + 20); 56887 * } 56888 * } 56889 * </code></div> 56890 * 56891 * @alt 56892 * This example does not render anything. 56893 */ 56894 _main.default.prototype.getURLPath = function () { 56895 return location.pathname.split('/').filter(function (v) { 56896 return v !== ''; 56897 }); 56898 }; 56899 /** 56900 * Gets the current URL params as an Object. Note: when using the 56901 * p5 Editor, this will return an empty object because the sketch 56902 * is embedded in an iframe. It will work correctly if you view the 56903 * sketch using the editor's present or share URLs. 56904 * @method getURLParams 56905 * @return {Object} URL params 56906 * @example 56907 * <div class='norender notest'> 56908 * <code> 56909 * // Example: http://p5js.org?year=2014&month=May&day=15 56910 * 56911 * function setup() { 56912 * let params = getURLParams(); 56913 * text(params.day, 10, 20); 56914 * text(params.month, 10, 40); 56915 * text(params.year, 10, 60); 56916 * } 56917 * </code> 56918 * </div> 56919 * 56920 * @alt 56921 * This example does not render anything. 56922 */ 56923 _main.default.prototype.getURLParams = function () { 56924 var re = /[?&]([^&=]+)(?:[&=])([^&=]+)/gim; 56925 var m; 56926 var v = { 56927 }; 56928 while ((m = re.exec(location.search)) != null) { 56929 if (m.index === re.lastIndex) { 56930 re.lastIndex++; 56931 } 56932 v[m[1]] = m[2]; 56933 } 56934 return v; 56935 }; 56936 var _default = _main.default; 56937 exports.default = _default; 56938 }, 56939 { 56940 './constants': 278, 56941 './main': 290, 56942 'core-js/modules/es.array.concat': 167, 56943 'core-js/modules/es.array.filter': 171, 56944 'core-js/modules/es.array.includes': 174, 56945 'core-js/modules/es.array.iterator': 176, 56946 'core-js/modules/es.object.get-own-property-descriptor': 191, 56947 'core-js/modules/es.object.to-string': 195, 56948 'core-js/modules/es.regexp.exec': 199, 56949 'core-js/modules/es.string.includes': 203, 56950 'core-js/modules/es.string.iterator': 204, 56951 'core-js/modules/es.string.search': 208, 56952 'core-js/modules/es.string.split': 209, 56953 'core-js/modules/es.symbol': 214, 56954 'core-js/modules/es.symbol.description': 212, 56955 'core-js/modules/es.symbol.iterator': 213, 56956 'core-js/modules/es.weak-map': 246, 56957 'core-js/modules/web.dom-collections.iterator': 248 56958 } 56959 ], 56960 280: [ 56961 function (_dereq_, module, exports) { 56962 'use strict'; 56963 Object.defineProperty(exports, '__esModule', { 56964 value: true 56965 }); 56966 exports.default = void 0; // This contains a data table used by ./fes_core.js/fesErrorMonitor(). 56967 // 56968 // Note: Different browsers use different error strings for the same error. 56969 // Extracting info from the browser error messages is easier and cleaner 56970 // if we have a predefined lookup. This file serves as that lookup. 56971 // Using this lookup we match the errors obtained from the browser, classify 56972 // them into types and extract the required information. 56973 // The FES can use the extracted info to generate a friendly error message 56974 // for the matching error. 56975 var strings = { 56976 ReferenceError: [ 56977 { 56978 msg: '{{}} is not defined', 56979 type: 'NOTDEFINED', 56980 browser: 'all' 56981 }, 56982 { 56983 msg: 'Can\'t find variable: {{}}', 56984 type: 'NOTDEFINED', 56985 browser: 'Safari' 56986 }, 56987 { 56988 msg: 'Cannot access \'{{.}}\' before initialization', 56989 type: 'CANNOTACCESS', 56990 browser: 'Chrome' 56991 }, 56992 { 56993 msg: 'can\'t access lexical declaration \'{{.}}\' before initialization', 56994 type: 'CANNOTACCESS', 56995 browser: 'Firefox' 56996 } 56997 ], 56998 SyntaxError: [ 56999 { 57000 msg: 'illegal character', 57001 type: 'INVALIDTOKEN', 57002 browser: 'Firefox' 57003 }, 57004 { 57005 msg: 'Invalid character', 57006 type: 'INVALIDTOKEN', 57007 browser: 'Safari' 57008 }, 57009 { 57010 msg: 'Invalid or unexpected token', 57011 type: 'INVALIDTOKEN', 57012 browser: 'Chrome' 57013 }, 57014 { 57015 msg: 'Unexpected token \'{{.}}\'', 57016 type: 'UNEXPECTEDTOKEN', 57017 browser: 'Chrome' 57018 }, 57019 { 57020 msg: 'expected {{.}}, got \'{{.}}\'', 57021 type: 'UNEXPECTEDTOKEN', 57022 browser: 'Chrome' 57023 }, 57024 { 57025 msg: 'Identifier \'{{.}}\' has already been declared', 57026 type: 'REDECLAREDVARIABLE', 57027 browser: 'Chrome' 57028 }, 57029 { 57030 msg: 'redeclaration of {} {{.}}', 57031 type: 'REDECLAREDVARIABLE', 57032 browser: 'Firefox' 57033 }, 57034 { 57035 msg: 'Missing initializer in const declaration', 57036 type: 'MISSINGINITIALIZER', 57037 browser: 'Chrome' 57038 }, 57039 { 57040 msg: 'missing = in const declaration', 57041 type: 'MISSINGINITIALIZER', 57042 browser: 'Firefox' 57043 }, 57044 { 57045 msg: 'Illegal return statement', 57046 type: 'BADRETURNORYIELD', 57047 browser: 'Chrome' 57048 }, 57049 { 57050 msg: 'return not in function', 57051 type: 'BADRETURNORYIELD', 57052 browser: 'Firefox' 57053 } 57054 ], 57055 TypeError: [ 57056 { 57057 msg: '{{.}} is not a function', 57058 type: 'NOTFUNC', 57059 browser: 'all' 57060 }, 57061 { 57062 msg: 'Cannot read {{.}} null', 57063 type: 'READNULL', 57064 browser: 'Chrome' 57065 }, 57066 { 57067 msg: '{{.}} is null', 57068 type: 'READNULL', 57069 browser: 'Firefox' 57070 }, 57071 { 57072 msg: 'Cannot read {{.}} undefined', 57073 type: 'READUDEFINED', 57074 browser: 'Chrome' 57075 }, 57076 { 57077 msg: '{{.}} is undefined', 57078 type: 'READUDEFINED', 57079 browser: 'Firefox' 57080 }, 57081 { 57082 msg: 'Assignment to constant variable', 57083 type: 'CONSTASSIGN', 57084 browser: 'Chrome' 57085 }, 57086 {
57087 msg: 'invalid assignment to const \'{{.}}\'', 57088 type: 'CONSTASSIGN', 57089 browser: 'Firefox' 57090 } 57091 ] 57092 }; 57093 var _default = strings; 57094 exports.default = _default; 57095 }, 57096 { 57097 } 57098 ], 57099 281: [ 57100 function (_dereq_, module, exports) { 57101 'use strict'; 57102 _dereq_('core-js/modules/es.symbol'); 57103 _dereq_('core-js/modules/es.symbol.description'); 57104 _dereq_('core-js/modules/es.symbol.iterator'); 57105 _dereq_('core-js/modules/es.array.concat'); 57106 _dereq_('core-js/modules/es.array.filter'); 57107 _dereq_('core-js/modules/es.array.for-each'); 57108 _dereq_('core-js/modules/es.array.includes'); 57109 _dereq_('core-js/modules/es.array.iterator'); 57110 _dereq_('core-js/modules/es.array.join'); 57111 _dereq_('core-js/modules/es.array.map'); 57112 _dereq_('core-js/modules/es.array.slice'); 57113 _dereq_('core-js/modules/es.array.some'); 57114 _dereq_('core-js/modules/es.function.name'); 57115 _dereq_('core-js/modules/es.object.assign'); 57116 _dereq_('core-js/modules/es.object.get-own-property-names'); 57117 _dereq_('core-js/modules/es.object.keys'); 57118 _dereq_('core-js/modules/es.object.to-string'); 57119 _dereq_('core-js/modules/es.regexp.constructor'); 57120 _dereq_('core-js/modules/es.regexp.exec'); 57121 _dereq_('core-js/modules/es.regexp.to-string'); 57122 _dereq_('core-js/modules/es.string.iterator'); 57123 _dereq_('core-js/modules/es.string.match'); 57124 _dereq_('core-js/modules/es.string.replace'); 57125 _dereq_('core-js/modules/es.string.search'); 57126 _dereq_('core-js/modules/es.string.split'); 57127 _dereq_('core-js/modules/web.dom-collections.for-each'); 57128 _dereq_('core-js/modules/web.dom-collections.iterator'); 57129 function _typeof2(obj) { 57130 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 57131 _typeof2 = function _typeof2(obj) { 57132 return typeof obj; 57133 }; 57134 } else { 57135 _typeof2 = function _typeof2(obj) { 57136 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 57137 }; 57138 } 57139 return _typeof2(obj); 57140 } 57141 _dereq_('core-js/modules/es.symbol'); 57142 _dereq_('core-js/modules/es.symbol.description'); 57143 _dereq_('core-js/modules/es.symbol.iterator'); 57144 _dereq_('core-js/modules/es.array.concat'); 57145 _dereq_('core-js/modules/es.array.filter'); 57146 _dereq_('core-js/modules/es.array.for-each'); 57147 _dereq_('core-js/modules/es.array.includes'); 57148 _dereq_('core-js/modules/es.array.iterator'); 57149 _dereq_('core-js/modules/es.array.join'); 57150 _dereq_('core-js/modules/es.array.map'); 57151 _dereq_('core-js/modules/es.array.slice'); 57152 _dereq_('core-js/modules/es.array.some'); 57153 _dereq_('core-js/modules/es.function.name'); 57154 _dereq_('core-js/modules/es.object.assign'); 57155 _dereq_('core-js/modules/es.object.get-own-property-names'); 57156 _dereq_('core-js/modules/es.object.keys'); 57157 _dereq_('core-js/modules/es.object.to-string'); 57158 _dereq_('core-js/modules/es.regexp.constructor'); 57159 _dereq_('core-js/modules/es.regexp.exec'); 57160 _dereq_('core-js/modules/es.regexp.to-string'); 57161 _dereq_('core-js/modules/es.string.iterator'); 57162 _dereq_('core-js/modules/es.string.match'); 57163 _dereq_('core-js/modules/es.string.replace'); 57164 _dereq_('core-js/modules/es.string.search'); 57165 _dereq_('core-js/modules/es.string.split'); 57166 _dereq_('core-js/modules/web.dom-collections.for-each'); 57167 _dereq_('core-js/modules/web.dom-collections.iterator'); 57168 Object.defineProperty(exports, '__esModule', { 57169 value: true 57170 }); 57171 exports.default = void 0; 57172 var _main = _interopRequireDefault(_dereq_('../main')); 57173 var _internationalization = _dereq_('../internationalization'); 57174 function _interopRequireDefault(obj) { 57175 return obj && obj.__esModule ? obj : { 57176 default: 57177 obj 57178 }; 57179 } 57180 function _slicedToArray(arr, i) { 57181 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); 57182 } 57183 function _nonIterableRest() {
57184 throw new TypeError('Invalid attempt to destructure non-iterable instance'); 57185 } 57186 function _iterableToArrayLimit(arr, i) { 57187 if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === '[object Arguments]')) { 57188 return; 57189 } 57190 var _arr = [ 57191 ]; 57192 var _n = true; 57193 var _d = false; 57194 var _e = undefined; 57195 try { 57196 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { 57197 _arr.push(_s.value); 57198 if (i && _arr.length === i) break; 57199 } 57200 } catch (err) { 57201 _d = true; 57202 _e = err; 57203 } finally { 57204 try { 57205 if (!_n && _i['return'] != null) _i['return'](); 57206 } finally { 57207 if (_d) throw _e; 57208 } 57209 } 57210 return _arr; 57211 } 57212 function _arrayWithHoles(arr) { 57213 if (Array.isArray(arr)) return arr; 57214 } 57215 function _typeof(obj) { 57216 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 57217 _typeof = function _typeof(obj) { 57218 return _typeof2(obj); 57219 }; 57220 } else { 57221 _typeof = function _typeof(obj) { 57222 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 57223 }; 57224 } 57225 return _typeof(obj); 57226 } // p5.js blue, p5.js orange, auto dark green; fallback p5.js darkened magenta 57227 // See testColors below for all the color codes and names 57228 57229 var typeColors = [ 57230 '#2D7BB6', 57231 '#EE9900', 57232 '#4DB200', 57233 '#C83C00' 57234 ]; 57235 var misusedAtTopLevelCode = null; 57236 var defineMisusedAtTopLevelCode = null; // the threshold for the maximum allowed levenshtein distance 57237 // used in misspelling detection 57238 var EDIT_DIST_THRESHOLD = 2; // to enable or disable styling (color, font-size, etc. ) for fes messages 57239 var ENABLE_FES_STYLING = false; 57240 if (typeof IS_MINIFIED !== 'undefined') { 57241 _main.default._friendlyError = _main.default._checkForUserDefinedFunctions = _main.default._fesErrorMonitor = function () { 57242 }; 57243 } else { 57244 var doFriendlyWelcome = false; // TEMP until we get it all working LM 57245 var errorTable = _dereq_('./browser_errors').default; // -- Borrowed from jQuery 1.11.3 -- 57246 var class2type = { 57247 }; 57248 var _toString = class2type.toString; 57249 var names = [ 57250 'Boolean', 57251 'Number', 57252 'String', 57253 'Function', 57254 'Array', 57255 'Date', 57256 'RegExp', 57257 'Object', 57258 'Error' 57259 ]; 57260 for (var n = 0; n < names.length; n++) { 57261 class2type['[object '.concat(names[n], ']')] = names[n].toLowerCase(); 57262 } 57263 var getType = function getType(obj) { 57264 if (obj == null) { 57265 return ''.concat(obj); 57266 } 57267 return _typeof(obj) === 'object' || typeof obj === 'function' ? class2type[_toString.call(obj)] || 'object' : _typeof(obj); 57268 }; // -- End borrow -- 57269 // entry points into user-defined code 57270 var entryPoints = [ 57271 'setup', 57272 'draw', 57273 'preload', 57274 'deviceMoved', 57275 'deviceTurned', 57276 'deviceShaken', 57277 'doubleClicked', 57278 'mousePressed', 57279 'mouseReleased', 57280 'mouseMoved', 57281 'mouseDragged', 57282 'mouseClicked', 57283 'mouseWheel', 57284 'touchStarted', 57285 'touchMoved', 57286 'touchEnded', 57287 'keyPressed', 57288 'keyReleased', 57289 'keyTyped', 57290 'windowResized' 57291 ]; 57292 var friendlyWelcome = function friendlyWelcome() { 57293 // p5.js brand - magenta: #ED225D 57294 //const astrixBgColor = 'transparent'; 57295 //const astrixTxtColor = '#ED225D'; 57296 //const welcomeBgColor = '#ED225D'; 57297 //const welcomeTextColor = 'white'; 57298 var welcomeMessage = (0, _internationalization.translator) ('fes.pre', { 57299 message: (0, _internationalization.translator) ('fes.welcome') 57300 }); 57301 console.log(' _ \n' + ' /\\| |/\\ \n' + ' \\ ` \' / \n' + ' / , . \\ \
57301n' + ' \\/|_|\\/ ' + '\n\n' + welcomeMessage); 57302 }; 57303 /** 57304 * Takes a message and a p5 function func, and adds a link pointing to 57305 * the reference documentation of func at the end of the message 57306 * 57307 * @method mapToReference 57308 * @private 57309 * @param {String} message the words to be said 57310 * @param {String} [func] the name of function 57311 * 57312 * @returns {String} 57313 */ 57314 var mapToReference = function mapToReference(message, func) { 57315 var msgWithReference = ''; 57316 if (func == null || func.substring(0, 4) === 'load') { 57317 msgWithReference = message; 57318 } else { 57319 var methodParts = func.split('.'); 57320 var referenceSection = methodParts.length > 1 ? ''.concat(methodParts[0], '.').concat(methodParts[1]) : 'p5'; 57321 var funcName = methodParts.length === 1 ? func : methodParts.slice(2).join('/'); 57322 msgWithReference = ''.concat(message, ' (http://p5js.org/reference/#/').concat(referenceSection, '/').concat(funcName, ')'); 57323 } 57324 return msgWithReference; 57325 }; 57326 /** 57327 * Prints out a fancy, colorful message to the console log 57328 * Attaches Friendly Errors prefix [fes.pre] to the message. 57329 * 57330 * @method _report 57331 * @private 57332 * @param {String} message Message to be printed 57333 * @param {String} [func] Name of function 57334 * @param {Number|String} [color] CSS color code 57335 * 57336 * @return console logs 57337 */ 57338 _main.default._report = function (message, func, color) { 57339 // if p5._fesLogger is set ( i.e we are running tests ), use that 57340 // instead of console.log 57341 var log = _main.default._fesLogger == null ? console.log.bind(console) : _main.default._fesLogger; 57342 if (doFriendlyWelcome) { 57343 friendlyWelcome(); 57344 doFriendlyWelcome = false; 57345 } 57346 if ('undefined' === getType(color)) { 57347 color = '#B40033'; // dark magenta 57348 } else if (getType(color) === 'number') { 57349 // Type to color 57350 color = typeColors[color]; 57351 } // Add a link to the reference docs of func at the end of the message 57352 57353 message = mapToReference(message, func); 57354 var style = [ 57355 'color: '.concat(color), 57356 'font-family: Arial', 57357 'font-size: larger' 57358 ]; 57359 var prefixedMsg = (0, _internationalization.translator) ('fes.pre', { 57360 message: message 57361 }); 57362 if (ENABLE_FES_STYLING) { 57363 log('%c' + prefixedMsg, style.join(';')); 57364 } else { 57365 log(prefixedMsg); 57366 } 57367 }; 57368 /** 57369 * This is a generic method that can be called from anywhere in the p5 57370 * library to alert users to a common error. 57371 * 57372 * @method _friendlyError 57373 * @private 57374 * @param {String} message Message to be printed 57375 * @param {String} [func] Name of the function linked to error 57376 * @param {Number|String} [color] CSS color code 57377 */ 57378 _main.default._friendlyError = function (message, func, color) { 57379 _main.default._report(message, func, color); 57380 }; 57381 /** 57382 * This is called internally if there is an error with autoplay. Generates 57383 * and prints a friendly error message [fes.autoplay]. 57384 * 57385 * @method _friendlyAutoplayError 57386 * @private 57387 */ 57388 _main.default._friendlyAutoplayError = function (src) { 57389 var message = (0, _internationalization.translator) ('fes.autoplay', { 57390 src: src, 57391 url: 'https://developer.mozilla.org/docs/Web/Media/Autoplay_guide' 57392 }); 57393 console.log((0, _internationalization.translator) ('fes.pre', { 57394 message: message 57395 })); 57396 }; 57397 /** 57398 * Measures dissimilarity between two strings by calculating 57399 * the Levenshtein distance. 57400 * 57401 * If the "distance" between them is small enough, it is
57402 * reasonable to think that one is the misspelled version of the other. 57403 * 57404 * Specifically, this uses the WagnerâFischer algorithm. 57405 * @method computeEditDistance 57406 * @private 57407 * @param {String} w1 the first word 57408 * @param {String} w2 the second word 57409 * 57410 * @returns {Number} the "distance" between the two words, a smaller value 57411 * indicates that the words are similar 57412 */ 57413 var computeEditDistance = function computeEditDistance(w1, w2) { 57414 var l1 = w1.length, 57415 l2 = w2.length; 57416 if (l1 === 0) return w2; 57417 if (l2 === 0) return w1; 57418 var prev = [ 57419 ]; 57420 var cur = [ 57421 ]; 57422 for (var j = 0; j < l2 + 1; j++) { 57423 cur[j] = j; 57424 } 57425 prev = cur; 57426 for (var i = 1; i < l1 + 1; i++) { 57427 cur = [ 57428 ]; 57429 for (var _j = 0; _j < l2 + 1; _j++) { 57430 if (_j === 0) { 57431 cur[_j] = i; 57432 } else { 57433 var a1 = w1[i - 1], 57434 a2 = w2[_j - 1]; 57435 var temp = 999999; 57436 var cost = a1.toLowerCase() === a2.toLowerCase() ? 0 : 1; 57437 temp = temp > cost + prev[_j - 1] ? cost + prev[_j - 1] : temp; 57438 temp = temp > 1 + cur[_j - 1] ? 1 + cur[_j - 1] : temp; 57439 temp = temp > 1 + prev[_j] ? 1 + prev[_j] : temp; 57440 cur[_j] = temp; 57441 } 57442 } 57443 prev = cur; 57444 } 57445 return cur[l2]; 57446 }; 57447 /** 57448 * Checks capitalization for user defined functions. 57449 * 57450 * Generates and prints a friendly error message using key: 57451 * "fes.checkUserDefinedFns". 57452 * 57453 * @method checkForUserDefinedFunctions 57454 * @private 57455 * @param {*} context Current default context. Set to window in 57456 * "global mode" and to a p5 instance in "instance mode" 57457 */ 57458 var checkForUserDefinedFunctions = function checkForUserDefinedFunctions(context) { 57459 if (_main.default.disableFriendlyErrors) return; // if using instance mode, this function would be called with the current 57460 // instance as context 57461 var instanceMode = context instanceof _main.default; 57462 context = instanceMode ? context : window; 57463 var fnNames = entryPoints; 57464 var fxns = { 57465 }; // lowercasename -> actualName mapping 57466 fnNames.forEach(function (symbol) { 57467 fxns[symbol.toLowerCase()] = symbol; 57468 }); 57469 for (var _i = 0, _Object$keys = Object.keys(context); _i < _Object$keys.length; _i++) { 57470 var prop = _Object$keys[_i]; 57471 var lowercase = prop.toLowerCase(); // check if the lowercase property name has an entry in fxns, if the 57472 // actual name with correct capitalization doesnt exist in context, 57473 // and if the user-defined symbol is of the type function 57474 if (fxns[lowercase] && !context[fxns[lowercase]] && typeof context[prop] === 'function') { 57475 var msg = (0, _internationalization.translator) ('fes.checkUserDefinedFns', { 57476 name: prop, 57477 actualName: fxns[lowercase] 57478 }); 57479 _main.default._friendlyError(msg, fxns[lowercase]); 57480 } 57481 } 57482 }; 57483 /** 57484 * Compares the symbol caught in the ReferenceErrror to everything in 57485 * misusedAtTopLevel ( all public p5 properties ). 57486 * 57487 * Generates and prints a friendly error message using key: "fes.misspelling". 57488 * 57489 * @method handleMisspelling 57490 * @private 57491 * @param {String} errSym Symbol to whose spelling to check 57492 * @param {Error} error ReferenceError object 57493 * 57494 * @returns {Boolean} tell whether error was likely due to typo 57495 */ 57496 var handleMisspelling = function handleMisspelling(errSym, error) { 57497 if (!misusedAtTopLevelCode) { 57498 defineMisusedAtTopLevelCode(); 57499 } 57500 var distanceMap = { 57501 }; 57502 var min = 999999; // compute the levenshtein distance for the symbol against all known 57503 // public p5 properties. Find the property with the minimum distance 57504 misusedAtTopLevelCode.forEach(function (symbol) { 57505 var dist = computeEditDistance(errSym, symbol.name); 57506 if (distanceMap[dist]) distanceMap[dist].push(symbol); 57507 else distanceMap[dist] = [ 57508 symbol 57509 ]; 57510 if (dist < min) min = dist; 57511 }); // if the closest match has more "distance" than the max allowed threshold 57512 if (min > Math.min(EDIT_DIST_THRESHOLD, errSym.length)) return false; // Show a message only if the caught symbol and the matched property name 57513 // differ in their name ( either letter difference or difference of case )
57514 var matchedSymbols = distanceMap[min].filter(function (symbol) { 57515 return symbol.name !== errSym; 57516 }); 57517 if (matchedSymbols.length !== 0) { 57518 var parsed = _main.default._getErrorStackParser().parse(error); 57519 var locationObj; 57520 if (parsed && parsed[0] && parsed[0].fileName && parsed[0].lineNumber && parsed[0].columnNumber) { 57521 locationObj = { 57522 location: ''.concat(parsed[0].fileName, ':').concat(parsed[0].lineNumber, ':').concat(parsed[0].columnNumber), 57523 file: parsed[0].fileName.split('/').slice( - 1), 57524 line: parsed[0].lineNumber 57525 }; 57526 } 57527 var msg; 57528 if (matchedSymbols.length === 1) { 57529 // To be used when there is only one closest match. The count parameter 57530 // allows i18n to pick between the keys "fes.misspelling" and 57531 // "fes.misspelling_plural" 57532 msg = (0, _internationalization.translator) ('fes.misspelling', { 57533 name: errSym, 57534 actualName: matchedSymbols[0].name, 57535 type: matchedSymbols[0].type, 57536 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '', 57537 count: matchedSymbols.length 57538 }); 57539 } else { 57540 // To be used when there are multiple closest matches. Gives each 57541 // suggestion on its own line, the function name followed by a link to 57542 // reference documentation 57543 var suggestions = matchedSymbols.map(function (symbol) { 57544 var message = 'â¶ï¸ ' + symbol.name + (symbol.type === 'function' ? '()' : ''); 57545 return mapToReference(message, symbol.name); 57546 }).join('\n'); 57547 msg = (0, _internationalization.translator) ('fes.misspelling', { 57548 name: errSym, 57549 suggestions: suggestions, 57550 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '', 57551 count: matchedSymbols.length 57552 }); 57553 } // If there is only one closest match, tell _friendlyError to also add 57554 // a link to the reference documentation. In case of multiple matches, 57555 // this is already done in the suggestions variable, one link for each 57556 // suggestion. 57557 57558 _main.default._friendlyError(msg, matchedSymbols.length === 1 ? matchedSymbols[0].name : undefined); 57559 return true; 57560 } 57561 return false; 57562 }; 57563 /** 57564 * Prints a friendly stacktrace for user-written functions for "global" errors 57565 * 57566 * Generates and prints a friendly error message using key: 57567 * "fes.globalErrors.stackTop", "fes.globalErrors.stackSubseq". 57568 * 57569 * @method printFriendlyStack 57570 * @private 57571 * @param {Array} friendlyStack 57572 */ 57573 var printFriendlyStack = function printFriendlyStack(friendlyStack) { 57574 var log = _main.default._fesLogger && typeof _main.default._fesLogger === 'function' ? _main.default._fesLogger : console.log.bind(console); 57575 if (friendlyStack.length > 1) { 57576 var stacktraceMsg = ''; 57577 friendlyStack.forEach(function (frame, idx) { 57578 var location = ''.concat(frame.fileName, ':').concat(frame.lineNumber, ':').concat(frame.columnNumber); 57579 var frameMsg, 57580 translationObj = { 57581 func: frame.functionName, 57582 line: frame.lineNumber, 57583 location: location, 57584 file: frame.fileName.split('/').slice( - 1) 57585 }; 57586 if (idx === 0) { 57587 frameMsg = (0, _internationalization.translator) ('fes.globalErrors.stackTop', translationObj); 57588 } else { 57589 frameMsg = (0, _internationalization.translator) ('fes.globalErrors.stackSubseq', translationObj); 57590 } 57591 stacktraceMsg += frameMsg; 57592 }); 57593 log(stacktraceMsg); 57594 } 57595 }; 57596 /** 57597 * Takes a stacktrace array and filters out all frames that show internal p5 57598 * details. 57599 * 57600 * Generates and prints a friendly error message using key: 57601 * "fes.wrongPreload", "fes.libraryError". 57602 * 57603 * The processed stack is used to find whether the error happended internally 57604 * within the library, and if the error was due to a non-loadX() method 57605 * being used in preload. 57606 * 57607 * "Internally" here means that the exact location of the error (the top of 57608 * the stack) is a piece of code write in the p5.js library (which may or 57609 * may not have been called from the user's sketch). 57610 * 57611 * @method processStack 57612 * @private 57613 * @param {Error} error 57614 * @param {Array} stacktrace 57615 * 57616 * @returns {Array} An array with two elements, [isInternal, friendlyStack] 57617 * isInternal: a boolean value indicating whether the error 57618 * happened internally 57619 * friendlyStack: the filtered (simplified) stacktrace 57620 */ 57621 var processStack = function processStack(error, stacktrace) { 57622 // cannot process a stacktrace that doesn't exist 57623 if (!stacktrace) return [false, 57624 null]; 57625 stacktrace.forEach(function (frame) { 57626 frame.functionName = frame.functionName || ''; 57627 }); // isInternal - Did this error happen inside the library 57628 var isInternal = false;
57629 var p5FileName, 57630 friendlyStack, 57631 currentEntryPoint; 57632 for (var i = stacktrace.length - 1; i >= 0; i--) { 57633 var splitted = stacktrace[i].functionName.split('.'); 57634 if (entryPoints.includes(splitted[splitted.length - 1])) { 57635 // remove everything below an entry point function (setup, draw, etc). 57636 // (it's usually the internal initialization calls) 57637 friendlyStack = stacktrace.slice(0, i + 1); 57638 currentEntryPoint = splitted[splitted.length - 1]; 57639 for (var j = 0; j < i; j++) { 57640 // Due to the current build process, all p5 functions have 57641 // _main.default in their names in the final build. This is the 57642 // easiest way to check if a function is inside the p5 library 57643 if (stacktrace[j].functionName.search('_main.default') !== - 1) { 57644 isInternal = true; 57645 p5FileName = stacktrace[j].fileName; 57646 break; 57647 } 57648 } 57649 break; 57650 } 57651 } // in some cases ( errors in promises, callbacks, etc), no entry-point 57652 // function may be found in the stacktrace. In that case just use the 57653 // entire stacktrace for friendlyStack 57654 57655 if (!friendlyStack) friendlyStack = stacktrace; 57656 if (isInternal) { 57657 // the frameIndex property is added before the filter, so frameIndex 57658 // corresponds to the index of a frame in the original stacktrace. 57659 // Then we filter out all frames which belong to the file that contains 57660 // the p5 library 57661 friendlyStack = friendlyStack.map(function (frame, index) { 57662 frame.frameIndex = index; 57663 return frame; 57664 }).filter(function (frame) { 57665 return frame.fileName !== p5FileName; 57666 }); // a weird case, if for some reason we can't identify the function called 57667 // from user's code 57668 if (friendlyStack.length === 0) return [true, 57669 null]; // get the function just above the topmost frame in the friendlyStack. 57670 // i.e the name of the library function called from user's code 57671 var func = stacktrace[friendlyStack[0].frameIndex - 1].functionName.split('.').slice( - 1) [0]; // Try and get the location (line no.) from the top element of the stack 57672 var locationObj; 57673 if (friendlyStack[0].fileName && friendlyStack[0].lineNumber && friendlyStack[0].columnNumber) { 57674 locationObj = { 57675 location: ''.concat(friendlyStack[0].fileName, ':').concat(friendlyStack[0].lineNumber, ':').concat(friendlyStack[0].columnNumber), 57676 file: friendlyStack[0].fileName.split('/').slice( - 1), 57677 line: friendlyStack[0].lineNumber 57678 }; // if already handled by another part of the FES, don't handle again 57679 if (_main.default._fesLogCache[locationObj.location]) return [true, 57680 null]; 57681 } // Check if the error is due to a non loadX method being used incorrectly 57682 // in preload 57683 57684 if (currentEntryPoint === 'preload' && _main.default.prototype._preloadMethods[func] == null) { 57685 _main.default._friendlyError((0, _internationalization.translator) ('fes.wrongPreload', { 57686 func: func, 57687 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '', 57688 error: error.message 57689 }), 'preload'); 57690 } else { 57691 // Library error 57692 _main.default._friendlyError((0, _internationalization.translator) ('fes.libraryError', { 57693 func: func, 57694 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '', 57695 error: error.message 57696 }), func); 57697 } // Finally, if it's an internal error, print the friendlyStack 57698 // ( fesErrorMonitor won't handle this error ) 57699 57700 if (friendlyStack && friendlyStack.length) { 57701 printFriendlyStack(friendlyStack); 57702 } 57703 } 57704 return [isInternal, 57705 friendlyStack]; 57706 }; 57707 /** 57708 * Handles "global" errors that the browser catches. 57709 * 57710 * Called when an error event happens and detects the type of error. 57711 * 57712 * Generates and prints a friendly error message using key: 57713 * "fes.globalErrors.syntax.[*]", "fes.globalErrors.reference.[*]", 57714 * "fes.globalErrors.type.[*]". 57715 * 57716 * @method fesErrorMonitor
57717 * @private 57718 * @param {*} e Event object to extract error details from 57719 */ 57720 var fesErrorMonitor = function fesErrorMonitor(e) { 57721 if (_main.default.disableFriendlyErrors) return; // Try to get the error object from e 57722 var error; 57723 if (e instanceof Error) { 57724 error = e; 57725 } else if (e instanceof ErrorEvent) { 57726 error = e.error; 57727 } else if (e instanceof PromiseRejectionEvent) { 57728 error = e.reason; 57729 if (!(error instanceof Error)) return; 57730 } 57731 if (!error) return; 57732 var stacktrace = _main.default._getErrorStackParser().parse(error); // process the stacktrace from the browser and simplify it to give 57733 // friendlyStack. 57734 var _processStack = processStack(error, stacktrace), 57735 _processStack2 = _slicedToArray(_processStack, 2), 57736 isInternal = _processStack2[0], 57737 friendlyStack = _processStack2[1]; // if this is an internal library error, the type of the error is not relevant, 57738 // only the user code that lead to it is. 57739 if (isInternal) { 57740 return; 57741 } 57742 var errList = errorTable[error.name]; 57743 if (!errList) return; // this type of error can't be handled yet 57744 var matchedError; 57745 var _iteratorNormalCompletion = true; 57746 var _didIteratorError = false; 57747 var _iteratorError = undefined; 57748 try { 57749 for (var _iterator = errList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 57750 var obj = _step.value; 57751 var string = obj.msg; // capture the primary symbol mentioned in the error 57752 string = string.replace(new RegExp('{{}}', 'g'), '([a-zA-Z0-9_]+)'); 57753 string = string.replace(new RegExp('{{.}}', 'g'), '(.+)'); 57754 string = string.replace(new RegExp('{}', 'g'), '(?:[a-zA-Z0-9_]+)'); 57755 var matched = error.message.match(string); 57756 if (matched) { 57757 matchedError = Object.assign({ 57758 }, obj); 57759 matchedError.match = matched; 57760 break; 57761 } 57762 } 57763 } catch (err) { 57764 _didIteratorError = true; 57765 _iteratorError = err; 57766 } finally { 57767 try { 57768 if (!_iteratorNormalCompletion && _iterator.return != null) { 57769 _iterator.return(); 57770 } 57771 } finally { 57772 if (_didIteratorError) { 57773 throw _iteratorError; 57774 } 57775 } 57776 } 57777 if (!matchedError) return; // Try and get the location from the top element of the stack 57778 var locationObj; 57779 if (stacktrace && stacktrace[0].fileName && stacktrace[0].lineNumber && stacktrace[0].columnNumber) { 57780 locationObj = { 57781 location: ''.concat(stacktrace[0].fileName, ':').concat(stacktrace[0].lineNumber, ':').concat(stacktrace[0].columnNumber), 57782 file: stacktrace[0].fileName.split('/').slice( - 1), 57783 line: friendlyStack[0].lineNumber 57784 }; 57785 } 57786 switch (error.name) { 57787 case 'SyntaxError': 57788 { 57789 // We can't really do much with syntax errors other than try to use 57790 // a simpler framing of the error message. The stack isn't available 57791 // for syntax errors 57792 switch (matchedError.type) { 57793 case 'INVALIDTOKEN': 57794 { 57795 //Error if there is an invalid or unexpected token that doesn't belong at this position in the code 57796 //let x = ânot a stringâ; -> string not in proper quotes 57797 var url = 'https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Illegal_character#What_went_wrong'; 57798 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.syntax.invalidToken', { 57799 url: url 57800 })); 57801 break; 57802 } 57803 case 'UNEXPECTEDTOKEN': 57804 { 57805 //Error if a specific language construct(, { ; etc) was expected, but something else was provided 57806 //for (let i = 0; i < 5,; ++i) -> a comma after i<5 instead of a semicolon 57807 var _url = 'https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Unexpected_token#What_went_wrong'; 57808 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.syntax.unex
57808pectedToken', { 57809 url: _url 57810 })); 57811 break; 57812 } 57813 case 'REDECLAREDVARIABLE': 57814 { 57815 //Error if a variable is redeclared by the user. Example=> 57816 //let a = 10; 57817 //let a = 100; 57818 var errSym = matchedError.match[1]; 57819 var _url2 = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Redeclared_parameter#what_went_wrong'; 57820 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.syntax.redeclaredVariable', { 57821 symbol: errSym, 57822 url: _url2 57823 })); 57824 break; 57825 } 57826 case 'MISSINGINITIALIZER': 57827 { 57828 //Error if a const variable is not initialized during declaration 57829 //Example => const a; 57830 var _url3 = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_initializer_in_const#what_went_wrong'; 57831 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.syntax.missingInitializer', { 57832 url: _url3 57833 })); 57834 break; 57835 } 57836 case 'BADRETURNORYIELD': 57837 { 57838 //Error when a return statement is misplaced(usually outside of a function) 57839 // const a = function(){ 57840 // ..... 57841 // } 57842 // return; -> misplaced return statement 57843 var _url4 = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Bad_return_or_yield#what_went_wrong'; 57844 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.syntax.badReturnOrYield', { 57845 url: _url4 57846 })); 57847 break; 57848 } 57849 } 57850 break; 57851 } 57852 case 'ReferenceError': 57853 { 57854 switch (matchedError.type) { 57855 case 'NOTDEFINED': 57856 { 57857 //Error if there is a non-existent variable referenced somewhere 57858 //let a = 10; 57859 //console.log(x); 57860 var _errSym = matchedError.match[1]; 57861 if (_errSym && handleMisspelling(_errSym, error)) { 57862 break; 57863 } // if the flow gets this far, this is likely not a misspelling 57864 // of a p5 property/function 57865 57866 var _url5 = 'https://p5js.org/examples/data-variable-scope.html'; 57867 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.reference.notDefined', { 57868 url: _url5, 57869 symbol: _errSym, 57870 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '' 57871 })); 57872 if (friendlyStack) printFriendlyStack(friendlyStack); 57873 break; 57874 } 57875 case 'CANNOTACCESS': 57876 { 57877 //Error if a lexical variable was accessed before it was initialized 57878 //console.log(a); -> variable accessed before it was initialized 57879 //let a=100; 57880 var _errSym2 = matchedError.match[1]; 57881 var _url6 = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init#what_went_wrong'; 57882 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.reference.cannotAccess', { 57883 url: _url6, 57884 symbol: _errSym2, 57885 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '' 57886 })); 57887 if (friendlyStack) printFriendlyStack(friendlyStack); 57888 break; 57889 } 57890 } 57891 break; 57892 } 57893 case 'TypeError': 57894 { 57895 switch (matchedError.type) { 57896 case 'NOTFUNC': 57897 { 57898 //Error when some code expects you to provide a function, but that didn't happen 57899 //let a = document.getElementByID('foo'); -> getElementById instead of getElementByID 57900 var _errSym3 = matchedError.match[1]; 57901 var splitSym = _errSym3.split('.'); 57902 var _url7 = 'https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Not_a_function#What_went_wrong'; // if errSym is aa.bb.cc , symbol would be cc and obj would aa.bb 57903 var translationObj = { 57904 url: _url7, 57905 symbol: splitSym[splitSym.length - 1], 57906 obj: splitSym.slice(0, splitSym.length - 1).join('.'), 57907 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '' 57908 }; // There are two cases to handle here. When the function is called 57909 // as a property of an object and when it's called
57909independently. 57910 // Both have different explanations. 57911 if (splitSym.length > 1) { 57912 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.type.notfuncObj', translationObj)); 57913 } else { 57914 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.type.notfunc', translationObj)); 57915 } 57916 if (friendlyStack) printFriendlyStack(friendlyStack); 57917 break; 57918 } 57919 case 'READNULL': 57920 { 57921 //Error if a property of null is accessed 57922 //let a = null; 57923 //console.log(a.property); -> a is null 57924 var _errSym4 = matchedError.match[1]; 57925 var _url8 = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_property#what_went_wrong'; 57926 /*let url2 = 57927 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null';*/ 57928 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.type.readFromNull', { 57929 url: _url8, 57930 symbol: _errSym4, 57931 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '' 57932 })); 57933 if (friendlyStack) printFriendlyStack(friendlyStack); 57934 break; 57935 } 57936 case 'READUDEFINED': 57937 { 57938 //Error if a property of undefined is accessed 57939 //let a; -> default value of a is undefined 57940 //console.log(a.property); -> a is undefined 57941 var _errSym5 = matchedError.match[1]; 57942 var _url9 = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_property#what_went_wrong'; 57943 /*let url2 = 57944 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined#description';*/ 57945 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.type.readFromUndefined', { 57946 url: _url9, 57947 symbol: _errSym5, 57948 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '' 57949 })); 57950 if (friendlyStack) printFriendlyStack(friendlyStack); 57951 break; 57952 } 57953 case 'CONSTASSIGN': 57954 { 57955 //Error when a const variable is reassigned a value 57956 //const a = 100; 57957 //a=10; 57958 var _url10 = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment#what_went_wrong'; 57959 _main.default._friendlyError((0, _internationalization.translator) ('fes.globalErrors.type.constAssign', { 57960 url: _url10, 57961 location: locationObj ? (0, _internationalization.translator) ('fes.location', locationObj) : '' 57962 })); 57963 if (friendlyStack) printFriendlyStack(friendlyStack); 57964 break; 57965 } 57966 } 57967 } 57968 } 57969 }; 57970 _main.default._fesErrorMonitor = fesErrorMonitor; 57971 _main.default._checkForUserDefinedFunctions = checkForUserDefinedFunctions; // logger for testing purposes. 57972 _main.default._fesLogger = null; 57973 _main.default._fesLogCache = { 57974 }; 57975 window.addEventListener('load', checkForUserDefinedFunctions, false); 57976 window.addEventListener('error', _main.default._fesErrorMonitor, false); 57977 window.addEventListener('unhandledrejection', _main.default._fesErrorMonitor, false); 57978 /** 57979 * Prints out all the colors in the color pallete with white text. 57980 * For color blindness testing. 57981 */ 57982 /* function testColors() { 57983 const str = 'A box of biscuits, a box of mixed biscuits and a biscuit mixer'; 57984 p5._friendlyError(str, 'print', '#ED225D'); // p5.js magenta 57985 p5._friendlyError(str, 'print', '#2D7BB6'); // p5.js blue 57986 p5._friendlyError(str, 'print', '#EE9900'); // p5.js orange 57987 p5._friendlyError(str, 'print', '#A67F59'); // p5.js light brown 57988 p5._friendlyError(str, 'print', '#704F21'); // p5.js gold 57989 p5._friendlyError(str, 'print', '#1CC581'); // auto cyan 57990 p5._friendlyError(str, 'print', '#FF6625'); // auto orange 57991 p5._friendlyError(str, 'print', '#79EB22'); // auto green 57992 p5._friendlyError(str, 'print', '#B40033'); // p5.js darkened magenta 57993 p5._friendlyError(str, 'print', '#084B7F'); // p5.js darkened blue 57994 p5._friendlyError(str, 'print', '#945F00'); // p5.js darkened orange 57995 p5._friendlyError(str, 'print', '#6B441D'); // p5.js darkened brown 57996 p5._friendlyError(str, 'print', '#2E1B00'); // p5.js darkened gold 57997 p5._friendlyError(str, 'print', '#008851'); // auto dark cyan 57998 p5._friendlyError(str, 'print', '#C83C00'); // auto dark orange 57999 p5._friendlyError(str, 'print', '#4DB200'); // auto dark green 58000 } */ 58001 } // This is a lazily-defined list of p5 symbols that may be
58002 // misused by beginners at top-level code, outside of setup/draw. We'd like 58003 // to detect these errors and help the user by suggesting they move them 58004 // into setup/draw. 58005 // 58006 // For more details, see https://github.com/processing/p5.js/issues/1121. 58007 58008 misusedAtTopLevelCode = null; 58009 var FAQ_URL = 'https://github.com/processing/p5.js/wiki/p5.js-overview#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup'; 58010 /** 58011 * A helper function for populating misusedAtTopLevel list. 58012 * 58013 * @method defineMisusedAtTopLevelCode 58014 * @private 58015 */ 58016 defineMisusedAtTopLevelCode = function defineMisusedAtTopLevelCode() { 58017 var uniqueNamesFound = { 58018 }; 58019 var getSymbols = function getSymbols(obj) { 58020 return Object.getOwnPropertyNames(obj).filter(function (name) { 58021 if (name[0] === '_') { 58022 return false; 58023 } 58024 if (name in uniqueNamesFound) { 58025 return false; 58026 } 58027 uniqueNamesFound[name] = true; 58028 return true; 58029 }).map(function (name) { 58030 var type; 58031 if (typeof obj[name] === 'function') { 58032 type = 'function'; 58033 } else if (name === name.toUpperCase()) { 58034 type = 'constant'; 58035 } else { 58036 type = 'variable'; 58037 } 58038 return { 58039 name: name, 58040 type: type 58041 }; 58042 }); 58043 }; 58044 misusedAtTopLevelCode = [ 58045 ].concat(getSymbols(_main.default.prototype), // At present, p5 only adds its constants to p5.prototype during 58046 // construction, which may not have happened at the time a 58047 // ReferenceError is thrown, so we'll manually add them to our list. 58048 getSymbols(_dereq_('../constants'))); // This will ultimately ensure that we report the most specific error 58049 // possible to the user, e.g. advising them about HALF_PI instead of PI 58050 // when their code misuses the former. 58051 misusedAtTopLevelCode.sort(function (a, b) { 58052 return b.name.length - a.name.length; 58053 }); 58054 }; 58055 /** 58056 * Detects browser level error event for p5 constants/functions used outside 58057 * of setup() and draw(). 58058 * 58059 * Generates and prints a friendly error message using key: 58060 * "fes.misusedTopLevel". 58061 * 58062 * @method helpForMisusedAtTopLevelCode 58063 * @private 58064 * @param {Event} e Error event 58065 * @param {Boolean} log false 58066 * 58067 * @returns {Boolean} true 58068 */ 58069 var helpForMisusedAtTopLevelCode = function helpForMisusedAtTopLevelCode(e, log) { 58070 if (!log) { 58071 log = console.log.bind(console); 58072 } 58073 if (!misusedAtTopLevelCode) { 58074 defineMisusedAtTopLevelCode(); 58075 } // If we find that we're logging lots of false positives, we can 58076 // uncomment the following code to avoid displaying anything if the 58077 // user's code isn't likely to be using p5's global mode. (Note that 58078 // setup/draw are more likely to be defined due to JS function hoisting.) 58079 // 58080 //if (!('setup' in window || 'draw' in window)) { 58081 // return; 58082 //} 58083 58084 misusedAtTopLevelCode.some(function (symbol) { 58085 // Note that while just checking for the occurrence of the 58086 // symbol name in the error message could result in false positives, 58087 // a more rigorous test is difficult because different browsers 58088 // log different messages, and the format of those messages may 58089 // change over time. 58090 // 58091 // For example, if the user uses 'PI' in their code, it may result 58092 // in any one of the following messages: 58093 // 58094 // * 'PI' is undefined (Microsoft Edge) 58095 // * ReferenceError: PI is undefined (Firefox) 58096 // * Uncaught ReferenceError: PI is not defined (Chrome) 58097 if (e.message && e.message.match('\\W?'.concat(symbol.name, '\\W')) !== null) { 58098 var symbolName = symbol.type === 'function' ? ''.concat(symbol.name, '()') : symbol.name; 58099 if (typeof IS_MINIFIED !== 'undefined') { 58100 log('Did you just try to use p5.js\'s '.concat(symbolName, ' ').concat(symbol.type, '? If so, you may want to move it into your sketch\'s setup() function.\n\nFor more details, see: ').concat(FAQ_URL)); 58101 } else { 58102 log((0, _internationalization.translator) ('fes.misusedTopLevel', { 58103 symbolName: symbolName, 58104 symbolType: symbol.type, 58105 url: FAQ_URL 58106 })); 58107 } 58108 return true; 58109 } 58110 }); 58111 }; // Exposing this primarily for unit testing. 58112 _main.default.prototype._helpForMisusedAtTopLevelCode = helpForMisusedAtTopLevelCode;
58113 if (document.readyState !== 'complete') { 58114 window.addEventListener('error', helpForMisusedAtTopLevelCode, false); // Our job is only to catch ReferenceErrors that are thrown when 58115 // global (non-instance mode) p5 APIs are used at the top-level 58116 // scope of a file, so we'll unbind our error listener now to make 58117 // sure we don't log false positives later. 58118 window.addEventListener('load', function () { 58119 window.removeEventListener('error', helpForMisusedAtTopLevelCode, false); 58120 }); 58121 } 58122 var _default = _main.default; 58123 exports.default = _default; 58124 }, 58125 { 58126 '../constants': 278, 58127 '../internationalization': 288, 58128 '../main': 290, 58129 './browser_errors': 280, 58130 'core-js/modules/es.array.concat': 167, 58131 'core-js/modules/es.array.filter': 171, 58132 'core-js/modules/es.array.for-each': 172, 58133 'core-js/modules/es.array.includes': 174, 58134 'core-js/modules/es.array.iterator': 176, 58135 'core-js/modules/es.array.join': 177, 58136 'core-js/modules/es.array.map': 179, 58137 'core-js/modules/es.array.slice': 180, 58138 'core-js/modules/es.array.some': 181, 58139 'core-js/modules/es.function.name': 183, 58140 'core-js/modules/es.object.assign': 190, 58141 'core-js/modules/es.object.get-own-property-names': 192, 58142 'core-js/modules/es.object.keys': 194, 58143 'core-js/modules/es.object.to-string': 195, 58144 'core-js/modules/es.regexp.constructor': 198, 58145 'core-js/modules/es.regexp.exec': 199, 58146 'core-js/modules/es.regexp.to-string': 200, 58147 'core-js/modules/es.string.iterator': 204, 58148 'core-js/modules/es.string.match': 205, 58149 'core-js/modules/es.string.replace': 207, 58150 'core-js/modules/es.string.search': 208, 58151 'core-js/modules/es.string.split': 209, 58152 'core-js/modules/es.symbol': 214, 58153 'core-js/modules/es.symbol.description': 212, 58154 'core-js/modules/es.symbol.iterator': 213, 58155 'core-js/modules/web.dom-collections.for-each': 247, 58156 'core-js/modules/web.dom-collections.iterator': 248 58157 } 58158 ], 58159 282: [ 58160 function (_dereq_, module, exports) { 58161 'use strict'; 58162 Object.defineProperty(exports, '__esModule', { 58163 value: true 58164 }); 58165 exports.default = void 0; 58166 var _main = _interopRequireDefault(_dereq_('../main')); 58167 var _internationalization = _dereq_('../internationalization'); 58168 function _interopRequireDefault(obj) { 58169 return obj && obj.__esModule ? obj : { 58170 default: 58171 obj 58172 }; 58173 } /** 58174 * @for p5 58175 * @requires core 58176 */ 58177 58178 if (typeof IS_MINIFIED !== 'undefined') { 58179 _main.default._friendlyFileLoadError = function () { 58180 }; 58181 } else { 58182 // mapping used by `_friendlyFileLoadError` 58183 var fileLoadErrorCases = function fileLoadErrorCases(num, filePath) { 58184 var suggestion = (0, _internationalization.translator) ('fes.fileLoadError.suggestion', { 58185 filePath: filePath, 58186 url: 'https://github.com/processing/p5.js/wiki/Local-server' 58187 }); 58188 switch (num) { 58189 case 0: 58190 return { 58191 message: (0, _internationalization.translator) ('fes.fileLoadError.image', { 58192 suggestion: suggestion 58193 }), 58194 method: 'loadImage' 58195 }; 58196 case 1: 58197 return { 58198 message: (0, _internationalization.translator) ('fes.fileLoadError.xml', { 58199 suggestion: suggestion 58200 }), 58201 method: 'loadXML' 58202 }; 58203 case 2: 58204 return { 58205 message: (0, _internationalization.translator) ('fes.fileLoadError.table', { 58206 suggestion: suggestion 58207 }), 58208 method: 'loadTable' 58209 }; 58210 case 3: 58211 return { 58212 message: (0, _internationalization.translator) ('fes.fileLoadError.strings', { 58213 suggestion: suggestion 58214 }), 58215 method: 'loadStrings' 58216 }; 58217 case 4: 58218 return { 58219 message: (0, _internationalization.translator) ('fes.fileLoadError.font', { 58220 suggestion: suggestion 58221 }), 58222 method: 'loadFont' 58223 }; 58224 case 5: 58225 return { 58226 message: (0, _internationalization.translator) ('fes.fileLoadError.json', { 58227 suggestion: suggestion 58228 }), 58229 method: 'loadJSON' 58230 }; 58231 case 6: 58232 return { 58233 message: (0, _internationalization.translator) ('fes.fileLoadError.bytes', { 58234 suggestion: suggestion 58235 }), 58236 method: 'loadBytes' 58237 }; 58238 case 7: 58239 return { 58240 message: (0, _internationalization.translator) ('fes.fileLoadError.large'), 58241 method: 'loadX' 58242 }; 58243 case 8: 58244 return { 58245 message: (0, _internationalization.translator) ('fes.fileLoadError.gif'), 58246 method: 'loadImage' 58247 }; 58248 } 58249 }; 58250 /**
58251 * Called internally if there is an error during file loading. 58252 * 58253 * Generates and prints a friendly error message using key: 58254 * "fes.fileLoadError.[*]". 58255 * 58256 * @method _friendlyFileLoadError 58257 * @private 58258 * @param {Number} errorType Number of file load error type 58259 * @param {String} filePath Path to file caused the error 58260 */ 58261 _main.default._friendlyFileLoadError = function (errorType, filePath) { 58262 var _fileLoadErrorCases = fileLoadErrorCases(errorType, filePath), 58263 message = _fileLoadErrorCases.message, 58264 method = _fileLoadErrorCases.method; 58265 _main.default._friendlyError(message, method, 3); 58266 }; 58267 } 58268 var _default = _main.default; 58269 exports.default = _default; 58270 }, 58271 { 58272 '../internationalization': 288, 58273 '../main': 290 58274 } 58275 ], 58276 283: [ 58277 function (_dereq_, module, exports) { 58278 'use strict'; 58279 _dereq_('core-js/modules/es.symbol'); 58280 _dereq_('core-js/modules/es.symbol.description'); 58281 _dereq_('core-js/modules/es.symbol.iterator'); 58282 _dereq_('core-js/modules/es.array.filter'); 58283 _dereq_('core-js/modules/es.array.for-each'); 58284 _dereq_('core-js/modules/es.array.from'); 58285 _dereq_('core-js/modules/es.array.includes'); 58286 _dereq_('core-js/modules/es.array.index-of'); 58287 _dereq_('core-js/modules/es.array.iterator'); 58288 _dereq_('core-js/modules/es.array.join'); 58289 _dereq_('core-js/modules/es.array.map'); 58290 _dereq_('core-js/modules/es.array.slice'); 58291 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 58292 _dereq_('core-js/modules/es.object.keys'); 58293 _dereq_('core-js/modules/es.object.to-string'); 58294 _dereq_('core-js/modules/es.regexp.constructor'); 58295 _dereq_('core-js/modules/es.regexp.exec'); 58296 _dereq_('core-js/modules/es.regexp.to-string'); 58297 _dereq_('core-js/modules/es.string.includes'); 58298 _dereq_('core-js/modules/es.string.iterator'); 58299 _dereq_('core-js/modules/es.string.match'); 58300 _dereq_('core-js/modules/es.string.split'); 58301 _dereq_('core-js/modules/es.string.trim'); 58302 _dereq_('core-js/modules/es.weak-map'); 58303 _dereq_('core-js/modules/web.dom-collections.for-each'); 58304 _dereq_('core-js/modules/web.dom-collections.iterator'); 58305 function _typeof2(obj) { 58306 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 58307 _typeof2 = function _typeof2(obj) { 58308 return typeof obj; 58309 }; 58310 } else { 58311 _typeof2 = function _typeof2(obj) { 58312 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 58313 }; 58314 } 58315 return _typeof2(obj); 58316 } 58317 function _typeof(obj) { 58318 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 58319 _typeof = function _typeof(obj) { 58320 return _typeof2(obj); 58321 }; 58322 } else { 58323 _typeof = function _typeof(obj) { 58324 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 58325 }; 58326 } 58327 return _typeof(obj); 58328 } 58329 _dereq_('core-js/modules/es.symbol'); 58330 _dereq_('core-js/modules/es.symbol.description'); 58331 _dereq_('core-js/modules/es.symbol.iterator'); 58332 _dereq_('core-js/modules/es.array.filter'); 58333 _dereq_('core-js/modules/es.array.for-each'); 58334 _dereq_('core-js/modules/es.array.from'); 58335 _dereq_('core-js/modules/es.array.includes'); 58336 _dereq_('core-js/modules/es.array.index-of'); 58337 _dereq_('core-js/modules/es.array.iterator'); 58338 _dereq_('core-js/modules/es.array.join'); 58339 _dereq_('core-js/modules/es.array.map'); 58340 _dereq_('core-js/modules/es.array.slice'); 58341 _dereq_('core-js/modules/es.object.keys'); 58342 _dereq_('core-js/modules/es.object.to-string'); 58343 _dereq_('core-js/modules/es.regexp.constructor'); 58344 _dereq_('core-js/modules/es.regexp.exec'); 58345 _dereq_('core-js/modules/es.regexp.to-string'); 58346 _dereq_('core-js/modules/es.string.includes'); 58347 _dereq_('core-js/modules/es.string.iterator'); 58348 _dereq_('core-js/modules/es.string.match'); 58349 _dereq_('core-js/modules/es.string.split'); 58350 _dereq_('core-js/modules/es.string.trim'); 58351 _dereq_('core-js/modules/web.dom-collections.for-each'); 58352 _dereq_('core-js/modules/web.dom-collections.iterator'); 58353 Object.defineProperty(exports, '__esModule', { 58354 value: true 58355 }); 58356 exports.default = void 0; 58357 var _main = _interopRequireDefault(_dereq_('../main')); 58358 var _internationalization = _dereq_('../internationalization'); 58359 var constants = _interopRequireWildcard(_dereq_('../constants')); 58360 function _getRequireWildcardCache() { 58361 if (typeof WeakMap !== 'function') return null; 58362 var cache = new WeakMap(); 58363 _getRequireWildcardCache = function _getRequireWildcardCache() { 58364 return cache; 58365 }; 58366 return cache; 58367 } 58368 function _interopRequireWildcard(obj) { 58369 if (obj && obj.__esModule) { 58370 return obj; 58371 } 58372 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 58373 return { 58374 default: 58375 obj 58376 }; 58377 } 58378 var cache = _getRequireWildcardCache(); 58379 if (cache && cache.has(obj)) { 58380 return cache.get(obj); 58381 } 58382 var newObj = { 58383 }; 58384 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 58385 for (var key in obj) { 58386 if (Object.prototype.hasOwnProperty.call(obj, key)) { 58387 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 58388 if (desc && (desc.get || desc.set)) { 58389 Object.defineProperty(newObj, key, desc); 58390 } else { 58391 newObj[key] = obj[key]; 58392 } 58393 } 58394 } 58395 newObj.default = obj; 58396 if (cache) { 58397 cache.set(obj, newObj); 58398 } 58399 return newObj; 58400 } 58401 function _interopRequireDefault(obj) { 58402 return obj && obj.__esModule ? obj : { 58403 default: 58404 obj 58405 }; 58406 } 58407 function _toConsumableArray(arr) { 58408 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); 58409 } 58410 function _nonIterableSpread() { 58411 throw new TypeError('Invalid attempt to spread non-iterable instance'); 58412 } 58413 function _iterableToArray(iter) { 58414 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') return Array.from(iter); 58415 } 58416 function _arrayWithoutHoles(arr) { 58417 if (Array.isArray(arr)) { 58418 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 58419 arr2[i] = arr[i]; 58420 } 58421 return arr2; 58422 } 58423 } /** 58424 * Checks if any p5.js constant/function is declared outside of setup() 58425 * and draw() function. Also checks any reserved constant/function is 58426 * redeclared. 58427 * 58428 * Generates and prints a friendly error message using key: 58429 * "fes.sketchReaderErrors.reservedConst", 58430 * "fes.sketchReaderErrors.reservedFunc". 58431 * 58432 * @method _fesCodeReader 58433 * @private 58434 */ 58435 58436 if (typeof IS_MINIFIED !== 'undefined') { 58437 _main.default._fesCodeReader = function () { 58438 }; 58439 } else { 58440 //list of functions to ignore as they either 58441 //are ment to be defined or generate false positive 58442 //outputs 58443 var ignoreFunction = [ 58444 'setup', 58445 'draw', 58446 'preload', 58447 'deviceMoved', 58448 'deviceTurned', 58449 'deviceShaken', 58450 'doubleClicked', 58451 'mousePressed', 58452 'mouseReleased', 58453 'mouseMoved', 58454 'mouseDragged', 58455 'mouseClicked', 58456 'mouseWheel', 58457 'touchStarted', 58458 'touchMoved', 58459 'touchEnded', 58460 'keyPressed', 58461 'keyReleased', 58462 'keyTyped', 58463 'windowResized', 58464 'name', 58465 'parent', 58466 'toString', 58467 'print', 58468 'stop', 58469 'onended' 58470 ]; 58471 /** 58472 * Takes a list of variables defined by the user in the code 58473 * as an array and checks if the list contains p5.js constants and functions. 58474 * 58475 * @method checkForConstsAndFuncs 58476 * @private 58477 * @param {Array} variableArray 58478 */ 58479 var checkForConstsAndFuncs = function checkForConstsAndFuncs(variableArray) { 58480 for (var i = 0; i < variableArray.length; i++) { 58481 //if the element in variableArray is a p5.js constant then the below condidion 58482 //will be true, hence a match is found 58483 if (constants[variableArray[i]] !== undefined) { 58484 var url = 'https://p5js.org/reference/#/p5/'.concat(variableArray[i]); //display the FES message if a match is found 58485 _main.default._friendlyError((0, _internationalization.translator) ('fes.sketchReaderErrors.reservedConst', { 58486 url: url, 58487 symbol: variableArray[i] 58488 })); 58489 return; //if match found then end search 58490 } 58491 } 58492 var p5Constructors = { 58493 }; 58494 for (var _i = 0, _Object$keys = Object.keys(_main.default); _i < _Object$keys.length; _i++) { 58495 var key = _Object$keys[_i]; // Get a list of all constructors in p5. They are functions whose names 58496 // start with a capital letter 58497 if (typeof _main.default[key] === 'function' && key[
584970] !== key[0].toLowerCase()) { 58498 p5Constructors[key] = _main.default[key]; 58499 } 58500 } 58501 for (var _i2 = 0; _i2 < variableArray.length; _i2++) { 58502 //ignoreFunction contains the list of functions to be ignored 58503 if (!ignoreFunction.includes(variableArray[_i2])) { 58504 var keyArray = Object.keys(p5Constructors); 58505 var j = 0; //for every function name obtained check if it matches any p5.js function name 58506 for (; j < keyArray.length; j++) { 58507 if (p5Constructors[keyArray[j]].prototype[variableArray[_i2]] !== undefined) { 58508 //if a p5.js function is used ie it is in the funcs array 58509 var _url = 'https://p5js.org/reference/#/p5/'.concat(variableArray[_i2]); 58510 _main.default._friendlyError((0, _internationalization.translator) ('fes.sketchReaderErrors.reservedFunc', { 58511 url: _url, 58512 symbol: variableArray[_i2] 58513 })); 58514 return; 58515 } 58516 } 58517 } 58518 } 58519 }; //these regex are used to perform variable extraction 58520 //visit https://regexr.com/ for the detailed view 58521 var optionalVarKeyword = /(?:(?:let|const|var)\s+)?/; // Bracketed expressions start with an opening bracket, some amount of non 58522 // bracket characters, then a closing bracket. Note that this won't properly 58523 // parse nested brackets: `constrain(millis(), 0, 1000)` will match 58524 // `constrain(millis()` only, but will still fail gracefully and not try to 58525 // mistakenly read any subsequent code as assignment expressions. 58526 var roundBracketedExpr = /(?:\([^)]*\))/; 58527 var squareBracketedExpr = /(?:\[[^\]]*\])/; 58528 var curlyBracketedExpr = /(?:\{[^}]*\})/; 58529 var bracketedExpr = new RegExp([roundBracketedExpr, 58530 squareBracketedExpr, 58531 curlyBracketedExpr].map(function (regex) { 58532 return regex.source; 58533 }).join('|')); // In an a = b expression, `b` can be any character up to a newline or comma, 58534 // unless the comma is inside of a bracketed expression of some kind (to make 58535 // sure we parse function calls with multiple arguments properly.) 58536 var rightHandSide = new RegExp('(?:' + bracketedExpr.source + '|[^\\n,])+'); 58537 var leftHandSide = /([\w$]+)/; 58538 var assignmentOperator = /\s*=\s*/; 58539 var singleAssignment = new RegExp(leftHandSide.source + assignmentOperator.source + rightHandSide.source); 58540 var listSeparator = /,\s*/; 58541 var oneOrMoreAssignments = new RegExp('(?:' + singleAssignment.source + listSeparator.source + ')*' + singleAssignment.source); 58542 var assignmentStatement = new RegExp('^' + optionalVarKeyword.source + oneOrMoreAssignments.source); 58543 var letConstName = /(?:(?:let|const)\s+)([\w$]+)/; 58544 /** 58545 * Takes an array in which each element is a line of code 58546 * containing a variable definition(Eg: arr=['let x = 100', 'const y = 200']) 58547 * and extracts the variables defined. 58548 * 58549 * @method extractVariables 58550 * @private 58551 * @param {Array} linesArray array of lines of code 58552 */ 58553 var extractVariables = function extractVariables(linesArray) { 58554 //extract variable names from the user's code 58555 var matches = [ 58556 ]; 58557 linesArray.forEach(function (ele) { 58558 // Match 0 is the part of the line of code that the regex looked at. 58559 // Matches 1 and onward will be only the variable names on the left hand 58560 // side of assignment expressions. 58561 var match = ele.match(assignmentStatement); 58562 if (!match) return; 58563 matches.push.apply(matches, _toConsumableArray(match.slice(1).filter(function (group) { 58564 return group !== undefined; 58565 }))); 58566 }); //check if the obtained variables are a part of p5.js or not 58567 checkForConstsAndFuncs(matches); 58568 }; 58569 /** 58570 * Takes an array in which each element is a line of code 58571 * containing a function definition(array=['let x = () => {...}']) 58572 * and extracts the functions defined. 58573 * 58574 * @method extractFuncVariables 58575 * @private 58576 * @param {Array} linesArray array of lines of code 58577 */ 58578 var extractFuncVariables = function extractFuncVariables(linesArray) { 58579 var matches = [ 58580 ]; //RegExp to extract function names from let/const x = function()... 58581 //visit https://regexr.com/ for the detailed view. 58582 linesArray.forEach(function (ele) { 58583 var m = ele.match(letConstName); 58584 if (m !== null) matches.push(ele.match(letConstName) [1]); 58585 }); //matches array contains the names of the functions 58586 checkForConstsAndFuncs(matches); 58587 }; 58588 /** 58589 * Converts code written by the user to an array 58590 * every element of which is a seperate line of code. 58591 *
58592 * @method codeToLines 58593 * @private 58594 * @param {String} code code written by the user 58595 */ 58596 var codeToLines = function codeToLines(code) { 58597 //convert code to array of code and filter out 58598 //unnecessary lines 58599 var arrayVariables = code.split('\n').map(function (line) { 58600 return line.trim(); 58601 }).filter(function (line) { 58602 return line !== '' && !line.includes('//') && (line.includes('let') || line.includes('const')) && !line.includes('=>') && !line.includes('function'); 58603 } //filter out lines containing variable names 58604 ); //filter out lines containing function names 58605 var arrayFunctions = code.split('\n').map(function (line) { 58606 return line.trim(); 58607 }).filter(function (line) { 58608 return line !== '' && !line.includes('//') && (line.includes('let') || line.includes('const')) && (line.includes('=>') || line.includes('function')); 58609 }); //pass the relevant array to a function which will extract all the variables/functions names 58610 extractVariables(arrayVariables); 58611 extractFuncVariables(arrayFunctions); 58612 }; 58613 /** 58614 * Remove multiline comments and the content inside it. 58615 * 58616 * @method removeMultilineComments 58617 * @private 58618 * @param {String} code code written by the user 58619 * @returns {String} 58620 */ 58621 var removeMultilineComments = function removeMultilineComments(code) { 58622 var start = code.indexOf('/*'); 58623 var end = code.indexOf('*/'); //create a new string which don't have multiline comments 58624 while (start !== - 1 && end !== - 1) { 58625 if (start === 0) { 58626 code = code.slice(end + 2); 58627 } else code = code.slice(0, start) + code.slice(end + 2); 58628 start = code.indexOf('/*'); 58629 end = code.indexOf('*/'); 58630 } 58631 return code; 58632 }; 58633 /** 58634 * Checks if any p5.js constant or function is declared outside a function 58635 * and reports it if found. 58636 * 58637 * @method globalConstFuncCheck 58638 * @private 58639 * @returns {Boolean} 58640 */ 58641 var globalConstFuncCheck = function globalConstFuncCheck() { 58642 // generate all the const key data as an array 58643 var tempArray = Object.keys(constants); 58644 var element; 58645 for (var i = 0; i < tempArray.length; i++) { 58646 try { 58647 //if the user has not declared p5.js constant anywhere outside the 58648 //setup or draw function then this will throw an 58649 //error. 58650 element = eval(tempArray[i]); 58651 } catch (e) { 58652 //We are catching the error due to the above mentioned 58653 //reason. Since there is no declaration of constant everything 58654 //is OK so we will skip the current iteration and check for the 58655 //next element. 58656 continue; 58657 } //if we are not getting an error this means 58658 //user have changed the value. We will check 58659 //if the value is changed and if it is changed 58660 //then report. 58661 58662 if (constants[tempArray[i]] !== element) { 58663 var url = 'https://p5js.org/reference/#/p5/'.concat(tempArray[i]); 58664 _main.default._friendlyError((0, _internationalization.translator) ('fes.sketchReaderErrors.reservedConst', { 58665 url: url, 58666 symbol: tempArray[i] 58667 })); //if a p5.js constant is already reported then no need to check 58668 //for p5.js functions. 58669 return true; 58670 } 58671 } //the below code gets a list of p5.js functions 58672 58673 var p5Constructors = { 58674 }; 58675 for (var _i3 = 0, _Object$keys2 = Object.keys(_main.default); _i3 < _Object$keys2.length; _i3++) { 58676 var key = _Object$keys2[_i3]; // Get a list of all constructors in p5. They are functions whose names 58677 // start with a capital letter 58678 if (typeof _main.default[key] === 'function' && key[
586780] !== key[0].toLowerCase()) { 58679 p5Constructors[key] = _main.default[key]; 58680 } 58681 } 58682 var keyArray = Object.keys(p5Constructors); 58683 var functionArray = [ 58684 ]; //get the names of all p5.js functions 58685 for (var _i4 = 0; _i4 < keyArray.length; _i4++) { 58686 var _functionArray; 58687 (_functionArray = functionArray).push.apply(_functionArray, _toConsumableArray(Object.keys(p5Constructors[keyArray[_i4]].prototype))); 58688 } 58689 functionArray = functionArray.filter(function (ele) { 58690 return !ele.includes('_'); 58691 }); //we have p5.js function names with us so we will check 58692 //if they have been declared or not. 58693 for (var _i5 = 0; _i5 < functionArray.length; _i5++) { 58694 //ignoreFunction contains the list of functions to be ignored 58695 if (!ignoreFunction.includes(functionArray[_i5])) { 58696 try { 58697 //if we get an error that means the function is not declared 58698 element = eval(functionArray[_i5]); 58699 } catch (e) { 58700 //we will skip the iteration 58701 continue; 58702 } //if we are not getting an error this means 58703 //user have used p5.js function. Check if it is 58704 //changed and if so then report it. 58705 58706 for (var k = 0; k < keyArray.length; k++) { 58707 if (p5Constructors[keyArray[k]].prototype[functionArray[_i5]] === undefined); 58708 else { 58709 if (p5Constructors[keyArray[k]].prototype[functionArray[_i5]] !== element) { 58710 var _url2 = 'https://p5js.org/reference/#/p5/'.concat(functionArray[_i5]); 58711 _main.default._friendlyError((0, _internationalization.translator) ('fes.sketchReaderErrors.reservedFunc', { 58712 url: _url2, 58713 symbol: functionArray[_i5] 58714 })); 58715 return true; 58716 } 58717 } 58718 } 58719 } 58720 } 58721 }; 58722 /** 58723 * Initiates the sketch_reader's processes. 58724 * Obtains the code in setup and draw function 58725 * and forwards it for further processing and evaluation. 58726 * 58727 * @method fesCodeReader 58728 * @private 58729 */ 58730 var fesCodeReader = function fesCodeReader() { 58731 //moveAhead will determine if a match is found outside 58732 //the setup and draw function. If a match is found then 58733 //to prevent further potential reporting we will exit immidiately 58734 var moveAhead = globalConstFuncCheck(); 58735 if (moveAhead) return; 58736 var code = ''; 58737 try { 58738 //get code from setup 58739 code += '' + setup; 58740 } catch (e) { 58741 code += ''; 58742 } 58743 try { 58744 //get code from draw 58745 code += '\n' + draw; 58746 } catch (e) { 58747 code += ''; 58748 } 58749 if (code === '') return; 58750 code = removeMultilineComments(code); 58751 codeToLines(code); 58752 }; 58753 _main.default._fesCodeReader = fesCodeReader; 58754 window.addEventListener('load', _main.default._fesCodeReader); 58755 } 58756 var _default = _main.default; 58757 exports.default = _default; 58758 }, 58759 { 58760 '../constants': 278, 58761 '../internationalization': 288, 58762 '../main': 290, 58763 'core-js/modules/es.array.filter': 171, 58764 'core-js/modules/es.array.for-each': 172, 58765 'core-js/modules/es.array.from': 173, 58766 'core-js/modules/es.array.includes': 174, 58767 'core-js/modules/es.array.index-of': 175, 58768 'core-js/modules/es.array.iterator': 176, 58769 'core-js/modules/es.array.join': 177, 58770 'core-js/modules/es.array.map': 179, 58771 'core-js/modules/es.array.slice': 180, 58772 'core-js/modules/es.object.get-own-property-descriptor': 191, 58773 'core-js/modules/es.object.keys': 194, 58774 'core-js/modules/es.object.to-string': 195, 58775 'core-js/modules/es.regexp.constructor': 198, 58776 'core-js/modules/es.regexp.exec': 199, 58777 'core-js/modules/es.regexp.to-string': 200, 58778 'core-js/modules/es.string.includes': 203, 58779 'core-js/modules/es.string.iterator': 204, 58780 'core-js/modules/es.string.match': 205, 58781 'core-js/modules/es.string.split': 209, 58782 'core-js/modules/es.string.trim': 211, 58783 'core-js/modules/es.symbol': 214, 58784 'core-js/modules/es.symbol.description': 212, 58785 'core-js/modules/es.symbol.iterator': 213, 58786 'core-js/modules/es.weak-map': 246, 58787 'core-js/modules/web.dom-collections.for-each': 247, 58788 'core-js/modules/web.dom-collections.iterator': 248 58789 } 58790 ], 58791 284: [
58792 function (_dereq_, module, exports) { 58793 'use strict'; 58794 _dereq_('core-js/modules/es.array.filter'); 58795 _dereq_('core-js/modules/es.array.index-of'); 58796 _dereq_('core-js/modules/es.array.join'); 58797 _dereq_('core-js/modules/es.array.map'); 58798 _dereq_('core-js/modules/es.array.slice'); 58799 _dereq_('core-js/modules/es.regexp.exec'); 58800 _dereq_('core-js/modules/es.string.match'); 58801 _dereq_('core-js/modules/es.string.replace'); 58802 _dereq_('core-js/modules/es.string.split'); 58803 _dereq_('core-js/modules/es.array.filter'); 58804 _dereq_('core-js/modules/es.array.index-of'); 58805 _dereq_('core-js/modules/es.array.join'); 58806 _dereq_('core-js/modules/es.array.map'); 58807 _dereq_('core-js/modules/es.array.slice'); 58808 _dereq_('core-js/modules/es.regexp.exec'); 58809 _dereq_('core-js/modules/es.string.match'); 58810 _dereq_('core-js/modules/es.string.replace'); 58811 _dereq_('core-js/modules/es.string.split'); 58812 Object.defineProperty(exports, '__esModule', { 58813 value: true 58814 }); 58815 exports.default = void 0; 58816 var _main = _interopRequireDefault(_dereq_('../main')); 58817 function _interopRequireDefault(obj) { 58818 return obj && obj.__esModule ? obj : { 58819 default: 58820 obj 58821 }; 58822 } /** 58823 * @for p5 58824 * @requires core 58825 */ 58826 // Borrow from stacktracejs https://github.com/stacktracejs/stacktrace.js with 58827 // minor modifications. The license for the same and the code is included below 58828 // Copyright (c) 2017 Eric Wendelin and other contributors 58829 // Permission is hereby granted, free of charge, to any person obtaining a copy of 58830 // this software and associated documentation files (the "Software"), to deal in 58831 // the Software without restriction, including without limitation the rights to 58832 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 58833 // of the Software, and to permit persons to whom the Software is furnished to do 58834 // so, subject to the following conditions: 58835 // The above copyright notice and this permission notice shall be included in all 58836 // copies or substantial portions of the Software. 58837 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 58838 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 58839 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 58840 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58841 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58842 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 58843 // SOFTWARE. 58844 58845 function ErrorStackParser() { 58846 'use strict'; 58847 var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/; 58848 var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m; 58849 var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/; 58850 return { 58851 /** 58852 * Given an Error object, extract the most information from it. 58853 * @private 58854 * @param {Error} error object 58855 * @return {Array} of stack frames 58856 */ 58857 parse: function ErrorStackParser$$parse(error) { 58858 if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { 58859 return this.parseOpera(error); 58860 } else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { 58861 return this.parseV8OrIE(error); 58862 } else if (error.stack) { 58863 return this.parseFFOrSafari(error); 58864 } else { // throw new Error('Cannot parse given Error object'); 58865 } 58866 }, 58867 // Separate line and column numbers from a string of the form: (URI:Line:Column) 58868 extractLocation: function ErrorStackParser$$extractLocation(urlLike) { 58869 // Fail-fast but return locations like "(native)" 58870 if (urlLike.indexOf(':') === - 1) { 58871 return [urlLike]; 58872 } 58873 var regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/; 58874 var parts = regExp.exec(urlLike.replace(/[()]/g, '')); 58875 return [parts[1], 58876 parts[2] || undefined, 58877 parts[3] || undefined]; 58878 }, 58879 parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { 58880 var filtered = error.stack.split('\n').filter(function (line) { 58881 return !!line.match(CHROME_IE_STACK_REGEXP); 58882 }, this); 58883 return filtered.map(function (line) { 58884 if (line.indexOf('(eval ') > - 1) { 58885 // Throw away eval information until we implement stacktrace.js/stackframe#8 58886 line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^()]*)|(\),.*$)/g, ''); 58887 } 58888 var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '('); // capture and preseve the parenthesized location "(/foo/my bar.js:12:87)" in 58889 // case it has spaces in it, as the string is split on \s+ later on 58890 var location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/); // remove the parenthesized location from the line, if it was matched 58891 sanitizedLine = location ? sanitizedLine.replace(location[0], '') : sanitizedLine; 58892 var tokens = sanitizedLine.split(/\s+/).slice(1); // if a location was matched, pass it to extractLocation() otherwise pop the last token 58893 var locationParts = this.extractLocation(location ? location[1] : tokens.pop()); 58894 var functionName = tokens.join(' ') || undefined; 58895 var fileName = [ 58896 'eval', 58897 '<anonymous>' 58898 ].indexOf(locationParts[0]) > - 1 ? undefined : locationParts[0]; 58899 return { 58900 functionName: functionName, 58901 fileName: fileName, 58902 lineNumber: locationParts[1], 58903 columnNumber: locationParts[2], 58904 source: line 58905 }; 58906 }, this); 58907 }, 58908 parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { 58909 var filtered = error.stack.split('\n').filter(function (line) { 58910 return !line.match(SAFARI_NATIVE_CODE_REGEXP); 58911 }, this); 58912 return filtered.map(function (line) { 58913 // Throw away eval information until we implement stacktrace.js/stackframe#8 58914 if (line.indexOf(' > eval') > - 1) { 58915 line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ':$1'); 58916 } 58917 if (line.indexOf('@') === - 1 && line.indexOf(':') === - 1) { 58918 // Safari eval frames only have function names and nothing else 58919 return { 58920 functionName: line 58921 }; 58922 } else { 58923 var functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/; 58924 var matches = line.match(functionNameRegex); 58925 var functionName = matches && matches[1] ? matches[1] : undefined; 58926 var locationParts = this.extractLocation(line.replace(functionNameRegex, '')); 58927 return { 58928 functionName: functionName, 58929 fileName: locationParts[0], 58930 lineNumber: locationParts[1], 58931 columnNumber: locationParts[2], 58932 source: line 58933 }; 58934 } 58935 }, this); 58936 }, 58937 parseOpera: function ErrorStackParser$$parseOpera(e) { 58938 if (!e.stacktrace || e.message.indexOf('\n') > - 1 && e.message.split('\n').length > e.stacktrace.split('\n').length) { 58939 return this.parseOpera9(e); 58940 } else if (!e.stack) { 58941 return this.parseOpera10(e); 58942 } else { 58943 return this.parseOpera11(e); 58944 } 58945 }, 58946 parseOpera9: function ErrorStackParser$$parseOpera9(e) { 58947 var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; 58948 var lines = e.message.split('\n'); 58949 var result = [ 58950 ]; 58951 for (var i = 2, len = lines.length; i < len; i += 2) { 58952 var match = lineRE.exec(lines[i]); 58953 if (match) { 58954 result.push({ 58955 fileName: match[2], 58956 lineNumber: match[1], 58957 source: lines[i] 58958 }); 58959 } 58960 } 58961 return result; 58962 }, 58963 parseOpera10: function ErrorStackParser$$parseOpera10(e) { 58964 var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; 58965 var lines = e.stacktrace.split('\n'); 58966 var result = [ 58967 ]; 58968 for (var i = 0, len = lines.length; i < len; i += 2) { 58969 var match = lineRE.exec(lines[i]); 58970 if (match) { 58971 result.push({ 58972 functionName: match[3] || undefined, 58973 fileName: match[2], 58974 lineNumber: match[1], 58975 source: lines[i] 58976 }); 58977 } 58978 } 58979 return result; 58980 }, 58981 // Opera 10.65+ Error.stack very similar to FF/Safari 58982 parseOpera11: function ErrorStackParser$$parseOpera11(error) { 58983 var filtered = error.stack.split('\n').filter(function (line) { 58984 return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); 58985 }, this); 58986 return filtered.map(function (line) { 58987 var tokens = line.split('@'); 58988 var locationParts = this.extractLocation(tokens.pop()); 58989 var functionCall = tokens.shift() || ''; 58990 var functionName = functionCall.replace(/<anonymous function(: (\w+))?>/, '$2').replace(/\([^)]*\)/g, '') || undefined; 58991 var argsRaw; 58992 if (functionCall.match(/\(([^)]*)\)/)) { 58993 argsRaw = functionCall.replace(/^[^(]+\(([^)]*)\)$/, '$1'); 58994 } 58995 var args = argsRaw === undefined || argsRaw === '[arguments not available]' ? undefined : argsRaw.split(','); 58996 return { 58997 functionName: functionName, 58998 args: args, 58999 fileName: locationParts[0], 59000 lineNumber: locationParts[1], 59001 columnNumber: locationParts[2], 59002 source: line 59003 }; 59004 }, this); 59005 } 59006 }; 59007 } // End borrow 59008 // wrapper exposing ErrorStackParser 59009 59010 _main.default._getErrorStackParser = function getErrorStackParser() { 59011 return new ErrorStackParser(); 59012 }; 59013 var _default = _main.default; 59014 exports.default = _default; 59015 }, 59016 { 59017 '../main': 290, 59018 'core-js/modules/es.array.filter': 171, 59019 'core-js/modules/es.array.index-of': 175, 59020 'core-js/modules/es.array.join': 177, 59021 'core-js/modules/es.array.map': 179, 59022 'core-js/modules/es.array.slice': 180, 59023 'core-js/modules/es.regexp.exec': 199, 59024 'core-js/modules/es.string.match': 205, 59025 'core-js/modules/es.string.replace': 207, 59026 'core-js/modules/es.string.split': 209 59027 } 59028 ], 59029 285: [
59030 function (_dereq_, module, exports) { 59031 'use strict'; 59032 _dereq_('core-js/modules/es.symbol'); 59033 _dereq_('core-js/modules/es.symbol.description'); 59034 _dereq_('core-js/modules/es.symbol.iterator'); 59035 _dereq_('core-js/modules/es.array.concat'); 59036 _dereq_('core-js/modules/es.array.for-each'); 59037 _dereq_('core-js/modules/es.array.includes'); 59038 _dereq_('core-js/modules/es.array.index-of'); 59039 _dereq_('core-js/modules/es.array.iterator'); 59040 _dereq_('core-js/modules/es.array.join'); 59041 _dereq_('core-js/modules/es.array.last-index-of'); 59042 _dereq_('core-js/modules/es.array.map'); 59043 _dereq_('core-js/modules/es.array.slice'); 59044 _dereq_('core-js/modules/es.function.name'); 59045 _dereq_('core-js/modules/es.map'); 59046 _dereq_('core-js/modules/es.number.constructor'); 59047 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 59048 _dereq_('core-js/modules/es.object.get-prototype-of'); 59049 _dereq_('core-js/modules/es.object.keys'); 59050 _dereq_('core-js/modules/es.object.to-string'); 59051 _dereq_('core-js/modules/es.reflect.construct'); 59052 _dereq_('core-js/modules/es.regexp.exec'); 59053 _dereq_('core-js/modules/es.regexp.to-string'); 59054 _dereq_('core-js/modules/es.set'); 59055 _dereq_('core-js/modules/es.string.includes'); 59056 _dereq_('core-js/modules/es.string.iterator'); 59057 _dereq_('core-js/modules/es.string.split'); 59058 _dereq_('core-js/modules/es.weak-map'); 59059 _dereq_('core-js/modules/web.dom-collections.for-each'); 59060 _dereq_('core-js/modules/web.dom-collections.iterator'); 59061 function _typeof2(obj) { 59062 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 59063 _typeof2 = function _typeof2(obj) { 59064 return typeof obj; 59065 }; 59066 } else { 59067 _typeof2 = function _typeof2(obj) { 59068 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 59069 }; 59070 } 59071 return _typeof2(obj); 59072 } 59073 _dereq_('core-js/modules/es.symbol'); 59074 _dereq_('core-js/modules/es.symbol.description'); 59075 _dereq_('core-js/modules/es.symbol.iterator'); 59076 _dereq_('core-js/modules/es.array.concat'); 59077 _dereq_('core-js/modules/es.array.for-each'); 59078 _dereq_('core-js/modules/es.array.includes'); 59079 _dereq_('core-js/modules/es.array.index-of'); 59080 _dereq_('core-js/modules/es.array.iterator'); 59081 _dereq_('core-js/modules/es.array.join'); 59082 _dereq_('core-js/modules/es.array.last-index-of'); 59083 _dereq_('core-js/modules/es.array.map'); 59084 _dereq_('core-js/modules/es.array.slice'); 59085 _dereq_('core-js/modules/es.function.name'); 59086 _dereq_('core-js/modules/es.map'); 59087 _dereq_('core-js/modules/es.number.constructor'); 59088 _dereq_('core-js/modules/es.object.get-prototype-of'); 59089 _dereq_('core-js/modules/es.object.keys'); 59090 _dereq_('core-js/modules/es.object.to-string'); 59091 _dereq_('core-js/modules/es.reflect.construct'); 59092 _dereq_('core-js/modules/es.regexp.exec'); 59093 _dereq_('core-js/modules/es.regexp.to-string'); 59094 _dereq_('core-js/modules/es.set'); 59095 _dereq_('core-js/modules/es.string.includes'); 59096 _dereq_('core-js/modules/es.string.iterator'); 59097 _dereq_('core-js/modules/es.string.split'); 59098 _dereq_('core-js/modules/web.dom-collections.for-each'); 59099 _dereq_('core-js/modules/web.dom-collections.iterator'); 59100 Object.defineProperty(exports, '__esModule', { 59101 value: true 59102 }); 59103 exports.default = void 0; 59104 var _main = _interopRequireDefault(_dereq_('../main')); 59105 var constants = _interopRequireWildcard(_dereq_('../constants')); 59106 var _internationalization = _dereq_('../internationalization'); 59107 function _getRequireWildcardCache() { 59108 if (typeof WeakMap !== 'function') return null; 59109 var cache = new WeakMap(); 59110 _getRequireWildcardCache = function _getRequireWildcardCache() { 59111 return cache; 59112 }; 59113 return cache; 59114 } 59115 function _interopRequireWildcard(obj) { 59116 if (obj && obj.__esModule) { 59117 return obj; 59118 } 59119 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 59120 return { 59121 default: 59122 obj 59123 }; 59124 } 59125 var cache = _getRequireWildcardCache(); 59126 if (cache && cache.has(obj)) { 59127 return cache.get(obj); 59128 } 59129 var newObj = { 59130 }; 59131 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 59132 for (var key in obj) { 59133 if (Object.prototype.hasOwnProperty.call(obj, key)) { 59134 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 59135 if (desc && (desc.get || desc.set)) { 59136 Object.defineProperty(newObj, key, desc); 59137 } else { 59138 newObj[key] = obj[key]; 59139 } 59140 } 59141 } 59142 newObj.default = obj; 59143 if (cache) { 59144 cache.set(obj, newObj); 59145 } 59146 return newObj; 59147 } 59148 function _interopRequireDefault(obj) { 59149 return obj && obj.__esModule ? obj : { 59150 default: 59151 obj 59152 }; 59153 } 59154 function _classCallCheck(instance, Constructor) { 59155 if (!(instance instanceof Constructor)) { 59156 throw new TypeError('Cannot call a class as a function'); 59157 } 59158 } 59159 function _inherits(subClass, superClass) { 59160 if (typeof superClass !== 'function' && superClass !== null) { 59161 throw new TypeError('Super expression must either be null or a function'); 59162 } 59163 subClass.prototype = Object.create(superClass && superClass.prototype, { 59164 constructor: { 59165 value: subClass, 59166 writable: true, 59167 configurable: true 59168 } 59169 }); 59170 if (superClass) _setPrototypeOf(subClass, superClass); 59171 } 59172 function _createSuper(Derived) { 59173 function isNativeReflectConstruct() { 59174 if (typeof Reflect === 'undefined' || !Reflect.construct) return false;
vendor: 4,492 bytes, lines 59175-59289
59175 if (Reflect.construct.sham) return false; 59176 if (typeof Proxy === 'function') return true; 59177 try { 59178 Date.prototype.toString.call(Reflect.construct(Date, [ 59179 ], function () { 59180 })); 59181 return true; 59182 } catch (e) { 59183 return false; 59184 } 59185 } 59186 return function () { 59187 var Super = _getPrototypeOf(Derived), 59188 result; 59189 if (isNativeReflectConstruct()) { 59190 var NewTarget = _getPrototypeOf(this).constructor; 59191 result = Reflect.construct(Super, arguments, NewTarget); 59192 } else { 59193 result = Super.apply(this, arguments); 59194 } 59195 return _possibleConstructorReturn(this, result); 59196 }; 59197 } 59198 function _possibleConstructorReturn(self, call) { 59199 if (call && (_typeof(call) === 'object' || typeof call === 'function')) { 59200 return call; 59201 } 59202 return _assertThisInitialized(self); 59203 } 59204 function _assertThisInitialized(self) { 59205 if (self === void 0) { 59206 throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called'); 59207 } 59208 return self; 59209 } 59210 function _wrapNativeSuper(Class) { 59211 var _cache = typeof Map === 'function' ? new Map() : undefined; 59212 _wrapNativeSuper = function _wrapNativeSuper(Class) { 59213 if (Class === null || !_isNativeFunction(Class)) return Class; 59214 if (typeof Class !== 'function') { 59215 throw new TypeError('Super expression must either be null or a function'); 59216 } 59217 if (typeof _cache !== 'undefined') { 59218 if (_cache.has(Class)) return _cache.get(Class); 59219 _cache.set(Class, Wrapper); 59220 } 59221 function Wrapper() { 59222 return _construct(Class, arguments, _getPrototypeOf(this).constructor); 59223 } 59224 Wrapper.prototype = Object.create(Class.prototype, { 59225 constructor: { 59226 value: Wrapper, 59227 enumerable: false, 59228 writable: true, 59229 configurable: true 59230 } 59231 }); 59232 return _setPrototypeOf(Wrapper, Class); 59233 }; 59234 return _wrapNativeSuper(Class); 59235 } 59236 function isNativeReflectConstruct() { 59237 if (typeof Reflect === 'undefined' || !Reflect.construct) return false; 59238 if (Reflect.construct.sham) return false; 59239 if (typeof Proxy === 'function') return true; 59240 try { 59241 Date.prototype.toString.call(Reflect.construct(Date, [ 59242 ], function () { 59243 })); 59244 return true; 59245 } catch (e) { 59246 return false; 59247 } 59248 } 59249 function _construct(Parent, args, Class) { 59250 if (isNativeReflectConstruct()) { 59251 _construct = Reflect.construct; 59252 } else { 59253 _construct = function _construct(Parent, args, Class) { 59254 var a = [ 59255 null 59256 ]; 59257 a.push.apply(a, args); 59258 var Constructor = Function.bind.apply(Parent, a); 59259 var instance = new Constructor(); 59260 if (Class) _setPrototypeOf(instance, Class.prototype); 59261 return instance; 59262 }; 59263 } 59264 return _construct.apply(null, arguments); 59265 } 59266 function _isNativeFunction(fn) { 59267 return Function.toString.call(fn).indexOf('[native code]') !== - 1; 59268 } 59269 function _setPrototypeOf(o, p) { 59270 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { 59271 o.__proto__ = p; 59272 return o; 59273 }; 59274 return _setPrototypeOf(o, p); 59275 } 59276 function _getPrototypeOf(o) { 59277 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { 59278 return o.__proto__ || Object.getPrototypeOf(o); 59279 }; 59280 return _getPrototypeOf(o); 59281 } 59282 function _typeof(obj) { 59283 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 59284 _typeof = function _typeof(obj) { 59285 return _typeof2(obj); 59286 }; 59287 } else { 59288 _typeof = function _typeof(obj) { 59289 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
59289ypeof2(obj); 59290 }; 59291 } 59292 return _typeof(obj); 59293 } 59294 if (typeof IS_MINIFIED !== 'undefined') { 59295 _main.default._validateParameters = _main.default._clearValidateParamsCache = function () { 59296 }; 59297 } else { 59298 // for parameter validation 59299 var dataDoc = _dereq_('../../../docs/parameterData.json'); 59300 var arrDoc = JSON.parse(JSON.stringify(dataDoc)); 59301 var docCache = { 59302 }; 59303 var builtinTypes = new Set(['null', 59304 'number', 59305 'string', 59306 'boolean', 59307 'constant', 59308 'function', 59309 'any', 59310 'integer']); 59311 var basicTypes = { 59312 number: true, 59313 boolean: true, 59314 string: true, 59315 function : true, 59316 undefined: true 59317 }; // reverse map of all constants 59318 var constantsReverseMap = { 59319 }; 59320 for (var key in constants) { 59321 constantsReverseMap[constants[key]] = key; 59322 } // mapping names of p5 types to their constructor function 59323 // p5Constructors: 59324 // - Color: f() 59325 // - Graphics: f() 59326 // - Vector: f() 59327 // and so on 59328 59329 var p5Constructors = { 59330 }; // For speedup over many runs. funcSpecificConstructors[func] only has the 59331 // constructors for types which were seen earlier as args of "func" 59332 var funcSpecificConstructors = { 59333 }; 59334 window.addEventListener('load', function () { 59335 // Make a list of all p5 classes to be used for argument validation 59336 // This must be done only when everything has loaded otherwise we get 59337 // an empty array 59338 for (var _i = 0, _Object$keys = Object.keys(_main.default); _i < _Object$keys.length; _i++) { 59339 var _key = _Object$keys[_i]; // Get a list of all constructors in p5. They are functions whose names 59340 // start with a capital letter 59341 if (typeof _main.default[_key] === 'function' && _key[0] !== _key[0].toLowerCase()) { 59342 p5Constructors[_key] = _main.default[_key]; 59343 } 59344 } 59345 }); 59346 var argumentTree = { 59347 }; // The following two functions are responsible for querying and inserting 59348 // into the argument tree. It stores the types of arguments that each 59349 // function has seen so far. It is used to query if a sequence of 59350 // arguments seen in validate parameters was seen before. 59351 // Lets consider that the following segment of code runs repeatedly, perhaps 59352 // in a loop or in draw() 59353 // color(10, 10, 10); 59354 // color(10, 10); 59355 // color('r', 'g', 'b'); 59356 // After the first of run the code segment, the argument tree looks like 59357 // - color 59358 // - number 59359 // - number 59360 // - number 59361 // - seen: true 59362 // - seen: true 59363 // - string 59364 // - string 59365 // - string 59366 // - seen: true 59367 // seen: true signifies that this argument was also seen as the last 59368 // argument in a call. Now in the second run of the sketch, it would traverse 59369 // the existing tree and see seen: true, i.e this sequence was seen 59370 // before and so scoring can be skipped. This also prevents logging multiple 59371 // validation messages for the same thing. 59372 /** 59373 * Query type and return the result as an object 59374 * 59375 * This would be called repeatedly over and over again, 59376 * so it needs to be as optimized for performance as possible 59377 * @method addType 59378 * @private 59379 */ 59380 var addType = function addType(value, obj, func) { 59381 var type = _typeof(value); 59382 if (basicTypes[type]) { 59383 if (constantsReverseMap[value]) { 59384 // check if the value is a p5 constant and if it is, we would want the 59385 // value itself to be stored in the tree instead of the type 59386 obj = obj[value] || (obj[value] = { 59387 }); 59388 } else { 59389 obj = obj[type] || (obj[type] = { 59390 }); 59391 } 59392 } else if (value === null) { 59393 // typeof null -> "object". don't want that 59394 obj = obj['null'] || (obj['null'] = { 59395 }); 59396 } else { 59397 // objects which are instances of p5 classes have nameless constructors. 59398 // native objects have a constructor named "Object". This check 59399 // differentiates between the two so that we dont waste time finding the 59400 // p5 class if we just have a native object 59401 if (value.constructor && value.constructor.name) {
59402 obj = obj[value.constructor.name] || (obj[value.constructor.name] = { 59403 }); 59404 return obj; 59405 } // constructors for types defined in p5 do not have a name property. 59406 // e.constructor.name gives "". Code in this segment is a workaround for it 59407 // p5C will only have the name: constructor mapping for types 59408 // which were already seen as args of "func" 59409 59410 var p5C = funcSpecificConstructors[func]; // p5C would contain much fewer items than p5Constructors. if we find our 59411 // answer in p5C, we don't have to scan through p5Constructors 59412 if (p5C === undefined) { 59413 // if there isn't an entry yet for func 59414 // make an entry of empty object 59415 p5C = funcSpecificConstructors[func] = { 59416 }; 59417 } 59418 for (var _key2 in p5C) { 59419 // search on the constructors we have already seen (smaller search space) 59420 if (value instanceof p5C[_key2]) {
59421 obj = obj[_key2] || (obj[_key2] = { 59422 }); 59423 return obj; 59424 } 59425 } 59426 for (var _key3 in p5Constructors) { 59427 // if the above search didn't work, search on all p5 constructors 59428 if (value instanceof p5Constructors[_key3]) { 59429 obj = obj[_key3] || (obj[_key3] = { 59430 }); // if found, add to known constructors for this function 59431 p5C[_key3] = p5Constructors[_key3]; 59432 return obj; 59433 } 59434 } // nothing worked, put the type as is 59435 59436 obj = obj[type] || (obj[type] = { 59437 }); 59438 } 59439 return obj; 59440 }; 59441 /** 59442 * Build the argument type tree, argumentTree 59443 * 59444 * This would be called repeatedly over and over again, 59445 * so it needs to be as optimized for performance as possible 59446 * @method buildArgTypeCache 59447 * @private 59448 */ 59449 var buildArgTypeCache = function buildArgTypeCache(func, arr) { 59450 // get the if an argument tree for current function already exists 59451 var obj = argumentTree[func]; 59452 if (obj === undefined) { 59453 // if it doesn't, create an empty tree 59454 obj = argumentTree[func] = { 59455 }; 59456 } 59457 for (var i = 0, len = arr.length; i < len; ++i) { 59458 var value = arr[i]; 59459 if (value instanceof Array) { 59460 // an array is passed as an argument, expand it and get the type of 59461 // each of its element. We distinguish the start of an array with 'as' 59462 // or arraystart. This would help distinguish between the arguments 59463 // (number, number, number) and (number, [number, number]) 59464 obj = obj['as'] || (obj['as'] = { 59465 }); 59466 for (var j = 0, lenA = value.length; j < lenA; ++j) { 59467 obj = addType(value[j], obj, func); 59468 } 59469 } else { 59470 obj = addType(value, obj, func); 59471 } 59472 } 59473 return obj; 59474 }; 59475 /** 59476 * Query data.json 59477 * This is a helper function for validateParameters() 59478 * @method lookupParamDoc 59479 * @private 59480 */ 59481 var lookupParamDoc = function lookupParamDoc(func) { 59482 // look for the docs in the `data.json` datastructure 59483 var ichDot = func.lastIndexOf('.'); 59484 var funcName = func.slice(ichDot + 1); 59485 var funcClass = func.slice(0, ichDot !== - 1 ? ichDot : 0) || 'p5'; 59486 var classitems = arrDoc; 59487 var queryResult = classitems[funcClass][funcName]; // different JSON structure for funct with multi-format 59488 var overloads = [ 59489 ]; 59490 if (queryResult.hasOwnProperty('overloads')) { 59491 // add all the overloads 59492 for (var i = 0; i < queryResult.overloads.length; i++) { 59493 overloads.push({ 59494 formats: queryResult.overloads[i].params 59495 }); 59496 } 59497 } else { 59498 // no overloads, just add the main method definition 59499 overloads.push({ 59500 formats: queryResult.params || [ 59501 ] 59502 }); 59503 } // parse the parameter types for each overload 59504 59505 var mapConstants = { 59506 }; 59507 var maxParams = 0; 59508 overloads.forEach(function (overload) { 59509 var formats = overload.formats; // keep a record of the maximum number of arguments 59510 // this method requires. 59511 if (maxParams < formats.length) { 59512 maxParams = formats.length; 59513 } // calculate the minimum number of arguments 59514 // this overload requires. 59515 59516 var minParams = formats.length; 59517 while (minParams > 0 && formats[minParams - 1].optional) { 59518 minParams--; 59519 } 59520 overload.minParams = minParams; // loop through each parameter position, and parse its types
59521 formats.forEach(function (format) { 59522 // split this parameter's types 59523 format.types = format.type.split('|').map(function ct(type) { 59524 // array 59525 if (type.slice( - 2) === '[]') { 59526 return { 59527 name: type, 59528 array: ct(type.slice(0, - 2)) 59529 }; 59530 } 59531 var lowerType = type.toLowerCase(); // contant 59532 if (lowerType === 'constant') { 59533 var constant; 59534 if (mapConstants.hasOwnProperty(format.name)) { 59535 constant = mapConstants[format.name]; 59536 } else { 59537 // parse possible constant values from description 59538 var myRe = /either\s+(?:[A-Z0-9_]+\s*,?\s*(?:or)?\s*)+/g; 59539 var values = { 59540 }; 59541 var names = [ 59542 ]; 59543 constant = mapConstants[format.name] = { 59544 values: values, 59545 names: names 59546 }; 59547 var myArray = myRe.exec(format.description); 59548 if (func === 'endShape' && format.name === 'mode') { 59549 values[constants.CLOSE] = true; 59550 names.push('CLOSE'); 59551 } else { 59552 var match = myArray[0]; 59553 var reConst = /[A-Z0-9_]+/g; 59554 var matchConst; 59555 while ((matchConst = reConst.exec(match)) !== null) { 59556 var name = matchConst[0]; 59557 if (constants.hasOwnProperty(name)) { 59558 values[constants[name]] = true; 59559 names.push(name); 59560 } 59561 } 59562 } 59563 } 59564 return { 59565 name: type, 59566 builtin: lowerType, 59567 names: constant.names, 59568 values: constant.values 59569 }; 59570 } // function 59571 59572 if (lowerType.slice(0, 'function'.length) === 'function') { 59573 lowerType = 'function'; 59574 } // builtin 59575 59576 if (builtinTypes.has(lowerType)) { 59577 return { 59578 name: type, 59579 builtin: lowerType 59580 }; 59581 } // find type's prototype 59582 59583 var t = window; 59584 var typeParts = type.split('.'); // special-case 'p5' since it may be non-global 59585 if (typeParts[0] === 'p5') { 59586 t = _main.default; 59587 typeParts.shift(); 59588 } 59589 typeParts.forEach(function (p) { 59590 t = t && t[p]; 59591 }); 59592 if (t) { 59593 return { 59594 name: type, 59595 prototype: t 59596 }; 59597 } 59598 return { 59599 name: type, 59600 type: lowerType 59601 }; 59602 }); 59603 }); 59604 }); 59605 return { 59606 overloads: overloads, 59607 maxParams: maxParams 59608 }; 59609 }; 59610 /** 59611 * Checks whether input type is Number 59612 * This is a helper function for validateParameters() 59613 * @method isNumber 59614 * @private 59615 * 59616 * @returns {String} a string indicating the type 59617 */ 59618 var isNumber = function isNumber(param) { 59619 switch (_typeof(param)) { 59620 case 'number': 59621 return true; 59622 case 'string': 59623 return !isNaN(param); 59624 default: 59625 return false; 59626 } 59627 }; 59628 /** 59629 * Test type for non-object type parameter validation 59630 * @method testParamType 59631 * @private 59632 */ 59633 var testParamType = function testParamType(param, type) { 59634 var isArray = param instanceof Array; 59635 var matches = true; 59636 if (type.array && isArray) { 59637 for (var i = 0; i < param.length; i++) { 59638 var error = testParamType(param[i], type.array); 59639 if (error) return error / 2; // half error for elements 59640 } 59641 } else if (type.prototype) { 59642 matches = param instanceof type.prototype; 59643 } else if (type.builtin) { 59644 switch (type.builtin) { 59645 case 'number': 59646 matches = isNumber(param); 59647 break; 59648 case 'integer': 59649 matches = isNumber(param) && Number(param) === Math.floor(param); 59650 break; 59651 case 'boolean': 59652 case 'any': 59653 matches = true; 59654 break; 59655 case 'array': 59656 matches = isArray; 59657 break; 59658 case 'string': 59659 matches = /*typeof param === 'number' ||*/ 59660 typeof param === 'string'; 59661 break; 59662 case 'constant': 59663 matches = type.values.hasOwnProperty(param); 59664 break; 59665 case 'function': 59666 matches = param instanceof Function; 59667 break; 59668 case 'null': 59669 matches = param === null; 59670 break; 59671 } 59672 } else { 59673 matches = _typeof(param) === type.t; 59674 } 59675 return matches ? 0 : 1; 59676 }; 59677 /** 59678 * Test type for multiple parameters 59679 * @method testParamTypes 59680 * @private 59681 */ 59682 var testParamTypes = function testParamTypes(param, types) { 59683 var minScore = 9999; 59684 for (var i = 0; minScore > 0 && i < types.length; i++) { 59685 var score = testParamType(param, types[i]); 59686 if (minScore > score) minScore = score; 59687 } 59688 return minScore; 59689 }; 59690 /** 59691 * generate a score (higher is worse) for applying these args to 59692 * this overload. 59693 * @method scoreOverload 59694 * @private 59695 */ 59696 var scoreOverload = function scoreOverload(args, argCount, overload, minScore) { 59697 var score = 0; 59698 var formats = overload.formats; 59699 var minParams = overload.minParams; // check for too few/many args 59700 // the score is double number of extra/missing args 59701 if (argCount < minParams) { 59702 score = (minParams - argCount) * 2; 59703 } else if (argCount > formats.length) { 59704 score = (argCount - formats.length) * 2; 59705 } // loop through the formats, adding up the error score for each arg. 59706 // quit early if the score gets higher than the previous best overload. 59707 59708 for (var p = 0; score <= minScore && p < formats.length; p++) { 59709 var arg = args[p]; 59710 var format = formats[p]; // '== null' checks for 'null' and typeof 'undefined' 59711 if (arg == null) { 59712 // handle undefined args 59713 if (!format.optional || p < minParams || p < argCount) { 59714 score += 1; 59715 } 59716 } else { 59717 score += testParamTypes(arg, format.types); 59718 } 59719 } 59720 return score; 59721 }; 59722 /** 59723 * Gets a list of errors for this overload 59724 * @method getOverloadErrors 59725 * @private 59726 */ 59727 var getOverloadErrors = function getOverloadErrors(args, argCount, overload) { 59728 var formats = overload.formats; 59729 var minParams = overload.minParams; // check for too few/many args 59730 if (argCount < minParams) { 59731 return [{ 59732 type: 'TOO_FEW_ARGUMENTS', 59733 argCount: argCount, 59734 minParams: minParams 59735 } 59736 ]; 59737 } else if (argCount > formats.length) { 59738 return [{ 59739 type: 'TOO_MANY_ARGUMENTS', 59740 argCount: argCount, 59741 maxParams: formats.length 59742 } 59743 ]; 59744 } 59745 var errorArray = [ 59746 ]; 59747 for (var p = 0; p < formats.length; p++) { 59748 var arg = args[p]; 59749 var format = formats[p]; // '== null' checks for 'null' and typeof 'undefined' 59750 if (arg == null) { 59751 // handle undefined args 59752 if (!format.optional || p < minParams || p < argCount) { 59753 errorArray.push({ 59754 type: 'EMPTY_VAR', 59755 position: p, 59756 format: format 59757 }); 59758 } 59759 } else if (testParamTypes(arg, format.types) > 0) { 59760 errorArray.push({ 59761 type: 'WRONG_TYPE', 59762 position: p, 59763 format: format, 59764 arg: arg 59765 }); 59766 } 59767 } 59768 return errorArray; 59769 }; 59770 /** 59771 * a custom error type, used by the mocha 59772 * tests when expecting validation errors 59773 * @method ValidationError 59774 * @private 59775 */ 59776 _main.default.ValidationError = function (name) { 59777 var err = /*#__PURE__*/ 59778 function (_Error) { 59779 _inherits(err, _Error); 59780 var _super = _createSuper(err); 59781 function err(message, func, type) { 59782 var _this; 59783 _classCallCheck(this, err); 59784 _this = _super.call(this); 59785 _this.message = message; 59786 _this.func = func; 59787 _this.type = type;
59788 if ('captureStackTrace' in Error) Error.captureStackTrace(_assertThisInitialized(_this), err); 59789 else _this.stack = new Error().stack; 59790 return _this; 59791 } 59792 return err; 59793 }( /*#__PURE__*/ 59794 _wrapNativeSuper(Error)); 59795 err.prototype.name = name; 59796 return err; 59797 }('ValidationError'); 59798 /** 59799 * Prints a friendly msg after parameter validation 59800 * @method _friendlyParamError 59801 * @private 59802 */ 59803 _main.default._friendlyParamError = function (errorObj, func) { 59804 var message; 59805 var translationObj; 59806 function formatType() { 59807 var format = errorObj.format; 59808 return format.types.map(function (type) { 59809 return type.names ? type.names.join('|') : type.name; 59810 }).join('|'); 59811 } 59812 switch (errorObj.type) { 59813 case 'EMPTY_VAR': 59814 { 59815 translationObj = { 59816 func: func, 59817 formatType: formatType(), 59818 // It needs to be this way for i18next-extract to work. The comment 59819 // specifies the values that the context can take so that it can 59820 // statically prepare the translation files with them. 59821 /* i18next-extract-mark-context-next-line ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"] */ 59822 position: (0, _internationalization.translator) ('fes.positions.p', { 59823 context: (errorObj.position + 1).toString(), 59824 defaultValue: (errorObj.position + 1).toString() 59825 }), 59826 url: 'https://p5js.org/examples/data-variable-scope.html' 59827 }; 59828 break; 59829 } 59830 case 'WRONG_TYPE': 59831 { 59832 var arg = errorObj.arg; 59833 var argType = arg instanceof Array ? 'array' : arg === null ? 'null' : arg.name || _typeof(arg); 59834 translationObj = { 59835 func: func, 59836 formatType: formatType(), 59837 argType: argType, 59838 /* i18next-extract-mark-context-next-line ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"] */ 59839 position: (0, _internationalization.translator) ('fes.positions.p', { 59840 context: (errorObj.position + 1).toString(), 59841 defaultValue: (errorObj.position + 1).toString() 59842 }) 59843 }; 59844 break; 59845 } 59846 case 'TOO_FEW_ARGUMENTS': 59847 { 59848 translationObj = { 59849 func: func, 59850 minParams: errorObj.minParams, 59851 argCount: errorObj.argCount 59852 }; 59853 break; 59854 } 59855 case 'TOO_MANY_ARGUMENTS': 59856 { 59857 translationObj = { 59858 func: func, 59859 maxParams: errorObj.maxParams, 59860 argCount: errorObj.argCount 59861 }; 59862 break; 59863 } 59864 } 59865 if (translationObj) { 59866 try { 59867 // const re = /Function\.validateParameters.*[\r\n].*[\r\n].*\(([^)]*)/; 59868 var myError = new Error(); 59869 var parsed = _main.default._getErrorStackParser().parse(myError); 59870 if (parsed[3] && parsed[3].functionName && parsed[3].functionName.includes('.') && _main.default.prototype[parsed[3].functionName.split('.').slice( - 1) [0]]) { 59871 return; 59872 } 59873 if (_main.default._throwValidationErrors) { 59874 throw new _main.default.ValidationError(message, func, errorObj.type); 59875 } // try to extract the location from where the function was called 59876 59877 if (parsed[3] && parsed[3].fileName && parsed[3].lineNumber && parsed[3].columnNumber) { 59878 var location = ''.concat(parsed[3].fileName, ':').concat(parsed[3].lineNumber, ':').concat(parsed[3].columnNumber); 59879 translationObj.location = (0, _internationalization.translator) ('fes.location', { 59880 location: location, 59881 // for e.g. get "sketch.js" from "https://example.com/abc/sketch.js" 59882 file: parsed[3].fileName.split('/').slice( - 1), 59883 line: parsed[3].lineNumber 59884 }); // tell fesErrorMonitor that we have already given a friendly message 59885 // for this line, so it need not to do the same in case of an error 59886 _main.default._fesLogCache[location] = true; 59887 } 59888 } catch (err) { 59889 if (err instanceof _main.default.ValidationError) { 59890 throw err; 59891 } 59892 } 59893 translationObj.context = errorObj.type; // i18next-extract-mark-context-next-line ["EMPTY_VAR", "TOO_MANY_ARGUMENTS", "TOO_FEW_ARGUMENTS", "WRONG_TYPE"] 59894 message = (0, _internationalization.translator) ('fes.friendlyParamError.type', translationObj); 59895 _main.default._friendlyError(''.concat(message), func, 3); 59896 } 59897 }; 59898 /** 59899 * Clears cache to avoid having multiple FES messages for the same set of 59900 * parameters. 59901 * 59902 * If a function is called with some set of wrong arguments, and then called 59903 * again with the same set of arguments, the messages due to the second call 59904 * will be supressed. If two tests test on the same wrong arguments, the 59905 * second test won't see the validationError. clearing argumentTree solves it 59906 *
59907 * @method _clearValidateParamsCache 59908 * @private 59909 */ 59910 _main.default._clearValidateParamsCache = function clearValidateParamsCache() { 59911 for (var _i2 = 0, _Object$keys2 = Object.keys(argumentTree); _i2 < _Object$keys2.length; _i2++) { 59912 var _key4 = _Object$keys2[_i2]; 59913 delete argumentTree[_key4]; 59914 } 59915 }; // allowing access to argumentTree for testing 59916 _main.default._getValidateParamsArgTree = function getValidateParamsArgTree() { 59917 return argumentTree; 59918 }; 59919 /** 59920 * Runs parameter validation by matching the input parameters with information 59921 * from `docs/reference/data.json`. 59922 * Generates and prints a friendly error message using key: 59923 * "fes.friendlyParamError.[*]". 59924 * 59925 * @method _validateParameters 59926 * @private 59927 * @param {String} func Name of the function 59928 * @param {Array} args User input arguments 59929 * 59930 * @example: 59931 * const a; 59932 * ellipse(10,10,a,5); 59933 * console ouput: 59934 * "It looks like ellipse received an empty variable in spot #2." 59935 * 59936 * @example: 59937 * ellipse(10,"foo",5,5); 59938 * console output: 59939 * "ellipse was expecting a number for parameter #1, 59940 * received "foo" instead." 59941 */ 59942 _main.default._validateParameters = function validateParameters(func, args) { 59943 if (_main.default.disableFriendlyErrors) { 59944 return; // skip FES 59945 } // query / build the argument type tree and check if this sequence 59946 // has already been seen before. 59947 59948 var obj = buildArgTypeCache(func, args); 59949 if (obj.seen) { 59950 return; 59951 } // mark this sequence as seen 59952 59953 obj.seen = true; // lookup the docs in the 'data.json' file 59954 var docs = docCache[func] || (docCache[func] = lookupParamDoc(func)); 59955 var overloads = docs.overloads; 59956 var argCount = args.length; // the following line ignores trailing undefined arguments, commenting 59957 // it to resolve https://github.com/processing/p5.js/issues/4571 59958 // '== null' checks for 'null' and typeof 'undefined' 59959 // while (argCount > 0 && args[argCount - 1] == null) argCount--; 59960 // find the overload with the best score 59961 var minScore = 99999; 59962 var minOverload; 59963 for (var i = 0; i < overloads.length; i++) { 59964 var score = scoreOverload(args, argCount, overloads[i], minScore); 59965 if (score === 0) { 59966 return; // done! 59967 } else if (minScore > score) { 59968 // this score is better that what we have so far... 59969 minScore = score; 59970 minOverload = i; 59971 } 59972 } // this should _always_ be true here... 59973 59974 if (minScore > 0) { 59975 // get the errors for the best overload 59976 var errorArray = getOverloadErrors(args, argCount, overloads[minOverload]); // generate err msg 59977 for (var n = 0; n < errorArray.length; n++) { 59978 _main.default._friendlyParamError(errorArray[n], func); 59979 } 59980 } 59981 }; 59982 _main.default.prototype._validateParameters = _main.default.validateParameters; 59983 } 59984 var _default = _main.default; 59985 exports.default = _default; 59986 }, 59987 { 59988 '../../../docs/parameterData.json': 1, 59989 '../constants': 278, 59990 '../internationalization': 288, 59991 '../main': 290, 59992 'core-js/modules/es.array.concat': 167, 59993 'core-js/modules/es.array.for-each': 172, 59994 'core-js/modules/es.array.includes': 174, 59995 'core-js/modules/es.array.index-of': 175, 59996 'core-js/modules/es.array.iterator': 176, 59997 'core-js/modules/es.array.join': 177, 59998 'core-js/modules/es.array.last-index-of': 178, 59999 'core-js/modules/es.array.map': 179, 60000 'core-js/modules/es.array.slice': 180, 60001 'core-js/modules/es.function.name': 183, 60002 'core-js/modules/es.map': 184, 60003 'core-js/modules/es.number.constructor': 187, 60004 'core-js/modules/es.object.get-own-property-descriptor': 191, 60005 'core-js/modules/es.object.get-prototype-of': 193, 60006 'core-js/modules/es.object.keys': 194, 60007 'core-js/modules/es.object.to-string': 195, 60008 'core-js/modules/es.reflect.construct': 197, 60009 'core-js/modules/es.regexp.exec': 199, 60010 'core-js/modules/es.regexp.to-string': 200, 60011 'core-js/modules/es.set': 201, 60012 'core-js/modules/es.string.includes': 203, 60013 'core-js/modules/es.string.iterator': 204, 60014 'core-js/modules/es.string.split': 209, 60015 'core-js/modules/es.symbol': 214, 60016 'core-js/modules/es.symbol.description': 212, 60017 'core-js/modules/es.symbol.iterator': 213, 60018 'core-js/modules/es.weak-map': 246, 60019 'core-js/modules/web.dom-collections.for-each': 247, 60020 'core-js/modules/web.dom-collections.iterator': 248 60021 } 60022 ], 60023 286: [
60024 function (_dereq_, module, exports) { 60025 'use strict'; 60026 _dereq_('core-js/modules/es.symbol'); 60027 _dereq_('core-js/modules/es.symbol.description'); 60028 _dereq_('core-js/modules/es.symbol.iterator'); 60029 _dereq_('core-js/modules/es.array.iterator'); 60030 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 60031 _dereq_('core-js/modules/es.object.to-string'); 60032 _dereq_('core-js/modules/es.string.iterator'); 60033 _dereq_('core-js/modules/es.weak-map'); 60034 _dereq_('core-js/modules/web.dom-collections.iterator'); 60035 function _typeof2(obj) { 60036 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 60037 _typeof2 = function _typeof2(obj) { 60038 return typeof obj; 60039 }; 60040 } else { 60041 _typeof2 = function _typeof2(obj) { 60042 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 60043 }; 60044 } 60045 return _typeof2(obj); 60046 } 60047 function _typeof(obj) { 60048 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 60049 _typeof = function _typeof(obj) { 60050 return _typeof2(obj); 60051 }; 60052 } else { 60053 _typeof = function _typeof(obj) { 60054 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 60055 }; 60056 } 60057 return _typeof(obj); 60058 } 60059 Object.defineProperty(exports, '__esModule', { 60060 value: true 60061 }); 60062 exports.default = void 0; 60063 var constants = _interopRequireWildcard(_dereq_('./constants')); 60064 function _getRequireWildcardCache() { 60065 if (typeof WeakMap !== 'function') return null; 60066 var cache = new WeakMap(); 60067 _getRequireWildcardCache = function _getRequireWildcardCache() { 60068 return cache; 60069 }; 60070 return cache; 60071 } 60072 function _interopRequireWildcard(obj) { 60073 if (obj && obj.__esModule) { 60074 return obj; 60075 } 60076 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 60077 return { 60078 default: 60079 obj 60080 }; 60081 } 60082 var cache = _getRequireWildcardCache(); 60083 if (cache && cache.has(obj)) { 60084 return cache.get(obj); 60085 } 60086 var newObj = { 60087 }; 60088 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 60089 for (var key in obj) { 60090 if (Object.prototype.hasOwnProperty.call(obj, key)) { 60091 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 60092 if (desc && (desc.get || desc.set)) { 60093 Object.defineProperty(newObj, key, desc); 60094 } else { 60095 newObj[key] = obj[key]; 60096 } 60097 } 60098 } 60099 newObj.default = obj; 60100 if (cache) { 60101 cache.set(obj, newObj); 60102 } 60103 return newObj; 60104 } /** 60105 * @requires constants 60106 */ 60107 60108 function modeAdjust(a, b, c, d, mode) { 60109 if (mode === constants.CORNER) { 60110 return { 60111 x: a, 60112 y: b, 60113 w: c, 60114 h: d 60115 }; 60116 } else if (mode === constants.CORNERS) { 60117 return { 60118 x: a, 60119 y: b, 60120 w: c - a, 60121 h: d - b 60122 }; 60123 } else if (mode === constants.RADIUS) { 60124 return { 60125 x: a - c, 60126 y: b - d, 60127 w: 2 * c, 60128 h: 2 * d 60129 }; 60130 } else if (mode === constants.CENTER) { 60131 return { 60132 x: a - c * 0.5, 60133 y: b - d * 0.5, 60134 w: c, 60135 h: d 60136 }; 60137 } 60138 } 60139 var _default = { 60140 modeAdjust: modeAdjust 60141 }; 60142 exports.default = _default; 60143 }, 60144 { 60145 './constants': 278, 60146 'core-js/modules/es.array.iterator': 176, 60147 'core-js/modules/es.object.get-own-property-descriptor': 191, 60148 'core-js/modules/es.object.to-string': 195, 60149 'core-js/modules/es.string.iterator': 204, 60150 'core-js/modules/es.symbol': 214, 60151 'core-js/modules/es.symbol.description': 212, 60152 'core-js/modules/es.symbol.iterator': 213, 60153 'core-js/modules/es.weak-map': 246, 60154 'core-js/modules/web.dom-collections.iterator': 248 60155 } 60156 ], 60157 287: [
60158 function (_dereq_, module, exports) { 60159 'use strict'; 60160 _dereq_('core-js/modules/es.array.iterator'); 60161 _dereq_('core-js/modules/es.object.to-string'); 60162 _dereq_('core-js/modules/es.promise'); 60163 _dereq_('core-js/modules/es.string.iterator'); 60164 _dereq_('core-js/modules/web.dom-collections.iterator'); 60165 _dereq_('core-js/modules/es.array.iterator'); 60166 _dereq_('core-js/modules/es.object.to-string'); 60167 _dereq_('core-js/modules/es.promise'); 60168 _dereq_('core-js/modules/es.string.iterator'); 60169 _dereq_('core-js/modules/web.dom-collections.iterator'); 60170 var _main = _interopRequireDefault(_dereq_('../core/main')); 60171 var _internationalization = _dereq_('./internationalization'); 60172 function _interopRequireDefault(obj) { 60173 return obj && obj.__esModule ? obj : { 60174 default: 60175 obj 60176 }; 60177 } /** 60178 * _globalInit 60179 * 60180 * TODO: ??? 60181 * if sketch is on window 60182 * assume "global" mode 60183 * and instantiate p5 automatically 60184 * otherwise do nothing 60185 * 60186 * @private 60187 * @return {Undefined} 60188 */ 60189 60190 var _globalInit = function _globalInit() { 60191 // Could have been any property defined within the p5 constructor. 60192 // If that property is already a part of the global object, 60193 // this code has already run before, likely due to a duplicate import 60194 if (typeof window._setupDone !== 'undefined') { 60195 console.warn('p5.js seems to have been imported multiple times. Please remove the duplicate import'); 60196 return; 60197 } 60198 if (!window.mocha) { 60199 // If there is a setup or draw function on the window 60200 // then instantiate p5 in "global" mode 60201 if ((window.setup && typeof window.setup === 'function' || window.draw && typeof window.draw === 'function') && !_main.default.instance) { 60202 new _main.default(); 60203 } 60204 } 60205 }; // make a promise that resolves when the document is ready 60206 var waitForDocumentReady = function waitForDocumentReady() { 60207 return new Promise(function (resolve, reject) { 60208 // if the page is ready, initialize p5 immediately 60209 if (document.readyState === 'complete') { 60210 resolve(); // if the page is still loading, add an event listener 60211 // and initialize p5 as soon as it finishes loading 60212 } else { 60213 window.addEventListener('load', resolve, false); 60214 } 60215 }); 60216 }; // only load translations if we're using the full, un-minified library 60217 var waitingForTranslator = typeof IS_MINIFIED === 'undefined' ? (0, _internationalization.initialize) () : Promise.resolve(); 60218 Promise.all([waitForDocumentReady(), 60219 waitingForTranslator]).then(_globalInit); 60220 }, 60221 { 60222 '../core/main': 290, 60223 './internationalization': 288, 60224 'core-js/modules/es.array.iterator': 176, 60225 'core-js/modules/es.object.to-string': 195, 60226 'core-js/modules/es.promise': 196, 60227 'core-js/modules/es.string.iterator': 204, 60228 'core-js/modules/web.dom-collections.iterator': 248 60229 } 60230 ], 60231 288: [ 60232 function (_dereq_, module, exports) { 60233 'use strict'; 60234 _dereq_('core-js/modules/es.array.includes'); 60235 _dereq_('core-js/modules/es.array.iterator'); 60236 _dereq_('core-js/modules/es.array.join'); 60237 _dereq_('core-js/modules/es.array.slice'); 60238 _dereq_('core-js/modules/es.object.keys'); 60239 _dereq_('core-js/modules/es.object.to-string'); 60240 _dereq_('core-js/modules/es.promise'); 60241 _dereq_('core-js/modules/es.regexp.exec'); 60242 _dereq_('core-js/modules/es.string.includes'); 60243 _dereq_('core-js/modules/es.string.iterator'); 60244 _dereq_('core-js/modules/es.string.split'); 60245 _dereq_('core-js/modules/web.dom-collections.iterator'); 60246 _dereq_('core-js/modules/es.array.includes'); 60247 _dereq_('core-js/modules/es.array.iterator'); 60248 _dereq_('core-js/modules/es.array.join'); 60249 _dereq_('core-js/modules/es.array.slice'); 60250 _dereq_('core-js/modules/es.object.keys'); 60251 _dereq_('core-js/modules/es.object.to-string'); 60252 _dereq_('core-js/modules/es.promise'); 60253 _dereq_('core-js/modules/es.regexp.exec'); 60254 _dereq_('core-js/modules/es.string.includes'); 60255 _dereq_('core-js/modules/es.string.iterator'); 60256 _dereq_('core-js/modules/es.string.split'); 60257 _dereq_('core-js/modules/web.dom-collections.iterator'); 60258 Object.defineProperty(exports, '__esModule', { 60259 value: true 60260 }); 60261 exports.setTranslatorLanguage = exports.currentTranslatorLanguage = exports.availableTranslatorLanguages = exp
60261orts.initialize = exports.translator = void 0; 60262 var _i18next = _interopRequireDefault(_dereq_('i18next')); 60263 var _i18nextBrowserLanguagedetector = _interopRequireDefault(_dereq_('i18next-browser-languagedetector')); 60264 function _interopRequireDefault(obj) { 60265 return obj && obj.__esModule ? obj : { 60266 default: 60267 obj 60268 }; 60269 } 60270 function _classCallCheck(instance, Constructor) { 60271 if (!(instance instanceof Constructor)) { 60272 throw new TypeError('Cannot call a class as a function'); 60273 } 60274 } 60275 function _defineProperties(target, props) { 60276 for (var i = 0; i < props.length; i++) { 60277 var descriptor = props[i]; 60278 descriptor.enumerable = descriptor.enumerable || false; 60279 descriptor.configurable = true; 60280 if ('value' in descriptor) descriptor.writable = true; 60281 Object.defineProperty(target, descriptor.key, descriptor); 60282 } 60283 } 60284 function _createClass(Constructor, protoProps, staticProps) { 60285 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 60286 if (staticProps) _defineProperties(Constructor, staticProps); 60287 return Constructor; 60288 } 60289 var fallbackResources, 60290 languages; 60291 if (typeof IS_MINIFIED === 'undefined') { 60292 // internationalization is only for the unminified build 60293 var translationsModule = _dereq_('../../translations'); 60294 fallbackResources = translationsModule.default; 60295 languages = translationsModule.languages; 60296 if (typeof P5_DEV_BUILD !== 'undefined') { 60297 // When the library is built in development mode ( using npm run dev ) 60298 // we want to use the current translation files on the disk, which may have 60299 // been updated but not yet pushed to the CDN. 60300 var completeResources = _dereq_('../../translations/dev'); 60301 for (var _i = 0, _Object$keys = Object.keys(completeResources); _i < _Object$keys.length; _i++) { 60302 var language = _Object$keys[_i]; // In es_translation, language is es and namespace is translation 60303 // In es_MX_translation, language is es-MX and namespace is translation 60304 var parts = language.split('_'); 60305 var lng = parts.slice(0, parts.length - 1).join('-'); 60306 var ns = parts[parts.length - 1]; 60307 fallbackResources[lng] = fallbackResources[lng] || { 60308 }; 60309 fallbackResources[lng][ns] = completeResources[language]; 60310 } 60311 } 60312 } /** 60313 * This is our i18next "backend" plugin. It tries to fetch languages 60314 * from a CDN. 60315 */ 60316 60317 var FetchResources = /*#__PURE__*/ 60318 function () { 60319 function FetchResources(services, options) { 60320 _classCallCheck(this, FetchResources); 60321 this.init(services, options); 60322 } // run fetch with a timeout. Automatically rejects on timeout 60323 // default timeout = 2000 ms 60324 60325 _createClass(FetchResources, [ 60326 { 60327 key: 'fetchWithTimeout', 60328 value: function fetchWithTimeout(url, options) { 60329 var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2000; 60330 return Promise.race([fetch(url, options), 60331 new Promise(function (_, reject) { 60332 return setTimeout(function () { 60333 return reject(new Error('timeout')); 60334 }, timeout); 60335 })]); 60336 } 60337 }, 60338 { 60339 key: 'init', 60340 value: function init(services) { 60341 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 60342 }; 60343 this.services = services; 60344 this.options = options; 60345 } 60346 }, 60347 { 60348 key: 'read', 60349 value: function read(language, namespace, callback) { 60350 var loadPath = this.options.loadPath; 60351 if (language === this.options.fallback) { 60352 // if the default language of the user is the same as our inbuilt fallback, 60353 // there's no need to fetch resources from the c
60353dn. This won't actually 60354 // need to run when we use "partialBundledLanguages" in the init 60355 // function. 60356 callback(null, fallbackResources[language][namespace]); 60357 } else if (languages.includes(language)) { 60358 // The user's language is included in the list of languages 60359 // that we so far added translations for. 60360 var url = this.services.interpolator.interpolate(loadPath, { 60361 lng: language, 60362 ns: namespace 60363 }); 60364 this.loadUrl(url, callback); 60365 } else { 60366 // We don't have translations for this language. i18next will use 60367 // the default language instead. 60368 callback('Not found', false); 60369 } 60370 } 60371 }, 60372 { 60373 key: 'loadUrl', 60374 value: function loadUrl(url, callback) { 60375 this.fetchWithTimeout(url).then(function (response) { 60376 var ok = response.ok; 60377 if (!ok) { 60378 // caught in the catch() below 60379 throw new Error('failed loading '.concat(url)); 60380 } 60381 return response.json(); 60382 }, function () { 60383 // caught in the catch() below 60384 throw new Error('failed loading '.concat(url)); 60385 }).then(function (data) { 60386 return callback(null, data); 60387 }).catch(callback); 60388 } 60389 } 60390 ]); 60391 return FetchResources; 60392 }(); 60393 FetchResources.type = 'backend'; 60394 /** 60395 * This is our translation function. Give it a key and 60396 * it will retrieve the appropriate string 60397 * (within supported languages) according to the 60398 * user's browser's language settings. 60399 * @function translator 60400 * @param {String} key a key that corresponds to a message in our translation files 60401 * @param {Object} values values for use in the message under the given `key` 60402 * @returns {String} message (with values inserted) in the user's browser language 60403 * @private 60404 */ 60405 var translator = function translator(key, values) { 60406 console.debug('p5.js translator called before translations were loaded'); // Certain FES functionality may trigger before translations are downloaded. 60407 // Using "partialBundledLanguages" option during initialization, we can 60408 // still use our fallback language to display messages 60409 _i18next.default.t(key, values); 60410 /* i18next-extract-disable-line */ 60411 }; // (We'll set this to a real value in the init function below!) 60412 /** 60413 * Set up our translation function, with loaded languages 60414 */ 60415 exports.translator = translator; 60416 var initialize = function initialize() { 60417 var i18init = _i18next.default.use(_i18nextBrowserLanguagedetector.default).use(FetchResources).init({ 60418 fallbackLng: 'en', 60419 nestingPrefix: '$tr(', 60420 nestingSuffix: ')', 60421 defaultNS: 'translation', 60422 returnEmptyString: false, 60423 interpolation: { 60424 escapeValue: false 60425 }, 60426 detection: { 60427 checkWhitelist: false, 60428 // prevent storing or locating language from cookie or localStorage 60429 // more info on https://github.com/processing/p5.js/issues/4862 60430 order: [ 60431 'querystring', 60432 'navigator', 60433 'htmlTag', 60434 'path', 60435 'subdomain' 60436 ], 60437 caches: [ 60438 ] 60439 }, 60440 backend: { 60441 fallback: 'en', 60442 loadPath: 'https://cdn.jsdelivr.net/npm/p5/translations/{{lng}}/{{ns}}.json' 60443 }, 60444 partialBundledLanguages: true, 60445 resources: fallbackResources 60446 }).then(function (translateFn) { 60447 exports.translator = translator = translateFn; 60448 }, function (e) { 60449 return console.debug('Translations failed to load ('.concat(e, ')')); 60450 });
60450 // i18next.init() returns a promise that resolves when the translations 60451 // are loaded. We use this in core/init.js to hold p5 initialization until 60452 // we have the translation files. 60453 return i18init; 60454 }; 60455 /** 60456 * Returns a list of languages we have translations loaded for 60457 */ 60458 exports.initialize = initialize; 60459 var availableTranslatorLanguages = function availableTranslatorLanguages() { 60460 return _i18next.default.languages; 60461 }; 60462 /** 60463 * Returns the current language selected for translation 60464 */ 60465 exports.availableTranslatorLanguages = availableTranslatorLanguages; 60466 var currentTranslatorLanguage = function currentTranslatorLanguage(language) { 60467 return _i18next.default.language; 60468 }; 60469 /** 60470 * Sets the current language for translation 60471 * Returns a promise that resolved when loading is finished, 60472 * or rejects if it fails. 60473 */ 60474 exports.currentTranslatorLanguage = currentTranslatorLanguage; 60475 var setTranslatorLanguage = function setTranslatorLanguage(language) { 60476 return _i18next.default.changeLanguage(language || undefined, function (e) { 60477 return console.debug('Translations failed to load ('.concat(e, ')')); 60478 }); 60479 }; 60480 exports.setTranslatorLanguage = setTranslatorLanguage; 60481 }, 60482 { 60483 '../../translations': 349, 60484 '../../translations/dev': undefined, 60485 'core-js/modules/es.array.includes': 174, 60486 'core-js/modules/es.array.iterator': 176, 60487 'core-js/modules/es.array.join': 177, 60488 'core-js/modules/es.array.slice': 180, 60489 'core-js/modules/es.object.keys': 194, 60490 'core-js/modules/es.object.to-string': 195, 60491 'core-js/modules/es.promise': 196, 60492 'core-js/modules/es.regexp.exec': 199, 60493 'core-js/modules/es.string.includes': 203, 60494 'core-js/modules/es.string.iterator': 204, 60495 'core-js/modules/es.string.split': 209, 60496 'core-js/modules/web.dom-collections.iterator': 248, 60497 'i18next': 259, 60498 'i18next-browser-languagedetector': 256 60499 } 60500 ], 60501 289: [ 60502 function (_dereq_, module, exports) { 60503 'use strict'; 60504 Object.defineProperty(exports, '__esModule', { 60505 value: true 60506 }); 60507 exports.default = void 0; 60508 var _main = _interopRequireDefault(_dereq_('./main')); 60509 function _interopRequireDefault(obj) { 60510 return obj && obj.__esModule ? obj : { 60511 default: 60512 obj 60513 }; 60514 } /** 60515 * @for p5 60516 * @requires core 60517 * These are functions that are part of the Processing API but are not part of 60518 * the p5.js API. In some cases they have a new name, in others, they are 60519 * removed completely. Not all unsupported Processing functions are listed here 60520 * but we try to include ones that a user coming from Processing might likely 60521 * call. 60522 */ 60523 60524 _main.default.prototype.pushStyle = function () { 60525 throw new Error('pushStyle() not used, see push()'); 60526 }; 60527 _main.default.prototype.popStyle = function () { 60528 throw new Error('popStyle() not used, see pop()'); 60529 }; 60530 _main.default.prototype.popMatrix = function () { 60531 throw new Error('popMatrix() not used, see pop()'); 60532 }; 60533 _main.default.prototype.pushMatrix = function () { 60534 throw new Error('pushMatrix() not used, see push()'); 60535 }; 60536 var _default = _main.default; 60537 exports.default = _default; 60538 }, 60539 { 60540 './main': 290 60541 } 60542 ], 60543 290: [ 60544 function (_dereq_, module, exports) { 60545 'use strict'; 60546 _dereq_('core-js/modules/es.symbol'); 60547 _dereq_('core-js/modules/es.symbol.description'); 60548 _dereq_('core-js/modules/es.symbol.iterator'); 60549 _dereq_('core-js/modules/es.array.for-each'); 60550 _dereq_('core-js/modules/es.array.iterator'); 60551 _dereq_('core-js/modules/es.array.slice'); 60552 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 60553 _dereq_('core-js/modules/es.object.get-own-property-names'); 60554 _dereq_('core-js/modules/es.object.to-string'); 60555 _dereq_('core-js/modules/es.string.iterator'); 60556 _dereq_('core-js/modules/es.weak-map'); 60557 _dereq_('core-js/modules/web.dom-collections.for-each'); 60558 _dereq_('core-js/modules/web.dom-collections.iterator'); 60559 function _typeof2(obj) { 60560 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 60561 _typeof2 = function _typeof2(obj) { 60562 return typeof obj; 60563 }; 60564 } else { 60565 _typeof2 = function _typeof2(obj) { 60566 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 60567 }; 60568 } 60569 return _typeof2(obj); 60570 } 60571 function _typeof(obj) { 60572 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 60573 _typeof = function _typeof(obj) { 60574 return _typeof2(obj); 60575 }; 60576 } else { 60577 _typeof = function _typeof(obj) { 60578 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
60578ypeof2(obj); 60579 }; 60580 } 60581 return _typeof(obj); 60582 } 60583 _dereq_('core-js/modules/es.symbol'); 60584 _dereq_('core-js/modules/es.symbol.description'); 60585 _dereq_('core-js/modules/es.symbol.iterator'); 60586 _dereq_('core-js/modules/es.array.for-each'); 60587 _dereq_('core-js/modules/es.array.iterator'); 60588 _dereq_('core-js/modules/es.array.slice'); 60589 _dereq_('core-js/modules/es.object.get-own-property-names'); 60590 _dereq_('core-js/modules/es.object.to-string'); 60591 _dereq_('core-js/modules/es.string.iterator'); 60592 _dereq_('core-js/modules/web.dom-collections.for-each'); 60593 _dereq_('core-js/modules/web.dom-collections.iterator'); 60594 Object.defineProperty(exports, '__esModule', { 60595 value: true 60596 }); 60597 exports.default = void 0; 60598 _dereq_('./shim'); 60599 var constants = _interopRequireWildcard(_dereq_('./constants')); 60600 function _getRequireWildcardCache() { 60601 if (typeof WeakMap !== 'function') return null; 60602 var cache = new WeakMap(); 60603 _getRequireWildcardCache = function _getRequireWildcardCache() { 60604 return cache; 60605 }; 60606 return cache; 60607 } 60608 function _interopRequireWildcard(obj) { 60609 if (obj && obj.__esModule) { 60610 return obj; 60611 } 60612 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 60613 return { 60614 default: 60615 obj 60616 }; 60617 } 60618 var cache = _getRequireWildcardCache(); 60619 if (cache && cache.has(obj)) { 60620 return cache.get(obj); 60621 } 60622 var newObj = { 60623 }; 60624 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 60625 for (var key in obj) { 60626 if (Object.prototype.hasOwnProperty.call(obj, key)) { 60627 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 60628 if (desc && (desc.get || desc.set)) { 60629 Object.defineProperty(newObj, key, desc); 60630 } else { 60631 newObj[key] = obj[key]; 60632 } 60633 } 60634 } 60635 newObj.default = obj; 60636 if (cache) { 60637 cache.set(obj, newObj); 60638 } 60639 return newObj; 60640 } 60641 function _classCallCheck(instance, Constructor) { 60642 if (!(instance instanceof Constructor)) { 60643 throw new TypeError('Cannot call a class as a function'); 60644 } 60645 } 60646 function _defineProperties(target, props) { 60647 for (var i = 0; i < props.length; i++) { 60648 var descriptor = props[i]; 60649 descriptor.enumerable = descriptor.enumerable || false; 60650 descriptor.configurable = true; 60651 if ('value' in descriptor) descriptor.writable = true; 60652 Object.defineProperty(target, descriptor.key, descriptor); 60653 } 60654 } 60655 function _createClass(Constructor, protoProps, staticProps) { 60656 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 60657 if (staticProps) _defineProperties(Constructor, staticProps); 60658 return Constructor; 60659 } /** 60660 * This is the p5 instance constructor. 60661 * 60662 * A p5 instance holds all the properties and methods related to 60663 * a p5 sketch. It expects an incoming sketch closure and it can also 60664 * take an optional node parameter for attaching the generated p5 canvas 60665 * to a node. The sketch closure takes the newly created p5 instance as 60666 * its sole argument and may optionally set <a href="#/p5/preload">preload()</a>, 60667 * <a href="#/p5/setup">setup()</a>, and/or 60668 * <a href="#/p5/draw">draw()</a> properties on it for running a sketch. 60669 * 60670 * A p5 sketch can run in "global" or "instance" mode: 60671 * "global" - all properties and methods are attached to the window 60672 * "instance" - all properties and methods are bound to this p5 object 60673 * 60674 * @class p5 60675 * @constructor 60676 * @param {function} sketch a closure that can set optional <a href="#/p5/preload">preload()</a>, 60677 * <a href="#/p5/setup">setup()</a>, and/or <a href="#/p5/draw">draw()</a> properties on the 60678 * given p5 instance 60679 * @param {HTMLElement} [node] element to attach canvas to 60680 * @return {p5} a p5 instance 60681 */ 60682 60683 var p5 = /*#__PURE__*/ 60684 function () { 60685 function p5(sketch, node, sync) { 60686 var _this = this; 60687 _classCallCheck(this, p5); ////////////////////////////////////////////// 60688 // PUBLIC p5 PROPERTIES AND METHODS
60689 ////////////////////////////////////////////// 60690 /** 60691 * Called directly before <a href="#/p5/setup">setup()</a>, the <a href="#/p5/preload">preload()</a> function is used to handle 60692 * asynchronous loading of external files in a blocking way. If a preload 60693 * function is defined, <a href="#/p5/setup">setup()</a> will wait until any load calls within have 60694 * finished. Nothing besides load calls (<a href="#/p5/loadImage">loadImage</a>, <a href="#/p5/loadJSON">loadJSON</a>, <a href="#/p5/loadFont">loadFont</a>, 60695 * <a href="#/p5/loadStrings">loadStrings</a>, etc.) should be inside the preload function. If asynchronous 60696 * loading is preferred, the load methods can instead be called in <a href="#/p5/setup">setup()</a> 60697 * or anywhere else with the use of a callback parameter. 60698 * 60699 * By default the text "loading..." will be displayed. To make your own 60700 * loading page, include an HTML element with id "p5_loading" in your 60701 * page. More information <a href="http://bit.ly/2kQ6Nio">here</a>. 60702 * 60703 * @method preload 60704 * @example 60705 * <div><code> 60706 * let img; 60707 * let c; 60708 * function preload() { 60709 * // preload() runs once 60710 * img = loadImage('assets/laDefense.jpg'); 60711 * } 60712 * 60713 * function setup() { 60714 * // setup() waits until preload() is done 60715 * img.loadPixels(); 60716 * // get color of middle pixel 60717 * c = img.get(img.width / 2, img.height / 2); 60718 * } 60719 * 60720 * function draw() { 60721 * background(c); 60722 * image(img, 25, 25, 50, 50); 60723 * } 60724 * </code></div> 60725 * 60726 * @alt 60727 * nothing displayed 60728 * 60729 */ 60730 /** 60731 * The <a href="#/p5/setup">setup()</a> function is called once when the program starts. It's used to 60732 * define initial environment properties such as screen size and background 60733 * color and to load media such as images and fonts as the program starts. 60734 * There can only be one <a href="#/p5/setup">setup()</a> function for each program and it shouldn't 60735 * be called again after its initial execution. 60736 * 60737 * Note: Variables declared within <a href="#/p5/setup">setup()</a> are not accessible within other 60738 * functions, including <a href="#/p5/draw">draw()</a>. 60739 * 60740 * @method setup 60741 * @example 60742 * <div><code> 60743 * let a = 0; 60744 * 60745 * function setup() { 60746 * background(0); 60747 * noStroke(); 60748 * fill(102); 60749 * } 60750 * 60751 * function draw() { 60752 * rect(a++ % width, 10, 2, 80); 60753 * } 60754 * </code></div> 60755 * 60756 * @alt 60757 * nothing displayed 60758 * 60759 */ 60760 /** 60761 * Called directly after <a href="#/p5/setup">setup()</a>, the <a href="#/p5/draw">draw()</a> function continuously executes 60762 * the lines of code contained inside its block until the program is stopped 60763 * or <a href="#/p5/noLoop">noLoop()</a> is called. Note if <a href="#/p5/noLoop">noLoop()</a> is called in <a href="#/p5/setup">setup()</a>, <a href="#/p5/draw">draw()</a> will 60764 * still be executed once before stopping. <a href="#/p5/draw">draw()</a> is called automatically and 60765 * should never be called explicitly. 60766 * 60767 * It should always be controlled with <a href="#/p5/noLoop">noLoop()</a>, <a href="#/p5/redraw">redraw()</a> and <a href="#/p5/loop">loop()</a>. After 60768 * <a href="#/p5/noLoop">noLoop()</a> stops the code in <a href="#/p5/draw">draw()</a> from executing, <a href="#/p5/redraw">redraw()</a> causes the 60769 * code inside <a href="#/p5/draw">draw()</a> to execute once, and <a href="#/p5/loop">loop()</a> will cause the code 60770 * inside <a href="#/p5/draw">draw()</a> to resume executing continuously. 60771 * 60772 * The number of times <a href="#/p5/draw">draw()</a> executes in each second may be controlled with 60773 * the <a href="#/p5/frameRate">frameRate()</a> function. 60774 * 60775 * There can only be one <a href="#/p5/draw">draw()</a> function for each sketch, and <a href="#/p5/draw">draw()</a> must 60776 * exist if you want the code to run continuously, or to process events such 60777 * as <a href="#/p5/mousePressed">mousePressed()</a>. Sometimes, you might have an empty call to <a href="#/p5/draw">draw()</a> in 60778 * your program, as shown in the above example. 60779 * 60780 * It is important to note that the drawing coordinate system will be reset 60781 * at the beginning of each <a href="#/p5/draw">draw()</a> call. If any transformations are performed 60782 * within <a href="#/p5/draw">draw()</a> (ex: scale, rotate, translate), their effects will be 60783 * undone at the beginning of <a href="#/p5/draw">draw()</a>, so transformations will not accumulate 60784 * over time. On the other hand, styling applied (ex: fill, stroke, etc) will 60785 * remain in effect. 60786 * 60787 * @method draw 60788 * @example 60789 * <div><code> 60790 * let yPos = 0; 60791 * function setup() { 60792 * // setup() runs once 60793 * frameRate(30); 60794 * } 60795 * function draw() { 60796 * // draw() loops forever, until stopped 60797 * background(204); 60798 * yPos = yPos - 1; 60799 * if (yPos < 0) { 60800 * yPos = height; 60801 * } 60802 * line(0, yPos, width, yPos); 60803 * } 60804 * </code></div> 60805 * 60806 * @alt 60807 * nothing displayed 60808 * 60809 */
60810 ////////////////////////////////////////////// 60811 // PRIVATE p5 PROPERTIES AND METHODS 60812 ////////////////////////////////////////////// 60813 this._setupDone = false; 60814 this._preloadDone = false; // for handling hidpi 60815 this._pixelDensity = Math.ceil(window.devicePixelRatio) || 1; 60816 this._userNode = node; 60817 this._curElement = null; 60818 this._elements = [ 60819 ]; 60820 this._glAttributes = null; 60821 this._requestAnimId = 0; 60822 this._preloadCount = 0; 60823 this._isGlobal = false; 60824 this._loop = true; 60825 this._initializeInstanceVariables(); 60826 this._defaultCanvasSize = { 60827 width: 100, 60828 height: 100 60829 }; 60830 this._events = { 60831 // keep track of user-events for unregistering later 60832 mousemove: null, 60833 mousedown: null, 60834 mouseup: null, 60835 dragend: null, 60836 dragover: null, 60837 click: null, 60838 dblclick: null, 60839 mouseover: null, 60840 mouseout: null, 60841 keydown: null, 60842 keyup: null, 60843 keypress: null, 60844 touchstart: null, 60845 touchmove: null, 60846 touchend: null, 60847 resize: null, 60848 blur: null 60849 }; 60850 this._millisStart = - 1; 60851 this._recording = false; // States used in the custom random generators 60852 this._lcg_random_state = null; 60853 this._gaussian_previous = false; 60854 this._events.wheel = null; 60855 this._loadingScreenId = 'p5_loading'; // Allows methods to be registered on an instance that 60856 // are instance-specific. 60857 this._registeredMethods = { 60858 }; 60859 var methods = Object.getOwnPropertyNames(p5.prototype._registeredMethods); 60860 var _iteratorNormalCompletion = true; 60861 var _didIteratorError = false; 60862 var _iteratorError = undefined; 60863 try { 60864 for (var _iterator = methods[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 60865 var prop = _step.value; 60866 this._registeredMethods[prop] = p5.prototype._registeredMethods[prop].slice(); 60867 } 60868 } catch (err) { 60869 _didIteratorError = true; 60870 _iteratorError = err; 60871 } finally { 60872 try { 60873 if (!_iteratorNormalCompletion && _iterator.return != null) { 60874 _iterator.return(); 60875 } 60876 } finally { 60877 if (_didIteratorError) { 60878 throw _iteratorError; 60879 } 60880 } 60881 } 60882 if (window.DeviceOrientationEvent) { 60883 this._events.deviceorientation = null; 60884 } 60885 if (window.DeviceMotionEvent && !window._isNodeWebkit) { 60886 this._events.devicemotion = null; 60887 } 60888 this._start = function () { 60889 // Find node if id given 60890 if (_this._userNode) { 60891 if (typeof _this._userNode === 'string') { 60892 _this._userNode = document.getElementById(_this._userNode); 60893 } 60894 } 60895 var context = _this._isGlobal ? window : _this; 60896 if (context.preload) { 60897 // Setup loading screen 60898 // Set loading screen into dom if not present 60899 // Otherwise displays and removes user provided loading screen 60900 var loadingScreen = document.getElementById(_this._loadingScreenId); 60901 if (!loadingScreen) { 60902 loadingScreen = document.createElement('div'); 60903 loadingScreen.innerHTML = 'Loading...'; 60904 loadingScreen.style.position = 'absolute'; 60905 loadingScreen.id = _this._loadingScreenId; 60906 var _node = _this._userNode || document.body; 60907 _node.appendChild(loadingScreen); 60908 } 60909 var _methods = _this._preloadMethods; 60910 for (var method in _methods) { 60911 // default to p5 if no object defined 60912 _methods[method] = _methods[method] || p5; 60913 var obj = _methods[method]; //it's p5, check if it's global or instance 60914 if (obj === p5.prototype || obj === p5) { 60915 if (_this._isGlobal) { 60916 window[method] = _this._wrapPreload(_this, method); 60917 } 60918 obj = _this; 60919 } 60920 _this._registeredPreloadMethods[method] = obj[method]; 60921 obj[method] = _this._wrapPreload(obj, method); 60922 } 60923 context.preload(); 60924 _this._runIfPreloadsAreDone(); 60925 } else { 60926 _this._setup(); 60927 if (!_this._recording) { 60928 _this._draw(); 60929 } 60930 } 60931 }; 60932 this._runIfPreloadsAreDone = function () { 60933 var context = this._isGlobal ? window : this; 60934 if (context._preloadCount === 0) { 60935 var loadingScreen = document.getElementById(context._loadingScreenId); 60936 if (loadingScreen) { 60937 loadingScreen.parentNode.removeChild(loadingScreen); 60938 } 60939 if (!this._setupDone) { 60940 this._lastTargetFrameTime = window.performance.now(); 60941 this._lastRealFrameTime = window.performance.now(); 60942 context._setup(); 60943 if (!this._recording) { 60944 context._draw(); 60945 } 60946 } 60947 } 60948 }; 60949 this._decrementPreload = function () { 60950 var context = this._isGlobal ? window : this; 60951 if (!context._preloadDone && typeof context.preload === 'function') { 60952 context._setProperty('_preloadCount', context._preloadCount - 1); 60953 context._runIfPreloadsAreDone(); 60954 } 60955 }; 60956 this._wrapPreload = function (obj, fnName) { 60957 var _this2 = this; 60958 return function () { 60959 //increment counter 60960 _this2._incrementPreload(); //call original function 60961 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 60962 args[_key] = arguments[_key]; 60963 } 60964 return _this2._registeredPreloadMethods[fnName].apply(obj, args); 60965 }; 60966 }; 60967 this._incrementPreload = function () { 60968 var context = this._isGlobal ? window : this;
60968 // Do nothing if we tried to increment preloads outside of `preload` 60969 if (context._preloadDone) return; 60970 context._setProperty('_preloadCount', context._preloadCount + 1); 60971 }; 60972 this._setup = function () { 60973 // Always create a default canvas. 60974 // Later on if the user calls createCanvas, this default one 60975 // will be replaced 60976 _this.createCanvas(_this._defaultCanvasSize.width, _this._defaultCanvasSize.height, 'p2d'); // return preload functions to their normal vals if switched by preload 60977 var context = _this._isGlobal ? window : _this; 60978 if (typeof context.preload === 'function') { 60979 for (var f in _this._preloadMethods) { 60980 context[f] = _this._preloadMethods[f][f]; 60981 if (context[f] && _this) { 60982 context[f] = context[f].bind(_this); 60983 } 60984 } 60985 } // Record the time when sketch starts 60986 60987 _this._millisStart = window.performance.now(); 60988 context._preloadDone = true; // Short-circuit on this, in case someone used the library in "global" 60989 // mode earlier 60990 if (typeof context.setup === 'function') { 60991 context.setup(); 60992 } // unhide any hidden canvases that were created 60993 60994 var canvases = document.getElementsByTagName('canvas'); 60995 var _iteratorNormalCompletion2 = true; 60996 var _didIteratorError2 = false;
60997 var _iteratorError2 = undefined; 60998 try { 60999 for (var _iterator2 = canvases[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 61000 var k = _step2.value; 61001 if (k.dataset.hidden === 'true') { 61002 k.style.visibility = ''; 61003 delete k.dataset.hidden; 61004 } 61005 } 61006 } catch (err) { 61007 _didIteratorError2 = true; 61008 _iteratorError2 = err; 61009 } finally { 61010 try { 61011 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 61012 _iterator2.return(); 61013 } 61014 } finally { 61015 if (_didIteratorError2) { 61016 throw _iteratorError2; 61017 } 61018 } 61019 } 61020 _this._lastTargetFrameTime = window.performance.now(); 61021 _this._lastRealFrameTime = window.performance.now(); 61022 _this._setupDone = true; 61023 if (_this._accessibleOutputs.grid || _this._accessibleOutputs.text) { 61024 _this._updateAccsOutput(); 61025 } 61026 }; 61027 this._draw = function () { 61028 var now = window.performance.now(); 61029 var time_since_last = now - _this._lastTargetFrameTime; 61030 var target_time_between_frames = 1000 / _this._targetFrameRate; // only draw if we really need to; don't overextend the browser. 61031 // draw if we're within 5ms of when our next frame should paint 61032 // (this will prevent us from giving up opportunities to draw 61033 // again when it's really about time for us to do so). fixes an 61034 // issue where the frameRate is too low if our refresh loop isn't 61035 // in sync with the browser. note that we have to draw once even 61036 // if looping is off, so we bypass the time delay if that 61037 // is the case. 61038 var epsilon = 5; 61039 if (!_this._loop || time_since_last >= target_time_between_frames - epsilon) { 61040 //mandatory update values(matrixes and stack) 61041 _this.redraw(); 61042 _this._frameRate = 1000 / (now - _this._lastRealFrameTime); 61043 _this.deltaTime = now - _this._lastRealFrameTime; 61044 _this._setProperty('deltaTime', _this.deltaTime); 61045 _this._lastTargetFrameTime = Math.max(_this._lastTargetFrameTime + target_time_between_frames, now); 61046 _this._lastRealFrameTime = now; // If the user is actually using mouse module, then update 61047 // coordinates, otherwise skip. We can test this by simply 61048 // checking if any of the mouse functions are available or not. 61049 // NOTE : This reflects only in complete build or modular build. 61050 if (typeof _this._updateMouseCoords !== 'undefined') { 61051 _this._updateMouseCoords(); //reset delta values so they reset even if there is no mouse event to set them 61052 // for example if the mouse is outside the screen 61053 _this._setProperty('movedX', 0); 61054 _this._setProperty('movedY', 0); 61055 } 61056 } // get notified the next time the browser gives us 61057 // an opportunity to draw. 61058 61059 if (_this._loop) { 61060 _this._requestAnimId = window.requestAnimationFrame(_this._draw); 61061 } 61062 }; 61063 this._setProperty = function (prop, value) { 61064 _this[prop] = value; 61065 if (_this._isGlobal) { 61066 window[prop] = value; 61067 } 61068 }; 61069 /** 61070 * Removes the entire p5 sketch. This will remove the canvas and any 61071 * elements created by p5.js. It will also stop the draw loop and unbind 61072 * any properties or methods from the window global scope. It will 61073 * leave a variable p5 in case you wanted to create a new p5 sketch. 61074 * If you like, you can set p5 = null to erase it. While all functions and 61075 * variables and objects created by the p5 library will be removed, any 61076 * other global variables created by your code will remain. 61077 * 61078 * @method remove 61079 * @example 61080 * <div class='norender'><code> 61081 * function draw() { 61082 * ellipse(50, 50, 10, 10); 61083 * } 61084 * 61085 * function mousePressed() { 61086 * remove(); // remove whole sketch on mouse press 61087 * } 61088 * </code></div> 61089 * 61090 * @alt 61091 * nothing displayed 61092 * 61093 */ 61094 this.remove = function () { 61095 var loadingScreen = document.getElementById(_this._loadingScreenId); 61096 if (loadingScreen) { 61097 loadingScreen.parentNode.removeChild(loadingScreen); // Add 1 to preload counter to prevent the sketch ever executing setup() 61098 _this._incrementPreload(); 61099 } 61100 if (_this._curElement) { 61101 // stop draw 61102 _this._loop = false;
61103 if (_this._requestAnimId) { 61104 window.cancelAnimationFrame(_this._requestAnimId); 61105 } // unregister events sketch-wide 61106 61107 for (var ev in _this._events) { 61108 window.removeEventListener(ev, _this._events[ev]); 61109 } // remove DOM elements created by p5, and listeners 61110 61111 var _iteratorNormalCompletion3 = true; 61112 var _didIteratorError3 = false; 61113 var _iteratorError3 = undefined; 61114 try { 61115 for (var _iterator3 = _this._elements[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 61116 var e = _step3.value; 61117 if (e.elt && e.elt.parentNode) { 61118 e.elt.parentNode.removeChild(e.elt); 61119 } 61120 for (var elt_ev in e._events) { 61121 e.elt.removeEventListener(elt_ev, e._events[elt_ev]); 61122 } 61123 } // call any registered remove functions 61124 61125 } catch (err) { 61126 _didIteratorError3 = true; 61127 _iteratorError3 = err; 61128 } finally { 61129 try { 61130 if (!_iteratorNormalCompletion3 && _iterator3.return != null) { 61131 _iterator3.return(); 61132 } 61133 } finally { 61134 if (_didIteratorError3) { 61135 throw _iteratorError3; 61136 } 61137 } 61138 } 61139 var self = _this; 61140 _this._registeredMethods.remove.forEach(function (f) { 61141 if (typeof f !== 'undefined') { 61142 f.call(self); 61143 } 61144 }); 61145 } // remove window bound properties and methods 61146 61147 if (_this._isGlobal) { 61148 for (var p in p5.prototype) { 61149 try { 61150 delete window[p]; 61151 } catch (x) { 61152 window[p] = undefined; 61153 } 61154 } 61155 for (var p2 in _this) { 61156 if (_this.hasOwnProperty(p2)) { 61157 try { 61158 delete window[p2]; 61159 } catch (x) { 61160 window[p2] = undefined; 61161 } 61162 } 61163 } 61164 p5.instance = null; 61165 } 61166 }; // call any registered init functions 61167 this._registeredMethods.init.forEach(function (f) { 61168 if (typeof f !== 'undefined') { 61169 f.call(this); 61170 } 61171 }, this); // Set up promise preloads 61172 this._setupPromisePreloads(); 61173 var friendlyBindGlobal = this._createFriendlyGlobalFunctionBinder(); // If the user has created a global setup or draw function, 61174 // assume "global" mode and make everything global (i.e. on the window) 61175 if (!sketch) { 61176 this._isGlobal = true; 61177 p5.instance = this; // Loop through methods on the prototype and attach them to the window 61178 for (var p in p5.prototype) { 61179 if (typeof p5.prototype[p] === 'function') { 61180 var ev = p.substring(2); 61181 if (!this._events.hasOwnProperty(ev)) { 61182 if (Math.hasOwnProperty(p) && Math[p] === p5.prototype[p]) { 61183 // Multiple p5 methods are just native Math functions. These can be 61184 // called without any binding. 61185 friendlyBindGlobal(p, p5.prototype[p]); 61186 } else { 61187 friendlyBindGlobal(p, p5.prototype[p].bind(this)); 61188 } 61189 } 61190 } else { 61191 friendlyBindGlobal(p, p5.prototype[p]); 61192 } 61193 } // Attach its properties to the window 61194 61195 for (var p2 in this) { 61196 if (this.hasOwnProperty(p2)) { 61197 friendlyBindGlobal(p2, this[p2]); 61198 } 61199 } 61200 } else { 61201 // Else, the user has passed in a sketch closure that may set
61202 // user-provided 'setup', 'draw', etc. properties on this instance of p5 61203 sketch(this); // Run a check to see if the user has misspelled 'setup', 'draw', etc 61204 // detects capitalization mistakes only ( Setup, SETUP, MouseClicked, etc) 61205 p5._checkForUserDefinedFunctions(this); 61206 } // Bind events to window (not using container div bc key events don't work) 61207 61208 for (var e in this._events) { 61209 var f = this['_on'.concat(e)]; 61210 if (f) { 61211 var m = f.bind(this); 61212 window.addEventListener(e, m, { 61213 passive: false 61214 }); 61215 this._events[e] = m; 61216 } 61217 } 61218 var focusHandler = function focusHandler() { 61219 _this._setProperty('focused', true); 61220 }; 61221 var blurHandler = function blurHandler() { 61222 _this._setProperty('focused', false); 61223 }; 61224 window.addEventListener('focus', focusHandler); 61225 window.addEventListener('blur', blurHandler); 61226 this.registerMethod('remove', function () { 61227 window.removeEventListener('focus', focusHandler); 61228 window.removeEventListener('blur', blurHandler); 61229 }); 61230 if (document.readyState === 'complete') { 61231 this._start(); 61232 } else { 61233 window.addEventListener('load', this._start.bind(this), false); 61234 } 61235 } 61236 _createClass(p5, [ 61237 { 61238 key: '_initializeInstanceVariables', 61239 value: function _initializeInstanceVariables() { 61240 this._accessibleOutputs = { 61241 text: false, 61242 grid: false, 61243 textLabel: false, 61244 gridLabel: false 61245 }; 61246 this._styles = [ 61247 ]; 61248 this._bezierDetail = 20; 61249 this._curveDetail = 20; 61250 this._colorMode = constants.RGB; 61251 this._colorMaxes = { 61252 rgb: [ 61253 255, 61254 255, 61255 255, 61256 255 61257 ], 61258 hsb: [ 61259 360, 61260 100, 61261 100, 61262 1 61263 ], 61264 hsl: [ 61265 360, 61266 100, 61267 100, 61268 1 61269 ] 61270 }; 61271 this._downKeys = { 61272 }; //Holds the key codes of currently pressed keys 61273 } 61274 }, 61275 { 61276 key: 'registerPreloadMethod', 61277 value: function registerPreloadMethod(fnString, obj) { 61278 // obj = obj || p5.prototype; 61279 if (!p5.prototype._preloadMethods.hasOwnProperty(fnString)) { 61280 p5.prototype._preloadMethods[fnString] = obj; 61281 } 61282 } 61283 }, 61284 { 61285 key: 'registerMethod', 61286 value: function registerMethod(name, m) { 61287 var target = this || p5.prototype; 61288 if (!target._registeredMethods.hasOwnProperty(name)) { 61289 target._registeredMethods[name] = [ 61290 ]; 61291 } 61292 target._registeredMethods[name].push(m); 61293 } // create a function which provides a standardized process for binding 61294 // globals; this is implemented as a factory primarily so that there's a 61295 // way to redefine what "global" means for the binding function so it 61296 // can be used in scenarios like unit testing where the window object 61297 // might not exist 61298 61299 }, 61300 { 61301 key: '_createFriendlyGlobalFunctionBinder', 61302 value: function _createFriendlyGlobalFunctionBinder() { 61303 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 61304 }; 61305 var globalObject = options.globalObject || window; 61306 var log = options.log || console.log.bind(console); 61307 var propsToForciblyOverwrite = { 61308 // p5.print actually always overwrites an existing global function, 61309 // albeit one that is very unlikely to be used: 61310 // 61311 // https://developer.mozilla.org/en-US/docs/Web/API/Window/print 61312 print: true 61313 }; 61314 return function (prop, value) { 61315 if (!p5.disableFriendlyErrors && typeof IS_MINIFIED === 'undefined' && typeof value === 'function' && !(prop in p5.prototype._preloadMethods)) { 61316 try { 61317 // Because p5 has so many common function names, it's likely 61318 // that users may accidentally overwrite global p5 functions with 61319 // their own variables. Let's allow this but log a warning to 61320 // help users who may be doing this unintentionally. 61321 // 61322 // For more information, see: 61323 // 61324 // https://github.com/processing/p5.js/issues/1317 61325 if (prop in globalObject && !(prop in propsToForciblyOverwrite)) { 61326 throw new Error('global "'.concat(prop, '" already exists')); 61327 } // It's possible that this might throw an error because there 61328 // are a lot of edge-cases in which `Object.defineProperty` might 61329 // not succeed; since this functionality is only intended to 61330 // help beginners anyways, we'll just catch such an exception 61331 // if it occurs, and fall back to legacy behavior. 61332 61333 Object.defineProperty(globalObject, prop, { 61334 configurable: true, 61335 enumerable: true, 61336 get: function get() { 61337 return value; 61338 }, 61339 set: function set(newValue) { 61340 Object.defineProperty(globalObject, prop, { 61341 configurable: true, 61342 enumerable: true, 61343 value: newValue, 61344 writable: true 61345 }); 61346 log('You just changed the value of "'.concat(prop, '", which was a p5 function. This could cause problems later if you\'re not careful.')); 61347 } 61348 }); 61349 } catch (e) { 61350 var message = 'p5 had problems creating the global function "'.concat(prop, '", possibly because your co
61350de is already using that name as a variable. You may want to rename your variable to something else.'); 61351 p5._friendlyError(message, prop); 61352 globalObject[prop] = value; 61353 } 61354 } else { 61355 globalObject[prop] = value; 61356 } 61357 }; 61358 } 61359 } 61360 ]); 61361 return p5; 61362 }(); // This is a pointer to our global mode p5 instance, if we're in 61363 // global mode. 61364 p5.instance = null; 61365 /** 61366 * Turn off some features of the friendly error system (FES), which can give 61367 * a significant boost to performance when needed. 61368 * 61369 * Note that this will disable the parts of the FES that cause performance 61370 * slowdown (like argument checking). Friendly errors that have no performance 61371 * cost (like giving a descriptive error if a file load fails, or warning you 61372 * if you try to override p5.js functions in the global space), 61373 * will remain in place. 61374 * 61375 * See <a href='https://github.com/processing/p5.js/wiki/Optimizing-p5.js-Code-for-Performance#disable-the-friendly-error-system-fes'> 61376 * disabling the friendly error system</a>. 61377 * 61378 * @property {Boolean} disableFriendlyErrors 61379 * @example 61380 * <div class="norender notest"><code> 61381 * p5.disableFriendlyErrors = true; 61382 * 61383 * function setup() { 61384 * createCanvas(100, 50); 61385 * } 61386 * </code></div> 61387 */ 61388 p5.disableFriendlyErrors = false; // attach constants to p5 prototype 61389 for (var k in constants) { 61390 p5.prototype[k] = constants[k]; 61391 } // makes the `VERSION` constant available on the p5 object 61392 // in instance mode, even if it hasn't been instatiated yet 61393 61394 p5.VERSION = constants.VERSION; // functions that cause preload to wait 61395 // more can be added by using registerPreloadMethod(func) 61396 p5.prototype._preloadMethods = { 61397 loadJSON: p5.prototype, 61398 loadImage: p5.prototype, 61399 loadStrings: p5.prototype, 61400 loadXML: p5.prototype, 61401 loadBytes: p5.prototype, 61402 loadTable: p5.prototype, 61403 loadFont: p5.prototype, 61404 loadModel: p5.prototype, 61405 loadShader: p5.prototype 61406 }; 61407 p5.prototype._registeredMethods = { 61408 init: [ 61409 ], 61410 pre: [ 61411 ], 61412 post: [ 61413 ], 61414 remove: [ 61415 ] 61416 }; 61417 p5.prototype._registeredPreloadMethods = { 61418 }; 61419 var _default = p5; 61420 exports.default = _default; 61421 }, 61422 { 61423 './constants': 278, 61424 './shim': 301, 61425 'core-js/modules/es.array.for-each': 172, 61426 'core-js/modules/es.array.iterator': 176, 61427 'core-js/modules/es.array.slice': 180, 61428 'core-js/modules/es.object.get-own-property-descriptor': 191, 61429 'core-js/modules/es.object.get-own-property-names': 192, 61430 'core-js/modules/es.object.to-string': 195, 61431 'core-js/modules/es.string.iterator': 204, 61432 'core-js/modules/es.symbol': 214, 61433 'core-js/modules/es.symbol.description': 212, 61434 'core-js/modules/es.symbol.iterator': 213, 61435 'core-js/modules/es.weak-map': 246, 61436 'core-js/modules/web.dom-collections.for-each': 247, 61437 'core-js/modules/web.dom-collections.iterator': 248 61438 } 61439 ], 61440 291: [ 61441 function (_dereq_, module, exports) { 61442 'use strict'; 61443 Object.defineProperty(exports, '__esModule', { 61444 value: true 61445 }); 61446 exports.default = void 0; 61447 var _main = _interopRequireDefault(_dereq_('./main')); 61448 function _interopRequireDefault(obj) { 61449 return obj && obj.__esModule ? obj : { 61450 default: 61451 obj 61452 }; 61453 } /** 61454 * @module DOM 61455 * @submodule DOM 61456 * @for p5.Element 61457 */ 61458 /** 61459 * Base class for all elements added to a sketch, including canvas, 61460 * graphics buffers, and other HTML elements. It is not called directly, but <a href="#/p5.Element">p5.Element</a> 61461 * objects are created by calling <a href="#/p5/createCanvas">createCanvas()</a>, <a href="#/p5/createGraphics">createGraphics()</a>, 61462 * <a href="#/p5/createDiv">createDiv()</a>, <a href="#/p5/createImg">createImg()</a>, <a href="#/p5/createInput">createInput()</a>, etc. 61463 * 61464 * @class p5.Element 61465 * @constructor 61466 * @param {String} elt DOM node that is wrapped 61467 * @param {p5} [pInst] pointer to p5 instance 61468 */ 61469 61470 _main.default.Element = function (elt, pInst) { 61471 /** 61472 * Underlying HTML element. All normal HTML methods can be called on this. 61473 * @example 61474 * <div> 61475 * <code> 61476 * function setup() { 61477 * let c = createCanvas(50, 50); 61478 * c.elt.style.border = '5px solid red'; 61479 * } 61480 * 61481 * function draw() { 61482 * background(220); 61483 * } 61484 * </code> 61485 * </div> 61486 * 61487 * @property elt 61488 * @readOnly 61489 */ 61490 this.elt = elt; 61491 this._pInst = this._pixelsState = pInst; 61492 this._events = { 61493 }; 61494 this.width = this.elt.offsetWidth; 61495 this.height = this.elt.offsetHeight; 61496 }; 61497 /** 61498 * 61499 * Attaches the element to the parent specified. A way of setting 61500 * the container for the element. Accepts either a string ID, DOM 61501 * node, or <a href="#/p5.Element">p5.Element</a>. If no arguments are given, parent node is returned. 61502 * For more ways to position the canvas, see the 61503 * <a href='https://github.com/processing/p5.js/wiki/Positioning-your-canvas'> 61504 * positioning the canvas</a> wiki page. 61505 * 61506 * @method parent
61507 * @param {String|p5.Element|Object} parent the ID, DOM node, or <a href="#/p5.Element">p5.Element</a> 61508 * of desired parent element 61509 * @chainable 61510 * 61511 * @example 61512 * <div class="norender notest"><code> 61513 * // Add the following comment to html file. 61514 * // <div id="myContainer"></div> 61515 * 61516 * // The js code 61517 * let cnv = createCanvas(100, 100); 61518 * cnv.parent('myContainer'); 61519 * </code></div> 61520 * 61521 * <div class='norender'><code> 61522 * let div0 = createDiv('this is the parent'); 61523 * let div1 = createDiv('this is the child'); 61524 * div1.parent(div0); // use p5.Element 61525 * </code></div> 61526 * 61527 * <div class='norender'><code> 61528 * let div0 = createDiv('this is the parent'); 61529 * div0.id('apples'); 61530 * let div1 = createDiv('this is the child'); 61531 * div1.parent('apples'); // use id 61532 * </code></div> 61533 * 61534 * <div class='norender notest'><code> 61535 * let elt = document.getElementById('myParentDiv'); 61536 * let div1 = createDiv('this is the child'); 61537 * div1.parent(elt); // use element from page 61538 * </code></div> 61539 * 61540 * @alt 61541 * no display. 61542 */ 61543 /** 61544 * @method parent 61545 * @return {p5.Element} 61546 */ 61547 _main.default.Element.prototype.parent = function (p) { 61548 if (typeof p === 'undefined') { 61549 return this.elt.parentNode; 61550 } 61551 if (typeof p === 'string') { 61552 if (p[0] === '#') { 61553 p = p.substring(1); 61554 } 61555 p = document.getElementById(p); 61556 } else if (p instanceof _main.default.Element) { 61557 p = p.elt; 61558 } 61559 p.appendChild(this.elt); 61560 return this; 61561 }; 61562 /** 61563 * 61564 * Sets the ID of the element. If no ID argument is passed in, it instead 61565 * returns the current ID of the element. 61566 * Note that only one element can have a particular id in a page. 61567 * The <a href="#/p5.Element/class">class()</a> method can be used 61568 * to identify multiple elements with the same class name. 61569 * 61570 * @method id 61571 * @param {String} id ID of the element 61572 * @chainable 61573 * 61574 * @example 61575 * <div class='norender'><code> 61576 * function setup() { 61577 * let cnv = createCanvas(100, 100); 61578 * // Assigns a CSS selector ID to 61579 * // the canvas element. 61580 * cnv.id('mycanvas'); 61581 * } 61582 * </code></div> 61583 * 61584 * @alt 61585 * no display. 61586 */ 61587 /** 61588 * @method id 61589 * @return {String} the id of the element 61590 */ 61591 _main.default.Element.prototype.id = function (id) { 61592 if (typeof id === 'undefined') { 61593 return this.elt.id; 61594 } 61595 this.elt.id = id; 61596 this.width = this.elt.offsetWidth; 61597 this.height = this.elt.offsetHeight; 61598 return this; 61599 }; 61600 /** 61601 * 61602 * Adds given class to the element. If no class argument is passed in, it 61603 * instead returns a string containing the current class(es) of the element. 61604 * 61605 * @method class 61606 * @param {String} class class to add 61607 * @chainable 61608 * 61609 * @example 61610 * <div class='norender'><code> 61611 * function setup() { 61612 * let cnv = createCanvas(100, 100); 61613 * // Assigns a CSS selector class 'small' 61614 * // to the canvas element. 61615 * cnv.class('small'); 61616 * } 61617 * </code></div> 61618 * 61619 * @alt 61620 * no display. 61621 */ 61622 /** 61623 * @method class 61624 * @return {String} the class of the element 61625 */ 61626 _main.default.Element.prototype.class = function (c) { 61627 if (typeof c === 'undefined') { 61628 return this.elt.className; 61629 } 61630 this.elt.className = c; 61631 return this; 61632 }; 61633 /** 61634 * The <a href="#/p5.Element/mousePressed">mousePressed()</a> method is called 61635 * once after every time a mouse button is pressed over the element. Some mobile 61636 * browsers may also trigger this event on a touch screen, if the user performs 61637 * a quick tap. This can be used to attach element-specific event listeners. 61638 * 61639 * @method mousePressed 61640 * @param {Function|Boolean} fxn function to be fired when mouse is 61641 * pressed over the element. 61642 * if `false` is passed instead, the previously 61643 * firing function will no longer fire. 61644 * @chainable 61645 * @example 61646 * <div class='norender'><code> 61647 * let cnv, d, g; 61648 * function setup() { 61649 * cnv = createCanvas(100, 100); 61650 * cnv.mousePressed(changeGray); // attach listener for 61651 * // canvas click only 61652 * d = 10; 61653 * g = 100; 61654 * } 61655 * 61656 * function draw() { 61657 * background(g); 61658 * ellipse(width / 2, height / 2, d, d); 61659 * } 61660 *
61661 * // this function fires with any click anywhere 61662 * function mousePressed() { 61663 * d = d + 10; 61664 * } 61665 * 61666 * // this function fires only when cnv is clicked 61667 * function changeGray() { 61668 * g = random(0, 255); 61669 * } 61670 * </code></div> 61671 * 61672 * @alt 61673 * no display. 61674 */ 61675 _main.default.Element.prototype.mousePressed = function (fxn) { 61676 // Prepend the mouse property setters to the event-listener. 61677 // This is required so that mouseButton is set correctly prior to calling the callback (fxn). 61678 // For details, see https://github.com/processing/p5.js/issues/3087. 61679 var eventPrependedFxn = function eventPrependedFxn(event) { 61680 this._pInst._setProperty('mouseIsPressed', true); 61681 this._pInst._setMouseButton(event); // Pass along the return-value of the callback: 61682 return fxn.call(this, event); 61683 }; // Pass along the event-prepended form of the callback. 61684 _main.default.Element._adjustListener('mousedown', eventPrependedFxn, this); 61685 return this; 61686 }; 61687 /** 61688 * The <a href="#/p5.Element/doubleClicked">doubleClicked()</a> method is called once after every time a 61689 * mouse button is pressed twice over the element. This can be used to 61690 * attach element and action-specific event listeners. 61691 * 61692 * @method doubleClicked 61693 * @param {Function|Boolean} fxn function to be fired when mouse is 61694 * double clicked over the element. 61695 * if `false` is passed instead, the previously 61696 * firing function will no longer fire. 61697 * @return {p5.Element} 61698 * @example 61699 * <div class='norender'><code> 61700 * let cnv, d, g; 61701 * function setup() { 61702 * cnv = createCanvas(100, 100); 61703 * cnv.doubleClicked(changeGray); // attach listener for 61704 * // canvas double click only 61705 * d = 10; 61706 * g = 100; 61707 * } 61708 * 61709 * function draw() { 61710 * background(g); 61711 * ellipse(width / 2, height / 2, d, d); 61712 * } 61713 * 61714 * // this function fires with any double click anywhere 61715 * function doubleClicked() { 61716 * d = d + 10; 61717 * } 61718 * 61719 * // this function fires only when cnv is double clicked 61720 * function changeGray() { 61721 * g = random(0, 255); 61722 * } 61723 * </code></div> 61724 * 61725 * @alt 61726 * no display. 61727 */ 61728 _main.default.Element.prototype.doubleClicked = function (fxn) { 61729 _main.default.Element._adjustListener('dblclick', fxn, this); 61730 return this; 61731 }; 61732 /** 61733 * The <a href="#/p5.Element/mouseWheel">mouseWheel()</a> method is called 61734 * once after every time a mouse wheel is scrolled over the element. This can 61735 * be used to attach element-specific event listeners. 61736 * 61737 * The method accepts a callback function as argument which will be executed 61738 * when the `wheel` event is triggered on the element, the callback function is 61739 * passed one argument `event`. The `event.deltaY` property returns negative 61740 * values if the mouse wheel is rotated up or away from the user and positive 61741 * in the other direction. The `event.deltaX` does the same as `event.deltaY` 61742 * except it reads the horizontal wheel scroll of the mouse wheel. 61743 * 61744 * On macOS with "natural" scrolling enabled, the `event.deltaY` values are 61745 * reversed. 61746 * 61747 * @method mouseWheel 61748 * @param {Function|Boolean} fxn function to be fired when mouse is 61749 * scrolled over the element. 61750 * if `false` is passed instead, the previously 61751 * firing function will no longer fire. 61752 * @chainable 61753 * @example 61754 * <div class='norender'><code> 61755 * let cnv, d, g; 61756 * function setup() { 61757 * cnv = createCanvas(100, 100); 61758 * cnv.mouseWheel(changeSize); // attach listener for 61759 * // activity on canvas only 61760 * d = 10; 61761 * g = 100; 61762 * } 61763 * 61764 * function draw() { 61765 * background(g); 61766 * ellipse(width / 2, height / 2, d, d); 61767 * } 61768 * 61769 * // this function fires with mousewheel movement 61770 * // anywhere on screen 61771 * function mouseWheel() { 61772 * g = g + 10; 61773 * } 61774 * 61775 * // this function fires with mousewheel movement 61776 * // over canvas only 61777 * function changeSize(event) { 61778 * if (event.deltaY > 0) { 61779 * d = d + 10; 61780 * } else { 61781 * d = d - 10; 61782 * } 61783 * } 61784 * </code></div> 61785 * 61786 * @alt
61787 * no display. 61788 */ 61789 _main.default.Element.prototype.mouseWheel = function (fxn) { 61790 _main.default.Element._adjustListener('wheel', fxn, this); 61791 return this; 61792 }; 61793 /** 61794 * The <a href="#/p5.Element/mouseReleased">mouseReleased()</a> method is 61795 * called once after every time a mouse button is released over the element. 61796 * Some mobile browsers may also trigger this event on a touch screen, if the 61797 * user performs a quick tap. This can be used to attach element-specific event listeners. 61798 * 61799 * @method mouseReleased 61800 * @param {Function|Boolean} fxn function to be fired when mouse is 61801 * released over the element. 61802 * if `false` is passed instead, the previously 61803 * firing function will no longer fire. 61804 * @chainable 61805 * @example 61806 * <div class='norender'><code> 61807 * let cnv, d, g; 61808 * function setup() { 61809 * cnv = createCanvas(100, 100); 61810 * cnv.mouseReleased(changeGray); // attach listener for 61811 * // activity on canvas only 61812 * d = 10; 61813 * g = 100; 61814 * } 61815 * 61816 * function draw() { 61817 * background(g); 61818 * ellipse(width / 2, height / 2, d, d); 61819 * } 61820 * 61821 * // this function fires after the mouse has been 61822 * // released 61823 * function mouseReleased() { 61824 * d = d + 10; 61825 * } 61826 * 61827 * // this function fires after the mouse has been 61828 * // released while on canvas 61829 * function changeGray() { 61830 * g = random(0, 255); 61831 * } 61832 * </code></div> 61833 * 61834 * @alt 61835 * no display. 61836 */ 61837 _main.default.Element.prototype.mouseReleased = function (fxn) { 61838 _main.default.Element._adjustListener('mouseup', fxn, this); 61839 return this; 61840 }; 61841 /** 61842 * The <a href="#/p5.Element/mouseClicked">mouseClicked()</a> method is 61843 * called once after a mouse button is pressed and released over the element. 61844 * Some mobile browsers may also trigger this event on a touch screen, if the 61845 * user performs a quick tap. This can be used to attach element-specific event listeners. 61846 * 61847 * @method mouseClicked 61848 * @param {Function|Boolean} fxn function to be fired when mouse is 61849 * clicked over the element. 61850 * if `false` is passed instead, the previously 61851 * firing function will no longer fire. 61852 * @chainable 61853 * @example 61854 * <div class="norender"> 61855 * <code> 61856 * let cnv, d, g; 61857 * function setup() { 61858 * cnv = createCanvas(100, 100); 61859 * cnv.mouseClicked(changeGray); // attach listener for 61860 * // activity on canvas only 61861 * d = 10; 61862 * g = 100; 61863 * } 61864 * 61865 * function draw() { 61866 * background(g); 61867 * ellipse(width / 2, height / 2, d, d); 61868 * } 61869 * 61870 * // this function fires after the mouse has been 61871 * // clicked anywhere 61872 * function mouseClicked() { 61873 * d = d + 10; 61874 * } 61875 * 61876 * // this function fires after the mouse has been 61877 * // clicked on canvas 61878 * function changeGray() { 61879 * g = random(0, 255); 61880 * } 61881 * </code> 61882 * </div> 61883 * 61884 * @alt 61885 * no display. 61886 */ 61887 _main.default.Element.prototype.mouseClicked = function (fxn) { 61888 _main.default.Element._adjustListener('click', fxn, this); 61889 return this; 61890 }; 61891 /** 61892 * The <a href="#/p5.Element/mouseMoved">mouseMoved()</a> method is called once every time a 61893 * mouse moves over the element. This can be used to attach an 61894 * element-specific event listener. 61895 * 61896 * @method mouseMoved 61897 * @param {Function|Boolean} fxn function to be fired when a mouse moves 61898 * over the element. 61899 * if `false` is passed instead, the previously 61900 * firing function will no longer fire. 61901 * @chainable 61902 * @example 61903 * <div class='norender'><code> 61904 * let cnv; 61905 * let d = 30; 61906 * let g; 61907 * function setup() { 61908 * cnv = createCanvas(100, 100); 61909 * cnv.mouseMoved(changeSize); // attach listener for 61910 * // activity on canvas only 61911 * d = 10; 61912 * g = 100; 61913 * } 61914 * 61915 * function draw() { 61916 * background(g); 61917 * fill(200); 61918 * ellipse(width / 2, height / 2, d, d); 61919 * } 61920 * 61921 * // this function fires when mouse moves anywhere on 61922 * // page 61923 * function mouseMoved() { 61924 * g = g + 5; 61925 * if (g > 255) { 61926 * g = 0; 61927 * } 61928 * } 61929 * 61930 * // this function fires when mouse moves over canvas 61931 * function changeSize() { 61932 * d = d + 2; 61933 * if (d > 100) { 61934 * d = 0; 61935 * } 61936 * } 61937 * </code></div> 61938 * 61939 * @alt
61940 * no display. 61941 */ 61942 _main.default.Element.prototype.mouseMoved = function (fxn) { 61943 _main.default.Element._adjustListener('mousemove', fxn, this); 61944 return this; 61945 }; 61946 /** 61947 * The <a href="#/p5.Element/mouseOver">mouseOver()</a> method is called once after every time a 61948 * mouse moves onto the element. This can be used to attach an 61949 * element-specific event listener. 61950 * 61951 * @method mouseOver 61952 * @param {Function|Boolean} fxn function to be fired when a mouse moves 61953 * onto the element. 61954 * if `false` is passed instead, the previously 61955 * firing function will no longer fire. 61956 * @chainable 61957 * @example 61958 * <div class='norender'><code> 61959 * let cnv; 61960 * let d; 61961 * function setup() { 61962 * cnv = createCanvas(100, 100); 61963 * cnv.mouseOver(changeGray); 61964 * d = 10; 61965 * } 61966 * 61967 * function draw() { 61968 * ellipse(width / 2, height / 2, d, d); 61969 * } 61970 * 61971 * function changeGray() { 61972 * d = d + 10; 61973 * if (d > 100) { 61974 * d = 0; 61975 * } 61976 * } 61977 * </code></div> 61978 * 61979 * @alt 61980 * no display. 61981 */ 61982 _main.default.Element.prototype.mouseOver = function (fxn) { 61983 _main.default.Element._adjustListener('mouseover', fxn, this); 61984 return this; 61985 }; 61986 /** 61987 * The <a href="#/p5.Element/mouseOut">mouseOut()</a> method is called once after every time a 61988 * mouse moves off the element. This can be used to attach an 61989 * element-specific event listener. 61990 * 61991 * @method mouseOut 61992 * @param {Function|Boolean} fxn function to be fired when a mouse 61993 * moves off of an element. 61994 * if `false` is passed instead, the previously 61995 * firing function will no longer fire. 61996 * @chainable 61997 * @example 61998 * <div class='norender'><code> 61999 * let cnv; 62000 * let d; 62001 * function setup() { 62002 * cnv = createCanvas(100, 100); 62003 * cnv.mouseOut(changeGray); 62004 * d = 10; 62005 * } 62006 * 62007 * function draw() { 62008 * ellipse(width / 2, height / 2, d, d); 62009 * } 62010 * 62011 * function changeGray() { 62012 * d = d + 10; 62013 * if (d > 100) { 62014 * d = 0; 62015 * } 62016 * } 62017 * </code></div> 62018 * 62019 * @alt 62020 * no display. 62021 */ 62022 _main.default.Element.prototype.mouseOut = function (fxn) { 62023 _main.default.Element._adjustListener('mouseout', fxn, this); 62024 return this; 62025 }; 62026 /** 62027 * The <a href="#/p5.Element/touchStarted">touchStarted()</a> method is called once after every time a touch is 62028 * registered. This can be used to attach element-specific event listeners. 62029 * 62030 * @method touchStarted 62031 * @param {Function|Boolean} fxn function to be fired when a touch 62032 * starts over the element. 62033 * if `false` is passed instead, the previously 62034 * firing function will no longer fire. 62035 * @chainable 62036 * @example 62037 * <div class='norender'><code> 62038 * let cnv; 62039 * let d; 62040 * let g; 62041 * function setup() { 62042 * cnv = createCanvas(100, 100); 62043 * cnv.touchStarted(changeGray); // attach listener for 62044 * // canvas click only 62045 * d = 10; 62046 * g = 100; 62047 * } 62048 * 62049 * function draw() { 62050 * background(g); 62051 * ellipse(width / 2, height / 2, d, d); 62052 * } 62053 * 62054 * // this function fires with any touch anywhere 62055 * function touchStarted() { 62056 * d = d + 10; 62057 * } 62058 * 62059 * // this function fires only when cnv is clicked 62060 * function changeGray() { 62061 * g = random(0, 255); 62062 * } 62063 * </code></div> 62064 * 62065 * @alt 62066 * no display. 62067 */ 62068 _main.default.Element.prototype.touchStarted = function (fxn) { 62069 _main.default.Element._adjustListener('touchstart', fxn, this); 62070 return this; 62071 }; 62072 /** 62073 * The <a href="#/p5.Element/touchMoved">touchMoved()</a> method is called once after every time a touch move is 62074 * registered. This can be used to attach element-specific event listeners. 62075 * 62076 * @method touchMoved 62077 * @param {Function|Boolean} fxn function to be fired when a touch moves over 62078 * the element. 62079 * if `false` is passed instead, the previously 62080 * firing function will no longer fire. 62081 * @chainable 62082 * @example 62083 * <div class='norender'><code> 62084 * let cnv; 62085 * let g; 62086 * function setup() { 62087 * cnv = createCanvas(100, 100); 62088 * cnv.touchMoved(changeGray); // attach listener for 62089 * // canvas click only 62090 * g = 100; 62091 * } 62092 * 62093 * function draw() { 62094 * background(g); 62095 * } 62096 * 62097 * // this function fires only when cnv is clicked 62098 * function changeGray() { 62099 * g = random(0, 255); 62100 * } 62101 * </code></div> 62102 * 62103 * @alt
62104 * no display. 62105 */ 62106 _main.default.Element.prototype.touchMoved = function (fxn) { 62107 _main.default.Element._adjustListener('touchmove', fxn, this); 62108 return this; 62109 }; 62110 /** 62111 * The <a href="#/p5.Element/touchEnded">touchEnded()</a> method is called once after every time a touch is 62112 * registered. This can be used to attach element-specific event listeners. 62113 * 62114 * @method touchEnded 62115 * @param {Function|Boolean} fxn function to be fired when a touch ends 62116 * over the element. 62117 * if `false` is passed instead, the previously 62118 * firing function will no longer fire. 62119 * @chainable 62120 * @example 62121 * <div class='norender'><code> 62122 * let cnv; 62123 * let d; 62124 * let g; 62125 * function setup() { 62126 * cnv = createCanvas(100, 100); 62127 * cnv.touchEnded(changeGray); // attach listener for 62128 * // canvas click only 62129 * d = 10; 62130 * g = 100; 62131 * } 62132 * 62133 * function draw() { 62134 * background(g); 62135 * ellipse(width / 2, height / 2, d, d); 62136 * } 62137 * 62138 * // this function fires with any touch anywhere 62139 * function touchEnded() { 62140 * d = d + 10; 62141 * } 62142 * 62143 * // this function fires only when cnv is clicked 62144 * function changeGray() { 62145 * g = random(0, 255); 62146 * } 62147 * </code></div> 62148 * 62149 * @alt 62150 * no display. 62151 */ 62152 _main.default.Element.prototype.touchEnded = function (fxn) { 62153 _main.default.Element._adjustListener('touchend', fxn, this); 62154 return this; 62155 }; 62156 /** 62157 * The <a href="#/p5.Element/dragOver">dragOver()</a> method is called once after every time a 62158 * file is dragged over the element. This can be used to attach an 62159 * element-specific event listener. 62160 * 62161 * @method dragOver 62162 * @param {Function|Boolean} fxn function to be fired when a file is 62163 * dragged over the element. 62164 * if `false` is passed instead, the previously 62165 * firing function will no longer fire. 62166 * @chainable 62167 * @example 62168 * <div><code> 62169 * // To test this sketch, simply drag a 62170 * // file over the canvas 62171 * function setup() { 62172 * let c = createCanvas(100, 100); 62173 * background(200); 62174 * textAlign(CENTER); 62175 * text('Drag file', width / 2, height / 2); 62176 * c.dragOver(dragOverCallback); 62177 * } 62178 * 62179 * // This function will be called whenever 62180 * // a file is dragged over the canvas 62181 * function dragOverCallback() { 62182 * background(240); 62183 * text('Dragged over', width / 2, height / 2); 62184 * } 62185 * </code></div> 62186 * @alt 62187 * nothing displayed 62188 */ 62189 _main.default.Element.prototype.dragOver = function (fxn) { 62190 _main.default.Element._adjustListener('dragover', fxn, this); 62191 return this; 62192 }; 62193 /** 62194 * The <a href="#/p5.Element/dragLeave">dragLeave()</a> method is called once after every time a 62195 * dragged file leaves the element area. This can be used to attach an 62196 * element-specific event listener. 62197 * 62198 * @method dragLeave 62199 * @param {Function|Boolean} fxn function to be fired when a file is 62200 * dragged off the element. 62201 * if `false` is passed instead, the previously 62202 * firing function will no longer fire. 62203 * @chainable 62204 * @example 62205 * <div><code> 62206 * // To test this sketch, simply drag a file 62207 * // over and then out of the canvas area 62208 * function setup() { 62209 * let c = createCanvas(100, 100); 62210 * background(200); 62211 * textAlign(CENTER); 62212 * text('Drag file', width / 2, height / 2); 62213 * c.dragLeave(dragLeaveCallback); 62214 * } 62215 * 62216 * // This function will be called whenever 62217 * // a file is dragged out of the canvas 62218 * function dragLeaveCallback() { 62219 * background(240); 62220 * text('Dragged off', width / 2, height / 2); 62221 * } 62222 * </code></div> 62223 * @alt 62224 * nothing displayed 62225 */ 62226 _main.default.Element.prototype.dragLeave = function (fxn) { 62227 _main.default.Element._adjustListener('dragleave', fxn, this); 62228 return this; 62229 }; // General handler for event attaching and detaching 62230 _main.default.Element._adjustListener = function (ev, fxn, ctx) { 62231 if (fxn === false) { 62232 _main.default.Element._detachListener(ev, ctx); 62233 } else { 62234 _main.default.Element._attachListener(ev, fxn, ctx); 62235 } 62236 return this; 62237 }; 62238 _main.default.Element._attachListener = function (ev, fxn, ctx) { 62239 // detach the old listener if there was one 62240 if (ctx._events[ev]) { 62241 _main.default.Element._detachListener(ev, ctx); 62242 } 62243 var f = fxn.bind(ctx); 62244 ctx.elt.addEventListener(ev, f, false); 62245 ctx._events[ev] = f; 62246 }; 62247 _main.default.Element._detachListener = function (ev, ctx) { 62248 var f = ctx._events[ev]; 62249 ctx.elt.removeEventListener(ev, f, false); 62250 ctx._events[ev] = null; 62251 }; 62252 /** 62253 * Helper fxn for sharing pixel methods 62254 */ 62255 _main.default.Element.prototype._setProperty = function (prop, value) { 62256 this[prop] = value; 62257 }; 62258 var _default = _main.default.Element; 62259 exports.default = _default; 62260 }, 62261 { 62262 './main': 290 62263 } 62264 ], 62265 292: [
62266 function (_dereq_, module, exports) { 62267 'use strict'; 62268 _dereq_('core-js/modules/es.symbol'); 62269 _dereq_('core-js/modules/es.symbol.description'); 62270 _dereq_('core-js/modules/es.symbol.iterator'); 62271 _dereq_('core-js/modules/es.array.index-of'); 62272 _dereq_('core-js/modules/es.array.iterator'); 62273 _dereq_('core-js/modules/es.array.splice'); 62274 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 62275 _dereq_('core-js/modules/es.object.to-string'); 62276 _dereq_('core-js/modules/es.string.iterator'); 62277 _dereq_('core-js/modules/es.weak-map'); 62278 _dereq_('core-js/modules/web.dom-collections.iterator'); 62279 function _typeof2(obj) { 62280 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 62281 _typeof2 = function _typeof2(obj) { 62282 return typeof obj; 62283 }; 62284 } else { 62285 _typeof2 = function _typeof2(obj) { 62286 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 62287 }; 62288 } 62289 return _typeof2(obj); 62290 } 62291 function _typeof(obj) { 62292 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 62293 _typeof = function _typeof(obj) { 62294 return _typeof2(obj); 62295 }; 62296 } else { 62297 _typeof = function _typeof(obj) { 62298 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 62299 }; 62300 } 62301 return _typeof(obj); 62302 } 62303 _dereq_('core-js/modules/es.array.index-of'); 62304 _dereq_('core-js/modules/es.array.splice'); 62305 Object.defineProperty(exports, '__esModule', { 62306 value: true 62307 }); 62308 exports.default = void 0; 62309 var _main = _interopRequireDefault(_dereq_('./main')); 62310 var constants = _interopRequireWildcard(_dereq_('./constants')); 62311 function _getRequireWildcardCache() { 62312 if (typeof WeakMap !== 'function') return null; 62313 var cache = new WeakMap(); 62314 _getRequireWildcardCache = function _getRequireWildcardCache() { 62315 return cache; 62316 }; 62317 return cache; 62318 } 62319 function _interopRequireWildcard(obj) { 62320 if (obj && obj.__esModule) { 62321 return obj; 62322 } 62323 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 62324 return { 62325 default: 62326 obj 62327 }; 62328 } 62329 var cache = _getRequireWildcardCache(); 62330 if (cache && cache.has(obj)) { 62331 return cache.get(obj); 62332 } 62333 var newObj = { 62334 }; 62335 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 62336 for (var key in obj) { 62337 if (Object.prototype.hasOwnProperty.call(obj, key)) { 62338 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 62339 if (desc && (desc.get || desc.set)) { 62340 Object.defineProperty(newObj, key, desc); 62341 } else { 62342 newObj[key] = obj[key]; 62343 } 62344 } 62345 } 62346 newObj.default = obj; 62347 if (cache) { 62348 cache.set(obj, newObj); 62349 } 62350 return newObj; 62351 } 62352 function _interopRequireDefault(obj) { 62353 return obj && obj.__esModule ? obj : { 62354 default: 62355 obj 62356 }; 62357 } /** 62358 * @module Rendering 62359 * @submodule Rendering 62360 * @for p5 62361 */ 62362 /** 62363 * Thin wrapper around a renderer, to be used for creating a 62364 * graphics buffer object. Use this class if you need 62365 * to draw into an off-screen graphics buffer. The two parameters define the 62366 * width and height in pixels. The fields and methods for this class are 62367 * extensive, but mirror the normal drawing API for p5. 62368 * 62369 * @class p5.Graphics 62370 * @constructor 62371 * @extends p5.Element 62372 * @param {Number} w width 62373 * @param {Number} h height 62374 * @param {Constant} renderer the renderer to use, either P2D or WEBGL 62375 * @param {p5} [pInst] pointer to p5 instance 62376 */ 62377 62378 _main.default.Graphics = function (w, h, renderer, pInst) { 62379 var r = renderer || constants.P2D; 62380 this.canvas = document.createElement('canvas'); 62381 var node = pInst._userNode || document.body; 62382 node.appendChild(this.canvas); 62383 _main.default.Element.call(this, this.canvas, pInst); // bind methods and props of p5 to the new object 62384 for (var p in _main.default.prototype) { 62385 if (!this[p]) { 62386 if (typeof _main.default.prototype[p] === 'function') { 62387 this[p] = _main.default.prototype[p].bind(this); 62388 } else { 62389 this[p] = _main.default.prototype[p]; 62390 } 62391 } 62392 } 62393 _main.default.prototype._initializeInstanceVariables.apply(this); 62394 this.width = w; 62395 this.height = h; 62396 this._pixelDensity = pInst._pixelDensity; 62397 if (r === constants.WEBGL) { 62398 this._renderer = new _main.default.RendererGL(this.canvas, this, false); 62399 } else { 62400 this._renderer = new _main.default.Renderer2D(this.canvas, this, false); 62401 } 62402 pInst._elements.push(this); 62403 Object.defineProperty(this, 'deltaTime', { 62404 get: function get() { 62405 return this._pInst.deltaTime; 62406 } 62407 }); 62408 this._renderer.resize(w, h); 62409 this._renderer._applyDefaults(); 62410 return this; 62411 }; 62412 _main.default.Graphics.prototype = Object.create(_main.default.Element.prototype); 62413 /** 62414 * Resets certain values such as those modified by functions in the Transform category 62415 * and in the Lights category that are not automatically reset 62416 * with graphics buffer objects. Calling this in <a href='#/p5/draw'>draw()</a> will copy the behavior 62417 * of the standard canvas. 62418 * 62419 * @method reset 62420 * @example 62421 * 62422 * <div><code> 62423 * let pg; 62424 * function setup() { 62425 * createCanvas(100, 100); 62426 * background(0); 62427 * pg = createGraphics(50, 100); 62428 * pg.fill(0); 62429 * frameRate(5); 62430 * } 62431 * 62432 * function draw() { 62433 * image(pg, width / 2, 0); 62434 * pg.background(255); 62435 * // p5.Graphics object behave a bit differently in some cases 62436 * // The normal canvas on the left resets the translate 62437 * // with every loop through draw() 62438 * // the graphics object on the right doesn't automatically reset 62439 * // so translate() is additive and it moves down the screen 62440 * rect(0, 0, width / 2, 5); 62441 * pg.rect(0, 0, width / 2, 5); 62442 * translate(0, 5, 0); 62443 * pg.translate(0, 5, 0); 62444 * } 62445 * function mouseClicked() { 62446 * // if you click you will see that 62447 * // reset() resets the translate back to the initial state 62448 * // of the Graphics object 62449 * pg.reset(); 62450 * } 62451 * </code></div> 62452 * 62453 * @alt 62454 * A white line on a black background stays still on the top-left half. 62455 * A black line animates from top to bottom on a white background on the right half. 62456 * When clicked, the black line starts back over at the top. 62457 */ 62458 _main.default.Graphics.prototype.reset = function () { 62459 this._renderer.resetMatrix(); 62460 if (this._renderer.isP3D) { 62461 this._renderer._update(); 62462 } 62463 }; 62464 /** 62465 * Removes a Graphics object from the page and frees any resources 62466 * associated with it. 62467 * 62468 * @method remove 62469 * 62470 * @example 62471 * <div class='norender'><code> 62472 * let bg; 62473 * function setup() { 62474 * bg = createCanvas(100, 100); 62475 * bg.background(0); 62476 * image(bg, 0, 0); 62477 * bg.remove(); 62478 * } 62479 * </code></div> 62480 * 62481 * <div><code> 62482 * let bg; 62483 * function setup() { 62484 * pixelDensity(1); 62485 * createCanvas(100, 100);
62486 * stroke(255); 62487 * fill(0); 62488 * 62489 * // create and draw the background image 62490 * bg = createGraphics(100, 100); 62491 * bg.background(200); 62492 * bg.ellipse(50, 50, 80, 80); 62493 * } 62494 * function draw() { 62495 * let t = millis() / 1000; 62496 * // draw the background 62497 * if (bg) { 62498 * image(bg, frameCount % 100, 0); 62499 * image(bg, frameCount % 100 - 100, 0); 62500 * } 62501 * // draw the foreground 62502 * let p = p5.Vector.fromAngle(t, 35).add(50, 50); 62503 * ellipse(p.x, p.y, 30); 62504 * } 62505 * function mouseClicked() { 62506 * // remove the background 62507 * if (bg) { 62508 * bg.remove(); 62509 * bg = null; 62510 * } 62511 * } 62512 * </code></div> 62513 * 62514 * @alt 62515 * no image 62516 * a multi-colored circle moving back and forth over a scrolling background. 62517 */ 62518 _main.default.Graphics.prototype.remove = function () { 62519 if (this.elt.parentNode) { 62520 this.elt.parentNode.removeChild(this.elt); 62521 } 62522 var idx = this._pInst._elements.indexOf(this); 62523 if (idx !== - 1) { 62524 this._pInst._elements.splice(idx, 1); 62525 } 62526 for (var elt_ev in this._events) { 62527 this.elt.removeEventListener(elt_ev, this._events[elt_ev]); 62528 } 62529 }; 62530 var _default = _main.default.Graphics; 62531 exports.default = _default; 62532 }, 62533 { 62534 './constants': 278, 62535 './main': 290, 62536 'core-js/modules/es.array.index-of': 175, 62537 'core-js/modules/es.array.iterator': 176, 62538 'core-js/modules/es.array.splice': 182, 62539 'core-js/modules/es.object.get-own-property-descriptor': 191, 62540 'core-js/modules/es.object.to-string': 195, 62541 'core-js/modules/es.string.iterator': 204, 62542 'core-js/modules/es.symbol': 214, 62543 'core-js/modules/es.symbol.description': 212, 62544 'core-js/modules/es.symbol.iterator': 213, 62545 'core-js/modules/es.weak-map': 246, 62546 'core-js/modules/web.dom-collections.iterator': 248 62547 } 62548 ], 62549 293: [ 62550 function (_dereq_, module, exports) { 62551 'use strict'; 62552 _dereq_('core-js/modules/es.symbol'); 62553 _dereq_('core-js/modules/es.symbol.description'); 62554 _dereq_('core-js/modules/es.symbol.iterator'); 62555 _dereq_('core-js/modules/es.array.iterator'); 62556 _dereq_('core-js/modules/es.number.constructor'); 62557 _dereq_('core-js/modules/es.object.assign'); 62558 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 62559 _dereq_('core-js/modules/es.object.to-string'); 62560 _dereq_('core-js/modules/es.regexp.exec'); 62561 _dereq_('core-js/modules/es.regexp.to-string'); 62562 _dereq_('core-js/modules/es.string.iterator'); 62563 _dereq_('core-js/modules/es.string.replace'); 62564 _dereq_('core-js/modules/es.string.split'); 62565 _dereq_('core-js/modules/es.string.trim'); 62566 _dereq_('core-js/modules/es.weak-map'); 62567 _dereq_('core-js/modules/web.dom-collections.iterator'); 62568 function _typeof2(obj) { 62569 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 62570 _typeof2 = function _typeof2(obj) { 62571 return typeof obj; 62572 }; 62573 } else { 62574 _typeof2 = function _typeof2(obj) { 62575 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 62576 }; 62577 } 62578 return _typeof2(obj); 62579 } 62580 _dereq_('core-js/modules/es.symbol'); 62581 _dereq_('core-js/modules/es.symbol.description'); 62582 _dereq_('core-js/modules/es.symbol.iterator'); 62583 _dereq_('core-js/modules/es.array.iterator'); 62584 _dereq_('core-js/modules/es.number.constructor'); 62585 _dereq_('core-js/modules/es.object.assign'); 62586 _dereq_('core-js/modules/es.object.to-string'); 62587 _dereq_('core-js/modules/es.regexp.exec'); 62588 _dereq_('core-js/modules/es.regexp.to-string'); 62589 _dereq_('core-js/modules/es.string.iterator'); 62590 _dereq_('core-js/modules/es.string.replace'); 62591 _dereq_('core-js/modules/es.string.split'); 62592 _dereq_('core-js/modules/es.string.trim'); 62593 _dereq_('core-js/modules/web.dom-collections.iterator'); 62594 Object.defineProperty(exports, '__esModule', { 62595 value: true 62596 }); 62597 exports.default = void 0; 62598 var _main = _interopRequireDefault(_dereq_('./main')); 62599 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 62600 function _getRequireWildcardCache() { 62601 if (typeof WeakMap !== 'function') return null; 62602 var cache = new WeakMap(); 62603 _getRequireWildcardCache = function _getRequireWildcardCache() { 62604 return cache; 62605 }; 62606 return cache; 62607 } 62608 function _interopRequireWildcard(obj) { 62609 if (obj && obj.__esModule) { 62610 return obj; 62611 } 62612 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 62613 return { 62614 default: 62615 obj 62616 }; 62617 } 62618 var cache = _getRequireWildcardCache(); 62619 if (cache && cache.has(obj)) { 62620 return cache.get(obj); 62621 } 62622 var newObj = { 62623 }; 62624 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 62625 for (var key in obj) { 62626 if (Object.prototype.hasOwnProperty.call(obj, key)) { 62627 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 62628 if (desc && (desc.get || desc.set)) { 62629 Object.defineProperty(newObj, key, desc); 62630 } else { 62631 newObj[key] = obj[key]; 62632 } 62633 } 62634 } 62635 newObj.default = obj; 62636 if (cache) { 62637 cache.set(obj, newObj); 62638 } 62639 return newObj; 62640 } 62641 function _interopRequireDefault(obj) { 62642 return obj && obj.__esModule ? obj : { 62643 default: 62644 obj 62645 }; 62646 } 62647 function _typeof(obj) { 62648 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 62649 _typeof = function _typeof(obj) { 62650 return _typeof2(obj); 62651 }; 62652 } else { 62653 _typeof = function _typeof(obj) { 62654 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
62654ypeof2(obj); 62655 }; 62656 } 62657 return _typeof(obj); 62658 } /** 62659 * Main graphics and rendering context, as well as the base API 62660 * implementation for p5.js "core". To be used as the superclass for 62661 * Renderer2D and Renderer3D classes, respectively. 62662 * 62663 * @class p5.Renderer 62664 * @constructor 62665 * @extends p5.Element 62666 * @param {String} elt DOM node that is wrapped 62667 * @param {p5} [pInst] pointer to p5 instance 62668 * @param {Boolean} [isMainCanvas] whether we're using it as main canvas 62669 */ 62670 62671 _main.default.Renderer = function (elt, pInst, isMainCanvas) { 62672 _main.default.Element.call(this, elt, pInst); 62673 this.canvas = elt; 62674 this._pixelsState = pInst; 62675 if (isMainCanvas) { 62676 this._isMainCanvas = true; // for pixel method sharing with pimage 62677 this._pInst._setProperty('_curElement', this); 62678 this._pInst._setProperty('canvas', this.canvas); 62679 this._pInst._setProperty('width', this.width); 62680 this._pInst._setProperty('height', this.height); 62681 } else { 62682 // hide if offscreen buffer by default 62683 this.canvas.style.display = 'none'; 62684 this._styles = [ 62685 ]; // non-main elt styles stored in p5.Renderer 62686 } 62687 this._textSize = 12; 62688 this._textLeading = 15; 62689 this._textFont = 'sans-serif'; 62690 this._textStyle = constants.NORMAL; 62691 this._textAscent = null; 62692 this._textDescent = null; 62693 this._textAlign = constants.LEFT; 62694 this._textBaseline = constants.BASELINE; 62695 this._textWrap = constants.WORD; 62696 this._rectMode = constants.CORNER; 62697 this._ellipseMode = constants.CENTER; 62698 this._curveTightness = 0; 62699 this._imageMode = constants.CORNER; 62700 this._tint = null; 62701 this._doStroke = true; 62702 this._doFill = true; 62703 this._strokeSet = false; 62704 this._fillSet = false; 62705 this._leadingSet = false; 62706 }; 62707 _main.default.Renderer.prototype = Object.create(_main.default.Element.prototype); // the renderer should return a 'style' object that it wishes to 62708 // store on the push stack. 62709 _main.default.Renderer.prototype.push = function () { 62710 return { 62711 properties: { 62712 _doStroke: this._doStroke, 62713 _strokeSet: this._strokeSet, 62714 _doFill: this._doFill, 62715 _fillSet: this._fillSet, 62716 _tint: this._tint, 62717 _imageMode: this._imageMode, 62718 _rectMode: this._rectMode, 62719 _ellipseMode: this._ellipseMode, 62720 _textFont: this._textFont, 62721 _textLeading: this._textLeading, 62722 _leadingSet: this._leadingSet, 62723 _textSize: this._textSize, 62724 _textAlign: this._textAlign, 62725 _textBaseline: this._textBaseline, 62726 _textStyle: this._textStyle, 62727 _textWrap: this._textWrap 62728 } 62729 }; 62730 }; // a pop() operation is in progress 62731 // the renderer is passed the 'style' object that it returned 62732 // from its push() method. 62733 _main.default.Renderer.prototype.pop = function (style) { 62734 if (style.properties) { 62735 // copy the style properties back into the renderer 62736 Object.assign(this, style.properties); 62737 } 62738 }; 62739 /** 62740 * Resize our canvas element. 62741 */ 62742 _main.default.Renderer.prototype.resize = function (w, h) { 62743 this.width = w; 62744 this.height = h; 62745 this.elt.width = w * this._pInst._pixelDensity; 62746 this.elt.height = h * this._pInst._pixelDensity; 62747 this.elt.style.width = ''.concat(w, 'px'); 62748 this.elt.style.height = ''.concat(h, 'px'); 62749 if (this._isMainCanvas) { 62750 this._pInst._setProperty('width', this.width); 62751 this._pInst._setProperty('height', this.height); 62752 } 62753 }; 62754 _main.default.Renderer.prototype.get = function (x, y, w, h) { 62755 var pixelsState = this._pixelsState; 62756 var pd = pixelsState._pixelDensity; 62757 var canvas = this.canvas; 62758 if (typeof x === 'undefined' && typeof y === 'undefined') { 62759 // get() 62760 x = y = 0; 62761 w = pixelsState.width; 62762 h = pixelsState.height; 62763 } else { 62764 x *= pd; 62765 y *= pd; 62766 if (typeof w === 'undefined' && typeof h === 'undefined') { 62767 // get(x,y) 62768 if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) { 62769 return [0, 62770 0, 62771 0, 62772 0]; 62773 } 62774 return this._getPixel(x, y); 62775 } // get(x,y,w,h) 62776 62777 } 62778 var region = new _main.default.Image(w, h); 62779 region.canvas.getContext('2d').drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w, h); 62780 return region; 62781 }; 62782 _main.default.Renderer.prototype.textLeading = function (l) { 62783 if (typeof l === 'number') { 62784 this._setProperty('_leadingSet', true); 62785 this._setProperty('_textLeading', l); 62786 return this._pInst; 62787 } 62788 return this._textLeading; 62789 }; 62790 _main.default.Renderer.prototype.textSize = function (s) { 62791 if (typeof s === 'number') { 62792 this._setProperty('_textSize', s); 62793 if (!this._leadingSet) { 62794 // only use a default value if not previously set (#5181) 62795 this._setProperty('_textLeading', s * constants._DEFAULT_LEADMULT); 62796 } 62797 return this._applyTextProperties(); 62798 } 62799 return this._textSize; 62800 }; 62801 _main.default.Renderer.prototype.textStyle = function (s) { 62802 if (s) { 62803 if (s === constants.NORMAL || s === constants.ITALIC || s === constants.BOLD || s === constants.BOLDITALIC) { 62804 this._setProperty('_textStyle', s); 62805 } 62806 return this._applyTextProperties(); 62807 } 62808 return this._textStyle; 62809 }; 62810 _main.default.Renderer.prototype.textAscent = function () { 62811 if (this._textAscent === null) { 62812 this._updateTextMetrics(); 62813 } 62814 return this._textAscent; 62815 }; 62816 _main.default.Renderer.prototype.textDescent = function () { 62817 if (this._textDescent === null) { 62818 this._updateTextMetrics(); 62819 } 62820 return this._textDescent; 62821 }; 62822 _main.default.Renderer.prototype.textAlign = function (h, v) { 62823 if (typeof h !== 'undefined') { 62824 this._setProperty('_textAlign', h); 62825 if (typeof v !== 'undefined') { 62826 this._setProperty('_textBaseline', v); 62827 } 62828 return this._applyTextProperties(); 62829 } else { 62830 return { 62831 horizontal: this._textAlign, 62832 vertical: this._textBaseline 62833 }; 62834 } 62835 }; 62836 _main.default.Renderer.prototype.textWrap = function (wrapStyle) { 62837 this._setProperty('_textWrap', wrapStyle); 62838 return this._textWrap; 62839 }; 62840 _main.default.Renderer.prototype.text = function (str, x, y, maxWidth, maxHeight) { 62841 var p = this._pInst; 62842 var textWrapStyle = this._textWrap; 62843 var lines; 62844 var line; 62845 var testLine; 62846 var testWidth; 62847 var words; 62848 var chars; 62849 var shiftedY; 62850 var finalMaxHeight = Number.MAX_VALUE; // fix for #5785 (top of bounding box) 62851 var finalMinHeight = y; 62852 if (!(this._doFill || this._doStroke)) { 62853 return; 62854 } 62855 if (typeof str === 'undefined') { 62856 return; 62857 } else if (typeof str !== 'string') { 62858 str = str.toString(); 62859 } // Replaces tabs with double-spaces and splits string on any line 62860 // breaks present in the original string 62861 62862 str = str.replace(/(\t)/g, ' '); 62863 lines = str.split('\n'); 62864 if (typeof maxWidth !== 'undefined') { 62865 if (this._rectMode === constants.CENTER) { 62866 x -= maxWidth / 2; 62867 } 62868 switch (this._textAlign) { 62869 case constants.CENTER: 62870 x += maxWidth / 2; 62871 break; 62872 case constants.RIGHT: 62873 x += maxWidth; 62874 break; 62875 } 62876 if (typeof maxHeight !== 'undefined') { 62877 if (this._rectMode === constants.CENTER) { 62878 y -= maxHeight / 2; 62879 finalMinHeight -= maxHeight / 2; 62880 } 62881 var originalY = y; 62882 var ascent = p.textAscent(); 62883 switch (this._textBaseline) { 62884 case constants.BOTTOM: 62885 shiftedY = y + maxHeight; 62886 y = Math.max(shiftedY, y);
62886 // fix for #5785 (top of bounding box) 62887 finalMinHeight += ascent; 62888 break; 62889 case constants.CENTER: 62890 shiftedY = y + maxHeight / 2; 62891 y = Math.max(shiftedY, y); // fix for #5785 (top of bounding box) 62892 finalMinHeight += ascent / 2; 62893 break; 62894 } // remember the max-allowed y-position for any line (fix to #928) 62895 62896 finalMaxHeight = y + maxHeight - ascent; // fix for #5785 (bottom of bounding box) 62897 if (this._textBaseline === constants.CENTER) { 62898 finalMaxHeight = originalY + maxHeight - ascent / 2; 62899 } 62900 } else { 62901 // no text-height specified, show warning for BOTTOM / CENTER 62902 if (this._textBaseline === constants.BOTTOM) { 62903 return console.warn('textAlign(*, BOTTOM) requires x, y, width and height'); 62904 } 62905 if (this._textBaseline === constants.CENTER) { 62906 return console.warn('textAlign(*, CENTER) requires x, y, width and height'); 62907 } 62908 } // Render lines of text according to settings of textWrap 62909 // Splits lines at spaces, for loop adds one word + space
62910 // at a time and tests length with next word added 62911 62912 if (textWrapStyle === constants.WORD) { 62913 var nlines = [ 62914 ]; 62915 for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) { 62916 line = ''; 62917 words = lines[lineIndex].split(' '); 62918 for (var wordIndex = 0; wordIndex < words.length; wordIndex++) { 62919 testLine = ''.concat(line + words[wordIndex]) + ' '; 62920 testWidth = this.textWidth(testLine); 62921 if (testWidth > maxWidth && line.length > 0) { 62922 nlines.push(line); 62923 line = ''.concat(words[wordIndex]) + ' '; 62924 } else { 62925 line = testLine; 62926 } 62927 } 62928 nlines.push(line); 62929 } 62930 var offset = 0; 62931 if (this._textBaseline === constants.CENTER) { 62932 offset = (nlines.length - 1) * p.textLeading() / 2; 62933 } else if (this._textBaseline === constants.BOTTOM) { 62934 offset = (nlines.length - 1) * p.textLeading(); 62935 } 62936 for (var _lineIndex = 0; _lineIndex < lines.length; _lineIndex++) { 62937 line = ''; 62938 words = lines[_lineIndex].split(' '); 62939 for (var _wordIndex = 0; _wordIndex < words.length; _wordIndex++) { 62940 testLine = ''.concat(line + words[_wordIndex]) + ' '; 62941 testWidth = this.textWidth(testLine); 62942 if (testWidth > maxWidth && line.length > 0) { 62943 this._renderText(p, line.trim(), x, y - offset, finalMaxHeight, finalMinHeight); 62944 line = ''.concat(words[_wordIndex]) + ' '; 62945 y += p.textLeading(); 62946 } else { 62947 line = testLine; 62948 } 62949 } 62950 this._renderText(p, line.trim(), x, y - offset, finalMaxHeight, finalMinHeight); 62951 y += p.textLeading(); 62952 } 62953 } else { 62954 var _nlines = [ 62955 ]; 62956 for (var _lineIndex2 = 0; _lineIndex2 < lines.length; _lineIndex2++) { 62957 line = ''; 62958 chars = lines[_lineIndex2].split(''); 62959 for (var charIndex = 0; charIndex < chars.length; charIndex++) { 62960 testLine = ''.concat(line + chars[charIndex]); 62961 testWidth = this.textWidth(testLine); 62962 if (testWidth <= maxWidth) { 62963 line += chars[charIndex]; 62964 } else if (testWidth > maxWidth && line.length > 0) { 62965 _nlines.push(line); 62966 line = ''.concat(chars[charIndex]); 62967 } 62968 } 62969 } 62970 _nlines.push(line); 62971 var _offset = 0; 62972 if (this._textBaseline === constants.CENTER) { 62973 _offset = (_nlines.length - 1) * p.textLeading() / 2; 62974 } else if (this._textBaseline === constants.BOTTOM) { 62975 _offset = (_nlines.length - 1) * p.textLeading(); 62976 } // Splits lines at characters, for loop adds one char at a time
62977 // and tests length with next char added 62978 62979 for (var _lineIndex3 = 0; _lineIndex3 < lines.length; _lineIndex3++) { 62980 line = ''; 62981 chars = lines[_lineIndex3].split(''); 62982 for (var _charIndex = 0; _charIndex < chars.length; _charIndex++) { 62983 testLine = ''.concat(line + chars[_charIndex]); 62984 testWidth = this.textWidth(testLine); 62985 if (testWidth <= maxWidth) { 62986 line += chars[_charIndex]; 62987 } else if (testWidth > maxWidth && line.length > 0) { 62988 this._renderText(p, line.trim(), x, y - _offset, finalMaxHeight, finalMinHeight); 62989 y += p.textLeading(); 62990 line = ''.concat(chars[_charIndex]); 62991 } 62992 } 62993 } 62994 this._renderText(p, line.trim(), x, y - _offset, finalMaxHeight, finalMinHeight); 62995 y += p.textLeading(); 62996 } 62997 } else { 62998 // Offset to account for vertically centering multiple lines of text - no 62999 // need to adjust anything for vertical align top or baseline 63000 var _offset2 = 0; 63001 if (this._textBaseline === constants.CENTER) { 63002 _offset2 = (lines.length - 1) * p.textLeading() / 2; 63003 } else if (this._textBaseline === constants.BOTTOM) { 63004 _offset2 = (lines.length - 1) * p.textLeading(); 63005 } // Renders lines of text at any line breaks present in the original string 63006 63007 for (var i = 0; i < lines.length; i++) { 63008 this._renderText(p, lines[i], x, y - _offset2, finalMaxHeight, finalMinHeight - _offset2); 63009 y += p.textLeading(); 63010 } 63011 } 63012 return p; 63013 }; 63014 _main.default.Renderer.prototype._applyDefaults = function () { 63015 return this; 63016 }; 63017 /** 63018 * Helper function to check font type (system or otf) 63019 */ 63020 _main.default.Renderer.prototype._isOpenType = function () { 63021 var f = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._textFont; 63022 return _typeof(f) === 'object' && f.font && f.font.supported; 63023 }; 63024 _main.default.Renderer.prototype._updateTextMetrics = function () { 63025 if (this._isOpenType()) { 63026 this._setProperty('_textAscent', this._textFont._textAscent()); 63027 this._setProperty('_textDescent', this._textFont._textDescent()); 63028 return this; 63029 } // Adapted from http://stackoverflow.com/a/25355178 63030 63031 var text = document.createElement('span'); 63032 text.style.fontFamily = this._textFont; 63033 text.style.fontSize = ''.concat(this._textSize, 'px'); 63034 text.innerHTML = 'ABCjgq|'; 63035 var block = document.createElement('div'); 63036 block.style.display = 'inline-block'; 63037 block.style.width = '1px'; 63038 block.style.height = '0px'; 63039 var container = document.createElement('div'); 63040 container.appendChild(text); 63041 container.appendChild(block); 63042 container.style.height = '0px'; 63043 container.style.overflow = 'hidden'; 63044 document.body.appendChild(container); 63045 block.style.verticalAlign = 'baseline'; 63046 var blockOffset = calculateOffset(block); 63047 var textOffset = calculateOffset(text); 63048 var ascent = blockOffset[1] - textOffset[1]; 63049 block.style.verticalAlign = 'bottom'; 63050 blockOffset = calculateOffset(block); 63051 textOffset = calculateOffset(text); 63052 var height = blockOffset[1] - textOffset[1]; 63053 var descent = height - ascent; 63054 document.body.removeChild(container); 63055 this._setProperty('_textAscent', ascent); 63056 this._setProperty('_textDescent', descent); 63057 return this; 63058 }; 63059 /** 63060 * Helper fxn to measure ascent and descent. 63061 * Adapted from http://stackoverflow.com/a/25355178 63062 */ 63063 function calculateOffset(object) { 63064 var currentLeft = 0, 63065 currentTop = 0; 63066 if (object.offsetParent) { 63067 do { 63068 currentLeft += object.offsetLeft; 63069 currentTop += object.offsetTop; 63070 } while (object = object.offsetParent); 63071 } else { 63072 currentLeft += object.offsetLeft; 63073 currentTop += object.offsetTop; 63074 } 63075 return [currentLeft, 63076 currentTop]; 63077 } 63078 var _default = _main.default.Renderer; 63079 exports.default = _default; 63080 }, 63081 { 63082 '../core/constants': 278, 63083 './main': 290, 63084 'core-js/modules/es.array.iterator': 176, 63085 'core-js/modules/es.number.constructor': 187, 63086 'core-js/modules/es.object.assign': 190, 63087 'core-js/modules/es.object.get-own-property-descriptor': 191, 63088 'core-js/modules/es.object.to-string': 195, 63089 'core-js/modules/es.regexp.exec': 199, 63090 'core-js/modules/es.regexp.to-string': 200, 63091 'core-js/modules/es.string.iterator': 204, 63092 'core-js/modules/es.string.replace': 207, 63093 'core-js/modules/es.string.split': 209, 63094 'core-js/modules/es.string.trim': 211, 63095 'core-js/modules/es.symbol': 214, 63096 'core-js/modules/es.symbol.description': 212, 63097 'core-js/modules/es.symbol.iterator': 213, 63098 'core-js/modules/es.weak-map': 246, 63099 'core-js/modules/web.dom-collections.iterator': 248 63100 } 63101 ], 63102 294: [
63103 function (_dereq_, module, exports) { 63104 'use strict'; 63105 _dereq_('core-js/modules/es.symbol'); 63106 _dereq_('core-js/modules/es.symbol.description'); 63107 _dereq_('core-js/modules/es.symbol.iterator'); 63108 _dereq_('core-js/modules/es.array.concat'); 63109 _dereq_('core-js/modules/es.array.fill'); 63110 _dereq_('core-js/modules/es.array.for-each'); 63111 _dereq_('core-js/modules/es.array.iterator'); 63112 _dereq_('core-js/modules/es.array.join'); 63113 _dereq_('core-js/modules/es.array.slice'); 63114 _dereq_('core-js/modules/es.function.name'); 63115 _dereq_('core-js/modules/es.number.to-fixed'); 63116 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 63117 _dereq_('core-js/modules/es.object.to-string'); 63118 _dereq_('core-js/modules/es.regexp.to-string'); 63119 _dereq_('core-js/modules/es.string.iterator'); 63120 _dereq_('core-js/modules/es.weak-map'); 63121 _dereq_('core-js/modules/web.dom-collections.iterator'); 63122 function _typeof2(obj) { 63123 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 63124 _typeof2 = function _typeof2(obj) { 63125 return typeof obj; 63126 }; 63127 } else { 63128 _typeof2 = function _typeof2(obj) { 63129 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 63130 }; 63131 } 63132 return _typeof2(obj); 63133 } 63134 function _typeof(obj) { 63135 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 63136 _typeof = function _typeof(obj) { 63137 return _typeof2(obj); 63138 }; 63139 } else { 63140 _typeof = function _typeof(obj) { 63141 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 63142 }; 63143 } 63144 return _typeof(obj); 63145 } 63146 _dereq_('core-js/modules/es.array.concat'); 63147 _dereq_('core-js/modules/es.array.fill'); 63148 _dereq_('core-js/modules/es.array.for-each'); 63149 _dereq_('core-js/modules/es.array.join'); 63150 _dereq_('core-js/modules/es.array.slice'); 63151 _dereq_('core-js/modules/es.function.name'); 63152 _dereq_('core-js/modules/es.number.to-fixed'); 63153 _dereq_('core-js/modules/es.object.to-string'); 63154 _dereq_('core-js/modules/es.regexp.to-string'); 63155 Object.defineProperty(exports, '__esModule', { 63156 value: true 63157 }); 63158 exports.default = void 0; 63159 var _main = _interopRequireDefault(_dereq_('./main')); 63160 var constants = _interopRequireWildcard(_dereq_('./constants')); 63161 _dereq_('./p5.Renderer'); 63162 function _getRequireWildcardCache() { 63163 if (typeof WeakMap !== 'function') return null; 63164 var cache = new WeakMap(); 63165 _getRequireWildcardCache = function _getRequireWildcardCache() { 63166 return cache; 63167 }; 63168 return cache; 63169 } 63170 function _interopRequireWildcard(obj) { 63171 if (obj && obj.__esModule) { 63172 return obj; 63173 } 63174 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 63175 return { 63176 default: 63177 obj 63178 }; 63179 } 63180 var cache = _getRequireWildcardCache(); 63181 if (cache && cache.has(obj)) { 63182 return cache.get(obj); 63183 } 63184 var newObj = { 63185 }; 63186 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 63187 for (var key in obj) { 63188 if (Object.prototype.hasOwnProperty.call(obj, key)) { 63189 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 63190 if (desc && (desc.get || desc.set)) { 63191 Object.defineProperty(newObj, key, desc); 63192 } else { 63193 newObj[key] = obj[key]; 63194 } 63195 } 63196 } 63197 newObj.default = obj; 63198 if (cache) { 63199 cache.set(obj, newObj); 63200 } 63201 return newObj; 63202 } 63203 function _interopRequireDefault(obj) { 63204 return obj && obj.__esModule ? obj : { 63205 default: 63206 obj 63207 }; 63208 } /** 63209 * p5.Renderer2D 63210 * The 2D graphics canvas renderer class. 63211 * extends p5.Renderer 63212 */ 63213 63214 var styleEmpty = 'rgba(0,0,0,0)';
63214 // const alphaThreshold = 0.00125; // minimum visible 63215 _main.default.Renderer2D = function (elt, pInst, isMainCanvas) { 63216 _main.default.Renderer.call(this, elt, pInst, isMainCanvas); 63217 this.drawingContext = this.canvas.getContext('2d'); 63218 this._pInst._setProperty('drawingContext', this.drawingContext); 63219 return this; 63220 }; 63221 _main.default.Renderer2D.prototype = Object.create(_main.default.Renderer.prototype); 63222 _main.default.Renderer2D.prototype._applyDefaults = function () { 63223 this._cachedFillStyle = this._cachedStrokeStyle = undefined; 63224 this._cachedBlendMode = constants.BLEND; 63225 this._setFill(constants._DEFAULT_FILL); 63226 this._setStroke(constants._DEFAULT_STROKE); 63227 this.drawingContext.lineCap = constants.ROUND; 63228 this.drawingContext.font = 'normal 12px sans-serif'; 63229 }; 63230 _main.default.Renderer2D.prototype.resize = function (w, h) { 63231 _main.default.Renderer.prototype.resize.call(this, w, h); 63232 this.drawingContext.scale(this._pInst._pixelDensity, this._pInst._pixelDensity); 63233 }; ////////////////////////////////////////////// 63234 // COLOR | Setting
63235 ////////////////////////////////////////////// 63236 _main.default.Renderer2D.prototype.background = function () { 63237 this.drawingContext.save(); 63238 this.resetMatrix(); 63239 if ((arguments.length <= 0 ? undefined : arguments[0]) instanceof _main.default.Image) { 63240 if ((arguments.length <= 1 ? undefined : arguments[1]) >= 0) { 63241 // set transparency of background 63242 var img = arguments.length <= 0 ? undefined : arguments[0]; 63243 this.drawingContext.globalAlpha = (arguments.length <= 1 ? undefined : arguments[1]) / 255; 63244 this._pInst.image(img, 0, 0, this.width, this.height); 63245 } else { 63246 this._pInst.image(arguments.length <= 0 ? undefined : arguments[0], 0, 0, this.width, this.height); 63247 } 63248 } else { 63249 var _this$_pInst; 63250 var curFill = this._getFill(); // create background rect 63251 var color = (_this$_pInst = this._pInst).color.apply(_this$_pInst, arguments); //accessible Outputs 63252 if (this._pInst._addAccsOutput()) { 63253 this._pInst._accsBackground(color.levels); 63254 } 63255 var newFill = color.toString(); 63256 this._setFill(newFill); 63257 if (this._isErasing) { 63258 this.blendMode(this._cachedBlendMode); 63259 } 63260 this.drawingContext.fillRect(0, 0, this.width, this.height); // reset fill 63261 this._setFill(curFill); 63262 if (this._isErasing) { 63263 this._pInst.erase(); 63264 } 63265 } 63266 this.drawingContext.restore(); 63267 }; 63268 _main.default.Renderer2D.prototype.clear = function () { 63269 this.drawingContext.save(); 63270 this.resetMatrix(); 63271 this.drawingContext.clearRect(0, 0, this.width, this.height); 63272 this.drawingContext.restore(); 63273 }; 63274 _main.default.Renderer2D.prototype.fill = function () { 63275 var _this$_pInst2; 63276 var color = (_this$_pInst2 = this._pInst).color.apply(_this$_pInst2, arguments); 63277 this._setFill(color.toString()); //accessible Outputs 63278 if (this._pInst._addAccsOutput()) { 63279 this._pInst._accsCanvasColors('fill', color.levels); 63280 } 63281 }; 63282 _main.default.Renderer2D.prototype.stroke = function () { 63283 var _this$_pInst3; 63284 var color = (_this$_pInst3 = this._pInst).color.apply(_this$_pInst3, arguments); 63285 this._setStroke(color.toString()); //accessible Outputs 63286 if (this._pInst._addAccsOutput()) { 63287 this._pInst._accsCanvasColors('stroke', color.levels); 63288 } 63289 }; 63290 _main.default.Renderer2D.prototype.erase = function (opacityFill, opacityStroke) { 63291 if (!this._isErasing) { 63292 // cache the fill style 63293 this._cachedFillStyle = this.drawingContext.fillStyle; 63294 var newFill = this._pInst.color(255, opacityFill).toString(); 63295 this.drawingContext.fillStyle = newFill; //cache the stroke style 63296 this._cachedStrokeStyle = this.drawingContext.strokeStyle; 63297 var newStroke = this._pInst.color(255, opacityStroke).toString(); 63298 this.drawingContext.strokeStyle = newStroke; //cache blendMode 63299 var tempBlendMode = this._cachedBlendMode; 63300 this.blendMode(constants.REMOVE); 63301 this._cachedBlendMode = tempBlendMode; 63302 this._isErasing = true; 63303 } 63304 }; 63305 _main.default.Renderer2D.prototype.noErase = function () { 63306 if (this._isErasing) { 63307 this.drawingContext.fillStyle = this._cachedFillStyle; 63308 this.drawingContext.strokeStyle = this._cachedStrokeStyle; 63309 this.blendMode(this._cachedBlendMode); 63310 this._isErasing = false; 63311 } 63312 }; ////////////////////////////////////////////// 63313 // IMAGE | Loading & Displaying
63314 ////////////////////////////////////////////// 63315 _main.default.Renderer2D.prototype.image = function (img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) { 63316 var cnv; 63317 if (img.gifProperties) { 63318 img._animateGif(this._pInst); 63319 } 63320 try { 63321 if (_main.default.MediaElement && img instanceof _main.default.MediaElement) { 63322 img._ensureCanvas(); 63323 } 63324 if (this._tint && img.canvas) { 63325 cnv = this._getTintedImageCanvas(img); 63326 } 63327 if (!cnv) { 63328 cnv = img.canvas || img.elt; 63329 } 63330 var s = 1; 63331 if (img.width && img.width > 0) { 63332 s = cnv.width / img.width; 63333 } 63334 if (this._isErasing) { 63335 this.blendMode(this._cachedBlendMode); 63336 } 63337 this.drawingContext.drawImage(cnv, s * sx, s * sy, s * sWidth, s * sHeight, dx, dy, dWidth, dHeight); 63338 if (this._isErasing) { 63339 this._pInst.erase(); 63340 } 63341 } catch (e) { 63342 if (e.name !== 'NS_ERROR_NOT_AVAILABLE') { 63343 throw e; 63344 } 63345 } 63346 }; 63347 _main.default.Renderer2D.prototype._getTintedImageCanvas = function (img) { 63348 if (!img.canvas) { 63349 return img; 63350 } 63351 if (!img.tintCanvas) { 63352 // Once an image has been tinted, keep its tint canvas 63353 // around so we don't need to re-incur the cost of 63354 // creating a new one for each tint 63355 img.tintCanvas = document.createElement('canvas'); 63356 } // Keep the size of the tint canvas up-to-date 63357 63358 if (img.tintCanvas.width !== img.canvas.width) { 63359 img.tintCanvas.width = img.canvas.width; 63360 } 63361 if (img.tintCanvas.height !== img.canvas.height) { 63362 img.tintCanvas.height = img.canvas.height; 63363 } // Goal: multiply the r,g,b,a values of the source by 63364 // the r,g,b,a values of the tint color 63365 63366 var ctx = img.tintCanvas.getContext('2d'); 63367 ctx.save(); 63368 ctx.clearRect(0, 0, img.canvas.width, img.canvas.height); 63369 if (this._tint[0] < 255 || this._tint[1] < 255 || this._tint[2] < 255) { 63370 // Color tint: we need to use the multiply blend mode to change the colors. 63371 // However, the canvas implementation of this destroys the alpha channel of 63372 // the image. To accommodate, we first get a version of the image with full 63373 // opacity everywhere, tint using multiply, and then use the destination-in 63374 // blend mode to restore the alpha channel again. 63375 // Start with the original image 63376 ctx.drawImage(img.canvas, 0, 0); // This blend mode makes everything opaque but forces the luma to match 63377 // the original image again 63378 ctx.globalCompositeOperation = 'luminosity'; 63379 ctx.drawImage(img.canvas, 0, 0); // This blend mode forces the hue and chroma to match the original image. 63380 // After this we should have the original again, but with full opacity. 63381 ctx.globalCompositeOperation = 'color'; 63382 ctx.drawImage(img.canvas, 0, 0); // Apply color tint 63383 ctx.globalCompositeOperation = 'multiply'; 63384 ctx.fillStyle = 'rgb('.concat(this._tint.slice(0, 3).join(', '), ')'); 63385 ctx.fillRect(0, 0, img.canvas.width, img.canvas.height); // Replace the alpha channel with the original alpha * the alpha tint 63386 ctx.globalCompositeOperation = 'destination-in'; 63387 ctx.globalAlpha = this._tint[3] / 255; 63388 ctx.drawImage(img.canvas, 0, 0); 63389 } else { 63390 // If we only need to change the alpha, we can skip all the extra work! 63391 ctx.globalAlpha = this._tint[3] / 255; 63392 ctx.drawImage(img.canvas, 0, 0); 63393 } 63394 ctx.restore(); 63395 return img.tintCanvas; 63396 }; ////////////////////////////////////////////// 63397 // IMAGE | Pixels
63398 ////////////////////////////////////////////// 63399 _main.default.Renderer2D.prototype.blendMode = function (mode) { 63400 if (mode === constants.SUBTRACT) { 63401 console.warn('blendMode(SUBTRACT) only works in WEBGL mode.'); 63402 } else if (mode === constants.BLEND || mode === constants.REMOVE || mode === constants.DARKEST || mode === constants.LIGHTEST || mode === constants.DIFFERENCE || mode === constants.MULTIPLY || mode === constants.EXCLUSION || mode === constants.SCREEN || mode === constants.REPLACE || mode === constants.OVERLAY || mode === constants.HARD_LIGHT || mode === constants.SOFT_LIGHT || mode === constants.DODGE || mode === constants.BURN || mode === constants.ADD) { 63403 this._cachedBlendMode = mode; 63404 this.drawingContext.globalCompositeOperation = mode; 63405 } else { 63406 throw new Error('Mode '.concat(mode, ' not recognized.')); 63407 } 63408 }; 63409 _main.default.Renderer2D.prototype.blend = function () { 63410 var currBlend = this.drawingContext.globalCompositeOperation; 63411 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 63412 args[_key] = arguments[_key]; 63413 } 63414 var blendMode = args[args.length - 1]; 63415 var copyArgs = Array.prototype.slice.call(args, 0, args.length - 1); 63416 this.drawingContext.globalCompositeOperation = blendMode; 63417 _main.default.prototype.copy.apply(this, copyArgs); 63418 this.drawingContext.globalCompositeOperation = currBlend; 63419 }; // p5.Renderer2D.prototype.get = p5.Renderer.prototype.get; 63420 // .get() is not overridden 63421 // x,y are canvas-relative (pre-scaled by _pixelDensity) 63422 _main.default.Renderer2D.prototype._getPixel = function (x, y) { 63423 var imageData, 63424 index; 63425 imageData = this.drawingContext.getImageData(x, y, 1, 1).data; 63426 index = 0; 63427 return [imageData[index + 0], 63428 imageData[index + 1], 63429 imageData[index + 2], 63430 imageData[index + 3]]; 63431 }; 63432 _main.default.Renderer2D.prototype.loadPixels = function () { 63433 var pixelsState = this._pixelsState; // if called by p5.Image 63434 var pd = pixelsState._pixelDensity; 63435 var w = this.width * pd; 63436 var h = this.height * pd; 63437 var imageData = this.drawingContext.getImageData(0, 0, w, h); // @todo this should actually set pixels per object, so diff buffers can 63438 // have diff pixel arrays. 63439 pixelsState._setProperty('imageData', imageData); 63440 pixelsState._setProperty('pixels', imageData.data); 63441 }; 63442 _main.default.Renderer2D.prototype.set = function (x, y, imgOrCol) { 63443 // round down to get integer numbers 63444 x = Math.floor(x); 63445 y = Math.floor(y); 63446 var pixelsState = this._pixelsState; 63447 if (imgOrCol instanceof _main.default.Image) { 63448 this.drawingContext.save(); 63449 this.drawingContext.setTransform(1, 0, 0, 1, 0, 0); 63450 this.drawingContext.scale(pixelsState._pixelDensity, pixelsState._pixelDensity); 63451 this.drawingContext.clearRect(x, y, imgOrCol.width, imgOrCol.height); 63452 this.drawingContext.drawImage(imgOrCol.canvas, x, y); 63453 this.drawingContext.restore(); 63454 } else { 63455 var r = 0, 63456 g = 0, 63457 b = 0, 63458 a = 0; 63459 var idx = 4 * (y * pixelsState._pixelDensity * (this.width * pixelsState._pixelDensity) + x * pixelsState._pixelDensity); 63460 if (!pixelsState.imageData) { 63461 pixelsState.loadPixels.call(pixelsState); 63462 } 63463 if (typeof imgOrCol === 'number') { 63464 if (idx < pixelsState.pixels.length) { 63465 r = imgOrCol; 63466 g = imgOrCol; 63467 b = imgOrCol; 63468 a = 255; //this.updatePixels.call(this); 63469 } 63470 } else if (imgOrCol instanceof Array) { 63471 if (imgOrCol.length < 4) { 63472 throw new Error('pixel array must be of the form [R, G, B, A]'); 63473 } 63474 if (idx < pixelsState.pixels.length) { 63475 r = imgOrCol[0]; 63476 g = imgOrCol[1]; 63477 b = imgOrCol[2]; 63478 a = imgOrCol[3]; //this.updatePixels.call(this); 63479 } 63480 } else if (imgOrCol instanceof _main.default.Color) { 63481 if (idx < pixelsState.pixels.length) { 63482 r = imgOrCol.levels[0]; 63483 g = imgOrCol.levels[1]; 63484 b = imgOrCol.levels[2]; 63485 a = imgOrCol.levels[3]; //this.updatePixels.call(this); 63486 } 63487 } // loop over pixelDensity * pixelDensity 63488 63489 for (var i = 0; i < pixelsState._pixelDensity; i++) { 63490 for (var j = 0; j < pixelsState._pixelDensity; j++) { 63491 // loop over 63492 idx = 4 * ((y * pixelsState._pixelDensity + j) * this.width * pixelsState._pixelDensity + (x * pixelsState._pixelDensity + i)); 63493 pixelsState.pixels[idx] = r; 63494 pixelsState.pixels[idx + 1] = g; 63495 pixelsState.pixels[idx + 2] = b; 63496 pixelsState.pixels[idx + 3] = a; 63497 } 63498 } 63499 } 63500 }; 63501 _main.default.Renderer2D.prototype.updatePixels = function (x, y, w, h) { 63502 var pixelsState = this._pixelsState; 63503 var pd = pixelsState._pixelDensity; 63504 if (x === undefined && y === undefined && w === undefined && h === undefined) { 63505 x = 0; 63506 y = 0; 63507 w = this.width; 63508 h = this.height; 63509 } 63510 x *= pd; 63511 y *= pd; 63512 w *= pd; 63513 h *= pd; 63514 if (this.gifProperties) { 63515 this.gifProperties.frames[this.gifProperties.displayIndex].image = pixelsState.imageData; 63516 } 63517 this.drawingContext.putImageData(pixelsState.imageData, x, y, 0, 0, w, h); 63518 }; ////////////////////////////////////////////// 63519 // SHAPE | 2D Primitives
63520 ////////////////////////////////////////////// 63521 /** 63522 * Generate a cubic Bezier representing an arc on the unit circle of total 63523 * angle `size` radians, beginning `start` radians above the x-axis. Up to 63524 * four of these curves are combined to make a full arc. 63525 * 63526 * See ecridge.com/bezier.pdf for an explanation of the method. 63527 */ 63528 _main.default.Renderer2D.prototype._acuteArcToBezier = function _acuteArcToBezier(start, size) { 63529 // Evaluate constants. 63530 var alpha = size / 2, 63531 cos_alpha = Math.cos(alpha), 63532 sin_alpha = Math.sin(alpha), 63533 cot_alpha = 1 / Math.tan(alpha), 63534 // This is how far the arc needs to be rotated. 63535 phi = start + alpha, 63536 cos_phi = Math.cos(phi), 63537 sin_phi = Math.sin(phi), 63538 lambda = (4 - cos_alpha) / 3, 63539 mu = sin_alpha + (cos_alpha - lambda) * cot_alpha; // Return rotated waypoints. 63540 return { 63541 ax: Math.cos(start).toFixed(7), 63542 ay: Math.sin(start).toFixed(7), 63543 bx: (lambda * cos_phi + mu * sin_phi).toFixed(7), 63544 by: (lambda * sin_phi - mu * cos_phi).toFixed(7), 63545 cx: (lambda * cos_phi - mu * sin_phi).toFixed(7), 63546 cy: (lambda * sin_phi + mu * cos_phi).toFixed(7), 63547 dx: Math.cos(start + size).toFixed(7), 63548 dy: Math.sin(start + size).toFixed(7) 63549 }; 63550 }; 63551 /* 63552 * This function requires that: 63553 * 63554 * 0 <= start < TWO_PI 63555 * 63556 * start <= stop < start + TWO_PI 63557 */ 63558 _main.default.Renderer2D.prototype.arc = function (x, y, w, h, start, stop, mode) { 63559 var ctx = this.drawingContext; 63560 var rx = w / 2; 63561 var ry = h / 2; 63562 var epsilon = 0.00001; // Smallest visible angle on displays up to 4K. 63563 var arcToDraw = 0; 63564 var curves = [ 63565 ]; 63566 x += rx; 63567 y += ry; // Create curves 63568 while (stop - start >= epsilon) { 63569 arcToDraw = Math.min(stop - start, constants.HALF_PI); 63570 curves.push(this._acuteArcToBezier(start, arcToDraw)); 63571 start += arcToDraw; 63572 } // Fill curves 63573 63574 if (this._doFill) { 63575 ctx.beginPath(); 63576 curves.forEach(function (curve, index) { 63577 if (index === 0) { 63578 ctx.moveTo(x + curve.ax * rx, y + curve.ay * ry); 63579 } /* eslint-disable indent */ 63580 63581 ctx.bezierCurveTo(x + curve.bx * rx, y + curve.by * ry, x + curve.cx * rx, y + curve.cy * ry, x + curve.dx * rx, y + curve.dy * ry); 63582 /* eslint-enable indent */ 63583 }); 63584 if (mode === constants.PIE || mode == null) { 63585 ctx.lineTo(x, y); 63586 } 63587 ctx.closePath(); 63588 ctx.fill(); 63589 } // Stroke curves 63590 63591 if (this._doStroke) { 63592 ctx.beginPath(); 63593 curves.forEach(function (curve, index) { 63594 if (index === 0) { 63595 ctx.moveTo(x + curve.ax * rx, y + curve.ay * ry); 63596 } /* eslint-disable indent */ 63597 63598 ctx.bezierCurveTo(x + curve.bx * rx, y + curve.by * ry, x + curve.cx * rx, y + curve.cy * ry, x + curve.dx * rx, y + curve.dy * ry); 63599 /* eslint-enable indent */ 63600 }); 63601 if (mode === constants.PIE) { 63602 ctx.lineTo(x, y); 63603 ctx.closePath(); 63604 } else if (mode === constants.CHORD) { 63605 ctx.closePath(); 63606 } 63607 ctx.stroke(); 63608 } 63609 return this; 63610 }; 63611 _main.default.Renderer2D.prototype.ellipse = function (args) { 63612 var ctx = this.drawingContext; 63613 var doFill = this._doFill, 63614 doStroke = this._doStroke; 63615 var x = parseFloat(args[0]), 63616 y = parseFloat(args[1]), 63617 w = parseFloat(args[2]), 63618 h = parseFloat(args[3]); 63619 if (doFill && !doStroke) { 63620 if (this._getFill() === styleEmpty) { 63621 return this; 63622 } 63623 } else if (!doFill && doStroke) { 63624 if (this._getStroke() === styleEmpty) { 63625 return this; 63626 } 63627 } 63628 var kappa = 0.5522847498, 63629 // control point offset horizontal 63630 ox = w / 2 * kappa, 63631 // control point offset vertical 63632 oy = h / 2 * kappa, 63633 // x-end 63634 xe = x + w, 63635 // y-end 63636 ye = y + h, 63637 // x-middle 63638 xm = x + w / 2, 63639 ym = y + h / 2; // y-middle 63640 ctx.beginPath(); 63641 ctx.moveTo(x, ym); 63642 ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); 63643 ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); 63644 ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); 63645 ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); 63646 if (doFill) { 63647 ctx.fill(); 63648 } 63649 if (doStroke) { 63650 ctx.stroke(); 63651 } 63652 }; 63653 _main.default.Renderer2D.prototype.line = function (x1, y1, x2, y2) { 63654 var ctx = this.drawingContext; 63655 if (!this._doStroke) { 63656 return this; 63657 } else if (this._getStroke() === styleEmpty) { 63658 return this; 63659 } 63660 ctx.beginPath(); 63661 ctx.moveTo(x1, y1); 63662 ctx.lineTo(x2, y2); 63663 ctx.stroke(); 63664 return this; 63665 }; 63666 _main.default.Renderer2D.prototype.point = function (x, y) { 63667 var ctx = this.drawingContext; 63668 if (!this._doStroke) { 63669 return this; 63670 } else if (this._getStroke() === styleEmpty) { 63671 return this; 63672 } 63673 var s = this._getStroke(); 63674 var f = this._getFill(); // swapping fill color to stroke and back after for correct point rendering 63675 this._setFill(s); 63676 ctx.beginPath(); 63677 ctx.arc(x, y, ctx.lineWidth / 2, 0, constants.TWO_PI, false); 63678 ctx.fill(); 63679 this._setFill(f); 63680 }; 63681 _main.default.Renderer2D.prototype.quad = function (x1, y1, x2, y2, x3, y3, x4, y4) { 63682 var ctx = this.drawingContext; 63683 var doFill = this._doFill, 63684 doStroke = this._doStroke; 63685 if (doFill && !doStroke) { 63686 if (this._getFill() === styleEmpty) { 63687 return this; 63688 } 63689 } else if (!doFill && doStroke) { 63690 if (this._getStroke() === styleEmpty) { 63691 return this; 63692 } 63693 } 63694 ctx.beginPath(); 63695 ctx.moveTo(x1, y1); 63696 ctx.lineTo(x2, y2); 63697 ctx.lineTo(x3, y3); 63698 ctx.lineTo(x4, y4); 63699 ctx.closePath(); 63700 if (doFill) { 63701 ctx.fill(); 63702 } 63703 if (doStroke) { 63704 ctx.stroke(); 63705 } 63706 return this; 63707 }; 63708 _main.default.Renderer2D.prototype.rect = function (args) { 63709 var x = args[0]; 63710 var y = args[1]; 63711 var w = args[2]; 63712 var h = args[3]; 63713 var tl = args[4]; 63714 var tr = args[5]; 63715 var br = args[6]; 63716 var bl = args[7]; 63717 var ctx = this.drawingContext; 63718 var doFill = this._doFill, 63719 doStroke = this._doStroke; 63720 if (doFill && !doStroke) { 63721 if (this._getFill() === styleEmpty) { 63722 return this; 63723 } 63724 } else if (!doFill && doStroke) { 63725 if (this._getStroke() === styleEmpty) { 63726 return this; 63727 } 63728 } 63729 ctx.beginPath(); 63730 if (typeof tl === 'undefined') { 63731 // No rounded corners 63732 ctx.rect(x, y, w, h); 63733 } else { 63734 // At least one rounded corner 63735 // Set defaults when not specified 63736 if (typeof tr === 'undefined') { 63737 tr = tl; 63738 } 63739 if (typeof br === 'undefined') { 63740 br = tr; 63741 } 63742 if (typeof bl === 'undefined') { 63743 bl = br; 63744 } // corner rounding must always be positive 63745 63746 var absW = Math.abs(w); 63747 var absH = Math.abs(h);
63748 var hw = absW / 2; 63749 var hh = absH / 2; // Clip radii 63750 if (absW < 2 * tl) { 63751 tl = hw; 63752 } 63753 if (absH < 2 * tl) { 63754 tl = hh; 63755 } 63756 if (absW < 2 * tr) { 63757 tr = hw; 63758 } 63759 if (absH < 2 * tr) { 63760 tr = hh; 63761 } 63762 if (absW < 2 * br) { 63763 br = hw; 63764 } 63765 if (absH < 2 * br) { 63766 br = hh; 63767 } 63768 if (absW < 2 * bl) { 63769 bl = hw; 63770 } 63771 if (absH < 2 * bl) { 63772 bl = hh; 63773 } // Draw shape 63774 63775 ctx.beginPath(); 63776 ctx.moveTo(x + tl, y); 63777 ctx.arcTo(x + w, y, x + w, y + h, tr); 63778 ctx.arcTo(x + w, y + h, x, y + h, br); 63779 ctx.arcTo(x, y + h, x, y, bl); 63780 ctx.arcTo(x, y, x + w, y, tl); 63781 ctx.closePath(); 63782 } 63783 if (this._doFill) { 63784 ctx.fill(); 63785 } 63786 if (this._doStroke) { 63787 ctx.stroke(); 63788 } 63789 return this; 63790 }; 63791 _main.default.Renderer2D.prototype.triangle = function (args) { 63792 var ctx = this.drawingContext; 63793 var doFill = this._doFill, 63794 doStroke = this._doStroke; 63795 var x1 = args[0], 63796 y1 = args[1]; 63797 var x2 = args[2], 63798 y2 = args[3]; 63799 var x3 = args[4], 63800 y3 = args[5]; 63801 if (doFill && !doStroke) { 63802 if (this._getFill() === styleEmpty) { 63803 return this; 63804 } 63805 } else if (!doFill && doStroke) { 63806 if (this._getStroke() === styleEmpty) { 63807 return this; 63808 } 63809 } 63810 ctx.beginPath(); 63811 ctx.moveTo(x1, y1); 63812 ctx.lineTo(x2, y2); 63813 ctx.lineTo(x3, y3); 63814 ctx.closePath(); 63815 if (doFill) { 63816 ctx.fill(); 63817 } 63818 if (doStroke) { 63819 ctx.stroke(); 63820 } 63821 }; 63822 _main.default.Renderer2D.prototype.endShape = function (mode, vertices, isCurve, isBezier, isQuadratic, isContour, shapeKind) { 63823 if (vertices.length === 0) { 63824 return this; 63825 } 63826 if (!this._doStroke && !this._doFill) { 63827 return this; 63828 } 63829 var closeShape = mode === constants.CLOSE; 63830 var v; 63831 if (closeShape && !isContour) { 63832 vertices.push(vertices[0]); 63833 } 63834 var i, 63835 j; 63836 var numVerts = vertices.length; 63837 if (isCurve && (shapeKind === constants.POLYGON || shapeKind === null)) { 63838 if (numVerts > 3) { 63839 var b = [ 63840 ], 63841 s = 1 - this._curveTightness; 63842 this.drawingContext.beginPath(); 63843 this.drawingContext.moveTo(vertices[1][0], vertices[1][1]); 63844 for (i = 1; i + 2 < numVerts; i++) { 63845 v = vertices[i]; 63846 b[0] = [ 63847 v[0], 63848 v[1] 63849 ]; 63850 b[1] = [ 63851 v[0] + (s * vertices[i + 1][0] - s * vertices[i - 1][0]) / 6, 63852 v[1] + (s * vertices[i + 1][1] - s * vertices[i - 1][1]) / 6 63853 ]; 63854 b[2] = [ 63855 vertices[i + 1][0] + (s * vertices[i][0] - s * vertices[i + 2][0]) / 6, 63856 vertices[i + 1][1] + (s * vertices[i][1] - s * vertices[i + 2][1]) / 6 63857 ]; 63858 b[3] = [ 63859 vertices[i + 1][0], 63860 vertices[i + 1][1] 63861 ]; 63862 this.drawingContext.bezierCurveTo(b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1]); 63863 } 63864 if (closeShape) { 63865 this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); 63866 } 63867 this._doFillStrokeClose(closeShape); 63868 } 63869 } else if (isBezier && (shapeKind === constants.POLYGON || shapeKind === null)) { 63870 this.drawingContext.beginPath(); 63871 for (i = 0; i < numVerts; i++) { 63872 if (vertices[i].isVert) { 63873 if (vertices[i].moveTo) {
63874 this.drawingContext.moveTo(vertices[i][0], vertices[i][1]); 63875 } else { 63876 this.drawingContext.lineTo(vertices[i][0], vertices[i][1]); 63877 } 63878 } else { 63879 this.drawingContext.bezierCurveTo(vertices[i][0], vertices[i][1], vertices[i][2], vertices[i][3], vertices[i][4], vertices[i][5]); 63880 } 63881 } 63882 this._doFillStrokeClose(closeShape); 63883 } else if (isQuadratic && (shapeKind === constants.POLYGON || shapeKind === null)) { 63884 this.drawingContext.beginPath(); 63885 for (i = 0; i < numVerts; i++) { 63886 if (vertices[i].isVert) { 63887 if (vertices[i].moveTo) { 63888 this.drawingContext.moveTo(vertices[i][0], vertices[i][1]); 63889 } else { 63890 this.drawingContext.lineTo(vertices[i][0], vertices[i][1]); 63891 } 63892 } else { 63893 this.drawingContext.quadraticCurveTo(vertices[i][0], vertices[i][1], vertices[i][2], vertices[i][3]); 63894 } 63895 } 63896 this._doFillStrokeClose(closeShape); 63897 } else { 63898 if (shapeKind === constants.POINTS) { 63899 for (i = 0; i < numVerts; i++) { 63900 v = vertices[i]; 63901 if (this._doStroke) { 63902 this._pInst.stroke(v[6]); 63903 } 63904 this._pInst.point(v[0], v[1]); 63905 } 63906 } else if (shapeKind === constants.LINES) { 63907 for (i = 0; i + 1 < numVerts; i += 2) { 63908 v = vertices[i]; 63909 if (this._doStroke) { 63910 this._pInst.stroke(vertices[i + 1][6]); 63911 } 63912 this._pInst.line(v[0], v[1], vertices[i + 1][0], vertices[i + 1][1]); 63913 } 63914 } else if (shapeKind === constants.TRIANGLES) { 63915 for (i = 0; i + 2 < numVerts; i += 3) { 63916 v = vertices[i]; 63917 this.drawingContext.beginPath(); 63918 this.drawingContext.moveTo(v[0], v[1]); 63919 this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); 63920 this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]); 63921 this.drawingContext.closePath(); 63922 if (this._doFill) { 63923 this._pInst.fill(vertices[i + 2][5]); 63924 this.drawingContext.fill(); 63925 } 63926 if (this._doStroke) { 63927 this._pInst.stroke(vertices[i + 2][6]); 63928 this.drawingContext.stroke(); 63929 } 63930 } 63931 } else if (shapeKind === constants.TRIANGLE_STRIP) { 63932 for (i = 0; i + 1 < numVerts; i++) { 63933 v = vertices[i]; 63934 this.drawingContext.beginPath(); 63935 this.drawingContext.moveTo(vertices[i + 1][0], vertices[i + 1][1]); 63936 this.drawingContext.lineTo(v[0], v[1]); 63937 if (this._doStroke) { 63938 this._pInst.stroke(vertices[i + 1][6]); 63939 } 63940 if (this._doFill) { 63941 this._pInst.fill(vertices[i + 1][5]); 63942 } 63943 if (i + 2 < numVerts) { 63944 this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]); 63945 if (this._doStroke) { 63946 this._pInst.stroke(vertices[i + 2][6]); 63947 } 63948 if (this._doFill) { 63949 this._pInst.fill(vertices[i + 2][5]); 63950 } 63951 } 63952 this._doFillStrokeClose(closeShape); 63953 } 63954 } else if (shapeKind === constants.TRIANGLE_FAN) { 63955 if (numVerts > 2) { 63956 // For performance reasons, try to batch as many of the 63957 // fill and stroke calls as possible. 63958 this.drawingContext.beginPath(); 63959 for (i = 2; i < numVerts; i++) { 63960 v = vertices[i]; 63961 this.drawingContext.moveTo(vertices[0][0], vertices[0][1]); 63962 this.drawingContext.lineTo(vertices[i - 1][0], vertices[i - 1][1]); 63963 this.drawingContext.lineTo(v[0], v[1]); 63964 this.drawingContext.lineTo(vertices[0][0], vertices[0][1]); // If the next colour is going to be different, stroke / fill now 63965 if (i < numVerts - 1) { 63966 if (this._doFill && v[5] !== vertices[i + 1][5] || this._doStroke && v[6] !== vertices[i + 1][6]) { 63967 if (this._doFill) { 63968 this._pInst.fill(v[5]); 63969 this.drawingContext.fill(); 63970 this._pInst.fill(vertices[i + 1][5]); 63971 } 63972 if (this._doStroke) { 63973 this._pInst.stroke(v[6]); 63974 this.drawingContext.stroke(); 63975 this._pInst.stroke(vertices[i + 1][6]); 63976 } 63977 this.drawingContext.closePath(); 63978 this.drawingContext.beginPath(); // Begin the next one 63979 } 63980 } 63981 } 63982 this._doFillStrokeClose(closeShape); 63983 } 63984 } else if (shapeKind === constants.QUADS) { 63985 for (i = 0; i + 3 < numVerts; i += 4) { 63986 v = vertices[i]; 63987 this.drawingContext.beginPath(); 63988 this.drawingContext.moveTo(v[0], v[1]); 63989 for (j = 1; j < 4; j++) { 63990 this.drawingContext.lineTo(vertices[i + j][0], vertices[i + j][1]); 63991 } 63992 this.drawingContext.lineTo(v[0], v[1]); 63993 if (this._doFill) { 63994 this._pInst.fill(vertices[i + 3][5]); 63995 } 63996 if (this._doStroke) { 63997 this._pInst.stroke(vertices[i + 3][6]); 63998 } 63999 this._doFillStrokeClose(closeShape); 64000 } 64001 } else if (shapeKind === constants.QUAD_STRIP) { 64002 if (numVerts > 3) { 64003 for (i = 0; i + 1 < numVerts; i += 2) { 64004 v = vertices[i]; 64005 this.drawingContext.beginPath(); 64006 if (i + 3 < numVerts) {
64007 this.drawingContext.moveTo(vertices[i + 2][0], vertices[i + 2][1]); 64008 this.drawingContext.lineTo(v[0], v[1]); 64009 this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); 64010 this.drawingContext.lineTo(vertices[i + 3][0], vertices[i + 3][1]); 64011 if (this._doFill) { 64012 this._pInst.fill(vertices[i + 3][5]); 64013 } 64014 if (this._doStroke) { 64015 this._pInst.stroke(vertices[i + 3][6]); 64016 } 64017 } else { 64018 this.drawingContext.moveTo(v[0], v[1]); 64019 this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); 64020 } 64021 this._doFillStrokeClose(closeShape); 64022 } 64023 } 64024 } else { 64025 this.drawingContext.beginPath(); 64026 this.drawingContext.moveTo(vertices[0][0], vertices[0][1]); 64027 for (i = 1; i < numVerts; i++) { 64028 v = vertices[i]; 64029 if (v.isVert) { 64030 if (v.moveTo) { 64031 this.drawingContext.moveTo(v[0], v[1]); 64032 } else { 64033 this.drawingContext.lineTo(v[0], v[1]); 64034 } 64035 } 64036 } 64037 this._doFillStrokeClose(closeShape); 64038 } 64039 } 64040 isCurve = false; 64041 isBezier = false;
64042 isQuadratic = false; 64043 isContour = false; 64044 if (closeShape) { 64045 vertices.pop(); 64046 } 64047 return this; 64048 }; ////////////////////////////////////////////// 64049 // SHAPE | Attributes 64050 ////////////////////////////////////////////// 64051 _main.default.Renderer2D.prototype.strokeCap = function (cap) { 64052 if (cap === constants.ROUND || cap === constants.SQUARE || cap === constants.PROJECT) { 64053 this.drawingContext.lineCap = cap; 64054 } 64055 return this; 64056 }; 64057 _main.default.Renderer2D.prototype.strokeJoin = function (join) { 64058 if (join === constants.ROUND || join === constants.BEVEL || join === constants.MITER) { 64059 this.drawingContext.lineJoin = join; 64060 } 64061 return this; 64062 }; 64063 _main.default.Renderer2D.prototype.strokeWeight = function (w) { 64064 if (typeof w === 'undefined' || w === 0) { 64065 // hack because lineWidth 0 doesn't work 64066 this.drawingContext.lineWidth = 0.0001; 64067 } else { 64068 this.drawingContext.lineWidth = w; 64069 } 64070 return this; 64071 }; 64072 _main.default.Renderer2D.prototype._getFill = function () { 64073 if (!this._cachedFillStyle) { 64074 this._cachedFillStyle = this.drawingContext.fillStyle; 64075 } 64076 return this._cachedFillStyle; 64077 }; 64078 _main.default.Renderer2D.prototype._setFill = function (fillStyle) { 64079 if (fillStyle !== this._cachedFillStyle) { 64080 this.drawingContext.fillStyle = fillStyle; 64081 this._cachedFillStyle = fillStyle; 64082 } 64083 }; 64084 _main.default.Renderer2D.prototype._getStroke = function () { 64085 if (!this._cachedStrokeStyle) { 64086 this._cachedStrokeStyle = this.drawingContext.strokeStyle; 64087 } 64088 return this._cachedStrokeStyle; 64089 }; 64090 _main.default.Renderer2D.prototype._setStroke = function (strokeStyle) { 64091 if (strokeStyle !== this._cachedStrokeStyle) { 64092 this.drawingContext.strokeStyle = strokeStyle; 64093 this._cachedStrokeStyle = strokeStyle; 64094 } 64095 }; ////////////////////////////////////////////// 64096 // SHAPE | Curves
64097 ////////////////////////////////////////////// 64098 _main.default.Renderer2D.prototype.bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) { 64099 this._pInst.beginShape(); 64100 this._pInst.vertex(x1, y1); 64101 this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4); 64102 this._pInst.endShape(); 64103 return this; 64104 }; 64105 _main.default.Renderer2D.prototype.curve = function (x1, y1, x2, y2, x3, y3, x4, y4) { 64106 this._pInst.beginShape(); 64107 this._pInst.curveVertex(x1, y1); 64108 this._pInst.curveVertex(x2, y2); 64109 this._pInst.curveVertex(x3, y3); 64110 this._pInst.curveVertex(x4, y4); 64111 this._pInst.endShape(); 64112 return this; 64113 }; ////////////////////////////////////////////// 64114 // SHAPE | Vertex 64115 ////////////////////////////////////////////// 64116 _main.default.Renderer2D.prototype._doFillStrokeClose = function (closeShape) { 64117 if (closeShape) { 64118 this.drawingContext.closePath(); 64119 } 64120 if (this._doFill) { 64121 this.drawingContext.fill(); 64122 } 64123 if (this._doStroke) { 64124 this.drawingContext.stroke(); 64125 } 64126 }; ////////////////////////////////////////////// 64127 // TRANSFORM
64128 ////////////////////////////////////////////// 64129 _main.default.Renderer2D.prototype.applyMatrix = function (a, b, c, d, e, f) { 64130 this.drawingContext.transform(a, b, c, d, e, f); 64131 }; 64132 _main.default.Renderer2D.prototype.resetMatrix = function () { 64133 this.drawingContext.setTransform(1, 0, 0, 1, 0, 0); 64134 this.drawingContext.scale(this._pInst._pixelDensity, this._pInst._pixelDensity); 64135 return this; 64136 }; 64137 _main.default.Renderer2D.prototype.rotate = function (rad) { 64138 this.drawingContext.rotate(rad); 64139 }; 64140 _main.default.Renderer2D.prototype.scale = function (x, y) { 64141 this.drawingContext.scale(x, y); 64142 return this; 64143 }; 64144 _main.default.Renderer2D.prototype.translate = function (x, y) { 64145 // support passing a vector as the 1st parameter 64146 if (x instanceof _main.default.Vector) { 64147 y = x.y; 64148 x = x.x; 64149 } 64150 this.drawingContext.translate(x, y); 64151 return this; 64152 }; ////////////////////////////////////////////// 64153 // TYPOGRAPHY 64154 //
64155 ////////////////////////////////////////////// 64156 _main.default.Renderer2D.prototype.text = function (str, x, y, maxWidth, maxHeight) { 64157 var baselineHacked; // baselineHacked: (HACK) 64158 // A temporary fix to conform to Processing's implementation 64159 // of BASELINE vertical alignment in a bounding box 64160 if (typeof maxWidth !== 'undefined') { 64161 if (this.drawingContext.textBaseline === constants.BASELINE) { 64162 baselineHacked = true; 64163 this.drawingContext.textBaseline = constants.TOP; 64164 } 64165 } 64166 var p = _main.default.Renderer.prototype.text.apply(this, arguments); 64167 if (baselineHacked) { 64168 this.drawingContext.textBaseline = constants.BASELINE; 64169 } 64170 return p; 64171 }; 64172 _main.default.Renderer2D.prototype._renderText = function (p, line, x, y, maxY, minY) { 64173 if (y < minY || y >= maxY) { 64174 return; // don't render lines beyond our minY/maxY bounds (see #5785) 64175 } 64176 p.push(); // fix to #803 64177 if (!this._isOpenType()) { 64178 // a system/browser font 64179 // no stroke unless specified by user 64180 if (this._doStroke && this._strokeSet) { 64181 this.drawingContext.strokeText(line, x, y); 64182 } 64183 if (this._doFill) { 64184 // if fill hasn't been set by user, use default text fill 64185 if (!this._fillSet) { 64186 this._setFill(constants._DEFAULT_TEXT_FILL); 64187 } 64188 this.drawingContext.fillText(line, x, y); 64189 } 64190 } else { 64191 // an opentype font, let it handle the rendering 64192 this._textFont._renderPath(line, x, y, { 64193 renderer: this 64194 }); 64195 } 64196 p.pop(); 64197 return p; 64198 }; 64199 _main.default.Renderer2D.prototype.textWidth = function (s) { 64200 if (this._isOpenType()) { 64201 return this._textFont._textWidth(s, this._textSize); 64202 } 64203 return this.drawingContext.measureText(s).width; 64204 }; 64205 _main.default.Renderer2D.prototype._applyTextProperties = function () { 64206 var font; 64207 var p = this._pInst; 64208 this._setProperty('_textAscent', null); 64209 this._setProperty('_textDescent', null); 64210 font = this._textFont; 64211 if (this._isOpenType()) { 64212 font = this._textFont.font.familyName; 64213 this._setProperty('_textStyle', this._textFont.font.styleName); 64214 } 64215 this.drawingContext.font = ''.concat(this._textStyle || 'normal', ' ').concat(this._textSize || 12, 'px ').concat(font || 'sans-serif'); 64216 this.drawingContext.textAlign = this._textAlign; 64217 if (this._textBaseline === constants.CENTER) { 64218 this.drawingContext.textBaseline = constants._CTX_MIDDLE; 64219 } else { 64220 this.drawingContext.textBaseline = this._textBaseline; 64221 } 64222 return p; 64223 }; ////////////////////////////////////////////// 64224 // STRUCTURE
64225 ////////////////////////////////////////////// 64226 // a push() operation is in progress. 64227 // the renderer should return a 'style' object that it wishes to 64228 // store on the push stack. 64229 // derived renderers should call the base class' push() method 64230 // to fetch the base style object. 64231 _main.default.Renderer2D.prototype.push = function () { 64232 this.drawingContext.save(); // get the base renderer style 64233 return _main.default.Renderer.prototype.push.apply(this); 64234 }; // a pop() operation is in progress 64235 // the renderer is passed the 'style' object that it returned 64236 // from its push() method. 64237 // derived renderers should pass this object to their base 64238 // class' pop method 64239 _main.default.Renderer2D.prototype.pop = function (style) { 64240 this.drawingContext.restore(); // Re-cache the fill / stroke state 64241 this._cachedFillStyle = this.drawingContext.fillStyle; 64242 this._cachedStrokeStyle = this.drawingContext.strokeStyle; 64243 _main.default.Renderer.prototype.pop.call(this, style); 64244 }; 64245 var _default = _main.default.Renderer2D; 64246 exports.default = _default; 64247 }, 64248 { 64249 './constants': 278, 64250 './main': 290, 64251 './p5.Renderer': 293, 64252 'core-js/modules/es.array.concat': 167, 64253 'core-js/modules/es.array.fill': 170, 64254 'core-js/modules/es.array.for-each': 172, 64255 'core-js/modules/es.array.iterator': 176, 64256 'core-js/modules/es.array.join': 177, 64257 'core-js/modules/es.array.slice': 180, 64258 'core-js/modules/es.function.name': 183, 64259 'core-js/modules/es.number.to-fixed': 189, 64260 'core-js/modules/es.object.get-own-property-descriptor': 191, 64261 'core-js/modules/es.object.to-string': 195, 64262 'core-js/modules/es.regexp.to-string': 200, 64263 'core-js/modules/es.string.iterator': 204, 64264 'core-js/modules/es.symbol': 214, 64265 'core-js/modules/es.symbol.description': 212, 64266 'core-js/modules/es.symbol.iterator': 213, 64267 'core-js/modules/es.weak-map': 246, 64268 'core-js/modules/web.dom-collections.iterator': 248 64269 } 64270 ], 64271 295: [ 64272 function (_dereq_, module, exports) { 64273 'use strict'; 64274 _dereq_('core-js/modules/es.symbol'); 64275 _dereq_('core-js/modules/es.symbol.description'); 64276 _dereq_('core-js/modules/es.symbol.iterator'); 64277 _dereq_('core-js/modules/es.array.iterator'); 64278 _dereq_('core-js/modules/es.object.assign'); 64279 _dereq_('core-js/modules/es.object.to-string'); 64280 _dereq_('core-js/modules/es.promise'); 64281 _dereq_('core-js/modules/es.string.iterator'); 64282 _dereq_('core-js/modules/web.dom-collections.iterator'); 64283 _dereq_('core-js/modules/es.symbol'); 64284 _dereq_('core-js/modules/es.symbol.description'); 64285 _dereq_('core-js/modules/es.symbol.iterator'); 64286 _dereq_('core-js/modules/es.array.iterator'); 64287 _dereq_('core-js/modules/es.object.assign'); 64288 _dereq_('core-js/modules/es.object.to-string'); 64289 _dereq_('core-js/modules/es.promise'); 64290 _dereq_('core-js/modules/es.string.iterator'); 64291 _dereq_('core-js/modules/web.dom-collections.iterator'); 64292 var _main = _interopRequireDefault(_dereq_('./main')); 64293 function _interopRequireDefault(obj) { 64294 return obj && obj.__esModule ? obj : { 64295 default: 64296 obj 64297 }; 64298 } 64299 _main.default.prototype._promisePreloads = [ 64300 /* Example object 64301 { 64302 target: p5.prototype, // The target object to have the method modified 64303 method: 'loadXAsync', // The name of the preload function to wrap 64304 addCallbacks: true, // Whether to automatically handle the p5 callbacks 64305 legacyPreloadSetup: { // Optional object to generate a legacy-style preload 64306 method: 'loadX', // The name of the legacy preload function to generate 64307 createBaseObject: function() { 64308 return {}; 64309 } // An optional function to create the base object for the legacy preload. 64310 } 64311 } 64312 */ 64313 ]; 64314 _main.default.prototype.registerPromisePreload = function (setup) { 64315 _main.default.prototype._promisePreloads.push(setup); 64316 }; 64317 var initialSetupRan = false;
64318 _main.default.prototype._setupPromisePreloads = function () { 64319 var _iteratorNormalCompletion = true; 64320 var _didIteratorError = false; 64321 var _iteratorError = undefined; 64322 try { 64323 for (var _iterator = this._promisePreloads[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 64324 var preloadSetup = _step.value; 64325 var thisValue = this; 64326 var method = preloadSetup.method, 64327 addCallbacks = preloadSetup.addCallbacks, 64328 legacyPreloadSetup = preloadSetup.legacyPreloadSetup; // Get the target object that the preload gets assigned to by default, 64329 // that is the current object. 64330 var target = preloadSetup.target || this; 64331 var sourceFunction = target[method].bind(target); // If the target is the p5 prototype, then only set it up on the first run per page 64332 if (target === _main.default.prototype) { 64333 if (initialSetupRan) { 64334 continue; 64335 } 64336 thisValue = null; 64337 sourceFunction = target[method]; 64338 } // Replace the original method with a wrapped version 64339 64340 target[method] = this._wrapPromisePreload(thisValue, sourceFunction, addCallbacks); // If a legacy preload is required 64341 if (legacyPreloadSetup) { 64342 // What is the name for this legacy preload 64343 var legacyMethod = legacyPreloadSetup.method; // Wrap the already wrapped Promise-returning method with the legacy setup 64344 target[legacyMethod] = this._legacyPreloadGenerator(thisValue, legacyPreloadSetup, target[method]); 64345 } 64346 } 64347 } catch (err) { 64348 _didIteratorError = true; 64349 _iteratorError = err; 64350 } finally { 64351 try { 64352 if (!_iteratorNormalCompletion && _iterator.return != null) { 64353 _iterator.return(); 64354 } 64355 } finally { 64356 if (_didIteratorError) { 64357 throw _iteratorError; 64358 } 64359 } 64360 } 64361 initialSetupRan = true; 64362 }; 64363 _main.default.prototype._wrapPromisePreload = function (thisValue, fn, addCallbacks) { 64364 var replacementFunction = function replacementFunction() { 64365 var _this = this; // Uses the current preload counting mechanism for now. 64366 this._incrementPreload(); // A variable for the callback function if specified 64367 var callback = null; // A variable for the errorCallback function if specified 64368 var errorCallback = null; 64369 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 64370 args[_key] = arguments[_key]; 64371 } 64372 if (addCallbacks) { 64373 // Loop from the end of the args array, pulling up to two functions off of 64374 // the end and putting them in fns 64375 for (var i = args.length - 1; i >= 0 && !errorCallback; i--) { 64376 if (typeof args[i] !== 'function') { 64377 break; 64378 } 64379 errorCallback = callback; 64380 callback = args.pop(); 64381 } 64382 } // Call the underlying function and pass it to Promise.resolve, 64383 // so that even if it didn't return a promise we can still 64384 // act on the result as if it did. 64385 64386 var promise = Promise.resolve(fn.apply(this, args)); // Add the optional callbacks 64387 if (callback) { 64388 promise.then(callback); 64389 } 64390 if (errorCallback) { 64391 promise.catch(errorCallback); 64392 } // Decrement the preload counter only if the promise resolved 64393 64394 promise.then(function () { 64395 return _this._decrementPreload(); 64396 }); // Return the original promise so that neither callback changes the result. 64397 return promise; 64398 }; 64399 if (thisValue) { 64400 replacementFunction = replacementFunction.bind(thisValue); 64401 } 64402 return replacementFunction; 64403 }; 64404 var objectCreator = function objectCreator() { 64405 return { 64406 }; 64407 }; 64408 _main.default.prototype._legacyPreloadGenerator = function (thisValue, legacyPreloadSetup, fn) { 64409 // Create a function that will generate an object before the preload is 64410 // launched. For example, if the object should be an array or be an instance 64411 // of a specific class. 64412 var baseValueGenerator = legacyPreloadSetup.createBaseObject || objectCreator; 64413 var returnedFunction = function returnedFunction() { 64414 var _this2 = this; // Our then clause needs to run before setup, so we also increment the preload counter 64415 this._incrementPreload(); // Generate the return value based on the generator. 64416 var returnValue = baseValueGenerator.apply(this, arguments); // Run the original wrapper 64417 fn.apply(this, arguments).then(function (data) { 64418 // Copy each key from the resolved value into returnValue 64419 Object.assign(returnValue, data); // Decrement the preload counter, to allow setup to continue. 64420 _this2._decrementPreload(); 64421 }); 64422 return returnValue; 64423 }; 64424 if (thisValue) { 64425 returnedFunction = returnedFunction.bind(thisValue); 64426 } 64427 return returnedFunction; 64428 }; 64429 }, 64430 { 64431 './main': 290, 64432 'core-js/modules/es.array.iterator': 176, 64433 'core-js/modules/es.object.assign': 190, 64434 'core-js/modules/es.object.to-string': 195, 64435 'core-js/modules/es.promise': 196, 64436 'core-js/modules/es.string.iterator': 204, 64437 'core-js/modules/es.symbol': 214, 64438 'core-js/modules/es.symbol.description': 212, 64439 'core-js/modules/es.symbol.iterator': 213, 64440 'core-js/modules/web.dom-collections.iterator': 248 64441 } 64442 ], 64443 296: [
64444 function (_dereq_, module, exports) { 64445 'use strict'; 64446 _dereq_('core-js/modules/es.symbol'); 64447 _dereq_('core-js/modules/es.symbol.description'); 64448 _dereq_('core-js/modules/es.symbol.iterator'); 64449 _dereq_('core-js/modules/es.array.filter'); 64450 _dereq_('core-js/modules/es.array.iterator'); 64451 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 64452 _dereq_('core-js/modules/es.object.to-string'); 64453 _dereq_('core-js/modules/es.string.iterator'); 64454 _dereq_('core-js/modules/es.weak-map'); 64455 _dereq_('core-js/modules/web.dom-collections.iterator'); 64456 function _typeof2(obj) { 64457 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 64458 _typeof2 = function _typeof2(obj) { 64459 return typeof obj; 64460 }; 64461 } else { 64462 _typeof2 = function _typeof2(obj) { 64463 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 64464 }; 64465 } 64466 return _typeof2(obj); 64467 } 64468 _dereq_('core-js/modules/es.symbol'); 64469 _dereq_('core-js/modules/es.symbol.description'); 64470 _dereq_('core-js/modules/es.symbol.iterator'); 64471 _dereq_('core-js/modules/es.array.filter'); 64472 _dereq_('core-js/modules/es.array.iterator'); 64473 _dereq_('core-js/modules/es.object.to-string'); 64474 _dereq_('core-js/modules/es.string.iterator'); 64475 _dereq_('core-js/modules/web.dom-collections.iterator'); 64476 Object.defineProperty(exports, '__esModule', { 64477 value: true 64478 }); 64479 exports.default = void 0; 64480 var _main = _interopRequireDefault(_dereq_('./main')); 64481 var constants = _interopRequireWildcard(_dereq_('./constants')); 64482 _dereq_('./p5.Graphics'); 64483 _dereq_('./p5.Renderer2D'); 64484 _dereq_('../webgl/p5.RendererGL'); 64485 function _getRequireWildcardCache() { 64486 if (typeof WeakMap !== 'function') return null; 64487 var cache = new WeakMap(); 64488 _getRequireWildcardCache = function _getRequireWildcardCache() { 64489 return cache; 64490 }; 64491 return cache; 64492 } 64493 function _interopRequireWildcard(obj) { 64494 if (obj && obj.__esModule) { 64495 return obj; 64496 } 64497 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 64498 return { 64499 default: 64500 obj 64501 }; 64502 } 64503 var cache = _getRequireWildcardCache(); 64504 if (cache && cache.has(obj)) { 64505 return cache.get(obj); 64506 } 64507 var newObj = { 64508 }; 64509 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 64510 for (var key in obj) { 64511 if (Object.prototype.hasOwnProperty.call(obj, key)) { 64512 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 64513 if (desc && (desc.get || desc.set)) { 64514 Object.defineProperty(newObj, key, desc); 64515 } else { 64516 newObj[key] = obj[key]; 64517 } 64518 } 64519 } 64520 newObj.default = obj; 64521 if (cache) { 64522 cache.set(obj, newObj); 64523 } 64524 return newObj; 64525 } 64526 function _interopRequireDefault(obj) { 64527 return obj && obj.__esModule ? obj : { 64528 default: 64529 obj 64530 }; 64531 } 64532 function _typeof(obj) { 64533 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 64534 _typeof = function _typeof(obj) { 64535 return _typeof2(obj); 64536 }; 64537 } else { 64538 _typeof = function _typeof(obj) { 64539 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 64540 }; 64541 } 64542 return _typeof(obj); 64543 } 64544 var defaultId = 'defaultCanvas0'; // this gets set again in createCanvas 64545 var defaultClass = 'p5Canvas'; 64546 /** 64547 * Creates a canvas element in the document and sets its dimensions 64548 * in pixels. This method should be called only once at the start of <a href="#/p5/setup">setup()</a>. 64549 * Calling <a href="#/p5/createCanvas">createCanvas</a> more than once in a 64550 * sketch will result in very unpredictable behavior. If you want more than 64551 * one drawing canvas you could use <a href="#/p5/createGraphics">createGraphics()</a> 64552 * (hidden by default but it can be shown). 64553 * 64554 * Important note: in 2D mode (i.e. when `p5.Renderer` is not set) the origin (0,0) 64555 * is positioned at the top left of the screen. In 3D mode (i.e. when `p5.Renderer`
64556 * is set to `WEBGL`), the origin is positioned at the center of the canvas. 64557 * See [this issue](https://github.com/processing/p5.js/issues/1545) for more information. 64558 * 64559 * The system variables width and height are set by the parameters passed to this 64560 * function. If <a href="#/p5/createCanvas">createCanvas()</a> is not used, the 64561 * window will be given a default size of 100Ã100 pixels. 64562 * 64563 * For more ways to position the canvas, see the 64564 * <a href='https://github.com/processing/p5.js/wiki/Positioning-your-canvas'> 64565 * positioning the canvas</a> wiki page. 64566 * 64567 * @method createCanvas 64568 * @param {Number} w width of the canvas 64569 * @param {Number} h height of the canvas 64570 * @param {Constant} [renderer] either P2D or WEBGL 64571 * @return {p5.Renderer} pointer to p5.Renderer holding canvas 64572 * @example 64573 * <div> 64574 * <code> 64575 * function setup() { 64576 * createCanvas(100, 50); 64577 * background(153); 64578 * line(0, 0, width, height); 64579 * } 64580 * </code> 64581 * </div> 64582 * 64583 * @alt 64584 * Black line extending from top-left of canvas to bottom right. 64585 */ 64586 _main.default.prototype.createCanvas = function (w, h, renderer) { 64587 _main.default._validateParameters('createCanvas', arguments); //optional: renderer, otherwise defaults to p2d 64588 var r = renderer || constants.P2D; 64589 var c; 64590 if (r === constants.WEBGL) { 64591 c = document.getElementById(defaultId); 64592 if (c) { 64593 //if defaultCanvas already exists 64594 c.parentNode.removeChild(c); //replace the existing defaultCanvas 64595 var thisRenderer = this._renderer; 64596 this._elements = this._elements.filter(function (e) { 64597 return e !== thisRenderer; 64598 }); 64599 } 64600 c = document.createElement('canvas'); 64601 c.id = defaultId; 64602 c.classList.add(defaultClass); 64603 } else { 64604 if (!this._defaultGraphicsCreated) { 64605 c = document.createElement('canvas'); 64606 var i = 0; 64607 while (document.getElementById('defaultCanvas'.concat(i))) { 64608 i++; 64609 } 64610 defaultId = 'defaultCanvas'.concat(i); 64611 c.id = defaultId; 64612 c.classList.add(defaultClass); 64613 } else { 64614 // resize the default canvas if new one is created 64615 c = this.canvas; 64616 } 64617 } // set to invisible if still in setup (to prevent flashing with manipulate) 64618 64619 if (!this._setupDone) { 64620 c.dataset.hidden = true; // tag to show later 64621 c.style.visibility = 'hidden'; 64622 } 64623 if (this._userNode) { 64624 // user input node case 64625 this._userNode.appendChild(c); 64626 } else { 64627 //create main element 64628 if (document.getElementsByTagName('main').length === 0) { 64629 var m = document.createElement('main'); 64630 document.body.appendChild(m); 64631 } //append canvas to main 64632 64633 document.getElementsByTagName('main') [0].appendChild(c); 64634 } // Init our graphics renderer 64635 //webgl mode 64636 64637 if (r === constants.WEBGL) { 64638 this._setProperty('_renderer', new _main.default.RendererGL(c, this, true)); 64639 this._elements.push(this._renderer); 64640 } else { 64641 //P2D mode 64642 if (!this._defaultGraphicsCreated) { 64643 this._setProperty('_renderer', new _main.default.Renderer2D(c, this, true)); 64644 this._defaultGraphicsCreated = true; 64645 this._elements.push(this._renderer); 64646 } 64647 } 64648 this._renderer.resize(w, h); 64649 this._renderer._applyDefaults(); 64650 return this._renderer; 64651 }; 64652 /** 64653 * Resizes the canvas to given width and height. The canvas will be cleared 64654 * and draw will be called immediately, allowing the sketch to re-render itself 64655 * in the resized canvas. 64656 * @method resizeCanvas 64657 * @param {Number} w width of the canvas 64658 * @param {Number} h height of the canvas 64659 * @param {Boolean} [noRedraw] don't redraw the canvas immediately 64660 * @example 64661 * <div class="norender"><code> 64662 * function setup() { 64663 * createCanvas(windowWidth, windowHeight); 64664 * } 64665 * 64666 * function draw() { 64667 * background(0, 100, 200); 64668 * } 64669 * 64670 * function windowResized() { 64671 * resizeCanvas(windowWidth, windowHeight); 64672 * } 64673 * </code></div> 64674 * 64675 * @alt 64676 * No image displayed. 64677 */ 64678 _main.default.prototype.resizeCanvas = function (w, h, noRedraw) { 64679 _main.default._validateParameters('resizeCanvas', arguments); 64680 if (this._renderer) { 64681 // save canvas properties 64682 var props = { 64683 }; 64684 for (var key in this.drawingContext) { 64685 var val = this.drawingContext[key]; 64686 if (_typeof(val) !== 'object' && typeof val !== 'function') { 64687 props[key] = val; 64688 } 64689 } 64690 this._renderer.resize(w, h); 64691 this.width = w; 64692 this.height = h; // reset canvas properties 64693 for (var savedKey in props) { 64694 try { 64695 this.drawingContext[savedKey] = props[savedKey]; 64696 } catch (err) { // ignore read-only property errors 64697 } 64698 } 64699 if (!noRedraw) { 64700 this.redraw(); 64701 } 64702 } //accessible Outputs 64703 64704 if (this._addAccsOutput()) { 64705 this._updateAccsOutput(); 64706 } 64707 }; 64708 /** 64709 * Removes the default canvas for a p5 sketch that doesn't require a canvas 64710 * @method noCanvas 64711 * @example 64712 * <div> 64713 * <code> 64714 * function setup() { 64715 * noCanvas(); 64716 * } 64717 * </code> 64718 * </div> 64719 * 64720 * @alt 64721 * no image displayed 64722 */ 64723 _main.default.prototype.noCanvas = function () { 64724 if (this.canvas) { 64725 this.canvas.parentNode.removeChild(this.canvas); 64726 } 64727 }; 64728 /** 64729 * Creates and returns a new p5.Renderer object. Use this class if you need 64730 * to draw into an off-screen graphics buffer. The two parameters define the 64731 * width and height in pixels. 64732 * 64733 * @method createGraphics 64734 * @param {Number} w width of the offscreen graphics buffer 64735 * @param {Number} h height of the offscreen graphics buffer 64736 * @param {Constant} [renderer] either P2D or WEBGL 64737 * undefined defaults to p2d 64738 * @return {p5.Graphics} offscreen graphics buffer 64739 * @example 64740 * <div> 64741 * <code> 64742 * let pg; 64743 * function setup() { 64744 * createCanvas(100, 100); 64745 * pg = createGraphics(100, 100); 64746 * } 64747 * 64748 * function draw() { 64749 * background(200); 64750 * pg.background(100); 64751 * pg.noStroke(); 64752 * pg.ellipse(pg.width / 2, pg.height / 2, 50, 50); 64753 * image(pg, 50, 50); 64754 * image(pg, 0, 0, 50, 50); 64755 * } 64756 * </code> 64757 * </div> 64758 * 64759 * @alt 64760 * 4 grey squares alternating light and dark grey. White quarter circle mid-left. 64761 */ 64762 _main.default.prototype.createGraphics = function (w, h, renderer) { 64763 _main.default._validateParameters('createGraphics', arguments); 64764 return new _main.default.Graphics(w, h, renderer, this); 64765 }; 64766 /** 64767 * Blends the pixels in the display window according to the defined mode. 64768 * There is a choice of the following modes to blend the source pixels (A) 64769 * with the ones of pixels already in the display window (B): 64770 * <ul> 64771 * <li><code>BLEND</code> - linear interpolation of colours: C = 64772 * A*factor + B. <b>This is the default blending mode.</b></li> 64773 * <li><code>ADD</code> - sum of A and B</li> 64774 * <li><code>DARKEST</code> - only the darkest colour succeeds: C = 64775 * min(A*factor, B).</li> 64776 * <li><code>LIGHTEST</code> - only the lightest colour succeeds: C = 64777 * max(A*factor, B).</li> 64778 * <li><code>DIFFERENCE</code> - subtract colors from underlying image. 64779 * <em>(2D)</em></li> 64780 * <li><code>EXCLUSION</code> - similar to <code>DIFFERENCE</code>, but less 64781 * extreme.</li> 64782 * <li><code>MULTIPLY</code> - multiply the colors, result will always be 64783 * darker.</li> 64784 * <li><code>SCREEN</code> - opposite multiply, uses inverse values of the 64785 * colors.</li> 64786 * <li><code>REPLACE</code> - the pixels entirely replace the others and
64787 * don't utilize alpha (transparency) values.</li> 64788 * <li><code>REMOVE</code> - removes pixels from B with the alpha strength of A.</li> 64789 * <li><code>OVERLAY</code> - mix of <code>MULTIPLY</code> and <code>SCREEN 64790 * </code>. Multiplies dark values, and screens light values. <em>(2D)</em></li> 64791 * <li><code>HARD_LIGHT</code> - <code>SCREEN</code> when greater than 50% 64792 * gray, <code>MULTIPLY</code> when lower. <em>(2D)</em></li> 64793 * <li><code>SOFT_LIGHT</code> - mix of <code>DARKEST</code> and 64794 * <code>LIGHTEST</code>. Works like <code>OVERLAY</code>, but not as harsh. <em>(2D)</em> 64795 * </li> 64796 * <li><code>DODGE</code> - lightens light tones and increases contrast, 64797 * ignores darks. <em>(2D)</em></li> 64798 * <li><code>BURN</code> - darker areas are applied, increasing contrast, 64799 * ignores lights. <em>(2D)</em></li> 64800 * <li><code>SUBTRACT</code> - remainder of A and B <em>(3D)</em></li> 64801 * </ul> 64802 * 64803 * <em>(2D)</em> indicates that this blend mode <b>only</b> works in the 2D renderer.<br> 64804 * <em>(3D)</em> indicates that this blend mode <b>only</b> works in the WEBGL renderer. 64805 * 64806 * @method blendMode 64807 * @param {Constant} mode blend mode to set for canvas. 64808 * either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY, 64809 * EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, 64810 * SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT 64811 * @example 64812 * <div> 64813 * <code> 64814 * blendMode(LIGHTEST); 64815 * strokeWeight(30); 64816 * stroke(80, 150, 255); 64817 * line(25, 25, 75, 75); 64818 * stroke(255, 50, 50); 64819 * line(75, 25, 25, 75); 64820 * </code> 64821 * </div> 64822 * 64823 * <div> 64824 * <code> 64825 * blendMode(MULTIPLY); 64826 * strokeWeight(30); 64827 * stroke(80, 150, 255); 64828 * line(25, 25, 75, 75); 64829 * stroke(255, 50, 50); 64830 * line(75, 25, 25, 75); 64831 * </code> 64832 * </div> 64833 * 64834 * @alt 64835 * translucent image thick red & blue diagonal rounded lines intersecting center 64836 * Thick red & blue diagonal rounded lines intersecting center. dark at overlap 64837 */ 64838 _main.default.prototype.blendMode = function (mode) { 64839 _main.default._validateParameters('blendMode', arguments); 64840 if (mode === constants.NORMAL) { 64841 // Warning added 3/26/19, can be deleted in future (1.0 release?) 64842 console.warn('NORMAL has been deprecated for use in blendMode. defaulting to BLEND instead.'); 64843 mode = constants.BLEND; 64844 } 64845 this._renderer.blendMode(mode); 64846 }; 64847 /** 64848 * The p5.js API provides a lot of functionality for creating graphics, but there is 64849 * some native HTML5 Canvas functionality that is not exposed by p5. You can still call 64850 * it directly using the variable `drawingContext`, as in the example shown. This is 64851 * the equivalent of calling `canvas.getContext('2d');` or `canvas.getContext('webgl');`. 64852 * See this 64853 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D"> 64854 * reference for the native canvas API</a> for possible drawing functions you can call. 64855 * 64856 * @property drawingContext 64857 * @example 64858 * <div> 64859 * <code> 64860 * function setup() { 64861 * drawingContext.shadowOffsetX = 5; 64862 * drawingContext.shadowOffsetY = -5; 64863 * drawingContext.shadowBlur = 10; 64864 * drawingContext.shadowColor = 'black'; 64865 * background(200); 64866 * ellipse(width / 2, height / 2, 50, 50); 64867 * } 64868 * </code> 64869 * </div> 64870 * 64871 * @alt 64872 * white ellipse with shadow blur effect around edges 64873 */ 64874 var _default = _main.default; 64875 exports.default = _default; 64876 }, 64877 { 64878 '../webgl/p5.RendererGL': 344, 64879 './constants': 278, 64880 './main': 290, 64881 './p5.Graphics': 292, 64882 './p5.Renderer2D': 294, 64883 'core-js/modules/es.array.filter': 171, 64884 'core-js/modules/es.array.iterator': 176, 64885 'core-js/modules/es.object.get-own-property-descriptor': 191, 64886 'core-js/modules/es.object.to-string': 195, 64887 'core-js/modules/es.string.iterator': 204, 64888 'core-js/modules/es.symbol': 214, 64889 'core-js/modules/es.symbol.description': 212, 64890 'core-js/modules/es.symbol.iterator': 213, 64891 'core-js/modules/es.weak-map': 246, 64892 'core-js/modules/web.dom-collections.iterator': 248 64893 } 64894 ], 64895 297: [
64896 function (_dereq_, module, exports) { 64897 'use strict'; 64898 _dereq_('core-js/modules/es.symbol'); 64899 _dereq_('core-js/modules/es.symbol.description'); 64900 _dereq_('core-js/modules/es.symbol.iterator'); 64901 _dereq_('core-js/modules/es.array.iterator'); 64902 _dereq_('core-js/modules/es.array.slice'); 64903 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 64904 _dereq_('core-js/modules/es.object.to-string'); 64905 _dereq_('core-js/modules/es.string.iterator'); 64906 _dereq_('core-js/modules/es.weak-map'); 64907 _dereq_('core-js/modules/web.dom-collections.iterator'); 64908 function _typeof2(obj) { 64909 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 64910 _typeof2 = function _typeof2(obj) { 64911 return typeof obj; 64912 }; 64913 } else { 64914 _typeof2 = function _typeof2(obj) { 64915 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 64916 }; 64917 } 64918 return _typeof2(obj); 64919 } 64920 function _typeof(obj) { 64921 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 64922 _typeof = function _typeof(obj) { 64923 return _typeof2(obj); 64924 }; 64925 } else { 64926 _typeof = function _typeof(obj) { 64927 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 64928 }; 64929 } 64930 return _typeof(obj); 64931 } 64932 _dereq_('core-js/modules/es.array.slice'); 64933 Object.defineProperty(exports, '__esModule', { 64934 value: true 64935 }); 64936 exports.default = void 0; 64937 var _main = _interopRequireDefault(_dereq_('../main')); 64938 var constants = _interopRequireWildcard(_dereq_('../constants')); 64939 var _helpers = _interopRequireDefault(_dereq_('../helpers')); 64940 _dereq_('../friendly_errors/fes_core'); 64941 _dereq_('../friendly_errors/file_errors'); 64942 _dereq_('../friendly_errors/validate_params'); 64943 function _getRequireWildcardCache() { 64944 if (typeof WeakMap !== 'function') return null; 64945 var cache = new WeakMap(); 64946 _getRequireWildcardCache = function _getRequireWildcardCache() { 64947 return cache; 64948 }; 64949 return cache; 64950 } 64951 function _interopRequireWildcard(obj) { 64952 if (obj && obj.__esModule) { 64953 return obj; 64954 } 64955 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 64956 return { 64957 default: 64958 obj 64959 }; 64960 } 64961 var cache = _getRequireWildcardCache(); 64962 if (cache && cache.has(obj)) { 64963 return cache.get(obj); 64964 } 64965 var newObj = { 64966 }; 64967 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 64968 for (var key in obj) { 64969 if (Object.prototype.hasOwnProperty.call(obj, key)) { 64970 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 64971 if (desc && (desc.get || desc.set)) { 64972 Object.defineProperty(newObj, key, desc); 64973 } else { 64974 newObj[key] = obj[key]; 64975 } 64976 } 64977 } 64978 newObj.default = obj; 64979 if (cache) { 64980 cache.set(obj, newObj); 64981 } 64982 return newObj; 64983 } 64984 function _interopRequireDefault(obj) { 64985 return obj && obj.__esModule ? obj : { 64986 default: 64987 obj 64988 }; 64989 } /** 64990 * @module Shape 64991 * @submodule 2D Primitives 64992 * @for p5 64993 * @requires core 64994 * @requires constants 64995 */ 64996 /** 64997 * This function does 3 things: 64998 * 64999 * 1. Bounds the desired start/stop angles for an arc (in radians) so that: 65000 * 65001 * 0 <= start < TWO_PI ; start <= stop < start + TWO_PI 65002 * 65003 * This means that the arc rendering functions don't have to be concerned 65004 * with what happens if stop is smaller than start, or if the arc 'goes 65005 * round more than once', etc.: they can just start at start and increase 65006 * until stop and the correct arc will be drawn. 65007 * 65008 * 2. Optionally adjusts the angles within each quadrant to counter the naive 65009 * scaling of the underlying ellipse up from the unit circle. Without 65010 * this, the angles become arbitrary when width != height: 45 degrees 65011 * might be drawn at 5 degrees on a 'wide' ellipse, or at 85 degrees on 65012 * a 'tall' ellipse. 65013 * 65014 * 3. Flags up when start and stop correspond to the same place on the 65015 * underlying ellipse. This is useful if you want to do something special 65016 * there (like rendering a whole ellipse instead). 65017 */ 65018 65019 _main.default.prototype._normalizeArcAngles = function (start, stop, width, height, correctForScaling) { 65020 var epsilon = 0.00001; // Smallest visible angle on displays up to 4K. 65021 var separation; // The order of the steps is important here: each one builds upon the 65022 // adjustments made in the steps that precede it. 65023 // Constrain both start and stop to [0,TWO_PI). 65024 start = start - constants.TWO_PI * Math.floor(start / constants.TWO_PI); 65025 stop = stop - constants.TWO_PI * Math.floor(stop / constants.TWO_PI); // Get the angular separation between the requested start and stop points. 65026 // 65027 // Technically this separation only matches what gets drawn if 65028 // correctForScaling is enabled. We could add a more complicated calculation 65029 // for when the scaling is uncorrected (in which case the drawn points could 65030 // end up pushed together or pulled apart quite dramatically relative to what 65031 // was requested), but it would make things more opaque for little practical 65032 // benefit. 65033 // 65034 // (If you do disable correctForScaling and find that correspondToSamePoint 65035 // is set too aggressively, the easiest thing to do is probably to just make 65036 // epsilon smaller...) 65037 separation = Math.min(Math.abs(start - stop), constants.TWO_PI - Math.abs(start - stop)); // Optionally adjust the angles to counter linear scaling. 65038 if (correctForScaling) { 65039 if (start <= constants.HALF_PI) { 65040 start = Math.atan(width / height * Math.tan(start)); 65041 } else if (start > constants.HALF_PI && start <= 3 * constants.HALF_PI) { 65042 start = Math.atan(width / height * Math.tan(start)) + constants.PI; 65043 } else { 65044 start = Math.atan(width / height * Math.tan(start)) + constants.TWO_PI; 65045 } 65046 if (stop <= constants.HALF_PI) { 65047 stop = Math.atan(width / height * Math.tan(stop)); 65048 } else if (stop > constants.HALF_PI && stop <= 3 * constants.HALF_PI) { 65049 stop = Math.atan(width / height * Math.tan(stop)) + constants.PI; 65050 } else { 65051 stop = Math.atan(width / height * Math.tan(stop)) + constants.TWO_PI; 65052 } 65053 } // Ensure that start <= stop < start + TWO_PI. 65054 65055 if (start > stop) { 65056 stop += constants.TWO_PI; 65057 } 65058 return { 65059 start: start, 65060 stop: stop, 65061 correspondToSamePoint: separation < epsilon 65062 }; 65063 }; 65064 /** 65065 * Draw an arc to the screen. If called with only x, y, w, h, start and stop, 65066 * the arc will be drawn and filled as an open pie segment. If a mode parameter 65067 * is provided, the arc will be filled like an open semi-circle (OPEN), a closed 65068 * semi-circle (CHORD), or as a closed pie segment (PIE). The origin may be changed 65069 * with the <a href="#/p5/ellipseMode">ellipseMode()</a> function. 65070 * 65071 * The arc is always drawn clockwise from wherever start falls to wherever stop 65072 * falls on the ellipse. Adding or subtracting TWO_PI to either angle does not 65073 * change where they fall. If both start and stop fall at the same place, a full 65074 * ellipse will be drawn. Be aware that the y-axis increases in the downward 65075 * direction, therefore angles are measured clockwise from the positive 65076 * x-direction ("3 o'clock"). 65077 * 65078 * @method arc 65079 * @param {Number} x x-coordinate of the arc's ellipse 65080 * @param {Number} y y-coordinate of the arc's ellipse 65081 * @param {Number} w width of the arc's ellipse by default 65082 * @param {Number} h height of the arc's ellipse by default 65083 * @param {Number} start angle to start the arc, specified in radians 65084 * @param {Number} stop angle to stop the arc, specified in radians 65085 * @param {Constant} [mode] optional parameter to determine the way of drawing 65086 * the arc. either CHORD, PIE or OPEN 65087 * @param {Integer} [detail] optional parameter for WebGL mode only. This is to 65088 * specify the number of vertices that makes up the 65089 * perimeter of the arc. Default value is 25. Won't 65090 * draw a stroke for a detail of more than 50. 65091 * @chainable 65092 * 65093 * @example 65094 * <div> 65095 * <code> 65096 * arc(50, 55, 50, 50, 0, HALF_PI); 65097 * noFill(); 65098 * arc(50, 55, 60, 60, HALF_PI, PI); 65099 * arc(50, 55, 70, 70, PI, PI + QUARTER_PI); 65100 * arc(50, 55, 80, 80, PI + QUARTER_PI, TWO_PI); 65101 * describe( 65102 * 'shattered outline of ellipse with a quarter of a white circle bottom-right' 65103 * ); 65104 * </code> 65105 * </div> 65106 * 65107 * <div> 65108 * <code> 65109 * arc(50, 50, 80, 80, 0, PI + QUARTER_PI); 65110 * describe('white ellipse with top right quarter missing'); 65111 * </code> 65112 * </div> 65113 * 65114 * <div> 65115 * <code> 65116 * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, OPEN); 65117 * describe('white ellipse with black outline with top right missing'); 65118 * </code> 65119 * </div> 65120 * 65121 * <div> 65122 * <code> 65123 * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, CHORD); 65124 * describe('white open arc with black outline with top right missing'); 65125 * </code> 65126 * </div> 65127 * 65128 * <div> 65129 * <code> 65130 * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, PIE); 65131 * describe( 65132 * 'white ellipse with top right quarter missing with black outline around the shape' 65133 * ); 65134 * </code> 65135 * </div> 65136 * 65137 */ 65138 _main.default.prototype.arc = function (x, y, w, h, start, stop, mode, detail) { 65139 _main.default._validateParameters('arc', arguments); // if the current stroke and fill settings wouldn't result in something 65140 // visible, exit immediately 65141 if (!this._renderer._doStroke && !this._renderer._doFill) { 65142 return this; 65143 } 65144 if (start === stop) { 65145 return this; 65146 } 65147 start = this._toRadians(start); 65148 stop = this._toRadians(stop); // p5 supports negative width and heights for ellipses 65149 w = Math.abs(w); 65150 h = Math.abs(h); 65151 var vals = _helpers.default.modeAdjust(x, y, w, h, this._renderer._ellipseMode); 65152 var angles = this._normalizeArcAngles(start, stop, vals.w, vals.h, true); 65153 if (angles.correspondToSamePoint) { 65154 // If the arc starts and ends at (near enough) the same place, we choose to 65155 // draw an ellipse instead. This is preferable to faking an ellipse (by 65156 // making stop ever-so-slightly less than start + TWO_PI) because the ends 65157 // join up to each other rather than at a vertex at the centre (leaving 65158 // an unwanted spike in the stroke/fill). 65159 this._renderer.ellipse([vals.x, 65160 vals.y, 65161 vals.w, 65162 vals.h, 65163 detail]); 65164 } else { 65165 this._renderer.arc(vals.x, vals.y, vals.w, vals.h, angles.start, // [0, TWO_PI) 65166 angles.stop, // [start, start + TWO_PI) 65167 mode, detail); //accessible Outputs 65168 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 65169 this._accsOutput('arc', [ 65170 vals.x, 65171 vals.y, 65172 vals.w, 65173 vals.h, 65174 angles.start, 65175 angles.stop, 65176 mode 65177 ]); 65178 } 65179 } 65180 return this; 65181 }; 65182 /** 65183 * Draws an ellipse (oval) to the screen. By default, the first two parameters 65184 * set the location of the center of the ellipse, and the third and fourth 65185 * parameters set the shape's width and height. If no height is specified, the 65186 * value of width is used for both the width and height. If a negative height or 65187 * width is specified, the absolute value is taken. 65188 * 65189 * An ellipse with equal width and height is a circle. The origin may be changed 65190 * with the <a href="#/p5/ellipseMode">ellipseMode()</a> function. 65191 * 65192 * @method ellipse 65193 * @param {Number} x x-coordinate of the center of the ellipse. 65194 * @param {Number} y y-coordinate of the center of the ellipse. 65195 * @param {Number} w width of the ellipse. 65196 * @param {Number} [h] height of the ellipse. 65197 * @chainable 65198 * @example 65199 * <div> 65200 * <code> 65201 * ellipse(56, 46, 55, 55); 65202 * describe('white ellipse with black outline in middle of a gray canvas'); 65203 * </code> 65204 * </div> 65205 * 65206 */ 65207 /** 65208 * @method ellipse 65209 * @param {Number} x 65210 * @param {Number} y 65211 * @param {Number} w 65212 * @param {Number} h 65213 * @param {Integer} [detail] optional parameter for WEBGL mode only. This is to 65214 * specify the number of vertices that makes up the 65215 * perimeter of the ellipse. Default value is 25. Won't 65216 * draw a stroke for a detail of more than 50. 65217 */ 65218 _main.default.prototype.ellipse = function (x, y, w, h, detailX) { 65219 _main.default._validateParameters('ellipse', arguments); 65220 return this._renderEllipse.apply(this, arguments); 65221 }; 65222 /** 65223 * Draws a circle to the screen. A circle is a simple closed shape. It is the set 65224 * of all points in a plane that are at a given distance from a given point, 65225 * the center. This function is a special case of the 65226 * <a href="#/p5/ellipse">ellipse()</a> function, where the width and height 65227 * of the ellipse are the same. Height and width of the ellipse correspond to 65228 * the diameter of the circle. By default, the first two parameters set the 65229 * location of the center of the circle, the third sets the diameter of the 65230 * circle. 65231 * 65232 * @method circle 65233 * @param {Number} x x-coordinate of the center of the circle. 65234 * @param {Number} y y-coordinate of the center of the circle. 65235 * @param {Number} d diameter of the circle. 65236 * @chainable 65237 * @example 65238 * <div> 65239 * <code> 65240 * // Draw a circle at location (30, 30) with a diameter of 20. 65241 * circle(30, 30, 20); 65242 * describe('white circle with black outline in mid of gray canvas'); 65243 * </code> 65244 * </div> 65245 * 65246 */ 65247 _main.default.prototype.circle = function () { 65248 _main.default._validateParameters('circle', arguments); 65249 var args = Array.prototype.slice.call(arguments, 0, 2); 65250 args.push(arguments[2]); 65251 args.push(arguments[2]); 65252 return this._renderEllipse.apply(this, args); 65253 }; // internal method for drawing ellipses (without parameter validation) 65254 _main.default.prototype._renderEllipse = function (x, y, w, h, detailX) { 65255 // if the current stroke and fill settings wouldn't result in something 65256 // visible, exit immediately 65257 if (!this._renderer._doStroke && !this._renderer._doFill) { 65258 return this; 65259 } // p5 supports negative width and heights for rects 65260 65261 if (w < 0) { 65262 w = Math.abs(w); 65263 } 65264 if (typeof h === 'undefined') { 65265 // Duplicate 3rd argument if only 3 given. 65266 h = w; 65267 } else if (h < 0) { 65268 h = Math.abs(h); 65269 } 65270 var vals = _helpers.default.modeAdjust(x, y, w, h, this._renderer._ellipseMode); 65271 this._renderer.ellipse([vals.x, 65272 vals.y, 65273 vals.w, 65274 vals.h, 65275 detailX]); //accessible Outputs 65276 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 65277 this._accsOutput('ellipse', [ 65278 vals.x, 65279 vals.y, 65280 vals.w, 65281 vals.h 65282 ]); 65283 } 65284 return this; 65285 }; 65286 /** 65287 * Draws a line (a direct path between two points) to the screen. If called with 65288 * only 4 parameters, it will draw a line in 2D with a default width of 1
65288 pixel. 65289 * This width can be modified by using the <a href="#/p5/strokeWeight"> 65290 * strokeWeight()</a> function. A line cannot be filled, therefore the <a 65291 * href="#/p5/fill">fill()</a> function will not affect the color of a line. So to 65292 * color a line, use the <a href="#/p5/stroke">stroke()</a> function. 65293 * 65294 * @method line 65295 * @param {Number} x1 the x-coordinate of the first point 65296 * @param {Number} y1 the y-coordinate of the first point 65297 * @param {Number} x2 the x-coordinate of the second point 65298 * @param {Number} y2 the y-coordinate of the second point 65299 * @chainable 65300 * @example 65301 * <div> 65302 * <code> 65303 * line(30, 20, 85, 75); 65304 * describe( 65305 * 'a 78 pixels long line running from mid-top to bottom-right of canvas' 65306 * ); 65307 * </code> 65308 * </div> 65309 * 65310 * <div> 65311 * <code> 65312 * line(30, 20, 85, 20); 65313 * stroke(126); 65314 * line(85, 20, 85, 75); 65315 * stroke(255); 65316 * line(85, 75, 30, 75); 65317 * describe( 65318 * '3 lines of various stroke colors. Form top, bottom and right sides of a square' 65319 * ); 65320 * </code> 65321 * </div> 65322 * 65323 */ 65324 /** 65325 * @method line 65326 * @param {Number} x1 65327 * @param {Number} y1 65328 * @param {Number} z1 the z-coordinate of the first point 65329 * @param {Number} x2 65330 * @param {Number} y2 65331 * @param {Number} z2 the z-coordinate of the second point 65332 * @chainable 65333 */ 65334 _main.default.prototype.line = function () { 65335 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 65336 args[_key] = arguments[_key]; 65337 } 65338 _main.default._validateParameters('line', args); 65339 if (this._renderer._doStroke) { 65340 var _this$_renderer; 65341 (_this$_renderer = this._renderer).line.apply(_this$_renderer, args); 65342 } //accessible Outputs 65343 65344 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 65345 this._accsOutput('line', args); 65346 } 65347 return this; 65348 }; 65349 /** 65350 * Draws a point, a coordinate in space at the dimension of one pixel. 65351 * The first parameter is the horizontal value for the point, the second 65352 * param is the vertical value for the point. The color of the point is 65353 * changed with the <a href="#/p5/stroke">stroke()</a> function. The size of the point 65354 * can be changed with the <a href="#/p5/strokeWeight">
65354strokeWeight()</a> function. 65355 * 65356 * @method point 65357 * @param {Number} x the x-coordinate 65358 * @param {Number} y the y-coordinate 65359 * @param {Number} [z] the z-coordinate (for WebGL mode) 65360 * @chainable 65361 * @example 65362 * <div> 65363 * <code> 65364 * point(30, 20); 65365 * point(85, 20); 65366 * point(85, 75); 65367 * point(30, 75); 65368 * describe('4 points create the corners of a square'); 65369 * </code> 65370 * </div> 65371 * 65372 * <div> 65373 * <code> 65374 * point(30, 20); 65375 * point(85, 20); 65376 * stroke('purple'); // Change the color 65377 * strokeWeight(10); // Make the points 10 pixels in size 65378 * point(85, 75); 65379 * point(30, 75); 65380 * describe('2 points and 2 large purple points in middle-right of canvas'); 65381 * </code> 65382 * </div> 65383 * 65384 * <div> 65385 * <code> 65386 * let a = createVector(10, 10); 65387 * point(a); 65388 * let b = createVector(10, 20); 65389 * point(b); 65390 * point(createVector(20, 10)); 65391 * point(createVector(20, 20)); 65392 * describe( 65393 * 'four points create vertices of 10x10 pixel square on top-left of canvas' 65394 * ); 65395 * </code> 65396 * </div> 65397 * 65398 */ 65399 /** 65400 * @method point 65401 * @param {p5.Vector} coordinate_vector the coordinate vector 65402 * @chainable 65403 */ 65404 _main.default.prototype.point = function () { 65405 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 65406 args[_key2] = arguments[_key2]; 65407 } 65408 _main.default._validateParameters('point', args); 65409 if (this._renderer._doStroke) { 65410 if (args.length === 1 && args[0] instanceof _main.default.Vector) { 65411 this._renderer.point.call(this._renderer, args[0].x, args[0].y, args[0].z); 65412 } else { 65413 var _this$_renderer2; 65414 (_this$_renderer2 = this._renderer).point.apply(_this$_renderer2, args); //accessible Outputs 65415 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 65416 this._accsOutput('point', args); 65417 } 65418 } 65419 } 65420 return this; 65421 }; 65422 /** 65423 * Draws a quad on the canvas. A quad is a quadrilateral, a four-sided polygon. It is 65424 * similar to a rectangle, but the angles between its edges are not 65425 * constrained to ninety degrees. The first pair of parameters (x1,y1) 65426 * sets the first vertex and the subsequent pairs should proceed 65427 * clockwise or counter-clockwise around the defined shape. 65428 * z-arguments only work when quad() is used in WEBGL mode. 65429 * 65430 * @method quad 65431 * @param {Number} x1 the x-coordinate of the first point 65432 * @param {Number} y1 the y-coordinate of the first point 65433 * @param {Number} x2 the x-coordinate of the second point 65434 * @param {Number} y2 the y-coordinate of the second point 65435 * @param {Number} x3 the x-coordinate of the third point 65436 * @param {Number} y3 the y-coordinate of the third point 65437 * @param {Number} x4 the x-coordinate of the fourth point 65438 * @param {Number} y4 the y-coordinate of the fourth point 65439 * @param {Integer} [detailX] number of segments in the x-direction 65440 * @param {Integer} [detailY] number of segments in the y-direction 65441 * @chainable 65442 * @example 65443 * <div> 65444 * <code> 65445 * quad(38, 31, 86, 20, 69, 63, 30, 76); 65446 * describe('irregular white quadrilateral with black outline'); 65447 * </code> 65448 * </div> 65449 * 65450 */ 65451 /** 65452 * @method quad 65453 * @param {Number} x1 65454 * @param {Number} y1 65455 * @param {Number} z1 the z-coordinate of the first point 65456 * @param {Number} x2 65457 * @param {Number} y2 65458 * @param {Number} z2 the z-coordinate of the second point 65459 * @param {Number} x3 65460 * @param {Number} y3 65461 * @param {Number} z3 the z-coordinate of the third point 65462 * @param {Number} x4 65463 * @param {Number} y4 65464 * @param {Number} z4 the z-coordinate of the fourth point 65465 * @param {Integer} [detailX] 65466 * @param {Integer} [detailY] 65467 * @chainable 65468 */ 65469 _main.default.prototype.quad = function () { 65470 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 65471 args[_key3] = arguments[_key3]; 65472 } 65473 _main.default._validateParameters('quad', args); 65474 if (this._renderer._doStroke || this._renderer._doFill) { 65475 if (this._renderer.isP3D && args.length < 12) { 65476 // if 3D and we weren't passed 12 args, assume Z is 0 65477 this._renderer.quad.call(this._renderer, args[0], args[1], 0, args[2], args[3], 0, args[4], args[5], 0, args[6], args[7], 0, args[8], args[9]); 65478 } else { 65479 var _this$_renderer3; 65480 (_this$_renderer3 = this._renderer).quad.apply(_this$_renderer3, args); //accessibile outputs 65481 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 65482 this._accsOutput('quadrilateral', args); 65483 } 65484 } 65485 } 65486 return this; 65487 }; 65488 /** 65489 * Draws a rectangle on the canvas. A rectangle is a four-sided closed shape with 65490 * every angle at ninety degrees. By default, the first two parameters set 65491 * the location of the upper-left corner, the third sets the width, and the 65492 * fourth sets the height. The way these parameters are interpreted may be 65493 * changed with the <a href="#/p5/rectMode">rectMode()</a> function. 65494 * 65495 * The fifth, sixth, seventh and eighth parameters, if specified, 65496 * determine corner radius for the top-left, top-right, lower-right and 65497 * lower-left corners, respectively. An omitted corner radius parameter is set 65498 * to the value of the previously specified radius value in the parameter list. 65499 * 65500 * @method rect 65501 * @param {Number} x x-coordinate of the rectangle. 65502 * @param {Number} y y-coordinate of the rectangle. 65503 * @param {Number} w width of the rectangle. 65504 * @param {Number} [h] height of the rectangle. 65505 * @param {Number} [tl] optional radius of top-left corner. 65506 * @param {Number} [tr] optional radius of top-right corner. 65507 * @param {Number} [br] optional radius of bottom-right corner. 65508 * @param {Number} [bl] optional radius of bottom-left corner. 65509 * @chainable 65510 * @example 65511 * <div> 65512 * <code> 65513 * // Draw a rectangle at location (30, 20) with a width and height of 55. 65514 * rect(30, 20, 55, 55); 65515 * describe('white rect with black outline in mid-right of canvas'); 65516 * </code> 65517 * </div> 65518 * 65519 * <div> 65520 * <code> 65521 * // Draw a rectangle with rounded corners, each having a radius of 20. 65522 * rect(30, 20, 55, 55, 20); 65523 * describe( 65524 * 'white rect with black outline and round edges in mid-right of canvas' 65525 * ); 65526 * </code> 65527 * </div> 65528 * 65529 * <div> 65530 * <code> 65531 * // Draw a rectangle with rounded corners having the following radii: 65532 * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5. 65533 * rect(30, 20, 55, 55, 20, 15, 10, 5); 65534 * describe('white rect with black outline and round edges of different radii'); 65535 * </code> 65536 * </div> 65537 * 65538 */ 65539 /** 65540 * @method rect 65541 * @param {Number} x 65542 * @param {Number} y 65543 * @param {Number} w 65544 * @param {Number} h 65545 * @param {Integer} [detailX] number of segments in the x-direction (for WebGL mode) 65546 * @param {Integer} [detailY] number of segments in the y-direction (for WebGL mode) 65547 * @chainable 65548 */ 65549 _main.default.prototype.rect = function () { 65550 _main.default._validateParameters('rect', arguments); 65551 return this._renderRect.apply(this, arguments); 65552 }; 65553 /**
65554 * Draws a square to the screen. A square is a four-sided shape with every angle 65555 * at ninety degrees, and equal side size. This function is a special case of the 65556 * rect() function, where the width and height are the same, and the parameter 65557 * is called "s" for side size. By default, the first two parameters set the 65558 * location of the upper-left corner, the third sets the side size of the square. 65559 * The way these parameters are interpreted, may be changed with the <a 65560 * href="#/p5/rectMode">rectMode()</a> function. 65561 * 65562 * The fourth, fifth, sixth and seventh parameters, if specified, 65563 * determine corner radius for the top-left, top-right, lower-right and 65564 * lower-left corners, respectively. An omitted corner radius parameter is set 65565 * to the value of the previously specified radius value in the parameter list. 65566 * 65567 * @method square 65568 * @param {Number} x x-coordinate of the square. 65569 * @param {Number} y y-coordinate of the square. 65570 * @param {Number} s side size of the square. 65571 * @param {Number} [tl] optional radius of top-left corner. 65572 * @param {Number} [tr] optional radius of top-right corner. 65573 * @param {Number} [br] optional radius of bottom-right corner. 65574 * @param {Number} [bl] optional radius of bottom-left corner. 65575 * @chainable 65576 * @example 65577 * <div> 65578 * <code> 65579 * // Draw a square at location (30, 20) with a side size of 55. 65580 * square(30, 20, 55); 65581 * describe('white square with black outline in mid-right of canvas'); 65582 * </code> 65583 * </div> 65584 * 65585 * <div> 65586 * <code> 65587 * // Draw a square with rounded corners, each having a radius of 20. 65588 * square(30, 20, 55, 20); 65589 * describe( 65590 * 'white square with black outline and round edges in mid-right of canvas' 65591 * ); 65592 * </code> 65593 * </div> 65594 * 65595 * <div> 65596 * <code> 65597 * // Draw a square with rounded corners having the following radii: 65598 * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5. 65599 * square(30, 20, 55, 20, 15, 10, 5); 65600 * describe('white square with black outline and round edges of different radii'); 65601 * </code> 65602 * </div> 65603 * 65604 */ 65605 _main.default.prototype.square = function (x, y, s, tl, tr, br, bl) { 65606 _main.default._validateParameters('square', arguments); // duplicate width for height in case of square 65607 return this._renderRect.call(this, x, y, s, s, tl, tr, br, bl); 65608 }; // internal method to have renderer draw a rectangle 65609 _main.default.prototype._renderRect = function () { 65610 if (this._renderer._doStroke || this._renderer._doFill) { 65611 // duplicate width for height in case only 3 arguments is provided 65612 if (arguments.length === 3) { 65613 arguments[3] = arguments[2]; 65614 } 65615 var vals = _helpers.default.modeAdjust(arguments[0], arguments[1], arguments[2], arguments[3], this._renderer._rectMode); 65616 var args = [ 65617 vals.x, 65618 vals.y, 65619 vals.w, 65620 vals.h 65621 ]; // append the additional arguments (either cornder radii, or 65622 // segment details) to the argument list 65623 for (var i = 4; i < arguments.length; i++) { 65624 args[i] = arguments[i]; 65625 } 65626 this._renderer.rect(args); //accessible outputs 65627 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 65628 this._accsOutput('rectangle', [ 65629 vals.x, 65630 vals.y, 65631 vals.w, 65632 vals.h 65633 ]); 65634 } 65635 } 65636 return this; 65637 }; 65638 /** 65639 * Draws a triangle to the canvas. A triangle is a plane created by connecting 65640 * three points. The first two arguments specify the first point, the middle two 65641 * arguments specify the second point, and the last two arguments specify the 65642 * third point. 65643 * 65644 * @method triangle 65645 * @param {Number} x1 x-coordinate of the first point 65646 * @param {Number} y1 y-coordinate of the first point 65647 * @param {Number} x2 x-coordinate of the second point 65648 * @param {Number} y2 y-coordinate of the second point 65649 * @param {Number} x3 x-coordinate of the third point 65650 * @param {Number} y3 y-coordinate of the third point 65651 * @chainable 65652 * @example 65653 * <div> 65654 * <code> 65655 * triangle(30, 75, 58, 20, 86, 75); 65656 * describe('white triangle with black outline in mid-right of canvas'); 65657 * </code> 65658 * </div> 65659 * 65660 */ 65661 _main.default.prototype.triangle = function () { 65662 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
65663 args[_key4] = arguments[_key4]; 65664 } 65665 _main.default._validateParameters('triangle', args); 65666 if (this._renderer._doStroke || this._renderer._doFill) { 65667 this._renderer.triangle(args); 65668 } //accessible outputs 65669 65670 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 65671 this._accsOutput('triangle', args); 65672 } 65673 return this; 65674 }; 65675 var _default = _main.default; 65676 exports.default = _default; 65677 }, 65678 { 65679 '../constants': 278, 65680 '../friendly_errors/fes_core': 281, 65681 '../friendly_errors/file_errors': 282, 65682 '../friendly_errors/validate_params': 285, 65683 '../helpers': 286, 65684 '../main': 290, 65685 'core-js/modules/es.array.iterator': 176, 65686 'core-js/modules/es.array.slice': 180, 65687 'core-js/modules/es.object.get-own-property-descriptor': 191, 65688 'core-js/modules/es.object.to-string': 195, 65689 'core-js/modules/es.string.iterator': 204, 65690 'core-js/modules/es.symbol': 214, 65691 'core-js/modules/es.symbol.description': 212, 65692 'core-js/modules/es.symbol.iterator': 213, 65693 'core-js/modules/es.weak-map': 246, 65694 'core-js/modules/web.dom-collections.iterator': 248 65695 } 65696 ], 65697 298: [ 65698 function (_dereq_, module, exports) { 65699 'use strict'; 65700 _dereq_('core-js/modules/es.symbol'); 65701 _dereq_('core-js/modules/es.symbol.description'); 65702 _dereq_('core-js/modules/es.symbol.iterator'); 65703 _dereq_('core-js/modules/es.array.iterator'); 65704 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 65705 _dereq_('core-js/modules/es.object.to-string'); 65706 _dereq_('core-js/modules/es.string.iterator'); 65707 _dereq_('core-js/modules/es.weak-map'); 65708 _dereq_('core-js/modules/web.dom-collections.iterator'); 65709 function _typeof2(obj) { 65710 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 65711 _typeof2 = function _typeof2(obj) { 65712 return typeof obj; 65713 }; 65714 } else { 65715 _typeof2 = function _typeof2(obj) { 65716 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 65717 }; 65718 } 65719 return _typeof2(obj); 65720 } 65721 function _typeof(obj) { 65722 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 65723 _typeof = function _typeof(obj) { 65724 return _typeof2(obj); 65725 }; 65726 } else { 65727 _typeof = function _typeof(obj) { 65728 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 65729 }; 65730 } 65731 return _typeof(obj); 65732 } 65733 Object.defineProperty(exports, '__esModule', { 65734 value: true 65735 }); 65736 exports.default = void 0; 65737 var _main = _interopRequireDefault(_dereq_('../main')); 65738 var constants = _interopRequireWildcard(_dereq_('../constants')); 65739 function _getRequireWildcardCache() { 65740 if (typeof WeakMap !== 'function') return null; 65741 var cache = new WeakMap(); 65742 _getRequireWildcardCache = function _getRequireWildcardCache() { 65743 return cache; 65744 }; 65745 return cache; 65746 } 65747 function _interopRequireWildcard(obj) { 65748 if (obj && obj.__esModule) { 65749 return obj; 65750 } 65751 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 65752 return { 65753 default: 65754 obj 65755 }; 65756 } 65757 var cache = _getRequireWildcardCache(); 65758 if (cache && cache.has(obj)) { 65759 return cache.get(obj); 65760 } 65761 var newObj = { 65762 }; 65763 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 65764 for (var key in obj) { 65765 if (Object.prototype.hasOwnProperty.call(obj, key)) { 65766 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 65767 if (desc && (desc.get || desc.set)) { 65768 Object.defineProperty(newObj, key, desc); 65769 } else { 65770 newObj[key] = obj[key]; 65771 } 65772 } 65773 } 65774 newObj.default = obj; 65775 if (cache) { 65776 cache.set(obj, newObj); 65777 } 65778 return newObj; 65779 } 65780 function _interopRequireDefault(obj) { 65781 return obj && obj.__esModule ? obj : { 65782 default: 65783 obj 65784 }; 65785 } /** 65786 * @module Shape 65787 * @submodule Attributes 65788 * @for p5 65789 * @requires core 65790 * @requires constants 65791 */ 65792 /** 65793 * Modifies the location from which ellipses are drawn by changing the way in 65794 * which parameters given to <a href="#/p5/ellipse">ellipse()</a>, 65795 * <a href="#/p5/circle">circle()</a> and <a href="#/p5/arc">arc()</a> are interpreted. 65796 * 65797 * The default mode is `CENTER`, in which the first two parameters are interpreted 65798 * as the shape's center point's x and y coordinates respectively, while the third 65799 * and fourth parameters are its width and height. 65800 * 65801 * `ellipseMode(RADIUS)` also uses the first two parameters as the shape's center 65802 * point's x and y coordinates, but uses the third and fourth parameters to 65803 * specify half of the shapes's width and height. 65804 * 65805 * `ellipseMode(CORNER)` interprets the first two parameters as the upper-left 65806 * corner of the shape, while the third and fourth parameters are its width 65807 * and height. 65808 * 65809 * `ellipseMode(CORNERS)` interprets the first two parameters as the location of 65810 * one corner of the ellipse's bounding box, and the third and fourth parameters 65811 * as the location of the opposite corner. 65812 * 65813 * The parameter to this method must be written in ALL CAPS because they are 65814 * predefined as constants in ALL CAPS and Javascript is a case-sensitive language. 65815 * 65816 * @method ellipseMode 65817 * @param {Constant} mode either CENTER, RADIUS, CORNER, or CORNERS 65818 * @chainable 65819 * @example 65820 * <div> 65821 * <code> 65822 * // Example showing RADIUS and CENTER ellipsemode with 2 overlaying ellipses 65823 * ellipseMode(RADIUS); 65824 * fill(255); 65825 * ellipse(50, 50, 30, 30); // Outer white ellipse 65826 * ellipseMode(CENTER); 65827 * fill(100); 65828 * ellipse(50, 50, 30, 30); // Inner gray ellipse 65829 * </code> 65830 * </div> 65831 * 65832 * <div> 65833 * <code> 65834 * // Example showing CORNER and CORNERS ellipseMode with 2 overlaying ellipses 65835 * ellipseMode(CORNER); 65836 * fill(255); 65837 * ellipse(25, 25, 50, 50); // Outer white ellipse 65838 * ellipseMode(CORNERS); 65839 * fill(100); 65840 * ellipse(25, 25, 50, 50); // Inner gray ellipse 65841 * </code> 65842 * </div> 65843 * 65844 * @alt 65845 * 60Ã60 white ellipse and 30Ã30 grey ellipse with black outlines at center. 65846 * 60Ã60 white ellipse and 30Ã30 grey ellipse top-right with black outlines. 65847 */ 65848 65849 _main.default.prototype.ellipseMode = function (m) { 65850 _main.default._validateParameters('ellipseMode', arguments); 65851 if (m === constants.CORNER || m === constants.CORNERS || m === constants.RADIUS || m === constants.CENTER) { 65852 this._renderer._ellipseMode = m; 65853 } 65854 return this; 65855 }; 65856 /** 65857 * Draws all geometry with jagged (aliased) edges. 65858 *
65859 * Note that <a href="#/p5/smooth">smooth()</a> is active by default in 2D mode, so it is 65860 * necessary to call <a href="#/p5/noSmooth">noSmooth()</a> to disable smoothing of geometry, 65861 * images, and fonts. 65862 * 65863 * In 3D mode, <a href="#/p5/noSmooth">noSmooth()</a> is enabled by default, so it is necessary 65864 * to call <a href="#/p5/smooth">smooth()</a> if you would like smooth (antialiased) edges on your 65865 * geometry. 65866 * 65867 * @method noSmooth 65868 * @chainable 65869 * @example 65870 * <div> 65871 * <code> 65872 * background(0); 65873 * noStroke(); 65874 * smooth(); 65875 * ellipse(30, 48, 36, 36); 65876 * noSmooth(); 65877 * ellipse(70, 48, 36, 36); 65878 * </code> 65879 * </div> 65880 * 65881 * @alt 65882 * 2 pixelated 36Ã36 white ellipses to left & right of center, black background 65883 */ 65884 _main.default.prototype.noSmooth = function () { 65885 if (!this._renderer.isP3D) { 65886 if ('imageSmoothingEnabled' in this.drawingContext) { 65887 this.drawingContext.imageSmoothingEnabled = false; 65888 } 65889 } else { 65890 this.setAttributes('antialias', false); 65891 } 65892 return this; 65893 }; 65894 /** 65895 * Modifies the location from which rectangles are drawn by changing the way 65896 * in which parameters given to <a href="#/p5/rect">rect()</a> are interpreted. 65897 * 65898 * The default mode is `CORNER`, which interprets the first two parameters as the 65899 * upper-left corner of the shape, while the third and fourth parameters are its 65900 * width and height. 65901 * 65902 * `rectMode(CORNERS)` interprets the first two parameters as the location of 65903 * one of the corners, and the third and fourth parameters as the location of 65904 * the diagonally opposite corner. Note, the rectangle is drawn between the 65905 * coordinates, so it is not necessary that the first corner be the upper left 65906 * corner. 65907 * 65908 * `rectMode(CENTER)` interprets the first two parameters as the shape's center 65909 * point, while the third and fourth parameters are its width and height. 65910 * 65911 * `rectMode(RADIUS)` also uses the first two parameters as the shape's center 65912 * point, but uses the third and fourth parameters to specify half of the shape's 65913 * width and height respectively. 65914 * 65915 * The parameter to this method must be written in ALL CAPS because they are 65916 * predefined as constants in ALL CAPS and Javascript is a case-sensitive language. 65917 * 65918 * @method rectMode 65919 * @param {Constant} mode either CORNER, CORNERS, CENTER, or RADIUS 65920 * @chainable 65921 * @example 65922 * <div> 65923 * <code> 65924 * rectMode(CORNER); 65925 * fill(255); 65926 * rect(25, 25, 50, 50); // Draw white rectangle using CORNER mode 65927 * 65928 * rectMode(CORNERS); 65929 * fill(100); 65930 * rect(25, 25, 50, 50); // Draw gray rectangle using CORNERS mode 65931 * </code> 65932 * </div> 65933 * 65934 * <div> 65935 * <code> 65936 * rectMode(RADIUS); 65937 * fill(255); 65938 * rect(50, 50, 30, 30); // Draw white rectangle using RADIUS mode 65939 * 65940 * rectMode(CENTER); 65941 * fill(100); 65942 * rect(50, 50, 30, 30); // Draw gray rectangle using CENTER mode 65943 * </code> 65944 * </div> 65945 * 65946 * @alt 65947 * 50Ã50 white rect at center and 25Ã25 grey rect in the top left of the other. 65948 * 50Ã50 white rect at center and 25Ã25 grey rect in the center of the other. 65949 */ 65950 _main.default.prototype.rectMode = function (m) { 65951 _main.default._validateParameters('rectMode', arguments); 65952 if (m === constants.CORNER || m === constants.CORNERS || m === constants.RADIUS || m === constants.CENTER) { 65953 this._renderer._rectMode = m; 65954 } 65955 return this; 65956 }; 65957 /** 65958 * Draws all geometry with smooth (anti-aliased) edges. <a href="#/p5/smooth">smooth()</a> will also 65959 * improve image quality of resized images. 65960 * 65961 * Note that <a href="#/p5/smooth">smooth()</a> is active by default in 2D mode; 65962 * <a href="#/p5/noSmooth">noSmooth()</a> can be used to disable smoothing of geometry, 65963 * images, and fonts. 65964 * 65965 * In 3D mode, <a href="#/p5/noSmooth">noSmooth()</a> is enabled by default, so it is 65966 * necessary to call <a href="#/p5/smooth">smooth()</a> if you would like smooth (antialiased) 65967 * edges on your geometry. 65968 * 65969 * @method smooth 65970 * @chainable 65971 * @example 65972 * <div> 65973 * <code> 65974 * background(0); 65975 * noStroke(); 65976 * smooth(); 65977 * ellipse(30, 48, 36, 36); 65978 * noSmooth(); 65979 * ellipse(70, 48, 36, 36); 65980 * </code> 65981 * </div> 65982 * 65983 * @alt 65984 * 2 pixelated 36Ã36 white ellipses one left one right of center. On black. 65985 */ 65986 _main.default.prototype.smooth = function () { 65987 this.setAttributes('antialias', true); 65988 if (!this._renderer.isP3D) { 65989 if ('imageSmoothingEnabled' in this.drawingContext) {
65990 this.drawingContext.imageSmoothingEnabled = true; 65991 } 65992 } 65993 return this; 65994 }; 65995 /** 65996 * Sets the style for rendering line endings. These ends are either rounded, 65997 * squared, or extended, each of which specified with the corresponding 65998 * parameters: `ROUND`, `SQUARE`, or `PROJECT`. The default cap is `ROUND`. 65999 * 66000 * The parameter to this method must be written in ALL CAPS because they are 66001 * predefined as constants in ALL CAPS and Javascript is a case-sensitive language. 66002 * 66003 * @method strokeCap 66004 * @param {Constant} cap either ROUND, SQUARE, or PROJECT 66005 * @chainable 66006 * @example 66007 * <div> 66008 * <code> 66009 * // Example of different strokeCaps 66010 * strokeWeight(12.0); 66011 * strokeCap(ROUND); 66012 * line(20, 30, 80, 30); 66013 * strokeCap(SQUARE); 66014 * line(20, 50, 80, 50); 66015 * strokeCap(PROJECT); 66016 * line(20, 70, 80, 70); 66017 * </code> 66018 * </div> 66019 * 66020 * @alt 66021 * 3 lines. Top line: rounded ends, mid: squared, bottom:longer squared ends. 66022 */ 66023 _main.default.prototype.strokeCap = function (cap) { 66024 _main.default._validateParameters('strokeCap', arguments); 66025 if (cap === constants.ROUND || cap === constants.SQUARE || cap === constants.PROJECT) { 66026 this._renderer.strokeCap(cap); 66027 } 66028 return this; 66029 }; 66030 /** 66031 * Sets the style of the joints which connect line segments. These joints 66032 * are either mitered, beveled, or rounded and specified with the 66033 * corresponding parameters: `MITER`, `BEVEL`, or `ROUND`. The default joint is 66034 * `MITER` in 2D mode and `ROUND` in WebGL mode. 66035 * 66036 * The parameter to this method must be written in ALL CAPS because they are 66037 * predefined as constants in ALL CAPS and Javascript is a case-sensitive language. 66038 * 66039 * @method strokeJoin 66040 * @param {Constant} join either MITER, BEVEL, or ROUND 66041 * @chainable 66042 * @example 66043 * <div> 66044 * <code> 66045 * // Example of MITER type of joints 66046 * noFill(); 66047 * strokeWeight(10.0); 66048 * strokeJoin(MITER); 66049 * beginShape(); 66050 * vertex(35, 20); 66051 * vertex(65, 50); 66052 * vertex(35, 80); 66053 * endShape(); 66054 * </code> 66055 * </div> 66056 * 66057 * <div> 66058 * <code> 66059 * // Example of BEVEL type of joints 66060 * noFill(); 66061 * strokeWeight(10.0); 66062 * strokeJoin(BEVEL); 66063 * beginShape(); 66064 * vertex(35, 20); 66065 * vertex(65, 50); 66066 * vertex(35, 80); 66067 * endShape(); 66068 * </code> 66069 * </div> 66070 * 66071 * <div> 66072 * <code> 66073 * // Example of ROUND type of joints 66074 * noFill(); 66075 * strokeWeight(10.0); 66076 * strokeJoin(ROUND); 66077 * beginShape(); 66078 * vertex(35, 20); 66079 * vertex(65, 50); 66080 * vertex(35, 80); 66081 * endShape(); 66082 * </code> 66083 * </div> 66084 * 66085 * @alt 66086 * Right-facing arrowhead shape with pointed tip in center of canvas. 66087 * Right-facing arrowhead shape with flat tip in center of canvas. 66088 * Right-facing arrowhead shape with rounded tip in center of canvas. 66089 */ 66090 _main.default.prototype.strokeJoin = function (join) { 66091 _main.default._validateParameters('strokeJoin', arguments); 66092 if (join === constants.ROUND || join === constants.BEVEL || join === constants.MITER) { 66093 this._renderer.strokeJoin(join); 66094 } 66095 return this; 66096 }; 66097 /** 66098 * Sets the width of the stroke used for lines, points, and the border around 66099 * shapes. All widths are set in units of pixels. 66100 * 66101 * Note that it is affected by any transformation or scaling that has 66102 * been applied previously. 66103 * 66104 * @method strokeWeight 66105 * @param {Number} weight the weight of the stroke (in pixels) 66106 * @chainable 66107 * @example 66108 * <div> 66109 * <code> 66110 * // Example of different stroke weights 66111 * strokeWeight(1); // Default 66112 * line(20, 20, 80, 20);
66113 * strokeWeight(4); // Thicker 66114 * line(20, 40, 80, 40); 66115 * strokeWeight(10); // Beastly 66116 * line(20, 70, 80, 70); 66117 * </code> 66118 * </div> 66119 * 66120 * <div> 66121 * <code> 66122 * //Example of stroke weights 66123 * //after transformations 66124 * strokeWeight(1); // Default 66125 * line(20, 20, 80, 20); 66126 * scale(5); // Adding scale transformation 66127 * strokeWeight(1); // Resulting strokeweight is 5 66128 * line(4, 8, 16, 8); // Coordinates adjusted for scaling 66129 * </code> 66130 * </div> 66131 * 66132 * @alt 66133 * 3 horizontal black lines. Top line: thin, mid: medium, bottom:thick. 66134 * 2 horizontal black line. Top line: thin, botton line: 5 times thicker than top 66135 */ 66136 _main.default.prototype.strokeWeight = function (w) { 66137 _main.default._validateParameters('strokeWeight', arguments); 66138 this._renderer.strokeWeight(w); 66139 return this; 66140 }; 66141 var _default = _main.default; 66142 exports.default = _default; 66143 }, 66144 { 66145 '../constants': 278, 66146 '../main': 290, 66147 'core-js/modules/es.array.iterator': 176, 66148 'core-js/modules/es.object.get-own-property-descriptor': 191, 66149 'core-js/modules/es.object.to-string': 195, 66150 'core-js/modules/es.string.iterator': 204, 66151 'core-js/modules/es.symbol': 214, 66152 'core-js/modules/es.symbol.description': 212, 66153 'core-js/modules/es.symbol.iterator': 213, 66154 'core-js/modules/es.weak-map': 246, 66155 'core-js/modules/web.dom-collections.iterator': 248 66156 } 66157 ], 66158 299: [ 66159 function (_dereq_, module, exports) { 66160 'use strict'; 66161 Object.defineProperty(exports, '__esModule', { 66162 value: true 66163 }); 66164 exports.default = void 0; 66165 var _main = _interopRequireDefault(_dereq_('../main')); 66166 _dereq_('../friendly_errors/fes_core'); 66167 _dereq_('../friendly_errors/file_errors'); 66168 _dereq_('../friendly_errors/validate_params'); 66169 function _interopRequireDefault(obj) { 66170 return obj && obj.__esModule ? obj : { 66171 default: 66172 obj 66173 }; 66174 } /** 66175 * @module Shape 66176 * @submodule Curves 66177 * @for p5 66178 * @requires core 66179 */ 66180 /** 66181 * Draws a cubic Bezier curve on the screen. These curves are defined by a 66182 * series of anchor and control points. The first two parameters specify 66183 * the first anchor point and the last two parameters specify the other 66184 * anchor point, which become the first and last points on the curve. The 66185 * middle parameters specify the two control points which define the shape 66186 * of the curve. Approximately speaking, control points "pull" the curve 66187 * towards them. 66188 * 66189 * Bezier curves were developed by French automotive engineer Pierre Bezier, 66190 * and are commonly used in computer graphics to define gently sloping curves. 66191 * See also <a href="#/p5/curve">curve()</a>. 66192 * 66193 * @method bezier 66194 * @param {Number} x1 x-coordinate for the first anchor point 66195 * @param {Number} y1 y-coordinate for the first anchor point 66196 * @param {Number} x2 x-coordinate for the first control point 66197 * @param {Number} y2 y-coordinate for the first control point 66198 * @param {Number} x3 x-coordinate for the second control point 66199 * @param {Number} y3 y-coordinate for the second control point 66200 * @param {Number} x4 x-coordinate for the second anchor point 66201 * @param {Number} y4 y-coordinate for the second anchor point 66202 * @chainable 66203 * @example 66204 * <div> 66205 * <code> 66206 * noFill(); 66207 * stroke(255, 102, 0); 66208 * line(85, 20, 10, 10); 66209 * line(90, 90, 15, 80); 66210 * stroke(0, 0, 0); 66211 * bezier(85, 20, 10, 10, 90, 90, 15, 80); 66212 * </code> 66213 * </div> 66214 * 66215 * <div> 66216 * <code> 66217 * background(0, 0, 0); 66218 * noFill(); 66219 * stroke(255); 66220 * bezier(250, 250, 0, 100, 100, 0, 100, 0, 0, 0, 100, 0); 66221 * </code> 66222 * </div> 66223 * 66224 * @alt 66225 * stretched black s-shape in center with orange lines extending from end points. 66226 * a white colored curve on black background from the upper-right corner to the lower right corner. 66227 */ 66228 /** 66229 * @method bezier 66230 * @param {Number} x1 66231 * @param {Number} y1 66232 * @param {Number} z1 z-coordinate for the first anchor point 66233 * @param {Number} x2 66234 * @param {Number} y2 66235 * @param {Number} z2 z-coordinate for the first control point 66236 * @param {Number} x3 66237 * @param {Number} y3 66238 * @param {Number} z3 z-coordinate for the second control point 66239 * @param {Number} x4 66240 * @param {Number} y4 66241 * @param {Number} z4 z-coordinate for the second anchor point 66242 * @chainable 66243 */ 66244 66245 _main.default.prototype.bezier = function () { 66246 var _this$_renderer; 66247 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 66248 args[_key] = arguments[_key]; 66249 } 66250 _main.default._validateParameters('bezier', args); // if the current stroke and fill settings wouldn't result in something 66251 // visible, exit immediately 66252 if (!this._renderer._doStroke && !this._renderer._doFill) { 66253 return this; 66254 }(_this$_renderer = this._renderer).bezier.apply(_this$_renderer, args); 66255 return this; 66256 }; 66257 /** 66258 * Sets the resolution at which Bezier's curve is displayed. The default value is 20. 66259 *
66260 * Note, This function is only useful when using the WEBGL renderer 66261 * as the default canvas renderer does not use this information. 66262 * 66263 * @method bezierDetail 66264 * @param {Number} detail resolution of the curves 66265 * @chainable 66266 * @example 66267 * <div modernizr='webgl'> 66268 * <code> 66269 * function setup() { 66270 * createCanvas(100, 100, WEBGL); 66271 * noFill(); 66272 * bezierDetail(5); 66273 * } 66274 * 66275 * function draw() { 66276 * background(200); 66277 * bezier( 66278 * -40, -40, 0, 66279 * 90, -40, 0, 66280 * -90, 40, 0, 66281 * 40, 40, 0 66282 * ); 66283 * } 66284 * </code> 66285 * </div> 66286 * 66287 * @alt 66288 * stretched black s-shape with a low level of bezier detail 66289 */ 66290 _main.default.prototype.bezierDetail = function (d) { 66291 _main.default._validateParameters('bezierDetail', arguments); 66292 this._bezierDetail = d; 66293 return this; 66294 }; 66295 /** 66296 * Given the x or y co-ordinate values of control and anchor points of a bezier 66297 * curve, it evaluates the x or y coordinate of the bezier at position t. The 66298 * parameters a and d are the x or y coordinates of first and last points on the 66299 * curve while b and c are of the control points.The final parameter t is the 66300 * position of the resultant point which is given between 0 and 1. 66301 * This can be done once with the x coordinates and a second time 66302 * with the y coordinates to get the location of a bezier curve at t. 66303 * 66304 * @method bezierPoint 66305 * @param {Number} a coordinate of first point on the curve 66306 * @param {Number} b coordinate of first control point 66307 * @param {Number} c coordinate of second control point 66308 * @param {Number} d coordinate of second point on the curve 66309 * @param {Number} t value between 0 and 1 66310 * @return {Number} the value of the Bezier at position t 66311 * @example 66312 * <div> 66313 * <code> 66314 * noFill(); 66315 * let x1 = 85, 66316 x2 = 10, 66317 x3 = 90, 66318 x4 = 15; 66319 * let y1 = 20, 66320 y2 = 10, 66321 y3 = 90, 66322 y4 = 80; 66323 * bezier(x1, y1, x2, y2, x3, y3, x4, y4); 66324 * fill(255); 66325 * let steps = 10; 66326 * for (let i = 0; i <= steps; i++) { 66327 * let t = i / steps; 66328 * let x = bezierPoint(x1, x2, x3, x4, t); 66329 * let y = bezierPoint(y1, y2, y3, y4, t); 66330 * circle(x, y, 5); 66331 * } 66332 * </code> 66333 * </div> 66334 * 66335 * @alt 66336 * 10 points plotted on a given bezier at equal distances. 66337 */ 66338 _main.default.prototype.bezierPoint = function (a, b, c, d, t) { 66339 _main.default._validateParameters('bezierPoint', arguments); 66340 var adjustedT = 1 - t; 66341 return Math.pow(adjustedT, 3) * a + 3 * Math.pow(adjustedT, 2) * t * b + 3 * adjustedT * Math.pow(t, 2) * c + Math.pow(t, 3) * d; 66342 }; 66343 /** 66344 * Evaluates the tangent to the Bezier at position t for points a, b, c, d. 66345 * The parameters a and d are the first and last points 66346 * on the curve, and b and c are the control points. 66347 * The final parameter t varies between 0 and 1. 66348 * 66349 * @method bezierTangent 66350 * @param {Number} a coordinate of first point on the curve 66351 * @param {Number} b coordinate of first control point 66352 * @param {Number} c coordinate of second control point 66353 * @param {Number} d coordinate of second point on the curve 66354 * @param {Number} t value between 0 and 1 66355 * @return {Number} the tangent at position t 66356 * @example 66357 * <div> 66358 * <code> 66359 * noFill(); 66360 * bezier(85, 20, 10, 10, 90, 90, 15, 80); 66361 * let steps = 6; 66362 * fill(255); 66363 * for (let i = 0; i <= steps; i++) { 66364 * let t = i / steps; 66365 * // Get the location of the point 66366 * let x = bezierPoint(85, 10, 90, 15, t); 66367 * let y = bezierPoint(20, 10, 90, 80, t); 66368 * // Get the tangent points 66369 * let tx = bezierTangent(85, 10, 90, 15, t); 66370 * let ty = bezierTangent(20, 10, 90, 80, t); 66371 * // Calculate an angle from the tangent points 66372 * let a = atan2(ty, tx); 66373 * a += PI; 66374 * stroke(255, 102, 0); 66375 * line(x, y, cos(a) * 30 + x, sin(a) * 30 + y); 66376 * // The following line of code makes a line 66377 * // inverse of the above line 66378 * //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y); 66379 * stroke(0); 66380 * ellipse(x, y, 5, 5); 66381 * } 66382 * </code> 66383 * </div> 66384 * 66385 * <div> 66386 * <code> 66387 * noFill(); 66388 * bezier(85, 20, 10, 10, 90, 90, 15, 80); 66389 * stroke(255, 102, 0); 66390 * let steps = 16; 66391 * for (let i = 0; i <= steps; i++) { 66392 * let t = i / steps; 66393 * let x = bezierPoint(85, 10, 90, 15, t); 66394 * let y = bezierPoint(20, 10, 90, 80, t); 66395 * let tx = bezierTangent(85, 10, 90, 15, t); 66396 * let ty = bezierTangent(20, 10, 90, 80, t); 66397 * let a = atan2(ty, tx); 66398 * a -= HALF_PI; 66399 * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y); 66400 * } 66401 * </code> 66402 * </div> 66403 * 66404 * @alt 66405 * s-shaped line with 6 short orange lines showing the tangents at those points. 66406 * s-shaped line with 6 short orange lines showing lines coming out the underside of the bezier. 66407 */ 66408 _main.default.prototype.bezierTangent = function (a, b, c, d, t) { 66409 _main.default._validateParameters('bezierTangent', arguments); 66410 var adjustedT = 1 - t; 66411 return 3 * d * Math.pow(t, 2) - 3 * c * Math.pow(t, 2) + 6 * c * adjustedT * t - 6 * b * adjustedT * t + 3 * b * Math.pow(adjustedT, 2) - 3 * a * Math.pow(adjustedT, 2); 66412 }; 66413 /** 66414 * Draws a curved line on the screen between two points, given as the 66415 * middle four parameters. The first two parameters are a control point, as 66416 * if the curve came from this point even though it's not drawn. The last 66417 * two parameters similarly describe the other control point. <br /><br /> 66418 * Longer curves can be created by putting a series of <a href="#/p5/curve">curve()</a> functions
66419 * together or using <a href="#/p5/curveVertex">curveVertex()</a>. An additional function called 66420 * <a href="#/p5/curveTightness">curveTightness()</a> provides control for the visual quality of the curve. 66421 * The <a href="#/p5/curve">curve()</a> function is an implementation of Catmull-Rom splines. 66422 * 66423 * @method curve 66424 * @param {Number} x1 x-coordinate for the beginning control point 66425 * @param {Number} y1 y-coordinate for the beginning control point 66426 * @param {Number} x2 x-coordinate for the first point 66427 * @param {Number} y2 y-coordinate for the first point 66428 * @param {Number} x3 x-coordinate for the second point 66429 * @param {Number} y3 y-coordinate for the second point 66430 * @param {Number} x4 x-coordinate for the ending control point 66431 * @param {Number} y4 y-coordinate for the ending control point 66432 * @chainable 66433 * @example 66434 * <div> 66435 * <code> 66436 * noFill(); 66437 * stroke(255, 102, 0); 66438 * curve(5, 26, 5, 26, 73, 24, 73, 61); 66439 * stroke(0); 66440 * curve(5, 26, 73, 24, 73, 61, 15, 65); 66441 * stroke(255, 102, 0); 66442 * curve(73, 24, 73, 61, 15, 65, 15, 65); 66443 * </code> 66444 * </div> 66445 * 66446 * <div> 66447 * <code> 66448 * // Define the curve points as JavaScript objects 66449 * let p1 = { x: 5, y: 26 }; 66450 * let p2 = { x: 73, y: 24 }; 66451 * let p3 = { x: 73, y: 61 }; 66452 * let p4 = { x: 15, y: 65 }; 66453 * noFill(); 66454 * stroke(255, 102, 0); 66455 * curve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); 66456 * stroke(0); 66457 * curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y); 66458 * stroke(255, 102, 0); 66459 * curve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y); 66460 * </code> 66461 * </div> 66462 * 66463 * <div> 66464 * <code> 66465 * noFill(); 66466 * stroke(255, 102, 0); 66467 * curve(5, 26, 0, 5, 26, 0, 73, 24, 0, 73, 61, 0); 66468 * stroke(0); 66469 * curve(5, 26, 0, 73, 24, 0, 73, 61, 0, 15, 65, 0); 66470 * stroke(255, 102, 0); 66471 * curve(73, 24, 0, 73, 61, 0, 15, 65, 0, 15, 65, 0); 66472 * </code> 66473 * </div> 66474 * 66475 * @alt 66476 * horseshoe shape with orange ends facing left and black curved center. 66477 * horseshoe shape with orange ends facing left and black curved center. 66478 * curving black and orange lines. 66479 */ 66480 /** 66481 * @method curve 66482 * @param {Number} x1 66483 * @param {Number} y1 66484 * @param {Number} z1 z-coordinate for the beginning control point 66485 * @param {Number} x2 66486 * @param {Number} y2 66487 * @param {Number} z2 z-coordinate for the first point 66488 * @param {Number} x3 66489 * @param {Number} y3 66490 * @param {Number} z3 z-coordinate for the second point 66491 * @param {Number} x4 66492 * @param {Number} y4 66493 * @param {Number} z4 z-coordinate for the ending control point 66494 * @chainable 66495 */ 66496 _main.default.prototype.curve = function () { 66497 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 66498 args[_key2] = arguments[_key2]; 66499 } 66500 _main.default._validateParameters('curve', args); 66501 if (this._renderer._doStroke) { 66502 var _this$_renderer2; 66503 (_this$_renderer2 = this._renderer).curve.apply(_this$_renderer2, args); 66504 } 66505 return this; 66506 }; 66507 /** 66508 * Sets the resolution at which curves display. The default value is 20 while 66509 * the minimum value is 3. 66510 * 66511 * This function is only useful when using the WEBGL renderer 66512 * as the default canvas renderer does not use this 66513 * information. 66514 * 66515 * @method curveDetail 66516 * @param {Number} resolution resolution of the curves 66517 * @chainable 66518 * @example 66519 * <div modernizr='webgl'> 66520 * <code> 66521 * function setup() { 66522 * createCanvas(100, 100, WEBGL); 66523 * 66524 * curveDetail(5); 66525 * } 66526 * function draw() { 66527 * background(200); 66528 * 66529 * curve(250, 600, 0, -30, 40, 0, 30, 30, 0, -250, 600, 0); 66530 * } 66531 * </code> 66532 * </div> 66533 * 66534 * @alt 66535 * white arch shape with a low level of curve detail. 66536 */ 66537 _main.default.prototype.curveDetail = function (d) { 66538 _main.default._validateParameters('curveDetail', arguments); 66539 if (d < 3) { 66540 this._curveDetail = 3; 66541 } else { 66542 this._curveDetail = d; 66543 } 66544 return this; 66545 }; 66546 /** 66547 * Modifies the quality of forms created with <a href="#/p5/curve">curve()</a> 66548 * and <a href="#/p5/curveVertex">curveVertex()</a>.The parameter tightness 66549 * determines how the curve fits to the vertex points. The value 0.0 is the 66550 * default value for tightness (this value defines the curves to be Catmull-Rom 66551 * splines) and the value 1.0 connects all the points with straight lines. 66552 * Values within the range -5.0 and 5.0 will deform the curves but will leave 66553 * them recognizable and as values increase in magnitude, they will continue to deform. 66554 * 66555 * @method curveTightness 66556 * @param {Number} amount amount of deformation from the original vertices 66557 * @chainable 66558 * @example 66559 * <div> 66560 * <code> 66561 * // Move the mouse left and right to see the curve change 66562 * function setup() { 66563 * createCanvas(100, 100); 66564 * noFill(); 66565 * } 66566 * 66567 * function draw() { 66568 * background(204); 66569 * let t = map(mouseX, 0, width, -5, 5); 66570 * curveTightness(t); 66571 * beginShape(); 66572 * curveVertex(10, 26); 66573 * curveVertex(10, 26); 66574 * curveVertex(83, 24); 66575 * curveVertex(83, 61); 66576 * curveVertex(25, 65); 66577 * curveVertex(25, 65); 66578 * endShape(); 66579 * } 66580 * </code> 66581 * </div> 66582 * 66583 * @alt 66584 * Line shaped like right-facing arrow,points move with mouse-x and warp shape. 66585 */ 66586 _main.default.prototype.curveTightness = function (t) { 66587 _main.default._validateParameters('curveTightness', arguments); 66588 this._renderer._curveTightness = t; 66589 return this; 66590 }; 66591 /** 66592 * Evaluates the curve at position t for points a, b, c, d. 66593 * The parameter t varies between 0 and 1, a and d are control points 66594 * of the curve, and b and c are the start and end points of the curve. 66595 * This can be done once with the x coordinates and a second time 66596 * with the y coordinates to get the location of a curve at t. 66597 * 66598 * @method curvePoint 66599 * @param {Number} a coordinate of first control point of the curve 66600 * @param {Number} b coordinate of first point 66601 * @param {Number} c coordinate of second point 66602 * @param {Number} d coordinate of second control point 66603 * @param {Number} t value between 0 and 1 66604 * @return {Number} <a href="#/p5/curve">Curve</a> value at position t 66605 * @example 66606 * <div> 66607 * <code> 66608 * noFill(); 66609 * curve(5, 26, 5, 26, 73, 24, 73, 61); 66610 * curve(5, 26, 73, 24, 73, 61, 15, 65); 66611 * fill(255); 66612 * ellipseMode(CENTER); 66613 * let steps = 6; 66614 * for (let i = 0; i <= steps; i++) { 66615 * let t = i / steps; 66616 * let x = curvePoint(5, 5, 73, 73, t); 66617 * let y = curvePoint(26, 26, 24, 61, t); 66618 * ellipse(x, y, 5, 5); 66619 * x = curvePoint(5, 73, 73, 15, t); 66620 * y = curvePoint(26, 24, 61, 65, t); 66621 * ellipse(x, y, 5, 5); 66622 * } 66623 * </code> 66624 * </div> 66625 * 66626 *line hooking down to right-bottom with 13 5Ã5 white ellipse points 66627 */ 66628 _main.default.prototype.curvePoint = function (a, b, c, d, t) { 66629 _main.default._validateParameters('curvePoint', arguments); 66630 var s = this._renderer._curveTightness, 66631 t3 = t * t * t, 66632 t2 = t * t, 66633 f1 = (s - 1) / 2 * t3 + (1 - s) * t2 + (s - 1) / 2 * t, 66634 f2 = (s + 3) / 2 * t3 + ( - 5 - s) / 2 * t2 + 1, 66635 f3 = ( - 3 - s) / 2 * t3 + (s + 2) * t2 + (1 - s) / 2 * t, 66636 f4 = (1 - s) / 2 * t3 + (s - 1) / 2 * t2; 66637 return a * f1 + b * f2 + c * f3 + d * f4; 66638 }; 66639 /** 66640 * Evaluates the tangent to the curve at position t for points a, b, c, d. 66641 * The parameter t varies between 0 and 1, a and d are points on the curve, 66642 * and b and c are the control points. 66643 * 66644 * @method curveTangent 66645 * @param {Number} a coordinate of first control point 66646 * @param {Number} b coordinate of first point on the curve 66647 * @param {Number} c coordinate of second point on the curve 66648 * @param {Number} d coordinate of second conrol point 66649 * @param {Number} t value between 0 and 1 66650 * @return {Number} the tangent at position t 66651 * @example 66652 * <div> 66653 * <code> 66654 * noFill(); 66655 * curve(5, 26, 73, 24, 73, 61, 15, 65); 66656 * let steps = 6; 66657 * for (let i = 0; i <= steps; i++) { 66658 * let t = i / steps; 66659 * let x = curvePoint(5, 73, 73, 15, t); 66660 * let y = curvePoint(26, 24, 61, 65, t); 66661 * //ellipse(x, y, 5, 5); 66662 * let tx = curveTangent(5, 73, 73, 15, t); 66663 * let ty = curveTangent(26, 24, 61, 65, t); 66664 * let a = atan2(ty, tx); 66665 * a -= PI / 2.0; 66666 * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y); 66667 * } 66668 * </code> 66669 * </div> 66670 * 66671 * @alt 66672 * right curving line mid-right of canvas with 7 short lines radiating from it. 66673 */ 66674 _main.default.prototype.curveTangent = function (a, b, c, d, t) { 66675 _main.default._validateParameters('curveTangent', arguments); 66676 var s = this._renderer._curveTightness, 66677 tt3 = t * t * 3, 66678 t2 = t * 2, 66679 f1 = (s - 1) / 2 * tt3 + (1 - s) * t2 + (s - 1) / 2, 66680 f2 = (s + 3) / 2 * tt3 + ( - 5 - s) / 2 * t2, 66681 f3 = ( - 3 - s) / 2 * tt3 + (s + 2) * t2 + (1 - s) / 2, 66682 f4 = (1 - s) / 2 * tt3 + (s - 1) / 2 * t2; 66683 return a * f1 + b * f2 + c * f3 + d * f4; 66684 }; 66685 var _default = _main.default; 66686 exports.default = _default; 66687 }, 66688 { 66689 '../friendly_errors/fes_core': 281, 66690 '../friendly_errors/file_errors': 282, 66691 '../friendly_errors/validate_params': 285, 66692 '../main': 290 66693 } 66694 ], 66695 300: [
66696 function (_dereq_, module, exports) { 66697 'use strict'; 66698 _dereq_('core-js/modules/es.symbol'); 66699 _dereq_('core-js/modules/es.symbol.description'); 66700 _dereq_('core-js/modules/es.symbol.iterator'); 66701 _dereq_('core-js/modules/es.array.iterator'); 66702 _dereq_('core-js/modules/es.array.slice'); 66703 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 66704 _dereq_('core-js/modules/es.object.to-string'); 66705 _dereq_('core-js/modules/es.string.iterator'); 66706 _dereq_('core-js/modules/es.weak-map'); 66707 _dereq_('core-js/modules/web.dom-collections.iterator'); 66708 function _typeof2(obj) { 66709 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 66710 _typeof2 = function _typeof2(obj) { 66711 return typeof obj; 66712 }; 66713 } else { 66714 _typeof2 = function _typeof2(obj) { 66715 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 66716 }; 66717 } 66718 return _typeof2(obj); 66719 } 66720 function _typeof(obj) { 66721 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 66722 _typeof = function _typeof(obj) { 66723 return _typeof2(obj); 66724 }; 66725 } else { 66726 _typeof = function _typeof(obj) { 66727 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 66728 }; 66729 } 66730 return _typeof(obj); 66731 } 66732 _dereq_('core-js/modules/es.array.slice'); 66733 Object.defineProperty(exports, '__esModule', { 66734 value: true 66735 }); 66736 exports.default = void 0; 66737 var _main = _interopRequireDefault(_dereq_('../main')); 66738 var constants = _interopRequireWildcard(_dereq_('../constants')); 66739 function _getRequireWildcardCache() { 66740 if (typeof WeakMap !== 'function') return null; 66741 var cache = new WeakMap(); 66742 _getRequireWildcardCache = function _getRequireWildcardCache() { 66743 return cache; 66744 }; 66745 return cache; 66746 } 66747 function _interopRequireWildcard(obj) { 66748 if (obj && obj.__esModule) { 66749 return obj; 66750 } 66751 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 66752 return { 66753 default: 66754 obj 66755 }; 66756 } 66757 var cache = _getRequireWildcardCache(); 66758 if (cache && cache.has(obj)) { 66759 return cache.get(obj); 66760 } 66761 var newObj = { 66762 }; 66763 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 66764 for (var key in obj) { 66765 if (Object.prototype.hasOwnProperty.call(obj, key)) { 66766 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 66767 if (desc && (desc.get || desc.set)) { 66768 Object.defineProperty(newObj, key, desc); 66769 } else { 66770 newObj[key] = obj[key]; 66771 } 66772 } 66773 } 66774 newObj.default = obj; 66775 if (cache) { 66776 cache.set(obj, newObj); 66777 } 66778 return newObj; 66779 } 66780 function _interopRequireDefault(obj) { 66781 return obj && obj.__esModule ? obj : { 66782 default: 66783 obj 66784 }; 66785 } /** 66786 * @module Shape 66787 * @submodule Vertex 66788 * @for p5 66789 * @requires core 66790 * @requires constants 66791 */ 66792 66793 var shapeKind = null; 66794 var vertices = [ 66795 ]; 66796 var contourVertices = [ 66797 ]; 66798 var isBezier = false;
66799 var isCurve = false; 66800 var isQuadratic = false; 66801 var isContour = false; 66802 var isFirstContour = true; 66803 /** 66804 * Use the <a href="#/p5/beginContour">beginContour()</a> and 66805 * <a href="#/p5/endContour">endContour()</a> functions to create negative shapes 66806 * within shapes such as the center of the letter 'O'. <a href="#/p5/beginContour">beginContour()</a> 66807 * begins recording vertices for the shape and <a href="#/p5/endContour">endContour()</a> stops recording. 66808 * The vertices that define a negative shape must "wind" in the opposite direction 66809 * from the exterior shape. First draw vertices for the exterior clockwise order, then for internal shapes, draw vertices 66810 * shape in counter-clockwise. 66811 * 66812 * These functions can only be used within a <a href="#/p5/beginShape">beginShape()</a>/<a href="#/p5/endShape">endShape()</a> pair and 66813 * transformations such as <a href="#/p5/translate">translate()</a>, <a href="#/p5/rotate">rotate()</a>, and <a href="#/p5/scale">scale()</a> do not work 66814 * within a <a href="#/p5/beginContour">beginContour()</a>/<a href="#/p5/endContour">endContour()</a> pair. It is also not possible to use 66815 * other shapes, such as <a href="#/p5/ellipse">ellipse()</a> or <a href="#/p5/rect">rect()</a> within. 66816 * 66817 * @method beginContour 66818 * @chainable 66819 * @example 66820 * <div> 66821 * <code> 66822 * translate(50, 50); 66823 * stroke(255, 0, 0); 66824 * beginShape(); 66825 * // Exterior part of shape, clockwise winding 66826 * vertex(-40, -40); 66827 * vertex(40, -40); 66828 * vertex(40, 40); 66829 * vertex(-40, 40); 66830 * // Interior part of shape, counter-clockwise winding 66831 * beginContour(); 66832 * vertex(-20, -20); 66833 * vertex(-20, 20); 66834 * vertex(20, 20); 66835 * vertex(20, -20); 66836 * endContour(); 66837 * endShape(CLOSE); 66838 * </code> 66839 * </div> 66840 * 66841 * @alt 66842 * white rect and smaller grey rect with red outlines in center of canvas. 66843 */ 66844 _main.default.prototype.beginContour = function () { 66845 contourVertices = [ 66846 ]; 66847 isContour = true; 66848 return this; 66849 }; 66850 /** 66851 * Using the <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a> functions allow creating more 66852 * complex forms. <a href="#/p5/beginShape">beginShape()</a> begins recording vertices for a shape and 66853 * <a href="#/p5/endShape">endShape()</a> stops recording. The value of the kind parameter tells it which 66854 * types of shapes to create from the provided vertices. With no mode 66855 * specified, the shape can be any irregular polygon. 66856 * 66857 * The parameters available for <a href="#/p5/beginShape">beginShape()</a> are: 66858 * 66859 * POINTS 66860 * Draw a series of points 66861 * 66862 * LINES 66863 * Draw a series of unconnected line segments (individual lines) 66864 * 66865 * TRIANGLES 66866 * Draw a series of separate triangles 66867 * 66868 * TRIANGLE_FAN 66869 * Draw a series of connected triangles sharing the first vertex in a fan-like fashion 66870 * 66871 * TRIANGLE_STRIP 66872 * Draw a series of connected triangles in strip fashion 66873 * 66874 * QUADS 66875 * Draw a series of separate quads 66876 * 66877 * QUAD_STRIP 66878 * Draw quad strip using adjacent edges to form the next quad 66879 * 66880 * TESS (WEBGL only) 66881 * Handle irregular polygon for filling curve by explicit tessellation 66882 * 66883 * After calling the <a href="#/p5/beginShape">beginShape()</a> function, a series of <a href="#/p5/vertex">vertex()</a> commands must follow. To stop 66884 * drawing the shape, call <a href="#/p5/endShape">endShape()</a>. Each shape will be outlined with the 66885 * current stroke color and filled with the fill color. 66886 * 66887 * Transformations such as <a href="#/p5/translate">translate()</a>, <a href="#/p5/rotate">rotate()</a>, and <a href="#/p5/scale">scale()</a> do not work 66888 * within <a href="#/p5/beginShape">beginShape()</a>. It is also not possible to use other shapes, such as 66889 * <a href="#/p5/ellipse">ellipse()</a> or <a href="#/p5/rect">rect()</a> within <a href="#/p5/beginShape">beginShape()</a>. 66890 * 66891 * @method beginShape 66892 * @param {Constant} [kind] either POINTS, LINES, TRIANGLES, TRIANGLE_FAN 66893 * TRIANGLE_STRIP, QUADS, QUAD_STRIP or TESS 66894 * @chainable 66895 * @example 66896 * <div> 66897 * <code> 66898 * beginShape(); 66899 * vertex(30, 20); 66900 * vertex(85, 20);
66901 * vertex(85, 75); 66902 * vertex(30, 75); 66903 * endShape(CLOSE); 66904 * </code> 66905 * </div> 66906 * 66907 * <div> 66908 * <code> 66909 * beginShape(POINTS); 66910 * vertex(30, 20); 66911 * vertex(85, 20); 66912 * vertex(85, 75); 66913 * vertex(30, 75); 66914 * endShape(); 66915 * </code> 66916 * </div> 66917 * 66918 * <div> 66919 * <code> 66920 * beginShape(LINES); 66921 * vertex(30, 20); 66922 * vertex(85, 20); 66923 * vertex(85, 75); 66924 * vertex(30, 75); 66925 * endShape(); 66926 * </code> 66927 * </div> 66928 * 66929 * <div> 66930 * <code> 66931 * noFill(); 66932 * beginShape(); 66933 * vertex(30, 20); 66934 * vertex(85, 20); 66935 * vertex(85, 75); 66936 * vertex(30, 75); 66937 * endShape(); 66938 * </code> 66939 * </div> 66940 * 66941 * <div> 66942 * <code> 66943 * noFill(); 66944 * beginShape(); 66945 * vertex(30, 20); 66946 * vertex(85, 20); 66947 * vertex(85, 75); 66948 * vertex(30, 75); 66949 * endShape(CLOSE); 66950 * </code> 66951 * </div> 66952 * 66953 * <div> 66954 * <code> 66955 * beginShape(TRIANGLES); 66956 * vertex(30, 75); 66957 * vertex(40, 20); 66958 * vertex(50, 75); 66959 * vertex(60, 20); 66960 * vertex(70, 75); 66961 * vertex(80, 20); 66962 * endShape(); 66963 * </code> 66964 * </div> 66965 * 66966 * <div> 66967 * <code> 66968 * beginShape(TRIANGLE_STRIP); 66969 * vertex(30, 75); 66970 * vertex(40, 20); 66971 * vertex(50, 75); 66972 * vertex(60, 20); 66973 * vertex(70, 75); 66974 * vertex(80, 20); 66975 * vertex(90, 75); 66976 * endShape(); 66977 * </code> 66978 * </div> 66979 * 66980 * <div> 66981 * <code> 66982 * beginShape(TRIANGLE_FAN); 66983 * vertex(57.5, 50); 66984 * vertex(57.5, 15); 66985 * vertex(92, 50); 66986 * vertex(57.5, 85); 66987 * vertex(22, 50); 66988 * vertex(57.5, 15); 66989 * endShape(); 66990 * </code> 66991 * </div> 66992 * 66993 * <div> 66994 * <code> 66995 * beginShape(QUADS); 66996 * vertex(30, 20); 66997 * vertex(30, 75); 66998 * vertex(50, 75); 66999 * vertex(50, 20); 67000 * vertex(65, 20); 67001 * vertex(65, 75); 67002 * vertex(85, 75); 67003 * vertex(85, 20); 67004 * endShape(); 67005 * </code> 67006 * </div> 67007 * 67008 * <div> 67009 * <code> 67010 * beginShape(QUAD_STRIP); 67011 * vertex(30, 20); 67012 * vertex(30, 75); 67013 * vertex(50, 20); 67014 * vertex(50, 75); 67015 * vertex(65, 20); 67016 * vertex(65, 75); 67017 * vertex(85, 20); 67018 * vertex(85, 75); 67019 * endShape(); 67020 * </code> 67021 * </div> 67022 * 67023 * <div> 67024 * <code> 67025 * beginShape(TESS); 67026 * vertex(20, 20); 67027 * vertex(80, 20); 67028 * vertex(80, 40); 67029 * vertex(40, 40); 67030 * vertex(40, 60); 67031 * vertex(80, 60); 67032 * vertex(80, 80); 67033 * vertex(20, 80); 67034 * endShape(CLOSE); 67035 * </code> 67036 * </div> 67037 * 67038 * @alt 67039 * white square-shape with black outline in middle-right of canvas. 67040 * 4 black points in a square shape in middle-right of canvas. 67041 * 2 horizontal black lines. In the top-right and bottom-right of canvas. 67042 * 3 line shape with horizontal on top, vertical in middle and horizontal bottom. 67043 * square line shape in middle-right of canvas. 67044 * 2 white triangle shapes mid-right canvas. left one pointing up and right down. 67045 * 5 horizontal interlocking and alternating white triangles in mid-right canvas. 67046 * 4 interlocking white triangles in 45 degree rotated square-shape. 67047 * 2 white rectangle shapes in mid-right canvas. Both 20Ã55. 67048 * 3 side-by-side white rectangles center rect is smaller in mid-right canvas. 67049 * Thick white l-shape with black outline mid-top-left of canvas. 67050 */ 67051 _main.default.prototype.beginShape = function (kind) { 67052 _main.default._validateParameters('beginShape', arguments); 67053 if (this._renderer.isP3D) { 67054 var _this$_renderer; 67055 (_this$_renderer = this._renderer).beginShape.apply(_this$_renderer, arguments); 67056 } else { 67057 if (kind === constants.POINTS || kind === constants.LINES || kind === constants.TRIANGLES || kind === constants.TRIANGLE_FAN || kind === constants.TRIANGLE_STRIP || kind === constants.QUADS || kind === constants.QUAD_STRIP) { 67058 shapeKind = kind; 67059 } else { 67060 shapeKind = null; 67061 } 67062 vertices = [ 67063 ]; 67064 contourVertices = [ 67065 ]; 67066 } 67067 return this; 67068 }; 67069 /** 67070 * Specifies vertex coordinates for Bezier curves. Each call to 67071 * bezierVertex() defines the position of two control points and 67072 * one anchor point of a Bezier curve, adding a new segment to a 67073 * line or shape. For WebGL mode bezierVertex() can be used in 2D 67074 * as well as 3D mode. 2D mode expects 6 parameters, while 3D mode 67075 * expects 9 parameters (including z coordinates). 67076 * 67077 * The first time bezierVertex() is used within a <a href="#/p5/beginShape">beginShape()</a> 67078 * call, it must be prefaced with a call to <a href="#/p5/vertex">vertex()</a> to set the first anchor 67079 * point. This function must be used between <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a> 67080 * and only when there is no MODE or POINTS parameter specified to 67081 * <a href="#/p5/beginShape">beginShape()</a>. 67082 * 67083 * @method bezierVertex 67084 * @param {Number} x2 x-coordinate for the first control point 67085 * @param {Number} y2 y-coordinate for the first control point 67086 * @param {Number} x3 x-coordinate for the second control point 67087 * @param {Number} y3 y-coordinate for the second control point 67088 * @param {Number}
67088 x4 x-coordinate for the anchor point 67089 * @param {Number} y4 y-coordinate for the anchor point 67090 * @chainable 67091 * 67092 * @example 67093 * <div> 67094 * <code> 67095 * noFill(); 67096 * beginShape(); 67097 * vertex(30, 20); 67098 * bezierVertex(80, 0, 80, 75, 30, 75); 67099 * endShape(); 67100 * </code> 67101 * </div> 67102 * 67103 * <div> 67104 * <code> 67105 * beginShape(); 67106 * vertex(30, 20); 67107 * bezierVertex(80, 0, 80, 75, 30, 75); 67108 * bezierVertex(50, 80, 60, 25, 30, 20); 67109 * endShape(); 67110 * </code> 67111 * </div> 67112 * 67113 * <div> 67114 * <code> 67115 * function setup() { 67116 * createCanvas(100, 100, WEBGL); 67117 * setAttributes('antialias', true); 67118 * } 67119 * function draw() { 67120 * orbitControl(); 67121 * background(50); 67122 * strokeWeight(4); 67123 * stroke(255); 67124 * point(-25, 30); 67125 * point(25, 30); 67126 * point(25, -30); 67127 * point(-25, -30); 67128 * 67129 * strokeWeight(1); 67130 * noFill(); 67131 * 67132 * beginShape(); 67133 * vertex(-25, 30); 67134 * bezierVertex(25, 30, 25, -30, -25, -30); 67135 * endShape(); 67136 * 67137 * beginShape(); 67138 * vertex(-25, 30, 20); 67139 * bezierVertex(25, 30, 20, 25, -30, 20, -25, -30, 20); 67140 * endShape(); 67141 * } 67142 * </code> 67143 * </div> 67144 * 67145 * @alt 67146 * crescent-shaped line in middle of canvas. Points facing left. 67147 * white crescent shape in middle of canvas. Points facing left. 67148 * crescent shape in middle of canvas with another crescent shape on positive z-axis. 67149 */ 67150 /** 67151 * @method bezierVertex 67152 * @param {Number} x2 67153 * @param {Number} y2 67154 * @param {Number} z2 z-coordinate for the first control point (for WebGL mode) 67155 * @param {Number} x3 67156 * @param {Number} y3 67157 * @param {Number} z3 z-coordinate for the second control point (for WebGL mode) 67158 * @param {Number} x4 67159 * @param {Number} y4 67160 * @param {Number} z4 z-coordinate for the anchor point (for WebGL mode) 67161 * @chainable 67162 */ 67163 _main.default.prototype.bezierVertex = function () { 67164 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 67165 args[_key] = arguments[_key]; 67166 } 67167 _main.default._validateParameters('bezierVertex', args); 67168 if (this._renderer.isP3D) { 67169 var _this$_renderer2; 67170 (_this$_renderer2 = this._renderer).bezierVertex.apply(_this$_renderer2, args); 67171 } else { 67172 if (vertices.length === 0) { 67173 _main.default._friendlyError('vertex() must be used once before calling bezierVertex()', 'bezierVertex'); 67174 } else { 67175 isBezier = true; 67176 var vert = [ 67177 ]; 67178 for (var i = 0; i < args.length; i++) { 67179 vert[i] = args[i]; 67180 } 67181 vert.isVert = false; 67182 if (isContour) { 67183 contourVertices.push(vert); 67184 } else { 67185 vertices.push(vert); 67186 } 67187 } 67188 } 67189 return this; 67190 }; 67191 /** 67192 * Specifies vertex coordinates for curves. This function may only 67193 * be used between <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a> and only when there 67194 * is no MODE parameter specified to <a href="#/p5/beginShape">beginShape()</a>. 67195 * For WebGL mode curveVertex() can be used in 2D as well as 3D mode. 67196 * 2D mode expects 2 parameters, while 3D mode expects 3 parameters. 67197 * 67198 * The first and last points in a series of curveVertex() lines will be used to 67199 * guide the beginning and end of the curve. A minimum of four 67200 * points is required to draw a tiny curve between the second and 67201 * third points. Adding a fifth point with curveVertex() will draw 67202 * the curve between the second, third, and fourth points. The 67203 * curveVertex() function is an implementation of Catmull-Rom 67204 * splines. 67205 * 67206 * @method curveVertex 67207 * @param {Number} x x-coordinate of the vertex 67208 * @param {Number} y y-coordinate of the vertex 67209 * @chainable 67210 * @example 67211 * <div> 67212 * <code> 67213 * strokeWeight(5); 67214 * point(84, 91); 67215 * point(68, 19); 67216 * point(21, 17); 67217 * point(32, 91); 67218 * strokeWeight(1); 67219 * 67220 * noFill(); 67221 * beginShape(); 67222 * curveVertex(84, 91); 67223 * curveVertex(84, 91); 67224 * curveVertex(68, 19); 67225 * curveVertex(21, 17); 67226 * curveVertex(32, 91); 67227 * curveVertex(32, 91); 67228 * endShape(); 67229 * </code> 67230 * </div> 67231 * 67232 * @alt 67233 * Upside-down u-shape line, mid canvas. left point extends beyond canvas view. 67234 */ 67235 /** 67236 * @method curveVertex 67237 * @param {Number} x 67238 * @param {Number} y 67239 * @param {Number} [z] z-coordinate of the vertex (for WebGL mode) 67240 * @chainable 67241 * @example 67242 * <div> 67243 * <code> 67244 * function setup() { 67245 * createCanvas(100, 100, WEBGL); 67246 * setAttributes('antialias', true); 67247 * } 67248 * function draw() { 67249 * orbitControl(); 67250 * background(50); 67251 * strokeWeight(4);
67252 * stroke(255); 67253 * 67254 * point(-25, 25); 67255 * point(-25, 25); 67256 * point(-25, -25); 67257 * point(25, -25); 67258 * point(25, 25); 67259 * point(25, 25); 67260 * 67261 * strokeWeight(1); 67262 * noFill(); 67263 * 67264 * beginShape(); 67265 * curveVertex(-25, 25); 67266 * curveVertex(-25, 25); 67267 * curveVertex(-25, -25); 67268 * curveVertex(25, -25); 67269 * curveVertex(25, 25); 67270 * curveVertex(25, 25); 67271 * endShape(); 67272 * 67273 * beginShape(); 67274 * curveVertex(-25, 25, 20); 67275 * curveVertex(-25, 25, 20); 67276 * curveVertex(-25, -25, 20); 67277 * curveVertex(25, -25, 20); 67278 * curveVertex(25, 25, 20); 67279 * curveVertex(25, 25, 20); 67280 * endShape(); 67281 * } 67282 * </code> 67283 * </div> 67284 * 67285 * @alt 67286 * Upside-down u-shape line, mid canvas with the same shape in positive z-axis. 67287 */ 67288 _main.default.prototype.curveVertex = function () { 67289 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 67290 args[_key2] = arguments[_key2]; 67291 } 67292 _main.default._validateParameters('curveVertex', args); 67293 if (this._renderer.isP3D) { 67294 var _this$_renderer3; 67295 (_this$_renderer3 = this._renderer).curveVertex.apply(_this$_renderer3, args); 67296 } else { 67297 isCurve = true; 67298 this.vertex(args[0], args[1]); 67299 } 67300 return this; 67301 }; 67302 /** 67303 * Use the <a href="#/p5/beginContour">beginContour()</a> and <a href="#/p5/endContour">endContour()</a> functions to create negative 67304 * shapes within shapes such as the center of the letter 'O'. <a href="#/p5/beginContour">beginContour()</a> 67305 * begins recording vertices for the shape and <a href="#/p5/endContour">endContour()</a> stops recording. 67306 * The vertices that define a negative shape must "wind" in the opposite 67307 * direction from the exterior shape. First draw vertices for the exterior 67308 * clockwise order, then for internal shapes, draw vertices 67309 * shape in counter-clockwise. 67310 * 67311 * These functions can only be used within a <a href="#/p5/beginShape">beginShape()</a>/<a href="#/p5/endShape">endShape()</a> pair and 67312 * transformations such as <a href="#/p5/translate">translate()</a>, <a href="#/p5/rotate">rotate()</a>, and <a href="#/p5/scale">scale()</a> do not work 67313 * within a <a href="#/p5/beginContour">beginContour()</a>/<a href="#/p5/endContour">endContour()</a> pair. It is also not possible to use 67314 * other shapes, such as <a href="#/p5/ellipse">ellipse()</a> or <a href="#/p5/rect">rect()</a> within. 67315 * 67316 * @method endContour 67317 * @chainable 67318 * @example 67319 * <div> 67320 * <code> 67321 * translate(50, 50); 67322 * stroke(255, 0, 0); 67323 * beginShape(); 67324 * // Exterior part of shape, clockwise winding 67325 * vertex(-40, -40); 67326 * vertex(40, -40); 67327 * vertex(40, 40); 67328 * vertex(-40, 40); 67329 * // Interior part of shape, counter-clockwise winding 67330 * beginContour(); 67331 * vertex(-20, -20); 67332 * vertex(-20, 20); 67333 * vertex(20, 20); 67334 * vertex(20, -20); 67335 * endContour(); 67336 * endShape(CLOSE); 67337 * </code> 67338 * </div> 67339 * 67340 * @alt 67341 * white rect and smaller grey rect with red outlines in center of canvas. 67342 */ 67343 _main.default.prototype.endContour = function () { 67344 var vert = contourVertices[0].slice(); // copy all data 67345 vert.isVert = contourVertices[0].isVert; 67346 vert.moveTo = false; 67347 contourVertices.push(vert); // prevent stray lines with multiple contours 67348 if (isFirstContour) { 67349 vertices.push(vertices[0]); 67350 isFirstContour = false; 67351 } 67352 for (var i = 0; i < contourVertices.length; i++) { 67353 vertices.push(contourVertices[i]); 67354 } 67355 return this; 67356 }; 67357 /** 67358 * The <a href="#/p5/endShape">endShape()</a> function is the companion to <a href="#/p5/beginShape">beginShape()</a> and may only be 67359 * called after <a href="#/p5/beginShape">beginShape()</a>. When <a href="#/p5/endshape">endShape()</a> is called, all of the image 67360 * data defined since the previous call to <a href="#/p5/beginShape">beginShape()</a> is written into the image 67361 * buffer. The constant CLOSE as the value for the `mode` parameter to close 67362 * the shape (to connect the beginning and the end). 67363 * 67364 * @method endShape 67365 * @param {Constant} [mode] use CLOSE to close the shape 67366 * @chainable 67367 * @example 67368 * <div> 67369 * <code> 67370 * noFill(); 67371 * 67372 * beginShape(); 67373 * vertex(20, 20); 67374 * vertex(45, 20); 67375 * vertex(45, 80); 67376 * endShape(CLOSE); 67377 * 67378 * beginShape(); 67379 * vertex(50, 20); 67380 * vertex(75, 20); 67381 * vertex(75, 80); 67382 * endShape(); 67383 * </code> 67384 * </div> 67385 * 67386 * @alt 67387 * Triangle line shape with smallest interior angle on bottom and upside-
67387down L. 67388 */ 67389 _main.default.prototype.endShape = function (mode) { 67390 _main.default._validateParameters('endShape', arguments); 67391 if (this._renderer.isP3D) { 67392 this._renderer.endShape(mode, isCurve, isBezier, isQuadratic, isContour, shapeKind); 67393 } else { 67394 if (vertices.length === 0) { 67395 return this; 67396 } 67397 if (!this._renderer._doStroke && !this._renderer._doFill) { 67398 return this; 67399 } 67400 var closeShape = mode === constants.CLOSE; // if the shape is closed, the first element is also the last element 67401 if (closeShape && !isContour) { 67402 vertices.push(vertices[0]); 67403 } 67404 this._renderer.endShape(mode, vertices, isCurve, isBezier, isQuadratic, isContour, shapeKind); // Reset some settings 67405 isCurve = false; 67406 isBezier = false; 67407 isQuadratic = false; 67408 isContour = false; 67409 isFirstContour = true; // If the shape is closed, the first element was added as last element. 67410 // We must remove it again to prevent the list of vertices from growing 67411 // over successive calls to endShape(CLOSE) 67412 if (closeShape) { 67413 vertices.pop(); 67414 } 67415 } 67416 return this; 67417 }; 67418 /** 67419 * Specifies vertex coordinates for quadratic Bezier curves. Each call to 67420 * quadraticVertex() defines the position of one control points and one 67421 * anchor point of a Bezier curve, adding a new segment to a line or shape. 67422 * The first time quadraticVertex() is used within a <a href="#/p5/beginShape">beginShape()</a> call, it 67423 * must be prefaced with a call to <a href="#/p5/vertex">vertex()</a> to set the first anchor point. 67424 * For WebGL mode quadraticVertex() can be used in 2D as well as 3D mode. 67425 * 2D mode expects 4 parameters, while 3D mode expects 6 parameters 67426 * (including z coordinates). 67427 * 67428 * This function must be used between <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a> 67429 * and only when there is no MODE or POINTS parameter specified to 67430 * <a href="#/p5/beginShape">beginShape()</a>. 67431 * 67432 * @method quadraticVertex 67433 * @param {Number} cx x-coordinate for the control point 67434 * @param {Number} cy y-coordinate for the control point 67435 * @param {Number} x3 x-coordinate for the anchor point 67436 * @param {Number} y3 y-coordinate for the anchor point 67437 * @chainable 67438 * 67439 * @example 67440 * <div> 67441 * <code> 67442 * strokeWeight(5); 67443 * point(20, 20); 67444 * point(80, 20); 67445 * point(50, 50); 67446 * 67447 * noFill(); 67448 * strokeWeight(1); 67449 * beginShape(); 67450 * vertex(20, 20); 67451 * quadraticVertex(80, 20, 50, 50); 67452 * endShape(); 67453 * </code> 67454 * </div> 67455 * 67456 * <div> 67457 * <code> 67458 * strokeWeight(5); 67459 * point(20, 20); 67460 * point(80, 20); 67461 * point(50, 50); 67462 * 67463 * point(20, 80); 67464 * point(80, 80); 67465 * point(80, 60); 67466 * 67467 * noFill(); 67468 * strokeWeight(1); 67469 * beginShape(); 67470 * vertex(20, 20); 67471 * quadraticVertex(80, 20, 50, 50); 67472 * quadraticVertex(20, 80, 80, 80); 67473 * vertex(80, 60); 67474 * endShape(); 67475 * </code> 67476 * </div> 67477 * 67478 * @alt 67479 * arched-shaped black line with 4 pixel thick stroke weight. 67480 * backwards s-shaped black line with 4 pixel thick stroke weight. 67481 */ 67482 /** 67483 * @method quadraticVertex 67484 * @param {Number} cx 67485 * @param {Number} cy 67486 * @param {Number} cz z-coordinate for the control point (for WebGL mode) 67487 * @param {Number} x3 67488 * @param {Number} y3 67489 * @param {Number} z3 z-coordinate for the anchor point (for WebGL mode) 67490 * @chainable 67491 * 67492 * @example 67493 * <div> 67494 * <code> 67495 * function setup() { 67496 * createCanvas(100, 100, WEBGL); 67497 * setAttributes('antialias', true); 67498 * } 67499 * function draw() { 67500 * orbitControl(); 67501 * background(50); 67502 * strokeWeight(4); 67503 * stroke(255); 67504 * 67505 * point(-35, -35); 67506 * point(35, -35); 67507 * point(0, 0); 67508 * point(-35, 35); 67509 * point(35, 35); 67510 * point(35, 10); 67511 * 67512 * strokeWeight(1); 67513 * noFill(); 67514 * 67515 * beginShape(); 67516 * vertex(-35, -35); 67517 * quadraticVertex(35, -35, 0, 0); 67518 * quadraticVertex(-35, 35, 35, 35); 67519 * vertex(35, 10); 67520 * endShape(); 67521 * 67522 * beginShape(); 67523 * vertex(-35, -35, 20); 67524 * quadraticVertex(35, -35, 20, 0, 0, 20); 67525 * quadraticVertex(-35, 35, 20, 35, 35, 20); 67526 * vertex(35, 10, 20); 67527 * endShape(); 67528 * } 67529 * </code> 67530 * </div> 67531 * 67532 * @alt 67533 * backwards s-shaped black line with the same s-shaped line in positive z-axis. 67534 */ 67535 _main.default.prototype.quadraticVertex = function () { 67536 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 67537 args[_key3] = arguments[_key3]; 67538 } 67539 _main.default._validateParameters('quadraticVertex', args
67539); 67540 if (this._renderer.isP3D) { 67541 var _this$_renderer4; 67542 (_this$_renderer4 = this._renderer).quadraticVertex.apply(_this$_renderer4, args); 67543 } else { 67544 //if we're drawing a contour, put the points into an 67545 // array for inside drawing 67546 if (this._contourInited) { 67547 var pt = { 67548 }; 67549 pt.x = args[0]; 67550 pt.y = args[1]; 67551 pt.x3 = args[2]; 67552 pt.y3 = args[3]; 67553 pt.type = constants.QUADRATIC; 67554 this._contourVertices.push(pt); 67555 return this; 67556 } 67557 if (vertices.length > 0) { 67558 isQuadratic = true; 67559 var vert = [ 67560 ]; 67561 for (var i = 0; i < args.length; i++) { 67562 vert[i] = args[i]; 67563 } 67564 vert.isVert = false; 67565 if (isContour) { 67566 contourVertices.push(vert); 67567 } else { 67568 vertices.push(vert); 67569 } 67570 } else { 67571 _main.default._friendlyError('vertex() must be used once before calling quadraticVertex()', 'quadraticVertex'); 67572 } 67573 } 67574 return this; 67575 }; 67576 /** 67577 * All shapes are constructed by connecting a series of vertices. <a href="#/p5/vertex">vertex()</a> 67578 * is used to specify the vertex coordinates for points, lines, triangles, 67579 * quads, and polygons. It is used exclusively within the <a href="#/p5/beginShape">beginShape()</a> and 67580 * <a href="#/p5/endShape">endShape()</a> functions. 67581 * 67582 * @method vertex 67583 * @param {Number} x x-coordinate of the vertex 67584 * @param {Number} y y-coordinate of the vertex 67585 * @chainable 67586 * @example 67587 * <div> 67588 * <code> 67589 * strokeWeight(3); 67590 * beginShape(POINTS); 67591 * vertex(30, 20); 67592 * vertex(85, 20); 67593 * vertex(85, 75); 67594 * vertex(30, 75); 67595 * endShape(); 67596 * </code> 67597 * </div> 67598 * 67599 * <div> 67600 * <code> 67601 * createCanvas(100, 100, WEBGL); 67602 * background(240, 240, 240); 67603 * fill(237, 34, 93); 67604 * noStroke(); 67605 * beginShape(); 67606 * vertex(0, 35); 67607 * vertex(35, 0); 67608 * vertex(0, -35); 67609 * vertex(-35, 0); 67610 * endShape(); 67611 * </code> 67612 * </div> 67613 * 67614 * <div> 67615 * <code> 67616 * createCanvas(100, 100, WEBGL); 67617 * background(240, 240, 240); 67618 * fill(237, 34, 93); 67619 * noStroke(); 67620 * beginShape(); 67621 * vertex(-10, 10); 67622 * vertex(0, 35); 67623 * vertex(10, 10); 67624 * vertex(35, 0); 67625 * vertex(10, -8); 67626 * vertex(0, -35); 67627 * vertex(-10, -8); 67628 * vertex(-35, 0); 67629 * endShape(); 67630 * </code> 67631 * </div> 67632 * 67633 * <div> 67634 * <code> 67635 * strokeWeight(3); 67636 * stroke(237, 34, 93); 67637 * beginShape(LINES); 67638 * vertex(10, 35); 67639 * vertex(90, 35); 67640 * vertex(10, 65); 67641 * vertex(90, 65); 67642 * vertex(35, 10); 67643 * vertex(35, 90); 67644 * vertex(65, 10); 67645 * vertex(65, 90); 67646 * endShape(); 67647 * </code> 67648 * </div> 67649 * 67650 * <div> 67651 * <code> 67652 * // Click to change the number of sides. 67653 * // In WebGL mode, custom shapes will only 67654 * // display hollow fill sections when 67655 * // all calls to vertex() use the same z-value. 67656 * 67657 * let sides = 3; 67658 * let angle, px, py; 67659 * 67660 * function setup() { 67661 * createCanvas(100, 100, WEBGL); 67662 * setAttributes('antialias', true); 67663 * fill(237, 34, 93); 67664 * strokeWeight(3); 67665 * } 67666 * 67667 * function draw() { 67668 * background(200); 67669 * rotateX(frameCount * 0.01); 67670 * rotateZ(frameCount * 0.01); 67671 * ngon(sides, 0, 0, 80); 67672 * } 67673 * 67674 * function mouseClicked() { 67675 * if (sides > 6) { 67676 * sides = 3; 67677 * } else { 67678 * sides++; 67679 * } 67680 * } 67681 * 67682 * function ngon(n, x, y, d) { 67683 * beginShape(TESS); 67684 * for (let i = 0; i < n + 1; i++) { 67685 * angle = TWO_PI / n * i; 67686 * px = x + sin(angle) * d / 2; 67687 * py = y - cos(angle) * d / 2; 67688 * vertex(px, py, 0); 67689 * } 67690 * for (let i = 0; i < n + 1; i++) { 67691 * angle = TWO_PI / n * i; 67692 * px = x + sin(angle) * d / 4; 67693 * py = y - cos(angle) * d / 4; 67694 * vertex(px, py, 0); 67695 * } 67696 * endShape(); 67697 * } 67698 * </code> 67699 * </div> 67700 * @alt 67701 * 4 black points in a square shape in middle-right of canvas. 67702 * 4 points making a diamond shape. 67703 * 8 points making a star. 67704 * 8 points making 4 lines. 67705 * A rotating 3D shape with a hollow section in the middle. 67706 */ 67707 /** 67708 * @method vertex 67709 * @param {Number} x 67710 * @param {Number} y 67711 * @param {Number} [z] z-coordinate of the vertex. 67712 * Defaults to 0 if not specified. 67713 * @chainable 67714 */ 67715 /** 67716 * @method vertex 67717 * @param {Number} x 67718 * @param {Number} y 67719 * @param {Number} [z] 67720 * @param {Number} [u] the vertex's texture u-coordinate 67721 * @param {Number} [v] the vertex's texture v-coordinate 67722 * @chainable 67723 */ 67724 _main.default.prototype.vertex = function (x, y, moveTo, u, v) { 67725 if (this._renderer.isP3D) { 67726 var _this$_renderer5; 67727 (_this$_renderer5 = this._renderer).vertex.apply(_this$_renderer5, arguments); 67728 } else { 67729 var vert = [ 67730 ]; 67731 vert.isVert = true; 67732 vert[0] = x; 67733 vert[1] = y; 67734 vert[2] = 0; 67735 vert[3] = 0; 67736 vert[4] = 0; 67737 vert[5] = this._renderer._getFill(); 67738 vert[6] = this._renderer._getStroke(); 67739 if (moveTo) { 67740 vert.moveTo = moveTo; 67741 } 67742 if (isContour) { 67743 if (contourVertices.length === 0) { 67744 vert.moveTo = true; 67745 } 67746 contourVertices.push(vert); 67747 } else { 67748 vertices.push(vert); 67749 } 67750 } 67751 return this; 67752 }; 67753 /** 67754 * Sets the 3d vertex normal to use for subsequent vertices drawn with 67755 * <a href="#/p5/vertex">vertex()</a>. A normal is a vector that is generally 67756 * nearly perpendicular to a shape's surface which controls how much light will 67757 * be reflected from that part of the surface. 67758 * 67759 * @method normal 67760 * @param {Vector} vector A p5.Vector representing the vertex normal. 67761 * @chainable 67762 * @example 67763 * <div> 67764 * <code> 67765 * function setup() { 67766 * createCanvas(100, 100, WEBGL); 67767 * noStroke(); 67768 * } 67769 * 67770 * function draw() { 67771 * background(255); 67772 * rotateY(frameCount / 100); 67773 * normalMaterial(); 67774 * beginShape(TRIANGLE_STRIP); 67775 * normal(-0.4, 0.4, 0.8); 67776 * vertex(-30, 30, 0); 67777 * 67778 * normal(0, 0, 1); 67779 * vertex(-30, -30, 30); 67780 * vertex(30, 30, 30); 67781 * 67782 * normal(0.4, -0.4, 0.8); 67783 * vertex(30, -30, 0); 67784 * endShape(); 67785 * } 67786 * </code> 67787 * </div> 67788 */ 67789 /** 67790 * @method normal 67791 * @param {Number} x The x component of the vertex normal. 67792 * @param {Number} y The y component of the vertex normal. 67793 * @param {Number} z The z component of the vertex normal. 67794 * @chainable 67795 */ 67796 _main.default.prototype.normal = function (x, y, z) { 67797 var _this$_renderer6; 67798 this._assert3d('normal'); 67799 _main.default._validateParameters('normal', arguments); 67800 (_this$_renderer6 = this._renderer).normal.apply(_this$_renderer6, arguments); 67801 return this; 67802 }; 67803 var _default = _main.default; 67804 exports.default = _default; 67805 }, 67806 { 67807 '../constants': 278, 67808 '../main': 290, 67809 'core-js/modules/es.array.iterator': 176, 67810 'core-js/modules/es.array.slice': 180, 67811 'core-js/modules/es.object.get-own-property-descriptor': 191, 67812 'core-js/modules/es.object.to-string': 195, 67813 'core-js/modules/es.string.iterator': 204, 67814 'core-js/modules/es.symbol': 214, 67815 'core-js/modules/es.symbol.description': 212, 67816 'core-js/modules/es.symbol.iterator': 213, 67817 'core-js/modules/es.weak-map': 246, 67818 'core-js/modules/web.dom-collections.iterator': 248 67819 } 67820 ], 67821 301: [
67822 function (_dereq_, module, exports) { 67823 'use strict'; 67824 _dereq_('core-js/modules/es.symbol'); 67825 _dereq_('core-js/modules/es.symbol.description'); 67826 _dereq_('core-js/modules/es.symbol.iterator'); 67827 _dereq_('core-js/modules/es.array.filter'); 67828 _dereq_('core-js/modules/es.array.iterator'); 67829 _dereq_('core-js/modules/es.array.slice'); 67830 _dereq_('core-js/modules/es.object.assign'); 67831 _dereq_('core-js/modules/es.object.keys'); 67832 _dereq_('core-js/modules/es.object.to-string'); 67833 _dereq_('core-js/modules/es.string.iterator'); 67834 _dereq_('core-js/modules/es.typed-array.uint8-clamped-array'); 67835 _dereq_('core-js/modules/es.typed-array.copy-within'); 67836 _dereq_('core-js/modules/es.typed-array.every'); 67837 _dereq_('core-js/modules/es.typed-array.fill'); 67838 _dereq_('core-js/modules/es.typed-array.filter'); 67839 _dereq_('core-js/modules/es.typed-array.find'); 67840 _dereq_('core-js/modules/es.typed-array.find-index'); 67841 _dereq_('core-js/modules/es.typed-array.for-each'); 67842 _dereq_('core-js/modules/es.typed-array.includes'); 67843 _dereq_('core-js/modules/es.typed-array.index-of'); 67844 _dereq_('core-js/modules/es.typed-array.iterator'); 67845 _dereq_('core-js/modules/es.typed-array.join'); 67846 _dereq_('core-js/modules/es.typed-array.last-index-of'); 67847 _dereq_('core-js/modules/es.typed-array.map'); 67848 _dereq_('core-js/modules/es.typed-array.reduce'); 67849 _dereq_('core-js/modules/es.typed-array.reduce-right'); 67850 _dereq_('core-js/modules/es.typed-array.reverse'); 67851 _dereq_('core-js/modules/es.typed-array.set'); 67852 _dereq_('core-js/modules/es.typed-array.slice'); 67853 _dereq_('core-js/modules/es.typed-array.some'); 67854 _dereq_('core-js/modules/es.typed-array.sort'); 67855 _dereq_('core-js/modules/es.typed-array.subarray'); 67856 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 67857 _dereq_('core-js/modules/es.typed-array.to-string'); 67858 _dereq_('core-js/modules/web.dom-collections.iterator'); 67859 function _typeof2(obj) { 67860 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 67861 _typeof2 = function _typeof2(obj) { 67862 return typeof obj; 67863 }; 67864 } else { 67865 _typeof2 = function _typeof2(obj) { 67866 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 67867 }; 67868 } 67869 return _typeof2(obj); 67870 } 67871 _dereq_('core-js/modules/es.symbol'); 67872 _dereq_('core-js/modules/es.symbol.description'); 67873 _dereq_('core-js/modules/es.symbol.iterator'); 67874 _dereq_('core-js/modules/es.array.filter'); 67875 _dereq_('core-js/modules/es.array.iterator'); 67876 _dereq_('core-js/modules/es.array.slice'); 67877 _dereq_('core-js/modules/es.object.assign'); 67878 _dereq_('core-js/modules/es.object.keys'); 67879 _dereq_('core-js/modules/es.object.to-string'); 67880 _dereq_('core-js/modules/es.string.iterator'); 67881 _dereq_('core-js/modules/es.typed-array.uint8-clamped-array'); 67882 _dereq_('core-js/modules/es.typed-array.copy-within'); 67883 _dereq_('core-js/modules/es.typed-array.every'); 67884 _dereq_('core-js/modules/es.typed-array.fill'); 67885 _dereq_('core-js/modules/es.typed-array.filter'); 67886 _dereq_('core-js/modules/es.typed-array.find'); 67887 _dereq_('core-js/modules/es.typed-array.find-index'); 67888 _dereq_('core-js/modules/es.typed-array.for-each'); 67889 _dereq_('core-js/modules/es.typed-array.includes'); 67890 _dereq_('core-js/modules/es.typed-array.index-of'); 67891 _dereq_('core-js/modules/es.typed-array.iterator'); 67892 _dereq_('core-js/modules/es.typed-array.join'); 67893 _dereq_('core-js/modules/es.typed-array.last-index-of'); 67894 _dereq_('core-js/modules/es.typed-array.map'); 67895 _dereq_('core-js/modules/es.typed-array.reduce'); 67896 _dereq_('core-js/modules/es.typed-array.reduce-right'); 67897 _dereq_('core-js/modules/es.typed-array.reverse'); 67898 _dereq_('core-js/modules/es.typed-array.set'); 67899 _dereq_('core-js/modules/es.typed-array.slice'); 67900 _dereq_('core-js/modules/es.typed-array.some'); 67901 _dereq_('core-js/modules/es.typed-array.sort'); 67902 _dereq_('core-js/modules/es.typed-array.subarray'); 67903 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 67904 _dereq_('core-js/modules/es.typed-array.to-string'); 67905 _dereq_('core-js/modules/web.dom-collections.iterator'); 67906 function _typeof(obj) { 67907 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 67908 _typeof = function _typeof(obj) { 67909 return _typeof2(obj); 67910 }; 67911 } else { 67912 _typeof = function _typeof(obj) { 67913 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
67913ypeof2(obj); 67914 }; 67915 } 67916 return _typeof(obj); 67917 } // requestAnim shim layer by Paul Irish 67918 // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ 67919 // http://my.opera.com/emoller/blog/2011/12/20/ 67920 // requestanimationframe-for-smart-er-animating 67921 // requestAnimationFrame polyfill by Erik Möller 67922 // fixes from Paul Irish and Tino Zijdel 67923 67924 window.requestAnimationFrame = function () { 67925 return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) { 67926 // should '60' here be framerate? 67927 window.setTimeout(callback, 1000 / 60); 67928 }; 67929 }(); 67930 /** 67931 * shim for Uint8ClampedArray.slice 67932 * (allows arrayCopy to work with pixels[]) 67933 * with thanks to http://halfpapstudios.com/blog/tag/html5-canvas/ 67934 * Enumerable set to false to protect for...in from 67935 * Uint8ClampedArray.prototype pollution. 67936 */ 67937 (function () { 67938 if (typeof Uint8ClampedArray !== 'undefined' && !Uint8ClampedArray.prototype.slice) { 67939 Object.defineProperty(Uint8ClampedArray.prototype, 'slice', { 67940 value: Array.prototype.slice, 67941 writable: true, 67942 configurable: true, 67943 enumerable: false 67944 }); 67945 } 67946 }) (); 67947 /** 67948 * this is implementation of Object.assign() which is unavailable in 67949 * IE11 and (non-Chrome) Android browsers. 67950 * The assign() method is used to copy the values of all enumerable 67951 * own properties from one or more source objects to a target object. 67952 * It will return the target object. 67953 * Modified from https://github.com/ljharb/object.assign 67954 */ 67955 (function () { 67956 if (!Object.assign) { 67957 var keys = Object.keys; 67958 var defineProperty = Object.defineProperty; 67959 var canBeObject = function canBeObject(obj) { 67960 return typeof obj !== 'undefined' && obj !== null; 67961 }; 67962 var hasSymbols = typeof Symbol === 'function' && _typeof(Symbol()) === 'symbol'; 67963 var propIsEnumerable = Object.prototype.propertyIsEnumerable; 67964 var isEnumerableOn = function isEnumerableOn(obj) { 67965 return function isEnumerable(prop) { 67966 return propIsEnumerable.call(obj, prop); 67967 }; 67968 }; // per ES6 spec, this function has to have a length of 2 67969 var assignShim = function assign(target, source1) { 67970 if (!canBeObject(target)) { 67971 throw new TypeError('target must be an object'); 67972 } 67973 var objTarget = Object(target); 67974 var s, 67975 source, 67976 i, 67977 props; 67978 for (s = 1; s < arguments.length; ++s) { 67979 source = Object(arguments[s]); 67980 props = keys(source); 67981 if (hasSymbols && Object.getOwnPropertySymbols) { 67982 props.push.apply(props, Object.getOwnPropertySymbols(source).filter(isEnumerableOn(source))); 67983 } 67984 for (i = 0; i < props.length; ++i) { 67985 objTarget[props[i]] = source[props[i]]; 67986 } 67987 } 67988 return objTarget; 67989 }; 67990 defineProperty(Object, 'assign', { 67991 value: assignShim, 67992 configurable: true, 67993 enumerable: false, 67994 writable: true 67995 }); 67996 } 67997 }) (); 67998 }, 67999 { 68000 'core-js/modules/es.array.filter': 171, 68001 'core-js/modules/es.array.iterator': 176, 68002 'core-js/modules/es.array.slice': 180, 68003 'core-js/modules/es.object.assign': 190, 68004 'core-js/modules/es.object.keys': 194, 68005 'core-js/modules/es.object.to-string': 195, 68006 'core-js/modules/es.string.iterator': 204, 68007 'core-js/modules/es.symbol': 214, 68008 'core-js/modules/es.symbol.description': 212, 68009 'core-js/modules/es.symbol.iterator': 213, 68010 'core-js/modules/es.typed-array.copy-within': 215, 68011 'core-js/modules/es.typed-array.every': 216, 68012 'core-js/modules/es.typed-array.fill': 217, 68013 'core-js/modules/es.typed-array.filter': 218, 68014 'core-js/modules/es.typed-array.find': 220, 68015 'core-js/modules/es.typed-array.find-index': 219, 68016 'core-js/modules/es.typed-array.for-each': 223, 68017 'core-js/modules/es.typed-array.includes': 224, 68018 'core-js/modules/es.typed-array.index-of': 225, 68019 'core-js/modules/es.typed-array.iterator': 228, 68020 'core-js/modules/es.typed-array.join': 229, 68021 'core-js/modules/es.typed-array.last-index-of': 230, 68022 'core-js/modules/es.typed-array.map': 231, 68023 'core-js/modules/es.typed-array.reduce': 233, 68024 'core-js/modules/es.typed-array.reduce-right': 232, 68025 'core-js/modules/es.typed-array.reverse': 234, 68026 'core-js/modules/es.typed-array.set': 235, 68027 'core-js/modules/es.typed-array.slice': 236, 68028 'core-js/modules/es.typed-array.some': 237, 68029 'core-js/modules/es.typed-array.sort': 238, 68030 'core-js/modules/es.typed-array.subarray': 239, 68031 'core-js/modules/es.typed-array.to-locale-string': 240, 68032 'core-js/modules/es.typed-array.to-string': 241, 68033 'core-js/modules/es.typed-array.uint8-clamped-array': 245, 68034 'core-js/modules/web.dom-collections.iterator': 248 68035 } 68036 ], 68037 302: [
68038 function (_dereq_, module, exports) { 68039 'use strict'; 68040 _dereq_('core-js/modules/es.array.for-each'); 68041 _dereq_('core-js/modules/es.object.assign'); 68042 _dereq_('core-js/modules/web.dom-collections.for-each'); 68043 _dereq_('core-js/modules/es.array.for-each'); 68044 _dereq_('core-js/modules/es.object.assign'); 68045 _dereq_('core-js/modules/web.dom-collections.for-each'); 68046 Object.defineProperty(exports, '__esModule', { 68047 value: true 68048 }); 68049 exports.default = void 0; 68050 var _main = _interopRequireDefault(_dereq_('./main')); 68051 function _interopRequireDefault(obj) { 68052 return obj && obj.__esModule ? obj : { 68053 default: 68054 obj 68055 }; 68056 } /** 68057 * @module Structure 68058 * @submodule Structure 68059 * @for p5 68060 * @requires core 68061 */ 68062 /** 68063 * Stops p5.js from continuously executing the code within <a href="#/p5/draw">draw()</a>. 68064 * If <a href="#/p5/loop">loop()</a> is called, the code in <a href="#/p5/draw">draw()</a> 68065 * begins to run continuously again. If using <a href="#/p5/noLoop">noLoop()</a> 68066 * in <a href="#/p5/setup">setup()</a>, it should be the last line inside the block. 68067 * 68068 * When <a href="#/p5/noLoop">noLoop()</a> is used, it's not possible to manipulate 68069 * or access the screen inside event handling functions such as 68070 * <a href="#/p5/mousePressed">mousePressed()</a> or 68071 * <a href="#/p5/keyPressed">keyPressed()</a>. Instead, use those functions to 68072 * call <a href="#/p5/redraw">redraw()</a> or <a href="#/p5/loop">loop()</a>, 68073 * which will run <a href="#/p5/draw">draw()</a>, which can update the screen 68074 * properly. This means that when <a href="#/p5/noLoop">noLoop()</a> has been 68075 * called, no drawing can happen, and functions like <a href="#/p5/saveFrames">saveFrames()</a> 68076 * or <a href="#/p5/loadPixels">loadPixels()</a> may not be used. 68077 * 68078 * Note that if the sketch is resized, <a href="#/p5/redraw">redraw()</a> will 68079 * be called to update the sketch, even after <a href="#/p5/noLoop">noLoop()</a> 68080 * has been specified. Otherwise, the sketch would enter an odd state until 68081 * <a href="#/p5/loop">loop()</a> was called. 68082 * 68083 * Use <a href="#/p5/isLooping">isLooping()</a> to check the current state of <a href="#/p5/loop">loop()</a>. 68084 * 68085 * @method noLoop 68086 * @example 68087 * <div> 68088 * <code> 68089 * function setup() { 68090 * createCanvas(100, 100); 68091 * background(200); 68092 * noLoop(); 68093 * } 68094 68095 * function draw() { 68096 * line(10, 10, 90, 90); 68097 * } 68098 * </code> 68099 * </div> 68100 * 68101 * <div> 68102 * <code> 68103 * let x = 0; 68104 * function setup() { 68105 * createCanvas(100, 100); 68106 * } 68107 * 68108 * function draw() { 68109 * background(204); 68110 * x = x + 0.1; 68111 * if (x > width) { 68112 * x = 0; 68113 * } 68114 * line(x, 0, x, height); 68115 * } 68116 * 68117 * function mousePressed() { 68118 * noLoop(); 68119 * } 68120 * 68121 * function mouseReleased() { 68122 * loop(); 68123 * } 68124 * </code> 68125 * </div> 68126 * 68127 * @alt 68128 * 113 pixel long line extending from top-left to bottom right of canvas. 68129 * horizontal line moves slowly from left. Loops but stops on mouse press. 68130 */ 68131 68132 _main.default.prototype.noLoop = function () { 68133 this._loop = false; 68134 }; 68135 /** 68136 * By default, p5.js loops through draw() continuously, executing the code within 68137 * it. However, the <a href="#/p5/draw">draw()</a> loop may be stopped by calling 68138 * <a href="#/p5/noLoop">noLoop()</a>. In that case, the <a href="#/p5/draw">draw()</a> 68139 * loop can be resumed with loop(). 68140 * 68141 * Avoid calling loop() from inside setup(). 68142 * 68143 * Use <a href="#/p5/isLooping">isLooping()</a> to check the current state of <a href="#/p5/loop">loop()</a>. 68144 * 68145 * @method loop 68146 * @example 68147 * <div> 68148 * <code> 68149 * let x = 0; 68150 * function setup() { 68151 * createCanvas(100, 100); 68152 * noLoop(); 68153 * } 68154 * 68155 * function draw() { 68156 * background(204); 68157 * x = x + 0.1; 68158 * if (x > width) { 68159 * x = 0; 68160 * } 68161 * line(x, 0, x, height); 68162 * } 68163 * 68164 * function mousePressed() { 68165 * loop(); 68166 * } 68167 * 68168 * function mouseReleased() { 68169 * noLoop(); 68170 * } 68171 * </code> 68172 * </div> 68173 * 68174 * @alt 68175 * horizontal line moves slowly from left. Loops but stops on mouse press. 68176 */ 68177 _main.default.prototype.loop = function () { 68178 if (!this._loop) { 68179 this._loop = true; 68180 if (this._setupDone) { 68181 this._draw(); 68182 } 68183 } 68184 }; 68185 /** 68186 * By default, p5.js loops through <a href="#/p5/draw">draw()</a> continuously, 68187 * executing the code within it. If the sketch is stopped with 68188 * <a href="#/p5/noLoop">noLoop()</a> or resumed with <a href="#/p5/loop">loop()</a>, 68189 * isLooping() returns the current state for use within custom event handlers. 68190 * 68191 * @method isLooping 68192 * @returns {boolean} 68193 * @example 68194 * <div> 68195 * <code> 68196 * let checkbox, button, colBG, colFill; 68197 * 68198 * function setup() { 68199 * createCanvas(100, 100); 68200 * 68201 * button = createButton('Colorize if loop()'); 68202 * button.position(0, 120); 68203 * button.mousePressed(changeBG); 68204 * 68205 * checkbox = createCheckbox('loop()', true); 68206 * checkbox.changed(checkLoop); 68207 * 68208 * colBG = color(0); 68209 * colFill = color(255); 68210 * } 68211 * 68212 * function changeBG() { 68213 * if (isLooping()) { 68214 * colBG = color(random(255), random(255), random(255)); 68215 * colFill = color(random(255), random(255), random(255)); 68216 * } 68217 * } 68218 * 68219 * function checkLoop() { 68220 * if (this.checked()) { 68221 * loop(); 68222 * } else { 68223 * noLoop(); 68224 * } 68225 * } 68226 * 68227 * function draw() { 68228 * background(colBG); 68229 * fill(colFill);
68230 * ellipse(frameCount % width, height / 2, 50); 68231 * } 68232 * </code> 68233 * </div> 68234 * 68235 * @alt 68236 * Ellipse moves slowly from left. Checkbox toggles loop()/noLoop(). 68237 * Button colorizes sketch if isLooping(). 68238 * 68239 */ 68240 _main.default.prototype.isLooping = function () { 68241 return this._loop; 68242 }; 68243 /** 68244 * The <a href="#/p5/push">push()</a> function saves the current drawing style 68245 * settings and transformations, while <a href="#/p5/pop">pop()</a> restores these 68246 * settings. Note that these functions are always used together. They allow you to 68247 * change the style and transformation settings and later return to what you had. 68248 * When a new state is started with <a href="#/p5/push">push()</a>, it builds on 68249 * the current style and transform information. The <a href="#/p5/push">push()</a> 68250 * and <a href="#/p5/pop">pop()</a> functions can be embedded to provide more 68251 * control. (See the second example for a demonstration.) 68252 * 68253 * <a href="#/p5/push">push()</a> stores information related to the current transformation state 68254 * and style settings controlled by the following functions: 68255 * <a href="#/p5/fill">fill()</a>, 68256 * <a href="#/p5/noFill">noFill()</a>, 68257 * <a href="#/p5/noStroke">noStroke()</a>, 68258 * <a href="#/p5/stroke">stroke()</a>, 68259 * <a href="#/p5/tint">tint()</a>, 68260 * <a href="#/p5/noTint">noTint()</a>, 68261 * <a href="#/p5/strokeWeight">
68261strokeWeight()</a>, 68262 * <a href="#/p5/strokeCap">strokeCap()</a>, 68263 * <a href="#/p5/strokeJoin">strokeJoin()</a>, 68264 * <a href="#/p5/imageMode">imageMode()</a>, 68265 * <a href="#/p5/rectMode">rectMode()</a>, 68266 * <a href="#/p5/ellipseMode">ellipseMode()</a>, 68267 * <a href="#/p5/colorMode">colorMode()</a>, 68268 * <a href="#/p5/textAlign">textAlign()</a>, 68269 * <a href="#/p5/textFont">textFont()</a>, 68270 * <a href="#/p5/textSize">textSize()</a>, 68271 * <a href="#/p5/textLeading">textLeading()</a>, 68272 * <a href="#/p5/applyMatrix">applyMatrix()</a>, 68273 * <a href="#/p5/resetMatrix">resetMatrix()</a>, 68274 * <a href="#/p5/rotate">rotate()</a>, 68275 * <a href="#/p5/scale">scale()</a>, 68276 * <a href="#/p5/shearX">shearX()</a>, 68277 * <a href="#/p5/shearY">shearY()</a>, 68278 * <a href="#/p5/translate">translate()</a>, 68279 * <a href="#/p5/noiseSeed">noiseSeed()</a>. 68280 * 68281 * In WEBGL mode additional style settings are stored. These are controlled by the 68282 * following functions: <a href="#/p5/setCamera">setCamera()</a>, 68283 * <a href="#/p5/ambientLight">ambientLight()</a>, 68284 * <a href="#/p5/directionalLight">directionalLight()</a>, 68285 * <a href="#/p5/pointLight">pointLight()</a>, <a href="#/p5/texture">texture()</a>, 68286 * <a href="#/p5/specularMaterial">specularMaterial()</a>, 68287 * <a href="#/p5/shininess">shininess()</a>, 68288 * <a href="#/p5/normalMaterial">normalMaterial()</a> 68289 * and <a href="#/p5/shader">shader()</a>. 68290 * 68291 * @method push 68292 * @example 68293 * <div> 68294 * <code> 68295 * ellipse(0, 50, 33, 33); // Left circle 68296 * 68297 * push(); // Start a new drawing state 68298 * strokeWeight(10); 68299 * fill(204, 153, 0); 68300 * translate(50, 0); 68301 * ellipse(0, 50, 33, 33); // Middle circle 68302 * pop(); // Restore original state 68303 * 68304 * ellipse(100, 50, 33, 33); // Right circle 68305 * </code> 68306 * </div> 68307 * 68308 * <div> 68309 * <code> 68310 * ellipse(0, 50, 33, 33); // Left circle 68311 * 68312 * push(); // Start a new drawing state 68313 * strokeWeight(10); 68314 * fill(204, 153, 0); 68315 * ellipse(33, 50, 33, 33); // Left-middle circle 68316 * 68317 * push(); // Start another new drawing state 68318 * stroke(0, 102, 153); 68319 * ellipse(66, 50, 33, 33); // Right-middle circle 68320 * pop(); // Restore previous state 68321 * 68322 * pop(); // Restore original state 68323 * 68324 * ellipse(100, 50, 33, 33); // Right circle 68325 * </code> 68326 * </div> 68327 * 68328 * @alt 68329 * Gold ellipse + thick black outline @center 2 white ellipses on left and right. 68330 * 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right. 68331 */ 68332 _main.default.prototype.push = function () { 68333 this._styles.push({ 68334 props: { 68335 _colorMode: this._colorMode 68336 }, 68337 renderer: this._renderer.push() 68338 }); 68339 }; 68340 /** 68341 * The <a href="#/p5/push">push()</a> function saves the current drawing style 68342 * settings and transformations, while <a href="#/p5/pop">pop()</a> restores 68343 * these settings. Note that these functions are always used together. They allow 68344 * you to change the style and transformation settings and later return to what 68345 * you had. When a new state is started with <a href="#/p5/push">push()</a>, it 68346 * builds on the current style and transform information. The <a href="#/p5/push">push()</a> 68347 * and <a href="#/p5/pop">pop()</a> functions can be embedded to provide more 68348 * control. (See the second example for a demonstration.) 68349 * 68350 * <a href="#/p5/push">push()</a> stores information related to the current transformation state 68351 * and style settings controlled by the following functions: 68352 * <a href="#/p5/fill">fill()</a>, 68353 * <a href="#/p5/noFill">noFill()</a>, 68354 * <a href="#/p5/noStroke">noStroke()</a>, 68355 * <a href="#/p5/stroke">stroke()</a>, 68356 * <a href="#/p5/tint">tint()</a>, 68357 * <a href="#/p5/noTint">noTint()</a>, 68358 * <a href="#/p5/strokeWeight">
68358strokeWeight()</a>, 68359 * <a href="#/p5/strokeCap">strokeCap()</a>, 68360 * <a href="#/p5/strokeJoin">strokeJoin()</a>, 68361 * <a href="#/p5/imageMode">imageMode()</a>, 68362 * <a href="#/p5/rectMode">rectMode()</a>, 68363 * <a href="#/p5/ellipseMode">ellipseMode()</a>, 68364 * <a href="#/p5/colorMode">colorMode()</a>, 68365 * <a href="#/p5/textAlign">textAlign()</a>, 68366 * <a href="#/p5/textFont">textFont()</a>, 68367 * <a href="#/p5/textSize">textSize()</a>, 68368 * <a href="#/p5/textLeading">textLeading()</a>, 68369 * <a href="#/p5/applyMatrix">applyMatrix()</a>, 68370 * <a href="#/p5/resetMatrix">resetMatrix()</a>, 68371 * <a href="#/p5/rotate">rotate()</a>, 68372 * <a href="#/p5/scale">scale()</a>, 68373 * <a href="#/p5/shearX">shearX()</a>, 68374 * <a href="#/p5/shearY">shearY()</a>, 68375 * <a href="#/p5/translate">translate()</a>, 68376 * <a href="#/p5/noiseSeed">noiseSeed()</a>. 68377 * 68378 * In WEBGL mode additional style settings are stored. These are controlled by 68379 * the following functions: 68380 * <a href="#/p5/setCamera">setCamera()</a>, 68381 * <a href="#/p5/ambientLight">ambientLight()</a>, 68382 * <a href="#/p5/directionalLight">directionalLight()</a>, 68383 * <a href="#/p5/pointLight">pointLight()</a>, 68384 * <a href="#/p5/texture">texture()</a>, 68385 * <a href="#/p5/specularMaterial">specularMaterial()</a>, 68386 * <a href="#/p5/shininess">shininess()</a>, 68387 * <a href="#/p5/normalMaterial">normalMaterial()</a> and 68388 * <a href="#/p5/shader">shader()</a>. 68389 * 68390 * @method pop 68391 * @example 68392 * <div> 68393 * <code> 68394 * ellipse(0, 50, 33, 33); // Left circle 68395 * 68396 * push(); // Start a new drawing state 68397 * translate(50, 0); 68398 * strokeWeight(10); 68399 * fill(204, 153, 0); 68400 * ellipse(0, 50, 33, 33); // Middle circle 68401 * pop(); // Restore original state 68402 * 68403 * ellipse(100, 50, 33, 33); // Right circle 68404 * </code> 68405 * </div> 68406 * 68407 * <div> 68408 * <code> 68409 * ellipse(0, 50, 33, 33); // Left circle 68410 * 68411 * push(); // Start a new drawing state 68412 * strokeWeight(10); 68413 * fill(204, 153, 0); 68414 * ellipse(33, 50, 33, 33); // Left-middle circle 68415 * 68416 * push(); // Start another new drawing state 68417 * stroke(0, 102, 153); 68418 * ellipse(66, 50, 33, 33); // Right-middle circle 68419 * pop(); // Restore previous state 68420 * 68421 * pop(); // Restore original state 68422 * 68423 * ellipse(100, 50, 33, 33); // Right circle 68424 * </code> 68425 * </div> 68426 * 68427 * @alt 68428 * Gold ellipse + thick black outline @center 2 white ellipses on left and right. 68429 * 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right. 68430 */ 68431 _main.default.prototype.pop = function () { 68432 var style = this._styles.pop(); 68433 if (style) { 68434 this._renderer.pop(style.renderer); 68435 Object.assign(this, style.props); 68436 } else { 68437 console.warn('pop() was called without matching push()'); 68438 } 68439 }; 68440 /** 68441 * Executes the code within <a href="#/p5/draw">draw()</a> one time. This 68442 * function allows the program to update the display window only when necessary, 68443 * for example when an event registered by <a href="#/p5/mousePressed">mousePressed()</a> 68444 * or <a href="#/p5/keyPressed">keyPressed()</a> occurs. 68445 * 68446 * In structuring a program, it only makes sense to call <a href="#/p5/redraw">redraw()</a> 68447 * within events such as <a href="#/p5/mousePressed">mousePressed()</a>. This 68448 * is because <a href="#/p5/redraw">redraw()</a> does not run 68449 * <a href="#/p5/draw">draw()</a> immediately (it only sets a flag that indicates 68450 * an update is needed). 68451 * 68452 * The <a href="#/p5/redraw">redraw()</a> function does not work properly when 68453 * called inside <a href="#/p5/draw">draw()</a>.To enable/disable animations, 68454 * use <a href="#/p5/loop">loop()</a> and <a href="#/p5/noLoop">noLoop()</a>. 68455 * 68456 * In addition you can set the number of redraws per method call. Just 68457 * add an integer as single parameter for the number of redraws. 68458 * 68459 * @method redraw 68460 * @param {Integer} [n] Redraw for n-times. The default value is 1. 68461 * @example 68462 * <div><code> 68463 * let x = 0; 68464 * 68465 * function setup() { 68466 * createCanvas(100, 100); 68467 * noLoop(); 68468 * } 68469 * 68470 * function draw() { 68471 * background(204); 68472 * line(x, 0, x, height); 68473 * } 68474 * 68475 * function mousePressed() { 68476 * x += 1; 68477 * redraw(); 68478 * } 68479 * </code> 68480 * </div> 68481 * 68482 * <div class='norender'> 68483 * <code> 68484 * let x = 0; 68485 * 68486 * function setup() { 68487 * createCanvas(100, 100); 68488 * noLoop(); 68489 * } 68490 * 68491 * function draw() { 68492 * background(204); 68493 * x += 1; 68494 * line(x, 0, x, height); 68495 * } 68496 * 68497 * function mousePressed() { 68498 * redraw(5); 68499 * } 68500 * </code> 68501 * </div> 68502 * 68503 * @alt 68504 * black line on far left of canvas 68505 * black line on far left of canvas 68506 */ 68507 _main.default.prototype.redraw = function (n) { 68508 if (this._inUserDraw || !this._setupDone) { 68509 return; 68510 } 68511 var numberOfRedraws = parseInt(n); 68512 if (isNaN(numberOfRedraws) || numberOfRedraws < 1) { 68513 numberOfRedraws = 1; 68514 } 68515 var context = this._isGlobal ? window : this; 68516 if (typeof context.draw === 'function') { 68517 if (typeof context.setup === 'undefined') { 68518 context.scale(context._pixelDensity, context._pixelDensity); 68519 } 68520 var callMethod = function callMethod(f) { 68521 f.call(context); 68522 }; 68523 for (var idxRedraw = 0; idxRedraw < numberOfRedraws; idxRedraw++) { 68524 context.resetMatrix(); 68525 if (this._accessibleOutputs.grid || this._accessibleOutputs.text) { 68526 this._updateAccsOutput(); 68527 } 68528 if (context._renderer.isP3D) { 68529 context._renderer._update(); 68530 } 68531 context._setProperty('frameCount', context.frameCount + 1); 68532 context._registeredMethods.pre.forEach(callMethod); 68533 this._inUserDraw = true; 68534 try { 68535 context.draw(); 68536 } finally { 68537 this._inUserDraw = false;
68538 } 68539 context._registeredMethods.post.forEach(callMethod); 68540 } 68541 } 68542 }; 68543 /** 68544 * The `p5()` constructor enables you to activate "instance mode" instead of normal 68545 * "global mode". This is an advanced topic. A short description and example is 68546 * included below. Please see 68547 * <a target="blank" href="https://www.youtube.com/watch?v=Su792jEauZg&feature=youtu.be"> 68548 * Dan Shiffman's Coding Train video tutorial</a> or this 68549 * <a target="blank" href="https://github.com/processing/p5.js/wiki/p5.js-overview#instantiation--namespace">tutorial page</a> 68550 * for more info. 68551 * 68552 * By default, all p5.js functions are in the global namespace (i.e. bound to the window 68553 * object), meaning you can call them simply `ellipse()`, `fill()`, etc. However, this 68554 * might be inconvenient if you are mixing with other JS libraries (synchronously or 68555 * asynchronously) or writing long programs of your own. p5.js currently supports a 68556 * way around this problem called "instance mode". In instance mode, all p5 functions 68557 * are bound up in a single variable instead of polluting your global namespace. 68558 * 68559 * Optionally, you can specify a default container for the canvas and any other elements 68560 * to append to with a second argument. You can give the ID of an element in your html, 68561 * or an html node itself. 68562 * 68563 * Note that creating instances like this also allows you to have more than one p5 sketch on 68564 * a single web page, as they will each be wrapped up with their own set up variables. Of 68565 * course, you could also use iframes to have multiple sketches in global mode. 68566 * 68567 * @method p5 68568 * @param {Object} sketch a function containing a p5.js sketch 68569 * @param {String|Object} node ID or pointer to HTML DOM node to contain sketch in 68570 * @example 68571 * <div class='norender'><code> 68572 * const s = p => { 68573 * let x = 100; 68574 * let y = 100; 68575 * 68576 * p.setup = function() { 68577 * p.createCanvas(700, 410); 68578 * }; 68579 * 68580 * p.draw = function() { 68581 * p.background(0); 68582 * p.fill(255); 68583 * p.rect(x, y, 50, 50); 68584 * }; 68585 * }; 68586 * 68587 * new p5(s); // invoke p5 68588 * </code></div> 68589 * 68590 * @alt 68591 * white rectangle on black background 68592 */ 68593 var _default = _main.default; 68594 exports.default = _default; 68595 }, 68596 { 68597 './main': 290, 68598 'core-js/modules/es.array.for-each': 172, 68599 'core-js/modules/es.object.assign': 190, 68600 'core-js/modules/web.dom-collections.for-each': 247 68601 } 68602 ], 68603 303: [ 68604 function (_dereq_, module, exports) { 68605 'use strict'; 68606 _dereq_('core-js/modules/es.symbol'); 68607 _dereq_('core-js/modules/es.symbol.description'); 68608 _dereq_('core-js/modules/es.symbol.iterator'); 68609 _dereq_('core-js/modules/es.array.from'); 68610 _dereq_('core-js/modules/es.array.iterator'); 68611 _dereq_('core-js/modules/es.object.get-prototype-of'); 68612 _dereq_('core-js/modules/es.object.to-string'); 68613 _dereq_('core-js/modules/es.regexp.to-string'); 68614 _dereq_('core-js/modules/es.string.iterator'); 68615 _dereq_('core-js/modules/es.typed-array.uint8-array'); 68616 _dereq_('core-js/modules/es.typed-array.copy-within'); 68617 _dereq_('core-js/modules/es.typed-array.every'); 68618 _dereq_('core-js/modules/es.typed-array.fill'); 68619 _dereq_('core-js/modules/es.typed-array.filter'); 68620 _dereq_('core-js/modules/es.typed-array.find'); 68621 _dereq_('core-js/modules/es.typed-array.find-index'); 68622 _dereq_('core-js/modules/es.typed-array.for-each'); 68623 _dereq_('core-js/modules/es.typed-array.includes'); 68624 _dereq_('core-js/modules/es.typed-array.index-of'); 68625 _dereq_('core-js/modules/es.typed-array.iterator'); 68626 _dereq_('core-js/modules/es.typed-array.join'); 68627 _dereq_('core-js/modules/es.typed-array.last-index-of'); 68628 _dereq_('core-js/modules/es.typed-array.map'); 68629 _dereq_('core-js/modules/es.typed-array.reduce'); 68630 _dereq_('core-js/modules/es.typed-array.reduce-right'); 68631 _dereq_('core-js/modules/es.typed-array.reverse'); 68632 _dereq_('core-js/modules/es.typed-array.set'); 68633 _dereq_('core-js/modules/es.typed-array.slice'); 68634 _dereq_('core-js/modules/es.typed-array.some'); 68635 _dereq_('core-js/modules/es.typed-array.sort'); 68636 _dereq_('core-js/modules/es.typed-array.subarray'); 68637 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 68638 _dereq_('core-js/modules/es.typed-array.to-string'); 68639 _dereq_('core-js/modules/web.dom-collections.iterator'); 68640 _dereq_('core-js/modules/es.symbol'); 68641 _dereq_('core-js/modules/es.symbol.description'); 68642 _dereq_('core-js/modules/es.symbol.iterator'); 68643 _dereq_('core-js/modules/es.array.from'); 68644 _dereq_('core-js/modules/es.array.iterator'); 68645 _dereq_('core-js/modules/es.object.get-prototype-of'); 68646 _dereq_('core-js/modules/es.object.to-string'); 68647 _dereq_('core-js/modules/es.regexp.to-string'); 68648 _dereq_('core-js/modules/es.string.iterator'); 68649 _dereq_('core-js/modules/es.typed-array.uint8-array'); 68650 _dereq_('core-js/modules/es.typed-array.copy-within'); 68651 _dereq_('core-js/modules/es.typed-array.every'); 68652 _dereq_('core-js/modules/es.typed-array.fill'); 68653 _dereq_('core-js/modules/es.typed-array.filter'); 68654 _dereq_('core-js/modules/es.typed-array.find'); 68655 _dereq_('core-js/modules/es.typed-array.find-index'); 68656 _dereq_('core-js/modules/es.typed-array.for-each'); 68657 _dereq_('core-js/modules/es.typed-array.includes'); 68658 _dereq_('core-js/modules/es.typed-array.index-of'); 68659 _dereq_('core-js/modules/es.typed-array.iterator'); 68660 _dereq_('core-js/modules/es.typed-array.join'); 68661 _dereq_('core-js/modules/es.typed-array.last-index-of'); 68662 _dereq_('core-js/modules/es.typed-array.map'); 68663 _dereq_('core-js/modules/es.typed-array.reduce'); 68664 _dereq_('core-js/modules/es.typed-array.reduce-right'); 68665 _dereq_('core-js/modules/es.typed-array.reverse'); 68666 _dereq_('core-js/modules/es.typed-array.set'); 68667 _dereq_('core-js/modules/es.typed-array.slice'); 68668 _dereq_('core-js/modules/es.typed-array.some'); 68669 _dereq_('core-js/modules/es.typed-array.sort'); 68670 _dereq_('core-js/modules/es.typed-array.subarray'); 68671 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 68672 _dereq_('core-js/modules/es.typed-array.to-string'); 68673 _dereq_('core-js/modules/web.dom-collections.iterator'); 68674 Object.defineProperty(exports, '__esModule', { 68675 value: true 68676 }); 68677 exports.default = void 0; 68678 var _main = _interopRequireDefault(_dereq_('./main')); 68679 function _interopRequireDefault(obj) { 68680 return obj && obj.__esModule ? obj : { 68681 default: 68682 obj 68683 }; 68684 } 68685 function _toConsumableArray(arr) { 68686 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); 68687 } 68688 function _nonIterableSpread() { 68689 throw new TypeError('Invalid attempt to spread non-iterable instance'); 68690 } 68691 function _iterableToArray(iter) { 68692 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') return Array.from(iter); 68693 } 68694 function _arrayWithoutHoles(arr) { 68695 if (Array.isArray(arr)) { 68696 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 68697 arr2[i] = arr[i]; 68698 } 68699 return arr2; 68700 } 68701 } /** 68702 * Multiplies the current matrix by the one specified through the parameters. 68703 * This is a powerful operation that can perform the equivalent of translate, 68704 * scale, shear and rotate all at once. You can learn more about transformation 68705 * matrices on <a href="https://en.wikipedia.org/wiki/Transformation_matrix"> 68706 * Wikipedia</a>. 68707 * 68708 * The naming of the arguments here follows the naming of the <a href= 68709 * "https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-transform"> 68710 * WHATWG specification</a> and corresponds to a 68711 * transformation matrix of the 68712 * form: 68713 * 68714 * > <img style="max-width: 150px" src="assets/transformation-matrix.png"
68715 * alt="The transformation matrix used when applyMatrix is called"/> 68716 * 68717 * <img style="max-width: 300px" src="assets/transformation-matrix-4-4.png" 68718 * alt="The transformation matrix used when applyMatrix is called with 4x4 matrix"/> 68719 * 68720 * @method applyMatrix 68721 * @param {Array} arr an array of numbers - should be 6 or 16 length (2*3 or 4*4 matrix values) 68722 * @chainable 68723 * @example 68724 * <div> 68725 * <code> 68726 * function setup() { 68727 * frameRate(10); 68728 * rectMode(CENTER); 68729 * } 68730 * 68731 * function draw() { 68732 * let step = frameCount % 20; 68733 * background(200); 68734 * // Equivalent to translate(x, y); 68735 * applyMatrix(1, 0, 0, 1, 40 + step, 50); 68736 * rect(0, 0, 50, 50); 68737 * } 68738 * </code> 68739 * </div> 68740 * 68741 * <div> 68742 * <code> 68743 * function setup() { 68744 * frameRate(10); 68745 * rectMode(CENTER); 68746 * } 68747 * 68748 * function draw() { 68749 * let step = frameCount % 20; 68750 * background(200); 68751 * translate(50, 50); 68752 * // Equivalent to scale(x, y); 68753 * applyMatrix(1 / step, 0, 0, 1 / step, 0, 0); 68754 * rect(0, 0, 50, 50); 68755 * } 68756 * </code> 68757 * </div> 68758 * 68759 * <div> 68760 * <code> 68761 * function setup() { 68762 * frameRate(10); 68763 * rectMode(CENTER); 68764 * } 68765 * 68766 * function draw() { 68767 * let step = frameCount % 20; 68768 * let angle = map(step, 0, 20, 0, TWO_PI); 68769 * let cos_a = cos(angle); 68770 * let sin_a = sin(angle); 68771 * background(200); 68772 * translate(50, 50); 68773 * // Equivalent to rotate(angle); 68774 * applyMatrix(cos_a, sin_a, -sin_a, cos_a, 0, 0); 68775 * rect(0, 0, 50, 50); 68776 * } 68777 * </code> 68778 * </div> 68779 * 68780 * <div> 68781 * <code> 68782 * function setup() { 68783 * frameRate(10); 68784 * rectMode(CENTER); 68785 * } 68786 * 68787 * function draw() { 68788 * let step = frameCount % 20; 68789 * let angle = map(step, 0, 20, -PI / 4, PI / 4); 68790 * background(200); 68791 * translate(50, 50); 68792 * // equivalent to shearX(angle); 68793 * let shear_factor = 1 / tan(PI / 2 - angle); 68794 * applyMatrix(1, 0, shear_factor, 1, 0, 0); 68795 * rect(0, 0, 50, 50); 68796 * } 68797 * </code> 68798 * </div> 68799 * 68800 * <div modernizr='webgl'> 68801 * <code> 68802 * function setup() { 68803 * createCanvas(100, 100, WEBGL); 68804 * noFill(); 68805 * } 68806 * 68807 * function draw() { 68808 * background(200); 68809 * rotateY(PI / 6); 68810 * stroke(153); 68811 * box(35); 68812 * let rad = millis() / 1000; 68813 * // Set rotation angles 68814 * let ct = cos(rad); 68815 * let st = sin(rad); 68816 * // Matrix for rotation around the Y axis 68817 * applyMatrix( 68818 * ct, 0.0, st, 0.0, 68819 * 0.0, 1.0, 0.0, 0.0, 68820 * -st, 0.0, ct, 0.0, 68821 * 0.0, 0.0, 0.0, 1.0 68822 * ); 68823 * stroke(255); 68824 * box(50); 68825 * } 68826 * </code> 68827 * </div> 68828 * 68829 * <div> 68830 * <code> 68831 * function draw() { 68832 * background(200); 68833 * let testMatrix = [1, 0, 0, 1, 0, 0]; 68834 * applyMatrix(testMatrix); 68835 * rect(0, 0, 50, 50); 68836 * } 68837 * </code> 68838 * </div> 68839 * 68840 * @alt 68841 * A rectangle translating to the right 68842 * A rectangle shrinking to the center 68843 * A rectangle rotating clockwise about the center 68844 * A rectangle shearing 68845 * A rectangle in the upper left corner 68846 */ 68847 /**
68848 * @method applyMatrix 68849 * @param {Number} a numbers which define the 2Ã3 or 4x4 matrix to be multiplied 68850 * @param {Number} b numbers which define the 2Ã3 or 4x4 matrix to be multiplied 68851 * @param {Number} c numbers which define the 2Ã3 or 4x4 matrix to be multiplied 68852 * @param {Number} d numbers which define the 2Ã3 or 4x4 matrix to be multiplied 68853 * @param {Number} e numbers which define the 2Ã3 or 4x4 matrix to be multiplied 68854 * @param {Number} f numbers which define the 2Ã3 or 4x4 matrix to be multiplied 68855 * @chainable 68856 */ 68857 /** 68858 * @method applyMatrix 68859 * @param {Number} a 68860 * @param {Number} b 68861 * @param {Number} c 68862 * @param {Number} d 68863 * @param {Number} e 68864 * @param {Number} f 68865 * @param {Number} g numbers which define the 4x4 matrix to be multiplied 68866 * @param {Number} h numbers which define the 4x4 matrix to be multiplied 68867 * @param {Number} i numbers which define the 4x4 matrix to be multiplied 68868 * @param {Number} j numbers which define the 4x4 matrix to be multiplied 68869 * @param {Number} k numbers which define the 4x4 matrix to be multiplied 68870 * @param {Number} l numbers which define the 4x4 matrix to be multiplied 68871 * @param {Number} m numbers which define the 4x4 matrix to be multiplied 68872 * @param {Number} n numbers which define the 4x4 matrix to be multiplied 68873 * @param {Number} o numbers which define the 4x4 matrix to be multiplied 68874 * @param {Number} p numbers which define the 4x4 matrix to be multiplied 68875 * @chainable 68876 */ 68877 68878 _main.default.prototype.applyMatrix = function () { 68879 var isTypedArray = arguments[0] instanceof Object.getPrototypeOf(Uint8Array); 68880 if (Array.isArray(arguments[0]) || isTypedArray) { 68881 var _this$_renderer; 68882 (_this$_renderer = this._renderer).applyMatrix.apply(_this$_renderer, _toConsumableArray(arguments[0])); 68883 } else { 68884 var _this$_renderer2; 68885 (_this$_renderer2 = this._renderer).applyMatrix.apply(_this$_renderer2, arguments); 68886 } 68887 return this; 68888 }; 68889 /** 68890 * Replaces the current matrix with the identity matrix. 68891 * 68892 * @method resetMatrix 68893 * @chainable 68894 * @example 68895 * <div> 68896 * <code> 68897 * translate(50, 50); 68898 * applyMatrix(0.5, 0.5, -0.5, 0.5, 0, 0); 68899 * rect(0, 0, 20, 20); 68900 * // Note that the translate is also reset. 68901 * resetMatrix(); 68902 * rect(0, 0, 20, 20); 68903 * </code> 68904 * </div> 68905 * 68906 * @alt 68907 * A rotated rectangle in the center with another at the top left corner 68908 */ 68909 _main.default.prototype.resetMatrix = function () { 68910 this._renderer.resetMatrix(); 68911 return this; 68912 }; 68913 /** 68914 * Rotates a shape by the amount specified by the angle parameter. This 68915 * function accounts for <a href="#/p5/angleMode">angleMode</a>, so angles 68916 * can be entered in either RADIANS or DEGREES. 68917 * 68918 * Objects are always rotated around their relative position to the 68919 * origin and positive numbers rotate objects in a clockwise direction. 68920 * Transformations apply to everything that happens after and subsequent 68921 * calls to the function accumulate the effect. For example, calling 68922 * rotate(HALF_PI) and then rotate(HALF_PI) is the same as rotate(PI). 68923 * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again. 68924 * 68925 * Technically, <a href="#/p5/rotate">rotate()</a> multiplies the current transformation matrix 68926 * by a rotation matrix. This function can be further controlled by 68927 * <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>. 68928 * 68929 * @method rotate 68930 * @param {Number} angle the angle of rotation, specified in radians 68931 * or degrees, depending on current angleMode 68932 * @param {p5.Vector|Number[]} [axis] (in 3d) the axis to rotate around 68933 * @chainable 68934 * @example 68935 * <div> 68936 * <code> 68937 * translate(width / 2, height / 2); 68938 * rotate(PI / 3.0); 68939 * rect(-26, -26, 52, 52); 68940 * </code> 68941 * </div> 68942 * 68943 * @alt 68944 * white 52Ã52 rect with black outline at center rotated counter 45 degrees 68945 */ 68946 _main.default.prototype.rotate = function (angle, axis) { 68947 _main.default._validateParameters('rotate', arguments); 68948 this._renderer.rotate(this._toRadians(angle), axis); 68949 return this; 68950 }; 68951 /** 68952 * Rotates a shape around X axis by the amount specified in angle parameter. 68953 * The angles can be entered in either RADIANS or DEGREES.
68954 * 68955 * Objects are always rotated around their relative position to the 68956 * origin and positive numbers rotate objects in a clockwise direction. 68957 * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again. 68958 * 68959 * @method rotateX 68960 * @param {Number} angle the angle of rotation, specified in radians 68961 * or degrees, depending on current angleMode 68962 * @chainable 68963 * @example 68964 * <div modernizr='webgl'> 68965 * <code> 68966 * function setup() { 68967 * createCanvas(100, 100, WEBGL); 68968 * } 68969 * function draw() { 68970 * background(255); 68971 * rotateX(millis() / 1000); 68972 * box(); 68973 * } 68974 * </code> 68975 * </div> 68976 * 68977 * @alt 68978 * 3d box rotating around the x axis. 68979 */ 68980 _main.default.prototype.rotateX = function (angle) { 68981 this._assert3d('rotateX'); 68982 _main.default._validateParameters('rotateX', arguments); 68983 this._renderer.rotateX(this._toRadians(angle)); 68984 return this; 68985 }; 68986 /** 68987 * Rotates a shape around Y axis by the amount specified in angle parameter. 68988 * The angles can be entered in either RADIANS or DEGREES. 68989 * 68990 * Objects are always rotated around their relative position to the 68991 * origin and positive numbers rotate objects in a clockwise direction. 68992 * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again. 68993 * 68994 * @method rotateY 68995 * @param {Number} angle the angle of rotation, specified in radians 68996 * or degrees, depending on current angleMode 68997 * @chainable 68998 * @example 68999 * <div modernizr='webgl'> 69000 * <code> 69001 * function setup() { 69002 * createCanvas(100, 100, WEBGL); 69003 * } 69004 * function draw() { 69005 * background(255); 69006 * rotateY(millis() / 1000); 69007 * box(); 69008 * } 69009 * </code> 69010 * </div> 69011 * 69012 * @alt 69013 * 3d box rotating around the y axis. 69014 */ 69015 _main.default.prototype.rotateY = function (angle) { 69016 this._assert3d('rotateY'); 69017 _main.default._validateParameters('rotateY', arguments); 69018 this._renderer.rotateY(this._toRadians(angle)); 69019 return this; 69020 }; 69021 /** 69022 * Rotates a shape around Z axis by the amount specified in angle parameter. 69023 * The angles can be entered in either RADIANS or DEGREES. 69024 * 69025 * This method works in WEBGL mode only. 69026 * 69027 * Objects are always rotated around their relative position to the 69028 * origin and positive numbers rotate objects in a clockwise direction. 69029 * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again. 69030 * 69031 * @method rotateZ 69032 * @param {Number} angle the angle of rotation, specified in radians 69033 * or degrees, depending on current angleMode 69034 * @chainable 69035 * @example 69036 * <div modernizr='webgl'> 69037 * <code> 69038 * function setup() { 69039 * createCanvas(100, 100, WEBGL); 69040 * } 69041 * function draw() { 69042 * background(255); 69043 * rotateZ(millis() / 1000); 69044 * box(); 69045 * } 69046 * </code> 69047 * </div> 69048 * 69049 * @alt 69050 * 3d box rotating around the z axis. 69051 */ 69052 _main.default.prototype.rotateZ = function (angle) { 69053 this._assert3d('rotateZ'); 69054 _main.default._validateParameters('rotateZ', arguments); 69055 this._renderer.rotateZ(this._toRadians(angle)); 69056 return this; 69057 }; 69058 /** 69059 * Increases or decreases the size of a shape by expanding or contracting 69060 * vertices. Objects always scale from their relative origin to the 69061 * coordinate system. Scale values are specified as decimal percentages. 69062 * For example, the function call scale(2.0) increases the dimension of a 69063 * shape by 200%. 69064 * 69065 * Transformations apply to everything that happens after and subsequent 69066 * calls to the function multiply the effect. For example, calling scale(2.0) 69067 * and then scale(1.5) is the same as scale(3.0). If <a href="#/p5/scale">scale()</a> is called 69068 * within <a href="#/p5/draw">draw()</a>, the transformation is reset when the loop begins again. 69069 * 69070 * Using this function with the z parameter is only available in WEBGL mode. 69071 * This function can be further controlled with <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>. 69072 * 69073 * @method scale 69074 * @param {Number|p5.Vector|Number[]} s 69075 * percent to scale the object, or percentage to 69076 * scale the object in the x-axis if multiple arguments 69077 * are given 69078 * @param {Number} [y] percent to scale the object in the y-axis 69079 * @param {Number} [z] percent to scale the object in the z-axis (webgl only) 69080 * @chainable 69081 * @example 69082 * <div> 69083 * <code> 69084 * rect(30, 20, 50, 50); 69085 * scale(0.5); 69086 * rect(30, 20, 50, 50); 69087 * </code> 69088 * </div> 69089 * 69090 * <div> 69091 * <code> 69092 * rect(30, 20, 50, 50); 69093 * scale(0.5, 1.3); 69094 * rect(30, 20, 50, 50); 69095 * </code> 69096 * </div> 69097 * 69098 * @alt 69099 * white 52Ã52 rect with black outline at center rotated counter 45 degrees 69100 * 2 white rects with black outline- 1 50Ã50 at center. other 25Ã65 bottom left 69101 */ 69102 /** 69103 * @method scale 69104 * @param {p5.Vector|Number[]} scales per-axis percents to scale the object 69105 * @chainable 69106 */ 69107 _main.default.prototype.scale = function (x, y, z) { 69108 _main.default._validateParameters('scale', arguments); // Only check for Vector argument type if Vector is available 69109 if (x instanceof _main.default.Vector) { 69110 var v = x; 69111 x = v.x; 69112 y = v.y; 69113 z = v.z; 69114 } else if (x instanceof Array) { 69115 var rg = x; 69116 x = rg[0]; 69117 y = rg[1]; 69118 z = rg[2] || 1; 69119 } 69120 if (isNaN(y)) { 69121 y = z = x; 69122 } else if (isNaN(z)) { 69123 z = 1; 69124 } 69125 this._renderer.scale.call(this._renderer, x, y, z); 69126 return this; 69127 }; 69128 /** 69129 * Shears a shape around the x-axis by the amount specified by the angle 69130 * parameter. Angles should be specified in the current angleMode. 69131 * Objects are always sheared around their relative position to the origin 69132 * and positive numbers shear objects in a clockwise direction. 69133 * 69134 * Transformations apply to everything that happens after and subsequent 69135 * calls to the function accumulates the effect. For example, calling 69136 * shearX(PI/2) and then shearX(PI/2) is the same as shearX(PI). 69137 * If <a href="#/p5/shearX">shearX()</a> is called within the <a href="#/p5/draw">draw()</a>, 69138 * the transformation is reset when the loop begins again. 69139 *
69140 * Technically, <a href="#/p5/shearX">shearX()</a> multiplies the current 69141 * transformation matrix by a rotation matrix. This function can be further 69142 * controlled by the <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a> functions. 69143 * 69144 * @method shearX 69145 * @param {Number} angle angle of shear specified in radians or degrees, 69146 * depending on current angleMode 69147 * @chainable 69148 * @example 69149 * <div> 69150 * <code> 69151 * translate(width / 4, height / 4); 69152 * shearX(PI / 4.0); 69153 * rect(0, 0, 30, 30); 69154 * </code> 69155 * </div> 69156 * 69157 * @alt 69158 * white irregular quadrilateral with black outline at top middle. 69159 */ 69160 _main.default.prototype.shearX = function (angle) { 69161 _main.default._validateParameters('shearX', arguments); 69162 var rad = this._toRadians(angle); 69163 this._renderer.applyMatrix(1, 0, Math.tan(rad), 1, 0, 0); 69164 return this; 69165 }; 69166 /** 69167 * Shears a shape around the y-axis the amount specified by the angle 69168 * parameter. Angles should be specified in the current angleMode. Objects 69169 * are always sheared around their relative position to the origin and 69170 * positive numbers shear objects in a clockwise direction. 69171 * 69172 * Transformations apply to everything that happens after and subsequent 69173 * calls to the function accumulates the effect. For example, calling 69174 * shearY(PI/2) and then shearY(PI/2) is the same as shearY(PI). If 69175 * <a href="#/p5/shearY">shearY()</a> is called within the <a href="#/p5/draw">draw()</a>, the transformation is reset when 69176 * the loop begins again. 69177 * 69178 * Technically, <a href="#/p5/shearY">shearY()</a> multiplies the current transformation matrix by a 69179 * rotation matrix. This function can be further controlled by the 69180 * <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a> functions. 69181 * 69182 * @method shearY 69183 * @param {Number} angle angle of shear specified in radians or degrees, 69184 * depending on current angleMode 69185 * @chainable 69186 * @example 69187 * <div> 69188 * <code> 69189 * translate(width / 4, height / 4); 69190 * shearY(PI / 4.0); 69191 * rect(0, 0, 30, 30); 69192 * </code> 69193 * </div> 69194 * 69195 * @alt 69196 * white irregular quadrilateral with black outline at middle bottom. 69197 */ 69198 _main.default.prototype.shearY = function (angle) { 69199 _main.default._validateParameters('shearY', arguments); 69200 var rad = this._toRadians(angle); 69201 this._renderer.applyMatrix(1, Math.tan(rad), 0, 1, 0, 0); 69202 return this; 69203 }; 69204 /** 69205 * Specifies an amount to displace objects within the display window. 69206 * The x parameter specifies left/right translation, the y parameter 69207 * specifies up/down translation. 69208 * 69209 * Transformations are cumulative and apply to everything that happens after 69210 * and subsequent calls to the function accumulates the effect. For example, 69211 * calling translate(50, 0) and then translate(20, 0) is the same as 69212 * translate(70, 0). If <a href="#/p5/translate">translate()</a> is called within <a href="#/p5/draw">draw()</a>, the 69213 * transformation is reset when the loop begins again. This function can be 69214 * further controlled by using <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>. 69215 * 69216 * @method translate 69217 * @param {Number} x left/right translation 69218 * @param {Number} y up/down translation 69219 * @param {Number} [z] forward/backward translation (WEBGL only) 69220 * @chainable 69221 * @example 69222 * <div> 69223 * <code> 69224 * translate(30, 20); 69225 * rect(0, 0, 55, 55); 69226 * </code> 69227 * </div> 69228 * 69229 * <div> 69230 * <code> 69231 * rect(0, 0, 55, 55); // Draw rect at original 0,0 69232 * translate(30, 20); 69233 * rect(0, 0, 55, 55); // Draw rect at new 0,0 69234 * translate(14, 14); 69235 * rect(0, 0, 55, 55); // Draw rect at new 0,0 69236 * </code> 69237 * </div> 69238 * 69239 69240 * <div> 69241 * <code> 69242 * function draw() { 69243 * background(200); 69244 * rectMode(CENTER); 69245 * translate(width / 2, height / 2); 69246 * translate(p5.Vector.fromAngle(millis() / 1000, 40)); 69247 * rect(0, 0, 20, 20); 69248 * } 69249 * </code> 69250 * </div> 69251 * 69252 * @alt 69253 * white 55Ã55 rect with black outline at center right. 69254 * 3 white 55Ã55 rects with black outlines at top-l, center-r and bottom-r. 69255 * a 20Ã20 white rect moving in a circle around the canvas 69256 */ 69257 /** 69258 * @method translate 69259 * @param {p5.Vector} vector the vector to translate by 69260 * @chainable 69261 */ 69262 _main.default.prototype.translate = function (x, y, z) { 69263 _main.default._validateParameters('translate', arguments); 69264 if (this._renderer.isP3D) { 69265 this._renderer.translate(x, y, z); 69266 } else { 69267 this._renderer.translate(x, y); 69268 } 69269 return this; 69270 }; 69271 var _default = _main.default; 69272 exports.default = _default; 69273 }, 69274 { 69275 './main': 290, 69276 'core-js/modules/es.array.from': 173, 69277 'core-js/modules/es.array.iterator': 176, 69278 'core-js/modules/es.object.get-prototype-of': 193, 69279 'core-js/modules/es.object.to-string': 195, 69280 'core-js/modules/es.regexp.to-string': 200, 69281 'core-js/modules/es.string.iterator': 204, 69282 'core-js/modules/es.symbol': 214, 69283 'core-js/modules/es.symbol.description': 212, 69284 'core-js/modules/es.symbol.iterator': 213, 69285 'core-js/modules/es.typed-array.copy-within': 215, 69286 'core-js/modules/es.typed-array.every': 216, 69287 'core-js/modules/es.typed-array.fill': 217, 69288 'core-js/modules/es.typed-array.filter': 218, 69289 'core-js/modules/es.typed-array.find': 220, 69290 'core-js/modules/es.typed-array.find-index': 219, 69291 'core-js/modules/es.typed-array.for-each': 223, 69292 'core-js/modules/es.typed-array.includes': 224, 69293 'core-js/modules/es.typed-array.index-of': 225, 69294 'core-js/modules/es.typed-array.iterator': 228, 69295 'core-js/modules/es.typed-array.join': 229, 69296 'core-js/modules/es.typed-array.last-index-of': 230, 69297 'core-js/modules/es.typed-array.map': 231, 69298 'core-js/modules/es.typed-array.reduce': 233, 69299 'core-js/modules/es.typed-array.reduce-right': 232, 69300 'core-js/modules/es.typed-array.reverse': 234, 69301 'core-js/modules/es.typed-array.set': 235, 69302 'core-js/modules/es.typed-array.slice': 236, 69303 'core-js/modules/es.typed-array.some': 237, 69304 'core-js/modules/es.typed-array.sort': 238, 69305 'core-js/modules/es.typed-array.subarray': 239, 69306 'core-js/modules/es.typed-array.to-locale-string': 240, 69307 'core-js/modules/es.typed-array.to-string': 241, 69308 'core-js/modules/es.typed-array.uint8-array': 244, 69309 'core-js/modules/web.dom-collections.iterator': 248 69310 } 69311 ], 69312 304: [
69313 function (_dereq_, module, exports) { 69314 'use strict'; 69315 _dereq_('core-js/modules/es.symbol'); 69316 _dereq_('core-js/modules/es.symbol.description'); 69317 _dereq_('core-js/modules/es.symbol.iterator'); 69318 _dereq_('core-js/modules/es.array.from'); 69319 _dereq_('core-js/modules/es.array.iterator'); 69320 _dereq_('core-js/modules/es.object.to-string'); 69321 _dereq_('core-js/modules/es.regexp.to-string'); 69322 _dereq_('core-js/modules/es.string.ends-with'); 69323 _dereq_('core-js/modules/es.string.iterator'); 69324 _dereq_('core-js/modules/web.dom-collections.iterator'); 69325 function _typeof2(obj) { 69326 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 69327 _typeof2 = function _typeof2(obj) { 69328 return typeof obj; 69329 }; 69330 } else { 69331 _typeof2 = function _typeof2(obj) { 69332 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 69333 }; 69334 } 69335 return _typeof2(obj); 69336 } 69337 _dereq_('core-js/modules/es.symbol'); 69338 _dereq_('core-js/modules/es.symbol.description'); 69339 _dereq_('core-js/modules/es.symbol.iterator'); 69340 _dereq_('core-js/modules/es.array.from'); 69341 _dereq_('core-js/modules/es.array.iterator'); 69342 _dereq_('core-js/modules/es.object.to-string'); 69343 _dereq_('core-js/modules/es.regexp.to-string'); 69344 _dereq_('core-js/modules/es.string.ends-with'); 69345 _dereq_('core-js/modules/es.string.iterator'); 69346 _dereq_('core-js/modules/web.dom-collections.iterator'); 69347 var _main = _interopRequireDefault(_dereq_('../core/main')); 69348 function _interopRequireDefault(obj) { 69349 return obj && obj.__esModule ? obj : { 69350 default: 69351 obj 69352 }; 69353 } 69354 function _toConsumableArray(arr) { 69355 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); 69356 } 69357 function _nonIterableSpread() { 69358 throw new TypeError('Invalid attempt to spread non-iterable instance'); 69359 } 69360 function _iterableToArray(iter) { 69361 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') return Array.from(iter); 69362 } 69363 function _arrayWithoutHoles(arr) { 69364 if (Array.isArray(arr)) { 69365 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 69366 arr2[i] = arr[i]; 69367 } 69368 return arr2; 69369 } 69370 } 69371 function _typeof(obj) { 69372 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 69373 _typeof = function _typeof(obj) { 69374 return _typeof2(obj); 69375 }; 69376 } else { 69377 _typeof = function _typeof(obj) { 69378 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 69379 }; 69380 } 69381 return _typeof(obj); 69382 } /** 69383 * 69384 * Stores a value in local storage under the key name. 69385 * Local storage is saved in the browser and persists 69386 * between browsing sessions and page reloads. 69387 * The key can be the name of the variable but doesn't 69388 * have to be. To retrieve stored items 69389 * see <a href="#/p5/getItem">getItem</a>. 69390 * 69391 * Sensitive data such as passwords or personal information 69392 * should not be stored in local storage. 69393 * 69394 * @method storeItem 69395 * @for p5 69396 * @param {String} key 69397 * @param {String|Number|Object|Boolean|p5.Color|p5.Vector} value 69398 * 69399 * @example 69400 * <div><code> 69401 * // Type to change the letter in the 69402 * // center of the canvas. 69403 * // If you reload the page, it will 69404 * // still display the last key you entered 69405 * 69406 * let myText; 69407 * 69408 * function setup() { 69409 * createCanvas(100, 100); 69410 * myText = getItem('myText'); 69411 * if (myText === null) { 69412 * myText = ''; 69413 * } 69414 * describe(`When you type the key name is displayed as black text on white background. 69415 * If you reload the page, the last letter typed is still displaying.`); 69416 * } 69417 * 69418 * function draw() { 69419 * textSize(40); 69420 * background(255); 69421 * text(myText, width / 2, height / 2); 69422 * } 69423 * 69424 * function keyPressed() {
69425 * myText = key; 69426 * storeItem('myText', myText); 69427 * } 69428 * </code></div> 69429 */ 69430 69431 _main.default.prototype.storeItem = function (key, value) { 69432 if (typeof key !== 'string') { 69433 console.log('The argument that you passed to storeItem() - '.concat(key, ' is not a string.')); 69434 } 69435 if (key.endsWith('p5TypeID')) { 69436 console.log('The argument that you passed to storeItem() - '.concat(key, ' must not end with \'p5TypeID\'.')); 69437 } 69438 if (typeof value === 'undefined') { 69439 console.log('You cannot store undefined variables using storeItem().'); 69440 } 69441 var type = _typeof(value); 69442 switch (type) { 69443 case 'number': 69444 case 'boolean': 69445 value = value.toString(); 69446 break; 69447 case 'object': 69448 if (value instanceof _main.default.Color) { 69449 type = 'p5.Color'; 69450 } else if (value instanceof _main.default.Vector) { 69451 type = 'p5.Vector'; 69452 var coord = [ 69453 value.x, 69454 value.y, 69455 value.z 69456 ]; 69457 value = coord; 69458 } 69459 value = JSON.stringify(value); 69460 break; 69461 case 'string': 69462 default: 69463 break; 69464 } 69465 localStorage.setItem(key, value); 69466 var typeKey = ''.concat(key, 'p5TypeID'); 69467 localStorage.setItem(typeKey, type); 69468 }; 69469 /** 69470 * 69471 * Returns the value of an item that was stored in local storage 69472 * using storeItem() 69473 * 69474 * @method getItem 69475 * @for p5 69476 * @param {String} key name that you wish to use to store in local storage 69477 * @return {Number|Object|String|Boolean|p5.Color|p5.Vector} Value of stored item 69478 * 69479 * @example 69480 * <div><code> 69481 * // Click the mouse to change 69482 * // the color of the background 69483 * // Once you have changed the color 69484 * // it will stay changed even when you 69485 * // reload the page. 69486 * 69487 * let myColor; 69488 * 69489 * function setup() { 69490 * createCanvas(100, 100); 69491 * myColor = getItem('myColor'); 69492 * } 69493 * 69494 * function draw() { 69495 * if (myColor !== null) { 69496 * background(myColor); 69497 * } 69498 * describe(`If you click, the canvas changes to a random color.· 69499 * If you reload the page, the canvas is still the color it was when the 69500 * page was previously loaded.`); 69501 * } 69502 * 69503 * function mousePressed() { 69504 * myColor = color(random(255), random(255), random(255)); 69505 * storeItem('myColor', myColor); 69506 * } 69507 * </code></div> 69508 */ 69509 _main.default.prototype.getItem = function (key) { 69510 var value = localStorage.getItem(key); 69511 var type = localStorage.getItem(''.concat(key, 'p5TypeID')); 69512 if (typeof type === 'undefined') { 69513 console.log('Unable to determine type of item stored under '.concat(key, 'in local storage. Did you save the item with something other than setItem()?')); 69514 } else if (value !== null) { 69515 switch (type) { 69516 case 'number': 69517 value = parseFloat(value); 69518 break; 69519 case 'boolean': 69520 value = value === 'true'; 69521 break; 69522 case 'object': 69523 value = JSON.parse(value); 69524 break; 69525 case 'p5.Color': 69526 value = JSON.parse(value); 69527 value = this.color.apply(this, _toConsumableArray(value.levels)); 69528 break; 69529 case 'p5.Vector': 69530 value = JSON.parse(value); 69531 value = this.createVector.apply(this, _toConsumableArray(value)); 69532 break; 69533 case 'string': 69534 default: 69535 break; 69536 } 69537 } 69538 return value; 69539 }; 69540 /** 69541 * 69542 * Clears all local storage items set with storeItem() 69543 * for the current domain. 69544 * 69545 * @method clearStorage 69546 * @for p5 69547 * 69548 * @example 69549 * <div class="norender"> 69550 * <code> 69551 * function setup() { 69552 * let myNum = 10; 69553 * let myBool = false; 69554 * storeItem('myNum', myNum); 69555 * storeItem('myBool', myBool); 69556 * print(getItem('myNum')); // logs 10 to the console 69557 * print(getItem('myBool')); // logs false to the console 69558 * clearStorage(); 69559 * print(getItem('myNum')); // logs null to the console 69560 * print(getItem('myBool')); // logs null to the console 69561 * } 69562 * </code></div> 69563 */ 69564 _main.default.prototype.clearStorage = function () { 69565 localStorage.clear(); 69566 }; 69567 /** 69568 * 69569 * Removes an item that was stored with storeItem() 69570 * 69571 * @method removeItem 69572 * @param {String} key 69573 * @for p5 69574 * 69575 * @example 69576 * <div class="norender"> 69577 * <code> 69578 * function setup() { 69579 * let myVar = 10; 69580 * storeItem('myVar', myVar); 69581 * print(getItem('myVar')); // logs 10 to the console 69582 * removeItem('myVar'); 69583 * print(getItem('myVar')); // logs null to the console 69584 * } 69585 * </code></div> 69586 */ 69587 _main.default.prototype.removeItem = function (key) { 69588 if (typeof key !== 'string') { 69589 console.log('The argument that you passed to removeItem() - '.concat(key, ' is not a string.')); 69590 } 69591 localStorage.removeItem(key); 69592 localStorage.removeItem(''.concat(key, 'p5TypeID')); 69593 }; 69594 }, 69595 { 69596 '../core/main': 290, 69597 'core-js/modules/es.array.from': 173, 69598 'core-js/modules/es.array.iterator': 176, 69599 'core-js/modules/es.object.to-string': 195, 69600 'core-js/modules/es.regexp.to-string': 200, 69601 'core-js/modules/es.string.ends-with': 202, 69602 'core-js/modules/es.string.iterator': 204, 69603 'core-js/modules/es.symbol': 214, 69604 'core-js/modules/es.symbol.description': 212, 69605 'core-js/modules/es.symbol.iterator': 213, 69606 'core-js/modules/web.dom-collections.iterator': 248 69607 } 69608 ], 69609 305: [
69610 function (_dereq_, module, exports) { 69611 'use strict'; 69612 _dereq_('core-js/modules/es.array.concat'); 69613 _dereq_('core-js/modules/es.object.keys'); 69614 _dereq_('core-js/modules/es.string.sub'); 69615 _dereq_('core-js/modules/es.array.concat'); 69616 _dereq_('core-js/modules/es.object.keys'); 69617 _dereq_('core-js/modules/es.string.sub'); 69618 Object.defineProperty(exports, '__esModule', { 69619 value: true 69620 }); 69621 exports.default = void 0; 69622 var _main = _interopRequireDefault(_dereq_('../core/main')); 69623 function _interopRequireDefault(obj) { 69624 return obj && obj.__esModule ? obj : { 69625 default: 69626 obj 69627 }; 69628 } /** 69629 * @module Data 69630 * @submodule Dictionary 69631 * @for p5.TypedDict 69632 * @requires core 69633 * 69634 * This module defines the p5 methods for the p5 Dictionary classes. 69635 * The classes StringDict and NumberDict are for storing and working 69636 * with key-value pairs. 69637 */ 69638 /** 69639 * 69640 * Creates a new instance of p5.StringDict using the key-value pair 69641 * or the object you provide. 69642 * 69643 * @method createStringDict 69644 * @for p5 69645 * @param {String} key 69646 * @param {String} value 69647 * @return {p5.StringDict} 69648 * 69649 * @example 69650 * <div class="norender"> 69651 * <code> 69652 * function setup() { 69653 * let myDictionary = createStringDict('p5', 'js'); 69654 * print(myDictionary.hasKey('p5')); // logs true to console 69655 * 69656 * let anotherDictionary = createStringDict({ happy: 'coding' }); 69657 * print(anotherDictionary.hasKey('happy')); // logs true to console 69658 * } 69659 * </code></div> 69660 */ 69661 /** 69662 * @method createStringDict 69663 * @param {Object} object object 69664 * @return {p5.StringDict} 69665 */ 69666 69667 _main.default.prototype.createStringDict = function (key, value) { 69668 _main.default._validateParameters('createStringDict', arguments); 69669 return new _main.default.StringDict(key, value); 69670 }; 69671 /** 69672 * 69673 * Creates a new instance of <a href="#/p5.NumberDict">p5.NumberDict</a> using the key-value pair 69674 * or object you provide. 69675 * 69676 * @method createNumberDict 69677 * @for p5 69678 * @param {Number} key 69679 * @param {Number} value 69680 * @return {p5.NumberDict} 69681 * 69682 * @example 69683 * <div class="norender"> 69684 * <code> 69685 * function setup() { 69686 * let myDictionary = createNumberDict(100, 42); 69687 * print(myDictionary.hasKey(100)); // logs true to console 69688 * 69689 * let anotherDictionary = createNumberDict({ 200: 84 }); 69690 * print(anotherDictionary.hasKey(200)); // logs true to console 69691 * } 69692 * </code></div> 69693 */ 69694 /** 69695 * @method createNumberDict 69696 * @param {Object} object object 69697 * @return {p5.NumberDict} 69698 */ 69699 _main.default.prototype.createNumberDict = function (key, value) { 69700 _main.default._validateParameters('createNumberDict', arguments); 69701 return new _main.default.NumberDict(key, value); 69702 }; 69703 /** 69704 * 69705 * Base class for all p5.Dictionary types. Specifically 69706 * typed Dictionary classes inherit from this class. 69707 * 69708 * @class p5.TypedDict 69709 * @constructor 69710 */ 69711 _main.default.TypedDict = function (key, value) { 69712 if (key instanceof Object) { 69713 this.data = key; 69714 } else { 69715 this.data = { 69716 }; 69717 this.data[key] = value; 69718 } 69719 return this; 69720 }; 69721 /** 69722 * Returns the number of key-value pairs currently stored in the Dictionary. 69723 * 69724 * @method size 69725 * @return {Integer} the number of key-value pairs in the Dictionary 69726 * 69727 * @example 69728 * <div class="norender"> 69729 * <code> 69730 * function setup() { 69731 * let myDictionary = createNumberDict(1, 10); 69732 * myDictionary.create(2, 20); 69733 * myDictionary.create(3, 30); 69734 * print(myDictionary.size()); // logs 3 to the console 69735 * } 69736 * </code></div> 69737 */ 69738 _main.default.TypedDict.prototype.size = function () { 69739 return Object.keys(this.data).length; 69740 }; 69741 /** 69742 * Returns true if the given key exists in the Dictionary, 69743 * otherwise returns false. 69744 * 69745 * @method hasKey 69746 * @param {Number|String} key that you want to look up 69747 * @return {Boolean} whether that key exists in Dictionary 69748 * 69749 * @example 69750 * <div class="norender"> 69751 * <code> 69752 * function setup() { 69753 * let myDictionary = createStringDict('p5', 'js'); 69754 * print(myDictionary.hasKey('p5')); // logs true to console 69755 * } 69756 * </code></div> 69757 */ 69758 _main.default.TypedDict.prototype.hasKey = function (key) { 69759 return this.data.hasOwnProperty(key); 69760 }; 69761 /** 69762 * Returns the value stored at the given key. 69763 * 69764 * @method get 69765 * @param {Number|String} the key you want to access 69766 * @return {Number|String} the value stored at that key 69767 * 69768 * @example 69769 * <div class="norender"> 69770 * <code> 69771 * function setup() { 69772 * let myDictionary = createStringDict('p5', 'js'); 69773 * let myValue = myDictionary.get('p5'); 69774 * print(myValue === 'js'); // logs true to console 69775 * } 69776 * </code></div> 69777 */ 69778 _main.default.TypedDict.prototype.get = function (key) { 69779 if (this.data.hasOwnProperty(key)) { 69780 return this.data[key]; 69781 } else { 69782 console.log(''.concat(key, ' does not exist in this Dictionary')); 69783 } 69784 }; 69785 /** 69786 * Updates the value associated with the given key in case it already exists 69787 * in the Dictionary. Otherwise a new key-value pair is added. 69788 * 69789 * @method set 69790 * @param {Number|String} key 69791 * @param {Number|String} value 69792 * 69793 * @example 69794 * <div class="norender"> 69795 * <code> 69796 * function setup() { 69797 * let myDictionary = createStringDict('p5', 'js'); 69798 * myDictionary.set('p5', 'JS'); 69799 * myDictionary.print(); // logs "key: p5 - value: JS" to console 69800 * } 69801 * </code></div> 69802 */ 69803 _main.default.TypedDict.prototype.set = function (key, value) {
69804 if (this._validate(value)) { 69805 this.data[key] = value; 69806 } else { 69807 console.log('Those values dont work for this dictionary type.'); 69808 } 69809 }; 69810 /** 69811 * private helper function to handle the user passing in objects 69812 * during construction or calls to create() 69813 */ 69814 _main.default.TypedDict.prototype._addObj = function (obj) { 69815 for (var key in obj) { 69816 this.set(key, obj[key]); 69817 } 69818 }; 69819 /** 69820 * Creates a new key-value pair in the Dictionary. 69821 * 69822 * @method create 69823 * @param {Number|String} key 69824 * @param {Number|String} value 69825 * 69826 * @example 69827 * <div class="norender"> 69828 * <code> 69829 * function setup() { 69830 * let myDictionary = createStringDict('p5', 'js'); 69831 * myDictionary.create('happy', 'coding'); 69832 * myDictionary.print(); 69833 * // above logs "key: p5 - value: js, key: happy - value: coding" to console 69834 * } 69835 * </code></div> 69836 */ 69837 /** 69838 * @method create 69839 * @param {Object} obj key/value pair 69840 */ 69841 _main.default.TypedDict.prototype.create = function (key, value) { 69842 if (key instanceof Object && typeof value === 'undefined') { 69843 this._addObj(key); 69844 } else if (typeof key !== 'undefined') { 69845 this.set(key, value); 69846 } else { 69847 console.log('In order to create a new Dictionary entry you must pass ' + 'an object or a key, value pair'); 69848 } 69849 }; 69850 /** 69851 * Removes all previously stored key-value pairs from the Dictionary. 69852 * 69853 * @method clear 69854 * @example 69855 * <div class="norender"> 69856 * <code> 69857 * function setup() { 69858 * let myDictionary = createStringDict('p5', 'js'); 69859 * print(myDictionary.hasKey('p5')); // prints 'true' 69860 * myDictionary.clear(); 69861 * print(myDictionary.hasKey('p5')); // prints 'false' 69862 * } 69863 * </code> 69864 * </div> 69865 */ 69866 _main.default.TypedDict.prototype.clear = function () { 69867 this.data = { 69868 }; 69869 }; 69870 /** 69871 * Removes the key-value pair stored at the given key from the Dictionary. 69872 * 69873 * @method remove 69874 * @param {Number|String} key for the pair to remove 69875 * 69876 * @example 69877 * <div class="norender"> 69878 * <code> 69879 * function setup() { 69880 * let myDictionary = createStringDict('p5', 'js'); 69881 * myDictionary.create('happy', 'coding'); 69882 * myDictionary.print(); 69883 * // above logs "key: p5 - value: js, key: happy - value: coding" to console 69884 * myDictionary.remove('p5'); 69885 * myDictionary.print(); 69886 * // above logs "key: happy value: coding" to console 69887 * } 69888 * </code></div> 69889 */ 69890 _main.default.TypedDict.prototype.remove = function (key) { 69891 if (this.data.hasOwnProperty(key)) { 69892 delete this.data[key]; 69893 } else { 69894 throw new Error(''.concat(key, ' does not exist in this Dictionary')); 69895 } 69896 }; 69897 /** 69898 * Logs the set of items currently stored in the Dictionary to the console. 69899 * 69900 * @method print 69901 * 69902 * @example 69903 * <div class="norender"> 69904 * <code> 69905 * function setup() { 69906 * let myDictionary = createStringDict('p5', 'js'); 69907 * myDictionary.create('happy', 'coding'); 69908 * myDictionary.print(); 69909 * // above logs "key: p5 - value: js, key: happy - value: coding" to console 69910 * } 69911 * </code> 69912 * </div> 69913 */ 69914 _main.default.TypedDict.prototype.print = function () { 69915 for (var item in this.data) { 69916 console.log('key:'.concat(item, ' value:').concat(this.data[item])); 69917 } 69918 }; 69919 /** 69920 * Converts the Dictionary into a CSV file for local download. 69921 * 69922 * @method saveTable 69923 * @example 69924 * <div> 69925 * <code> 69926 * function setup() { 69927 * createCanvas(100, 100); 69928 * background(200); 69929 * text('click here to save', 10, 10, 70, 80); 69930 * } 69931 * 69932 * function mousePressed() { 69933 * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { 69934 * createStringDict({ 69935 * john: 1940, 69936 * paul: 1942, 69937 * george: 1943, 69938 * ringo: 1940 69939 * }).saveTable('beatles'); 69940 * } 69941 * } 69942 * </code> 69943 * </div> 69944 */ 69945 _main.default.TypedDict.prototype.saveTable = function (filename) { 69946 var output = ''; 69947 for (var key in this.data) { 69948 output += ''.concat(key, ',').concat(this.data[key], '\n'); 69949 } 69950 var blob = new Blob([output], { 69951 type: 'text/csv' 69952 }); 69953 _main.default.prototype.downloadFile(blob, filename || 'mycsv', 'csv'); 69954 }; 69955 /** 69956 * Converts the Dictionary into a JSON file for local download. 69957 * 69958 * @method saveJSON 69959 * @example 69960 * <div> 69961 * <code> 69962 * function setup() { 69963 * createCanvas(100, 100); 69964 * background(200); 69965 * text('click here to save', 10, 10, 70, 80); 69966 * } 69967 * 69968 * function mousePressed() { 69969 * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { 69970 * createStringDict({ 69971 * john: 1940, 69972 * paul: 1942, 69973 * george: 1943, 69974 * ringo: 1940 69975 * }).saveJSON('beatles'); 69976 * } 69977 * } 69978 * </code> 69979 * </div> 69980 */ 69981 _main.default.TypedDict.prototype.saveJSON = function (filename, opt) { 69982 _main.default.prototype.saveJSON(this.data, filename, opt); 69983 }; 69984 /** 69985 * private helper function to ensure that the user passed in valid 69986 * values for the Dictionary type 69987 */ 69988 _main.default.TypedDict.prototype._validate = function (value) { 69989 return true; 69990 }; 69991 /** 69992 * 69993 * A simple Dictionary class for Strings. 69994 * 69995 * @class p5.StringDict 69996 * @extends p5.TypedDict 69997 */ 69998 _main.default.StringDict = function () { 69999 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 70000 args[_key] = arguments[_key]; 70001 } 70002 _main.default.TypedDict.apply(this, args); 70003 }; 70004 _main.default.StringDict.prototype = Object.create(_main.default.TypedDict.prototype); 70005 _main.default.StringDict.prototype._validate = function (value) { 70006 return typeof value === 'string'; 70007 }; 70008 /** 70009 * 70010 * A simple Dictionary class for Numbers. 70011 * 70012 * @class p5.NumberDict 70013 * @constructor 70014 * @extends p5.TypedDict 70015 */ 70016 _main.default.NumberDict = function () { 70017 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 70018 args[_key2] = arguments[_key2]; 70019 } 70020 _main.default.TypedDict.apply(this, args); 70021 }; 70022 _main.default.NumberDict.prototype = Object.create(_main.default.TypedDict.prototype); 70023 /** 70024 * private helper function to ensure that the user passed in valid 70025 * values for the Dictionary type 70026 */ 70027 _main.default.NumberDict.prototype._validate = function (value) { 70028 return typeof value === 'number'; 70029 }; 70030 /** 70031 * Add the given number to the value currently stored at the given key. 70032 * The sum then replaces the value previously stored in the Dictionary. 70033 * 70034 * @method add 70035 * @param {Number} Key for the value you wish to add to 70036 * @param {Number} Number to add to the value 70037 * @example 70038 * <div class='norender'> 70039 * <code> 70040 * function setup() { 70041 * let myDictionary = createNumberDict(2, 5); 70042 * myDictionary.add(2, 2); 70043 * print(myDictionary.get(2)); // logs 7 to console. 70044 * } 70045 * </code></div> 70046 * 70047 */ 70048 _main.default.NumberDict.prototype.add = function (key, amount) { 70049 if (this.data.hasOwnProperty(key)) { 70050 this.data[key] += amount; 70051 } else { 70052 console.log('The key - '.concat(key, ' does not exist in this dictionary.')); 70053 } 70054 }; 70055 /** 70056 * Subtract the given number from the value currently stored at the given key. 70057 * The difference then replaces the value previously stored in the Dictionary. 70058 * 70059 * @method sub 70060 * @param {Number}
70060 Key for the value you wish to subtract from 70061 * @param {Number} Number to subtract from the value 70062 * @example 70063 * <div class='norender'> 70064 * <code> 70065 * function setup() { 70066 * let myDictionary = createNumberDict(2, 5); 70067 * myDictionary.sub(2, 2); 70068 * print(myDictionary.get(2)); // logs 3 to console. 70069 * } 70070 * </code></div> 70071 * 70072 */ 70073 _main.default.NumberDict.prototype.sub = function (key, amount) { 70074 this.add(key, - amount); 70075 }; 70076 /** 70077 * Multiply the given number with the value currently stored at the given key. 70078 * The product then replaces the value previously stored in the Dictionary. 70079 * 70080 * @method mult 70081 * @param {Number} Key for value you wish to multiply 70082 * @param {Number} Amount to multiply the value by 70083 * @example 70084 * <div class='norender'> 70085 * <code> 70086 * function setup() { 70087 * let myDictionary = createNumberDict(2, 4); 70088 * myDictionary.mult(2, 2); 70089 * print(myDictionary.get(2)); // logs 8 to console. 70090 * } 70091 * </code></div> 70092 * 70093 */ 70094 _main.default.NumberDict.prototype.mult = function (key, amount) { 70095 if (this.data.hasOwnProperty(key)) { 70096 this.data[key] *= amount; 70097 } else { 70098 console.log('The key - '.concat(key, ' does not exist in this dictionary.')); 70099 } 70100 }; 70101 /** 70102 * Divide the given number with the value currently stored at the given key. 70103 * The quotient then replaces the value previously stored in the Dictionary. 70104 * 70105 * @method div 70106 * @param {Number} Key for value you wish to divide 70107 * @param {Number} Amount to divide the value by 70108 * @example 70109 * <div class='norender'> 70110 * <code> 70111 * function setup() { 70112 * let myDictionary = createNumberDict(2, 8); 70113 * myDictionary.div(2, 2); 70114 * print(myDictionary.get(2)); // logs 4 to console. 70115 * } 70116 * </code></div> 70117 * 70118 */ 70119 _main.default.NumberDict.prototype.div = function (key, amount) { 70120 if (this.data.hasOwnProperty(key)) { 70121 this.data[key] /= amount; 70122 } else { 70123 console.log('The key - '.concat(key, ' does not exist in this dictionary.')); 70124 } 70125 }; 70126 /** 70127 * private helper function for finding lowest or highest value 70128 * the argument 'flip' is used to flip the comparison arrow 70129 * from 'less than' to 'greater than' 70130 */ 70131 _main.default.NumberDict.prototype._valueTest = function (flip) { 70132 if (Object.keys(this.data).length === 0) { 70133 throw new Error('Unable to search for a minimum or maximum value on an empty NumberDict'); 70134 } else if (Object.keys(this.data).length === 1) { 70135 return this.data[Object.keys(this.data) [0]]; 70136 } else { 70137 var result = this.data[Object.keys(this.data) [0]]; 70138 for (var key in this.data) { 70139 if (this.data[key] * flip < result * flip) { 70140 result = this.data[key]; 70141 } 70142 } 70143 return result; 70144 } 70145 }; 70146 /** 70147 * Return the lowest number currently stored in the Dictionary. 70148 * 70149 * @method minValue 70150 * @return {Number} 70151 * @example 70152 * <div class='norender'> 70153 * <code> 70154 * function setup() { 70155 * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 }); 70156 * let lowestValue = myDictionary.minValue(); // value is -10 70157 * print(lowestValue); 70158 * } 70159 * </code></div> 70160 */ 70161 _main.default.NumberDict.prototype.minValue = function () { 70162 return this._valueTest(1); 70163 }; 70164 /** 70165 * Return the highest number currently stored in the Dictionary. 70166 * 70167 * @method maxValue 70168 * @return {Number} 70169 * @example 70170 * <div class='norender'> 70171 * <code> 70172 * function setup() { 70173 * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 }); 70174 * let highestValue = myDictionary.maxValue(); // value is 3 70175 * print(highestValue); 70176 * } 70177 * </code></div> 70178 */ 70179 _main.default.NumberDict.prototype.maxValue = function () { 70180 return this._valueTest( - 1); 70181 }; 70182 /** 70183 * private helper function for finding lowest or highest key 70184 * the argument 'flip' is used to flip the comparison arrow 70185 * from 'less than' to 'greater than' 70186 */ 70187 _main.default.NumberDict.prototype._keyTest = function (flip) { 70188 if (Object.keys(this.data).length === 0) { 70189 throw new Error('Unable to use minValue on an empty NumberDict'); 70190 } else if (Object.keys(this.data).length === 1) { 70191 return Object.keys(this.data) [0]; 70192 } else { 70193 var result = Object.keys(this.data) [0]; 70194 for (var i = 1; i < Object.keys(this.data).length; i++) { 70195 if (Object.keys(this.data) [i] * flip < result * flip) { 70196 result = Object.keys(this.data) [i]; 70197 } 70198 } 70199 return result; 70200 } 70201 }; 70202 /** 70203 * Return the lowest key currently used in the Dictionary. 70204 * 70205 * @method minKey 70206 * @return {Number} 70207 * @example 70208 * <div class='norender'> 70209 * <code> 70210 * function setup() { 70211 * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 }); 70212 * let lowestKey = myDictionary.minKey(); // value is 1.2 70213 * print(lowestKey); 70214 * } 70215 * </code></div> 70216 */ 70217 _main.default.NumberDict.prototype.minKey = function () { 70218 return this._keyTest(1); 70219 }; 70220 /** 70221 * Return the highest key currently used in the Dictionary. 70222 * 70223 * @method maxKey 70224 * @return {Number} 70225 * @example 70226 * <div class='norender'> 70227 * <code> 70228 * function setup() { 70229 * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 }); 70230 * let highestKey = myDictionary.maxKey(); // value is 4 70231 * print(highestKey); 70232 * } 70233 * </code></div> 70234 */ 70235 _main.default.NumberDict.prototype.maxKey = function () { 70236 return this._keyTest( - 1); 70237 }; 70238 var _default = _main.default.TypedDict; 70239 exports.default = _default; 70240 }, 70241 { 70242 '../core/main': 290,
70243 'core-js/modules/es.array.concat': 167, 70244 'core-js/modules/es.object.keys': 194, 70245 'core-js/modules/es.string.sub': 210 70246 } 70247 ], 70248 306: [ 70249 function (_dereq_, module, exports) { 70250 'use strict'; 70251 _dereq_('core-js/modules/es.symbol'); 70252 _dereq_('core-js/modules/es.symbol.description'); 70253 _dereq_('core-js/modules/es.symbol.iterator'); 70254 _dereq_('core-js/modules/es.array.every'); 70255 _dereq_('core-js/modules/es.array.filter'); 70256 _dereq_('core-js/modules/es.array.for-each'); 70257 _dereq_('core-js/modules/es.array.from'); 70258 _dereq_('core-js/modules/es.array.index-of'); 70259 _dereq_('core-js/modules/es.array.iterator'); 70260 _dereq_('core-js/modules/es.array.map'); 70261 _dereq_('core-js/modules/es.array.slice'); 70262 _dereq_('core-js/modules/es.array.splice'); 70263 _dereq_('core-js/modules/es.function.name'); 70264 _dereq_('core-js/modules/es.object.to-string'); 70265 _dereq_('core-js/modules/es.promise'); 70266 _dereq_('core-js/modules/es.regexp.exec'); 70267 _dereq_('core-js/modules/es.regexp.to-string'); 70268 _dereq_('core-js/modules/es.string.iterator'); 70269 _dereq_('core-js/modules/es.string.replace'); 70270 _dereq_('core-js/modules/es.string.split'); 70271 _dereq_('core-js/modules/es.string.trim'); 70272 _dereq_('core-js/modules/web.dom-collections.for-each'); 70273 _dereq_('core-js/modules/web.dom-collections.iterator'); 70274 _dereq_('core-js/modules/web.url'); 70275 function _typeof2(obj) { 70276 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 70277 _typeof2 = function _typeof2(obj) { 70278 return typeof obj; 70279 }; 70280 } else { 70281 _typeof2 = function _typeof2(obj) { 70282 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 70283 }; 70284 } 70285 return _typeof2(obj); 70286 } 70287 _dereq_('core-js/modules/es.symbol'); 70288 _dereq_('core-js/modules/es.symbol.description'); 70289 _dereq_('core-js/modules/es.symbol.iterator'); 70290 _dereq_('core-js/modules/es.array.every'); 70291 _dereq_('core-js/modules/es.array.filter'); 70292 _dereq_('core-js/modules/es.array.for-each'); 70293 _dereq_('core-js/modules/es.array.from'); 70294 _dereq_('core-js/modules/es.array.index-of'); 70295 _dereq_('core-js/modules/es.array.iterator'); 70296 _dereq_('core-js/modules/es.array.map'); 70297 _dereq_('core-js/modules/es.array.slice'); 70298 _dereq_('core-js/modules/es.array.splice'); 70299 _dereq_('core-js/modules/es.function.name'); 70300 _dereq_('core-js/modules/es.object.to-string'); 70301 _dereq_('core-js/modules/es.promise'); 70302 _dereq_('core-js/modules/es.regexp.exec'); 70303 _dereq_('core-js/modules/es.regexp.to-string'); 70304 _dereq_('core-js/modules/es.string.iterator'); 70305 _dereq_('core-js/modules/es.string.replace'); 70306 _dereq_('core-js/modules/es.string.split'); 70307 _dereq_('core-js/modules/es.string.trim'); 70308 _dereq_('core-js/modules/web.dom-collections.for-each'); 70309 _dereq_('core-js/modules/web.dom-collections.iterator'); 70310 _dereq_('core-js/modules/web.url'); 70311 Object.defineProperty(exports, '__esModule', { 70312 value: true 70313 }); 70314 exports.default = void 0; 70315 var _main = _interopRequireDefault(_dereq_('../core/main')); 70316 function _interopRequireDefault(obj) { 70317 return obj && obj.__esModule ? obj : { 70318 default: 70319 obj 70320 }; 70321 } 70322 function _typeof(obj) { 70323 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 70324 _typeof = function _typeof(obj) { 70325 return _typeof2(obj); 70326 }; 70327 } else { 70328 _typeof = function _typeof(obj) { 70329 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 70330 }; 70331 } 70332 return _typeof(obj); 70333 } /** 70334 * Searches the page for the first element that matches the given CSS selector string (can be an 70335 * ID, class, tag name or a combination) and returns it as a <a href="#/p5.Element">p5.Element</a>. 70336 * The DOM node itself can be accessed with .elt. 70337 * Returns null if none found. You can also specify a container to search within. 70338 * 70339 * @method select 70340 * @param {String} selectors CSS selector string of element to search for 70341 * @param {String|p5.Element|HTMLElement} [container] CSS selector string, <a href="#/p5.Element">p5.Element</a>, or 70342 * HTML element to search within 70343 * @return {p5.Element|null} <a href="#/p5.Element">p5.Element</a> containing node found 70344 * @example 70345 * <div><code> 70346 * function setup() { 70347 * createCanvas(50, 50); 70348 * background(30); 70349 * // move canvas down and right 70350 * select('canvas').position(10, 30); 70351 * } 70352 * </code></div> 70353 * 70354 * <div class="norender"><code> 70355 * // select using ID 70356 * let a = select('#container'); 70357 * let b = select('#beep', '#container'); 70358 * let c; 70359 * if (a) { 70360 * // select using class 70361 * c = select('.boop', a); 70362 * } 70363 * // select using CSS selector string 70364 * let d = select('#container #bleep'); 70365 * let e = select('#container p'); 70366 * [a, b, c, d, e]; // unused 70367 * </code></div> 70368 */ 70369 70370 _main.default.prototype.select = function (e, p) { 70371 _main.default._validateParameters('select', arguments); 70372 var container = this._getContainer(p); 70373 var res = container.querySelector(e); 70374 if (res) { 70375 return this._wrapElement(res); 70376 } else { 70377 return null; 70378 } 70379 }; 70380 /** 70381 * Searches the page for elements that match the given CSS selector string (can be an ID a class, 70382 * tag name or a combination) and returns them as <a href="#/p5.Element">p5.Element</a>s in 70383 * an array.
70384 * The DOM node itself can be accessed with .elt. 70385 * Returns an empty array if none found. 70386 * You can also specify a container to search within. 70387 * 70388 * @method selectAll 70389 * @param {String} selectors CSS selector string of elements to search for 70390 * @param {String|p5.Element|HTMLElement} [container] CSS selector string, <a href="#/p5.Element">p5.Element</a> 70391 * , or HTML element to search within 70392 * @return {p5.Element[]} Array of <a href="#/p5.Element">p5.Element</a>s containing nodes found 70393 * @example 70394 * <div><code> 70395 * function setup() { 70396 * createButton('btn'); 70397 * createButton('2nd btn'); 70398 * createButton('3rd btn'); 70399 * let buttons = selectAll('button'); 70400 * 70401 * for (let i = 0; i < 3; i++) { 70402 * buttons[i].size(100); 70403 * buttons[i].position(0, i * 30); 70404 * } 70405 * } 70406 * </code></div> 70407 * <div><code> 70408 * // these are all valid calls to selectAll() 70409 * let a = selectAll('.beep'); 70410 * a = selectAll('div'); 70411 * a = selectAll('button', '#container'); 70412 * 70413 * let b = createDiv(); 70414 * b.id('container'); 70415 * let c = select('#container'); 70416 * a = selectAll('p', c); 70417 * a = selectAll('#container p'); 70418 * 70419 * let d = document.getElementById('container'); 70420 * a = selectAll('.boop', d); 70421 * a = selectAll('#container .boop'); 70422 * console.log(a); 70423 * </code></div> 70424 */ 70425 _main.default.prototype.selectAll = function (e, p) { 70426 _main.default._validateParameters('selectAll', arguments); 70427 var arr = [ 70428 ]; 70429 var container = this._getContainer(p); 70430 var res = container.querySelectorAll(e); 70431 if (res) { 70432 for (var j = 0; j < res.length; j++) { 70433 var obj = this._wrapElement(res[j]); 70434 arr.push(obj); 70435 } 70436 } 70437 return arr; 70438 }; 70439 /** 70440 * Helper function for select and selectAll 70441 */ 70442 _main.default.prototype._getContainer = function (p) { 70443 var container = document; 70444 if (typeof p === 'string') { 70445 container = document.querySelector(p) || document; 70446 } else if (p instanceof _main.default.Element) { 70447 container = p.elt; 70448 } else if (p instanceof HTMLElement) { 70449 container = p; 70450 } 70451 return container; 70452 }; 70453 /** 70454 * Helper function for getElement and getElements. 70455 */ 70456 _main.default.prototype._wrapElement = function (elt) { 70457 var children = Array.prototype.slice.call(elt.children); 70458 if (elt.tagName === 'INPUT' && elt.type === 'checkbox') { 70459 var converted = new _main.default.Element(elt, this); 70460 converted.checked = function () { 70461 if (arguments.length === 0) { 70462 return this.elt.checked; 70463 } else if (arguments[0]) { 70464 this.elt.checked = true; 70465 } else { 70466 this.elt.checked = false; 70467 } 70468 return this; 70469 }; 70470 return converted; 70471 } else if (elt.tagName === 'VIDEO' || elt.tagName === 'AUDIO') { 70472 return new _main.default.MediaElement(elt, this); 70473 } else if (elt.tagName === 'SELECT') { 70474 return this.createSelect(new _main.default.Element(elt, this)); 70475 } else if (children.length > 0 && children.every(function (c) { 70476 return c.tagName === 'INPUT' || c.tagName === 'LABEL'; 70477 })) { 70478 return this.createRadio(new _main.default.Element(elt, this)); 70479 } else { 70480 return new _main.default.Element(elt, this); 70481 } 70482 }; 70483 /** 70484 * Removes all elements created by p5, except any canvas / graphics 70485 * elements created by <a href="#/p5/createCanvas">createCanvas</a> or <a href="#/p5/createGraphics">createGraphics</a>. 70486 * Event handlers are removed, and element is removed from the DOM. 70487 * @method removeElements 70488 * @example 70489 * <div><code> 70490 * function setup() { 70491 * createCanvas(100, 100); 70492 * background('grey'); 70493 * let div = createDiv('this is some text'); 70494 * let p = createP('this is a paragraph'); 70495 * div.style('font-size', '16px'); 70496 * p.style('font-size', '16px'); 70497 * } 70498 * function mousePressed() { 70499 * removeElements(); // this will remove the div and p, not canvas 70500 * } 70501 * </code></div> 70502 */ 70503 _main.default.prototype.removeElements = function (e) { 70504 _main.default._validateParameters('removeElements', arguments); // el.remove splices from this._elements, so don't mix iteration with it 70505 var isNotCanvasElement = function isNotCanvasElement(el) { 70506 return !(el.elt instanceof HTMLCanvasElement); 70507 }; 70508 var removeableElements = this._elements.filter(isNotCanvasElement); 70509 removeableElements.map(function (el) { 70510 return el.remove(); 70511 }); 70512 }; 70513 /** 70514 * The .<a href="#/p5.Element/changed">changed()</a> function is called when the value of an 70515 * element changes. 70516 * This can be used to attach an element specific event listener. 70517 * 70518 * @method changed 70519 * @param {Function|Boolean} fxn function to be fired when the value of 70520 * an element changes. 70521 * if `false` is passed instead, the previously 70522 * firing function will no longer fire. 70523 * @chainable 70524 * @example 70525 * <div><code> 70526 * let sel; 70527 * 70528 * function setup() { 70529 * textAlign(CENTER); 70530 * background(200); 70531 * sel = createSelect(); 70532 * sel.position(10, 10); 70533 * sel.option('pear'); 70534 * sel.option('kiwi'); 70535 * sel.option('grape'); 70536 * sel.changed(mySelectEvent); 70537 * } 70538 * 70539 * function mySelectEvent() { 70540 * let item = sel.value(); 70541 * background(200); 70542 * text("it's a " + item + '!', 50, 50); 70543 * } 70544 * </code></div> 70545 * 70546 * <div><code> 70547 * let checkbox; 70548 * let cnv; 70549 * 70550 * function setup() { 70551 * checkbox = createCheckbox(' fill'); 70552 * checkbox.changed(changeFill); 70553 * cnv = createCanvas(100, 100); 70554 * cnv.position(0, 30); 70555 * noFill(); 70556 * } 70557 * 70558 * function draw() { 70559 * background(200); 70560 * ellipse(50, 50, 50, 50); 70561 * } 70562 * 70563 * function changeFill() { 70564 * if (checkbox.checked()) { 70565 * fill(0); 70566 * } else { 70567 * noFill(); 70568 * } 70569 * } 70570 * </code></div> 70571 * 70572 * @alt 70573 * dropdown: pear, kiwi, grape. When selected text "it's a" + selection shown.
70574 */ 70575 _main.default.Element.prototype.changed = function (fxn) { 70576 _main.default.Element._adjustListener('change', fxn, this); 70577 return this; 70578 }; 70579 /** 70580 * The .<a href="#/p5.Element/input">input()</a> function is called when any user input is 70581 * detected with an element. The input event is often used 70582 * to detect keystrokes in a input element, or changes on a 70583 * slider element. This can be used to attach an element specific 70584 * event listener. 70585 * 70586 * @method input 70587 * @param {Function|Boolean} fxn function to be fired when any user input is 70588 * detected within the element. 70589 * if `false` is passed instead, the previously 70590 * firing function will no longer fire. 70591 * @chainable 70592 * @example 70593 * <div><code> 70594 * // Open your console to see the output 70595 * function setup() { 70596 * createCanvas(100, 100); 70597 * background('grey'); 70598 * let inp = createInput(''); 70599 * inp.position(0, 0); 70600 * inp.size(100); 70601 * inp.input(myInputEvent); 70602 * } 70603 * 70604 * function myInputEvent() { 70605 * console.log('you are typing: ', this.value()); 70606 * } 70607 * </code></div> 70608 * 70609 * @alt 70610 * no display. 70611 */ 70612 _main.default.Element.prototype.input = function (fxn) { 70613 _main.default.Element._adjustListener('input', fxn, this); 70614 return this; 70615 }; 70616 /** 70617 * Helpers for create methods. 70618 */ 70619 function addElement(elt, pInst, media) { 70620 var node = pInst._userNode ? pInst._userNode : document.body; 70621 node.appendChild(elt); 70622 var c = media ? new _main.default.MediaElement(elt, pInst) : new _main.default.Element(elt, pInst); 70623 pInst._elements.push(c); 70624 return c; 70625 } /** 70626 * Creates a `<div></div>` element in the DOM with given inner HTML. 70627 * 70628 * @method createDiv 70629 * @param {String} [html] inner HTML for element created 70630 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70631 * @example 70632 * <div><code> 70633 * let div = createDiv('this is some text'); 70634 * div.style('font-size', '16px'); 70635 * div.position(10, 0); 70636 * </code></div> 70637 */ 70638 70639 _main.default.prototype.createDiv = function () { 70640 var html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; 70641 var elt = document.createElement('div'); 70642 elt.innerHTML = html; 70643 return addElement(elt, this); 70644 }; 70645 /** 70646 * Creates a `<p></p>` element in the DOM with given inner HTML. Used 70647 * for paragraph length text. 70648 * 70649 * @method createP 70650 * @param {String} [html] inner HTML for element created 70651 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70652 * @example 70653 * <div><code> 70654 * let p = createP('this is some text'); 70655 * p.style('font-size', '16px'); 70656 * p.position(10, 0); 70657 * </code></div> 70658 */ 70659 _main.default.prototype.createP = function () { 70660 var html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; 70661 var elt = document.createElement('p'); 70662 elt.innerHTML = html; 70663 return addElement(elt, this); 70664 }; 70665 /** 70666 * Creates a `<span></span>` element in the DOM with given inner HTML. 70667 * 70668 * @method createSpan 70669 * @param {String} [html] inner HTML for element created 70670 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70671 * @example 70672 * <div><code> 70673 * let span = createSpan('this is some text'); 70674 * span.position(0, 0); 70675 * </code></div> 70676 */ 70677 _main.default.prototype.createSpan = function () { 70678 var html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; 70679 var elt = document.createElement('span'); 70680 elt.innerHTML = html; 70681 return addElement(elt, this); 70682 }; 70683 /** 70684 * Creates an `<img>` element in the DOM with given src and 70685 * alternate text. 70686 * 70687 * @method createImg 70688 * @param {String} src src path or url for image 70689 * @param {String} alt <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img#Attributes">alternate text</a> to be used if image does not load. You can use also an empty string (`""`) if that an image is not intended to be viewed. 70690 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70691 * @example 70692 * <div><code> 70693 * let img = createImg( 70694 * 'https://p5js.org/assets/img/asterisk-01.png', 70695 * 'the p5 magenta asterisk' 70696 * ); 70697 * img.position(0, -10); 70698 * </code></div> 70699 */ 70700 /** 70701 * @method createImg 70702 * @param {String} src 70703 * @param {String} alt 70704 * @param {String} crossOrigin <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes">crossOrigin property</a> of the `img` element; use either 'anonymous' or 'use-credentials' to retrieve the image with cross-origin access (for later use with `canvas`. if an empty string(`""`) is passed, CORS is not used 70705 * @param {Function} [successCallback] callback to be called once image data is loaded with the <a href="#/p5.Element">p5.Element</a> as argument 70706 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70707 */ 70708 _main.default.prototype.createImg = function () { 70709 _main.default._validateParameters('createImg', arguments); 70710 var elt = document.createElement('img'); 70711 var args = arguments; 70712 var self; 70713 if (args.length > 1 && typeof args[1] === 'string') { 70714 elt.alt = args[1]; 70715 } 70716 if (args.length > 2 && typeof args[2] === 'string') { 70717 elt.crossOrigin = args[2]; 70718 } 70719 elt.src = args[0]; 70720 self = addElement(elt, this); 70721 elt.addEventListener('load', function () { 70722 self.width = elt.offsetWidth || elt.width; 70723 self.height = elt.offsetHeight || elt.height; 70724 var last = args[args.length - 1]; 70725 if (typeof last === 'function') last(self); 70726 }); 70727 return self; 70728 }; 70729 /** 70730 * Creates an `<a></a>` element in the DOM for including a hyperlink. 70731 * 70732 * @method createA 70733 * @param {String} href url of page to link to 70734 * @param {String} html inner html of link element to display 70735 * @param {String} [target] target where new link should open, 70736 * could be _blank, _self, _parent, _top. 70737 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70738 * @example 70739 * <div><code> 70740 * let a = createA('http://p5js.org/', 'this is a link'); 70741 * a.position(0, 0); 70742 * </code></div> 70743 */ 70744 _main.default.prototype.createA = function (href, html, target) { 70745 _main.default._validateParameters('createA', arguments); 70746 var elt = document.createElement('a'); 70747 elt.href = href; 70748 elt.innerHTML = html; 70749 if (target) elt.target = target; 70750 return addElement(elt, this); 70751 }; 70752 /** INPUT **/ 70753 /** 70754 * Creates a slider `<input></input>` element in the DOM. 70755 * Use .size() to set the display length of the slider. 70756 * 70757 * @method createSlider 70758 * @param {Number} min minimum value of the slider 70759 * @param {Number} max maximum value of the slider 70760 * @param {Number} [value] default value of the slider 70761 * @param {Number} [step] step size for each tick of the slider (if step is set to 0, the slider will move continuously from the minimum to the maximum value) 70762 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding the created node 70763 * @example 70764 * <div><code> 70765 * let slider; 70766 * function setup() { 70767 * slider = createSlider(0, 255, 100); 70768 * slider.position(10, 10); 70769 * slider.style('width', '80px'); 70770 * } 70771 * 70772 * function draw() { 70773 * let val = slider.value(); 70774 * background(val); 70775 * } 70776 * </code></div> 70777 * 70778 * <div><code> 70779 * let slider; 70780 * function setup() { 70781 * colorMode(HSB); 70782 * slider = createSlider(0, 360, 60, 40); 70783 * slider.position(10, 10); 70784 * slider.style('width', '80px'); 70785 * } 70786 * 70787 * function draw() { 70788 * let val = slider.value();
70789 * background(val, 100, 100, 1); 70790 * } 70791 * </code></div> 70792 */ 70793 _main.default.prototype.createSlider = function (min, max, value, step) { 70794 _main.default._validateParameters('createSlider', arguments); 70795 var elt = document.createElement('input'); 70796 elt.type = 'range'; 70797 elt.min = min; 70798 elt.max = max; 70799 if (step === 0) { 70800 elt.step = 1e-18; // smallest valid step 70801 } else if (step) { 70802 elt.step = step; 70803 } 70804 if (typeof value === 'number') elt.value = value; 70805 return addElement(elt, this); 70806 }; 70807 /** 70808 * Creates a `<button></button>` element in the DOM. 70809 * Use .size() to set the display size of the button. 70810 * Use .mousePressed() to specify behavior on press. 70811 * 70812 * @method createButton 70813 * @param {String} label label displayed on the button 70814 * @param {String} [value] value of the button 70815 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70816 * @example 70817 * <div><code> 70818 * let button; 70819 * function setup() { 70820 * createCanvas(100, 100); 70821 * background(0); 70822 * button = createButton('click me'); 70823 * button.position(0, 0); 70824 * button.mousePressed(changeBG); 70825 * } 70826 * 70827 * function changeBG() { 70828 * let val = random(255); 70829 * background(val); 70830 * } 70831 * </code></div> 70832 */ 70833 _main.default.prototype.createButton = function (label, value) { 70834 _main.default._validateParameters('createButton', arguments); 70835 var elt = document.createElement('button'); 70836 elt.innerHTML = label; 70837 if (value) elt.value = value; 70838 return addElement(elt, this); 70839 }; 70840 /** 70841 * Creates a checkbox `<input></input>` element in the DOM. 70842 * Calling .checked() on a checkbox returns a boolean indicating whether 70843 * it is checked or not. 70844 * 70845 * @method createCheckbox 70846 * @param {String} [label] label displayed after checkbox 70847 * @param {boolean} [value] value of the checkbox; checked is true, unchecked is false 70848 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70849 * @example 70850 * <div><code> 70851 * let checkbox; 70852 * 70853 * function setup() { 70854 * checkbox = createCheckbox('label', false); 70855 * checkbox.changed(myCheckedEvent); 70856 * } 70857 * 70858 * function myCheckedEvent() { 70859 * if (checkbox.checked()) { 70860 * console.log('Checking!'); 70861 * } else { 70862 * console.log('Unchecking!'); 70863 * } 70864 * } 70865 * </code></div> 70866 */ 70867 _main.default.prototype.createCheckbox = function () { 70868 _main.default._validateParameters('createCheckbox', arguments); // Create a container element 70869 var elt = document.createElement('div'); // Create checkbox type input element 70870 var checkbox = document.createElement('input'); 70871 checkbox.type = 'checkbox'; // Create label element and wrap it around checkbox 70872 var label = document.createElement('label'); 70873 label.appendChild(checkbox); // Append label element inside the container 70874 elt.appendChild(label); //checkbox must be wrapped in p5.Element before label so that label appears after 70875 var self = addElement(elt, this); 70876 self.checked = function () { 70877 var cb = self.elt.firstElementChild.getElementsByTagName('input') [0]; 70878 if (cb) { 70879 if (arguments.length === 0) { 70880 return cb.checked; 70881 } else if (arguments[0]) { 70882 cb.checked = true; 70883 } else { 70884 cb.checked = false; 70885 } 70886 } 70887 return self; 70888 }; 70889 this.value = function (val) { 70890 self.value = val; 70891 return this; 70892 }; // Set the span element innerHTML as the label value if passed 70893 if (arguments[0]) { 70894 self.value(arguments[0]); 70895 var span = document.createElement('span'); 70896 span.innerHTML = arguments[0]; 70897 label.appendChild(span); 70898 } // Set the checked value of checkbox if passed 70899 70900 if (arguments[1]) { 70901 checkbox.checked = true; 70902 } 70903 return self; 70904 }; 70905 /** 70906 * Creates a dropdown menu `<select></select>` element in the DOM. 70907 * It also assigns select-related methods to <a href="#/p5.Element">p5.Element</a> when selecting an existing select box. Options in the menu are unique by `name` (the display text). 70908 * - `.option(name, [value])` can be used to add an option with `name` (the display text) and `value` to the select element. If an option with `name` already exists within the select element, this method will change its value to `value`. 70909 * - `.value()` will return the currently selected option. 70910 * - `.selected()` will return the current dropdown element which is an instance of <a href="#/p5.Element">p5.Element</a>. 70911 * - `.selected(value)` can be used to make given option selected by default when the page first loads. 70912 * - `.disable()` marks the whole dropdown element as disabled. 70913 * - `.disable(value)` marks a given option as disabled. 70914 * 70915 * @method createSelect 70916 * @param {boolean} [multiple] true if dropdown should support multiple selections 70917 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 70918 * @example 70919 * <div><code> 70920 * let sel; 70921 * 70922 * function setup() { 70923 * textAlign(CENTER); 70924 * background(200); 70925 * sel = createSelect(); 70926 * sel.position(10, 10); 70927 * sel.option('pear'); 70928 * sel.option('kiwi'); 70929 * sel.option('grape'); 70930 * sel.selected('kiwi'); 70931 * sel.changed(mySelectEvent); 70932 * } 70933 * 70934 * function mySelectEvent() { 70935 * let item = sel.value(); 70936 * background(200); 70937 * text('It is a ' + item + '!', 50, 50); 70938 * } 70939 * </code></div> 70940 * 70941 * <div><code> 70942 * let sel; 70943 * 70944 * function setup() { 70945 * textAlign(CENTER); 70946 * background(200); 70947 * sel = createSelect(); 70948 * sel.position(10, 10); 70949 * sel.option('oil'); 70950 * sel.option('milk'); 70951 * sel.option('bread'); 70952 * sel.disable('milk'); 70953 * } 70954 * </code></div> 70955 */ 70956 /** 70957 * @method createSelect 70958 * @param {Object} existing DOM select element 70959 * @return {p5.Element} 70960 */ 70961 _main.default.prototype.createSelect = function () { 70962 _main.default._validateParameters('createSelect', arguments); 70963 var self; 70964 var arg = arguments[0]; 70965 if (arg instanceof _main.default.Element && arg.elt instanceof HTMLSelectElement) { 70966 // If given argument is p5.Element of select type 70967 self = arg; 70968 this.elt = arg.elt; 70969 } else if (arg instanceof HTMLSelectElement) { 70970 self = addElement(arg, this); 70971 this.elt = arg; 70972 } else { 70973 var elt = document.createElement('select'); 70974 if (arg && typeof arg === 'boolean') { 70975 elt.setAttribute('multiple', 'true'); 70976 } 70977 self = addElement(elt, this); 70978 this.elt = elt; 70979 } 70980 self.option = function (name, value) { 70981 var index;
70981 // if no name is passed, return 70982 if (name === undefined) { 70983 return; 70984 } //see if there is already an option with this name 70985 70986 for (var i = 0; i < this.elt.length; i += 1) { 70987 if (this.elt[i].textContent === name) { 70988 index = i; 70989 break; 70990 } 70991 } //if there is an option with this name we will modify it 70992 70993 if (index !== undefined) { 70994 //if the user passed in false then delete that option 70995 if (value === false) { 70996 this.elt.remove(index); 70997 } else { 70998 // Update the option at index with the value 70999 this.elt[index].value = value; 71000 } 71001 } else { 71002 //if it doesn't exist create it 71003 var opt = document.createElement('option'); 71004 opt.textContent = name; 71005 opt.value = value === undefined ? name : value; 71006 this.elt.appendChild(opt); 71007 this._pInst._elements.push(opt); 71008 } 71009 }; 71010 self.selected = function (value) { 71011 // Update selected status of option 71012 if (value !== undefined) { 71013 for (var i = 0; i < this.elt.length; i += 1) { 71014 if (this.elt[i].value.toString() === value.toString()) { 71015 this.elt.selectedIndex = i; 71016 } 71017 } 71018 return this; 71019 } else { 71020 if (this.elt.getAttribute('multiple')) { 71021 var arr = [ 71022 ]; 71023 var _iteratorNormalCompletion = true; 71024 var _didIteratorError = false; 71025 var _iteratorError = undefined; 71026 try { 71027 for (var _iterator = this.elt.selectedOptions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 71028 var selectedOption = _step.value; 71029 arr.push(selectedOption.value); 71030 } 71031 } catch (err) { 71032 _didIteratorError = true; 71033 _iteratorError = err; 71034 } finally { 71035 try { 71036 if (!_iteratorNormalCompletion && _iterator.return != null) { 71037 _iterator.return(); 71038 } 71039 } finally { 71040 if (_didIteratorError) { 71041 throw _iteratorError; 71042 } 71043 } 71044 } 71045 return arr; 71046 } else { 71047 return this.elt.value; 71048 } 71049 } 71050 }; 71051 self.disable = function (value) { 71052 if (typeof value === 'string') { 71053 for (var i = 0; i < this.elt.length; i++) { 71054 if (this.elt[i].value.toString() === value) { 71055 this.elt[i].disabled = true; 71056 this.elt[i].selected = false; 71057 } 71058 } 71059 } else { 71060 this.elt.disabled = true; 71061 } 71062 return this; 71063 }; 71064 return self; 71065 }; 71066 /** 71067 * Creates a radio button element in the DOM. It also helps existing radio buttons 71068 * assign methods of <a href="#/p5.Element/">p5.Element</a>. 71069 * - `.option(value, [label])` can be used to create a new option for the 71070 * element. If an option with a value already exists, it will be returned. 71071 * It is recommended to use string values as input for `value`. 71072 * Optionally, a label can be provided as second argument for the option. 71073 * - `.remove(value)` can be used to remove an option for the element. String 71074 * values recommended as input for `value`. 71075 * - `.value()` method will return the currently selected value. 71076 * - `.selected()` method will return the currently selected input element. 71077 * - `.selected(value)` method will select the option and return it. String 71078 * values recommended as input for `value`. 71079 * - `.disable(Boolean)` method will enable/disable the whole radio button element. 71080 * 71081 * @method createRadio 71082 * @param {Object} containerElement A container HTML Element, either a div 71083 * or span, inside which all existing radio inputs will be considered as options. 71084 * @param {string} [name] A name parameter for each Input Element. 71085 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 71086 * @example 71087 * <div><code> 71088 * let radio; 71089 * 71090 * function setup() { 71091 * radio = createRadio(); 71092 * radio.option('black'); 71093 * radio.option('white'); 71094 * radio.option('gray'); 71095 * radio.style('width', '60px'); 71096 * textAlign(CENTER); 71097 * fill(255, 0, 0); 71098 * } 71099 * 71100 * function draw() {
71101 * let val = radio.value(); 71102 * background(val); 71103 * text(val, width / 2, height / 2); 71104 * } 71105 * </code></div> 71106 * <div><code> 71107 * let radio; 71108 * 71109 * function setup() { 71110 * radio = createRadio(); 71111 * radio.option('1', 'apple'); 71112 * radio.option('2', 'bread'); 71113 * radio.option('3', 'juice'); 71114 * radio.style('width', '30px'); 71115 * radio.selected('2'); 71116 * textAlign(CENTER); 71117 * } 71118 * 71119 * function draw() { 71120 * background(200); 71121 * let val = radio.value(); 71122 * if (val) { 71123 * text('item cost is $' + val, width / 2, height / 2); 71124 * } 71125 * } 71126 * </code></div> 71127 */ 71128 /** 71129 * @method createRadio 71130 * @param {String} name 71131 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 71132 */ 71133 /** 71134 * @method createRadio 71135 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 71136 */ 71137 _main.default.prototype.createRadio = function () { 71138 // Creates a div, adds each option as an individual input inside it. 71139 // If already given with a containerEl, will search for all input[radio] 71140 // it, create a p5.Element out of it, add options to it and return the p5.Element. 71141 var self; 71142 var radioElement; 71143 var name; 71144 var arg0 = arguments[0]; 71145 if (arg0 instanceof _main.default.Element && (arg0.elt instanceof HTMLDivElement || arg0.elt instanceof HTMLSpanElement)) { 71146 // If given argument is p5.Element of div/span type 71147 self = arg0; 71148 this.elt = arg0.elt; 71149 } else if ( // If existing radio Element is provided as argument 0 71150 arg0 instanceof HTMLDivElement || arg0 instanceof HTMLSpanElement) { 71151 self = addElement(arg0, this); 71152 this.elt = arg0; 71153 radioElement = arg0; 71154 if (typeof arguments[1] === 'string') name = arguments[1]; 71155 } else { 71156 if (typeof arg0 === 'string') name = arg0; 71157 radioElement = document.createElement('div'); 71158 self = addElement(radioElement, this); 71159 this.elt = radioElement; 71160 } 71161 self._name = name || 'radioOption'; // setup member functions 71162 var isRadioInput = function isRadioInput(el) { 71163 return el instanceof HTMLInputElement && el.type === 'radio'; 71164 }; 71165 var isLabelElement = function isLabelElement(el) { 71166 return el instanceof HTMLLabelElement; 71167 }; 71168 var isSpanElement = function isSpanElement(el) { 71169 return el instanceof HTMLSpanElement; 71170 }; 71171 self._getOptionsArray = function () { 71172 return Array.from(this.elt.children).filter(function (el) { 71173 return isRadioInput(el) || isLabelElement(el) && isRadioInput(el.firstElementChild); 71174 }).map(function (el) { 71175 return isRadioInput(el) ? el : el.firstElementChild; 71176 }); 71177 }; 71178 self.option = function (value, label) { 71179 // return an option with this value, create if not exists. 71180 var optionEl; 71181 var _iteratorNormalCompletion2 = true; 71182 var _didIteratorError2 = false;
71183 var _iteratorError2 = undefined; 71184 try { 71185 for (var _iterator2 = self._getOptionsArray() [Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 71186 var option = _step2.value; 71187 if (option.value === value) { 71188 optionEl = option; 71189 break; 71190 } 71191 } // Create a new option, add it to radioElement and return it. 71192 71193 } catch (err) { 71194 _didIteratorError2 = true; 71195 _iteratorError2 = err; 71196 } finally { 71197 try { 71198 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 71199 _iterator2.return(); 71200 } 71201 } finally { 71202 if (_didIteratorError2) { 71203 throw _iteratorError2; 71204 } 71205 } 71206 } 71207 if (optionEl === undefined) { 71208 optionEl = document.createElement('input'); 71209 optionEl.setAttribute('type', 'radio'); 71210 optionEl.setAttribute('value', value); 71211 } 71212 optionEl.setAttribute('name', self._name); // Check if label element exists, else create it 71213 var labelElement; 71214 if (!isLabelElement(optionEl.parentElement)) { 71215 labelElement = document.createElement('label'); 71216 labelElement.insertAdjacentElement('afterbegin', optionEl); 71217 } else { 71218 labelElement = optionEl.parentElement; 71219 } // Check if span element exists, else create it 71220 71221 var spanElement; 71222 if (!isSpanElement(labelElement.lastElementChild)) { 71223 spanElement = document.createElement('span'); 71224 optionEl.insertAdjacentElement('afterend', spanElement); 71225 } else { 71226 spanElement = labelElement.lastElementChild; 71227 } // Set the innerHTML of span element as the label text 71228 71229 spanElement.innerHTML = label === undefined ? value : label; // Append the label element, which includes option element and 71230 // span element to the radio container element 71231 this.elt.appendChild(labelElement); 71232 return optionEl; 71233 }; 71234 self.remove = function (value) { 71235 var _iteratorNormalCompletion3 = true; 71236 var _didIteratorError3 = false; 71237 var _iteratorError3 = undefined; 71238 try { 71239 for (var _iterator3 = self._getOptionsArray() [Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 71240 var optionEl = _step3.value; 71241 if (optionEl.value === value) { 71242 if (isLabelElement(optionEl.parentElement)) { 71243 // Remove parent label which also removes children elements 71244 optionEl.parentElement.remove(); 71245 } else { 71246 // Remove the option input if parent label does not exist 71247 optionEl.remove(); 71248 } 71249 return; 71250 } 71251 } 71252 } catch (err) { 71253 _didIteratorError3 = true; 71254 _iteratorError3 = err; 71255 } finally { 71256 try { 71257 if (!_iteratorNormalCompletion3 && _iterator3.return != null) { 71258 _iterator3.return(); 71259 } 71260 } finally { 71261 if (_didIteratorError3) { 71262 throw _iteratorError3; 71263 } 71264 } 71265 } 71266 }; 71267 self.value = function () { 71268 var result = ''; 71269 var _iteratorNormalCompletion4 = true; 71270 var _didIteratorError4 = false; 71271 var _iteratorError4 = undefined; 71272 try { 71273 for (var _iterator4 = self._getOptionsArray() [Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { 71274 var option = _step4.value; 71275 if (option.checked) { 71276 result = option.value; 71277 break; 71278 } 71279 } 71280 } catch (err) {
71281 _didIteratorError4 = true; 71282 _iteratorError4 = err; 71283 } finally { 71284 try { 71285 if (!_iteratorNormalCompletion4 && _iterator4.return != null) { 71286 _iterator4.return(); 71287 } 71288 } finally { 71289 if (_didIteratorError4) { 71290 throw _iteratorError4; 71291 } 71292 } 71293 } 71294 return result; 71295 }; 71296 self.selected = function (value) { 71297 var result = null; 71298 if (value === undefined) { 71299 var _iteratorNormalCompletion5 = true; 71300 var _didIteratorError5 = false; 71301 var _iteratorError5 = undefined; 71302 try { 71303 for (var _iterator5 = self._getOptionsArray() [Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { 71304 var option = _step5.value; 71305 if (option.checked) { 71306 result = option; 71307 break; 71308 } 71309 } 71310 } catch (err) { 71311 _didIteratorError5 = true; 71312 _iteratorError5 = err; 71313 } finally { 71314 try { 71315 if (!_iteratorNormalCompletion5 && _iterator5.return != null) { 71316 _iterator5.return(); 71317 } 71318 } finally { 71319 if (_didIteratorError5) { 71320 throw _iteratorError5; 71321 } 71322 } 71323 } 71324 } else { 71325 // forEach loop to uncheck all radio buttons before 71326 // setting any one as checked. 71327 self._getOptionsArray().forEach(function (option) { 71328 option.checked = false; 71329 option.removeAttribute('checked'); 71330 }); 71331 var _iteratorNormalCompletion6 = true; 71332 var _didIteratorError6 = false; 71333 var _iteratorError6 = undefined; 71334 try { 71335 for (var _iterator6 = self._getOptionsArray() [Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { 71336 var _option = _step6.value; 71337 if (_option.value === value) { 71338 _option.setAttribute('checked', true); 71339 _option.checked = true; 71340 result = _option; 71341 } 71342 } 71343 } catch (err) { 71344 _didIteratorError6 = true; 71345 _iteratorError6 = err; 71346 } finally { 71347 try { 71348 if (!_iteratorNormalCompletion6 && _iterator6.return != null) { 71349 _iterator6.return(); 71350 } 71351 } finally { 71352 if (_didIteratorError6) { 71353 throw _iteratorError6; 71354 } 71355 } 71356 } 71357 } 71358 return result; 71359 }; 71360 self.disable = function () { 71361 var shouldDisable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; 71362 var _iteratorNormalCompletion7 = true; 71363 var _didIteratorError7 = false; 71364 var _iteratorError7 = undefined; 71365 try { 71366 for (var _iterator7 = self._getOptionsArray() [Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { 71367 var radioInput = _step7.value; 71368 radioInput.setAttribute('disabled', shouldDisable); 71369 } 71370 } catch (err) { 71371 _didIteratorError7 = true; 71372 _iteratorError7 = err; 71373 } finally { 71374 try { 71375 if (!_iteratorNormalCompletion7 && _iterator7.return != null) { 71376 _iterator7.return(); 71377 } 71378 } finally { 71379 if (_didIteratorError7) { 71380 throw _iteratorError7; 71381 } 71382 } 71383 } 71384 }; 71385 return self; 71386 }; 71387 /** 71388 * Creates a colorPicker element in the DOM for color input. 71389 * The .value() method will return a hex string (#rrggbb) of the color. 71390 * The .color() method will return a <a href="#/p5.Color">p5.Color</a> 71391 * object with the current chosen color. 71392 * 71393 * @method createColorPicker 71394 * @param {String|p5.Color} [value] default color of element 71395 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 71396 * @example 71397 * <div><code> 71398 * let colorPicker; 71399 * function setup() { 71400 * createCanvas(100, 100); 71401 * colorPicker = createColorPicker('#ed225d'); 71402 * colorPicker.position(0, height + 5); 71403 * } 71404 * 71405 * function draw() { 71406 * background(colorPicker.color()); 71407 * } 71408 * </code></div> 71409 * <div><code> 71410 * let inp1, inp2; 71411 * function setup() { 71412 * createCanvas(100, 100); 71413 * background('grey'); 71414 * inp1 = createColorPicker('#ff0000'); 71415 * inp1.position(0, height + 5); 71416 * inp1.input(setShade1); 71417 * inp2 = createColorPicker(color('yellow')); 71418 * inp2.position(0, height + 30); 71419 * inp2.input(setShade2); 71420 * setMidShade(); 71421 * } 71422 * 71423 * function setMidShade() { 71424 * // Finding a shade between the two 71425 * let commonShade = lerpColor(inp1.color(), inp2.color(), 0.5); 71426 * fill(commonShade); 71427 * rect(20, 20, 60, 60); 71428 * } 71429 * 71430 * function setShade1() { 71431 * setMidShade();
71432 * console.log('You are choosing shade 1 to be : ', this.value()); 71433 * } 71434 * function setShade2() { 71435 * setMidShade(); 71436 * console.log('You are choosing shade 2 to be : ', this.value()); 71437 * } 71438 * </code></div> 71439 */ 71440 _main.default.prototype.createColorPicker = function (value) { 71441 _main.default._validateParameters('createColorPicker', arguments); 71442 var elt = document.createElement('input'); 71443 var self; 71444 elt.type = 'color'; 71445 if (value) { 71446 if (value instanceof _main.default.Color) { 71447 elt.value = value.toString('#rrggbb'); 71448 } else { 71449 _main.default.prototype._colorMode = 'rgb'; 71450 _main.default.prototype._colorMaxes = { 71451 rgb: [ 71452 255, 71453 255, 71454 255, 71455 255 71456 ], 71457 hsb: [ 71458 360, 71459 100, 71460 100, 71461 1 71462 ], 71463 hsl: [ 71464 360, 71465 100, 71466 100, 71467 1 71468 ] 71469 }; 71470 elt.value = _main.default.prototype.color(value).toString('#rrggbb'); 71471 } 71472 } else { 71473 elt.value = '#000000'; 71474 } 71475 self = addElement(elt, this); // Method to return a p5.Color object for the given color. 71476 self.color = function () { 71477 if (value) { 71478 if (value.mode) { 71479 _main.default.prototype._colorMode = value.mode; 71480 } 71481 if (value.maxes) { 71482 _main.default.prototype._colorMaxes = value.maxes; 71483 } 71484 } 71485 return _main.default.prototype.color(this.elt.value); 71486 }; 71487 return self; 71488 }; 71489 /** 71490 * Creates an `<input></input>` element in the DOM for text input. 71491 * Use .<a href="#/p5.Element/size">size()</a> to set the display length of the box. 71492 * 71493 * @method createInput 71494 * @param {String} value default value of the input box 71495 * @param {String} [type] type of text, ie text, password etc. Defaults to text. 71496 * Needs a value to be specified first. 71497 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 71498 * @example 71499 * <div><code> 71500 * function setup() { 71501 * createCanvas(100, 100); 71502 * background('grey'); 71503 * let inp = createInput(''); 71504 * inp.position(0, 0); 71505 * inp.size(100); 71506 * inp.input(myInputEvent); 71507 * } 71508 * 71509 * function myInputEvent() { 71510 * console.log('you are typing: ', this.value()); 71511 * } 71512 * </code></div> 71513 */ 71514 /** 71515 * @method createInput 71516 * @param {String} [value] 71517 * @return {p5.Element} 71518 */ 71519 _main.default.prototype.createInput = function () { 71520 var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; 71521 var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'text'; 71522 _main.default._validateParameters('createInput', arguments); 71523 var elt = document.createElement('input'); 71524 elt.setAttribute('value', value); 71525 elt.setAttribute('type', type); 71526 return addElement(elt, this); 71527 }; 71528 /** 71529 * Creates an `<input></input>` element in the DOM of type 'file'. 71530 * This allows users to select local files for use in a sketch. 71531 * 71532 * @method createFileInput 71533 * @param {Function} callback callback function for when a file is loaded 71534 * @param {Boolean} [multiple] optional, to allow multiple files to be selected 71535 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created DOM element 71536 * @example 71537 * <div><code> 71538 * let input; 71539 * let img; 71540 * 71541 * function setup() { 71542 * input = createFileInput(handleFile); 71543 * input.position(0, 0); 71544 * } 71545 * 71546 * function draw() { 71547 * background(255); 71548 * if (img) { 71549 * image(img, 0, 0, width, height); 71550 * } 71551 * } 71552 * 71553 * function handleFile(file) { 71554 * print(file); 71555 * if (file.type === 'image') { 71556 * img = createImg(file.data, ''); 71557 * img.hide(); 71558 * } else { 71559 * img = null; 71560 * } 71561 * } 71562 * </code></div> 71563 */ 71564 _main.default.prototype.createFileInput = function (callback) { 71565 var multiple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
71566 _main.default._validateParameters('createFileInput', arguments); 71567 var handleFileSelect = function handleFileSelect(event) { 71568 var _iteratorNormalCompletion8 = true; 71569 var _didIteratorError8 = false; 71570 var _iteratorError8 = undefined; 71571 try { 71572 for (var _iterator8 = event.target.files[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { 71573 var file = _step8.value; 71574 _main.default.File._load(file, callback); 71575 } 71576 } catch (err) { 71577 _didIteratorError8 = true; 71578 _iteratorError8 = err; 71579 } finally { 71580 try { 71581 if (!_iteratorNormalCompletion8 && _iterator8.return != null) { 71582 _iterator8.return(); 71583 } 71584 } finally { 71585 if (_didIteratorError8) { 71586 throw _iteratorError8; 71587 } 71588 } 71589 } 71590 }; // If File API's are not supported, throw Error 71591 if (!(window.File && window.FileReader && window.FileList && window.Blob)) { 71592 console.log('The File APIs are not fully supported in this browser. Cannot create element.'); 71593 return; 71594 } 71595 var fileInput = document.createElement('input'); 71596 fileInput.setAttribute('type', 'file'); 71597 if (multiple) fileInput.setAttribute('multiple', true); 71598 fileInput.addEventListener('change', handleFileSelect, false); 71599 return addElement(fileInput, this); 71600 }; 71601 /** VIDEO STUFF **/ 71602 // Helps perform similar tasks for media element methods. 71603 function createMedia(pInst, type, src, callback) { 71604 var elt = document.createElement(type); // Create source elements from given sources 71605 src = src || ''; 71606 if (typeof src === 'string') { 71607 src = [ 71608 src 71609 ]; 71610 } 71611 var _iteratorNormalCompletion9 = true; 71612 var _didIteratorError9 = false; 71613 var _iteratorError9 = undefined; 71614 try { 71615 for (var _iterator9 = src[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { 71616 var mediaSource = _step9.value; 71617 var sourceEl = document.createElement('source'); 71618 sourceEl.setAttribute('src', mediaSource); 71619 elt.appendChild(sourceEl); 71620 } // If callback is provided, attach to element 71621 71622 } catch (err) { 71623 _didIteratorError9 = true; 71624 _iteratorError9 = err; 71625 } finally { 71626 try { 71627 if (!_iteratorNormalCompletion9 && _iterator9.return != null) { 71628 _iterator9.return(); 71629 } 71630 } finally { 71631 if (_didIteratorError9) { 71632 throw _iteratorError9; 71633 } 71634 } 71635 } 71636 if (typeof callback === 'function') { 71637 var callbackHandler = function callbackHandler() { 71638 callback(); 71639 elt.removeEventListener('canplaythrough', callbackHandler); 71640 }; 71641 elt.addEventListener('canplaythrough', callbackHandler); 71642 } 71643 var mediaEl = addElement(elt, pInst, true); 71644 mediaEl.loadedmetadata = false; // set width and height onload metadata 71645 elt.addEventListener('loadedmetadata', function () { 71646 mediaEl.width = elt.videoWidth; 71647 mediaEl.height = elt.videoHeight; // set elt width and height if not set 71648 if (mediaEl.elt.width === 0) mediaEl.elt.width = elt.videoWidth; 71649 if (mediaEl.elt.height === 0) mediaEl.elt.height = elt.videoHeight; 71650 if (mediaEl.presetPlaybackRate) { 71651 mediaEl.elt.playbackRate = mediaEl.presetPlaybackRate; 71652 delete mediaEl.presetPlaybackRate; 71653 } 71654 mediaEl.loadedmetadata = true; 71655 }); 71656 return mediaEl; 71657 } /** 71658 * Creates an HTML5 `<video>` element in the DOM for simple playback 71659 * of audio/video. Shown by default, can be hidden with .<a href="#/p5.Element/hide">hide()</a> 71660 * and drawn into canvas using <a href="#/p5/image">image()</a>. The first parameter
71661 * can be either a single string path to a video file, or an array of string 71662 * paths to different formats of the same video. This is useful for ensuring 71663 * that your video can play across different browsers, as each supports 71664 * different formats. See <a href='https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats'>this 71665 * page</a> for further information about supported formats. 71666 * 71667 * @method createVideo 71668 * @param {String|String[]} src path to a video file, or array of paths for 71669 * supporting different browsers 71670 * @param {Function} [callback] callback function to be called upon 71671 * 'canplaythrough' event fire, that is, when the 71672 * browser can play the media, and estimates that 71673 * enough data has been loaded to play the media 71674 * up to its end without having to stop for 71675 * further buffering of content 71676 * @return {p5.MediaElement} pointer to video <a href="#/p5.MediaElement">p5.MediaElement</a> 71677 * @example 71678 * <div><code> 71679 * let vid; 71680 * function setup() { 71681 * noCanvas(); 71682 * 71683 * vid = createVideo( 71684 * ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm'], 71685 * vidLoad 71686 * ); 71687 * 71688 * vid.size(100, 100); 71689 * } 71690 * 71691 * // This function is called when the video loads 71692 * function vidLoad() { 71693 * vid.loop(); 71694 * vid.volume(0); 71695 * } 71696 * </code></div> 71697 */ 71698 71699 _main.default.prototype.createVideo = function (src, callback) { 71700 _main.default._validateParameters('createVideo', arguments); 71701 return createMedia(this, 'video', src, callback); 71702 }; 71703 /** AUDIO STUFF **/ 71704 /** 71705 * Creates a hidden HTML5 `<audio>` element in the DOM for simple audio 71706 * playback. The first parameter can be either a single string path to a 71707 * audio file, or an array of string paths to different formats of the same 71708 * audio. This is useful for ensuring that your audio can play across 71709 * different browsers, as each supports different formats. 71710 * See <a href='https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats'>this 71711 * page for further information about supported formats</a>. 71712 * 71713 * @method createAudio 71714 * @param {String|String[]} [src] path to an audio file, or array of paths 71715 * for supporting different browsers 71716 * @param {Function} [callback] callback function to be called upon 71717 * 'canplaythrough' event fire, that is, when the 71718 * browser can play the media, and estimates that 71719 * enough data has been loaded to play the media 71720 * up to its end without having to stop for 71721 * further buffering of content 71722 * @return {p5.MediaElement} pointer to audio <a href="#/p5.MediaElement">p5.MediaElement</a> 71723 * @example 71724 * <div><code> 71725 * let ele; 71726 * function setup() { 71727 * ele = createAudio('assets/beat.mp3'); 71728 * 71729 * // here we set the element to autoplay 71730 * // The element will play as soon 71731 * // as it is able to do so. 71732 * ele.autoplay(true); 71733 * } 71734 * </code></div> 71735 */ 71736 _main.default.prototype.createAudio = function (src, callback) { 71737 _main.default._validateParameters('createAudio', arguments); 71738 return createMedia(this, 'audio', src, callback); 71739 }; 71740 /** CAMERA STUFF **/ 71741 _main.default.prototype.VIDEO = 'video'; 71742 _main.default.prototype.AUDIO = 'audio'; // from: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia 71743 // Older browsers might not implement mediaDevices at all, so we set an empty object first 71744 if (navigator.mediaDevices === undefined) { 71745 navigator.mediaDevices = { 71746 }; 71747 } // Some browsers partially implement mediaDevices. We can't just assign an object 71748 // with getUserMedia as it would overwrite existing properties. 71749 // Here, we will just add the getUserMedia property if it's missing. 71750 71751 if (navigator.mediaDevices.getUserMedia === undefined) { 71752 navigator.mediaDevices.getUserMedia = function (constraints) { 71753 // First get ahold of the legacy getUserMedia, if present 71754 var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia; // Some browsers just don't implement it - return a rejected promise with an error 71755 // to keep a consistent interface 71756 if (!getUserMedia) { 71757 return Promise.reject(new Error('getUserMedia is not implemented in this browser')); 71758 } // Otherwise, wrap the call to the old navigator.getUserMedia with a Promise 71759 71760 return new Promise(function (resolve, reject) { 71761 getUserMedia.call(navigator, constraints, resolve, reject); 71762 }); 71763 }; 71764 } /** 71765 * Creates a new HTML5 `<video>` element that contains the audio/video feed 71766 * from a webcam. The element is separate from the canvas and is displayed by 71767 * default. The element can be hidden using .<a href="#/p5.Element/hide">hide()</a>. 71768 * The feed can be drawn onto the canvas using <a href="#/p5/image">image()</a>. 71769 * The loadedmetadata property can be used to detect when the element has fully 71770 * loaded (see second example). 71771 * 71772 * More specific properties of the feed can be passing in a Constraints object. 71773 * See the <a href='http://w3c.github.io/mediacapture-main/getusermedia.html#media-track-constraints'> 71774 * W3C spec</a> for possible properties. Note that not all of these are supported 71775 * by all browsers. 71776 * 71777 * <em>Security note</em>: A new browser security specification requires that 71778 * getUserMedia, which is behind <a href="#/p5/createCapture">createCapture()</a>, 71779 * only works when you're running the code locally, or on HTTPS. Learn more 71780 * <a href='http://stackoverflow.com/questions/34197653/getusermedia-in-chrome-47-without-using-https'>here</a> 71781 * and <a href='https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia'>here</a>. 71782 * 71783 * @method createCapture 71784 * @param {String|Constant|Object} type type of capture, either VIDEO or 71785 * AUDIO if none specified, default both, 71786 * or a Constraints object 71787 * @param {Function} [callback] function to be called once 71788 * stream has loaded 71789 * @return {p5.Element} capture video <a href="#/p5.Element">p5.Element</a> 71790 * @example 71791 * <div class='notest'> 71792 * <code> 71793 * let capture; 71794 * 71795 * function setup() { 71796 * createCanvas(100, 100); 71797 * capture = createCapture(VIDEO); 71798 * capture.hide(); 71799 * } 71800 * 71801 * function draw() { 71802 * image(capture, 0, 0, width, width * capture.height / capture.width); 71803 * filter(INVERT); 71804 * } 71805 * </code> 71806 * </div> 71807 * 71808 * <div class='notest norender'> 71809 * <code> 71810 * function setup() { 71811 * createCanvas(480, 120); 71812 * let constraints = { 71813 * video: { 71814 * mandatory: { 71815 * minWidth: 1280, 71816 * minHeight: 720 71817 * }, 71818 * optional: [{ maxFrameRate: 10 }] 71819 * }, 71820 * audio: true 71821 * }; 71822 * createCapture(constraints, function(stream) { 71823 * console.log(stream); 71824 * }); 71825 * } 71826 * </code> 71827 * </div> 71828 * <div class='notest norender'> 71829 * <code> 71830 * let capture; 71831 * 71832 * function setup() { 71833 * createCanvas(640, 480); 71834 * capture = createCapture(VIDEO); 71835 * } 71836 * function draw() { 71837 * background(0); 71838 * if (capture.loadedmetadata) { 71839 * let c = capture.get(0, 0, 100, 100); 71840 * image(c, 0, 0); 71841 * } 71842 * } 71843 * </code> 71844 * </div> 71845 */ 71846 71847 _main.default.prototype.createCapture = function () { 71848 _main.default._validateParameters('createCapture', arguments); // return if getUserMedia is not supported by browser 71849 if (!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)) { 71850 throw new DOMException('getUserMedia not supported in this browser'); 71851 } 71852 var useVideo = true; 71853 var useAudio = true; 71854 var constraints; 71855 var callback; 71856 var _iteratorNormalCompletion10 = true; 71857 var _didIteratorError10 = false;
71858 var _iteratorError10 = undefined; 71859 try { 71860 for (var _iterator10 = arguments[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { 71861 var arg = _step10.value; 71862 if (arg === _main.default.prototype.VIDEO) useAudio = false; 71863 else if (arg === _main.default.prototype.AUDIO) useVideo = false; 71864 else if (_typeof(arg) === 'object') constraints = arg; 71865 else if (typeof arg === 'function') callback = arg; 71866 } 71867 } catch (err) { 71868 _didIteratorError10 = true; 71869 _iteratorError10 = err; 71870 } finally { 71871 try { 71872 if (!_iteratorNormalCompletion10 && _iterator10.return != null) { 71873 _iterator10.return(); 71874 } 71875 } finally { 71876 if (_didIteratorError10) { 71877 throw _iteratorError10; 71878 } 71879 } 71880 } 71881 if (!constraints) constraints = { 71882 video: useVideo, 71883 audio: useAudio 71884 }; 71885 var domElement = document.createElement('video'); // required to work in iOS 11 & up: 71886 domElement.setAttribute('playsinline', ''); 71887 navigator.mediaDevices.getUserMedia(constraints).then(function (stream) { 71888 try { 71889 if ('srcObject' in domElement) { 71890 domElement.srcObject = stream; 71891 } else { 71892 domElement.src = window.URL.createObjectURL(stream); 71893 } 71894 } catch (err) { 71895 domElement.src = stream; 71896 } 71897 }, console.log); 71898 var videoEl = addElement(domElement, this, true); 71899 videoEl.loadedmetadata = false; // set width and height onload metadata 71900 domElement.addEventListener('loadedmetadata', function () { 71901 domElement.play(); 71902 if (domElement.width) { 71903 videoEl.width = domElement.width; 71904 videoEl.height = domElement.height; 71905 } else { 71906 videoEl.width = videoEl.elt.width = domElement.videoWidth; 71907 videoEl.height = videoEl.elt.height = domElement.videoHeight; 71908 } 71909 videoEl.loadedmetadata = true; 71910 if (callback) callback(domElement.srcObject); 71911 }); 71912 return videoEl; 71913 }; 71914 /** 71915 * Creates element with given tag in the DOM with given content. 71916 * 71917 * @method createElement 71918 * @param {String} tag tag for the new element 71919 * @param {String} [content] html content to be inserted into the element 71920 * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node 71921 * @example 71922 * <div><code> 71923 * let h5 = createElement('h5', 'im an h5 p5.element!'); 71924 * h5.style('color', '#00a1d3'); 71925 * h5.position(0, 0); 71926 * </code></div> 71927 */ 71928 _main.default.prototype.createElement = function (tag, content) { 71929 _main.default._validateParameters('createElement', arguments); 71930 var elt = document.createElement(tag); 71931 if (typeof content !== 'undefined') { 71932 elt.innerHTML = content; 71933 } 71934 return addElement(elt, this); 71935 }; // ============================================================================= 71936 // p5.Element additions 71937 // ============================================================================= 71938 /** 71939 * 71940 * Adds specified class to the element. 71941 * 71942 * @for p5.Element 71943 * @method addClass 71944 * @param {String} class name of class to add 71945 * @chainable 71946 * @example 71947 * <div class='norender'><code> 71948 * let div = createDiv('div'); 71949 * div.addClass('myClass'); 71950 * </code></div> 71951 */ 71952 _main.default.Element.prototype.addClass = function (c) { 71953 if (this.elt.className) { 71954 if (!this.hasClass(c)) { 71955 this.elt.className = this.elt.className + ' ' + c; 71956 } 71957 } else { 71958 this.elt.className = c; 71959 } 71960 return this; 71961 }; 71962 /** 71963 * 71964 * Removes specified class from the element. 71965 * 71966 * @method removeClass 71967 * @param {String} class name of class to remove 71968 * @chainable 71969 * @example 71970 * <div class='norender'><code> 71971 * // In this example, a class is set when the div is created 71972 * // and removed when mouse is pressed. This could link up 71973 * // with a CSS style rule to toggle style properties. 71974 * 71975 * let div; 71976 * 71977 * function setup() { 71978 * div = createDiv('div'); 71979 * div.addClass('myClass'); 71980 * } 71981 * 71982 * function mousePressed() { 71983 * div.removeClass('myClass'); 71984 * } 71985 * </code></div> 71986 */ 71987 _main.default.Element.prototype.removeClass = function (c) { 71988 // Note: Removing a class that does not exist does NOT throw an error in classList.remove method 71989 this.elt.classList.remove(c); 71990 return this; 71991 }; 71992 /** 71993 * 71994 * Checks if specified class is already applied to element. 71995 * 71996 * @method hasClass 71997 * @returns {boolean} a boolean value if element has specified class 71998 * @param c {String} class name of class to check 71999 * @example 72000 * <div class='norender'><code> 72001 * let div; 72002 * 72003 * function setup() { 72004 * div = createDiv('div'); 72005 * div.addClass('show'); 72006 * } 72007 * 72008 * function mousePressed() { 72009 * if (div.hasClass('show')) { 72010 * div.addClass('show'); 72011 * } else { 72012 * div.removeClass('show'); 72013 * } 72014 * } 72015 * </code></div> 72016 */ 72017 _main.default.Element.prototype.hasClass = function (c) { 72018 return this.elt.classList.contains(c); 72019 }; 72020 /** 72021 * 72022 * Toggles element class. 72023 * 72024 * @method toggleClass 72025 * @param c {String} class name to toggle 72026 * @chainable 72027 * @example 72028 * <div class='norender'><code> 72029 * let div; 72030 * 72031 * function setup() { 72032 * div = createDiv('div'); 72033 * div.addClass('show'); 72034 * } 72035 * 72036 * function mousePressed() { 72037 * div.toggleClass('show'); 72038 * } 72039 * </code></div> 72040 */ 72041 _main.default.Element.prototype.toggleClass = function (c) {
72042 // classList also has a toggle() method, but we cannot use that yet as support is unclear. 72043 // See https://github.com/processing/p5.js/issues/3631 72044 // this.elt.classList.toggle(c); 72045 if (this.elt.classList.contains(c)) { 72046 this.elt.classList.remove(c); 72047 } else { 72048 this.elt.classList.add(c); 72049 } 72050 return this; 72051 }; 72052 /** 72053 * 72054 * Attaches the element as a child to the parent specified. 72055 * Accepts either a string ID, DOM node, or <a href="#/p5.Element">p5.Element</a>. 72056 * If no argument is specified, an array of children DOM nodes is returned. 72057 * 72058 * @method child 72059 * @returns {Node[]} an array of child nodes 72060 * @example 72061 * <div class='norender'><code> 72062 * let div0 = createDiv('this is the parent'); 72063 * let div1 = createDiv('this is the child'); 72064 * div0.child(div1); // use p5.Element 72065 * </code></div> 72066 * <div class='norender'><code> 72067 * let div0 = createDiv('this is the parent'); 72068 * let div1 = createDiv('this is the child'); 72069 * div1.id('apples'); 72070 * div0.child('apples'); // use id 72071 * </code></div> 72072 * <div class='norender notest'><code> 72073 * // this example assumes there is a div already on the page 72074 * // with id "myChildDiv" 72075 * let div0 = createDiv('this is the parent'); 72076 * let elt = document.getElementById('myChildDiv'); 72077 * div0.child(elt); // use element from page 72078 * </code></div> 72079 */ 72080 /** 72081 * @method child 72082 * @param {String|p5.Element} [child] the ID, DOM node, or <a href="#/p5.Element">p5.Element</a> 72083 * to add to the current element 72084 * @chainable 72085 */ 72086 _main.default.Element.prototype.child = function (childNode) { 72087 if (typeof childNode === 'undefined') { 72088 return this.elt.childNodes; 72089 } 72090 if (typeof childNode === 'string') { 72091 if (childNode[0] === '#') { 72092 childNode = childNode.substring(1); 72093 } 72094 childNode = document.getElementById(childNode); 72095 } else if (childNode instanceof _main.default.Element) { 72096 childNode = childNode.elt; 72097 } 72098 if (childNode instanceof HTMLElement) { 72099 this.elt.appendChild(childNode); 72100 } 72101 return this; 72102 }; 72103 /** 72104 * Centers a p5.Element either vertically, horizontally, 72105 * or both, relative to its parent or according to 72106 * the body if the p5.Element has no parent. If no argument is passed 72107 * the p5.Element is aligned both vertically and horizontally. 72108 * 72109 * @method center 72110 * @param {String} [align] passing 'vertical', 'horizontal' aligns element accordingly 72111 * @chainable 72112 * 72113 * @example 72114 * <div><code> 72115 * function setup() { 72116 * let div = createDiv('').size(10, 10); 72117 * div.style('background-color', 'orange'); 72118 * div.center(); 72119 * } 72120 * </code></div> 72121 */ 72122 _main.default.Element.prototype.center = function (align) { 72123 var style = this.elt.style.display; 72124 var hidden = this.elt.style.display === 'none'; 72125 var parentHidden = this.parent().style.display === 'none'; 72126 var pos = { 72127 x: this.elt.offsetLeft, 72128 y: this.elt.offsetTop 72129 }; 72130 if (hidden) this.show(); 72131 if (parentHidden) this.parent().show(); 72132 this.elt.style.display = 'block'; 72133 this.position(0, 0); 72134 var wOffset = Math.abs(this.parent().offsetWidth - this.elt.offsetWidth); 72135 var hOffset = Math.abs(this.parent().offsetHeight - this.elt.offsetHeight); 72136 if (align === 'both' || align === undefined) { 72137 this.position(wOffset / 2 + this.parent().offsetLeft, hOffset / 2 + this.parent().offsetTop); 72138 } else if (align === 'horizontal') { 72139 this.position(wOffset / 2 + this.parent().offsetLeft, pos.y); 72140 } else if (align === 'vertical') { 72141 this.position(pos.x, hOffset / 2 + this.parent().offsetTop); 72142 } 72143 this.style('display', style); 72144 if (hidden) this.hide(); 72145 if (parentHidden) this.parent().hide(); 72146 return this; 72147 }; 72148 /** 72149 * 72150 * If an argument is given, sets the inner HTML of the element, 72151 * replacing any existing HTML. If true is included as a second 72152 * argument, HTML is appended instead of replacing existing HTML. 72153 * If no arguments are given, returns 72154 * the inner HTML of the element. 72155 * 72156 * @for p5.Element 72157 * @method html 72158 * @returns {String} the inner HTML of the element 72159 * @example 72160 * <div class='norender'><code> 72161 * let div = createDiv('').size(100, 100); 72162 * div.html('hi'); 72163 * </code></div> 72164 * <div class='norender'><code> 72165 * let div = createDiv('Hello ').size(100, 100); 72166 * div.html('World', true); 72167 * </code></div> 72168 */ 72169 /** 72170 * @method html 72171 * @param {String} [html] the HTML to be placed inside the element 72172 * @param {boolean} [append] whether to append HTML to existing 72173 * @chainable 72174 */ 72175 _main.default.Element.prototype.html = function () { 72176 if (arguments.length === 0) { 72177 return this.elt.innerHTML; 72178 } else if (arguments[1]) { 72179 this.elt.insertAdjacentHTML('beforeend', arguments[0]); 72180 return this; 72181 } else { 72182 this.elt.innerHTML = arguments[0]; 72183 return this; 72184 } 72185 }; 72186 /** 72187 * 72188 * Sets the position of the element. If no position type argument is given, the 72189 * position will be relative to (0, 0) of the window. 72190 * Essentially, this sets position:absolute and left and top 72191 * properties of style. If an optional third argument specifying position type is given, 72192 * the x and y-coordinates will be interpreted based on the <a target="_blank" 72193 * href="https://developer.mozilla.org/en-US/docs/Web/CSS/position">positioning scheme</a>. 72194 * If no arguments given, the function returns the x and y position of the element. 72195 *
72196 * found documentation on how to be more specific with object type 72197 * https://stackoverflow.com/questions/14714314/how-do-i-comment-object-literals-in-yuidoc 72198 * 72199 * @method position 72200 * @returns {Object} object of form { x: 0, y: 0 } containing the position of the element in an object 72201 * @example 72202 * <div><code class='norender'> 72203 * function setup() { 72204 * let cnv = createCanvas(100, 100); 72205 * // positions canvas 50px to the right and 100px 72206 * // below upper left corner of the window 72207 * cnv.position(50, 100); 72208 * } 72209 * </code></div> 72210 * <div><code class='norender'> 72211 * function setup() { 72212 * let cnv = createCanvas(100, 100); 72213 * // positions canvas at upper left corner of the window 72214 * // with a 'fixed' position type 72215 * cnv.position(0, 0, 'fixed'); 72216 * } 72217 * </code></div> 72218 */ 72219 /** 72220 * @method position 72221 * @param {Number} [x] x-position relative to upper left of window (optional) 72222 * @param {Number} [y] y-position relative to upper left of window (optional) 72223 * @param {String} [positionType] it can be static, fixed, relative, sticky, initial or inherit (optional) 72224 * @chainable 72225 */ 72226 _main.default.Element.prototype.position = function () { 72227 if (arguments.length === 0) { 72228 return { 72229 x: this.elt.offsetLeft, 72230 y: this.elt.offsetTop 72231 }; 72232 } else { 72233 var positionType = 'absolute'; 72234 if (arguments[2] === 'static' || arguments[2] === 'fixed' || arguments[2] === 'relative' || arguments[2] === 'sticky' || arguments[2] === 'initial' || arguments[2] === 'inherit') { 72235 positionType = arguments[2]; 72236 } 72237 this.elt.style.position = positionType; 72238 this.elt.style.left = arguments[0] + 'px'; 72239 this.elt.style.top = arguments[1] + 'px'; 72240 this.x = arguments[0]; 72241 this.y = arguments[1]; 72242 return this; 72243 } 72244 }; 72245 /* Helper method called by p5.Element.style() */ 72246 _main.default.Element.prototype._translate = function () { 72247 this.elt.style.position = 'absolute'; // save out initial non-translate transform styling 72248 var transform = ''; 72249 if (this.elt.style.transform) { 72250 transform = this.elt.style.transform.replace(/translate3d\(.*\)/g, ''); 72251 transform = transform.replace(/translate[X-Z]?\(.*\)/g, ''); 72252 } 72253 if (arguments.length === 2) { 72254 this.elt.style.transform = 'translate(' + arguments[0] + 'px, ' + arguments[1] + 'px)'; 72255 } else if (arguments.length > 2) { 72256 this.elt.style.transform = 'translate3d(' + arguments[0] + 'px,' + arguments[1] + 'px,' + arguments[2] + 'px)'; 72257 if (arguments.length === 3) { 72258 this.elt.parentElement.style.perspective = '1000px'; 72259 } else { 72260 this.elt.parentElement.style.perspective = arguments[3] + 'px'; 72261 } 72262 } // add any extra transform styling back on end 72263 72264 this.elt.style.transform += transform; 72265 return this; 72266 }; 72267 /* Helper method called by p5.Element.style() */ 72268 _main.default.Element.prototype._rotate = function () { 72269 // save out initial non-rotate transform styling 72270 var transform = ''; 72271 if (this.elt.style.transform) { 72272 transform = this.elt.style.transform.replace(/rotate3d\(.*\)/g, ''); 72273 transform = transform.replace(/rotate[X-Z]?\(.*\)/g, ''); 72274 } 72275 if (arguments.length === 1) { 72276 this.elt.style.transform = 'rotate(' + arguments[0] + 'deg)'; 72277 } else if (arguments.length === 2) { 72278 this.elt.style.transform = 'rotate(' + arguments[0] + 'deg, ' + arguments[1] + 'deg)'; 72279 } else if (arguments.length === 3) { 72280 this.elt.style.transform = 'rotateX(' + arguments[0] + 'deg)'; 72281 this.elt.style.transform += 'rotateY(' + arguments[1] + 'deg)'; 72282 this.elt.style.transform += 'rotateZ(' + arguments[2] + 'deg)'; 72283 } // add remaining transform back on 72284 72285 this.elt.style.transform += transform; 72286 return this; 72287 }; 72288 /** 72289 * Sets the given style (CSS) property (1st arg) of the element with the 72290 * given value (2nd arg). If a single argument is given, .style() 72291 * returns the value of the given property; however, if a single argument 72292 * is given in CSS syntax ('text-align:center'), .style() sets the CSS 72293 * appropriately. 72294 * 72295 * @method style 72296 * @param {String} property property to be set 72297 * @returns {String} value of property 72298 * @example 72299 * <div><code class='norender'> 72300 * let myDiv = createDiv('I like pandas.'); 72301 * myDiv.style('font-size', '18px'); 72302 * myDiv.style('color', '#ff0000'); 72303 * myDiv.position(0, 0); 72304 * </code></div> 72305 * <div><code class='norender'> 72306 * let col = color(25, 23, 200, 50); 72307 * let button = createButton('button'); 72308 * button.style('background-color', col); 72309 * button.position(0, 0); 72310 * </code></div> 72311 * <div><code class='norender'> 72312 * let myDiv, fontSize; 72313 * function setup() { 72314 * background(200); 72315 * myDiv = createDiv('I like gray.'); 72316 * myDiv.position(0, 0); 72317 * myDiv.style('z-index', 10); 72318 * } 72319 * 72320 * function draw() { 72321 * fontSize = min(mouseX, 90); 72322 * myDiv.style('font-size', fontSize + 'px'); 72323 * } 72324 * </code></div> 72325 */ 72326 /** 72327 * @method style 72328 * @param {String} property 72329 * @param {String|p5.Color} value value to assign to property 72330 * @return {String} current value of property, if no value is given as second argument 72331 * @chainable 72332 */ 72333 _main.default.Element.prototype.style = function (prop, val) { 72334 var self = this; 72335 if (val instanceof _main.default.Color) { 72336 val = 'rgba(' + val.levels[0] + ',' + val.levels[1] + ',' + val.levels[2] + ',' + val.levels[3] / 255 + ')'; 72337 } 72338 if (typeof val === 'undefined') { 72339 if (prop.indexOf(':') === - 1) { 72340 // no value set, so assume requesting a value 72341 var styles = window.getComputedStyle(self.elt); 72342 var style = styles.getPropertyValue(prop); 72343 return style; 72344 } else { 72345 // value set using `:` in a single line string 72346 var attrs = prop.split(';'); 72347 for (var i = 0; i < attrs.length; i++) { 72348 var parts = attrs[i].split(':'); 72349 if (parts[0] && parts[1]) { 72350 this.elt.style[parts[0].trim()] = parts[1].trim(); 72351 } 72352 } 72353 } 72354 } else { 72355 // input provided as key,val pair 72356 this.elt.style[prop] = val; 72357 if (prop === 'width' || prop === 'height' || prop === 'left' || prop === 'top') { 72358 var _styles = window.getComputedStyle(self.elt); 72359 var styleVal = _styles.getPropertyValue(prop); 72360 var numVal = styleVal.replace(/[^\d.]/g, ''); 72361 this[prop] = Math.round(parseFloat(numVal, 10)); 72362 } 72363 } 72364 return this; 72365 }; 72366 /** 72367 *
72368 * Adds a new attribute or changes the value of an existing attribute 72369 * on the specified element. If no value is specified, returns the 72370 * value of the given attribute, or null if the attribute is not set. 72371 * 72372 * @method attribute 72373 * @return {String} value of attribute 72374 * 72375 * @example 72376 * <div class='norender'><code> 72377 * let myDiv = createDiv('I like pandas.'); 72378 * myDiv.attribute('align', 'center'); 72379 * </code></div> 72380 */ 72381 /** 72382 * @method attribute 72383 * @param {String} attr attribute to set 72384 * @param {String} value value to assign to attribute 72385 * @chainable 72386 */ 72387 _main.default.Element.prototype.attribute = function (attr, value) { 72388 //handling for checkboxes and radios to ensure options get 72389 //attributes not divs 72390 if (this.elt.firstChild != null && (this.elt.firstChild.type === 'checkbox' || this.elt.firstChild.type === 'radio')) { 72391 if (typeof value === 'undefined') { 72392 return this.elt.firstChild.getAttribute(attr); 72393 } else { 72394 for (var i = 0; i < this.elt.childNodes.length; i++) { 72395 this.elt.childNodes[i].setAttribute(attr, value); 72396 } 72397 } 72398 } else if (typeof value === 'undefined') { 72399 return this.elt.getAttribute(attr); 72400 } else { 72401 this.elt.setAttribute(attr, value); 72402 return this; 72403 } 72404 }; 72405 /** 72406 * 72407 * Removes an attribute on the specified element. 72408 * 72409 * @method removeAttribute 72410 * @param {String} attr attribute to remove 72411 * @chainable 72412 * 72413 * @example 72414 * <div><code> 72415 * let button; 72416 * let checkbox; 72417 * 72418 * function setup() { 72419 * checkbox = createCheckbox('enable', true); 72420 * checkbox.changed(enableButton); 72421 * button = createButton('button'); 72422 * button.position(10, 10); 72423 * } 72424 * 72425 * function enableButton() { 72426 * if (this.checked()) { 72427 * // Re-enable the button 72428 * button.removeAttribute('disabled'); 72429 * } else { 72430 * // Disable the button 72431 * button.attribute('disabled', ''); 72432 * } 72433 * } 72434 * </code></div> 72435 */ 72436 _main.default.Element.prototype.removeAttribute = function (attr) { 72437 if (this.elt.firstChild != null && (this.elt.firstChild.type === 'checkbox' || this.elt.firstChild.type === 'radio')) { 72438 for (var i = 0; i < this.elt.childNodes.length; i++) { 72439 this.elt.childNodes[i].removeAttribute(attr); 72440 } 72441 } 72442 this.elt.removeAttribute(attr); 72443 return this; 72444 }; 72445 /** 72446 * Either returns the value of the element if no arguments 72447 * given, or sets the value of the element. 72448 * 72449 * @method value 72450 * @return {String|Number} value of the element 72451 * @example 72452 * <div class='norender'><code> 72453 * // gets the value 72454 * let inp; 72455 * function setup() { 72456 * inp = createInput(''); 72457 * } 72458 * 72459 * function mousePressed() { 72460 * print(inp.value()); 72461 * } 72462 * </code></div> 72463 * <div class='norender'><code> 72464 * // sets the value 72465 * let inp; 72466 * function setup() { 72467 * inp = createInput('myValue'); 72468 * } 72469 * 72470 * function mousePressed() { 72471 * inp.value('myValue'); 72472 * } 72473 * </code></div> 72474 */ 72475 /** 72476 * @method value 72477 * @param {String|Number} value 72478 * @chainable 72479 */ 72480 _main.default.Element.prototype.value = function () { 72481 if (arguments.length > 0) { 72482 this.elt.value = arguments[0]; 72483 return this; 72484 } else { 72485 if (this.elt.type === 'range') { 72486 return parseFloat(this.elt.value); 72487 } else return this.elt.value; 72488 } 72489 }; 72490 /** 72491 * 72492 * Shows the current element. Essentially, setting display:block for the style. 72493 * 72494 * @method show 72495 * @chainable 72496 * @example 72497 * <div class='norender'><code> 72498 * let div = createDiv('div'); 72499 * div.style('display', 'none'); 72500 * div.show(); // turns display to block 72501 * </code></div> 72502 */ 72503 _main.default.Element.prototype.show = function () { 72504 this.elt.style.display = 'block'; 72505 return this; 72506 }; 72507 /** 72508 * Hides the current element. Essentially, setting display:none for the style. 72509 * 72510 * @method hide 72511 * @chainable 72512 * @example 72513 * <div class='norender'><code> 72514 * let div = createDiv('this is a div'); 72515 * div.hide(); 72516 * </code></div> 72517 */ 72518 _main.default.Element.prototype.hide = function () { 72519 this.elt.style.display = 'none'; 72520 return this; 72521 }; 72522 /** 72523 * 72524 * Sets the width and height of the element. AUTO can be used to 72525 * only adjust one dimension at a time. If no arguments are given, it 72526 * returns the width and height of the element in an Object. In the case of 72527 * elements that need to be loaded, such as images, it is recommended 72528 * to call the function after the element has finished loading. 72529 * 72530 * @method size 72531 * @return {Object} the width and height of the element in an object 72532 * @example 72533 * <div class='norender'><code> 72534 * let div = createDiv('this is a div'); 72535 * div.size(100, 100); 72536 * let img = createImg( 72537 * 'assets/rockies.jpg',
72538 * 'A tall mountain with a small forest and field in front of it on a sunny day', 72539 * '', 72540 * () => { 72541 * img.size(10, AUTO); 72542 * } 72543 * ); 72544 * </code></div> 72545 */ 72546 /** 72547 * @method size 72548 * @param {Number|Constant} w width of the element, either AUTO, or a number 72549 * @param {Number|Constant} [h] height of the element, either AUTO, or a number 72550 * @chainable 72551 */ 72552 _main.default.Element.prototype.size = function (w, h) { 72553 if (arguments.length === 0) { 72554 return { 72555 width: this.elt.offsetWidth, 72556 height: this.elt.offsetHeight 72557 }; 72558 } else { 72559 var aW = w; 72560 var aH = h; 72561 var AUTO = _main.default.prototype.AUTO; 72562 if (aW !== AUTO || aH !== AUTO) { 72563 if (aW === AUTO) { 72564 aW = h * this.width / this.height; 72565 } else if (aH === AUTO) { 72566 aH = w * this.height / this.width; 72567 } // set diff for cnv vs normal div 72568 72569 if (this.elt instanceof HTMLCanvasElement) { 72570 var j = { 72571 }; 72572 var k = this.elt.getContext('2d'); 72573 var prop; 72574 for (prop in k) { 72575 j[prop] = k[prop]; 72576 } 72577 this.elt.setAttribute('width', aW * this._pInst._pixelDensity); 72578 this.elt.setAttribute('height', aH * this._pInst._pixelDensity); 72579 this.elt.style.width = aW + 'px'; 72580 this.elt.style.height = aH + 'px'; 72581 this._pInst.scale(this._pInst._pixelDensity, this._pInst._pixelDensity); 72582 for (prop in j) { 72583 this.elt.getContext('2d') [prop] = j[prop]; 72584 } 72585 } else { 72586 this.elt.style.width = aW + 'px'; 72587 this.elt.style.height = aH + 'px'; 72588 this.elt.width = aW; 72589 this.elt.height = aH; 72590 } 72591 this.width = this.elt.offsetWidth; 72592 this.height = this.elt.offsetHeight; 72593 if (this._pInst && this._pInst._curElement) { 72594 // main canvas associated with p5 instance 72595 if (this._pInst._curElement.elt === this.elt) { 72596 this._pInst._setProperty('width', this.elt.offsetWidth); 72597 this._pInst._setProperty('height', this.elt.offsetHeight); 72598 } 72599 } 72600 } 72601 return this; 72602 } 72603 }; 72604 /** 72605 * Removes the element, stops all media streams, and deregisters all listeners. 72606 * @method remove 72607 * @example 72608 * <div class='norender'><code> 72609 * let myDiv = createDiv('this is some text'); 72610 * myDiv.remove(); 72611 * </code></div> 72612 */ 72613 _main.default.Element.prototype.remove = function () { 72614 // stop all audios/videos and detach all devices like microphone/camera etc 72615 // used as input/output for audios/videos. 72616 if (this instanceof _main.default.MediaElement) { 72617 this.stop(); 72618 var sources = this.elt.srcObject; 72619 if (sources !== null) { 72620 var tracks = sources.getTracks(); 72621 tracks.forEach(function (track) { 72622 track.stop(); 72623 }); 72624 } 72625 } // delete the reference in this._pInst._elements 72626 72627 var index = this._pInst._elements.indexOf(this); 72628 if (index !== - 1) { 72629 this._pInst._elements.splice(index, 1); 72630 } // deregister events 72631 72632 for (var ev in this._events) { 72633 this.elt.removeEventListener(ev, this._events[ev]); 72634 } 72635 if (this.elt && this.elt.parentNode) { 72636 this.elt.parentNode.removeChild(this.elt); 72637 } 72638 }; 72639 /** 72640 * Registers a callback that gets called every time a file that is 72641 * dropped on the element has been loaded. 72642 * p5 will load every dropped file into memory and pass it as a p5.File object to the callback. 72643 * Multiple files dropped at the same time will result in multiple calls to the callback. 72644 * 72645 * You can optionally pass a second callback which will be registered to the raw 72646 * <a href="https://developer.mozilla.org/en-US/docs/Web/Events/drop">drop</a> event. 72647 * The callback will thus be provided the original 72648 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent">DragEvent</a>. 72649 * Dropping multiple files at the same time will trigger the second callback once per drop, 72650 * whereas the first callback will trigger for each loaded file. 72651 * 72652 * @method drop 72653 * @param {Function} callback callback to receive loaded file, called for each file dropped. 72654 * @param {Function}
72654 [fxn] callback triggered once when files are dropped with the drop event. 72655 * @chainable 72656 * @example 72657 * <div><code> 72658 * function setup() { 72659 * let c = createCanvas(100, 100); 72660 * background(200); 72661 * textAlign(CENTER); 72662 * text('drop file', width / 2, height / 2); 72663 * c.drop(gotFile); 72664 * } 72665 * 72666 * function gotFile(file) { 72667 * background(200); 72668 * text('received file:', width / 2, height / 2); 72669 * text(file.name, width / 2, height / 2 + 50); 72670 * } 72671 * </code></div> 72672 * 72673 * <div><code> 72674 * let img; 72675 * 72676 * function setup() { 72677 * let c = createCanvas(100, 100); 72678 * background(200); 72679 * textAlign(CENTER); 72680 * text('drop image', width / 2, height / 2); 72681 * c.drop(gotFile); 72682 * } 72683 * 72684 * function draw() { 72685 * if (img) { 72686 * image(img, 0, 0, width, height); 72687 * } 72688 * } 72689 * 72690 * function gotFile(file) { 72691 * img = createImg(file.data, '').hide(); 72692 * } 72693 * </code></div> 72694 * 72695 * @alt 72696 * Canvas turns into whatever image is dragged/dropped onto it. 72697 */ 72698 _main.default.Element.prototype.drop = function (callback, fxn) { 72699 // Is the file stuff supported? 72700 if (window.File && window.FileReader && window.FileList && window.Blob) { 72701 if (!this._dragDisabled) { 72702 this._dragDisabled = true; 72703 var preventDefault = function preventDefault(evt) { 72704 evt.preventDefault(); 72705 }; // If you want to be able to drop you've got to turn off 72706 // a lot of default behavior. 72707 // avoid `attachListener` here, since it overrides other handlers. 72708 this.elt.addEventListener('dragover', preventDefault); // If this is a drag area we need to turn off the default behavior 72709 this.elt.addEventListener('dragleave', preventDefault); 72710 } // Deal with the files 72711 72712 _main.default.Element._attachListener('drop', function (evt) { 72713 evt.preventDefault(); // Call the second argument as a callback that receives the raw drop event 72714 if (typeof fxn === 'function') { 72715 fxn.call(this, evt); 72716 } // A FileList 72717 72718 var files = evt.dataTransfer.files; // Load each one and trigger the callback 72719 for (var i = 0; i < files.length; i++) { 72720 var f = files[i]; 72721 _main.default.File._load(f, callback); 72722 } 72723 }, this); 72724 } else { 72725 console.log('The File APIs are not fully supported in this browser.'); 72726 } 72727 return this; 72728 }; // ============================================================================= 72729 // p5.MediaElement additions 72730 // ============================================================================= 72731 /** 72732 * Extends <a href="#/p5.Element">p5.Element</a> to handle audio and video. In addition to the methods 72733 * of <a href="#/p5.Element">p5.Element</a>, it also contains methods for controlling media. It is not 72734 * called directly, but <a href="#/p5.MediaElement">p5.MediaElement</a>s are created by calling <a href="#/p5/createVideo">createVideo</a>, 72735 * <a href="#/p5/createAudio">createAudio</a>, and <a href="#/p5/createCapture">createCapture</a>. 72736 * 72737 * @class p5.MediaElement 72738 * @constructor 72739 * @param {String} elt DOM node that is wrapped 72740 */ 72741 _main.default.MediaElement = function (elt, pInst) { 72742 _main.default.Element.call(this, elt, pInst); 72743 var self = this; 72744 this.elt.crossOrigin = 'anonymous'; 72745 this._prevTime = 0; 72746 this._cueIDCounter = 0; 72747 this._cues = [ 72748 ]; 72749 this._pixelsState = this; 72750 this._pixelDensity = 1; 72751 this._modified = false; 72752 /** 72753 * Path to the media element source. 72754 * 72755 * @property src 72756 * @return {String} src 72757 * @example 72758 * <div><code> 72759 * let ele; 72760 * 72761 * function setup() { 72762 * background(250); 72763 * 72764 * //p5.MediaElement objects are usually created 72765 * //by calling the createAudio(), createVideo(), 72766 * //and createCapture() functions. 72767 * 72768 * //In this example we create 72769 * //a new p5.MediaElement via createAudio(). 72770 * ele = createAudio('assets/beat.mp3'); 72771 * 72772 * //We'll set up our example so that 72773 * //when you click on the text, 72774 * //an alert box displays the MediaElement's 72775 * //src field. 72776 * textAlign(CENTER); 72777 * text('Click Me!', width / 2, height / 2); 72778 * } 72779 * 72780 * function mouseClicked() { 72781 * //here we test if the mouse is over the 72782 * //canvas element when it's clicked 72783 * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) { 72784 * //Show our p5.MediaElement's src field 72785 * alert(ele.src); 72786 * } 72787 * } 72788 * </code></div> 72789 */ 72790 Object.defineProperty(self, 'src', { 72791 get: function get() { 72792 var firstChildSrc = self.elt.children[0].src; 72793 var srcVal = self.elt.src === window.location.href ? '' : self.elt.src; 72794 var ret = firstChildSrc === window.location.href ? srcVal : firstChildSrc; 72795 return ret; 72796 }, 72797 set: function set(newValue) { 72798 for (var i = 0; i < self.elt.children.length; i++) { 72799 self.elt.removeChild(self.elt.children[i]); 72800 } 72801 var source = document.createElement('source'); 72802 source.src = newValue; 72803 elt.appendChild(source); 72804 self.elt.src = newValue; 72805 self.modified = true; 72806 } 72807 }); // private _onended callback, set by the method: onended(callback) 72808 self._onended = function () { 72809 };
72810 self.elt.onended = function () { 72811 self._onended(self); 72812 }; 72813 }; 72814 _main.default.MediaElement.prototype = Object.create(_main.default.Element.prototype); 72815 /** 72816 * Play an HTML5 media element. 72817 * 72818 * @method play 72819 * @chainable 72820 * @example 72821 * <div><code> 72822 * let ele; 72823 * 72824 * function setup() { 72825 * //p5.MediaElement objects are usually created 72826 * //by calling the createAudio(), createVideo(), 72827 * //and createCapture() functions. 72828 * 72829 * //In this example we create 72830 * //a new p5.MediaElement via createAudio(). 72831 * ele = createAudio('assets/beat.mp3'); 72832 * 72833 * background(250); 72834 * textAlign(CENTER); 72835 * text('Click to Play!', width / 2, height / 2); 72836 * } 72837 * 72838 * function mouseClicked() { 72839 * //here we test if the mouse is over the 72840 * //canvas element when it's clicked 72841 * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) { 72842 * //Here we call the play() function on 72843 * //the p5.MediaElement we created above. 72844 * //This will start the audio sample. 72845 * ele.play(); 72846 * 72847 * background(200); 72848 * text('You clicked Play!', width / 2, height / 2); 72849 * } 72850 * } 72851 * </code></div> 72852 */ 72853 _main.default.MediaElement.prototype.play = function () { 72854 var _this = this; 72855 if (this.elt.currentTime === this.elt.duration) { 72856 this.elt.currentTime = 0; 72857 } 72858 var promise; 72859 if (this.elt.readyState > 1) { 72860 promise = this.elt.play(); 72861 } else { 72862 // in Chrome, playback cannot resume after being stopped and must reload 72863 this.elt.load(); 72864 promise = this.elt.play(); 72865 } 72866 if (promise && promise.catch) { 72867 promise.catch(function (e) { 72868 // if it's an autoplay failure error 72869 if (e.name === 'NotAllowedError') { 72870 if (typeof IS_MINIFIED === 'undefined') { 72871 _main.default._friendlyAutoplayError(_this.src); 72872 } else { 72873 console.error(e); 72874 } 72875 } else { 72876 // any other kind of error 72877 console.error('Media play method encountered an unexpected error', e); 72878 } 72879 }); 72880 } 72881 return this; 72882 }; 72883 /** 72884 * Stops an HTML5 media element (sets current time to zero). 72885 * 72886 * @method stop 72887 * @chainable 72888 * @example 72889 * <div><code> 72890 * //This example both starts 72891 * //and stops a sound sample 72892 * //when the user clicks the canvas 72893 * 72894 * //We will store the p5.MediaElement 72895 * //object in here 72896 * let ele; 72897 * 72898 * //while our audio is playing, 72899 * //this will be set to true 72900 * let sampleIsPlaying = false; 72901 * 72902 * function setup() { 72903 * //Here we create a p5.MediaElement object 72904 * //using the createAudio() function. 72905 * ele = createAudio('assets/beat.mp3'); 72906 * background(200); 72907 * textAlign(CENTER); 72908 * text('Click to play!', width / 2, height / 2); 72909 * } 72910 * 72911 * function mouseClicked() { 72912 * //here we test if the mouse is over the 72913 * //canvas element when it's clicked 72914 * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) { 72915 * background(200); 72916 * 72917 * if (sampleIsPlaying) { 72918 * //if the sample is currently playing 72919 * //calling the stop() function on 72920 * //our p5.MediaElement will stop 72921 * //it and reset its current 72922 * //time to 0 (i.e. it will start 72923 * //at the beginning the next time 72924 * //you play it) 72925 * ele.stop(); 72926 * 72927 * sampleIsPlaying = false; 72928 * text('Click to play!', width / 2, height / 2); 72929 * } else { 72930 * //loop our sound element until we 72931 * //call ele.stop() on it. 72932 * ele.loop(); 72933 * 72934 * sampleIsPlaying = true; 72935 * text('Click to stop!', width / 2, height / 2); 72936 * } 72937 * } 72938 * } 72939 * </code></div> 72940 */ 72941 _main.default.MediaElement.prototype.stop = function () { 72942 this.elt.pause(); 72943 this.elt.currentTime = 0; 72944 return this; 72945 }; 72946 /** 72947 * Pauses an HTML5 media element. 72948 * 72949 * @method pause 72950 * @chainable 72951 * @example 72952 * <div><code> 72953 * //This example both starts 72954 * //and pauses a sound sample 72955 * //when the user clicks the canvas 72956 * 72957 * //We will store the p5.MediaElement 72958 * //object in here 72959 * let ele; 72960 * 72961 * //while our audio is playing, 72962 * //this will be set to true 72963 * let sampleIsPlaying = false;
72964 * 72965 * function setup() { 72966 * //Here we create a p5.MediaElement object 72967 * //using the createAudio() function. 72968 * ele = createAudio('assets/lucky_dragons.mp3'); 72969 * background(200); 72970 * textAlign(CENTER); 72971 * text('Click to play!', width / 2, height / 2); 72972 * } 72973 * 72974 * function mouseClicked() { 72975 * //here we test if the mouse is over the 72976 * //canvas element when it's clicked 72977 * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) { 72978 * background(200); 72979 * 72980 * if (sampleIsPlaying) { 72981 * //Calling pause() on our 72982 * //p5.MediaElement will stop it 72983 * //playing, but when we call the 72984 * //loop() or play() functions 72985 * //the sample will start from 72986 * //where we paused it. 72987 * ele.pause(); 72988 * 72989 * sampleIsPlaying = false; 72990 * text('Click to resume!', width / 2, height / 2); 72991 * } else { 72992 * //loop our sound element until we 72993 * //call ele.pause() on it. 72994 * ele.loop(); 72995 * 72996 * sampleIsPlaying = true; 72997 * text('Click to pause!', width / 2, height / 2); 72998 * } 72999 * } 73000 * } 73001 * </code></div> 73002 */ 73003 _main.default.MediaElement.prototype.pause = function () { 73004 this.elt.pause(); 73005 return this; 73006 }; 73007 /** 73008 * Set 'loop' to true for an HTML5 media element, and starts playing. 73009 * 73010 * @method loop 73011 * @chainable 73012 * @example 73013 * <div><code> 73014 * //Clicking the canvas will loop 73015 * //the audio sample until the user 73016 * //clicks again to stop it 73017 * 73018 * //We will store the p5.MediaElement 73019 * //object in here 73020 * let ele; 73021 * 73022 * //while our audio is playing, 73023 * //this will be set to true 73024 * let sampleIsLooping = false; 73025 * 73026 * function setup() { 73027 * //Here we create a p5.MediaElement object 73028 * //using the createAudio() function. 73029 * ele = createAudio('assets/lucky_dragons.mp3'); 73030 * background(200); 73031 * textAlign(CENTER); 73032 * text('Click to loop!', width / 2, height / 2); 73033 * } 73034 * 73035 * function mouseClicked() { 73036 * //here we test if the mouse is over the 73037 * //canvas element when it's clicked 73038 * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) { 73039 * background(200); 73040 * 73041 * if (!sampleIsLooping) { 73042 * //loop our sound element until we 73043 * //call ele.stop() on it. 73044 * ele.loop(); 73045 * 73046 * sampleIsLooping = true; 73047 * text('Click to stop!', width / 2, height / 2); 73048 * } else { 73049 * ele.stop(); 73050 * 73051 * sampleIsLooping = false; 73052 * text('Click to loop!', width / 2, height / 2); 73053 * } 73054 * } 73055 * } 73056 * </code></div> 73057 */ 73058 _main.default.MediaElement.prototype.loop = function () { 73059 this.elt.setAttribute('loop', true); 73060 this.play(); 73061 return this; 73062 }; 73063 /** 73064 * Set 'loop' to false for an HTML5 media element. Element will stop 73065 * when it reaches the end. 73066 * 73067 * @method noLoop 73068 * @chainable 73069 * @example 73070 * <div><code> 73071 * //This example both starts 73072 * //and stops loop of sound sample 73073 * //when the user clicks the canvas 73074 * 73075 * //We will store the p5.MediaElement 73076 * //object in here 73077 * let ele; 73078 * //while our audio is playing, 73079 * //this will be set to true 73080 * let sampleIsPlaying = false; 73081 * 73082 * function setup() { 73083 * //Here we create a p5.MediaElement object 73084 * //using the createAudio() function. 73085 * ele = createAudio('assets/beat.mp3'); 73086 * background(200); 73087 * textAlign(CENTER); 73088 * text('Click to play!', width / 2, height / 2); 73089 * } 73090 * 73091 * function mouseClicked() { 73092 * //here we test if the mouse is over the 73093 * //canvas element when it's clicked 73094 * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) { 73095 * background(200); 73096 * 73097 * if (sampleIsPlaying) { 73098 * ele.noLoop(); 73099 * sampleIsPlaying = false; 73100 * text('No more Loops!', width / 2, height / 2); 73101 * } else { 73102 * ele.loop(); 73103 * sampleIsPlaying = true; 73104 * text('Click to stop looping!', width / 2, height / 2); 73105 * } 73106 * } 73107 * } 73108 * </code></div> 73109 */ 73110 _main.default.MediaElement.prototype.noLoop = function () { 73111 this.elt.removeAttribute('loop'); 73112 return this; 73113 }; 73114 /** 73115 * Sets up logic to check that autoplay succeeded. 73116 * 73117 * @method setupAutoplayFailDetection 73118 * @private 73119 */ 73120 _main.default.MediaElement.prototype._setupAutoplayFailDetection = function () { 73121 var _this2 = this; 73122 var timeout = setTimeout(function () { 73123 if (typeof IS_MINIFIED === 'undefined') { 73124 _main.default._friendlyAutoplayError(_this2.src); 73125 } else { 73126 console.error(e); 73127 } 73128 }, 500); 73129 this.elt.addEventListener('play', function () { 73130 return clearTimeout(timeout); 73131 }, { 73132 passive: true, 73133 once: true 73134 }); 73135 }; 73136 /**
73137 * Set HTML5 media element to autoplay or not. If no argument is specified, by 73138 * default it will autoplay. 73139 * 73140 * @method autoplay 73141 * @param {Boolean} shouldAutoplay whether the element should autoplay 73142 * @chainable 73143 * @example 73144 * <div><code> 73145 * let videoElement; 73146 * function setup() { 73147 * noCanvas(); 73148 * videoElement = createVideo(['assets/small.mp4'], onVideoLoad); 73149 * } 73150 * function onVideoLoad() { 73151 * // The media will play as soon as it is loaded. 73152 * videoElement.autoplay(); 73153 * videoElement.volume(0); 73154 * videoElement.size(100, 100); 73155 * } 73156 * </code></div> 73157 * 73158 * <div><code> 73159 * let videoElement; 73160 * function setup() { 73161 * noCanvas(); 73162 * videoElement = createVideo(['assets/small.mp4'], onVideoLoad); 73163 * } 73164 * function onVideoLoad() { 73165 * // The media will not play until some explicitly triggered. 73166 * videoElement.autoplay(false); 73167 * videoElement.volume(0); 73168 * videoElement.size(100, 100); 73169 * } 73170 * 73171 * function mouseClicked() { 73172 * videoElement.play(); 73173 * } 73174 * </code></div> 73175 * 73176 * @alt 73177 * An example of a video element which autoplays after it is loaded. 73178 * An example of a video element which waits for a trigger for playing. 73179 */ 73180 _main.default.MediaElement.prototype.autoplay = function (val) { 73181 var _this3 = this; 73182 var oldVal = this.elt.getAttribute('autoplay'); 73183 this.elt.setAttribute('autoplay', val); // if we turned on autoplay 73184 if (val && !oldVal) { 73185 // bind method to this scope 73186 var setupAutoplayFailDetection = function setupAutoplayFailDetection() { 73187 return _this3._setupAutoplayFailDetection(); 73188 }; // if media is ready to play, schedule check now 73189 if (this.elt.readyState === 4) { 73190 setupAutoplayFailDetection(); 73191 } else { 73192 // otherwise, schedule check whenever it is ready 73193 this.elt.addEventListener('canplay', setupAutoplayFailDetection, { 73194 passive: true, 73195 once: true 73196 }); 73197 } 73198 } 73199 return this; 73200 }; 73201 /** 73202 * Sets volume for this HTML5 media element. If no argument is given, 73203 * returns the current volume. 73204 * 73205 * @method volume 73206 * @return {Number} current volume 73207 * 73208 * @example 73209 * <div><code> 73210 * let ele; 73211 * function setup() { 73212 * // p5.MediaElement objects are usually created 73213 * // by calling the createAudio(), createVideo(), 73214 * // and createCapture() functions. 73215 * // In this example we create 73216 * // a new p5.MediaElement via createAudio(). 73217 * ele = createAudio('assets/lucky_dragons.mp3'); 73218 * background(250); 73219 * textAlign(CENTER); 73220 * text('Click to Play!', width / 2, height / 2); 73221 * } 73222 * function mouseClicked() { 73223 * // Here we call the volume() function 73224 * // on the sound element to set its volume 73225 * // Volume must be between 0.0 and 1.0 73226 * ele.volume(0.2); 73227 * ele.play(); 73228 * background(200); 73229 * text('You clicked Play!', width / 2, height / 2); 73230 * } 73231 * </code></div> 73232 * <div><code> 73233 * let audio; 73234 * let counter = 0; 73235 * 73236 * function loaded() { 73237 * audio.play(); 73238 * } 73239 * 73240 * function setup() { 73241 * audio = createAudio('assets/lucky_dragons.mp3', loaded); 73242 * textAlign(CENTER); 73243 * } 73244 * 73245 * function draw() { 73246 * if (counter === 0) { 73247 * background(0, 255, 0); 73248 * text('volume(0.9)', width / 2, height / 2); 73249 * } else if (counter === 1) { 73250 * background(255, 255, 0); 73251 * text('volume(0.5)', width / 2, height / 2); 73252 * } else if (counter === 2) { 73253 * background(255, 0, 0); 73254 * text('volume(0.1)', width / 2, height / 2); 73255 * } 73256 * } 73257 * 73258 * function mousePressed() { 73259 * counter++; 73260 * if (counter === 0) { 73261 * audio.volume(0.9); 73262 * } else if (counter === 1) { 73263 * audio.volume(0.5); 73264 * } else if (counter === 2) { 73265 * audio.volume(0.1); 73266 * } else { 73267 * counter = 0; 73268 * audio.volume(0.9); 73269 * } 73270 * } 73271 * </code> 73272 * </div> 73273 */ 73274 /** 73275 * @method volume 73276 * @param {Number} val volume between 0.0 and 1.0 73277 * @chainable 73278 */ 73279 _main.default.MediaElement.prototype.volume = function (val) { 73280 if (typeof val === 'undefined') { 73281 return this.elt.volume; 73282 } else { 73283 this.elt.volume = val; 73284 } 73285 }; 73286 /** 73287 * If no arguments are given, returns the current playback speed of the 73288 * element. The speed parameter sets the speed where 2.0 will play the 73289 * element twice as fast, 0.5 will play at half the speed, and -1 will play 73290 * the element in normal speed in reverse.(Note that not all browsers support 73291 * backward playback and even if they do, playback might not be smooth.) 73292 * 73293 * @method speed 73294 * @return {Number} current playback speed of the element 73295 * 73296 * @example 73297 * <div class='norender notest'><code> 73298 * //Clicking the canvas will loop 73299 * //the audio sample until the user 73300 * //clicks again to stop it 73301 * 73302 * //We will store the p5.MediaElement 73303 * //object in here 73304 * let ele; 73305 * let button; 73306 * 73307 * function setup() { 73308 * createCanvas(710, 400); 73309 * //Here we create a p5.MediaElement object 73310 * //using the createAudio() function. 73311 * ele = createAudio('assets/beat.mp3'); 73312 * ele.loop(); 73313 * background(200); 73314 * 73315 * button = createButton('2x speed'); 73316 * button.position(100, 68); 73317 * button.mousePressed(twice_speed); 73318 * 73319 * button = createButton('half speed'); 73320 * button.position(200, 68); 73321 * button.mousePressed(half_speed); 73322 * 73323 * button = createButton('reverse play'); 73324 * button.position(300, 68); 73325 * button.mousePressed(reverse_speed); 73326 * 73327 * button = createButton('STOP'); 73328 * button.position(400, 68); 73329 * button.mousePressed(stop_song); 73330 * 73331 * button = createButton('PLAY!'); 73332 * button.position(500, 68); 73333 * button.mousePressed(play_speed); 73334 * } 73335 * 73336 * function twice_speed() { 73337 * ele.speed(2); 73338 * } 73339 * 73340 * function half_speed() { 73341 * ele.speed(0.5); 73342 * } 73343 * 73344 * function reverse_speed() { 73345 * ele.speed(-1); 73346 * } 73347 * 73348 * function stop_song() { 73349 * ele.stop(); 73350 * } 73351 * 73352 * function play_speed() { 73353 * ele.play(); 73354 * } 73355 * </code></div> 73356 */ 73357 /** 73358 * @method speed 73359 * @param {Number} speed speed multiplier for element playback 73360 * @chainable 73361 */ 73362 _main.default.MediaElement.prototype.speed = function (val) { 73363 if (typeof val === 'undefined') { 73364 return this.presetPlaybackRate || this.elt.playbackRate; 73365 } else { 73366 if (this.loadedmetadata) { 73367 this.elt.playbackRate = val; 73368 } else { 73369 this.presetPlaybackRate = val; 73370 } 73371 } 73372 }; 73373 /** 73374 * If no arguments are given, returns the current time of the element. 73375 * If an argument is given the current time of the element is set to it. 73376 * 73377 * @method time 73378 * @return {Number} current time (in seconds) 73379 * 73380 * @example 73381 * <div><code> 73382 * let ele; 73383 * let beginning = true; 73384 * function setup() { 73385 * //p5.MediaElement objects are usually created 73386 * //by calling the createAudio(), createVideo(), 73387 * //and createCapture() functions. 73388 * 73389 * //In this example we create 73390 * //a new p5.MediaElement via createAudio(). 73391 * ele = createAudio('assets/lucky_dragons.mp3'); 73392 * background(250); 73393 * textAlign(CENTER); 73394 * text('start at beginning', width / 2, height / 2); 73395 * } 73396 *
73397 * // this function fires with click anywhere 73398 * function mousePressed() { 73399 * if (beginning === true) { 73400 * // here we start the sound at the beginning 73401 * // time(0) is not necessary here 73402 * // as this produces the same result as 73403 * // play() 73404 * ele.play().time(0); 73405 * background(200); 73406 * text('jump 2 sec in', width / 2, height / 2); 73407 * beginning = false; 73408 * } else { 73409 * // here we jump 2 seconds into the sound 73410 * ele.play().time(2); 73411 * background(250); 73412 * text('start at beginning', width / 2, height / 2); 73413 * beginning = true; 73414 * } 73415 * } 73416 * </code></div> 73417 */ 73418 /** 73419 * @method time 73420 * @param {Number} time time to jump to (in seconds) 73421 * @chainable 73422 */ 73423 _main.default.MediaElement.prototype.time = function (val) { 73424 if (typeof val === 'undefined') { 73425 return this.elt.currentTime; 73426 } else { 73427 this.elt.currentTime = val; 73428 return this; 73429 } 73430 }; 73431 /** 73432 * Returns the duration of the HTML5 media element. 73433 * 73434 * @method duration 73435 * @return {Number} duration 73436 * 73437 * @example 73438 * <div><code> 73439 * let ele; 73440 * function setup() { 73441 * //p5.MediaElement objects are usually created 73442 * //by calling the createAudio(), createVideo(), 73443 * //and createCapture() functions. 73444 * //In this example we create 73445 * //a new p5.MediaElement via createAudio(). 73446 * ele = createAudio('assets/doorbell.mp3'); 73447 * background(250); 73448 * textAlign(CENTER); 73449 * text('Click to know the duration!', 10, 25, 70, 80); 73450 * } 73451 * function mouseClicked() { 73452 * ele.play(); 73453 * background(200); 73454 * //ele.duration dislpays the duration 73455 * text(ele.duration() + ' seconds', width / 2, height / 2); 73456 * } 73457 * </code></div> 73458 */ 73459 _main.default.MediaElement.prototype.duration = function () { 73460 return this.elt.duration; 73461 }; 73462 _main.default.MediaElement.prototype.pixels = [ 73463 ]; 73464 _main.default.MediaElement.prototype._ensureCanvas = function () { 73465 if (!this.canvas) { 73466 this.canvas = document.createElement('canvas'); 73467 this.drawingContext = this.canvas.getContext('2d'); 73468 this.setModified(true); 73469 } 73470 if (this.loadedmetadata) { 73471 // wait for metadata for w/h 73472 if (this.canvas.width !== this.elt.width) { 73473 this.canvas.width = this.elt.width; 73474 this.canvas.height = this.elt.height; 73475 this.width = this.canvas.width; 73476 this.height = this.canvas.height; 73477 } 73478 this.drawingContext.drawImage(this.elt, 0, 0, this.canvas.width, this.canvas.height); 73479 this.setModified(true); 73480 } 73481 }; 73482 _main.default.MediaElement.prototype.loadPixels = function () { 73483 this._ensureCanvas(); 73484 return _main.default.Renderer2D.prototype.loadPixels.apply(this, arguments); 73485 }; 73486 _main.default.MediaElement.prototype.updatePixels = function (x, y, w, h) { 73487 if (this.loadedmetadata) { 73488 // wait for metadata 73489 this._ensureCanvas(); 73490 _main.default.Renderer2D.prototype.updatePixels.call(this, x, y, w, h); 73491 } 73492 this.setModified(true); 73493 return this; 73494 }; 73495 _main.default.MediaElement.prototype.get = function () { 73496 this._ensureCanvas(); 73497 return _main.default.Renderer2D.prototype.get.apply(this, arguments); 73498 }; 73499 _main.default.MediaElement.prototype._getPixel = function () { 73500 this.loadPixels(); 73501 return _main.default.Renderer2D.prototype._getPixel.apply(this, arguments); 73502 }; 73503 _main.default.MediaElement.prototype.set = function (x, y, imgOrCol) { 73504 if (this.loadedmetadata) { 73505 // wait for metadata 73506 this._ensureCanvas(); 73507 _main.default.Renderer2D.prototype.set.call(this, x, y, imgOrCol); 73508 this.setModified(true); 73509 } 73510 }; 73511 _main.default.MediaElement.prototype.copy = function () { 73512 this._ensureCanvas(); 73513 _main.default.prototype.copy.apply(this, arguments); 73514 }; 73515 _main.default.MediaElement.prototype.mask = function () { 73516 this.loadPixels(); 73517 this.setModified(true); 73518 _main.default.Image.prototype.mask.apply(this, arguments); 73519 }; 73520 /** 73521 * helper method for web GL mode to figure out if the element 73522 * has been modified and might need to be re-uploaded to texture 73523 * memory between frames. 73524 * @method isModified 73525 * @private 73526 * @return {boolean} a boolean indicating whether or not the 73527 * image has been updated or modified since last texture upload. 73528 */ 73529 _main.default.MediaElement.prototype.isModified = function () { 73530 return this._modified; 73531 }; 73532 /** 73533 * helper method for web GL mode to indicate that an element has been 73534 * changed or unchanged since last upload. gl texture upload will 73535 * set this value to false after uploading the texture; or might set 73536 * it to true if metadata has become available but there is no actual 73537 * texture data available yet.. 73538 * @method setModified 73539 * @param {boolean} val sets whether or not the element has been 73540 * modified. 73541 * @private 73542 */ 73543 _main.default.MediaElement.prototype.setModified = function (value) { 73544 this._modified = value; 73545 }; 73546 /** 73547 * Schedule an event to be called when the audio or video 73548 * element reaches the end. If the element is looping, 73549 * this will not be called. The element is passed in 73550 * as the argument to the onended callback. 73551 * 73552 * @method onended 73553 * @param {Function} callback function to call when the 73554 * soundfile has ended. The 73555 * media element will be passed 73556 * in as the argument to the 73557 * callback. 73558 * @chainable 73559 * @example 73560 * <div><code> 73561 * function setup() { 73562 * let audioEl = createAudio('assets/beat.mp3'); 73563 * audioEl.showControls(); 73564 * audioEl.onended(sayDone); 73565 * } 73566 * 73567 * function sayDone(elt) { 73568 * alert('done playing ' + elt.src); 73569 * } 73570 * </code></div> 73571 */ 73572 _main.default.MediaElement.prototype.onended = function (callback) { 73573 this._onended = callback; 73574 return this; 73575 }; 73576 /*** CONNECT TO WEB AUDIO API / p5.sound.js ***/ 73577 /** 73578 * Send the audio output of this element to a specified audioNode or 73579 * p5.sound object. If no element is provided, connects to p5's main 73580 * output. That connection is established when this method is first called. 73581 * All connections are removed by the .disconnect() method. 73582 * 73583 * This method is meant to be used with the p5.sound.js addon library. 73584 * 73585 * @method connect 73586 * @param {AudioNode|Object} audioNode AudioNode from the Web Audio API, 73587 * or an object from the p5.sound library 73588 */ 73589 _main.default.MediaElement.prototype.connect = function (obj) { 73590 var audioContext, 73591 mainOutput; // if p5.sound exists, same audio context 73592 if (typeof _main.default.prototype.getAudioContext === 'function') { 73593 audioContext = _main.default.prototype.getAudioContext(); 73594 mainOutput = _main.default.soundOut.input; 73595 } else { 73596 try { 73597 audioContext = obj.context; 73598 mainOutput = audioContext.destination; 73599 } catch (e) { 73600 throw 'connect() is meant to be used with Web Audio API or p5.sound.js'; 73601 } 73602 } // create a Web Audio MediaElementAudioSourceNode if none already exists 73603 73604 if (!this.audioSourceNode) { 73605 this.audioSourceNode = audioContext.createMediaElementSource(this.elt); // connect to main output when this method is first called 73606 this.audioSourceNode.connect(mainOutput); 73607 } // connect to object if provided 73608 73609 if (obj) { 73610 if (obj.input) { 73611 this.audioSourceNode.connect(obj.input); 73612 } else { 73613 this.audioSourceNode.connect(obj); 73614 } 73615 } else { 73616 // otherwise connect to main output of p5.sound / AudioContext 73617 this.audioSourceNode.connect(mainOutput); 73618 } 73619 }; 73620 /** 73621 * Disconnect all Web Audio routing, including to main output. 73622 * This is useful if you want to re-route the output through 73623 * audio effects, for example. 73624 * 73625 * @method disconnect 73626 */ 73627 _main.default.MediaElement.prototype.disconnect = function () { 73628 if (this.audioSourceNode) { 73629 this.audioSourceNode.disconnect(); 73630 } else { 73631 throw 'nothing to disconnect'; 73632 } 73633 }; 73634 /*** SHOW / HIDE CONTROLS ***/ 73635 /** 73636 * Show the default MediaElement controls, as determined by the web browser. 73637 * 73638 * @method showControls 73639 * @example 73640 * <div><code> 73641 * let ele; 73642 * function setup() { 73643 * //p5.MediaElement objects are usually created 73644 * //by calling the createAudio(), createVideo(), 73645 * //and createCapture() functions. 73646 * //In this example we create 73647 * //a new p5.MediaElement via createAudio() 73648 * ele = createAudio('assets/lucky_dragons.mp3'); 73649 * background(200); 73650 * textAlign(CENTER); 73651 * text('Click to Show Controls!', 10, 25, 70, 80); 73652 * } 73653 * function mousePressed() { 73654 * ele.showControls(); 73655 * background(200); 73656 * text('Controls Shown', width / 2, height / 2); 73657 * } 73658 * </code></div> 73659 */ 73660 _main.default.MediaElement.prototype.showControls = function () { 73661 // must set style for the element to show on the page 73662 this.elt.style['text-align'] = 'inherit'; 73663 this.elt.controls = true; 73664 }; 73665 /** 73666 * Hide the default mediaElement controls. 73667 * @method hideControls 73668 * @example 73669 * <div><code> 73670 * let ele; 73671 * function setup() { 73672 * //p5.MediaElement objects are usually created 73673 * //by calling the createAudio(), createVideo(), 73674 * //and createCapture() functions. 73675 * //In this example we create 73676 * //a new p5.MediaElement via createAudio() 73677 * ele = createAudio('assets/lucky_dragons.mp3'); 73678 * ele.showControls(); 73679 * background(200); 73680 * textAlign(CENTER); 73681 * text('Click to hide Controls!', 10, 25, 70, 80); 73682 * } 73683 * function mousePressed() { 73684 * ele.hideControls(); 73685 * background(200); 73686 * text('Controls hidden', width / 2, height / 2); 73687 * } 73688 * </code></div> 73689 */ 73690 _main.default.MediaElement.prototype.hideControls = function () { 73691 this.elt.controls = false;
73692 }; 73693 /*** SCHEDULE EVENTS ***/ 73694 // Cue inspired by JavaScript setTimeout, and the 73695 // Tone.js Transport Timeline Event, MIT License Yotam Mann 2015 tonejs.org 73696 var Cue = function Cue(callback, time, id, val) { 73697 this.callback = callback; 73698 this.time = time; 73699 this.id = id; 73700 this.val = val; 73701 }; 73702 /** 73703 * Schedule events to trigger every time a MediaElement 73704 * (audio/video) reaches a playback cue point. 73705 * 73706 * Accepts a callback function, a time (in seconds) at which to trigger 73707 * the callback, and an optional parameter for the callback. 73708 * 73709 * Time will be passed as the first parameter to the callback function, 73710 * and param will be the second parameter. 73711 * 73712 * @method addCue 73713 * @param {Number} time Time in seconds, relative to this media 73714 * element's playback. For example, to trigger 73715 * an event every time playback reaches two 73716 * seconds, pass in the number 2. This will be 73717 * passed as the first parameter to 73718 * the callback function. 73719 * @param {Function} callback Name of a function that will be 73720 * called at the given time. The callback will 73721 * receive time and (optionally) param as its 73722 * two parameters. 73723 * @param {Object} [value] An object to be passed as the 73724 * second parameter to the 73725 * callback function. 73726 * @return {Number} id ID of this cue, 73727 * useful for removeCue(id) 73728 * @example 73729 * <div><code> 73730 * // 73731 * // 73732 * function setup() { 73733 * createCanvas(200, 200); 73734 * 73735 * let audioEl = createAudio('assets/beat.mp3'); 73736 * audioEl.showControls(); 73737 * 73738 * // schedule three calls to changeBackground 73739 * audioEl.addCue(0.5, changeBackground, color(255, 0, 0)); 73740 * audioEl.addCue(1.0, changeBackground, color(0, 255, 0)); 73741 * audioEl.addCue(2.5, changeBackground, color(0, 0, 255)); 73742 * audioEl.addCue(3.0, changeBackground, color(0, 255, 255)); 73743 * audioEl.addCue(4.2, changeBackground, color(255, 255, 0)); 73744 * audioEl.addCue(5.0, changeBackground, color(255, 255, 0)); 73745 * } 73746 * 73747 * function changeBackground(val) { 73748 * background(val); 73749 * } 73750 * </code></div> 73751 */ 73752 _main.default.MediaElement.prototype.addCue = function (time, callback, val) { 73753 var id = this._cueIDCounter++; 73754 var cue = new Cue(callback, time, id, val); 73755 this._cues.push(cue); 73756 if (!this.elt.ontimeupdate) { 73757 this.elt.ontimeupdate = this._onTimeUpdate.bind(this); 73758 } 73759 return id; 73760 }; 73761 /** 73762 * Remove a callback based on its ID. The ID is returned by the 73763 * addCue method. 73764 * @method removeCue 73765 * @param {Number} id ID of the cue, as returned by addCue 73766 * @example 73767 * <div><code> 73768 * let audioEl, id1, id2; 73769 * function setup() { 73770 * background(255, 255, 255); 73771 * audioEl = createAudio('assets/beat.mp3'); 73772 * audioEl.showControls(); 73773 * // schedule five calls to changeBackground 73774 * id1 = audioEl.addCue(0.5, changeBackground, color(255, 0, 0)); 73775 * audioEl.addCue(1.0, changeBackground, color(0, 255, 0)); 73776 * audioEl.addCue(2.5, changeBackground, color(0, 0, 255)); 73777 * audioEl.addCue(3.0, changeBackground, color(0, 255, 255)); 73778 * id2 = audioEl.addCue(4.2, changeBackground, color(255, 255, 0)); 73779 * text('Click to remove first and last Cue!', 10, 25, 70, 80); 73780 * } 73781 * function mousePressed() { 73782 * audioEl.removeCue(id1); 73783 * audioEl.removeCue(id2); 73784 * } 73785 * function changeBackground(val) { 73786 * background(val); 73787 * } 73788 * </code></div> 73789 */ 73790 _main.default.MediaElement.prototype.removeCue = function (id) { 73791 for (var i = 0; i < this._cues.length; i++) { 73792 if (this._cues[i].id === id) { 73793 console.log(id); 73794 this._cues.splice(i, 1); 73795 } 73796 } 73797 if (this._cues.length === 0) { 73798 this.elt.ontimeupdate = null; 73799 } 73800 }; 73801 /** 73802 * Remove all of the callbacks that had originally been scheduled 73803 * via the addCue method. 73804 * @method clearCues 73805 * @param {Number} id ID of the cue, as returned by addCue 73806 * @example 73807 * <div><code> 73808 * let audioEl; 73809 * function setup() { 73810 * background(255, 255, 255); 73811 * audioEl = createAudio('assets/beat.mp3'); 73812 * //Show the default MediaElement controls, as determined by the web browser 73813 * audioEl.showControls();
73814 * // schedule calls to changeBackground 73815 * background(200); 73816 * text('Click to change Cue!', 10, 25, 70, 80); 73817 * audioEl.addCue(0.5, changeBackground, color(255, 0, 0)); 73818 * audioEl.addCue(1.0, changeBackground, color(0, 255, 0)); 73819 * audioEl.addCue(2.5, changeBackground, color(0, 0, 255)); 73820 * audioEl.addCue(3.0, changeBackground, color(0, 255, 255)); 73821 * audioEl.addCue(4.2, changeBackground, color(255, 255, 0)); 73822 * } 73823 * function mousePressed() { 73824 * // here we clear the scheduled callbacks 73825 * audioEl.clearCues(); 73826 * // then we add some more callbacks 73827 * audioEl.addCue(1, changeBackground, color(2, 2, 2)); 73828 * audioEl.addCue(3, changeBackground, color(255, 255, 0)); 73829 * } 73830 * function changeBackground(val) { 73831 * background(val); 73832 * } 73833 * </code></div> 73834 */ 73835 _main.default.MediaElement.prototype.clearCues = function () { 73836 this._cues = [ 73837 ]; 73838 this.elt.ontimeupdate = null; 73839 }; // private method that checks for cues to be fired if events 73840 // have been scheduled using addCue(callback, time).
73841 _main.default.MediaElement.prototype._onTimeUpdate = function () { 73842 var playbackTime = this.time(); 73843 for (var i = 0; i < this._cues.length; i++) { 73844 var callbackTime = this._cues[i].time; 73845 var val = this._cues[i].val; 73846 if (this._prevTime < callbackTime && callbackTime <= playbackTime) { 73847 // pass the scheduled callbackTime as parameter to the callback 73848 this._cues[i].callback(val); 73849 } 73850 } 73851 this._prevTime = playbackTime; 73852 }; 73853 /** 73854 * Base class for a file. 73855 * Used for Element.drop and createFileInput. 73856 * 73857 * @class p5.File 73858 * @constructor 73859 * @param {File} file File that is wrapped 73860 */ 73861 _main.default.File = function (file, pInst) { 73862 /** 73863 * Underlying File object. All normal File methods can be called on this. 73864 * 73865 * @property file 73866 */ 73867 this.file = file; 73868 this._pInst = pInst; // Splitting out the file type into two components 73869 // This makes determining if image or text etc simpler 73870 var typeList = file.type.split('/'); 73871 /** 73872 * File type (image, text, etc.) 73873 * 73874 * @property type 73875 */ 73876 this.type = typeList[0]; 73877 /** 73878 * File subtype (usually the file extension jpg, png, xml, etc.) 73879 * 73880 * @property subtype 73881 */ 73882 this.subtype = typeList[1]; 73883 /** 73884 * File name 73885 * 73886 * @property name 73887 */ 73888 this.name = file.name; 73889 /** 73890 * File size 73891 * 73892 * @property size 73893 */ 73894 this.size = file.size; 73895 /** 73896 * URL string containing either image data, the text contents of the file or 73897 * a parsed object if file is JSON and p5.XML if XML 73898 * 73899 * @property data 73900 */ 73901 this.data = undefined; 73902 }; 73903 _main.default.File._createLoader = function (theFile, callback) { 73904 var reader = new FileReader(); 73905 reader.onload = function (e) { 73906 var p5file = new _main.default.File(theFile); 73907 if (p5file.file.type === 'application/json') { 73908 // Parse JSON and store the result in data 73909 p5file.data = JSON.parse(e.target.result); 73910 } else if (p5file.file.type === 'text/xml') { 73911 // Parse XML, wrap it in p5.XML and store the result in data 73912 var parser = new DOMParser(); 73913 var xml = parser.parseFromString(e.target.result, 'text/xml'); 73914 p5file.data = new _main.default.XML(xml.documentElement); 73915 } else { 73916 p5file.data = e.target.result; 73917 } 73918 callback(p5file); 73919 }; 73920 return reader; 73921 }; 73922 _main.default.File._load = function (f, callback) { 73923 // Text or data? 73924 // This should likely be improved 73925 if (/^text\//.test(f.type) || f.type === 'application/json') { 73926 _main.default.File._createLoader(f, callback).readAsText(f); 73927 } else if (!/^(video|audio)\//.test(f.type)) { 73928 _main.default.File._createLoader(f, callback).readAsDataURL(f); 73929 } else { 73930 var file = new _main.default.File(f); 73931 file.data = URL.createObjectURL(f); 73932 callback(file); 73933 } 73934 }; 73935 var _default = _main.default; 73936 exports.default = _default; 73937 }, 73938 { 73939 '../core/main': 290, 73940 'core-js/modules/es.array.every': 169, 73941 'core-js/modules/es.array.filter': 171, 73942 'core-js/modules/es.array.for-each': 172, 73943 'core-js/modules/es.array.from': 173, 73944 'core-js/modules/es.array.index-of': 175, 73945 'core-js/modules/es.array.iterator': 176, 73946 'core-js/modules/es.array.map': 179, 73947 'core-js/modules/es.array.slice': 180, 73948 'core-js/modules/es.array.splice': 182, 73949 'core-js/modules/es.function.name': 183, 73950 'core-js/modules/es.object.to-string': 195, 73951 'core-js/modules/es.promise': 196, 73952 'core-js/modules/es.regexp.exec': 199, 73953 'core-js/modules/es.regexp.to-string': 200, 73954 'core-js/modules/es.string.iterator': 204, 73955 'core-js/modules/es.string.replace': 207, 73956 'core-js/modules/es.string.split': 209, 73957 'core-js/modules/es.string.trim': 211, 73958 'core-js/modules/es.symbol': 214, 73959 'core-js/modules/es.symbol.description': 212, 73960 'core-js/modules/es.symbol.iterator': 213, 73961 'core-js/modules/web.dom-collections.for-each': 247, 73962 'core-js/modules/web.dom-collections.iterator': 248, 73963 'core-js/modules/web.url': 250 73964 } 73965 ], 73966 307: [
73967 function (_dereq_, module, exports) { 73968 'use strict'; 73969 _dereq_('core-js/modules/es.symbol'); 73970 _dereq_('core-js/modules/es.symbol.description'); 73971 _dereq_('core-js/modules/es.symbol.iterator'); 73972 _dereq_('core-js/modules/es.array.iterator'); 73973 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 73974 _dereq_('core-js/modules/es.object.to-string'); 73975 _dereq_('core-js/modules/es.string.iterator'); 73976 _dereq_('core-js/modules/es.weak-map'); 73977 _dereq_('core-js/modules/web.dom-collections.iterator'); 73978 function _typeof2(obj) { 73979 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 73980 _typeof2 = function _typeof2(obj) { 73981 return typeof obj; 73982 }; 73983 } else { 73984 _typeof2 = function _typeof2(obj) { 73985 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 73986 }; 73987 } 73988 return _typeof2(obj); 73989 } 73990 function _typeof(obj) { 73991 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 73992 _typeof = function _typeof(obj) { 73993 return _typeof2(obj); 73994 }; 73995 } else { 73996 _typeof = function _typeof(obj) { 73997 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 73998 }; 73999 } 74000 return _typeof(obj); 74001 } 74002 Object.defineProperty(exports, '__esModule', { 74003 value: true 74004 }); 74005 exports.default = void 0; 74006 var _main = _interopRequireDefault(_dereq_('../core/main')); 74007 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 74008 function _getRequireWildcardCache() { 74009 if (typeof WeakMap !== 'function') return null; 74010 var cache = new WeakMap(); 74011 _getRequireWildcardCache = function _getRequireWildcardCache() { 74012 return cache; 74013 }; 74014 return cache; 74015 } 74016 function _interopRequireWildcard(obj) { 74017 if (obj && obj.__esModule) { 74018 return obj; 74019 } 74020 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 74021 return { 74022 default: 74023 obj 74024 }; 74025 } 74026 var cache = _getRequireWildcardCache(); 74027 if (cache && cache.has(obj)) { 74028 return cache.get(obj); 74029 } 74030 var newObj = { 74031 }; 74032 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 74033 for (var key in obj) { 74034 if (Object.prototype.hasOwnProperty.call(obj, key)) { 74035 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 74036 if (desc && (desc.get || desc.set)) { 74037 Object.defineProperty(newObj, key, desc); 74038 } else { 74039 newObj[key] = obj[key]; 74040 } 74041 } 74042 } 74043 newObj.default = obj; 74044 if (cache) { 74045 cache.set(obj, newObj); 74046 } 74047 return newObj; 74048 } 74049 function _interopRequireDefault(obj) { 74050 return obj && obj.__esModule ? obj : { 74051 default: 74052 obj 74053 }; 74054 } /** 74055 * @module Events 74056 * @submodule Acceleration 74057 * @for p5 74058 * @requires core 74059 */ 74060 /** 74061 * The system variable deviceOrientation always contains the orientation of 74062 * the device. The value of this variable will either be set 'landscape' 74063 * or 'portrait'. If no data is available it will be set to 'undefined'. 74064 * either LANDSCAPE or PORTRAIT. 74065 * 74066 * @property {Constant} deviceOrientation 74067 * @readOnly 74068 */ 74069 74070 _main.default.prototype.deviceOrientation = window.innerWidth / window.innerHeight > 1 ? 'landscape' : 'portrait'; 74071 /** 74072 * The system variable accelerationX always contains the acceleration of the 74073 * device along the x axis. Value is represented as meters per second squared. 74074 * 74075 * @property {Number} accelerationX 74076 * @readOnly 74077 * @example 74078 * <div> 74079 * <code> 74080 * // Move a touchscreen device to register 74081 * // acceleration changes. 74082 * function draw() { 74083 * background(220, 50); 74084 * fill('magenta'); 74085 * ellipse(width / 2, height / 2, accelerationX); 74086 * describe('Magnitude of device acceleration is displayed as ellipse size.'); 74087 * } 74088 * </code> 74089 * </div> 74090 */ 74091 _main.default.prototype.accelerationX = 0; 74092 /** 74093 * The system variable accelerationY always contains the acceleration of the
74094 * device along the y axis. Value is represented as meters per second squared. 74095 * 74096 * @property {Number} accelerationY 74097 * @readOnly 74098 * @example 74099 * <div> 74100 * <code> 74101 * // Move a touchscreen device to register 74102 * // acceleration changes. 74103 * function draw() { 74104 * background(220, 50); 74105 * fill('magenta'); 74106 * ellipse(width / 2, height / 2, accelerationY); 74107 * describe('Magnitude of device acceleration is displayed as ellipse size'); 74108 * } 74109 * </code> 74110 * </div> 74111 */ 74112 _main.default.prototype.accelerationY = 0; 74113 /** 74114 * The system variable accelerationZ always contains the acceleration of the 74115 * device along the z axis. Value is represented as meters per second squared. 74116 * 74117 * @property {Number} accelerationZ 74118 * @readOnly 74119 * 74120 * @example 74121 * <div> 74122 * <code> 74123 * // Move a touchscreen device to register 74124 * // acceleration changes. 74125 * function draw() { 74126 * background(220, 50); 74127 * fill('magenta'); 74128 * ellipse(width / 2, height / 2, accelerationZ); 74129 * describe('Magnitude of device acceleration is displayed as ellipse size'); 74130 * } 74131 * </code> 74132 * </div> 74133 */ 74134 _main.default.prototype.accelerationZ = 0; 74135 /** 74136 * The system variable pAccelerationX always contains the acceleration of the 74137 * device along the x axis in the frame previous to the current frame. Value 74138 * is represented as meters per second squared. 74139 * 74140 * @property {Number} pAccelerationX 74141 * @readOnly 74142 */ 74143 _main.default.prototype.pAccelerationX = 0; 74144 /** 74145 * The system variable pAccelerationY always contains the acceleration of the 74146 * device along the y axis in the frame previous to the current frame. Value 74147 * is represented as meters per second squared. 74148 * 74149 * @property {Number} pAccelerationY 74150 * @readOnly 74151 */ 74152 _main.default.prototype.pAccelerationY = 0; 74153 /** 74154 * The system variable pAccelerationZ always contains the acceleration of the 74155 * device along the z axis in the frame previous to the current frame. Value 74156 * is represented as meters per second squared. 74157 * 74158 * @property {Number} pAccelerationZ 74159 * @readOnly 74160 */ 74161 _main.default.prototype.pAccelerationZ = 0; 74162 /** 74163 * _updatePAccelerations updates the pAcceleration values 74164 * 74165 * @private 74166 */ 74167 _main.default.prototype._updatePAccelerations = function () { 74168 this._setProperty('pAccelerationX', this.accelerationX); 74169 this._setProperty('pAccelerationY', this.accelerationY); 74170 this._setProperty('pAccelerationZ', this.accelerationZ); 74171 }; 74172 /** 74173 * The system variable rotationX always contains the rotation of the 74174 * device along the x axis. If the sketch <a href="#/p5/angleMode"> 74175 * angleMode()</a> is set to DEGREES, the value will be -180 to 180. If 74176 * it is set to RADIANS, the value will be -PI to PI. 74177 * 74178 * Note: The order the rotations are called is important, ie. if used 74179 * together, it must be called in the order Z-X-Y or there might be 74180 * unexpected behaviour. 74181 * 74182 * @property {Number} rotationX 74183 * @readOnly 74184 * @example 74185 * <div> 74186 * <code> 74187 * function setup() { 74188 * createCanvas(100, 100, WEBGL); 74189 * } 74190 * 74191 * function draw() { 74192 * background(200); 74193 * //rotateZ(radians(rotationZ)); 74194 * rotateX(radians(rotationX)); 74195 * //rotateY(radians(rotationY)); 74196 * box(200, 200, 200); 74197 * describe(`red horizontal line right, green vertical line bottom. 74198 * black background.`); 74199 * } 74200 * </code> 74201 * </div> 74202 */ 74203 _main.default.prototype.rotationX = 0; 74204 /** 74205 * The system variable rotationY always contains the rotation of the 74206 * device along the y axis. If the sketch <a href="#/p5/angleMode"> 74207 * angleMode()</a> is set to DEGREES, the value will be -90 to 90. If 74208 * it is set to RADIANS, the value will be -PI/2 to PI/2. 74209 * 74210 * Note: The order the rotations are called is important, ie. if used 74211 * together, it must be called in the order Z-X-Y or there might be 74212 * unexpected behaviour. 74213 * 74214 * @property {Number} rotationY 74215 * @readOnly 74216 * @example 74217 * <div> 74218 * <code> 74219 * function setup() { 74220 * createCanvas(100, 100, WEBGL); 74221 * } 74222 * 74223 * function draw() { 74224 * background(200); 74225 * //rotateZ(radians(rotationZ)); 74226 * //rotateX(radians(rotationX)); 74227 * rotateY(radians(rotationY)); 74228 * box(200, 200, 200); 74229 * describe(`red horizontal line right, green vertical line bottom. 74230 * black background.`); 74231 * } 74232 * </code> 74233 * </div> 74234 */ 74235 _main.default.prototype.rotationY = 0; 74236 /** 74237 * The system variable rotationZ always contains the rotation of the 74238 * device along the z axis. If the sketch <a href="#/p5/angleMode"> 74239 * angleMode()</a> is set to DEGREES, the value will be 0 to 360. If 74240 * it is set to RADIANS, the value will be 0 to 2*PI. 74241 * 74242 * Unlike rotationX and rotationY, this variable is available for devices 74243 * with a built-in compass only. 74244 *
74245 * Note: The order the rotations are called is important, ie. if used 74246 * together, it must be called in the order Z-X-Y or there might be 74247 * unexpected behaviour. 74248 * 74249 * @example 74250 * <div> 74251 * <code> 74252 * function setup() { 74253 * createCanvas(100, 100, WEBGL); 74254 * } 74255 * 74256 * function draw() { 74257 * background(200); 74258 * rotateZ(radians(rotationZ)); 74259 * //rotateX(radians(rotationX)); 74260 * //rotateY(radians(rotationY)); 74261 * box(200, 200, 200); 74262 * describe(`red horizontal line right, green vertical line bottom. 74263 * black background.`); 74264 * } 74265 * </code> 74266 * </div> 74267 * 74268 * @property {Number} rotationZ 74269 * @readOnly 74270 */ 74271 _main.default.prototype.rotationZ = 0; 74272 /** 74273 * The system variable pRotationX always contains the rotation of the 74274 * device along the x axis in the frame previous to the current frame. 74275 * If the sketch <a href="#/p5/angleMode"> angleMode()</a> is set to DEGREES, 74276 * the value will be -180 to 180. If it is set to RADIANS, the value will 74277 * be -PI to PI. 74278 * 74279 * pRotationX can also be used with rotationX to determine the rotate 74280 * direction of the device along the X-axis. 74281 * @example 74282 * <div class='norender'> 74283 * <code> 74284 * // A simple if statement looking at whether 74285 * // rotationX - pRotationX < 0 is true or not will be 74286 * // sufficient for determining the rotate direction 74287 * // in most cases. 74288 * 74289 * // Some extra logic is needed to account for cases where 74290 * // the angles wrap around. 74291 * let rotateDirection = 'clockwise'; 74292 * 74293 * // Simple range conversion to make things simpler. 74294 * // This is not absolutely necessary but the logic 74295 * // will be different in that case. 74296 * 74297 * let rX = rotationX + 180; 74298 * let pRX = pRotationX + 180; 74299 * 74300 * if ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) { 74301 * rotateDirection = 'clockwise'; 74302 * } else if (rX - pRX < 0 || rX - pRX > 270) { 74303 * rotateDirection = 'counter-clockwise'; 74304 * } 74305 * 74306 * print(rotateDirection); 74307 * describe('no image to display.'); 74308 * </code> 74309 * </div> 74310 * 74311 * @property {Number} pRotationX 74312 * @readOnly 74313 */ 74314 _main.default.prototype.pRotationX = 0; 74315 /** 74316 * The system variable pRotationY always contains the rotation of the 74317 * device along the y axis in the frame previous to the current frame. 74318 * If the sketch <a href="#/p5/angleMode"> angleMode()</a> is set to DEGREES, 74319 * the value will be -90 to 90. If it is set to RADIANS, the value will 74320 * be -PI/2 to PI/2. 74321 * 74322 * pRotationY can also be used with rotationY to determine the rotate 74323 * direction of the device along the Y-axis. 74324 * @example 74325 * <div class='norender'> 74326 * <code> 74327 * // A simple if statement looking at whether 74328 * // rotationY - pRotationY < 0 is true or not will be 74329 * // sufficient for determining the rotate direction 74330 * // in most cases. 74331 * 74332 * // Some extra logic is needed to account for cases where 74333 * // the angles wrap around. 74334 * let rotateDirection = 'clockwise'; 74335 * 74336 * // Simple range conversion to make things simpler. 74337 * // This is not absolutely necessary but the logic 74338 * // will be different in that case. 74339 * 74340 * let rY = rotationY + 180; 74341 * let pRY = pRotationY + 180; 74342 * 74343 * if ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) { 74344 * rotateDirection = 'clockwise'; 74345 * } else if (rY - pRY < 0 || rY - pRY > 270) { 74346 * rotateDirection = 'counter-clockwise'; 74347 * } 74348 * print(rotateDirection); 74349 * describe('no image to display.'); 74350 * </code> 74351 * </div> 74352 * 74353 * @property {Number} pRotationY 74354 * @readOnly 74355 */ 74356 _main.default.prototype.pRotationY = 0; 74357 /** 74358 * The system variable pRotationZ always contains the rotation of the 74359 * device along the z axis in the frame previous to the current frame. 74360 * If the sketch <a href="#/p5/angleMode"> angleMode()</a> is set to DEGREES, 74361 * the value will be 0 to 360. If it is set to RADIANS, the value will 74362 * be 0 to 2*PI. 74363 * 74364 * pRotationZ can also be used with rotationZ to determine the rotate 74365 * direction of the device along the Z-axis. 74366 * @example 74367 * <div class='norender'> 74368 * <code> 74369 * // A simple if statement looking at whether 74370 * // rotationZ - pRotationZ < 0 is true or not will be 74371 * // sufficient for determining the rotate direction 74372 * // in most cases. 74373 * 74374 * // Some extra logic is needed to account for cases where 74375 * // the angles wrap around. 74376 * let rotateDirection = 'clockwise'; 74377 * 74378 * if ( 74379 * (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) || 74380 * rotationZ - pRotationZ < -270 74381 * ) { 74382 * rotateDirection = 'clockwise'; 74383 * } else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) { 74384 * rotateDirection = 'counter-clockwise'; 74385 * } 74386 * print(rotateDirection); 74387 * describe('no image to display.'); 74388 * </code> 74389 * </div> 74390 * 74391 * @property {Number} pRotationZ 74392 * @readOnly 74393 */ 74394 _main.default.prototype.pRotationZ = 0; 74395 var startAngleX = 0; 74396 var startAngleY = 0; 74397 var startAngleZ = 0; 74398 var rotateDirectionX = 'clockwise'; 74399 var rotateDirectionY = 'clockwise'; 74400 var rotateDirectionZ = 'clockwise'; 74401 _main.default.prototype.pRotateDirectionX = undefined; 74402 _main.default.prototype.pRotateDirectionY = undefined; 74403 _main.default.prototype.pRotateDirectionZ = undefined; 74404 _main.default.prototype._updatePRotations = function () { 74405 this._setProperty('pRotationX', this.rotationX); 74406 this._setProperty('pRotationY', this.rotationY); 74407 this._setProperty('pRotationZ', this.rotationZ); 74408 }; 74409 /** 74410 * When a device is rotated, the axis that triggers the <a href="#/p5/deviceTurned">deviceTurned()</a> 74411 * method is stored in the turnAxis variable. The turnAxis variable is only defined within 74412 * the scope of deviceTurned(). 74413 * @property {String} turnAxis 74414 * @readOnly 74415 * @example 74416 * <div> 74417 * <code> 74418 * // Run this example on a mobile device 74419 * // Rotate the device by 90 degrees in the 74420 * // X-axis to change the value. 74421 * 74422 * let value = 0; 74423 * function draw() { 74424 * fill(value); 74425 * rect(25, 25, 50, 50); 74426 * describe(`50-by-50 black rect in center of canvas. 74427 * turns white on mobile when device turns`); 74428 * describe(`50-by-50 black rect in center of canvas. 74429 * turns white on mobile when x-axis turns`); 74430 * } 74431 * function deviceTurned() { 74432 * if (turnAxis === 'X') { 74433 * if (value === 0) { 74434 * value = 255; 74435 * }
74435 else if (value === 255) { 74436 * value = 0; 74437 * } 74438 * } 74439 * } 74440 * </code> 74441 * </div> 74442 */ 74443 _main.default.prototype.turnAxis = undefined; 74444 var move_threshold = 0.5; 74445 var shake_threshold = 30; 74446 /** 74447 * The <a href="#/p5/setMoveThreshold">setMoveThreshold()</a> function is used to set the movement threshold for 74448 * the <a href="#/p5/deviceMoved">deviceMoved()</a> function. The default threshold is set to 0.5. 74449 * 74450 * @method setMoveThreshold 74451 * @param {number} value The threshold value 74452 * @example 74453 * <div class="norender"> 74454 * <code> 74455 * // Run this example on a mobile device 74456 * // You will need to move the device incrementally further 74457 * // the closer the square's color gets to white in order to change the value. 74458 * 74459 * let value = 0; 74460 * let threshold = 0.5; 74461 * function setup() { 74462 * setMoveThreshold(threshold); 74463 * } 74464 * function draw() { 74465 * fill(value); 74466 * rect(25, 25, 50, 50); 74467 * describe(`50-by-50 black rect in center of canvas. 74468 * turns white on mobile when device moves`); 74469 * } 74470 * function deviceMoved() { 74471 * value = value + 5; 74472 * threshold = threshold + 0.1; 74473 * if (value > 255) { 74474 * value = 0; 74475 * threshold = 30; 74476 * } 74477 * setMoveThreshold(threshold); 74478 * } 74479 * </code> 74480 * </div> 74481 */ 74482 _main.default.prototype.setMoveThreshold = function (val) { 74483 _main.default._validateParameters('setMoveThreshold', arguments); 74484 move_threshold = val; 74485 }; 74486 /** 74487 * The <a href="#/p5/setShakeThreshold">setShakeThreshold()</a> function is used to set the movement threshold for 74488 * the <a href="#/p5/deviceShaken">deviceShaken()</a> function. The default threshold is set to 30. 74489 * 74490 * @method setShakeThreshold 74491 * @param {number} value The threshold value 74492 * @example 74493 * <div class="norender"> 74494 * <code> 74495 * // Run this example on a mobile device 74496 * // You will need to shake the device more firmly 74497 * // the closer the box's fill gets to white in order to change the value. 74498 * 74499 * let value = 0; 74500 * let threshold = 30; 74501 * function setup() { 74502 * setShakeThreshold(threshold); 74503 * } 74504 * function draw() { 74505 * fill(value); 74506 * rect(25, 25, 50, 50); 74507 * describe(`50-by-50 black rect in center of canvas. 74508 * turns white on mobile when device is being shaked`); 74509 * } 74510 * function deviceMoved() { 74511 * value = value + 5; 74512 * threshold = threshold + 5; 74513 * if (value > 255) { 74514 * value = 0; 74515 * threshold = 30; 74516 * } 74517 * setShakeThreshold(threshold); 74518 * } 74519 * </code> 74520 * </div> 74521 */ 74522 _main.default.prototype.setShakeThreshold = function (val) { 74523 _main.default._validateParameters('setShakeThreshold', arguments); 74524 shake_threshold = val; 74525 }; 74526 /** 74527 * The <a href="#/p5/deviceMoved">deviceMoved()</a> function is called when the device is moved by more than 74528 * the threshold value along X, Y or Z axis. The default threshold is set to 0.5. 74529 * The threshold value can be changed using <a href="https://p5js.org/reference/#/p5/setMoveThreshold">setMoveThreshold()</a>. 74530 * 74531 * @method deviceMoved 74532 * @example 74533 * <div class="norender"> 74534 * <code> 74535 * // Run this example on a mobile device 74536 * // Move the device around 74537 * // to change the value. 74538 * 74539 * let value = 0; 74540 * function draw() { 74541 * fill(value); 74542 * rect(25, 25, 50, 50); 74543 * describe(`50-by-50 black rect in center of canvas. 74544 * turns white on mobile when device moves`); 74545 * } 74546 * function deviceMoved() { 74547 * value = value + 5; 74548 * if (value > 255) { 74549 * value = 0; 74550 * } 74551 * } 74552 * </code> 74553 * </div> 74554 */ 74555 /** 74556 * The <a href="#/p5/deviceTurned">deviceTurned()</a> function is called when the device rotates by 74557 * more than 90 degrees continuously. 74558 * 74559 * The axis that triggers the <a href="#/p5/deviceTurned">deviceTurned()</a> method is stored in the turnAxis 74560 * variable. The <a href="#/p5/deviceTurned">deviceTurned()</a> method can be locked to trigger on any axis: 74561 * X, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'. 74562 * 74563 * @method deviceTurned 74564 * @example 74565 * <div class="norender"> 74566 * <code> 74567 * // Run this example on a mobile device 74568 * // Rotate the device by 90 degrees 74569 * // to change the value. 74570 * 74571 * let value = 0; 74572 * function draw() { 74573 * fill(value); 74574 * rect(25, 25, 50, 50); 74575 * describe(`50-by-50 black rect in center of canvas. 74576 * turns white on mobile when device turns`); 74577 * } 74578 * function deviceTurned() { 74579 * if (value === 0) { 74580 * value = 255; 74581 * }
74581 else if (value === 255) { 74582 * value = 0; 74583 * } 74584 * } 74585 * </code> 74586 * </div> 74587 * <div> 74588 * <code> 74589 * // Run this example on a mobile device 74590 * // Rotate the device by 90 degrees in the 74591 * // X-axis to change the value. 74592 * 74593 * let value = 0; 74594 * function draw() { 74595 * fill(value); 74596 * rect(25, 25, 50, 50); 74597 * describe(`50-by-50 black rect in center of canvas. 74598 * turns white on mobile when x-axis turns`); 74599 * } 74600 * function deviceTurned() { 74601 * if (turnAxis === 'X') { 74602 * if (value === 0) { 74603 * value = 255; 74604 * } else if (value === 255) { 74605 * value = 0; 74606 * } 74607 * } 74608 * } 74609 * </code> 74610 * </div> 74611 */ 74612 /** 74613 * The <a href="#/p5/deviceShaken">deviceShaken()</a> function is called when the device total acceleration 74614 * changes of accelerationX and accelerationY values is more than 74615 * the threshold value. The default threshold is set to 30. 74616 * The threshold value can be changed using <a href="https://p5js.org/reference/#/p5/setShakeThreshold">setShakeThreshold()</a>. 74617 * 74618 * @method deviceShaken 74619 * @example 74620 * <div class="norender"> 74621 * <code> 74622 * // Run this example on a mobile device 74623 * // Shake the device to change the value. 74624 * 74625 * let value = 0; 74626 * function draw() { 74627 * fill(value); 74628 * rect(25, 25, 50, 50); 74629 * describe(`50-by-50 black rect in center of canvas. 74630 * turns white on mobile when device shakes`); 74631 * } 74632 * function deviceShaken() { 74633 * value = value + 5; 74634 * if (value > 255) { 74635 * value = 0; 74636 * } 74637 * } 74638 * </code> 74639 * </div> 74640 */ 74641 _main.default.prototype._ondeviceorientation = function (e) { 74642 this._updatePRotations(); 74643 if (this._angleMode === constants.radians) { 74644 e.beta = e.beta * (_PI / 180); 74645 e.gamma = e.gamma * (_PI / 180); 74646 e.alpha = e.alpha * (_PI / 180); 74647 } 74648 this._setProperty('rotationX', e.beta); 74649 this._setProperty('rotationY', e.gamma); 74650 this._setProperty('rotationZ', e.alpha); 74651 this._handleMotion(); 74652 }; 74653 _main.default.prototype._ondevicemotion = function (e) { 74654 this._updatePAccelerations(); 74655 this._setProperty('accelerationX', e.acceleration.x * 2); 74656 this._setProperty('accelerationY', e.acceleration.y * 2); 74657 this._setProperty('accelerationZ', e.acceleration.z * 2); 74658 this._handleMotion(); 74659 }; 74660 _main.default.prototype._handleMotion = function () { 74661 if (window.orientation === 90 || window.orientation === - 90) { 74662 this._setProperty('deviceOrientation', 'landscape'); 74663 } else if (window.orientation === 0) { 74664 this._setProperty('deviceOrientation', 'portrait'); 74665 } else if (window.orientation === undefined) { 74666 this._setProperty('deviceOrientation', 'undefined'); 74667 } 74668 var context = this._isGlobal ? window : this; 74669 if (typeof context.deviceMoved === 'function') { 74670 if (Math.abs(this.accelerationX - this.pAccelerationX) > move_threshold || Math.abs(this.accelerationY - this.pAccelerationY) > move_threshold || Math.abs(this.accelerationZ - this.pAccelerationZ) > move_threshold) { 74671 context.deviceMoved(); 74672 } 74673 } 74674 if (typeof context.deviceTurned === 'function') { 74675 // The angles given by rotationX etc is from range -180 to 180. 74676 // The following will convert them to 0 to 360 for ease of calculation 74677 // of cases when the angles wrapped around. 74678 // _startAngleX will be converted back at the end and updated. 74679 var wRX = this.rotationX + 180; 74680 var wPRX = this.pRotationX + 180; 74681 var wSAX = startAngleX + 180; 74682 if (wRX - wPRX > 0 && wRX - wPRX < 270 || wRX - wPRX < - 270) { 74683 rotateDirectionX = 'clockwise'; 74684 } else if (wRX - wPRX < 0 || wRX - wPRX > 270) { 74685 rotateDirectionX = 'counter-clockwise'; 74686 } 74687 if (rotateDirectionX !== this.pRotateDirectionX) { 74688 wSAX = wRX; 74689 } 74690 if (Math.abs(wRX - wSAX) > 90 && Math.abs(wRX - wSAX) < 270) { 74691 wSAX = wRX; 74692 this._setProperty('turnAxis', 'X'); 74693 context.deviceTurned(); 74694 } 74695 this.pRotateDirectionX = rotateDirectionX; 74696 startAngleX = wSAX - 180; // Y-axis is identical to X-axis except for changing some names. 74697 var wRY = this.rotationY + 180; 74698 var wPRY = this.pRotationY + 180; 74699 var wSAY = startAngleY + 180; 74700 if (wRY - wPRY > 0 && wRY - wPRY < 270 || wRY - wPRY < - 270) { 74701 rotateDirectionY = 'clockwise'; 74702 } else if (wRY - wPRY < 0 || wRY - this.pRotationY > 270) { 74703 rotateDirectionY = 'counter-clockwise'; 74704 } 74705 if (rotateDirectionY !== this.pRotateDirectionY) { 74706 wSAY = wRY; 74707 } 74708 if (Math.abs(wRY - wSAY) > 90 && Math.abs(wRY - wSAY) < 270) { 74709 wSAY = wRY; 74710 this._setProperty('turnAxis', 'Y'); 74711 context.deviceTurned(); 74712 } 74713 this.pRotateDirectionY = rotateDirectionY; 74714 startAngleY = wSAY - 180; // Z-axis is already in the range 0 to 360 74715 // so no conversion is needed. 74716 if (this.rotationZ - this.pRotationZ > 0 && this.rotationZ - this.pRotationZ < 270 || this.rotationZ - this.pRotationZ < - 270) { 74717 rotateDirectionZ = 'clockwise'; 74718 } else if (this.rotationZ - this.pRotationZ < 0 || this.rotationZ - this.pRotationZ > 270) { 74719 rotateDirectionZ = 'counter-clockwise'; 74720 } 74721 if (rotateDirectionZ !== this.pRotateDirectionZ) { 74722 startAngleZ = this.rotationZ; 74723 } 74724 if (Math.abs(this.rotationZ - startAngleZ) > 90 && Math.abs(this.rotationZ - startAngleZ) < 270) { 74725 startAngleZ = this.rotationZ; 74726 this._setProperty('turnAxis', 'Z'); 74727 context.deviceTurned(); 74728 } 74729 this.pRotateDirectionZ = rotateDirectionZ; 74730 this._setProperty('turnAxis', undefined); 74731 } 74732 if (typeof context.deviceShaken === 'function') { 74733 var accelerationChangeX; 74734 var accelerationChangeY; // Add accelerationChangeZ if acceleration change on Z is needed 74735 if (this.pAccelerationX !== null) { 74736 accelerationChangeX = Math.abs(this.accelerationX - this.pAccelerationX); 74737 accelerationChangeY = Math.abs(this.accelerationY - this.pAccelerationY); 74738 } 74739 if (accelerationChangeX + accelerationChangeY > shake_threshold) { 74740 context.deviceShaken(); 74741 } 74742 } 74743 }; 74744 var _default = _main.default; 74745 exports.default = _default; 74746 }, 74747 { 74748 '../core/constants': 278, 74749 '../core/main': 290, 74750 'core-js/modules/es.array.iterator': 176, 74751 'core-js/modules/es.object.get-own-property-descriptor': 191, 74752 'core-js/modules/es.object.to-string': 195, 74753 'core-js/modules/es.string.iterator': 204, 74754 'core-js/modules/es.symbol': 214, 74755 'core-js/modules/es.symbol.description': 212, 74756 'core-js/modules/es.symbol.iterator': 213, 74757 'core-js/modules/es.weak-map': 246, 74758 'core-js/modules/web.dom-collections.iterator': 248 74759 } 74760 ], 74761 308: [
74762 function (_dereq_, module, exports) { 74763 'use strict'; 74764 Object.defineProperty(exports, '__esModule', { 74765 value: true 74766 }); 74767 exports.default = void 0; 74768 var _main = _interopRequireDefault(_dereq_('../core/main')); 74769 function _interopRequireDefault(obj) { 74770 return obj && obj.__esModule ? obj : { 74771 default: 74772 obj 74773 }; 74774 } /** 74775 * @module Events 74776 * @submodule Keyboard 74777 * @for p5 74778 * @requires core 74779 */ 74780 /** 74781 * The boolean system variable <a href="#/p5/keyIsPressed">keyIsPressed</a> is true if any key is pressed 74782 * and false if no keys are pressed. 74783 * 74784 * @property {Boolean} keyIsPressed 74785 * @readOnly 74786 * @example 74787 * <div> 74788 * <code> 74789 * function draw() { 74790 * if (keyIsPressed === true) { 74791 * fill(0); 74792 * } else { 74793 * fill(255); 74794 * } 74795 * rect(25, 25, 50, 50); 74796 * describe('50-by-50 white rect that turns black on keypress.'); 74797 * } 74798 * </code> 74799 * </div> 74800 */ 74801 74802 _main.default.prototype.isKeyPressed = false; 74803 _main.default.prototype.keyIsPressed = false; // khan 74804 /** 74805 * The system variable key always contains the value of the most recent 74806 * key on the keyboard that was typed. To get the proper capitalization, it 74807 * is best to use it within <a href="#/p5/keyTyped">keyTyped()</a>. For non-ASCII keys, use the <a href="#/p5/keyCode">keyCode</a> 74808 * variable. 74809 * 74810 * @property {String} key 74811 * @readOnly 74812 * @example 74813 * <div><code> 74814 * // Click any key to display it! 74815 * // (Not Guaranteed to be Case Sensitive) 74816 * function setup() { 74817 * fill(245, 123, 158); 74818 * textSize(50); 74819 * } 74820 * 74821 * function draw() { 74822 * background(200); 74823 * text(key, 33, 65); // Display last key pressed.
74824 * describe('canvas displays any key value that is pressed in pink font.'); 74825 * } 74826 * </code></div> 74827 */ 74828 _main.default.prototype.key = ''; 74829 /** 74830 * The variable keyCode is used to detect special keys such as BACKSPACE, 74831 * DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW, 74832 * DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW. 74833 * You can also check for custom keys by looking up the keyCode of any key 74834 * on a site like this: <a href="http://keycode.info/">keycode.info</a>. 74835 * 74836 * @property {Integer} keyCode 74837 * @readOnly 74838 * @example 74839 * <div><code> 74840 * let fillVal = 126; 74841 * function draw() { 74842 * fill(fillVal); 74843 * rect(25, 25, 50, 50); 74844 * describe(`Grey rect center. turns white when up arrow pressed and black when down. 74845 * Display key pressed and its keyCode in a yellow box.`); 74846 * } 74847 * 74848 * function keyPressed() { 74849 * if (keyCode === UP_ARROW) { 74850 * fillVal = 255; 74851 * } else if (keyCode === DOWN_ARROW) { 74852 * fillVal = 0; 74853 * } 74854 * } 74855 * </code></div> 74856 * <div><code> 74857 * function draw() {} 74858 * function keyPressed() { 74859 * background('yellow'); 74860 * text(`${key} ${keyCode}`, 10, 40); 74861 * print(key, ' ', keyCode); 74862 * } 74863 * </code></div> 74864 */ 74865 _main.default.prototype.keyCode = 0; 74866 /** 74867 * The <a href="#/p5/keyPressed">keyPressed()</a> function is called once every time a key is pressed. The 74868 * keyCode for the key that was pressed is stored in the <a href="#/p5/keyCode">keyCode</a> variable. 74869 * 74870 * For non-ASCII keys, use the keyCode variable. You can check if the keyCode 74871 * equals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, 74872 * OPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW. 74873 * 74874 * For ASCII keys, the key that was pressed is stored in the key variable. However, it 74875 * does not distinguish between uppercase and lowercase. For this reason, it 74876 * is recommended to use <a href="#/p5/keyTyped">keyTyped()</a> to read the key variable, in which the 74877 * case of the variable will be distinguished.
74878 * 74879 * Because of how operating systems handle key repeats, holding down a key 74880 * may cause multiple calls to <a href="#/p5/keyTyped">keyTyped()</a> (and <a href="#/p5/keyReleased">keyReleased()</a> as well). The 74881 * rate of repeat is set by the operating system and how each computer is 74882 * configured.<br><br> 74883 * Browsers may have different default 74884 * behaviors attached to various key events. To prevent any default 74885 * behavior for this event, add "return false" to the end of the method. 74886 * 74887 * @method keyPressed 74888 * @param {Object} [event] optional KeyboardEvent callback argument. 74889 * @example 74890 * <div> 74891 * <code> 74892 * let value = 0; 74893 * function draw() { 74894 * fill(value); 74895 * rect(25, 25, 50, 50); 74896 * describe(`black rect center. turns white when key pressed and black 74897 * when released.`); 74898 * } 74899 * function keyPressed() { 74900 * if (value === 0) { 74901 * value = 255; 74902 * } else { 74903 * value = 0; 74904 * } 74905 * } 74906 * </code> 74907 * </div> 74908 * <div> 74909 * <code> 74910 * let value = 0; 74911 * function draw() { 74912 * fill(value); 74913 * rect(25, 25, 50, 50); 74914 * describe(`black rect center. turns white when left arrow pressed and 74915 * black when right.`); 74916 * } 74917 * function keyPressed() { 74918 * if (keyCode === LEFT_ARROW) { 74919 * value = 255; 74920 * } else if (keyCode === RIGHT_ARROW) { 74921 * value = 0; 74922 * } 74923 * } 74924 * </code> 74925 * </div> 74926 * <div class="norender"> 74927 * <code> 74928 * function keyPressed() { 74929 * // Do something 74930 * return false; // prevent any default behaviour 74931 * } 74932 * </code> 74933 * </div> 74934 */ 74935 _main.default.prototype._onkeydown = function (e) { 74936 if (this._downKeys[e.which]) { 74937 // prevent multiple firings 74938 return; 74939 } 74940 this._setProperty('isKeyPressed', true); 74941 this._setProperty('keyIsPressed', true); 74942 this._setProperty('keyCode', e.which); 74943 this._downKeys[e.which] = true; 74944 this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which); 74945 var context = this._isGlobal ? window : this; 74946 if (typeof context.keyPressed === 'function' && !e.charCode) { 74947 var executeDefault = context.keyPressed(e); 74948 if (executeDefault === false) { 74949 e.preventDefault(); 74950 } 74951 } 74952 }; 74953 /** 74954 * The <a href="#/p5/keyReleased">keyReleased()</a> function is called once every time a key is released. 74955 * See <a href="#/p5/key">key</a> and <a href="#/p5/keyCode">keyCode</a> for more information.<br><br> 74956 * Browsers may have different default 74957 * behaviors attached to various key events. To prevent any default 74958 * behavior for this event, add "return false" to the end of the function. 74959 * 74960 * @method keyReleased 74961 * @param {Object} [event] optional KeyboardEvent callback argument. 74962 * @example 74963 * <div> 74964 * <code> 74965 * let value = 0; 74966 * function draw() { 74967 * fill(value); 74968 * rect(25, 25, 50, 50); 74969 * describe(`black rect center. turns white when key pressed and black 74970 * when pressed again`); 74971 * } 74972 * function keyReleased() { 74973 * if (value === 0) { 74974 * value = 255; 74975 * } else { 74976 * value = 0; 74977 * } 74978 * return false; // prevent any default behavior 74979 * } 74980 * </code> 74981 * </div> 74982 */ 74983 _main.default.prototype._onkeyup = function (e) { 74984 this._downKeys[e.which] = false; 74985 if (!this._areDownKeys()) { 74986 this._setProperty('isKeyPressed', false); 74987 this._setProperty('keyIsPressed', false); 74988 } 74989 this._setProperty('_lastKeyCodeTyped', null); 74990 this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which); 74991 this._setProperty('keyCode', e.which); 74992 var context = this._isGlobal ? window : this; 74993 if (typeof context.keyReleased === 'function') { 74994 var executeDefault = context.keyReleased(e); 74995 if (executeDefault === false) { 74996 e.preventDefault(); 74997 } 74998 } 74999 }; 75000 /** 75001 * The <a href="#/p5/keyTyped">keyTyped()</a> function is called once every time a key is pressed, but 75002 * action keys such as Backspace, Delete, Ctrl, Shift, and Alt are ignored. If you are trying to detect 75003 * a keyCode for one of these keys, use the <a href="#/p5/keyPressed">keyPressed()</a> function instead. 75004 * The most recent key typed will be stored in the key variable. 75005 * 75006 * Because of how operating systems handle key repeats, holding down a key 75007 * will cause multiple calls to <a href="#/p5/keyTyped">keyTyped()</a> (and <a href="#/p5/keyReleased">keyReleased()</a> as well). The 75008 * rate of repeat is set by the operating system and how each computer is 75009 * configured.<br><br> 75010 * Browsers may have different default behaviors attached to various key 75011 * events. To prevent any default behavior for this event, add "return false" 75012 * to the end of the function. 75013 * 75014 * @method keyTyped 75015 * @param {Object} [event] optional KeyboardEvent callback argument. 75016 * @example 75017 * <div> 75018 * <code> 75019 * let value = 0; 75020 * function draw() { 75021 * fill(value); 75022 * rect(25, 25, 50, 50); 75023 * describe(`black rect center. turns white when 'a' key typed and 75024 * black when 'b' pressed`); 75025 * } 75026 * function keyTyped() { 75027 * if (key === 'a') { 75028 * value = 255; 75029 * } else if (key === 'b') { 75030 * value = 0; 75031 * } 75032 * // uncomment to prevent any default behavior 75033 * // return false;
75034 * } 75035 * </code> 75036 * </div> 75037 */ 75038 _main.default.prototype._onkeypress = function (e) { 75039 if (e.which === this._lastKeyCodeTyped) { 75040 // prevent multiple firings 75041 return; 75042 } 75043 this._setProperty('_lastKeyCodeTyped', e.which); // track last keyCode 75044 this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which); 75045 var context = this._isGlobal ? window : this; 75046 if (typeof context.keyTyped === 'function') { 75047 var executeDefault = context.keyTyped(e); 75048 if (executeDefault === false) { 75049 e.preventDefault(); 75050 } 75051 } 75052 }; 75053 /** 75054 * The onblur function is called when the user is no longer focused 75055 * on the p5 element. Because the keyup events will not fire if the user is 75056 * not focused on the element we must assume all keys currently down have 75057 * been released. 75058 */ 75059 _main.default.prototype._onblur = function (e) { 75060 this._downKeys = { 75061 }; 75062 }; 75063 /** 75064 * The <a href="#/p5/keyIsDown">keyIsDown()</a> function checks if the key is currently down, i.e. pressed. 75065 * It can be used if you have an object that moves, and you want several keys 75066 * to be able to affect its behaviour simultaneously, such as moving a 75067 * sprite diagonally. You can put in any number representing the keyCode of 75068 * the key, or use any of the variable <a href="#/p5/keyCode">keyCode</a> names listed 75069 * <a href="http://p5js.org/reference/#p5/keyCode">here</a>. 75070 * 75071 * @method keyIsDown 75072 * @param {Number} code The key to check for. 75073 * @return {Boolean} whether key is down or not 75074 * @example 75075 * <div><code> 75076 * let x = 100; 75077 * let y = 100; 75078 * 75079 * function setup() { 75080 * createCanvas(512, 512); 75081 * fill(255, 0, 0); 75082 * } 75083 * 75084 * function draw() { 75085 * if (keyIsDown(LEFT_ARROW)) { 75086 * x -= 5; 75087 * } 75088 * 75089 * if (keyIsDown(RIGHT_ARROW)) { 75090 * x += 5; 75091 * } 75092 * 75093 * if (keyIsDown(UP_ARROW)) { 75094 * y -= 5; 75095 * } 75096 * 75097 * if (keyIsDown(DOWN_ARROW)) { 75098 * y += 5; 75099 * } 75100 * 75101 * clear(); 75102 * ellipse(x, y, 50, 50); 75103 * describe(`50-by-50 red ellipse moves left, right, up, and 75104 * down with arrow presses.`); 75105 * } 75106 * </code></div> 75107 * 75108 * <div><code> 75109 * let diameter = 50; 75110 * 75111 * function setup() { 75112 * createCanvas(512, 512); 75113 * } 75114 * 75115 * function draw() { 75116 * // 107 and 187 are keyCodes for "+" 75117 * if (keyIsDown(107) || keyIsDown(187)) { 75118 * diameter += 1; 75119 * } 75120 * 75121 * // 109 and 189 are keyCodes for "-" 75122 * if (keyIsDown(109) || keyIsDown(189)) { 75123 * diameter -= 1; 75124 * } 75125 * 75126 * clear(); 75127 * fill(255, 0, 0); 75128 * ellipse(50, 50, diameter, diameter); 75129 * describe(`50-by-50 red ellipse gets bigger or smaller when 75130 * + or - are pressed.`); 75131 * } 75132 * </code></div> 75133 */ 75134 _main.default.prototype.keyIsDown = function (code) { 75135 _main.default._validateParameters('keyIsDown', arguments); 75136 return this._downKeys[code] || false; 75137 }; 75138 /** 75139 * The _areDownKeys function returns a boolean true if any keys pressed 75140 * and a false if no keys are currently pressed. 75141 75142 * Helps avoid instances where multiple keys are pressed simultaneously and 75143 * releasing a single key will then switch the 75144 * keyIsPressed property to true. 75145 * @private 75146**/ 75147 _main.default.prototype._areDownKeys = function () { 75148 for (var key in this._downKeys) { 75149 if (this._downKeys.hasOwnProperty(key) && this._downKeys[key] === true) { 75150 return true; 75151 } 75152 } 75153 return false; 75154 }; 75155 var _default = _main.default; 75156 exports.default = _default; 75157 }, 75158 { 75159 '../core/main': 290 75160 } 75161 ], 75162 309: [ 75163 function (_dereq_, module, exports) { 75164 'use strict'; 75165 _dereq_('core-js/modules/es.symbol'); 75166 _dereq_('core-js/modules/es.symbol.description'); 75167 _dereq_('core-js/modules/es.symbol.iterator'); 75168 _dereq_('core-js/modules/es.array.includes'); 75169 _dereq_('core-js/modules/es.array.iterator'); 75170 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 75171 _dereq_('core-js/modules/es.object.to-string'); 75172 _dereq_('core-js/modules/es.string.includes'); 75173 _dereq_('core-js/modules/es.string.iterator'); 75174 _dereq_('core-js/modules/es.weak-map'); 75175 _dereq_('core-js/modules/web.dom-collections.iterator'); 75176 function _typeof2(obj) { 75177 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 75178 _typeof2 = function _typeof2(obj) { 75179 return typeof obj; 75180 }; 75181 } else { 75182 _typeof2 = function _typeof2(obj) { 75183 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 75184 }; 75185 } 75186 return _typeof2(obj); 75187 } 75188 function _typeof(obj) { 75189 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 75190 _typeof = function _typeof(obj) { 75191 return _typeof2(obj); 75192 }; 75193 } else { 75194 _typeof = function _typeof(obj) { 75195 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
75195ypeof2(obj); 75196 }; 75197 } 75198 return _typeof(obj); 75199 } 75200 _dereq_('core-js/modules/es.array.includes'); 75201 _dereq_('core-js/modules/es.string.includes'); 75202 Object.defineProperty(exports, '__esModule', { 75203 value: true 75204 }); 75205 exports.default = void 0; 75206 var _main = _interopRequireDefault(_dereq_('../core/main')); 75207 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 75208 function _getRequireWildcardCache() { 75209 if (typeof WeakMap !== 'function') return null; 75210 var cache = new WeakMap(); 75211 _getRequireWildcardCache = function _getRequireWildcardCache() { 75212 return cache; 75213 }; 75214 return cache; 75215 } 75216 function _interopRequireWildcard(obj) { 75217 if (obj && obj.__esModule) { 75218 return obj; 75219 } 75220 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 75221 return { 75222 default: 75223 obj 75224 }; 75225 } 75226 var cache = _getRequireWildcardCache(); 75227 if (cache && cache.has(obj)) { 75228 return cache.get(obj); 75229 } 75230 var newObj = { 75231 }; 75232 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 75233 for (var key in obj) { 75234 if (Object.prototype.hasOwnProperty.call(obj, key)) { 75235 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 75236 if (desc && (desc.get || desc.set)) { 75237 Object.defineProperty(newObj, key, desc); 75238 } else { 75239 newObj[key] = obj[key]; 75240 } 75241 } 75242 } 75243 newObj.default = obj; 75244 if (cache) { 75245 cache.set(obj, newObj); 75246 } 75247 return newObj; 75248 } 75249 function _interopRequireDefault(obj) { 75250 return obj && obj.__esModule ? obj : { 75251 default: 75252 obj 75253 }; 75254 } /** 75255 * @module Events 75256 * @submodule Mouse 75257 * @for p5 75258 * @requires core 75259 * @requires constants 75260 */ 75261 /** 75262 * 75263 * The variable movedX contains the horizontal movement of the mouse since the last frame 75264 * @property {Number} movedX 75265 * @readOnly 75266 * @example 75267 * <div class="notest"> 75268 * <code> 75269 * let x = 50; 75270 * function setup() { 75271 * rectMode(CENTER); 75272 * } 75273 * 75274 * function draw() { 75275 * if (x > 48) { 75276 * x -= 2; 75277 * } else if (x < 48) { 75278 * x += 2; 75279 * } 75280 * x += floor(movedX / 5); 75281 * background(237, 34, 93); 75282 * fill(0); 75283 * rect(x, 50, 50, 50); 75284 * describe(`box moves left and right according to mouse movement 75285 * then slowly back towards the center`); 75286 * } 75287 * </code> 75288 * </div> 75289 */ 75290 75291 _main.default.prototype.movedX = 0; 75292 /** 75293 * The variable movedY contains the vertical movement of the mouse since the last frame 75294 * @property {Number} movedY 75295 * @readOnly 75296 * @example 75297 * <div class="notest"> 75298 * <code> 75299 * let y = 50; 75300 * function setup() { 75301 * rectMode(CENTER); 75302 * } 75303 * 75304 * function draw() { 75305 * if (y > 48) { 75306 * y -= 2; 75307 * } else if (y < 48) { 75308 * y += 2; 75309 * } 75310 * y += floor(movedY / 5); 75311 * background(237, 34, 93); 75312 * fill(0); 75313 * rect(50, y, 50, 50); 75314 * describe(`box moves up and down according to mouse movement then 75315 * slowly back towards the center`); 75316 * } 75317 * </code> 75318 * </div> 75319 */ 75320 _main.default.prototype.movedY = 0; 75321 /* 75322 * This is a flag which is false until the first time 75323 * we receive a mouse event. The pmouseX and pmouseY 75324 * values will match the mouseX and mouseY values until 75325 * this interaction takes place. 75326 */ 75327 _main.default.prototype._hasMouseInteracted = false; 75328 /** 75329 * The system variable mouseX always contains the current horizontal 75330 * position of the mouse, relative to (0, 0) of the canvas. The value at 75331 * the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL. 75332 * If touch is used instead of mouse input, mouseX will hold the x value 75333 * of the most recent touch point. 75334 * 75335 * @property {Number} mouseX 75336 * @readOnly 75337 * 75338 * @example 75339 * <div> 75340 * <code> 75341 * // Move the mouse across the canvas 75342 * function draw() { 75343 * background(244, 248, 252); 75344 * line(mouseX, 0, mouseX, 100); 75345 * describe('horizontal black line moves left and right with mouse x-position'); 75346 * } 75347 * </code> 75348 * </div> 75349 */ 75350 _main.default.prototype.mouseX = 0; 75351 /** 75352 * The system variable mouseY always contains the current vertical 75353 * position of the mouse, relative to (0, 0) of the canvas. The value at 75354 * the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL.
75355 * If touch is used instead of mouse input, mouseY will hold the y value 75356 * of the most recent touch point. 75357 * 75358 * @property {Number} mouseY 75359 * @readOnly 75360 * 75361 * @example 75362 * <div> 75363 * <code> 75364 * // Move the mouse across the canvas 75365 * function draw() { 75366 * background(244, 248, 252); 75367 * line(0, mouseY, 100, mouseY); 75368 * describe('vertical black line moves up and down with mouse y-position'); 75369 * } 75370 * </code> 75371 * </div> 75372 */ 75373 _main.default.prototype.mouseY = 0; 75374 /** 75375 * The system variable pmouseX always contains the horizontal position of 75376 * the mouse or finger in the frame previous to the current frame, relative to 75377 * (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and 75378 * (-width/2, -height/2) for WebGL. Note: pmouseX will be reset to the current mouseX 75379 * value at the start of each touch event. 75380 * 75381 * @property {Number} pmouseX 75382 * @readOnly 75383 * 75384 * @example 75385 * <div> 75386 * <code> 75387 * // Move the mouse across the canvas to leave a trail 75388 * function setup() { 75389 * //slow down the frameRate to make it more visible 75390 * frameRate(10); 75391 * } 75392 * 75393 * function draw() { 75394 * background(244, 248, 252); 75395 * line(mouseX, mouseY, pmouseX, pmouseY); 75396 * print(pmouseX + ' -> ' + mouseX); 75397 * describe(`line trail is created from cursor movements. 75398 * faster movement make longer line.`); 75399 * } 75400 * </code> 75401 * </div> 75402 */ 75403 _main.default.prototype.pmouseX = 0; 75404 /** 75405 * The system variable pmouseY always contains the vertical position of 75406 * the mouse or finger in the frame previous to the current frame, relative to 75407 * (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and 75408 * (-width/2, -height/2) for WebGL. Note: pmouseY will be reset to the current mouseY 75409 * value at the start of each touch event. 75410 * 75411 * @property {Number} pmouseY 75412 * @readOnly 75413 * 75414 * @example 75415 * <div> 75416 * <code> 75417 * function draw() { 75418 * background(237, 34, 93); 75419 * fill(0); 75420 * //draw a square only if the mouse is not moving 75421 * if (mouseY === pmouseY && mouseX === pmouseX) { 75422 * rect(20, 20, 60, 60); 75423 * } 75424 * 75425 * print(pmouseY + ' -> ' + mouseY); 75426 * describe(`60-by-60 black rect center, fuchsia background. 75427 * rect flickers on mouse movement`); 75428 * } 75429 * </code> 75430 * </div> 75431 */ 75432 _main.default.prototype.pmouseY = 0; 75433 /** 75434 * The system variable winMouseX always contains the current horizontal 75435 * position of the mouse, relative to (0, 0) of the window. 75436 * 75437 * @property {Number} winMouseX 75438 * @readOnly 75439 * 75440 * @example 75441 * <div> 75442 * <code> 75443 * let myCanvas; 75444 * 75445 * function setup() { 75446 * //use a variable to store a pointer to the canvas 75447 * myCanvas = createCanvas(100, 100); 75448 * let body = document.getElementsByTagName('body')[0]; 75449 * myCanvas.parent(body); 75450 * } 75451 * 75452 * function draw() { 75453 * background(237, 34, 93); 75454 * fill(0); 75455 * 75456 * //move the canvas to the horizontal mouse position 75457 * //relative to the window 75458 * myCanvas.position(winMouseX + 1, windowHeight / 2); 75459 * 75460 * //the y of the square is relative to the canvas 75461 * rect(20, mouseY, 60, 60); 75462 * describe(`60-by-60 black rect y moves with mouse y and fuchsia 75463 * canvas moves with mouse x`); 75464 * } 75465 * </code> 75466 * </div> 75467 */ 75468 _main.default.prototype.winMouseX = 0; 75469 /** 75470 * The system variable winMouseY always contains the current vertical 75471 * position of the mouse, relative to (0, 0) of the window. 75472 * 75473 * @property {Number} winMouseY 75474 * @readOnly 75475 * 75476 * @example 75477 * <div> 75478 * <code> 75479 * let myCanvas; 75480 * 75481 * function setup() { 75482 * //use a variable to store a pointer to the canvas 75483 * myCanvas = createCanvas(100, 100); 75484 * let body = document.getElementsByTagName('body')[0]; 75485 * myCanvas.parent(body); 75486 * } 75487 * 75488 * function draw() { 75489 * background(237, 34, 93); 75490 * fill(0); 75491 * 75492 * //move the canvas to the vertical mouse position 75493 * //relative to the window 75494 * myCanvas.position(windowWidth / 2, winMouseY + 1); 75495 * 75496 * //the x of the square is relative to the canvas 75497 * rect(mouseX, 20, 60, 60); 75498 * describe(`60-by-60 black rect x moves with mouse x and 75499 * fuchsia canvas y moves with mouse y`); 75500 * } 75501 * </code> 75502 * </div> 75503 */ 75504 _main.default.prototype.winMouseY = 0; 75505 /** 75506 * The system variable pwinMouseX always contains the horizontal position 75507 * of the mouse in the frame previous to the current frame, relative to 75508 * (0, 0) of the window. Note: pwinMouseX will be reset to the current winMouseX 75509 * value at the start of each touch event. 75510 * 75511 * @property {Number} pwinMouseX 75512 * @readOnly 75513 * 75514 * @example 75515 * <div> 75516 * <code> 75517 * let myCanvas; 75518 * 75519 * function setup() { 75520 * //use a variable to store a pointer to the canvas 75521 * myCanvas = createCanvas(100, 100); 75522 * noStroke(); 75523 * fill(237, 34, 93); 75524 * } 75525 * 75526 * function draw() { 75527 * clear(); 75528 * //the difference between previous and 75529 * //current x position is the horizontal mouse speed 75530 * let speed = abs(winMouseX - pwinMouseX); 75531 * //change the size of the circle 75532 * //according to the horizontal speed 75533 * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5); 75534 * //move the canvas to the mouse position
75535 * myCanvas.position(winMouseX + 1, winMouseY + 1); 75536 * describe(`fuchsia ellipse moves with mouse x and y. 75537 * Grows and shrinks with mouse speed`); 75538 * } 75539 * </code> 75540 * </div> 75541 */ 75542 _main.default.prototype.pwinMouseX = 0; 75543 /** 75544 * The system variable pwinMouseY always contains the vertical position of 75545 * the mouse in the frame previous to the current frame, relative to (0, 0) 75546 * of the window. Note: pwinMouseY will be reset to the current winMouseY 75547 * value at the start of each touch event. 75548 * 75549 * @property {Number} pwinMouseY 75550 * @readOnly 75551 * 75552 * @example 75553 * <div> 75554 * <code> 75555 * let myCanvas; 75556 * 75557 * function setup() { 75558 * //use a variable to store a pointer to the canvas 75559 * myCanvas = createCanvas(100, 100); 75560 * noStroke(); 75561 * fill(237, 34, 93); 75562 * } 75563 * 75564 * function draw() { 75565 * clear(); 75566 * //the difference between previous and 75567 * //current y position is the vertical mouse speed 75568 * let speed = abs(winMouseY - pwinMouseY); 75569 * //change the size of the circle 75570 * //according to the vertical speed 75571 * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5); 75572 * //move the canvas to the mouse position 75573 * myCanvas.position(winMouseX + 1, winMouseY + 1); 75574 * describe(`fuchsia ellipse moves with mouse x and y. 75575 * Grows and shrinks with mouse speed`); 75576 * } 75577 * </code> 75578 * </div> 75579 */ 75580 _main.default.prototype.pwinMouseY = 0; 75581 /** 75582 * p5 automatically tracks if the mouse button is pressed and which 75583 * button is pressed. The value of the system variable mouseButton is either 75584 * LEFT, RIGHT, or CENTER depending on which button was pressed last. 75585 * Warning: different browsers may track mouseButton differently. 75586 * 75587 * @property {Constant} mouseButton 75588 * @readOnly 75589 * 75590 * @example 75591 * <div> 75592 * <code> 75593 * function draw() { 75594 * background(237, 34, 93); 75595 * fill(0); 75596 * 75597 * if (mouseIsPressed === true) { 75598 * if (mouseButton === LEFT) { 75599 * ellipse(50, 50, 50, 50); 75600 * } 75601 * if (mouseButton === RIGHT) { 75602 * rect(25, 25, 50, 50); 75603 * } 75604 * if (mouseButton === CENTER) { 75605 * triangle(23, 75, 50, 20, 78, 75); 75606 * } 75607 * } 75608 * 75609 * print(mouseButton); 75610 * describe(`50-by-50 black ellipse appears on center of fuchsia 75611 * canvas on mouse click/press.`); 75612 * } 75613 * </code> 75614 * </div> 75615 */ 75616 _main.default.prototype.mouseButton = 0; 75617 /** 75618 * The boolean system variable mouseIsPressed is true if the mouse is pressed 75619 * and false if not. 75620 * 75621 * @property {Boolean} mouseIsPressed 75622 * @readOnly 75623 * 75624 * @example 75625 * <div> 75626 * <code> 75627 * function draw() { 75628 * background(237, 34, 93); 75629 * fill(0); 75630 * 75631 * if (mouseIsPressed === true) { 75632 * ellipse(50, 50, 50, 50); 75633 * } else { 75634 * rect(25, 25, 50, 50); 75635 * } 75636 * 75637 * print(mouseIsPressed); 75638 * describe(`black 50-by-50 rect becomes ellipse with mouse click/press. 75639 * fuchsia background.`); 75640 * } 75641 * </code> 75642 * </div> 75643 */ 75644 _main.default.prototype.mouseIsPressed = false; 75645 _main.default.prototype._updateNextMouseCoords = function (e) { 75646 if (this._curElement !== null && (!e.touches || e.touches.length > 0)) { 75647 var mousePos = getMousePos(this._curElement.elt, this.width, this.height, e); 75648 this._setProperty('movedX', e.movementX); 75649 this._setProperty('movedY', e.movementY); 75650 this._setProperty('mouseX', mousePos.x); 75651 this._setProperty('mouseY', mousePos.y); 75652 this._setProperty('winMouseX', mousePos.winX); 75653 this._setProperty('winMouseY', mousePos.winY); 75654 } 75655 if (!this._hasMouseInteracted) { 75656 // For first draw, make previous and next equal 75657 this._updateMouseCoords(); 75658 this._setProperty('_hasMouseInteracted', true); 75659 } 75660 }; 75661 _main.default.prototype._updateMouseCoords = function () { 75662 this._setProperty('pmouseX', this.mouseX); 75663 this._setProperty('pmouseY', this.mouseY); 75664 this._setProperty('pwinMouseX', this.winMouseX); 75665 this._setProperty('pwinMouseY', this.winMouseY); 75666 this._setProperty('_pmouseWheelDeltaY', this._mouseWheelDeltaY); 75667 }; 75668 function getMousePos(canvas, w, h, evt) { 75669 if (evt && !evt.clientX) { 75670 // use touches if touch and not mouse 75671 if (evt.touches) { 75672 evt = evt.touches[0]; 75673 } else if (evt.changedTouches) { 75674 evt = evt.changedTouches[0]; 75675 } 75676 } 75677 var rect = canvas.getBoundingClientRect(); 75678 var sx = canvas.scrollWidth / w || 1; 75679 var sy = canvas.scrollHeight / h || 1; 75680 return { 75681 x: (evt.clientX - rect.left) / sx, 75682 y: (evt.clientY - rect.top) / sy, 75683 winX: evt.clientX, 75684 winY: evt.clientY, 75685 id: evt.identifier 75686 }; 75687 } 75688 _main.default.prototype._setMouseButton = function (e) { 75689 if (e.button === 1) { 75690 this._setProperty('mouseButton', constants.CENTER); 75691 } else if (e.button === 2) { 75692 this._setProperty('mouseButton', constants.RIGHT); 75693 } else { 75694 this._setProperty('mouseButton', constants.LEFT); 75695 } 75696 }; 75697 /** 75698 * The <a href="#/p5/mouseMoved">mouseMoved()</a> function is called every time the mouse moves and a mouse 75699 * button is not pressed.<br><br> 75700 * Browsers may have different default 75701 * behaviors attached to various mouse events. To prevent any default 75702 * behavior for this event, add "return false" to the end of the method. 75703 * 75704 * @method mouseMoved 75705 * @param {Object} [event] optional MouseEvent callback argument. 75706 * @example 75707 * <div> 75708 * <code> 75709 * // Move the mouse across the page 75710 * // to change its value 75711 * 75712 * let value = 0; 75713 * function draw() { 75714 * fill(value); 75715 * rect(25, 25, 50, 50); 75716 * describe(`black 50-by-50 rect becomes lighter with mouse movements until 75717 * white then resets no image displayed`); 75718 * } 75719 * function mouseMoved() { 75720 * value = value + 5; 75721 * if (value > 255) { 75722 * value = 0; 75723 * } 75724 * } 75725 * </code> 75726 * </div> 75727 * 75728 * <div class="norender"> 75729 * <code> 75730 * function mouseMoved() { 75731 * ellipse(mouseX, mouseY, 5, 5); 75732 * // prevent default 75733 * return false;
75734 * } 75735 * </code> 75736 * </div> 75737 * 75738 * <div class="norender"> 75739 * <code> 75740 * // returns a MouseEvent object 75741 * // as a callback argument 75742 * function mouseMoved(event) { 75743 * console.log(event); 75744 * } 75745 * </code> 75746 * </div> 75747 */ 75748 /** 75749 * The <a href="#/p5/mouseDragged">mouseDragged()</a> function is called once every time the mouse moves and 75750 * a mouse button is pressed. If no <a href="#/p5/mouseDragged">mouseDragged()</a> function is defined, the 75751 * <a href="#/p5/touchMoved">touchMoved()</a> function will be called instead if it is defined.<br><br> 75752 * Browsers may have different default 75753 * behaviors attached to various mouse events. To prevent any default 75754 * behavior for this event, add "return false" to the end of the function. 75755 * 75756 * @method mouseDragged 75757 * @param {Object} [event] optional MouseEvent callback argument. 75758 * @example 75759 * <div> 75760 * <code> 75761 * // Drag the mouse across the page 75762 * // to change its value 75763 * 75764 * let value = 0; 75765 * function draw() { 75766 * fill(value); 75767 * rect(25, 25, 50, 50); 75768 * describe(`black 50-by-50 rect turns lighter with mouse click and 75769 * drag until white, resets`); 75770 * } 75771 * function mouseDragged() { 75772 * value = value + 5; 75773 * if (value > 255) { 75774 * value = 0; 75775 * } 75776 * } 75777 * </code> 75778 * </div> 75779 * 75780 * <div class="norender"> 75781 * <code> 75782 * function mouseDragged() { 75783 * ellipse(mouseX, mouseY, 5, 5); 75784 * // prevent default 75785 * return false; 75786 * } 75787 * </code> 75788 * </div> 75789 * 75790 * <div class="norender"> 75791 * <code> 75792 * // returns a MouseEvent object 75793 * // as a callback argument 75794 * function mouseDragged(event) { 75795 * console.log(event); 75796 * } 75797 * </code> 75798 * </div> 75799 */ 75800 _main.default.prototype._onmousemove = function (e) { 75801 var context = this._isGlobal ? window : this; 75802 var executeDefault; 75803 this._updateNextMouseCoords(e); 75804 if (!this.mouseIsPressed) { 75805 if (typeof context.mouseMoved === 'function') { 75806 executeDefault = context.mouseMoved(e); 75807 if (executeDefault === false) { 75808 e.preventDefault(); 75809 } 75810 } 75811 } else { 75812 if (typeof context.mouseDragged === 'function') { 75813 executeDefault = context.mouseDragged(e); 75814 if (executeDefault === false) { 75815 e.preventDefault(); 75816 } 75817 } else if (typeof context.touchMoved === 'function') { 75818 executeDefault = context.touchMoved(e); 75819 if (executeDefault === false) { 75820 e.preventDefault(); 75821 } 75822 } 75823 } 75824 }; 75825 /** 75826 * The <a href="#/p5/mousePressed">mousePressed()</a> function is called once after every time a mouse button 75827 * is pressed. The mouseButton variable (see the related reference entry) 75828 * can be used to determine which button has been pressed. If no 75829 * <a href="#/p5/mousePressed">mousePressed()</a> function is defined, the <a href="#/p5/touchStarted">touchStarted()</a> function will be 75830 * called instead if it is defined.<br><br> 75831 * Browsers may have different default 75832 * behaviors attached to various mouse events. To prevent any default 75833 * behavior for this event, add "return false" to the end of the function. 75834 * 75835 * @method mousePressed 75836 * @param {Object} [event] optional MouseEvent callback argument. 75837 * @example 75838 * <div> 75839 * <code> 75840 * // Click within the image to change 75841 * // the value of the rectangle 75842 * 75843 * let value = 0; 75844 * function draw() { 75845 * fill(value); 75846 * rect(25, 25, 50, 50); 75847 * describe('black 50-by-50 rect turns white with mouse click/press.'); 75848 * } 75849 * function mousePressed() { 75850 * if (value === 0) { 75851 * value = 255; 75852 * } else { 75853 * value = 0; 75854 * } 75855 * } 75856 * </code> 75857 * </div> 75858 * 75859 * <div class="norender"> 75860 * <code> 75861 * function mousePressed() { 75862 * ellipse(mouseX, mouseY, 5, 5); 75863 * // prevent default 75864 * return false; 75865 * } 75866 * </code> 75867 * </div> 75868 * 75869 * <div class="norender"> 75870 * <code> 75871 * // returns a MouseEvent object 75872 * // as a callback argument 75873 * function mousePressed(event) { 75874 * console.log(event); 75875 * } 75876 * </code> 75877 * </div> 75878 */ 75879 _main.default.prototype._onmousedown = function (e) { 75880 var context = this._isGlobal ? window : this; 75881 var executeDefault; 75882 this._setProperty('mouseIsPressed', true); 75883 this._setMouseButton(e); 75884 this._updateNextMouseCoords(e); 75885 if (typeof context.mousePressed === 'function') { 75886 executeDefault = context.mousePressed(e); 75887 if (executeDefault === false) { 75888 e.preventDefault(); 75889 } // only safari needs this manual fallback for consistency 75890 75891 } else if (navigator.userAgent.toLowerCase().includes('safari') && typeof context.touchStarted === 'function') { 75892 executeDefault = context.touchStarted(e); 75893 if (executeDefault === false) { 75894 e.preventDefault(); 75895 } 75896 } 75897 }; 75898 /** 75899 * The <a href="#/p5/mouseReleased">mouseReleased()</a> function is called every time a mouse button is 75900 * released. If no <a href="#/p5/mouseReleased">mouseReleased()</a> function is defined, the <a href="#/p5/touchEnded">touchEnded()</a> 75901 * function will be called instead if it is defined.<br><br> 75902 * Browsers may have different default 75903 * behaviors attached to various mouse events. To prevent any default 75904 * behavior for this event, add "return false" to the end of the function. 75905 * 75906 * @method mouseReleased 75907 * @param {Object} [event] optional MouseEvent callback argument. 75908 * @example 75909 * <div> 75910 * <code> 75911 * // Click within the image to change 75912 * // the value of the rectangle 75913 * // after the mouse has been clicked 75914 * 75915 * let value = 0; 75916 * function draw() { 75917 * fill(value); 75918 * rect(25, 25, 50, 50); 75919 * describe('black 50-by-50 rect turns white with mouse click/press.'); 75920 * } 75921 * function mouseReleased() { 75922 * if (value === 0) { 75923 * value = 255; 75924 * } else { 75925 * value = 0; 75926 * } 75927 * } 75928 * </code> 75929 * </div> 75930 * 75931 * <div class="norender"> 75932 * <code> 75933 * function mouseReleased() { 75934 * ellipse(mouseX, mouseY, 5, 5); 75935 * // prevent default 75936 * return false;
75937 * } 75938 * </code> 75939 * </div> 75940 * 75941 * <div class="norender"> 75942 * <code> 75943 * // returns a MouseEvent object 75944 * // as a callback argument 75945 * function mouseReleased(event) { 75946 * console.log(event); 75947 * } 75948 * </code> 75949 * </div> 75950 */ 75951 _main.default.prototype._onmouseup = function (e) { 75952 var context = this._isGlobal ? window : this; 75953 var executeDefault; 75954 this._setProperty('mouseIsPressed', false); 75955 if (typeof context.mouseReleased === 'function') { 75956 executeDefault = context.mouseReleased(e); 75957 if (executeDefault === false) { 75958 e.preventDefault(); 75959 } 75960 } else if (typeof context.touchEnded === 'function') { 75961 executeDefault = context.touchEnded(e); 75962 if (executeDefault === false) { 75963 e.preventDefault(); 75964 } 75965 } 75966 }; 75967 _main.default.prototype._ondragend = _main.default.prototype._onmouseup; 75968 _main.default.prototype._ondragover = _main.default.prototype._onmousemove; 75969 /** 75970 * The <a href="#/p5/mouseClicked">mouseClicked()</a> function is called once after a mouse button has been 75971 * pressed and then released.<br><br> 75972 * Browsers handle clicks differently, so this function is only guaranteed to be 75973 * run when the left mouse button is clicked. To handle other mouse buttons 75974 * being pressed or released, see <a href="#/p5/mousePressed">mousePressed()</a> or <a href="#/p5/mouseReleased">mouseReleased()</a>.<br><br> 75975 * Browsers may have different default 75976 * behaviors attached to various mouse events. To prevent any default 75977 * behavior for this event, add "return false" to the end of the function. 75978 * 75979 * @method mouseClicked 75980 * @param {Object} [event] optional MouseEvent callback argument. 75981 * @example 75982 * <div> 75983 * <code> 75984 * // Click within the image to change 75985 * // the value of the rectangle 75986 * // after the mouse has been clicked 75987 * 75988 * let value = 0; 75989 * function draw() { 75990 * fill(value); 75991 * rect(25, 25, 50, 50); 75992 * describe('black 50-by-50 rect turns white with mouse click/press.'); 75993 * } 75994 * 75995 * function mouseClicked() { 75996 * if (value === 0) { 75997 * value = 255; 75998 * } else { 75999 * value = 0; 76000 * } 76001 * } 76002 * </code> 76003 * </div> 76004 * 76005 * <div class="norender"> 76006 * <code> 76007 * function mouseClicked() { 76008 * ellipse(mouseX, mouseY, 5, 5); 76009 * // prevent default 76010 * return false; 76011 * } 76012 * </code> 76013 * </div> 76014 * 76015 * <div class="norender"> 76016 * <code> 76017 * // returns a MouseEvent object 76018 * // as a callback argument 76019 * function mouseClicked(event) { 76020 * console.log(event); 76021 * } 76022 * </code> 76023 * </div> 76024 */ 76025 _main.default.prototype._onclick = function (e) { 76026 var context = this._isGlobal ? window : this; 76027 if (typeof context.mouseClicked === 'function') { 76028 var executeDefault = context.mouseClicked(e); 76029 if (executeDefault === false) { 76030 e.preventDefault(); 76031 } 76032 } 76033 }; 76034 /** 76035 * The <a href="#/p5/doubleClicked">doubleClicked()</a> function is executed every time a event 76036 * listener has detected a dblclick event which is a part of the 76037 * DOM L3 specification. The doubleClicked event is fired when a 76038 * pointing device button (usually a mouse's primary button) 76039 * is clicked twice on a single element. For more info on the 76040 * dblclick event refer to mozilla's documentation here: 76041 * https://developer.mozilla.org/en-US/docs/Web/Events/dblclick 76042 * 76043 * @method doubleClicked 76044 * @param {Object} [event] optional MouseEvent callback argument. 76045 * @example 76046 * <div> 76047 * <code> 76048 * // Click within the image to change 76049 * // the value of the rectangle 76050 * // after the mouse has been double clicked 76051 * 76052 * let value = 0; 76053 * function draw() { 76054 * fill(value); 76055 * rect(25, 25, 50, 50); 76056 * describe('black 50-by-50 rect turns white with mouse doubleClick/press.'); 76057 * } 76058 * 76059 * function doubleClicked() { 76060 * if (value === 0) { 76061 * value = 255; 76062 * } else { 76063 * value = 0; 76064 * } 76065 * } 76066 * </code> 76067 * </div> 76068 * 76069 * <div class="norender"> 76070 * <code> 76071 * function doubleClicked() { 76072 * ellipse(mouseX, mouseY, 5, 5); 76073 * // prevent default 76074 * return false;
76075 * } 76076 * </code> 76077 * </div> 76078 * 76079 * <div class="norender"> 76080 * <code> 76081 * // returns a MouseEvent object 76082 * // as a callback argument 76083 * function doubleClicked(event) { 76084 * console.log(event); 76085 * } 76086 * </code> 76087 * </div> 76088 */ 76089 _main.default.prototype._ondblclick = function (e) { 76090 var context = this._isGlobal ? window : this; 76091 if (typeof context.doubleClicked === 'function') { 76092 var executeDefault = context.doubleClicked(e); 76093 if (executeDefault === false) { 76094 e.preventDefault(); 76095 } 76096 } 76097 }; 76098 /** 76099 * For use with WebGL orbitControl. 76100 * @property {Number} _mouseWheelDeltaY 76101 * @readOnly 76102 * @private 76103 */ 76104 _main.default.prototype._mouseWheelDeltaY = 0; 76105 /** 76106 * For use with WebGL orbitControl. 76107 * @property {Number} _pmouseWheelDeltaY 76108 * @readOnly 76109 * @private 76110 */ 76111 _main.default.prototype._pmouseWheelDeltaY = 0; 76112 /** 76113 * The function <a href="#/p5/mouseWheel">mouseWheel()</a> is executed every time a vertical mouse wheel 76114 * event is detected either triggered by an actual mouse wheel or by a 76115 * touchpad.<br><br> 76116 * The event.delta property returns the amount the mouse wheel 76117 * have scrolled. The values can be positive or negative depending on the 76118 * scroll direction (on macOS with "natural" scrolling enabled, the signs 76119 * are inverted).<br><br> 76120 * Browsers may have different default behaviors attached to various 76121 * mouse events. To prevent any default behavior for this event, add 76122 * "return false" to the end of the method.<br><br> 76123 * Due to the current support of the "wheel" event on Safari, the function 76124 * may only work as expected if "return false" is included while using Safari. 76125 * 76126 * @method mouseWheel 76127 * @param {Object} [event] optional WheelEvent callback argument. 76128 * 76129 * @example 76130 * <div> 76131 * <code> 76132 * let pos = 25; 76133 * 76134 * function draw() { 76135 * background(237, 34, 93); 76136 * fill(0); 76137 * rect(25, pos, 50, 50); 76138 * describe(`black 50-by-50 rect moves up and down with vertical scroll. 76139 * fuchsia background`); 76140 * } 76141 * 76142 * function mouseWheel(event) { 76143 * print(event.delta); 76144 * //move the square according to the vertical scroll amount 76145 * pos += event.delta; 76146 * //uncomment to block page scrolling 76147 * //return false; 76148 * } 76149 * </code> 76150 * </div> 76151 */ 76152 _main.default.prototype._onwheel = function (e) { 76153 var context = this._isGlobal ? window : this; 76154 this._setProperty('_mouseWheelDeltaY', e.deltaY); 76155 if (typeof context.mouseWheel === 'function') { 76156 e.delta = e.deltaY; 76157 var executeDefault = context.mouseWheel(e); 76158 if (executeDefault === false) { 76159 e.preventDefault(); 76160 } 76161 } 76162 }; 76163 /** 76164 * The function <a href="#/p5/requestPointerLock">requestPointerLock()</a> 76165 * locks the pointer to its current position and makes it invisible. 76166 * Use <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a> to get the difference the mouse was moved since 76167 * the last call of draw. 76168 * Note that not all browsers support this feature. 76169 * This enables you to create experiences that aren't limited by the mouse moving out of the screen 76170 * even if it is repeatedly moved into one direction. 76171 * For example, a first person perspective experience. 76172 * 76173 * @method requestPointerLock 76174 * @example 76175 * <div class="notest"> 76176 * <code> 76177 * let cam; 76178 * function setup() { 76179 * createCanvas(100, 100, WEBGL); 76180 * requestPointerLock(); 76181 * cam = createCamera(); 76182 * } 76183 * 76184 * function draw() { 76185 * background(255); 76186 * cam.pan(-movedX * 0.001); 76187 * cam.tilt(movedY * 0.001); 76188 * sphere(25); 76189 * describe(`3D scene moves according to mouse mouse movement in a 76190 * first person perspective`); 76191 * } 76192 * </code> 76193 * </div> 76194 */ 76195 _main.default.prototype.requestPointerLock = function () { 76196 // pointer lock object forking for cross browser 76197 var canvas = this._curElement.elt; 76198 canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock; 76199 if (!canvas.requestPointerLock) { 76200 console.log('requestPointerLock is not implemented in this browser'); 76201 return false;
76202 } 76203 canvas.requestPointerLock(); 76204 return true; 76205 }; 76206 /** 76207 * The function <a href="#/p5/exitPointerLock">exitPointerLock()</a> 76208 * exits a previously triggered <a href="#/p5/requestPointerLock">pointer Lock</a> 76209 * for example to make ui elements usable etc 76210 * 76211 * @method exitPointerLock 76212 * @example 76213 * <div class="notest"> 76214 * <code> 76215 * //click the canvas to lock the pointer 76216 * //click again to exit (otherwise escape) 76217 * let locked = false; 76218 * function draw() { 76219 * background(237, 34, 93); 76220 * describe('cursor gets locked / unlocked on mouse-click'); 76221 * } 76222 * function mouseClicked() { 76223 * if (!locked) { 76224 * locked = true; 76225 * requestPointerLock(); 76226 * } else { 76227 * exitPointerLock(); 76228 * locked = false; 76229 * } 76230 * } 76231 * </code> 76232 * </div> 76233 */ 76234 _main.default.prototype.exitPointerLock = function () { 76235 document.exitPointerLock(); 76236 }; 76237 var _default = _main.default; 76238 exports.default = _default; 76239 }, 76240 { 76241 '../core/constants': 278, 76242 '../core/main': 290, 76243 'core-js/modules/es.array.includes': 174, 76244 'core-js/modules/es.array.iterator': 176, 76245 'core-js/modules/es.object.get-own-property-descriptor': 191, 76246 'core-js/modules/es.object.to-string': 195, 76247 'core-js/modules/es.string.includes': 203, 76248 'core-js/modules/es.string.iterator': 204, 76249 'core-js/modules/es.symbol': 214, 76250 'core-js/modules/es.symbol.description': 212, 76251 'core-js/modules/es.symbol.iterator': 213, 76252 'core-js/modules/es.weak-map': 246, 76253 'core-js/modules/web.dom-collections.iterator': 248 76254 } 76255 ], 76256 310: [ 76257 function (_dereq_, module, exports) { 76258 'use strict'; 76259 _dereq_('core-js/modules/es.array.includes'); 76260 _dereq_('core-js/modules/es.string.includes'); 76261 _dereq_('core-js/modules/es.array.includes'); 76262 _dereq_('core-js/modules/es.string.includes'); 76263 Object.defineProperty(exports, '__esModule', { 76264 value: true 76265 }); 76266 exports.default = void 0; 76267 var _main = _interopRequireDefault(_dereq_('../core/main')); 76268 function _interopRequireDefault(obj) { 76269 return obj && obj.__esModule ? obj : { 76270 default: 76271 obj 76272 }; 76273 } /** 76274 * @module Events 76275 * @submodule Touch 76276 * @for p5 76277 * @requires core 76278 */ 76279 /** 76280 * The system variable touches[] contains an array of the positions of all 76281 * current touch points, relative to (0, 0) of the canvas, and IDs identifying a 76282 * unique touch as it moves. Each element in the array is an object with x, y, 76283 * and id properties. 76284 * 76285 * The touches[] array is not supported on Safari and IE on touch-based 76286 * desktops (laptops). 76287 * 76288 * @property {Object[]} touches 76289 * @readOnly 76290 * 76291 * @example 76292 * <div> 76293 * <code> 76294 * // On a touchscreen device, touch 76295 * // the canvas using one or more fingers 76296 * // at the same time 76297 * function draw() { 76298 * clear(); 76299 * let display = touches.length + ' touches'; 76300 * text(display, 5, 10); 76301 * describe(`Number of touches currently registered are displayed 76302 * on the canvas`); 76303 * } 76304 * </code> 76305 * </div> 76306 */ 76307 76308 _main.default.prototype.touches = [ 76309 ]; 76310 _main.default.prototype._updateTouchCoords = function (e) { 76311 if (this._curElement !== null) { 76312 var touches = [ 76313 ]; 76314 for (var i = 0; i < e.touches.length; i++) { 76315 touches[i] = getTouchInfo(this._curElement.elt, this.width, this.height, e, i); 76316 } 76317 this._setProperty('touches', touches); 76318 } 76319 }; 76320 function getTouchInfo(canvas, w, h, e) { 76321 var i = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; 76322 var rect = canvas.getBoundingClientRect(); 76323 var sx = canvas.scrollWidth / w || 1; 76324 var sy = canvas.scrollHeight / h || 1; 76325 var touch = e.touches[i] || e.changedTouches[i]; 76326 return { 76327 x: (touch.clientX - rect.left) / sx, 76328 y: (touch.clientY - rect.top) / sy, 76329 winX: touch.clientX, 76330 winY: touch.clientY, 76331 id: touch.identifier 76332 }; 76333 } /** 76334 * The touchStarted() function is called once after every time a touch is 76335 * registered. If no <a href="#/p5/touchStarted">touchStarted()</a> function is defined, the <a href="#/p5/mousePressed">mousePressed()</a> 76336 * function will be called instead if it is defined.<br><br> 76337 * Browsers may have different default behaviors attached to various touch 76338 * events. To prevent any default behavior for this event, add "return false" 76339 * to the end of the method. 76340 * 76341 * @method touchStarted 76342 * @param {Object} [event] optional TouchEvent callback argument. 76343 * @example 76344 * <div> 76345 * <code> 76346 * // Touch within the image to change 76347 * // the value of the rectangle 76348 * 76349 * let value = 0; 76350 * function draw() { 76351 * fill(value); 76352 * rect(25, 25, 50, 50); 76353 * describe('50-by-50 black rect turns white with touch event.'); 76354 * } 76355 * function touchStarted() { 76356 * if (value === 0) { 76357 * value = 255; 76358 * } else { 76359 * value = 0; 76360 * } 76361 * } 76362 * </code> 76363 * </div> 76364 * 76365 * <div class="norender"> 76366 * <code> 76367 * function touchStarted() { 76368 * ellipse(mouseX, mouseY, 5, 5); 76369 * // prevent default 76370 * return false;
76371 * } 76372 * describe('no image displayed'); 76373 * </code> 76374 * </div> 76375 * 76376 * <div class="norender"> 76377 * <code> 76378 * // returns a TouchEvent object 76379 * // as a callback argument 76380 * function touchStarted(event) { 76381 * console.log(event); 76382 * } 76383 * describe('no image displayed'); 76384 * </code> 76385 * </div> 76386 */ 76387 76388 _main.default.prototype._ontouchstart = function (e) { 76389 var context = this._isGlobal ? window : this; 76390 var executeDefault; 76391 this._setProperty('mouseIsPressed', true); 76392 this._updateTouchCoords(e); 76393 this._updateNextMouseCoords(e); 76394 this._updateMouseCoords(); // reset pmouseXY at the start of each touch event 76395 if (typeof context.touchStarted === 'function') { 76396 executeDefault = context.touchStarted(e); 76397 if (executeDefault === false) { 76398 e.preventDefault(); 76399 } // only safari needs this manual fallback for consistency 76400 76401 } else if (navigator.userAgent.toLowerCase().includes('safari') && typeof context.mousePressed === 'function') { 76402 executeDefault = context.mousePressed(e); 76403 if (executeDefault === false) { 76404 e.preventDefault(); 76405 } 76406 } 76407 }; 76408 /** 76409 * The <a href="#/p5/touchMoved">touchMoved()</a> function is called every time a touch move is registered. 76410 * If no <a href="#/p5/touchMoved">touchMoved()</a> function is defined, the <a href="#/p5/mouseDragged">mouseDragged()</a> function will 76411 * be called instead if it is defined.<br><br> 76412 * Browsers may have different default behaviors attached to various touch 76413 * events. To prevent any default behavior for this event, add "return false" 76414 * to the end of the method. 76415 * 76416 * @method touchMoved 76417 * @param {Object} [event] optional TouchEvent callback argument. 76418 * @example 76419 * <div> 76420 * <code> 76421 * // Move your finger across the page 76422 * // to change its value 76423 * 76424 * let value = 0; 76425 * function draw() { 76426 * fill(value); 76427 * rect(25, 25, 50, 50); 76428 * describe('50-by-50 black rect turns lighter with touch until white. resets'); 76429 * } 76430 * function touchMoved() { 76431 * value = value + 5; 76432 * if (value > 255) { 76433 * value = 0; 76434 * } 76435 * } 76436 * </code> 76437 * </div> 76438 * 76439 * <div class="norender"> 76440 * <code> 76441 * function touchMoved() { 76442 * ellipse(mouseX, mouseY, 5, 5); 76443 * // prevent default 76444 * return false; 76445 * } 76446 * describe('no image displayed'); 76447 * </code> 76448 * </div> 76449 * 76450 * <div class="norender"> 76451 * <code> 76452 * // returns a TouchEvent object 76453 * // as a callback argument 76454 * function touchMoved(event) { 76455 * console.log(event); 76456 * } 76457 * describe('no image displayed'); 76458 * </code> 76459 * </div> 76460 */ 76461 _main.default.prototype._ontouchmove = function (e) { 76462 var context = this._isGlobal ? window : this; 76463 var executeDefault; 76464 this._updateTouchCoords(e); 76465 this._updateNextMouseCoords(e); 76466 if (typeof context.touchMoved === 'function') { 76467 executeDefault = context.touchMoved(e); 76468 if (executeDefault === false) { 76469 e.preventDefault(); 76470 } 76471 } else if (typeof context.mouseDragged === 'function') { 76472 executeDefault = context.mouseDragged(e); 76473 if (executeDefault === false) { 76474 e.preventDefault(); 76475 } 76476 } 76477 }; 76478 /** 76479 * The <a href="#/p5/touchEnded">touchEnded()</a> function is called every time a touch ends. If no 76480 * <a href="#/p5/touchEnded">touchEnded()</a> function is defined, the <a href="#/p5/mouseReleased">mouseReleased()</a> function will be 76481 * called instead if it is defined.<br><br> 76482 * Browsers may have different default behaviors attached to various touch 76483 * events. To prevent any default behavior for this event, add "return false" 76484 * to the end of the method. 76485 * 76486 * @method touchEnded 76487 * @param {Object} [event] optional TouchEvent callback argument. 76488 * @example 76489 * <div> 76490 * <code> 76491 * // Release touch within the image to 76492 * // change the value of the rectangle 76493 * 76494 * let value = 0; 76495 * function draw() { 76496 * fill(value); 76497 * rect(25, 25, 50, 50); 76498 * describe('50-by-50 black rect turns white with touch.'); 76499 * } 76500 * function touchEnded() { 76501 * if (value === 0) { 76502 * value = 255; 76503 * } else { 76504 * value = 0; 76505 * } 76506 * } 76507 * </code> 76508 * </div> 76509 * 76510 * <div class="norender"> 76511 * <code> 76512 * function touchEnded() { 76513 * ellipse(mouseX, mouseY, 5, 5); 76514 * // prevent default 76515 * return false;
76516 * } 76517 * describe('no image displayed'); 76518 * </code> 76519 * </div> 76520 * 76521 * <div class="norender"> 76522 * <code> 76523 * // returns a TouchEvent object 76524 * // as a callback argument 76525 * function touchEnded(event) { 76526 * console.log(event); 76527 * } 76528 * describe('no image displayed'); 76529 * </code> 76530 * </div> 76531 */ 76532 _main.default.prototype._ontouchend = function (e) { 76533 this._setProperty('mouseIsPressed', false); 76534 this._updateTouchCoords(e); 76535 this._updateNextMouseCoords(e); 76536 var context = this._isGlobal ? window : this; 76537 var executeDefault; 76538 if (typeof context.touchEnded === 'function') { 76539 executeDefault = context.touchEnded(e); 76540 if (executeDefault === false) { 76541 e.preventDefault(); 76542 } 76543 } else if (typeof context.mouseReleased === 'function') { 76544 executeDefault = context.mouseReleased(e); 76545 if (executeDefault === false) { 76546 e.preventDefault(); 76547 } 76548 } 76549 }; 76550 var _default = _main.default; 76551 exports.default = _default; 76552 }, 76553 { 76554 '../core/main': 290, 76555 'core-js/modules/es.array.includes': 174, 76556 'core-js/modules/es.string.includes': 203 76557 } 76558 ], 76559 311: [ 76560 function (_dereq_, module, exports) { 76561 'use strict'; 76562 _dereq_('core-js/modules/es.array.iterator'); 76563 _dereq_('core-js/modules/es.object.to-string'); 76564 _dereq_('core-js/modules/es.typed-array.int32-array'); 76565 _dereq_('core-js/modules/es.typed-array.uint8-array'); 76566 _dereq_('core-js/modules/es.typed-array.copy-within'); 76567 _dereq_('core-js/modules/es.typed-array.every'); 76568 _dereq_('core-js/modules/es.typed-array.fill'); 76569 _dereq_('core-js/modules/es.typed-array.filter'); 76570 _dereq_('core-js/modules/es.typed-array.find'); 76571 _dereq_('core-js/modules/es.typed-array.find-index'); 76572 _dereq_('core-js/modules/es.typed-array.for-each'); 76573 _dereq_('core-js/modules/es.typed-array.includes'); 76574 _dereq_('core-js/modules/es.typed-array.index-of'); 76575 _dereq_('core-js/modules/es.typed-array.iterator'); 76576 _dereq_('core-js/modules/es.typed-array.join'); 76577 _dereq_('core-js/modules/es.typed-array.last-index-of'); 76578 _dereq_('core-js/modules/es.typed-array.map'); 76579 _dereq_('core-js/modules/es.typed-array.reduce'); 76580 _dereq_('core-js/modules/es.typed-array.reduce-right'); 76581 _dereq_('core-js/modules/es.typed-array.reverse'); 76582 _dereq_('core-js/modules/es.typed-array.set'); 76583 _dereq_('core-js/modules/es.typed-array.slice'); 76584 _dereq_('core-js/modules/es.typed-array.some'); 76585 _dereq_('core-js/modules/es.typed-array.sort'); 76586 _dereq_('core-js/modules/es.typed-array.subarray'); 76587 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 76588 _dereq_('core-js/modules/es.typed-array.to-string'); 76589 _dereq_('core-js/modules/es.array.iterator'); 76590 _dereq_('core-js/modules/es.object.to-string'); 76591 _dereq_('core-js/modules/es.typed-array.int32-array'); 76592 _dereq_('core-js/modules/es.typed-array.uint8-array'); 76593 _dereq_('core-js/modules/es.typed-array.copy-within'); 76594 _dereq_('core-js/modules/es.typed-array.every'); 76595 _dereq_('core-js/modules/es.typed-array.fill'); 76596 _dereq_('core-js/modules/es.typed-array.filter'); 76597 _dereq_('core-js/modules/es.typed-array.find'); 76598 _dereq_('core-js/modules/es.typed-array.find-index'); 76599 _dereq_('core-js/modules/es.typed-array.for-each'); 76600 _dereq_('core-js/modules/es.typed-array.includes'); 76601 _dereq_('core-js/modules/es.typed-array.index-of'); 76602 _dereq_('core-js/modules/es.typed-array.iterator'); 76603 _dereq_('core-js/modules/es.typed-array.join'); 76604 _dereq_('core-js/modules/es.typed-array.last-index-of'); 76605 _dereq_('core-js/modules/es.typed-array.map'); 76606 _dereq_('core-js/modules/es.typed-array.reduce'); 76607 _dereq_('core-js/modules/es.typed-array.reduce-right'); 76608 _dereq_('core-js/modules/es.typed-array.reverse'); 76609 _dereq_('core-js/modules/es.typed-array.set'); 76610 _dereq_('core-js/modules/es.typed-array.slice'); 76611 _dereq_('core-js/modules/es.typed-array.some'); 76612 _dereq_('core-js/modules/es.typed-array.sort'); 76613 _dereq_('core-js/modules/es.typed-array.subarray'); 76614 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 76615 _dereq_('core-js/modules/es.typed-array.to-string'); 76616 Object.defineProperty(exports, '__esModule', { 76617 value: true 76618 }); 76619 exports.default = void 0; 76620 /** 76621 * This module defines the filters for use with image buffers. 76622 * 76623 * This module is basically a collection of functions stored in an object 76624 * as opposed to modules. The functions are destructive, modifying 76625 * the passed in canvas rather than creating a copy. 76626 * 76627 * Generally speaking users of this module will use the Filters.apply method 76628 * on a canvas to create an effect. 76629 * 76630 * A number of functions are borrowed/adapted from 76631 * http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ 76632 * or the java processing implementation. 76633 */ 76634 var Filters = { 76635 }; 76636 /* 76637 * Helper functions 76638 */ 76639 /** 76640 * Returns the pixel buffer for a canvas 76641 * 76642 * @private 76643 *
76644 * @param {Canvas|ImageData} canvas the canvas to get pixels from 76645 * @return {Uint8ClampedArray} a one-dimensional array containing 76646 * the data in thc RGBA order, with integer 76647 * values between 0 and 255 76648 */ 76649 Filters._toPixels = function (canvas) { 76650 if (canvas instanceof ImageData) { 76651 return canvas.data; 76652 } else { 76653 if (canvas.getContext('2d')) { 76654 return canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data; 76655 } else if (canvas.getContext('webgl')) { 76656 var gl = canvas.getContext('webgl'); 76657 var len = gl.drawingBufferWidth * gl.drawingBufferHeight * 4; 76658 var data = new Uint8Array(len); 76659 gl.readPixels(0, 0, canvas.width, canvas.height, gl.RGBA, gl.UNSIGNED_BYTE, data); 76660 return data; 76661 } 76662 } 76663 }; 76664 /** 76665 * Returns a 32 bit number containing ARGB data at ith pixel in the 76666 * 1D array containing pixels data. 76667 * 76668 * @private 76669 * 76670 * @param {Uint8ClampedArray} data array returned by _toPixels() 76671 * @param {Integer} i index of a 1D Image Array 76672 * @return {Integer} 32 bit integer value representing 76673 * ARGB value. 76674 */ 76675 Filters._getARGB = function (data, i) { 76676 var offset = i * 4; 76677 return data[offset + 3] << 24 & 4278190080 | data[offset] << 16 & 16711680 | data[offset + 1] << 8 & 65280 | data[offset + 2] & 255; 76678 }; 76679 /** 76680 * Modifies pixels RGBA values to values contained in the data object. 76681 * 76682 * @private 76683 * 76684 * @param {Uint8ClampedArray} pixels array returned by _toPixels() 76685 * @param {Int32Array} data source 1D array where each value 76686 * represents ARGB values 76687 */ 76688 Filters._setPixels = function (pixels, data) { 76689 var offset = 0; 76690 for (var i = 0, al = pixels.length; i < al; i++) { 76691 offset = i * 4; 76692 pixels[offset + 0] = (data[i] & 16711680) >>> 16; 76693 pixels[offset + 1] = (data[i] & 65280) >>> 8; 76694 pixels[offset + 2] = data[i] & 255; 76695 pixels[offset + 3] = (data[i] & 4278190080) >>> 24; 76696 } 76697 }; 76698 /** 76699 * Returns the ImageData object for a canvas 76700 * https://developer.mozilla.org/en-US/docs/Web/API/ImageData 76701 * 76702 * @private 76703 * 76704 * @param {Canvas|ImageData} canvas canvas to get image data from 76705 * @return {ImageData} Holder of pixel data (and width and 76706 * height) for a canvas 76707 */ 76708 Filters._toImageData = function (canvas) { 76709 if (canvas instanceof ImageData) { 76710 return canvas; 76711 } else { 76712 return canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height); 76713 } 76714 }; 76715 /** 76716 * Returns a blank ImageData object. 76717 * 76718 * @private 76719 * 76720 * @param {Integer} width 76721 * @param {Integer} height 76722 * @return {ImageData} 76723 */ 76724 Filters._createImageData = function (width, height) { 76725 Filters._tmpCanvas = document.createElement('canvas'); 76726 Filters._tmpCtx = Filters._tmpCanvas.getContext('2d'); 76727 return this._tmpCtx.createImageData(width, height); 76728 }; 76729 /** 76730 * Applys a filter function to a canvas. 76731 * 76732 * The difference between this and the actual filter functions defined below 76733 * is that the filter functions generally modify the pixel buffer but do 76734 * not actually put that data back to the canvas (where it would actually 76735 * update what is visible). By contrast this method does make the changes 76736 * actually visible in the canvas. 76737 * 76738 * The apply method is the method that callers of this module would generally 76739 * use. It has been separated from the actual filters to support an advanced 76740 * use case of creating a filter chain that executes without actually updating 76741 * the canvas in between everystep. 76742 * 76743 * @private 76744 * @param {HTMLCanvasElement} canvas [description] 76745 * @param {function(ImageData,Object)} func [description] 76746 * @param {Object} filterParam [description] 76747 */ 76748 Filters.apply = function (canvas, func, filterParam) { 76749 var pixelsState = canvas.getContext('2d'); 76750 var imageData = pixelsState.getImageData(0, 0, canvas.width, canvas.height); //Filters can either return a new ImageData object, or just modify 76751 //the one they received. 76752 var newImageData = func(imageData, filterParam); 76753 if (newImageData instanceof ImageData) { 76754 pixelsState.putImageData(newImageData, 0, 0, 0, 0, canvas.width, canvas.height); 76755 } else { 76756 pixelsState.putImageData(imageData, 0, 0, 0, 0, canvas.width, canvas.height); 76757 } 76758 }; 76759 /* 76760 * Filters 76761 */ 76762 /** 76763 * Converts the image to black and white pixels depending if they are above or 76764 * below the threshold defined by the level parameter. The parameter must be 76765 * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used. 76766 * 76767 * Borrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ 76768 * 76769 * @private
76770 * @param {Canvas} canvas 76771 * @param {Float} level 76772 */ 76773 Filters.threshold = function (canvas, level) { 76774 var pixels = Filters._toPixels(canvas); 76775 if (level === undefined) { 76776 level = 0.5; 76777 } 76778 var thresh = Math.floor(level * 255); 76779 for (var i = 0; i < pixels.length; i += 4) { 76780 var r = pixels[i]; 76781 var g = pixels[i + 1]; 76782 var b = pixels[i + 2]; 76783 var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b; 76784 var val = void 0; 76785 if (gray >= thresh) { 76786 val = 255; 76787 } else { 76788 val = 0; 76789 } 76790 pixels[i] = pixels[i + 1] = pixels[i + 2] = val; 76791 } 76792 }; 76793 /** 76794 * Converts any colors in the image to grayscale equivalents. 76795 * No parameter is used. 76796 * 76797 * Borrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ 76798 * 76799 * @private 76800 * @param {Canvas} canvas 76801 */ 76802 Filters.gray = function (canvas) { 76803 var pixels = Filters._toPixels(canvas); 76804 for (var i = 0; i < pixels.length; i += 4) { 76805 var r = pixels[i]; 76806 var g = pixels[i + 1]; 76807 var b = pixels[i + 2]; // CIE luminance for RGB 76808 var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b; 76809 pixels[i] = pixels[i + 1] = pixels[i + 2] = gray; 76810 } 76811 }; 76812 /** 76813 * Sets the alpha channel to entirely opaque. No parameter is used. 76814 * 76815 * @private 76816 * @param {Canvas} canvas 76817 */ 76818 Filters.opaque = function (canvas) { 76819 var pixels = Filters._toPixels(canvas); 76820 for (var i = 0; i < pixels.length; i += 4) { 76821 pixels[i + 3] = 255; 76822 } 76823 return pixels; 76824 }; 76825 /** 76826 * Sets each pixel to its inverse value. No parameter is used. 76827 * @private 76828 * @param {Canvas} canvas 76829 */ 76830 Filters.invert = function (canvas) { 76831 var pixels = Filters._toPixels(canvas); 76832 for (var i = 0; i < pixels.length; i += 4) { 76833 pixels[i] = 255 - pixels[i]; 76834 pixels[i + 1] = 255 - pixels[i + 1]; 76835 pixels[i + 2] = 255 - pixels[i + 2]; 76836 } 76837 }; 76838 /** 76839 * Limits each channel of the image to the number of colors specified as 76840 * the parameter. The parameter can be set to values between 2 and 255, but 76841 * results are most noticeable in the lower ranges. 76842 * 76843 * Adapted from java based processing implementation 76844 * 76845 * @private 76846 * @param {Canvas} canvas 76847 * @param {Integer} level 76848 */ 76849 Filters.posterize = function (canvas, level) { 76850 var pixels = Filters._toPixels(canvas); 76851 if (level < 2 || level > 255) { 76852 throw new Error('Level must be greater than 2 and less than 255 for posterize'); 76853 } 76854 var levels1 = level - 1; 76855 for (var i = 0; i < pixels.length; i += 4) { 76856 var rlevel = pixels[i]; 76857 var glevel = pixels[i + 1]; 76858 var blevel = pixels[i + 2]; 76859 pixels[i] = (rlevel * level >> 8) * 255 / levels1; 76860 pixels[i + 1] = (glevel * level >> 8) * 255 / levels1; 76861 pixels[i + 2] = (blevel * level >> 8) * 255 / levels1; 76862 } 76863 }; 76864 /** 76865 * reduces the bright areas in an image 76866 * @private 76867 * @param {Canvas} canvas 76868 */ 76869 Filters.dilate = function (canvas) { 76870 var pixels = Filters._toPixels(canvas); 76871 var currIdx = 0; 76872 var maxIdx = pixels.length ? pixels.length / 4 : 0; 76873 var out = new Int32Array(maxIdx); 76874 var currRowIdx, 76875 maxRowIdx, 76876 colOrig, 76877 colOut, 76878 currLum; 76879 var idxRight, 76880 idxLeft, 76881 idxUp, 76882 idxDown; 76883 var colRight, 76884 colLeft, 76885 colUp, 76886 colDown; 76887 var lumRight, 76888 lumLeft, 76889 lumUp, 76890 lumDown; 76891 while (currIdx < maxIdx) { 76892 currRowIdx = currIdx; 76893 maxRowIdx = currIdx + canvas.width; 76894 while (currIdx < maxRowIdx) { 76895 colOrig = colOut = Filters._getARGB(pixels, currIdx); 76896 idxLeft = currIdx - 1; 76897 idxRight = currIdx + 1; 76898 idxUp = currIdx - canvas.width; 76899 idxDown = currIdx + canvas.width; 76900 if (idxLeft < currRowIdx) { 76901 idxLeft = currIdx; 76902 } 76903 if (idxRight >= maxRowIdx) { 76904 idxRight = currIdx; 76905 } 76906 if (idxUp < 0) { 76907 idxUp = 0; 76908 } 76909 if (idxDown >= maxIdx) { 76910 idxDown = currIdx; 76911 } 76912 colUp = Filters._getARGB(pixels, idxUp); 76913 colLeft = Filters._getARGB(pixels, idxLeft); 76914 colDown = Filters._getARGB(pixels, idxDown); 76915 colRight = Filters._getARGB(pixels, idxRight); //compute luminance 76916 currLum = 77 * (colOrig >> 16 & 255) + 151 * (colOrig >> 8 & 255) + 28 * (colOrig & 255); 76917 lumLeft = 77 * (colLeft >> 16 & 255) + 151 * (colLeft >> 8 & 255) + 28 * (colLeft & 255); 76918 lumRight = 77 * (colRight >>
76918 16 & 255) + 151 * (colRight >> 8 & 255) + 28 * (colRight & 255); 76919 lumUp = 77 * (colUp >> 16 & 255) + 151 * (colUp >> 8 & 255) + 28 * (colUp & 255); 76920 lumDown = 77 * (colDown >> 16 & 255) + 151 * (colDown >> 8 & 255) + 28 * (colDown & 255); 76921 if (lumLeft > currLum) { 76922 colOut = colLeft; 76923 currLum = lumLeft; 76924 } 76925 if (lumRight > currLum) { 76926 colOut = colRight; 76927 currLum = lumRight; 76928 } 76929 if (lumUp > currLum) { 76930 colOut = colUp; 76931 currLum = lumUp; 76932 } 76933 if (lumDown > currLum) { 76934 colOut = colDown; 76935 currLum = lumDown; 76936 } 76937 out[currIdx++] = colOut; 76938 } 76939 } 76940 Filters._setPixels(pixels, out); 76941 }; 76942 /** 76943 * increases the bright areas in an image 76944 * @private 76945 * @param {Canvas} canvas 76946 */ 76947 Filters.erode = function (canvas) { 76948 var pixels = Filters._toPixels(canvas); 76949 var currIdx = 0; 76950 var maxIdx = pixels.length ? pixels.length / 4 : 0; 76951 var out = new Int32Array(maxIdx); 76952 var currRowIdx, 76953 maxRowIdx, 76954 colOrig, 76955 colOut, 76956 currLum; 76957 var idxRight, 76958 idxLeft, 76959 idxUp, 76960 idxDown; 76961 var colRight, 76962 colLeft, 76963 colUp, 76964 colDown; 76965 var lumRight, 76966 lumLeft, 76967 lumUp, 76968 lumDown; 76969 while (currIdx < maxIdx) { 76970 currRowIdx = currIdx; 76971 maxRowIdx = currIdx + canvas.width; 76972 while (currIdx < maxRowIdx) { 76973 colOrig = colOut = Filters._getARGB(pixels, currIdx); 76974 idxLeft = currIdx - 1; 76975 idxRight = currIdx + 1; 76976 idxUp = currIdx - canvas.width; 76977 idxDown = currIdx + canvas.width; 76978 if (idxLeft < currRowIdx) { 76979 idxLeft = currIdx; 76980 } 76981 if (idxRight >= maxRowIdx) { 76982 idxRight = currIdx; 76983 } 76984 if (idxUp < 0) { 76985 idxUp = 0; 76986 } 76987 if (idxDown >= maxIdx) { 76988 idxDown = currIdx; 76989 } 76990 colUp = Filters._getARGB(pixels, idxUp); 76991 colLeft = Filters._getARGB(pixels, idxLeft); 76992 colDown = Filters._getARGB(pixels, idxDown); 76993 colRight = Filters._getARGB(pixels, idxRight); //compute luminance 76994 currLum = 77 * (colOrig >> 16 & 255) + 151 * (colOrig >> 8 & 255) + 28 * (colOrig & 255); 76995 lumLeft = 77 * (colLeft >> 16 & 255) + 151 * (colLeft >> 8 & 255) + 28 * (colLeft & 255); 76996 lumRight = 77 * (colRight >> 16 & 255) + 151 * (colRight >> 8 & 255) + 28 * (colRight & 255); 76997 lumUp = 77 * (colUp >> 16 & 255) + 151 * (colUp >> 8 & 255) + 28 * (colUp & 255); 76998 lumDown = 77 * (colDown >> 16 & 255) + 151 * (colDown >> 8 & 255) + 28 * (colDown & 255); 76999 if (lumLeft < currLum) { 77000 colOut = colLeft; 77001 currLum = lumLeft; 77002 } 77003 if (lumRight < currLum) { 77004 colOut = colRight; 77005 currLum = lumRight; 77006 } 77007 if (lumUp < currLum) { 77008 colOut = colUp; 77009 currLum = lumUp; 77010 } 77011 if (lumDown < currLum) { 77012 colOut = colDown; 77013 currLum = lumDown; 77014 } 77015 out[currIdx++] = colOut; 77016 } 77017 } 77018 Filters._setPixels(pixels, out); 77019 }; // BLUR 77020 // internal kernel stuff for the gaussian blur filter 77021 var blurRadius; 77022 var blurKernelSize; 77023 var blurKernel; 77024 var blurMult; 77025 /* 77026 * Port of https://github.com/processing/processing/blob/ 77027 * main/core/src/processing/core/PImage.java#L1250 77028 * 77029 * Optimized code for building the blur kernel. 77030 * further optimized blur code (approx. 15% for radius=20) 77031 * bigger speed gains for larger radii (~30%)
77032 * added support for various image types (ALPHA, RGB, ARGB) 77033 * [toxi 050728] 77034 */ 77035 function buildBlurKernel(r) { 77036 var radius = r * 3.5 | 0; 77037 radius = radius < 1 ? 1 : radius < 248 ? radius : 248; 77038 if (blurRadius !== radius) { 77039 blurRadius = radius; 77040 blurKernelSize = 1 + blurRadius << 1; 77041 blurKernel = new Int32Array(blurKernelSize); 77042 blurMult = new Array(blurKernelSize); 77043 for (var l = 0; l < blurKernelSize; l++) { 77044 blurMult[l] = new Int32Array(256); 77045 } 77046 var bk, 77047 bki; 77048 var bm, 77049 bmi; 77050 for (var i = 1, radiusi = radius - 1; i < radius; i++) { 77051 blurKernel[radius + i] = blurKernel[radiusi] = bki = radiusi * radiusi; 77052 bm = blurMult[radius + i]; 77053 bmi = blurMult[radiusi--]; 77054 for (var j = 0; j < 256; j++) { 77055 bm[j] = bmi[j] = bki * j; 77056 } 77057 } 77058 bk = blurKernel[radius] = radius * radius; 77059 bm = blurMult[radius]; 77060 for (var k = 0; k < 256; k++) { 77061 bm[k] = bk * k; 77062 } 77063 } 77064 } // Port of https://github.com/processing/processing/blob/ 77065 // main/core/src/processing/core/PImage.java#L1433 77066 77067 function blurARGB(canvas, radius) { 77068 var pixels = Filters._toPixels(canvas); 77069 var width = canvas.width; 77070 var height = canvas.height; 77071 var numPackedPixels = width * height; 77072 var argb = new Int32Array(numPackedPixels); 77073 for (var j = 0; j < numPackedPixels; j++) { 77074 argb[j] = Filters._getARGB(pixels, j); 77075 } 77076 var sum, 77077 cr, 77078 cg, 77079 cb, 77080 ca; 77081 var read, 77082 ri, 77083 ym, 77084 ymi, 77085 bk0; 77086 var a2 = new Int32Array(numPackedPixels); 77087 var r2 = new Int32Array(numPackedPixels); 77088 var g2 = new Int32Array(numPackedPixels); 77089 var b2 = new Int32Array(numPackedPixels); 77090 var yi = 0; 77091 buildBlurKernel(radius); 77092 var x, 77093 y, 77094 i; 77095 var bm; 77096 for (y = 0; y < height; y++) { 77097 for (x = 0; x < width; x++) { 77098 cb = cg = cr = ca = sum = 0; 77099 read = x - blurRadius; 77100 if (read < 0) { 77101 bk0 = - read; 77102 read = 0; 77103 } else { 77104 if (read >= width) { 77105 break; 77106 } 77107 bk0 = 0; 77108 } 77109 for (i = bk0; i < blurKernelSize; i++) { 77110 if (read >= width) { 77111 break; 77112 } 77113 var c = argb[read + yi]; 77114 bm = blurMult[i]; 77115 ca += bm[(c & - 16777216) >>> 24]; 77116 cr += bm[(c & 16711680) >> 16]; 77117 cg += bm[(c & 65280) >> 8]; 77118 cb += bm[c & 255]; 77119 sum += blurKernel[i]; 77120 read++; 77121 } 77122 ri = yi + x; 77123 a2[ri] = ca / sum; 77124 r2[ri] = cr / sum; 77125 g2[ri] = cg / sum; 77126 b2[ri] = cb / sum; 77127 } 77128 yi += width; 77129 } 77130 yi = 0; 77131 ym = - blurRadius; 77132 ymi = ym * width; 77133 for (y = 0; y < height; y++) { 77134 for (x = 0; x < width; x++) { 77135 cb = cg = cr = ca = sum = 0; 77136 if (ym < 0) { 77137 bk0 = ri = - ym; 77138 read = x; 77139 } else { 77140 if (ym >= height) { 77141 break; 77142 } 77143 bk0 = 0; 77144 ri = ym; 77145 read = x + ymi; 77146 } 77147 for (i = bk0; i < blurKernelSize; i++) { 77148 if (ri >= height) { 77149 break; 77150 } 77151 bm = blurMult[i]; 77152 ca += bm[a2[read]]; 77153 cr += bm[r2[read]]; 77154 cg += bm[g2[read]]; 77155 cb += bm[b2[read]]; 77156 sum += blurKernel[i]; 77157 ri++; 77158 read += width; 77159 } 77160 argb[x + yi] = ca / sum << 24 | cr / sum << 16 | cg / sum << 8 | cb / sum; 77161 } 77162 yi += width; 77163 ymi += width; 77164 ym++; 77165 } 77166 Filters._setPixels(pixels, argb); 77167 } 77168 Filters.blur = function (canvas, radius) { 77169 blurARGB(canvas, radius); 77170 }; 77171 var _default = Filters; 77172 exports.default = _default; 77173 }, 77174 { 77175 'core-js/modules/es.array.iterator': 176, 77176 'core-js/modules/es.object.to-string': 195, 77177 'core-js/modules/es.typed-array.copy-within': 215, 77178 'core-js/modules/es.typed-array.every': 216, 77179 'core-js/modules/es.typed-array.fill': 217, 77180 'core-js/modules/es.typed-array.filter': 218, 77181 'core-js/modules/es.typed-array.find': 220, 77182 'core-js/modules/es.typed-array.find-index': 219, 77183 'core-js/modules/es.typed-array.for-each': 223, 77184 'core-js/modules/es.typed-array.includes': 224, 77185 'core-js/modules/es.typed-array.index-of': 225, 77186 'core-js/modules/es.typed-array.int32-array': 227, 77187 'core-js/modules/es.typed-array.iterator': 228, 77188 'core-js/modules/es.typed-array.join': 229, 77189 'core-js/modules/es.typed-array.last-index-of': 230, 77190 'core-js/modules/es.typed-array.map': 231, 77191 'core-js/modules/es.typed-array.reduce': 233, 77192 'core-js/modules/es.typed-array.reduce-right': 232, 77193 'core-js/modules/es.typed-array.reverse': 234, 77194 'core-js/modules/es.typed-array.set': 235, 77195 'core-js/modules/es.typed-array.slice': 236, 77196 'core-js/modules/es.typed-array.some': 237, 77197 'core-js/modules/es.typed-array.sort': 238, 77198 'core-js/modules/es.typed-array.subarray': 239, 77199 'core-js/modules/es.typed-array.to-locale-string': 240, 77200 'core-js/modules/es.typed-array.to-string': 241, 77201 'core-js/modules/es.typed-array.uint8-array': 244 77202 } 77203 ], 77204 312: [
77205 function (_dereq_, module, exports) { 77206 'use strict'; 77207 _dereq_('core-js/modules/es.symbol'); 77208 _dereq_('core-js/modules/es.symbol.description'); 77209 _dereq_('core-js/modules/es.symbol.iterator'); 77210 _dereq_('core-js/modules/es.array.concat'); 77211 _dereq_('core-js/modules/es.array.filter'); 77212 _dereq_('core-js/modules/es.array.from'); 77213 _dereq_('core-js/modules/es.array.iterator'); 77214 _dereq_('core-js/modules/es.array.map'); 77215 _dereq_('core-js/modules/es.array.slice'); 77216 _dereq_('core-js/modules/es.object.keys'); 77217 _dereq_('core-js/modules/es.object.to-string'); 77218 _dereq_('core-js/modules/es.regexp.exec'); 77219 _dereq_('core-js/modules/es.regexp.to-string'); 77220 _dereq_('core-js/modules/es.set'); 77221 _dereq_('core-js/modules/es.string.iterator'); 77222 _dereq_('core-js/modules/es.string.replace'); 77223 _dereq_('core-js/modules/es.string.split'); 77224 _dereq_('core-js/modules/es.typed-array.uint8-array'); 77225 _dereq_('core-js/modules/es.typed-array.uint32-array'); 77226 _dereq_('core-js/modules/es.typed-array.copy-within'); 77227 _dereq_('core-js/modules/es.typed-array.every'); 77228 _dereq_('core-js/modules/es.typed-array.fill'); 77229 _dereq_('core-js/modules/es.typed-array.filter'); 77230 _dereq_('core-js/modules/es.typed-array.find'); 77231 _dereq_('core-js/modules/es.typed-array.find-index'); 77232 _dereq_('core-js/modules/es.typed-array.for-each'); 77233 _dereq_('core-js/modules/es.typed-array.includes'); 77234 _dereq_('core-js/modules/es.typed-array.index-of'); 77235 _dereq_('core-js/modules/es.typed-array.iterator'); 77236 _dereq_('core-js/modules/es.typed-array.join'); 77237 _dereq_('core-js/modules/es.typed-array.last-index-of'); 77238 _dereq_('core-js/modules/es.typed-array.map'); 77239 _dereq_('core-js/modules/es.typed-array.reduce'); 77240 _dereq_('core-js/modules/es.typed-array.reduce-right'); 77241 _dereq_('core-js/modules/es.typed-array.reverse'); 77242 _dereq_('core-js/modules/es.typed-array.set'); 77243 _dereq_('core-js/modules/es.typed-array.slice'); 77244 _dereq_('core-js/modules/es.typed-array.some'); 77245 _dereq_('core-js/modules/es.typed-array.sort'); 77246 _dereq_('core-js/modules/es.typed-array.subarray'); 77247 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 77248 _dereq_('core-js/modules/es.typed-array.to-string'); 77249 _dereq_('core-js/modules/web.dom-collections.iterator'); 77250 _dereq_('core-js/modules/es.symbol'); 77251 _dereq_('core-js/modules/es.symbol.description'); 77252 _dereq_('core-js/modules/es.symbol.iterator'); 77253 _dereq_('core-js/modules/es.array.concat'); 77254 _dereq_('core-js/modules/es.array.filter'); 77255 _dereq_('core-js/modules/es.array.from'); 77256 _dereq_('core-js/modules/es.array.iterator'); 77257 _dereq_('core-js/modules/es.array.map'); 77258 _dereq_('core-js/modules/es.array.slice'); 77259 _dereq_('core-js/modules/es.object.keys'); 77260 _dereq_('core-js/modules/es.object.to-string'); 77261 _dereq_('core-js/modules/es.regexp.exec'); 77262 _dereq_('core-js/modules/es.regexp.to-string'); 77263 _dereq_('core-js/modules/es.set'); 77264 _dereq_('core-js/modules/es.string.iterator'); 77265 _dereq_('core-js/modules/es.string.replace'); 77266 _dereq_('core-js/modules/es.string.split'); 77267 _dereq_('core-js/modules/es.typed-array.uint8-array'); 77268 _dereq_('core-js/modules/es.typed-array.uint32-array'); 77269 _dereq_('core-js/modules/es.typed-array.copy-within'); 77270 _dereq_('core-js/modules/es.typed-array.every'); 77271 _dereq_('core-js/modules/es.typed-array.fill'); 77272 _dereq_('core-js/modules/es.typed-array.filter'); 77273 _dereq_('core-js/modules/es.typed-array.find'); 77274 _dereq_('core-js/modules/es.typed-array.find-index'); 77275 _dereq_('core-js/modules/es.typed-array.for-each'); 77276 _dereq_('core-js/modules/es.typed-array.includes'); 77277 _dereq_('core-js/modules/es.typed-array.index-of'); 77278 _dereq_('core-js/modules/es.typed-array.iterator'); 77279 _dereq_('core-js/modules/es.typed-array.join'); 77280 _dereq_('core-js/modules/es.typed-array.last-index-of'); 77281 _dereq_('core-js/modules/es.typed-array.map'); 77282 _dereq_('core-js/modules/es.typed-array.reduce'); 77283 _dereq_('core-js/modules/es.typed-array.reduce-right'); 77284 _dereq_('core-js/modules/es.typed-array.reverse'); 77285 _dereq_('core-js/modules/es.typed-array.set'); 77286 _dereq_('core-js/modules/es.typed-array.slice'); 77287 _dereq_('core-js/modules/es.typed-array.some'); 77288 _dereq_('core-js/modules/es.typed-array.sort'); 77289 _dereq_('core-js/modules/es.typed-array.subarray'); 77290 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 77291 _dereq_('core-js/modules/es.typed-array.to-string'); 77292 _dereq_('core-js/modules/web.dom-collections.iterator'); 77293 Object.defineProperty(exports, '__esModule', { 77294 value: true 77295 }); 77296 exports.default = void 0; 77297 var _main = _interopRequireDefault(_dereq_('../core/main')); 77298 var _omggif = _interopRequireDefault(_dereq_('omggif')); 77299 function _interopRequireDefault(obj) { 77300 return obj && obj.__esModule ? obj : { 77301 default: 77302 obj 77303 }; 77304 } 77305 function _toConsumableArray(arr) { 77306 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); 77307 } 77308 function _nonIterableSpread() { 77309 throw new TypeError('Invalid attempt to spread non-iterable instance'); 77310 } 77311 function _iterableToArray(iter) { 77312 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') return Array.from(iter); 77313 } 77314 function _arrayWithoutHoles(arr) { 77315 if (Array.isArray(arr)) { 77316 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 77317 arr2[i] = arr[i]; 77318 } 77319 return arr2; 77320 } 77321 } /** 77322 * Creates a new <a href="#/p5.Image">p5.Image</a> (the datatype for storing images). This provides a 77323 * fresh buffer of pixels to play with. Set the size of the buffer with the 77324 * width and height parameters. 77325 * 77326 * .<a href="#/p5.Image/pixels">pixels</a> gives access to an array containing the values for all the pixels 77327 * in the display window. 77328 * These values are numbers. This array is the size (including an appropriate 77329 * factor for the <a href="#/p5/pixelDensity">pixelDensity</a>) of the display window x4, 77330 * representing the R, G, B, A values in order for each pixel, mov
77330ing from 77331 * left to right across each row, then down each column. See .<a href="#/p5.Image/pixels">pixels</a> for 77332 * more info. It may also be simpler to use <a href="#/p5.Image/set">set()</a> or <a href="#/p5.Image/get">get()</a>. 77333 * 77334 * Before accessing the pixels of an image, the data must loaded with the 77335 * <a href="#/p5.Image/loadPixels">loadPixels()</a> function. After the array data has been modified, the 77336 * <a href="#/p5.Image/updatePixels">updatePixels()</a> function must be run to update the changes. 77337 * 77338 * @method createImage 77339 * @param {Integer} width width in pixels 77340 * @param {Integer} height height in pixels 77341 * @return {p5.Image} the <a href="#/p5.Image">p5.Image</a> object 77342 * @example 77343 * <div> 77344 * <code> 77345 * let img = createImage(66, 66); 77346 * img.loadPixels(); 77347 * for (let i = 0; i < img.width; i++) { 77348 * for (let j = 0; j < img.height; j++) { 77349 * img.set(i, j, color(0, 90, 102)); 77350 * } 77351 * } 77352 * img.updatePixels(); 77353 * image(img, 17, 17); 77354 * </code> 77355 * </div> 77356 * 77357 * <div> 77358 * <code> 77359 * let img = createImage(66, 66); 77360 * img.loadPixels(); 77361 * for (let i = 0; i < img.width; i++) { 77362 * for (let j = 0; j < img.height; j++) { 77363 * img.set(i, j, color(0, 90, 102, (i % img.width) * 2)); 77364 * } 77365 * } 77366 * img.updatePixels(); 77367 * image(img, 17, 17); 77368 * image(img, 34, 34); 77369 * </code> 77370 * </div> 77371 * 77372 * <div> 77373 * <code> 77374 * let pink = color(255, 102, 204); 77375 * let img = createImage(66, 66); 77376 * img.loadPixels(); 77377 * let d = pixelDensity(); 77378 * let halfImage = 4 * (img.width * d) * (img.height / 2 * d); 77379 * for (let i = 0; i < halfImage; i += 4) { 77380 * img.pixels[i] = red(pink); 77381 * img.pixels[i + 1] = green(pink); 77382 * img.pixels[i + 2] = blue(pink); 77383 * img.pixels[i + 3] = alpha(pink); 77384 * } 77385 * img.updatePixels(); 77386 * image(img, 17, 17); 77387 * </code> 77388 * </div> 77389 * 77390 * @alt 77391 * 66Ã66 dark turquoise rect in center of canvas. 77392 * 2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas 77393 * no image displayed 77394 */ 77395 77396 _main.default.prototype.createImage = function (width, height) { 77397 _main.default._validateParameters('createImage', arguments); 77398 return new _main.default.Image(width, height); 77399 }; 77400 /** 77401 * Save the current canvas as an image. The browser will either save the 77402 * file immediately, or prompt the user with a dialogue window. 77403 * 77404 * @method saveCanvas 77405 * @param {p5.Element|HTMLCanvasElement} selectedCanvas a variable 77406 * representing a specific html5 canvas (optional) 77407 * @param {String} [filename] 77408 * @param {String} [extension] 'jpg' or 'png' 77409 * 77410 * @example 77411 * <div class='norender notest'><code> 77412 * function setup() { 77413 * let c = createCanvas(100, 100); 77414 * background(255, 0, 0); 77415 * saveCanvas(c, 'myCanvas', 'jpg'); 77416 * } 77417 * </code></div> 77418 * <div class='norender notest'><code> 77419 * // note that this example has the same result as above 77420 * // if no canvas is specified, defaults to main canvas 77421 * function setup() { 77422 * let c = createCanvas(100, 100); 77423 * background(255, 0, 0); 77424 * saveCanvas('myCanvas', 'jpg'); 77425 * 77426 * // all of the following are valid 77427 * saveCanvas(c, 'myCanvas', 'jpg'); 77428 * saveCanvas(c, 'myCanvas.jpg'); 77429 * saveCanvas(c, 'myCanvas'); 77430 * saveCanvas(c); 77431 * saveCanvas('myCanvas', 'png'); 77432 * saveCanvas('myCanvas'); 77433 * saveCanvas(); 77434 * } 77435 * </code></div> 77436 * 77437 * @alt 77438 * no image displayed 77439 * no image displayed 77440 * no image displayed 77441 */ 77442 /** 77443 * @method saveCanvas 77444 * @param {String} [filename] 77445 * @param {String} [extension] 77446 */ 77447 _main.default.prototype.saveCanvas = function () { 77448 _main.default._validateParameters('saveCanvas', arguments); // copy arguments to array 77449 var args = [ 77450 ].slice.call(arguments); 77451 var htmlCanvas, 77452 filename, 77453 extension; 77454 if (arguments[0] instanceof HTMLCanvasElement) { 77455 htmlCanvas = arguments[0]; 77456 args.shift(); 77457 } else if (arguments[0] instanceof _main.default.Element) { 77458 htmlCanvas = arguments[0].elt; 77459 args.shift(); 77460 } else { 77461 htmlCanvas = this._curElement && this._curElement.elt; 77462 } 77463 if (args.length >= 1) { 77464 filename = args[0]; 77465 } 77466 if (args.length >= 2) { 77467 extension = args[1]; 77468 } 77469 extension = extension || _main.default.prototype._checkFileExtension(filename, extension) [1] || 'png'; 77470 var mimeType; 77471 switch (extension) { 77472 default: 77473 //case 'png': 77474 mimeType = 'image/png'; 77475 break; 77476 case 'jpeg': 77477 case 'jpg': 77478 mimeType = 'image/jpeg'; 77479 break; 77480 } 77481 htmlCanvas.toBlob(function (blob) { 77482 _main.default.prototype.downloadFile(blob, filename, extension); 77483 }, mimeType); 77484 }; // this is the old saveGif, left here for compatibility purposes 77485 // the only place I found it being used was on image/p5.Image.js, on the 77486 // save function. that has been changed to use this function. 77487 _main.default.prototype.encodeAndDownloadGif = function (pImg, filename) { 77488 var props = pImg.gifProperties; //convert loopLimit back into Netscape Block formatting 77489 var loopLimit = props.loopLimit; 77490 if (loopLimit === 1) { 77491 loopLimit = null; 77492 } else if (loopLimit === null) { 77493 loopLimit = 0; 77494 } 77495 var buffer = new Uint8Array(pImg.width * pImg.height * props.numFrames); 77496 var allFramesPixelColors = [ 77497 ]; // Used to determine the occurrence of unique palettes and the frames 77498 // which use them 77499 var paletteFreqsAndFrames = { 77500 }; // Pass 1: 77501 //loop over frames and get the frequency of each palette 77502 for (var i = 0; i < props.numFrames; i++) { 77503 var paletteSet = new Set(); 77504 var data = props.frames[i].image.data; 77505 var dataLength = data.length; // The color for each pixel in this frame ( for easier lookup later ) 77506 var pixelColors = new Uint32Array(pImg.width * pImg.height); 77507 for (var j = 0, k = 0; j < dataLength; j += 4, k++) { 77508 var r = data[j + 0]; 77509 var g = data[j + 1]; 77510 var b = data[j + 2]; 77511 var color = r << 16 | g << 8 | b << 0; 77512 paletteSet.add(color); // What color does this pixel have in this frame ? 77513 pixelColors[k] = color; 77514 } // A way to put use the entire palette as an object key 77515 77516 var paletteStr = _toConsumableArray(paletteSet).sort().toString(); 77517 if (paletteFreqsAndFrames[paletteStr] === undefined) { 77518 paletteFreqsAndFrames[paletteStr] = { 77519 freq: 1, 77520 frames: [ 77521 i 77522 ] 77523 }; 77524 } else { 77525 paletteFreqsAndFrames[paletteStr].freq += 1; 77526 paletteFreqsAndFrames[paletteStr].frames.push(i); 77527 } 77528 allFramesPixelColors.push(pixelColors); 77529 } 77530 var framesUsingGlobalPalette = [ 77531 ]; // Now to build the global palette 77532 // Sort all the unique palettes in descending order of their occurrence
77533 var palettesSortedByFreq = Object.keys(paletteFreqsAndFrames).sort(function (a, b) { 77534 return paletteFreqsAndFrames[b].freq - paletteFreqsAndFrames[a].freq; 77535 }); // The initial global palette is the one with the most occurrence 77536 var globalPalette = palettesSortedByFreq[0].split(',').map(function (a) { 77537 return parseInt(a); 77538 }); 77539 framesUsingGlobalPalette = framesUsingGlobalPalette.concat(paletteFreqsAndFrames[globalPalette].frames); 77540 var globalPaletteSet = new Set(globalPalette); // Build a more complete global palette 77541 // Iterate over the remaining palettes in the order of 77542 // their occurrence and see if the colors in this palette which are 77543 // not in the global palette can be added there, while keeping the length 77544 // of the global palette <= 256 77545 for (var _i = 1; _i < palettesSortedByFreq.length; _i++) { 77546 var palette = palettesSortedByFreq[_i].split(',').map(function (a) { 77547 return parseInt(a); 77548 }); 77549 var difference = palette.filter(function (x) { 77550 return !globalPaletteSet.has(x); 77551 }); 77552 if (globalPalette.length + difference.length <= 256) { 77553 for (var _j = 0; _j < difference.length; _j++) { 77554 globalPalette.push(difference[_j]); 77555 globalPaletteSet.add(difference[_j]); 77556 } // All frames using this palette now use the global palette 77557 77558 framesUsingGlobalPalette = framesUsingGlobalPalette.concat(paletteFreqsAndFrames[palettesSortedByFreq[_i]].frames); 77559 } 77560 } 77561 framesUsingGlobalPalette = new Set(framesUsingGlobalPalette); // Build a lookup table of the index of each color in the global palette 77562 // Maps a color to its index 77563 var globalIndicesLookup = { 77564 }; 77565 for (var _i2 = 0; _i2 < globalPalette.length; _i2++) { 77566 if (!globalIndicesLookup[globalPalette[_i2]]) { 77567 globalIndicesLookup[globalPalette[_i2]] = _i2; 77568 } 77569 } // force palette to be power of 2 77570 77571 var powof2 = 1; 77572 while (powof2 < globalPalette.length) { 77573 powof2 <<= 1; 77574 } 77575 globalPalette.length = powof2; // global opts 77576 var opts = { 77577 loop: loopLimit, 77578 palette: new Uint32Array(globalPalette) 77579 }; 77580 var gifWriter = new _omggif.default.GifWriter(buffer, pImg.width, pImg.height, opts); 77581 var previousFrame = { 77582 }; // Pass 2 77583 // Determine if the frame needs a local palette 77584 // Also apply transparency optimization. This function will often blow up 77585 // the size of a GIF if not for transparency. If a pixel in one frame has 77586 // the same color in the previous frame, that pixel can be marked as 77587 // transparent. We decide one particular color as transparent and make all 77588 // transparent pixels take this color. This helps in later in compression. 77589 var _loop = function _loop(_i3) { 77590 var localPaletteRequired = !framesUsingGlobalPalette.has(_i3); 77591 var palette = localPaletteRequired ? [ 77592 ] : globalPalette; 77593 var pixelPaletteIndex = new Uint8Array(pImg.width * pImg.height); // Lookup table mapping color to its indices 77594 var colorIndicesLookup = { 77595 }; // All the colors that cannot be marked transparent in this frame 77596 var cannotBeTransparent = new Set(); 77597 for (var _k = 0; _k < allFramesPixelColors[_i3].length; _k++) { 77598 var _color = allFramesPixelColors[_i3][_k]; 77599 if (localPaletteRequired) { 77600 if (colorIndicesLookup[_color] === undefined) { 77601 colorIndicesLookup[_color] = palette.length; 77602 palette.push(_color); 77603 } 77604 pixelPaletteIndex[_k] = colorIndicesLookup[_color]; 77605 } else { 77606 pixelPaletteIndex[_k] = globalIndicesLookup[_color]; 77607 } 77608 if (_i3 > 0) { 77609 // If even one pixel of this color has changed in this frame 77610 // from the previous frame, we cannot mark it as transparent 77611 if (allFramesPixelColors[_i3 - 1][_k] !== _color) { 77612 cannotBeTransparent.add(_color); 77613 } 77614 } 77615 } 77616 var frameOpts = { 77617 }; // Transparency optimization 77618 var canBeTransparent = palette.filter(function (a) { 77619 return !cannotBeTransparent.has(a); 77620 }); 77621 if (canBeTransparent.length > 0) { 77622 // Select a color to mark as transparent 77623 var transparent = canBeTransparent[0]; 77624 var transparentIndex = localPaletteRequired ? colorIndicesLookup[transparent] : globalIndicesLookup[transparent]; 77625 if (_i3 > 0) { 77626 for (var _k2 = 0; _k2 < allFramesPixelColors[_i3].length; _k2++) { 77627 // If this pixel in this frame has the same color in previous frame 77628 if (allFramesPixelColors[_i3 - 1][_k2] === allFramesPixelColors[_i3][_k2]) { 77629 pixelPaletteIndex[_k2] = transparentIndex; 77630 } 77631 } 77632 frameOpts.transparent = transparentIndex; // If this frame has any transparency, do not dispose the previous frame 77633 previousFrame.frameOpts.disposal = 1; 77634 } 77635 }
77636 frameOpts.delay = props.frames[_i3].delay / 10; // Move timing back into GIF formatting 77637 if (localPaletteRequired) { 77638 // force palette to be power of 2 77639 var _powof = 1; 77640 while (_powof < palette.length) { 77641 _powof <<= 1; 77642 } 77643 palette.length = _powof; 77644 frameOpts.palette = new Uint32Array(palette); 77645 } 77646 if (_i3 > 0) { 77647 // add the frame that came before the current one 77648 gifWriter.addFrame(0, 0, pImg.width, pImg.height, previousFrame.pixelPaletteIndex, previousFrame.frameOpts); 77649 } // previous frame object should now have details of this frame 77650 77651 previousFrame = { 77652 pixelPaletteIndex: pixelPaletteIndex, 77653 frameOpts: frameOpts 77654 }; 77655 }; 77656 for (var _i3 = 0; _i3 < props.numFrames; _i3++) { 77657 _loop(_i3); 77658 } 77659 previousFrame.frameOpts.disposal = 1; // add the last frame 77660 gifWriter.addFrame(0, 0, pImg.width, pImg.height, previousFrame.pixelPaletteIndex, previousFrame.frameOpts); 77661 var extension = 'gif'; 77662 var blob = new Blob([buffer.slice(0, gifWriter.end())], { 77663 type: 'image/gif' 77664 }); 77665 _main.default.prototype.downloadFile(blob, filename, extension); 77666 }; 77667 /** 77668 * Capture a sequence of frames that can be used to create a movie. 77669 * Accepts a callback. For example, you may wish to send the frames 77670 * to a server where they can be stored or converted into a movie. 77671 * If no callback is provided, the browser will pop up save dialogues in an 77672 * attempt to download all of the images that have just been created. With the 77673 * callback provided the image data isn't saved by default but instead passed 77674 * as an argument to the callback function as an array of objects, with the 77675 * size of array equal to the total number of frames. 77676 * 77677 * The arguments `duration` and `framerate` are constrained to be less or equal to 15 and 22, respectively, which means you 77678 * can only download a maximum of 15 seconds worth of frames at 22 frames per second, adding up to 330 frames. 77679 * This is done in order to avoid memory problems since a large enough canvas can fill up the memory in your computer 77680 * very easily and crash your program or even your browser. 77681 * 77682 * To export longer animations, you might look into a library like 77683 * <a href="https://github.com/spite/ccapture.js/">ccapture.js</a>. 77684 * 77685 * @method saveFrames 77686 * @param {String} filename 77687 * @param {String} extension 'jpg' or 'png' 77688 * @param {Number} duration Duration in seconds to save the frames for. This parameter will be constrained to be less or equal to 15. 77689 * @param {Number} framerate Framerate to save the frames in. This parameter will be constrained to be less or equal to 22. 77690 * @param {function(Array)} [callback] A callback function that will be executed 77691 to handle the image data. This function 77692 should accept an array as argument. The 77693 array will contain the specified number of 77694 frames of objects. Each object has three 77695 properties: imageData - an 77696 image/octet-stream, filename and extension. 77697 * @example 77698 * <div><code> 77699 * function draw() { 77700 * background(mouseX); 77701 * } 77702 * 77703 * function mousePressed() { 77704 * saveFrames('out', 'png', 1, 25, data => { 77705 * print(data); 77706 * }); 77707 * } 77708</code></div> 77709 * 77710 * @alt 77711 * canvas background goes from light to dark with mouse x. 77712 */ 77713 _main.default.prototype.saveFrames = function (fName, ext, _duration, _fps, callback) { 77714 _main.default._validateParameters('saveFrames', arguments); 77715 var duration = _duration || 3; 77716 duration = _main.default.prototype.constrain(duration, 0, 15); 77717 duration = duration * 1000; 77718 var fps = _fps || 15; 77719 fps = _main.default.prototype.constrain(fps, 0, 22); 77720 var count = 0; 77721 var makeFrame = _main.default.prototype._makeFrame; 77722 var cnv = this._curElement.elt; 77723 var frames = [ 77724 ]; 77725 var frameFactory = setInterval(function () { 77726 frames.push(makeFrame(fName + count, ext, cnv)); 77727 count++; 77728 }, 1000 / fps); 77729 setTimeout(function () { 77730 clearInterval(frameFactory); 77731 if (callback) { 77732 callback(frames); 77733 } else { 77734 var _iteratorNormalCompletion = true; 77735 var _didIteratorError = false;
77736 var _iteratorError = undefined; 77737 try { 77738 for (var _iterator = frames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 77739 var f = _step.value; 77740 _main.default.prototype.downloadFile(f.imageData, f.filename, f.ext); 77741 } 77742 } catch (err) { 77743 _didIteratorError = true; 77744 _iteratorError = err; 77745 } finally { 77746 try { 77747 if (!_iteratorNormalCompletion && _iterator.return != null) { 77748 _iterator.return(); 77749 } 77750 } finally { 77751 if (_didIteratorError) { 77752 throw _iteratorError; 77753 } 77754 } 77755 } 77756 } 77757 frames = [ 77758 ]; // clear frames 77759 }, duration + 0.01); 77760 }; 77761 _main.default.prototype._makeFrame = function (filename, extension, _cnv) { 77762 var cnv; 77763 if (this) { 77764 cnv = this._curElement.elt; 77765 } else { 77766 cnv = _cnv; 77767 } 77768 var mimeType; 77769 if (!extension) { 77770 extension = 'png'; 77771 mimeType = 'image/png'; 77772 } else { 77773 switch (extension.toLowerCase()) { 77774 case 'png': 77775 mimeType = 'image/png'; 77776 break; 77777 case 'jpeg': 77778 mimeType = 'image/jpeg'; 77779 break; 77780 case 'jpg': 77781 mimeType = 'image/jpeg'; 77782 break; 77783 default: 77784 mimeType = 'image/png'; 77785 break; 77786 } 77787 } 77788 var downloadMime = 'image/octet-stream'; 77789 var imageData = cnv.toDataURL(mimeType); 77790 imageData = imageData.replace(mimeType, downloadMime); 77791 var thisFrame = { 77792 }; 77793 thisFrame.imageData = imageData; 77794 thisFrame.filename = filename; 77795 thisFrame.ext = extension; 77796 return thisFrame; 77797 }; 77798 var _default = _main.default; 77799 exports.default = _default; 77800 }, 77801 { 77802 '../core/main': 290, 77803 'core-js/modules/es.array.concat': 167, 77804 'core-js/modules/es.array.filter': 171, 77805 'core-js/modules/es.array.from': 173, 77806 'core-js/modules/es.array.iterator': 176, 77807 'core-js/modules/es.array.map': 179, 77808 'core-js/modules/es.array.slice': 180, 77809 'core-js/modules/es.object.keys': 194, 77810 'core-js/modules/es.object.to-string': 195, 77811 'core-js/modules/es.regexp.exec': 199, 77812 'core-js/modules/es.regexp.to-string': 200, 77813 'core-js/modules/es.set': 201, 77814 'core-js/modules/es.string.iterator': 204, 77815 'core-js/modules/es.string.replace': 207, 77816 'core-js/modules/es.string.split': 209, 77817 'core-js/modules/es.symbol': 214, 77818 'core-js/modules/es.symbol.description': 212, 77819 'core-js/modules/es.symbol.iterator': 213, 77820 'core-js/modules/es.typed-array.copy-within': 215, 77821 'core-js/modules/es.typed-array.every': 216, 77822 'core-js/modules/es.typed-array.fill': 217, 77823 'core-js/modules/es.typed-array.filter': 218, 77824 'core-js/modules/es.typed-array.find': 220, 77825 'core-js/modules/es.typed-array.find-index': 219, 77826 'core-js/modules/es.typed-array.for-each': 223, 77827 'core-js/modules/es.typed-array.includes': 224, 77828 'core-js/modules/es.typed-array.index-of': 225, 77829 'core-js/modules/es.typed-array.iterator': 228, 77830 'core-js/modules/es.typed-array.join': 229, 77831 'core-js/modules/es.typed-array.last-index-of': 230, 77832 'core-js/modules/es.typed-array.map': 231, 77833 'core-js/modules/es.typed-array.reduce': 233, 77834 'core-js/modules/es.typed-array.reduce-right': 232, 77835 'core-js/modules/es.typed-array.reverse': 234, 77836 'core-js/modules/es.typed-array.set': 235, 77837 'core-js/modules/es.typed-array.slice': 236, 77838 'core-js/modules/es.typed-array.some': 237, 77839 'core-js/modules/es.typed-array.sort': 238, 77840 'core-js/modules/es.typed-array.subarray': 239, 77841 'core-js/modules/es.typed-array.to-locale-string': 240, 77842 'core-js/modules/es.typed-array.to-string': 241, 77843 'core-js/modules/es.typed-array.uint32-array': 243, 77844 'core-js/modules/es.typed-array.uint8-array': 244, 77845 'core-js/modules/web.dom-collections.iterator': 248, 77846 'omggif': 262 77847 } 77848 ], 77849 313: [
77850 function (_dereq_, module, exports) { 77851 'use strict'; 77852 _dereq_('core-js/modules/es.symbol'); 77853 _dereq_('core-js/modules/es.symbol.description'); 77854 _dereq_('core-js/modules/es.symbol.iterator'); 77855 _dereq_('core-js/modules/es.array.copy-within'); 77856 _dereq_('core-js/modules/es.array.includes'); 77857 _dereq_('core-js/modules/es.array.index-of'); 77858 _dereq_('core-js/modules/es.array.iterator'); 77859 _dereq_('core-js/modules/es.array.slice'); 77860 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 77861 _dereq_('core-js/modules/es.object.to-string'); 77862 _dereq_('core-js/modules/es.promise'); 77863 _dereq_('core-js/modules/es.regexp.to-string'); 77864 _dereq_('core-js/modules/es.string.includes'); 77865 _dereq_('core-js/modules/es.string.iterator'); 77866 _dereq_('core-js/modules/es.typed-array.uint8-array'); 77867 _dereq_('core-js/modules/es.typed-array.uint8-clamped-array'); 77868 _dereq_('core-js/modules/es.typed-array.copy-within'); 77869 _dereq_('core-js/modules/es.typed-array.every'); 77870 _dereq_('core-js/modules/es.typed-array.fill'); 77871 _dereq_('core-js/modules/es.typed-array.filter'); 77872 _dereq_('core-js/modules/es.typed-array.find'); 77873 _dereq_('core-js/modules/es.typed-array.find-index'); 77874 _dereq_('core-js/modules/es.typed-array.for-each'); 77875 _dereq_('core-js/modules/es.typed-array.includes'); 77876 _dereq_('core-js/modules/es.typed-array.index-of'); 77877 _dereq_('core-js/modules/es.typed-array.iterator'); 77878 _dereq_('core-js/modules/es.typed-array.join'); 77879 _dereq_('core-js/modules/es.typed-array.last-index-of'); 77880 _dereq_('core-js/modules/es.typed-array.map'); 77881 _dereq_('core-js/modules/es.typed-array.reduce'); 77882 _dereq_('core-js/modules/es.typed-array.reduce-right'); 77883 _dereq_('core-js/modules/es.typed-array.reverse'); 77884 _dereq_('core-js/modules/es.typed-array.set'); 77885 _dereq_('core-js/modules/es.typed-array.slice'); 77886 _dereq_('core-js/modules/es.typed-array.some'); 77887 _dereq_('core-js/modules/es.typed-array.sort'); 77888 _dereq_('core-js/modules/es.typed-array.subarray'); 77889 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 77890 _dereq_('core-js/modules/es.typed-array.to-string'); 77891 _dereq_('core-js/modules/es.weak-map'); 77892 _dereq_('core-js/modules/web.dom-collections.iterator'); 77893 function _typeof2(obj) { 77894 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 77895 _typeof2 = function _typeof2(obj) { 77896 return typeof obj; 77897 }; 77898 } else { 77899 _typeof2 = function _typeof2(obj) { 77900 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 77901 }; 77902 } 77903 return _typeof2(obj); 77904 } 77905 function _typeof(obj) { 77906 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 77907 _typeof = function _typeof(obj) { 77908 return _typeof2(obj); 77909 }; 77910 } else { 77911 _typeof = function _typeof(obj) { 77912 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 77913 }; 77914 } 77915 return _typeof(obj); 77916 } 77917 _dereq_('core-js/modules/es.array.copy-within'); 77918 _dereq_('core-js/modules/es.array.includes'); 77919 _dereq_('core-js/modules/es.array.index-of'); 77920 _dereq_('core-js/modules/es.array.iterator'); 77921 _dereq_('core-js/modules/es.array.slice'); 77922 _dereq_('core-js/modules/es.object.to-string'); 77923 _dereq_('core-js/modules/es.promise'); 77924 _dereq_('core-js/modules/es.regexp.to-string'); 77925 _dereq_('core-js/modules/es.string.includes'); 77926 _dereq_('core-js/modules/es.typed-array.uint8-array'); 77927 _dereq_('core-js/modules/es.typed-array.uint8-clamped-array'); 77928 _dereq_('core-js/modules/es.typed-array.copy-within'); 77929 _dereq_('core-js/modules/es.typed-array.every'); 77930 _dereq_('core-js/modules/es.typed-array.fill'); 77931 _dereq_('core-js/modules/es.typed-array.filter'); 77932 _dereq_('core-js/modules/es.typed-array.find'); 77933 _dereq_('core-js/modules/es.typed-array.find-index'); 77934 _dereq_('core-js/modules/es.typed-array.for-each'); 77935 _dereq_('core-js/modules/es.typed-array.includes'); 77936 _dereq_('core-js/modules/es.typed-array.index-of'); 77937 _dereq_('core-js/modules/es.typed-array.iterator'); 77938 _dereq_('core-js/modules/es.typed-array.join'); 77939 _dereq_('core-js/modules/es.typed-array.last-index-of'); 77940 _dereq_('core-js/modules/es.typed-array.map'); 77941 _dereq_('core-js/modules/es.typed-array.reduce'); 77942 _dereq_('core-js/modules/es.typed-array.reduce-right'); 77943 _dereq_('core-js/modules/es.typed-array.reverse'); 77944 _dereq_('core-js/modules/es.typed-array.set'); 77945 _dereq_('core-js/modules/es.typed-array.slice'); 77946 _dereq_('core-js/modules/es.typed-array.some'); 77947 _dereq_('core-js/modules/es.typed-array.sort'); 77948 _dereq_('core-js/modules/es.typed-array.subarray'); 77949 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 77950 _dereq_('core-js/modules/es.typed-array.to-string'); 77951 Object.defineProperty(exports, '__esModule', { 77952 value: true 77953 }); 77954 exports.default = void 0; 77955 _dereq_('regenerator-runtime/runtime'); 77956 var _main = _interopRequireDefault(_dereq_('../core/main')); 77957 var _helpers = _interopRequireDefault(_dereq_('../core/helpers')); 77958 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 77959 var _omggif = _interopRequireDefault(_dereq_('omggif')); 77960 var _gifenc = _dereq_('gifenc'); 77961 _dereq_('../core/friendly_errors/validate_params'); 77962 _dereq_('../core/friendly_errors/file_errors'); 77963 _dereq_('../core/friendly_errors/fes_core'); 77964 function _getRequireWildcardCache() { 77965 if (typeof WeakMap !== 'function') return null; 77966 var cache = new WeakMap(); 77967 _getRequireWildcardCache = function _getRequireWildcardCache() { 77968 return cache; 77969 }; 77970 return cache; 77971 } 77972 function _interopRequireWildcard(obj) { 77973 if (obj && obj.__esModule) { 77974 return obj; 77975 } 77976 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 77977 return { 77978 default: 77979 obj 77980 }; 77981 } 77982 var cache = _getRequireWildcardCache(); 77983 if (cache && cache.has(obj)) { 77984 return cache.get(obj); 77985 } 77986 var newObj = { 77987 }; 77988 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 77989 for (var key in obj) { 77990 if (Object.prototype.hasOwnProperty.call(obj, key)) { 77991 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 77992 if (desc && (desc.get || desc.set)) { 77993 Object.defineProperty(newObj, key, desc); 77994 } else { 77995 newObj[key] = obj[key]; 77996 } 77997 } 77998 } 77999 newObj.default = obj; 78000 if (cache) { 78001 cache.set(obj, newObj); 78002 } 78003 return newObj; 78004 } 78005 function _interopRequireDefault(obj) { 78006 return obj && obj.__esModule ? obj : { 78007 default: 78008 obj 78009 }; 78010 } 78011 function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { 78012 try { 78013 var info = gen[key](arg); 78014 var value = info.value; 78015 } catch (error) { 78016 reject(error); 78017 return; 78018 } 78019 if (info.done) { 78020 resolve(value); 78021 } else { 78022 Promise.resolve(value).then(_next, _throw); 78023 } 78024 } 78025 function _asyncToGenerator(fn) { 78026 return function () { 78027 var self = this, 78028 args = arguments; 78029 return new Promise(function (resolve, reject) { 78030 var gen = fn.apply(self, args); 78031 function _next(value) { 78032 asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value); 78033 } 78034 function _throw(err) { 78035 asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err); 78036 } 78037 _next(undefined); 78038 }); 78039 }; 78040 } /** 78041 * Loads an image from a path and creates a <a href="#/p5.Image">p5.Image</a> from it. 78042 * 78043 * The image may not be immediately available for rendering. 78044 * If you want to ensure that the image is ready before doing 78045 * anything with it, place the <a href="#/p5/loadImage">loadImage()</a> call in <a href="#/p5/preload">preload()</a>. 78046 * You may also supply a callback function to handle the image when it's ready. 78047 * 78048 * The path to the image should be relative to the HTML file 78049 * that links in your sketch. Loading an image from a URL or other 78050 * remote location may be blocked due to your browser's built-in 78051 * security. 78052 78053 * You can also pass in a string of a base64 encoded image as an alternative to the file path. 78054 * Remember to add "data:image/png;base64," in front of the string. 78055 * 78056 * @method loadImage 78057 * @param {String} path Path of the image to be loaded 78058 * @param {function(p5.Image)} [successCallback] Function to be called once 78059 * the image is loaded. Will be passed the 78060 * <a href="#/p5.Image">p5.Image</a>. 78061 * @param {function(Event)} [failureCallback] called with event error if 78062 * the image fails to load. 78063 * @return {p5.Image} the <a href="#/p5.Image">p5.Image</a> object 78064 * @example 78065 * <div> 78066 * <code> 78067 * let img; 78068 * function preload() { 78069 * img = loadImage('assets/laDefense.jpg'); 78070 * } 78071 * function setup() { 78072 * image(img, 0, 0); 78073 * } 78074 * </code> 78075 * </div> 78076 * <div> 78077 * <code> 78078 * function setup() { 78079 * // here we use a callback to display the image after loading 78080 * loadImage('assets/laDefense.jpg', img => { 78081 * image(img, 0, 0); 78082 * }); 78083 * } 78084 * </code> 78085 * </div> 78086 * 78087 * @alt 78088 * image of the underside of a white umbrella and grided ceililng above 78089 * image of the underside of a white umbrella and grided ceililng above 78090 */ 78091 78092 _main.default.prototype.loadImage = function (path, successCallback, failureCallback) { 78093 _main.default._validateParameters('loadImage', arguments); 78094 var pImg = new _main.default.Image(1, 1, this); 78095 var self = this;
78096 var req = new Request(path, { 78097 method: 'GET', 78098 mode: 'cors' 78099 }); 78100 fetch(path, req).then(function (response) { 78101 // GIF section 78102 var contentType = response.headers.get('content-type'); 78103 if (contentType === null) { 78104 console.warn('The image you loaded does not have a Content-Type header. If you are using the online editor consider reuploading the asset.'); 78105 } 78106 if (contentType && contentType.includes('image/gif')) { 78107 response.arrayBuffer().then(function (arrayBuffer) { 78108 if (arrayBuffer) { 78109 var byteArray = new Uint8Array(arrayBuffer); 78110 _createGif(byteArray, pImg, successCallback, failureCallback, function (pImg) { 78111 self._decrementPreload(); 78112 }.bind(self)); 78113 } 78114 }, function (e) { 78115 if (typeof failureCallback === 'function') { 78116 failureCallback(e); 78117 self._decrementPreload(); 78118 } else { 78119 console.error(e); 78120 } 78121 }); 78122 } else { 78123 // Non-GIF Section 78124 var img = new Image(); 78125 img.onload = function () { 78126 pImg.width = pImg.canvas.width = img.width; 78127 pImg.height = pImg.canvas.height = img.height; // Draw the image into the backing canvas of the p5.Image 78128 pImg.drawingContext.drawImage(img, 0, 0); 78129 pImg.modified = true; 78130 if (typeof successCallback === 'function') { 78131 successCallback(pImg); 78132 } 78133 self._decrementPreload(); 78134 }; 78135 img.onerror = function (e) { 78136 _main.default._friendlyFileLoadError(0, img.src); 78137 if (typeof failureCallback === 'function') { 78138 failureCallback(e); 78139 self._decrementPreload(); 78140 } else { 78141 console.error(e); 78142 } 78143 }; // Set crossOrigin in case image is served with CORS headers. 78144 // This will let us draw to the canvas without tainting it. 78145 // See https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image 78146 // When using data-uris the file will be loaded locally 78147 // so we don't need to worry about crossOrigin with base64 file types. 78148 if (path.indexOf('data:image/') !== 0) { 78149 img.crossOrigin = 'Anonymous'; 78150 } // start loading the image 78151 78152 img.src = path; 78153 } 78154 pImg.modified = true; 78155 }).catch(function (e) { 78156 _main.default._friendlyFileLoadError(0, path); 78157 if (typeof failureCallback === 'function') { 78158 failureCallback(e); 78159 self._decrementPreload(); 78160 } else { 78161 console.error(e); 78162 } 78163 }); 78164 return pImg; 78165 }; 78166 /** 78167 * Generates a gif of your current animation and downloads it to your computer! 78168 * 78169 * The duration argument specifies how many seconds you want to record from your animation. 78170 * This value is then converted to the necessary number of frames to generate it, depending 78171 * on the value of units. More on that on the next paragraph. 78172 * 78173 * An optional object that can contain two more arguments: delay (number) and units (string). 78174 * 78175 * `delay`, specifying how much time we should wait before recording 78176 * 78177 * `units`, a string that can be either 'seconds' or 'frames'. By default it's 'seconds'. 78178 * 78179 * `units` specifies how the duration and delay arguments will behave. 78180 * If 'seconds', these arguments will correspond to seconds, meaning that 3 seconds worth of animation 78181 * will be created. If 'frames', the arguments now correspond to the number of frames you want your 78182 * animation to be, if you are very sure of this number. 78183 * 78184 * This may be called in setup, or, like in the example below, inside an event function, 78185 * like keyPressed or mousePressed. 78186 * 78187 * @method saveGif 78188 * @param {String} filename File name of your gif 78189 * @param {Number} duration Duration in seconds that you wish to capture from your sketch 78190 * @param {Object} options An optional object that can contain two more arguments: delay, specifying 78191 * how much time we should wait before recording, and units, a string that can be either 'seconds' or 78192 * 'frames'. By default it's 'seconds'. 78193 * 78194 * @example 78195 * <div> 78196 * <code> 78197 * function setup() { 78198 * createCanvas(100, 100); 78199 * } 78200 * 78201 * function draw() { 78202 * colorMode(RGB); 78203 * background(30); 78204 * 78205 * // create a bunch of circles that move in... circles! 78206 * for (let i = 0; i < 10; i++) { 78207 * let opacity = map(i, 0, 10, 0, 255); 78208 * noStroke(); 78209 * fill(230, 250, 90, opacity); 78210 * circle( 78211 * 30 * sin(frameCount / (30 - i)) + width / 2, 78212 * 30 * cos(frameCount / (30 - i)) + height / 2, 78213 * 10 78214 * ); 78215 * } 78216 * } 78217 * 78218 * // you can put it in the mousePressed function, 78219 * // or keyPressed for example 78220 * function keyPressed() { 78221 * // this will download the first 5 seconds of the animation! 78222 * if (key === 's') { 78223 * saveGif('mySketch', 5); 78224 * } 78225 * } 78226 * </code> 78227 * </div> 78228 * 78229 * @alt 78230 * animation of a group of yellow circles moving in circles over a dark background 78231 */ 78232 _main.default.prototype.saveGif = /*#__PURE__*/ 78233 function () { 78234 var _ref = _asyncToGenerator( /*#__PURE__*/ 78235 regeneratorRuntime.mark(function _callee(fileName, duration) { 78236 var options, 78237 delay, 78238 units, 78239 _frameRate, 78240 gifFrameDelay, 78241 nFrames, 78242 nFramesDelay, 78243 totalNumberOfFrames, 78244 frameIterator, 78245 lastPixelDensity, 78246 frames, 78247 progressBarIdName, 78248 p, 78249 pixels, 78250 gl, 78251 data, 78252 gif, 78253 globalPalette, 78254 paletteCache, 78255 getIndexedFrame, 78256 transparentIndex, 78257 prevIndexedFrame, 78258 i, 78259 indexedFrame, 78260 originalIndexedFrame, 78261 _i, 78262 buffer, 78263 extension, 78264 blob, 78265 _args = arguments; 78266 return regeneratorRuntime.wrap(function _callee$(_context) { 78267 while (1) { 78268 switch (_context.prev = _context.next) { 78269 case 0: 78270 options = _args.length > 2 && _args[2] !== undefined ? _args[2] : { 78271 delay: 0, 78272 units: 'seconds' 78273 }; 78274 if (!(typeof fileName !== 'string')) { 78275 _context.next = 3; 78276 break; 78277 } 78278 throw TypeError('fileName parameter must be a string'); 78279 case 3: 78280 if (!(typeof duration !== 'number')) { 78281 _context.next = 5; 78282 break; 78283 } 78284 throw TypeError('Duration parameter must be a number'); 78285 case 5: 78286 // extract variables for more comfortable use
78287 delay = options && options.delay || 0; // in seconds 78288 units = options && options.units || 'seconds'; // either 'seconds' or 'frames' 78289 // if arguments in the options object are not correct, cancel operation 78290 if (!(typeof delay !== 'number')) { 78291 _context.next = 9; 78292 break; 78293 } 78294 throw TypeError('Delay parameter must be a number'); 78295 case 9: 78296 if (!(units !== 'seconds' && units !== 'frames')) { 78297 _context.next = 11; 78298 break; 78299 } 78300 throw TypeError('Units parameter must be either "frames" or "seconds"'); 78301 case 11: 78302 this._recording = true; // get the project's framerate 78303 _frameRate = this._targetFrameRate; // if it is undefined or some non useful value, assume it's 60 78304 if (_frameRate === Infinity || _frameRate === undefined || _frameRate === 0) { 78305 _frameRate = 60; 78306 } // calculate frame delay based on frameRate 78307 // this delay has nothing to do with the 78308 // delay in options, but rather is the delay 78309 // we have to specify to the gif encoder between frames. 78310 78311 gifFrameDelay = 1 / _frameRate * 1000; // constrain it to be always greater than 20, 78312 // otherwise it won't work in some browsers and systems 78313 // reference: https://stackoverflow.com/questions/64473278/gif-frame-duration-seems-slower-than-expected 78314 gifFrameDelay = gifFrameDelay < 20 ? 20 : gifFrameDelay; // check the mode we are in and how many frames 78315 // that duration translates to 78316 nFrames = units === 'seconds' ? duration * _frameRate : duration; 78317 nFramesDelay = units === 'seconds' ? delay * _frameRate : delay; 78318 totalNumberOfFrames = nFrames + nFramesDelay; // initialize variables for the frames processing 78319 frameIterator = nFramesDelay; 78320 this.frameCount = frameIterator; 78321 lastPixelDensity = this._pixelDensity; 78322 this.pixelDensity(1); // We first take every frame that we are going to use for the animation 78323 frames = [ 78324 ]; 78325 progressBarIdName = 'p5.gif.progressBar'; 78326 if (document.getElementById(progressBarIdName) !== null) document.getElementById(progressBarIdName).remove(); 78327 p = this.createP(''); 78328 p.id('progressBar'); 78329 p.style('font-size', '16px'); 78330 p.style('font-family', 'Montserrat'); 78331 p.style('background-color', '#ffffffa0'); 78332 p.style('padding', '8px'); 78333 p.style('border-radius', '10px'); 78334 p.position(0, 0); 78335 if (this.drawingContext instanceof WebGLRenderingContext) { 78336 // if we have a WEBGL context, initialize the pixels array 78337 // and the gl context to use them inside the loop 78338 gl = document.getElementById('defaultCanvas0').getContext('webgl'); 78339 pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4); 78340 } // stop the loop since we are going to manually redraw 78341 78342 this.noLoop(); 78343 case 36: 78344 if (!(frameIterator < totalNumberOfFrames)) { 78345 _context.next = 47; 78346 break; 78347 } /* 78348 we draw the next frame. this is important, since 78349 busy sketches or low end devices might take longer 78350 to render some frames. So we just wait for the frame 78351 to be drawn and immediately save it to a buffer and continue 78352 */ 78353 78354 this.redraw(); // depending on the context we'll extract the pixels one way 78355 // or another 78356 data = undefined; 78357 if (this.drawingContext instanceof WebGLRenderingContext) { 78358 pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4); 78359 gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels); 78360 data = _flipPixels(pixels); 78361 } else { 78362 data = this.drawingContext.getImageData(0, 0, this.width, this.height).data; 78363 } 78364 frames.push(data); 78365 frameIterator++; 78366 p.html('Saved frame <b>' + frames.length.toString() + '</b> out of ' + nFrames.toString()); 78367 _context.next = 45; 78368 return new Promise(function (resolve) { 78369 return setTimeout(resolve, 0); 78370 }); 78371 case 45: 78372 _context.next = 36; 78373 break; 78374 case 47: 78375 p.html('Frames processed, generating color palette...'); 78376 this.loop(); 78377 this.pixelDensity(lastPixelDensity); // create the gif encoder and the colorspace format 78378 gif = (0, _gifenc.GIFEncoder) (); // calculate the global palette for this set of frames 78379 globalPalette = _generateGlobalPalette(frames); // Rather than using applyPalette() from the gifenc library, we use our 78380 // own function to map frame pixels to a palette color. This way, we can 78381 // cache palette color mappings between frames for extra performance, and 78382 // use our own caching mechanism to avoid flickering colors from cache 78383 // key collisions. 78384 paletteCache = { 78385 }; 78386 getIndexedFrame = function getIndexedFrame(frame) { 78387 var length = frame.length / 4; 78388 var index = new Uint8Array(length); 78389 for (var i = 0; i < length; i++) { 78390 var key = frame[i * 4] << 24 | frame[i * 4 + 1] << 16 | frame[i * 4 + 2] << 8 | frame[i * 4 + 3]; 78391 if (paletteCache[key] === undefined) { 78392 paletteCache[key] = (0, _gifenc.nearestColorIndex) (globalPalette, frame.slice(i * 4, (i + 1) * 4)); 78393 } 78394 index[i] = paletteCache[key]; 78395 } 78396 return index; 78397 };
78397 // the way we designed the palette means we always take the last index for transparency 78398 transparentIndex = globalPalette.length - 1; // we are going to iterate the frames in pairs, n-1 and n 78399 prevIndexedFrame = [ 78400 ]; 78401 i = 0; 78402 case 57: 78403 if (!(i < frames.length)) { 78404 _context.next = 68; 78405 break; 78406 } //const indexedFrame = applyPalette(frames[i], globalPaletteWithoutAlpha, 'rgba565'); 78407 78408 indexedFrame = getIndexedFrame(frames[i]); // Make a copy of the palette-applied frame before editing the original 78409 // to use transparent pixels 78410 originalIndexedFrame = indexedFrame.slice(); 78411 if (i === 0) { 78412 gif.writeFrame(indexedFrame, this.width, this.height, { 78413 palette: globalPalette, 78414 delay: gifFrameDelay, 78415 dispose: 1 78416 }); 78417 } else { 78418 // Matching pixels between frames can be set to full transparency, 78419 // allowing the previous frame's pixels to show through. We only do 78420 // this for pixels that get mapped to the same quantized color so that 78421 // the resulting image would be the same. 78422 for (_i = 0; _i < indexedFrame.length; _i++) { 78423 if (indexedFrame[_i] === prevIndexedFrame[_i]) { 78424 indexedFrame[_i] = transparentIndex; 78425 } 78426 } // Write frame into the encoder 78427 78428 gif.writeFrame(indexedFrame, this.width, this.height, { 78429 delay: gifFrameDelay, 78430 transparent: true, 78431 transparentIndex: transparentIndex, 78432 dispose: 1 78433 }); 78434 } 78435 prevIndexedFrame = originalIndexedFrame; 78436 p.html('Rendered frame <b>' + i.toString() + '</b> out of ' + nFrames.toString()); // this just makes the process asynchronous, preventing 78437 // that the encoding locks up the browser 78438 _context.next = 65; 78439 return new Promise(function (resolve) { 78440 return setTimeout(resolve, 0); 78441 }); 78442 case 65: 78443 i++; 78444 _context.next = 57; 78445 break; 78446 case 68: 78447 gif.finish(); // Get a direct typed array view into the buffer to avoid copying it 78448 buffer = gif.bytesView(); 78449 extension = 'gif'; 78450 blob = new Blob([buffer], { 78451 type: 'image/gif' 78452 }); 78453 frames = [ 78454 ]; 78455 this._recording = false; 78456 this.loop(); 78457 p.html('Done. Downloading your gif!ð¸'); 78458 _main.default.prototype.downloadFile(blob, fileName, extension); 78459 case 77: 78460 case 'end': 78461 return _context.stop(); 78462 } 78463 } 78464 }, _callee, this); 78465 })); 78466 return function (_x, _x2) { 78467 return _ref.apply(this, arguments); 78468 }; 78469 }(); 78470 function _flipPixels(pixels) { 78471 // extracting the pixels using readPixels returns 78472 // an upside down image. we have to flip it back 78473 // first. this solution is proposed by gman on 78474 // this stack overflow answer: 78475 // https://stackoverflow.com/questions/41969562/how-can-i-flip-the-result-of-webglrenderingcontext-readpixels 78476 var halfHeight = parseInt(height / 2); 78477 var bytesPerRow = width * 4; // make a temp buffer to hold one row 78478 var temp = new Uint8Array(width * 4); 78479 for (var y = 0; y < halfHeight; ++y) { 78480 var topOffset = y * bytesPerRow; 78481 var bottomOffset = (height - y - 1) * bytesPerRow; // make copy of a row on the top half 78482 temp.set(pixels.subarray(topOffset, topOffset + bytesPerRow)); // copy a row from the bottom half to the top 78483 pixels.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow); // copy the copy of the top half row to the bottom half 78484 pixels.set(temp, bottomOffset); 78485 } 78486 return pixels; 78487 } 78488 function _generateGlobalPalette(frames) { 78489 // make an array the size of every possible color in every possible frame 78490 // that is: width * height * frames. 78491 var allColors = new Uint8Array(frames.length * frames[0].length); // put every frame one after the other in sequence. 78492 // this array will hold absolutely every pixel from the animation. 78493 // the set function on the Uint8Array works super fast tho! 78494 for (var f = 0; f < frames.length; f++) { 78495 allColors.set(frames[f], f * frames[0].length); 78496 } // quantize this massive array into 256 colors and return it! 78497 78498 var colorPalette = (0, _gifenc.quantize) (allColors, 256, { 78499 format: 'rgba4444', 78500 oneBitAlpha: true 78501 }); // when generating the palette, we have to leave space for 1 of the 78502 // indices to be a random color that does not appear anywhere in our 78503 // animation to use for transparency purposes. So, if the palette is full 78504 // (has 256 colors), we overwrite the last one with a random, fully transparent 78505 // color. Otherwise, we just push a new color into the palette the same way. 78506 // this guarantees that when using the transparency index, there are no matches 78507 // between some colors of the animation and the "holes" we want to dig on them,
78508 // which would cause pieces of some frames to be transparent and thus look glitchy. 78509 if (colorPalette.length === 256) { 78510 colorPalette[colorPalette.length - 1] = [ 78511 Math.random() * 255, 78512 Math.random() * 255, 78513 Math.random() * 255, 78514 0 78515 ]; 78516 } else { 78517 colorPalette.push([Math.random() * 255, 78518 Math.random() * 255, 78519 Math.random() * 255, 78520 0]); 78521 } 78522 return colorPalette; 78523 } /** 78524 * Helper function for loading GIF-based images 78525 */ 78526 78527 function _createGif(arrayBuffer, pImg, successCallback, failureCallback, finishCallback) { 78528 var gifReader = new _omggif.default.GifReader(arrayBuffer); 78529 pImg.width = pImg.canvas.width = gifReader.width; 78530 pImg.height = pImg.canvas.height = gifReader.height; 78531 var frames = [ 78532 ]; 78533 var numFrames = gifReader.numFrames(); 78534 var framePixels = new Uint8ClampedArray(pImg.width * pImg.height * 4); 78535 if (numFrames > 1) { 78536 var loadGIFFrameIntoImage = function loadGIFFrameIntoImage(frameNum, gifReader) { 78537 try { 78538 gifReader.decodeAndBlitFrameRGBA(frameNum, framePixels); 78539 } catch (e) { 78540 _main.default._friendlyFileLoadError(8, pImg.src); 78541 if (typeof failureCallback === 'function') { 78542 failureCallback(e); 78543 } else { 78544 console.error(e); 78545 } 78546 } 78547 }; 78548 for (var j = 0; j < numFrames; j++) { 78549 var frameInfo = gifReader.frameInfo(j); 78550 var prevFrameData = pImg.drawingContext.getImageData(0, 0, pImg.width, pImg.height); 78551 framePixels = prevFrameData.data.slice(); 78552 loadGIFFrameIntoImage(j, gifReader); 78553 var imageData = new ImageData(framePixels, pImg.width, pImg.height); 78554 pImg.drawingContext.putImageData(imageData, 0, 0); 78555 var frameDelay = frameInfo.delay; // To maintain the default of 10FPS when frameInfo.delay equals to 0 78556 if (frameDelay === 0) { 78557 frameDelay = 10; 78558 } 78559 frames.push({ 78560 image: pImg.drawingContext.getImageData(0, 0, pImg.width, pImg.height), 78561 delay: frameDelay * 10 //GIF stores delay in one-hundredth of a second, shift to ms 78562 }); // Some GIFs are encoded so that they expect the previous frame 78563 // to be under the current frame. This can occur at a sub-frame level 78564 // 78565 // Values : 0 - No disposal specified. The decoder is 78566 // not required to take any action. 78567 // 1 - Do not dispose. The graphic is to be left 78568 // in place. 78569 // 2 - Restore to background color. The area used by the 78570 // graphic must be restored to the background color. 78571 // 3 - Restore to previous. The decoder is required to 78572 // restore the area overwritten by the graphic with 78573 // what was there prior to rendering the graphic. 78574 // 4-7 - To be defined. 78575 if (frameInfo.disposal === 2) { 78576 // Restore background color 78577 pImg.drawingContext.clearRect(frameInfo.x, frameInfo.y, frameInfo.width, frameInfo.height); 78578 } else if (frameInfo.disposal === 3) { 78579 // Restore previous 78580 pImg.drawingContext.putImageData(prevFrameData, 0, 0, frameInfo.x, frameInfo.y, frameInfo.width, frameInfo.height); 78581 } 78582 } //Uses Netscape block encoding 78583 //to repeat forever, this will be 0 78584 //to repeat just once, this will be null 78585 //to repeat N times (1<N), should contain integer for loop number 78586 //this is changed to more usable values for us 78587 //to repeat forever, loopCount = null 78588 //everything else is just the number of loops 78589
78590 var loopLimit = gifReader.loopCount(); 78591 if (loopLimit === null) { 78592 loopLimit = 1; 78593 } else if (loopLimit === 0) { 78594 loopLimit = null; 78595 } // we used the pImg for painting and saving during load 78596 // so we have to reset it to the first frame 78597 78598 pImg.drawingContext.putImageData(frames[0].image, 0, 0); 78599 pImg.gifProperties = { 78600 displayIndex: 0, 78601 loopLimit: loopLimit, 78602 loopCount: 0, 78603 frames: frames, 78604 numFrames: numFrames, 78605 playing: true, 78606 timeDisplayed: 0, 78607 lastChangeTime: 0 78608 }; 78609 } 78610 if (typeof successCallback === 'function') { 78611 successCallback(pImg); 78612 } 78613 finishCallback(); 78614 } /** 78615 * @private 78616 * @param {Constant} xAlign either LEFT, RIGHT or CENTER 78617 * @param {Constant} yAlign either TOP, BOTTOM or CENTER 78618 * @param {Number} dx 78619 * @param {Number} dy 78620 * @param {Number} dw 78621 * @param {Number} dh 78622 * @param {Number} sw 78623 * @param {Number} sh 78624 * @returns {Object} 78625 */ 78626 78627 function _imageContain(xAlign, yAlign, dx, dy, dw, dh, sw, sh) { 78628 var r = Math.max(sw / dw, sh / dh); 78629 var adjusted_dw = sw / r, 78630 adjusted_dh = sh / r; 78631 var x = dx; 78632 var y = dy; 78633 if (xAlign === constants.CENTER) { 78634 x += (dw - adjusted_dw) / 2; 78635 } else if (xAlign === constants.RIGHT) { 78636 x += dw - adjusted_dw; 78637 } 78638 if (yAlign === constants.CENTER) { 78639 y += (dh - adjusted_dh) / 2; 78640 } else if (yAlign === constants.BOTTOM) { 78641 y += dh - adjusted_dh; 78642 } 78643 return { 78644 x: x, 78645 y: y, 78646 w: adjusted_dw, 78647 h: adjusted_dh 78648 }; 78649 } /** 78650 * @private 78651 * @param {Constant} xAlign either LEFT, RIGHT or CENTER 78652 * @param {Constant} yAlign either TOP, BOTTOM or CENTER 78653 * @param {Number} dw 78654 * @param {Number} dh 78655 * @param {Number} sx 78656 * @param {Number} sy 78657 * @param {Number} sw 78658 * @param {Number} sh 78659 * @returns {Object} 78660 */ 78661 78662 function _imageCover(xAlign, yAlign, dw, dh, sx, sy, sw, sh) { 78663 var r = Math.max(dw / sw, dh / sh); 78664 var adjusted_sw = dw / r, 78665 adjusted_sh = dh / r; 78666 var x = sx; 78667 var y = sy; 78668 if (xAlign === constants.CENTER) { 78669 x += (sw - adjusted_sw) / 2; 78670 } else if (xAlign === constants.RIGHT) { 78671 x += sw - adjusted_sw; 78672 } 78673 if (yAlign === constants.CENTER) { 78674 y += (sh - adjusted_sh) / 2; 78675 } else if (yAlign === constants.BOTTOM) { 78676 y += sh - adjusted_sh; 78677 } 78678 return { 78679 x: x, 78680 y: y, 78681 w: adjusted_sw, 78682 h: adjusted_sh 78683 }; 78684 } /** 78685 * @private 78686 * @param {Constant} [fit] either CONTAIN or COVER 78687 * @param {Constant} xAlign either LEFT, RIGHT or CENTER 78688 * @param {Constant} yAlign either TOP, BOTTOM or CENTER 78689 * @param {Number} dx 78690 * @param {Number} dy 78691 * @param {Number} dw 78692 * @param {Number} dh 78693 * @param {Number} sx 78694 * @param {Number} sy 78695 * @param {Number} sw 78696 * @param {Number} sh 78697 * @returns {Object} 78698 */ 78699 78700 function _imageFit(fit, xAlign, yAlign, dx, dy, dw, dh, sx, sy, sw, sh) { 78701 if (fit === constants.COVER) { 78702 var _imageCover2 = _imageCover(xAlign, yAlign, dw, dh, sx, sy, sw, sh), 78703 x = _imageCover2.x, 78704 y = _imageCover2.y, 78705 w = _imageCover2.w, 78706 h = _imageCover2.h; 78707 sx = x; 78708 sy = y; 78709 sw = w; 78710 sh = h; 78711 } 78712 if (fit === constants.CONTAIN) { 78713 var _imageContain2 = _imageContain(xAlign, yAlign, dx, dy, dw, dh, sw, sh), 78714 _x3 = _imageContain2.x, 78715 _y = _imageContain2.y, 78716 _w = _imageContain2.w, 78717 _h = _imageContain2.h; 78718 dx = _x3; 78719 dy = _y; 78720 dw = _w; 78721 dh = _h; 78722 } 78723 return { 78724 sx: sx, 78725 sy: sy, 78726 sw: sw, 78727 sh: sh, 78728 dx: dx, 78729 dy: dy, 78730 dw: dw, 78731 dh: dh 78732 }; 78733 } /** 78734 * Validates clipping params. Per drawImage spec sWidth and sHight cannot be 78735 * negative or greater than image intrinsic width and height 78736 * @private 78737 * @param {Number} sVal 78738 * @param {Number} iVal 78739 * @returns {Number} 78740 * @private 78741 */ 78742 78743 function _sAssign(sVal, iVal) { 78744 if (sVal > 0 && sVal < iVal) { 78745 return sVal; 78746 } else { 78747 return iVal; 78748 } 78749 } /** 78750 * Draw an image to the p5.js canvas. 78751 * 78752 * This function can be used with different numbers of parameters. The
78753 * simplest use requires only three parameters: img, x, and yâwhere (x, y) is 78754 * the position of the image. Two more parameters can optionally be added to 78755 * specify the width and height of the image. 78756 * 78757 * This function can also be used with eight Number parameters. To 78758 * differentiate between all these parameters, p5.js uses the language of 78759 * "destination rectangle" (which corresponds to "dx", "dy", etc.) and "source 78760 * image" (which corresponds to "sx", "sy", etc.) below. Specifying the 78761 * "source image" dimensions can be useful when you want to display a 78762 * subsection of the source image instead of the whole thing. Here's a diagram 78763 * to explain further: 78764 * <img src="assets/drawImage.png"></img> 78765 * 78766 * This function can also be used to draw images without distorting the orginal aspect ratio, 78767 * by adding 9th parameter, fit, which can either be COVER or CONTAIN. 78768 * CONTAIN, as the name suggests, contains the whole image within the specified destination box 78769 * without distorting the image ratio. 78770 * COVER covers the entire destination box. 78771 * 78772 * 78773 * 78774 * @method image 78775 * @param {p5.Image|p5.Element|p5.Texture} img the image to display 78776 * @param {Number} x the x-coordinate of the top-left corner of the image 78777 * @param {Number} y the y-coordinate of the top-left corner of the image 78778 * @param {Number} [width] the width to draw the image 78779 * @param {Number} [height] the height to draw the image 78780 * @example 78781 * <div> 78782 * <code> 78783 * let img; 78784 * function preload() { 78785 * img = loadImage('assets/laDefense.jpg'); 78786 * } 78787 * function setup() { 78788 * // Top-left corner of the img is at (0, 0) 78789 * // Width and height are the img's original width and height 78790 * image(img, 0, 0); 78791 * } 78792 * </code> 78793 * </div> 78794 * <div> 78795 * <code> 78796 * let img; 78797 * function preload() { 78798 * img = loadImage('assets/laDefense.jpg'); 78799 * } 78800 * function setup() { 78801 * background(50); 78802 * // Top-left corner of the img is at (10, 10) 78803 * // Width and height are 50Ã50 78804 * image(img, 10, 10, 50, 50); 78805 * } 78806 * </code> 78807 * </div> 78808 * <div> 78809 * <code> 78810 * function setup() { 78811 * // Here, we use a callback to display the image after loading 78812 * loadImage('assets/laDefense.jpg', img => { 78813 * image(img, 0, 0); 78814 * }); 78815 * } 78816 * </code> 78817 * </div> 78818 * <div> 78819 * <code> 78820 * let img; 78821 * function preload() { 78822 * img = loadImage('assets/gradient.png'); 78823 * } 78824 * function setup() { 78825 * // 1. Background image 78826 * // Top-left corner of the img is at (0, 0) 78827 * // Width and height are the img's original width and height, 100Ã100 78828 * image(img, 0, 0); 78829 * // 2. Top right image 78830 * // Top-left corner of destination rectangle is at (50, 0) 78831 * // Destination rectangle width and height are 40Ã20 78832 * // The next parameters are relative to the source image: 78833 * // - Starting at position (50, 50) on the source image, capture a 50Ã50 78834 * // subsection 78835 * // - Draw this subsection to fill the dimensions of the destination rectangle 78836 * image(img, 50, 0, 40, 20, 50, 50, 50, 50); 78837 * } 78838 * </code> 78839 * </div> 78840 * <div> 78841 * <code> 78842 * let img; 78843 * function preload() { 78844 * // dimensions of image are 780 x 440 78845 * // dimensions of canvas are 100 x 100 78846 * img = loadImage('assets/moonwalk.jpg'); 78847 * } 78848 * function setup() { 78849 * // CONTAIN the whole image without distorting the image's aspect ratio 78850 * // CONTAIN the image within the specified destination box and display at LEFT,CENTER position 78851 * background(color('green')); 78852 * image(img, 0, 0, width, height, 0, 0, img.width, img.height, CONTAIN, LEFT); 78853 * } 78854 * </code> 78855 * </div> 78856 * <div> 78857 * <code> 78858 * let img; 78859 * function preload() { 78860 * img = loadImage('assets/laDefense50.png'); // dimensions of image are 50 x 50 78861 * } 78862 * function setup() { 78863 * // COVER the whole destination box without distorting the image's aspect ratio 78864 * // COVER the specified destination box which is of dimension 100 x 100 78865 * // Without specifying xAlign or yAlign, the image will be 78866 * // centered in the destination box in both axes 78867 * image(img, 0, 0, width, height, 0, 0, img.width, img.height, COVER); 78868 * } 78869 * </code> 78870 * </div> 78871 * @alt 78872 * image of the underside of a white umbrella and gridded ceiling above 78873 * image of the underside of a white umbrella and gridded ceiling above 78874 */ 78875 /** 78876 * @method image 78877 * @param {p5.Image|p5.Element|p5.Texture} img 78878 * @param {Number} dx the x-coordinate of the destination 78879 * rectangle in which to draw the source image 78880 * @param {Number} dy the y-coordinate of the destination 78881 * rectangle in which to draw the source image 78882 * @param {Number} dWidth the width of the destination rectangle 78883 * @param {Number} dHeight the height of the destination rectangle 78884 * @param {Number} sx the x-coordinate of the subsection of the source 78885 * image to draw into the destination rectangle 78886 * @param {Number} sy the y-coordinate of the subsection of the source 78887 * image to draw into the destination rectangle 78888 * @param {Number} [sWidth] the width of the subsection of the 78889 * source image to draw into the destination 78890 * rectangle 78891 * @param {Number} [sHeight] the height of the subsection of the 78892 * source image to draw into the destination rectangle 78893 * @param {Constant} [fit] either CONTAIN or COVER 78894 * @param {Constant} [xAlign] either LEFT, RIGHT or CENTER default is CENTER 78895 * @param {Constant} [yAlign] either TOP, BOTTOM or CENTER default is CENTER 78896 */ 78897 78898 _main.default.prototype.image = function (img, dx, dy, dWidth, dHeight, sx, sy, sWidth, sHeight, fit, xAlign, yAlign) { 78899 // set defaults per spec: https://goo.gl/3ykfOq 78900 _main.default._validateParameters('image', arguments); 78901 var defW = img.width;
78902 var defH = img.height; 78903 yAlign = yAlign || constants.CENTER; 78904 xAlign = xAlign || constants.CENTER; 78905 if (img.elt && img.elt.videoWidth && !img.canvas) { 78906 // video no canvas 78907 defW = img.elt.videoWidth; 78908 defH = img.elt.videoHeight; 78909 } 78910 var _dx = dx; 78911 var _dy = dy; 78912 var _dw = dWidth || defW; 78913 var _dh = dHeight || defH; 78914 var _sx = sx || 0; 78915 var _sy = sy || 0; 78916 var _sw = sWidth || defW; 78917 var _sh = sHeight || defH; 78918 _sw = _sAssign(_sw, defW); 78919 _sh = _sAssign(_sh, defH); // This part needs cleanup and unit tests 78920 // see issues https://github.com/processing/p5.js/issues/1741 78921 // and https://github.com/processing/p5.js/issues/1673 78922 var pd = 1; 78923 if (img.elt && !img.canvas && img.elt.style.width) { 78924 //if img is video and img.elt.size() has been used and 78925 //no width passed to image() 78926 if (img.elt.videoWidth && !dWidth) { 78927 pd = img.elt.videoWidth; 78928 } else { 78929 //all other cases 78930 pd = img.elt.width; 78931 } 78932 pd /= parseInt(img.elt.style.width, 10); 78933 } 78934 _sx *= pd; 78935 _sy *= pd; 78936 _sh *= pd; 78937 _sw *= pd; 78938 var vals = _helpers.default.modeAdjust(_dx, _dy, _dw, _dh, this._renderer._imageMode); 78939 vals = _imageFit(fit, xAlign, yAlign, vals.x, vals.y, vals.w, vals.h, _sx, _sy, _sw, _sh); // tint the image if there is a tint 78940 this._renderer.image(img, vals.sx, vals.sy, vals.sw, vals.sh, vals.dx, vals.dy, vals.dw, vals.dh); 78941 }; 78942 /** 78943 * Sets the fill value for displaying images. Images can be tinted to 78944 * specified colors or made transparent by including an alpha value. 78945 * 78946 * To apply transparency to an image without affecting its color, use 78947 * white as the tint color and specify an alpha value. For instance, 78948 * tint(255, 128) will make an image 50% transparent (assuming the default 78949 * alpha range of 0-255, which can be changed with <a href="#/p5/colorMode">colorMode()</a>). 78950 * 78951 * The value for the gray parameter must be less than or equal to the current 78952 * maximum value as specified by <a href="#/p5/colorMode">colorMode()</a>. The default maximum value is 78953 * 255. 78954 * 78955 * @method tint 78956 * @param {Number} v1 red or hue value relative to 78957 * the current color range 78958 * @param {Number} v2 green or saturation value 78959 * relative to the current color range 78960 * @param {Number} v3 blue or brightness value 78961 * relative to the current color range 78962 * @param {Number} [alpha] 78963 * 78964 * @example 78965 * <div> 78966 * <code> 78967 * let img; 78968 * function preload() { 78969 * img = loadImage('assets/laDefense.jpg'); 78970 * } 78971 * function setup() { 78972 * image(img, 0, 0); 78973 * tint(0, 153, 204); // Tint blue 78974 * image(img, 50, 0); 78975 * } 78976 * </code> 78977 * </div> 78978 * 78979 * <div> 78980 * <code> 78981 * let img; 78982 * function preload() { 78983 * img = loadImage('assets/laDefense.jpg'); 78984 * } 78985 * function setup() { 78986 * image(img, 0, 0); 78987 * tint(0, 153, 204, 126); // Tint blue and set transparency 78988 * image(img, 50, 0); 78989 * } 78990 * </code> 78991 * </div> 78992 * 78993 * <div> 78994 * <code> 78995 * let img; 78996 * function preload() { 78997 * img = loadImage('assets/laDefense.jpg'); 78998 * } 78999 * function setup() { 79000 * image(img, 0, 0); 79001 * tint(255, 126); // Apply transparency without changing color 79002 * image(img, 50, 0); 79003 * } 79004 * </code> 79005 * </div> 79006 * 79007 * @alt 79008 * 2 side by side images of umbrella and ceiling, one image with blue tint 79009 * Images of umbrella and ceiling, one half of image with blue tint 79010 * 2 side by side images of umbrella and ceiling, one image translucent 79011 */ 79012 /** 79013 * @method tint 79014 * @param {String} value a color string 79015 */ 79016 /** 79017 * @method tint 79018 * @param {Number} gray a gray value 79019 * @param {Number} [alpha] 79020 */ 79021 /** 79022 * @method tint 79023 * @param {Number[]} values an array containing the red,green,blue & 79024 * and alpha components of the color 79025 */ 79026 /** 79027 * @method tint 79028 * @param {p5.Color} color the tint color 79029 */ 79030 _main.default.prototype.tint = function () { 79031 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 79032 args[_key] = arguments[_key]; 79033 } 79034 _main.default._validateParameters('tint', args); 79035 var c = this.color.apply(this, args); 79036 this._renderer._tint = c.levels; 79037 }; 79038 /** 79039 * Removes the current fill value for displaying images and reverts to 79040 * displaying images with their original hues. 79041 * 79042 * @method noTint 79043 * @example 79044 * <div> 79045 * <code> 79046 * let img; 79047 * function preload() { 79048 * img = loadImage('assets/bricks.jpg'); 79049 * } 79050 * function setup() { 79051 * tint(0, 153, 204); // Tint blue 79052 * image(img, 0, 0); 79053 * noTint(); // Disable tint 79054 * image(img, 50, 0); 79055 * } 79056 * </code> 79057 * </div> 79058 * 79059 * @alt 79060 * 2 side by side images of bricks, left image with blue tint 79061 */ 79062 _main.default.prototype.noTint = function () { 79063 this._renderer._tint = null; 79064 }; 79065 /** 79066 * Apply the current tint color to the input image, return the resulting 79067 * canvas. 79068 * 79069 * @private 79070 * @param {p5.Image} The image to be tinted 79071 * @return {canvas} The resulting tinted canvas 79072 */ 79073 _main.default.prototype._getTintedImageCanvas = _main.default.Renderer2D.prototype._getTintedImageCanvas; 79074 /** 79075 * Set image mode. Modifies the location from which images are drawn by 79076 * changing the way in which parameters given to <a href="#/p5/image">image()</a> are interpreted. 79077 * The default mode is imageMode(CORNER), which interprets the second and 79078 * third parameters of <a href="#/p5/image">image()</a> as the upper-left corner of the image. If 79079 * two additional parameters are specified, they are used to set the image's 79080 * width and height. 79081 * 79082 * imageMode(CORNERS) interprets the second and third parameters of <a href="#/p5/image">image()</a> 79083 * as the location of one corner, and the fourth and fifth parameters as the 79084 * opposite corner. 79085 * 79086 * imageMode(CENTER) interprets the second and third parameters of <a href="#/p5/image">image()</a> 79087 * as the image's center point. If two additional parameters are specified, 79088 * they are used to set the image's width and height. 79089 * 79090 * @method imageMode 79091 * @param {Constant} mode either CORNER, CORNERS, or CENTER 79092 * @example 79093 * 79094 * <div> 79095 * <code> 79096 * let img; 79097 * function preload() { 79098 * img = loadImage('assets/bricks.jpg'); 79099 * } 79100 * function setup() { 79101 * imageMode(CORNER);
79102 * image(img, 10, 10, 50, 50); 79103 * } 79104 * </code> 79105 * </div> 79106 * 79107 * <div> 79108 * <code> 79109 * let img; 79110 * function preload() { 79111 * img = loadImage('assets/bricks.jpg'); 79112 * } 79113 * function setup() { 79114 * imageMode(CORNERS); 79115 * image(img, 10, 10, 90, 40); 79116 * } 79117 * </code> 79118 * </div> 79119 * 79120 * <div> 79121 * <code> 79122 * let img; 79123 * function preload() { 79124 * img = loadImage('assets/bricks.jpg'); 79125 * } 79126 * function setup() { 79127 * imageMode(CENTER); 79128 * image(img, 50, 50, 80, 80); 79129 * } 79130 * </code> 79131 * </div> 79132 * 79133 * @alt 79134 * small square image of bricks 79135 * horizontal rectangle image of bricks 79136 * large square image of bricks 79137 */ 79138 _main.default.prototype.imageMode = function (m) { 79139 _main.default._validateParameters('imageMode', arguments); 79140 if (m === constants.CORNER || m === constants.CORNERS || m === constants.CENTER) { 79141 this._renderer._imageMode = m; 79142 } 79143 }; 79144 var _default = _main.default; 79145 exports.default = _default; 79146 }, 79147 { 79148 '../core/constants': 278, 79149 '../core/friendly_errors/fes_core': 281, 79150 '../core/friendly_errors/file_errors': 282, 79151 '../core/friendly_errors/validate_params': 285, 79152 '../core/helpers': 286, 79153 '../core/main': 290, 79154 'core-js/modules/es.array.copy-within': 168, 79155 'core-js/modules/es.array.includes': 174, 79156 'core-js/modules/es.array.index-of': 175, 79157 'core-js/modules/es.array.iterator': 176, 79158 'core-js/modules/es.array.slice': 180, 79159 'core-js/modules/es.object.get-own-property-descriptor': 191, 79160 'core-js/modules/es.object.to-string': 195, 79161 'core-js/modules/es.promise': 196, 79162 'core-js/modules/es.regexp.to-string': 200, 79163 'core-js/modules/es.string.includes': 203, 79164 'core-js/modules/es.string.iterator': 204, 79165 'core-js/modules/es.symbol': 214, 79166 'core-js/modules/es.symbol.description': 212, 79167 'core-js/modules/es.symbol.iterator': 213, 79168 'core-js/modules/es.typed-array.copy-within': 215, 79169 'core-js/modules/es.typed-array.every': 216, 79170 'core-js/modules/es.typed-array.fill': 217, 79171 'core-js/modules/es.typed-array.filter': 218, 79172 'core-js/modules/es.typed-array.find': 220, 79173 'core-js/modules/es.typed-array.find-index': 219, 79174 'core-js/modules/es.typed-array.for-each': 223, 79175 'core-js/modules/es.typed-array.includes': 224, 79176 'core-js/modules/es.typed-array.index-of': 225, 79177 'core-js/modules/es.typed-array.iterator': 228, 79178 'core-js/modules/es.typed-array.join': 229, 79179 'core-js/modules/es.typed-array.last-index-of': 230, 79180 'core-js/modules/es.typed-array.map': 231, 79181 'core-js/modules/es.typed-array.reduce': 233, 79182 'core-js/modules/es.typed-array.reduce-right': 232, 79183 'core-js/modules/es.typed-array.reverse': 234, 79184 'core-js/modules/es.typed-array.set': 235, 79185 'core-js/modules/es.typed-array.slice': 236, 79186 'core-js/modules/es.typed-array.some': 237, 79187 'core-js/modules/es.typed-array.sort': 238, 79188 'core-js/modules/es.typed-array.subarray': 239, 79189 'core-js/modules/es.typed-array.to-locale-string': 240, 79190 'core-js/modules/es.typed-array.to-string': 241, 79191 'core-js/modules/es.typed-array.uint8-array': 244, 79192 'core-js/modules/es.typed-array.uint8-clamped-array': 245, 79193 'core-js/modules/es.weak-map': 246, 79194 'core-js/modules/web.dom-collections.iterator': 248, 79195 'gifenc': 255, 79196 'omggif': 262, 79197 'regenerator-runtime/runtime': 266 79198 } 79199 ], 79200 314: [ 79201 function (_dereq_, module, exports) { 79202 'use strict'; 79203 _dereq_('core-js/modules/es.symbol'); 79204 _dereq_('core-js/modules/es.symbol.description'); 79205 _dereq_('core-js/modules/es.symbol.iterator'); 79206 _dereq_('core-js/modules/es.array.filter'); 79207 _dereq_('core-js/modules/es.array.iterator'); 79208 _dereq_('core-js/modules/es.object.to-string'); 79209 _dereq_('core-js/modules/es.string.iterator'); 79210 _dereq_('core-js/modules/web.dom-collections.iterator'); 79211 _dereq_('core-js/modules/es.symbol'); 79212 _dereq_('core-js/modules/es.symbol.description'); 79213 _dereq_('core-js/modules/es.symbol.iterator'); 79214 _dereq_('core-js/modules/es.array.filter'); 79215 _dereq_('core-js/modules/es.array.iterator'); 79216 _dereq_('core-js/modules/es.object.to-string'); 79217 _dereq_('core-js/modules/es.string.iterator'); 79218 _dereq_('core-js/modules/web.dom-collections.iterator'); 79219 Object.defineProperty(exports, '__esModule', { 79220 value: true 79221 }); 79222 exports.default = void 0; 79223 var _main = _interopRequireDefault(_dereq_('../core/main')); 79224 var _filters = _interopRequireDefault(_dereq_('./filters')); 79225 function _interopRequireDefault(obj) { 79226 return obj && obj.__esModule ? obj : { 79227 default: 79228 obj 79229 }; 79230 } /** 79231 * @module Image
79232 * @submodule Image 79233 * @requires core 79234 * @requires constants 79235 * @requires filters 79236 */ 79237 /** 79238 * This module defines the <a href="#/p5.Image">p5.Image</a> class and P5 methods for 79239 * drawing images to the main display canvas. 79240 */ 79241 /* 79242 * Class methods 79243 */ 79244 /** 79245 * Creates a new <a href="#/p5.Image">p5.Image</a>. A <a href="#/p5.Image">p5.Image</a> is a canvas backed representation of an 79246 * image. 79247 * 79248 * p5 can display .gif, .jpg and .png images. Images may be displayed 79249 * in 2D and 3D space. Before an image is used, it must be loaded with the 79250 * <a href="#/p5/loadImage">loadImage()</a> function. The <a href="#/p5.Image">p5.Image</a> class contains fields for the width and 79251 * height of the image, as well as an array called <a href="#/p5.Image/pixels">pixels[]</a> that contains the 79252 * values for every pixel in the image. 79253 * 79254 * The methods described below allow easy access to the image's pixels and 79255 * alpha channel and simplify the process of compositing. 79256 * 79257 * Before using the <a href="#/p5.Image/pixels">pixels[]</a> array, be sure to use the <a href="#/p5.Image/loadPixels">loadPixels()</a> method on 79258 * the image to make sure that the pixel data is properly loaded. 79259 * @example 79260 * <div><code> 79261 * function setup() { 79262 * let img = createImage(100, 100); // same as new p5.Image(100, 100); 79263 * img.loadPixels(); 79264 * createCanvas(100, 100); 79265 * background(0); 79266 * 79267 * // helper for writing color to array 79268 * function writeColor(image, x, y, red, green, blue, alpha) { 79269 * let index = (x + y * width) * 4; 79270 * image.pixels[index] = red; 79271 * image.pixels[index + 1] = green; 79272 * image.pixels[index + 2] = blue; 79273 * image.pixels[index + 3] = alpha; 79274 * } 79275 * 79276 * let x, y; 79277 * // fill with random colors 79278 * for (y = 0; y < img.height; y++) { 79279 * for (x = 0; x < img.width; x++) { 79280 * let red = random(255); 79281 * let green = random(255); 79282 * let blue = random(255); 79283 * let alpha = 255; 79284 * writeColor(img, x, y, red, green, blue, alpha); 79285 * } 79286 * } 79287 * 79288 * // draw a red line 79289 * y = 0; 79290 * for (x = 0; x < img.width; x++) { 79291 * writeColor(img, x, y, 255, 0, 0, 255); 79292 * } 79293 * 79294 * // draw a green line 79295 * y = img.height - 1; 79296 * for (x = 0; x < img.width; x++) { 79297 * writeColor(img, x, y, 0, 255, 0, 255); 79298 * } 79299 * 79300 * img.updatePixels(); 79301 * image(img, 0, 0); 79302 * } 79303 * </code></div> 79304 * 79305 * @class p5.Image 79306 * @constructor 79307 * @param {Number} width 79308 * @param {Number} height 79309 */ 79310 79311 _main.default.Image = function (width, height) { 79312 /** 79313 * Image width. 79314 * @property {Number} width 79315 * @readOnly 79316 * @example 79317 * <div><code> 79318 * let img; 79319 * function preload() { 79320 * img = loadImage('assets/rockies.jpg'); 79321 * } 79322 * 79323 * function setup() { 79324 * createCanvas(100, 100); 79325 * image(img, 0, 0); 79326 * for (let i = 0; i < img.width; i++) { 79327 * let c = img.get(i, img.height / 2); 79328 * stroke(c); 79329 * line(i, height / 2, i, height); 79330 * } 79331 * } 79332 * </code></div> 79333 * 79334 * @alt 79335 * rocky mountains in top and horizontal lines in corresponding colors in bottom. 79336 * 79337 */ 79338 this.width = width; 79339 /** 79340 * Image height. 79341 * @property {Number} height 79342 * @readOnly 79343 * @example 79344 * <div><code> 79345 * let img; 79346 * function preload() { 79347 * img = loadImage('assets/rockies.jpg'); 79348 * } 79349 * 79350 * function setup() { 79351 * createCanvas(100, 100); 79352 * image(img, 0, 0); 79353 * for (let i = 0; i < img.height; i++) { 79354 * let c = img.get(img.width / 2, i); 79355 * stroke(c); 79356 * line(0, i, width / 2, i); 79357 * } 79358 * } 79359 * </code></div> 79360 * 79361 * @alt 79362 * rocky mountains on right and vertical lines in corresponding colors on left. 79363 * 79364 */ 79365 this.height = height; 79366 this.canvas = document.createElement('canvas'); 79367 this.canvas.width = this.width; 79368 this.canvas.height = this.height; 79369 this.drawingContext = this.canvas.getContext('2d'); 79370 this._pixelsState = this; 79371 this._pixelDensity = 1; //Object for working with GIFs, defaults to null 79372 this.gifProperties = null; //For WebGL Texturing only: used to determine whether to reupload texture to GPU 79373 this._modified = false;
79374 /** 79375 * Array containing the values for all the pixels in the display window. 79376 * These values are numbers. This array is the size (include an appropriate 79377 * factor for pixelDensity) of the display window x4, 79378 * representing the R, G, B, A values in order for each pixel, moving from 79379 * left to right across each row, then down each column. Retina and other 79380 * high density displays may have more pixels (by a factor of 79381 * pixelDensity^2). 79382 * For example, if the image is 100Ã100 pixels, there will be 40,000. With 79383 * pixelDensity = 2, there will be 160,000. The first four values 79384 * (indices 0-3) in the array will be the R, G, B, A values of the pixel at 79385 * (0, 0). The second four values (indices 4-7) will contain the R, G, B, A 79386 * values of the pixel at (1, 0). More generally, to set values for a pixel 79387 * at (x, y): 79388 * ```javascript 79389 * let d = pixelDensity(); 79390 * for (let i = 0; i < d; i++) { 79391 * for (let j = 0; j < d; j++) { 79392 * // loop over 79393 * index = 4 * ((y * d + j) * width * d + (x * d + i
79393)); 79394 * pixels[index] = r; 79395 * pixels[index+1] = g; 79396 * pixels[index+2] = b; 79397 * pixels[index+3] = a; 79398 * } 79399 * } 79400 * ``` 79401 * 79402 * Before accessing this array, the data must loaded with the <a href="#/p5.Image/loadPixels">loadPixels()</a> 79403 * function. After the array data has been modified, the <a href="#/p5.Image/updatePixels">updatePixels()</a> 79404 * function must be run to update the changes. 79405 * @property {Number[]} pixels 79406 * @example 79407 * <div> 79408 * <code> 79409 * let img = createImage(66, 66); 79410 * img.loadPixels(); 79411 * for (let i = 0; i < img.width; i++) { 79412 * for (let j = 0; j < img.height; j++) { 79413 * img.set(i, j, color(0, 90, 102)); 79414 * } 79415 * } 79416 * img.updatePixels(); 79417 * image(img, 17, 17); 79418 * </code> 79419 * </div> 79420 * <div> 79421 * <code> 79422 * let pink = color(255, 102, 204); 79423 * let img = createImage(66, 66); 79424 * img.loadPixels(); 79425 * for (let i = 0; i < 4 * (width * height / 2); i += 4) { 79426 * img.pixels[i] = red(pink); 79427 * img.pixels[i + 1] = green(pink); 79428 * img.pixels[i + 2] = blue(pink); 79429 * img.pixels[i + 3] = alpha(pink); 79430 * } 79431 * img.updatePixels(); 79432 * image(img, 17, 17); 79433 * </code> 79434 * </div> 79435 * 79436 * @alt 79437 * 66Ã66 turquoise rect in center of canvas 79438 * 66Ã66 pink rect in center of canvas 79439 * 79440 */ 79441 this.pixels = [ 79442 ]; 79443 }; 79444 /** 79445 * Helper function for animating GIF-based images with time 79446 */ 79447 _main.default.Image.prototype._animateGif = function (pInst) { 79448 var props = this.gifProperties; 79449 var curTime = pInst._lastFrameTime; 79450 if (props.lastChangeTime === 0) { 79451 props.lastChangeTime = curTime; 79452 } 79453 if (props.playing) { 79454 props.timeDisplayed = curTime - props.lastChangeTime; 79455 var curDelay = props.frames[props.displayIndex].delay; 79456 if (props.timeDisplayed >= curDelay) { 79457 //GIF is bound to 'realtime' so can skip frames 79458 var skips = Math.floor(props.timeDisplayed / curDelay); 79459 props.timeDisplayed = 0; 79460 props.lastChangeTime = curTime; 79461 props.displayIndex += skips; 79462 props.loopCount = Math.floor(props.displayIndex / props.numFrames); 79463 if (props.loopLimit !== null && props.loopCount >= props.loopLimit) { 79464 props.playing = false; 79465 } else { 79466 var ind = props.displayIndex % props.numFrames; 79467 this.drawingContext.putImageData(props.frames[ind].image, 0, 0); 79468 props.displayIndex = ind; 79469 this.setModified(true); 79470 } 79471 } 79472 } 79473 }; 79474 /** 79475 * Helper fxn for sharing pixel methods 79476 */ 79477 _main.default.Image.prototype._setProperty = function (prop, value) { 79478 this[prop] = value; 79479 this.setModified(true); 79480 }; 79481 /** 79482 * Loads the pixels data for this image into the [pixels] attribute. 79483 * 79484 * @method loadPixels 79485 * @example 79486 * <div><code> 79487 * let myImage; 79488 * let halfImage; 79489 * 79490 * function preload() { 79491 * myImage = loadImage('assets/rockies.jpg'); 79492 * } 79493 * 79494 * function setup() { 79495 * myImage.loadPixels(); 79496 * halfImage = 4 * myImage.width * myImage.height / 2; 79497 * for (let i = 0; i < halfImage; i++) { 79498 * myImage.pixels[i + halfImage] = myImage.pixels[i]; 79499 * } 79500 * myImage.updatePixels(); 79501 * } 79502 * 79503 * function draw() { 79504 * image(myImage, 0, 0, width, height); 79505 * } 79506 * </code></div> 79507 * 79508 * @alt 79509 * 2 images of rocky mountains vertically stacked 79510 */ 79511 _main.default.Image.prototype.loadPixels = function () { 79512 _main.default.Renderer2D.prototype.loadPixels.call(this); 79513 this.setModified(true); 79514 }; 79515 /** 79516 * Updates the backing canvas for this image with the contents of 79517 * the [pixels] array. 79518 * 79519 * If this image is an animated GIF then the pixels will be updated 79520 * in the frame that is currently displayed. 79521 * 79522 * @method updatePixels 79523 * @param {Integer} x x-offset of the target update area for the 79524 * underlying canvas 79525 * @param {Integer} y y-offset of the target update area for the 79526 * underlying canvas 79527 * @param {Integer} w width of the target update area for the 79528 * underlying canvas 79529 * @param {Integer} h height of the target update area for the 79530 * underlying canvas 79531 * @example 79532 * <div><code> 79533 * let myImage; 79534 * let halfImage; 79535 * 79536 * function preload() { 79537 * myImage = loadImage('assets/rockies.jpg'); 79538 * } 79539 * 79540 * function setup() { 79541 * myImage.loadPixels(); 79542 * halfImage = 4 * myImage.width * myImage.height / 2; 79543 * for (let i = 0; i < halfImage; i++) { 79544 * myImage.pixels[i + halfImage] = myImage.pixels[i]; 79545 * } 79546 * myImage.updatePixels(); 79547 * } 79548 * 79549 * function draw() { 79550 * image(myImage, 0, 0, width, height); 79551 * } 79552 * </code></div> 79553 * 79554 * @alt 79555 * 2 images of rocky mountains vertically stacked 79556 */ 79557 /** 79558 * @method updatePixels 79559 */ 79560 _main.default.Image.prototype.updatePixels = function (x, y, w, h) { 79561 _main.default.Renderer2D.prototype.updatePixels.call(this, x, y, w, h); 79562 this.setModified(true); 79563 }; 79564 /** 79565 * Get a region of pixels from an image. 79566 * 79567 * If no params are passed, the whole image is returned. 79568 * If x and y are the only params passed a single pixel is extracted. 79569 * If all params are passed a rectangle region is extracted and a <a href="#/p5.Image">p5.Image</a> 79570 * is returned. 79571 * 79572 * @method get 79573 * @param {Number} x x-coordinate of the pixel 79574 * @param {Number} y y-coordinate of the pixel 79575 * @param {Number} w width 79576 * @param {Number} h height 79577 * @return {p5.Image} the rectangle <a href="#/p5.Image">p5.Image</a> 79578 * @example 79579 * <div><code> 79580 * let myImage; 79581 * let c; 79582 * 79583 * function preload() { 79584 * myImage = loadImage('assets/rockies.jpg'); 79585 * } 79586 * 79587 * function setup() { 79588 * background(myImage); 79589 * noStroke(); 79590 * c = myImage.get(60, 90); 79591 * fill(c); 79592 * rect(25, 25, 50, 50); 79593 * } 79594 * 79595 * //get() returns color here 79596 * </code></div> 79597 * 79598 * @alt 79599 * image of rocky mountains with 50Ã50 green rect in front 79600 */ 79601 /** 79602 * @method get 79603 * @return {p5.Image} the whole <a href="#/p5.Image">p5.Image</a> 79604 */ 79605 /** 79606 * @method get 79607 * @param {Number} x 79608 * @param {Number} y 79609 * @return {Number[]} color of pixel at x,y in array format [R, G, B, A] 79610 */ 79611 _main.default.Image.prototype.get = function (x, y, w, h) { 79612 _main.default._validateParameters('p5.Image.get', arguments); 79613 return _main.default.Renderer2D.prototype.get.apply(this, arguments); 79614 }; 79615 _main.default.Image.prototype._getPixel = _main.default.Renderer2D.prototype._getPixel; 79616 /** 79617 * Set the color of a single pixel or write an image into 79618 * this <a href="#/p5.Image">p5.Image</a>. 79619 *
79620 * Note that for a large number of pixels this will 79621 * be slower than directly manipulating the pixels array 79622 * and then calling <a href="#/p5.Image/updatePixels">updatePixels()</a>. 79623 * 79624 * @method set 79625 * @param {Number} x x-coordinate of the pixel 79626 * @param {Number} y y-coordinate of the pixel 79627 * @param {Number|Number[]|Object} a grayscale value | pixel array | 79628 * a <a href="#/p5.Color">p5.Color</a> | image to copy 79629 * @example 79630 * <div> 79631 * <code> 79632 * let img = createImage(66, 66); 79633 * img.loadPixels(); 79634 * for (let i = 0; i < img.width; i++) { 79635 * for (let j = 0; j < img.height; j++) { 79636 * img.set(i, j, color(0, 90, 102, (i % img.width) * 2)); 79637 * } 79638 * } 79639 * img.updatePixels(); 79640 * image(img, 17, 17); 79641 * image(img, 34, 34); 79642 * </code> 79643 * </div> 79644 * 79645 * @alt 79646 * 2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas 79647 */ 79648 _main.default.Image.prototype.set = function (x, y, imgOrCol) { 79649 _main.default.Renderer2D.prototype.set.call(this, x, y, imgOrCol); 79650 this.setModified(true); 79651 }; 79652 /** 79653 * Resize the image to a new width and height. To make the image scale 79654 * proportionally, use 0 as the value for the wide or high parameter. 79655 * For instance, to make the width of an image 150 pixels, and change 79656 * the height using the same proportion, use resize(150, 0). 79657 * 79658 * @method resize 79659 * @param {Number} width the resized image width 79660 * @param {Number} height the resized image height 79661 * @example 79662 * <div><code> 79663 * let img; 79664 * 79665 * function preload() { 79666 * img = loadImage('assets/rockies.jpg'); 79667 * } 79668 79669 * function draw() { 79670 * image(img, 0, 0); 79671 * } 79672 * 79673 * function mousePressed() { 79674 * img.resize(50, 100); 79675 * } 79676 * </code></div> 79677 * 79678 * @alt 79679 * image of rocky mountains. zoomed in 79680 */ 79681 _main.default.Image.prototype.resize = function (width, height) { 79682 // Copy contents to a temporary canvas, resize the original 79683 // and then copy back. 79684 // 79685 // There is a faster approach that involves just one copy and swapping the 79686 // this.canvas reference. We could switch to that approach if (as i think 79687 // is the case) there an expectation that the user would not hold a 79688 // reference to the backing canvas of a p5.Image. But since we do not 79689 // enforce that at the moment, I am leaving in the slower, but safer 79690 // implementation. 79691 // auto-resize 79692 if (width === 0 && height === 0) { 79693 width = this.canvas.width; 79694 height = this.canvas.height; 79695 } else if (width === 0) { 79696 width = this.canvas.width * height / this.canvas.height; 79697 } else if (height === 0) { 79698 height = this.canvas.height * width / this.canvas.width; 79699 } 79700 width = Math.floor(width); 79701 height = Math.floor(height); 79702 var tempCanvas = document.createElement('canvas'); 79703 tempCanvas.width = width; 79704 tempCanvas.height = height; 79705 if (this.gifProperties) { 79706 var props = this.gifProperties; //adapted from github.com/LinusU/resize-image-data 79707 var nearestNeighbor = function nearestNeighbor(src, dst) { 79708 var pos = 0; 79709 for (var y = 0; y < dst.height; y++) { 79710 for (var x = 0; x < dst.width; x++) { 79711 var srcX = Math.floor(x * src.width / dst.width); 79712 var srcY = Math.floor(y * src.height / dst.height); 79713 var srcPos = (srcY * src.width + srcX) * 4; 79714 dst.data[pos++] = src.data[srcPos++]; // R 79715 dst.data[pos++] = src.data[srcPos++]; // G 79716 dst.data[pos++] = src.data[srcPos++]; // B 79717 dst.data[pos++] = src.data[srcPos++]; // A 79718 } 79719 } 79720 }; 79721 for (var i = 0; i < props.numFrames; i++) { 79722 var resizedImageData = this.drawingContext.createImageData(width, height); 79723 nearestNeighbor(props.frames[i].image, resizedImageData); 79724 props.frames[i].image = resizedImageData; 79725 } 79726 } 79727 tempCanvas.getContext('2d').drawImage(this.canvas, 0, 0, this.canvas.width, this.canvas.height, 0, 0, tempCanvas.width, tempCanvas.height); // Resize the original canvas, which will clear its contents 79728 this.canvas.width = this.width = width; 79729 this.canvas.height = this.height = height; //Copy the image back 79730 this.drawingContext.drawImage(tempCanvas, 0, 0, width, height, 0, 0, width, height); 79731 if (this.pixels.length > 0) { 79732 this.loadPixels(); 79733 } 79734 this.setModified(true); 79735 }; 79736 /** 79737 * Copies a region of pixels from one image to another. If no 79738 * srcImage is specified this is used as the source. If the source 79739 * and destination regions aren't the same size, it will 79740 * automatically resize source pixels to fit the specified 79741 * target region. 79742 * 79743 * @method copy 79744 * @param {p5.Image|p5.Element} srcImage source image 79745 * @param {Integer} sx X coordinate of the source's upper left corner 79746 * @param {Integer} sy Y coordinate of the source's upper left corner 79747 * @param {Integer} sw source image width 79748 * @param {Integer} sh source image height 79749 * @param {Integer} dx X coordinate of the destination's upper left corner 79750 * @param {Integer} dy Y coordinate of the destination's upper left corner 79751 * @param {Integer} dw destination image width 79752 * @param {Integer} dh destination image height 79753 * @example 79754 * <div><code> 79755 * let photo; 79756 * let bricks; 79757 * let x; 79758 * let y; 79759 * 79760 * function preload() { 79761 * photo = loadImage('assets/rockies.jpg'); 79762 * bricks = loadImage('assets/bricks.jpg'); 79763 * } 79764 * 79765 * function setup() { 79766 * x = bricks.width / 2; 79767 * y = bricks.height / 2; 79768 * photo.copy(bricks, 0, 0, x, y, 0, 0, x, y); 79769 * image(photo, 0, 0); 79770 * } 79771 * </code></div> 79772 * 79773 * @alt 79774 * image of rocky mountains and smaller image on top of bricks at top left 79775 */ 79776 /** 79777 * @method copy 79778 * @param {Integer} sx 79779 * @param {Integer} sy 79780 * @param {Integer} sw 79781 * @param {Integer} sh 79782 * @param {Integer} dx 79783 * @param {Integer} dy 79784 * @param {Integer} dw 79785 * @param {Integer} dh 79786 */ 79787 _main.default.Image.prototype.copy = function () { 79788 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 79789 args[_key] = arguments[_key]; 79790 } 79791 _main.default.prototype.copy.apply(this, args); 79792 }; 79793 /** 79794 * Masks part of an image from displaying by loading another 79795 * image and using its alpha channel as an alpha channel for 79796 * this image. Masks are cumulative, once applied to an image 79797 * object, they cannot be removed. 79798 * 79799 * @method mask 79800 * @param {p5.Image} srcImage source image 79801 * @example 79802 * <div><code> 79803 * let photo, maskImage; 79804 * function preload() { 79805 * photo = loadImage('assets/rockies.jpg'); 79806 * maskImage = loadImage('assets/mask2.png'); 79807 * } 79808 * 79809 * function setup() { 79810 * createCanvas(100, 100); 79811 * photo.mask(maskImage); 79812 * image(photo, 0, 0); 79813 * } 79814 * </code></div> 79815 * 79816 * @alt 79817 * image of rocky mountains with white at right 79818 * 79819 * http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/ 79820 */ 79821 // TODO: - Accept an array of alpha values. 79822 _main.default.Image.prototype.mask = function (p5Image) { 79823 if (p5Image === undefined) { 79824 p5Image = this; 79825 } 79826 var currBlend = this.drawingContext.globalCompositeOperation; 79827 var scaleFactor = 1; 79828 if (p5Image instanceof _main.default.Renderer) { 79829 scaleFactor = p5Image._pInst._pixelDensity; 79830 } 79831 var copyArgs = [ 79832 p5Image, 79833 0, 79834 0, 79835 scaleFactor * p5Image.width, 79836 scaleFactor * p5Image.height, 79837 0, 79838 0, 79839 this.width, 79840 this.height 79841 ]; 79842 this.drawingContext.globalCompositeOperation = 'destination-in'; 79843 if (this.gifProperties) { 79844 for (var i = 0; i < this.gifProperties.frames.length; i++) { 79845 this.drawingContext.putImageData(this.gifProperties.frames[i].image, 0, 0
79845); 79846 _main.default.Image.prototype.copy.apply(this, copyArgs); 79847 this.gifProperties.frames[i].image = this.drawingContext.getImageData(0, 0, this.width, this.height); 79848 } 79849 this.drawingContext.putImageData(this.gifProperties.frames[this.gifProperties.displayIndex].image, 0, 0); 79850 } else { 79851 _main.default.Image.prototype.copy.apply(this, copyArgs); 79852 } 79853 this.drawingContext.globalCompositeOperation = currBlend; 79854 this.setModified(true); 79855 }; 79856 /** 79857 * Applies an image filter to a <a href="#/p5.Image">p5.Image</a> 79858 * 79859 * THRESHOLD 79860 * Converts the image to black and white pixels depending if they are above or 79861 * below the threshold defined by the level parameter. The parameter must be 79862 * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used. 79863 * 79864 * GRAY 79865 * Converts any colors in the image to grayscale equivalents. No parameter 79866 * is used. 79867 * 79868 * OPAQUE 79869 * Sets the alpha channel to entirely opaque. No parameter is used. 79870 * 79871 * INVERT 79872 * Sets each pixel to its inverse value. No parameter is used. 79873 * 79874 * POSTERIZE 79875 * Limits each channel of the image to the number of colors specified as the 79876 * parameter. The parameter can be set to values between 2 and 255, but 79877 * results are most noticeable in the lower ranges. 79878 * 79879 * BLUR 79880 * Executes a Gaussian blur with the level parameter specifying the extent 79881 * of the blurring. If no parameter is used, the blur is equivalent to 79882 * Gaussian blur of radius 1. Larger values increase the blur. 79883 * 79884 * ERODE 79885 * Reduces the light areas. No parameter is used. 79886 * 79887 * DILATE 79888 * Increases the light areas. No parameter is used. 79889 * 79890 * filter() does not work in WEBGL mode. 79891 * A similar effect can be achieved in WEBGL mode using custom 79892 * shaders. Adam Ferriss has written 79893 * a <a href="https://github.com/aferriss/p5jsShaderExamples" 79894 * target='_blank'>selection of shader examples</a> that contains many 79895 * of the effects present in the filter examples. 79896 * 79897 * @method filter 79898 * @param {Constant} filterType either THRESHOLD, GRAY, OPAQUE, INVERT, 79899 * POSTERIZE, ERODE, DILATE or BLUR. 79900 * See Filters.js for docs on 79901 * each available filter 79902 * @param {Number} [filterParam] an optional parameter unique 79903 * to each filter, see above 79904 * @example 79905 * <div><code> 79906 * let photo1; 79907 * let photo2; 79908 * 79909 * function preload() { 79910 * photo1 = loadImage('assets/rockies.jpg'); 79911 * photo2 = loadImage('assets/rockies.jpg'); 79912 * } 79913 * 79914 * function setup() { 79915 * photo2.filter(GRAY); 79916 * image(photo1, 0, 0); 79917 * image(photo2, width / 2, 0); 79918 * } 79919 * </code></div> 79920 * 79921 * @alt 79922 * 2 images of rocky mountains left one in color, right in black and white 79923 */ 79924 _main.default.Image.prototype.filter = function (operation, value) { 79925 _filters.default.apply(this.canvas, _filters.default[operation], value); 79926 this.setModified(true); 79927 }; 79928 /** 79929 * Copies a region of pixels from one image to another, using a specified 79930 * blend mode to do the operation. 79931 * 79932 * @method blend 79933 * @param {p5.Image} srcImage source image 79934 * @param {Integer} sx X coordinate of the source's upper left corner 79935 * @param {Integer} sy Y coordinate of the source's upper left corner 79936 * @param {Integer} sw source image width 79937 * @param {Integer} sh source image height 79938 * @param {Integer} dx X coordinate of the destination's upper left corner 79939 * @param {Integer} dy Y coordinate of the destination's upper left corner 79940 * @param {Integer} dw destination image width 79941 * @param {Integer} dh destination image height 79942 * @param {Constant} blendMode the blend mode. either 79943 * BLEND, DARKEST, LIGHTEST, DIFFERENCE, 79944 * MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, 79945 * SOFT_LIGHT, DODGE, BURN, ADD or NORMAL. 79946 * 79947 * Available blend modes are: normal | multiply | screen | overlay | 79948 * darken | lighten | color-dodge | color-burn | hard-light | 79949 * soft-light | difference | exclusion | hue | saturation | 79950 * color | luminosity 79951 * 79952 * http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/ 79953 * @example 79954 * <div><code> 79955 * let mountains; 79956 * let bricks; 79957 * 79958 * function preload() {
79959 * mountains = loadImage('assets/rockies.jpg'); 79960 * bricks = loadImage('assets/bricks_third.jpg'); 79961 * } 79962 * 79963 * function setup() { 79964 * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD); 79965 * image(mountains, 0, 0); 79966 * image(bricks, 0, 0); 79967 * } 79968 * </code></div> 79969 * <div><code> 79970 * let mountains; 79971 * let bricks; 79972 * 79973 * function preload() { 79974 * mountains = loadImage('assets/rockies.jpg'); 79975 * bricks = loadImage('assets/bricks_third.jpg'); 79976 * } 79977 * 79978 * function setup() { 79979 * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST); 79980 * image(mountains, 0, 0); 79981 * image(bricks, 0, 0); 79982 * } 79983 * </code></div> 79984 * <div><code> 79985 * let mountains; 79986 * let bricks; 79987 * 79988 * function preload() { 79989 * mountains = loadImage('assets/rockies.jpg'); 79990 * bricks = loadImage('assets/bricks_third.jpg'); 79991 * } 79992 * 79993 * function setup() { 79994 * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST); 79995 * image(mountains, 0, 0); 79996 * image(bricks, 0, 0); 79997 * } 79998 * </code></div> 79999 * 80000 * @alt 80001 * image of rocky mountains. Brick images on left and right. Right overexposed 80002 * image of rockies. Brickwall images on left and right. Right mortar transparent 80003 * image of rockies. Brickwall images on left and right. Right translucent 80004 */ 80005 /** 80006 * @method blend 80007 * @param {Integer} sx 80008 * @param {Integer} sy 80009 * @param {Integer} sw 80010 * @param {Integer} sh 80011 * @param {Integer} dx 80012 * @param {Integer} dy 80013 * @param {Integer} dw 80014 * @param {Integer} dh 80015 * @param {Constant} blendMode 80016 */ 80017 _main.default.Image.prototype.blend = function () { 80018 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 80019 args[_key2] = arguments[_key2]; 80020 } 80021 _main.default._validateParameters('p5.Image.blend', arguments); 80022 _main.default.prototype.blend.apply(this, args); 80023 this.setModified(true); 80024 }; 80025 /** 80026 * helper method for web GL mode to indicate that an image has been 80027 * changed or unchanged since last upload. gl texture upload will 80028 * set this value to false after uploading the texture. 80029 * @method setModified 80030 * @param {boolean} val sets whether or not the image has been 80031 * modified. 80032 * @private 80033 */ 80034 _main.default.Image.prototype.setModified = function (val) { 80035 this._modified = val; //enforce boolean? 80036 }; 80037 /** 80038 * helper method for web GL mode to figure out if the image 80039 * has been modified and might need to be re-uploaded to texture 80040 * memory between frames. 80041 * @method isModified 80042 * @private 80043 * @return {boolean} a boolean indicating whether or not the 80044 * image has been updated or modified since last texture upload. 80045 */ 80046 _main.default.Image.prototype.isModified = function () { 80047 return this._modified; 80048 }; 80049 /** 80050 * Saves the image to a file and force the browser to download it. 80051 * Accepts two strings for filename and file extension 80052 * Supports png (default), jpg, and gif 80053 *<br><br> 80054 * Note that the file will only be downloaded as an animated GIF 80055 * if the p5.Image was loaded from a GIF file. 80056 * @method save 80057 * @param {String} filename give your file a name 80058 * @param {String} extension 'png' or 'jpg' 80059 * @example 80060 * <div><code> 80061 * let photo; 80062 * 80063 * function preload() { 80064 * photo = loadImage('assets/rockies.jpg'); 80065 * } 80066 * 80067 * function draw() { 80068 * image(photo, 0, 0); 80069 * } 80070 * 80071 * function keyTyped() { 80072 * if (key === 's') { 80073 * photo.save('photo', 'png'); 80074 * } 80075 * } 80076 * </code></div> 80077 * 80078 * @alt 80079 * image of rocky mountains. 80080 */ 80081 _main.default.Image.prototype.save = function (filename, extension) { 80082 if (this.gifProperties) { 80083 _main.default.prototype.encodeAndDownloadGif(this, filename); 80084 } else { 80085 _main.default.prototype.saveCanvas(this.canvas, filename, extension); 80086 } 80087 }; // GIF Section 80088 /** 80089 * Starts an animated GIF over at the beginning state. 80090 * 80091 * @method reset 80092 * @example 80093 * <div><code> 80094 * let gif; 80095 * 80096 * function preload() { 80097 * gif = loadImage('assets/arnott-wallace-wink-loop-once.gif'); 80098 * } 80099 * 80100 * function draw() { 80101 * background(255); 80102 * // The GIF file that we loaded only loops once 80103 * // so it freezes on the last frame after playing through 80104 * image(gif, 0, 0); 80105 * } 80106 * 80107 * function mousePressed() { 80108 * // Click to reset the GIF and begin playback from start 80109 * gif.reset(); 80110 * } 80111 * </code></div> 80112 * @alt 80113 * Animated image of a cartoon face that winks once and then freezes 80114 * When you click it animates again, winks once and freezes 80115 */ 80116 _main.default.Image.prototype.reset = function () { 80117 if (this.gifProperties) { 80118 var props = this.gifProperties; 80119 props.playing = true; 80120 props.timeSinceStart = 0; 80121 props.timeDisplayed = 0; 80122 props.lastChangeTime = 0; 80123 props.loopCount = 0; 80124 props.displayIndex = 0; 80125 this.drawingContext.putImageData(props.frames[0].image, 0, 0
80125); 80126 } 80127 }; 80128 /** 80129 * Gets the index for the frame that is currently visible in an animated GIF. 80130 * 80131 * @method getCurrentFrame 80132 * @return {Number} The index for the currently displaying frame in animated GIF 80133 * @example 80134 * <div><code> 80135 * let gif; 80136 * 80137 * function preload() { 80138 * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); 80139 * } 80140 * 80141 * function draw() { 80142 * let frame = gif.getCurrentFrame(); 80143 * image(gif, 0, 0); 80144 * text(frame, 10, 90); 80145 * } 80146 * </code></div> 80147 * @alt 80148 * Animated image of a cartoon eye looking around and then 80149 * looking outwards, in the lower-left hand corner a number counts 80150 * up quickly to 124 and then starts back over at 0 80151 */ 80152 _main.default.Image.prototype.getCurrentFrame = function () { 80153 if (this.gifProperties) { 80154 var props = this.gifProperties; 80155 return props.displayIndex % props.numFrames; 80156 } 80157 }; 80158 /** 80159 * Sets the index of the frame that is currently visible in an animated GIF 80160 * 80161 * @method setFrame 80162 * @param {Number} index the index for the frame that should be displayed 80163 * @example 80164 * <div><code> 80165 * let gif; 80166 * 80167 * function preload() { 80168 * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); 80169 * } 80170 * 80171 * // Move your mouse up and down over canvas to see the GIF 80172 * // frames animate 80173 * function draw() { 80174 * gif.pause(); 80175 * image(gif, 0, 0); 80176 * // Get the highest frame number which is the number of frames - 1 80177 * let maxFrame = gif.numFrames() - 1; 80178 * // Set the current frame that is mapped to be relative to mouse position 80179 * let frameNumber = floor(map(mouseY, 0, height, 0, maxFrame, true)); 80180 * gif.setFrame(frameNumber); 80181 * } 80182 * </code></div> 80183 * @alt 80184 * A still image of a cartoon eye that looks around when you move your mouse 80185 * up and down over the canvas 80186 */ 80187 _main.default.Image.prototype.setFrame = function (index) { 80188 if (this.gifProperties) { 80189 var props = this.gifProperties; 80190 if (index < props.numFrames && index >= 0) { 80191 props.timeDisplayed = 0; 80192 props.lastChangeTime = 0; 80193 props.displayIndex = index; 80194 this.drawingContext.putImageData(props.frames[index].image, 0, 0); 80195 } else { 80196 console.log('Cannot set GIF to a frame number that is higher than total number of frames or below zero.'); 80197 } 80198 } 80199 }; 80200 /** 80201 * Returns the number of frames in an animated GIF 80202 * 80203 * @method numFrames 80204 * @return {Number} 80205 * @example The number of frames in the animated GIF 80206 * <div><code> 80207 * let gif; 80208 * 80209 * function preload() { 80210 * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); 80211 * } 80212 * 80213 * // Move your mouse up and down over canvas to see the GIF 80214 * // frames animate 80215 * function draw() { 80216 * gif.pause(); 80217 * image(gif, 0, 0); 80218 * // Get the highest frame number which is the number of frames - 1 80219 * let maxFrame = gif.numFrames() - 1; 80220 * // Set the current frame that is mapped to be relative to mouse position 80221 * let frameNumber = floor(map(mouseY, 0, height, 0, maxFrame, true)); 80222 * gif.setFrame(frameNumber); 80223 * } 80224 * </code></div> 80225 * @alt 80226 * A still image of a cartoon eye that looks around when you move your mouse 80227 * up and down over the canvas 80228 */ 80229 _main.default.Image.prototype.numFrames = function () { 80230 if (this.gifProperties) { 80231 return this.gifProperties.numFrames; 80232 } 80233 }; 80234 /** 80235 * Plays an animated GIF that was paused with 80236 * <a href="#/p5.Image/pause">pause()</a> 80237 * 80238 * @method play 80239 * @example 80240 * <div><code> 80241 * let gif; 80242 * 80243 * function preload() { 80244 * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif'); 80245 * } 80246 * 80247 * function draw() { 80248 * background(255); 80249 * image(gif, 0, 0); 80250 * } 80251 * 80252 * function mousePressed() { 80253 * gif.pause(); 80254 * } 80255 * 80256 * function mouseReleased() { 80257 * gif.play(); 80258 * } 80259 * </code></div> 80260 * @alt 80261 * An animated GIF of a drawing of small child with 80262 * hair blowing in the wind, when you click the image 80263 * freezes when you release it animates again 80264 */ 80265 _main.default.Image.prototype.play = function () { 80266 if (this.gifProperties) { 80267 this.gifProperties.playing = true; 80268 } 80269 }; 80270 /** 80271 * Pauses an animated GIF. 80272 * 80273 * @method pause 80274 * @example 80275 * <div><code> 80276 * let gif; 80277 * 80278 * function preload() {
80279 * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif'); 80280 * } 80281 * 80282 * function draw() { 80283 * background(255); 80284 * image(gif, 0, 0); 80285 * } 80286 * 80287 * function mousePressed() { 80288 * gif.pause(); 80289 * } 80290 * 80291 * function mouseReleased() { 80292 * gif.play(); 80293 * } 80294 * </code></div> 80295 * @alt 80296 * An animated GIF of a drawing of small child with 80297 * hair blowing in the wind, when you click the image 80298 * freezes when you release it animates again 80299 */ 80300 _main.default.Image.prototype.pause = function () { 80301 if (this.gifProperties) { 80302 this.gifProperties.playing = false; 80303 } 80304 }; 80305 /** 80306 * Changes the delay between frames in an animated GIF. There is an optional second parameter that 80307 * indicates an index for a specific frame that should have its delay modified. If no index is given, all frames 80308 * will have the new delay. 80309 * 80310 * @method delay 80311 * @param {Number} d the amount in milliseconds to delay between switching frames 80312 * @param {Number} [index] the index of the frame that should have the new delay value {optional} 80313 * @example 80314 * <div><code> 80315 * let gifFast, gifSlow; 80316 * 80317 * function preload() { 80318 * gifFast = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); 80319 * gifSlow = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); 80320 * } 80321 * 80322 * function setup() { 80323 * gifFast.resize(width / 2, height / 2); 80324 * gifSlow.resize(width / 2, height / 2); 80325 * 80326 * //Change the delay here 80327 * gifFast.delay(10); 80328 * gifSlow.delay(100); 80329 * } 80330 * 80331 * function draw() { 80332 * background(255); 80333 * image(gifFast, 0, 0); 80334 * image(gifSlow, width / 2, 0); 80335 * } 80336 * </code></div> 80337 * @alt 80338 * Two animated gifs of cartoon eyes looking around 80339 * The gif on the left animates quickly, on the right 80340 * the animation is much slower 80341 */ 80342 _main.default.Image.prototype.delay = function (d, index) { 80343 if (this.gifProperties) { 80344 var props = this.gifProperties; 80345 if (index < props.numFrames && index >= 0) { 80346 props.frames[index].delay = d; 80347 } else { 80348 // change all frames 80349 var _iteratorNormalCompletion = true; 80350 var _didIteratorError = false; 80351 var _iteratorError = undefined; 80352 try { 80353 for (var _iterator = props.frames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 80354 var frame = _step.value; 80355 frame.delay = d; 80356 } 80357 } catch (err) { 80358 _didIteratorError = true; 80359 _iteratorError = err; 80360 } finally { 80361 try { 80362 if (!_iteratorNormalCompletion && _iterator.return != null) { 80363 _iterator.return(); 80364 } 80365 } finally { 80366 if (_didIteratorError) { 80367 throw _iteratorError; 80368 } 80369 } 80370 } 80371 } 80372 } 80373 }; 80374 var _default = _main.default.Image; 80375 exports.default = _default; 80376 }, 80377 { 80378 '../core/main': 290, 80379 './filters': 311, 80380 'core-js/modules/es.array.filter': 171, 80381 'core-js/modules/es.array.iterator': 176, 80382 'core-js/modules/es.object.to-string': 195, 80383 'core-js/modules/es.string.iterator': 204, 80384 'core-js/modules/es.symbol': 214, 80385 'core-js/modules/es.symbol.description': 212, 80386 'core-js/modules/es.symbol.iterator': 213, 80387 'core-js/modules/web.dom-collections.iterator': 248 80388 } 80389 ], 80390 315: [ 80391 function (_dereq_, module, exports) { 80392 'use strict'; 80393 _dereq_('core-js/modules/es.array.filter'); 80394 _dereq_('core-js/modules/es.array.filter'); 80395 Object.defineProperty(exports, '__esModule', { 80396 value: true 80397 }); 80398 exports.default = void 0; 80399 var _main = _interopRequireDefault(_dereq_('../core/main')); 80400 var _filters = _interopRequireDefault(_dereq_('./filters')); 80401 _dereq_('../color/p5.Color'); 80402 function _interopRequireDefault(obj) { 80403 return obj && obj.__esModule ? obj : { 80404 default: 80405 obj 80406 }; 80407 } /** 80408 * @module Image
80409 * @submodule Pixels 80410 * @for p5 80411 * @requires core 80412 */ 80413 /** 80414 * <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference 80415 * /Global_Objects/Uint8ClampedArray' target='_blank'>Uint8ClampedArray</a> 80416 * containing the values for all the pixels in the display window. 80417 * These values are numbers. This array is the size (include an appropriate 80418 * factor for <a href="#/p5/pixelDensity">pixelDensity</a>) of the display window x4, 80419 * representing the R, G, B, A values in order for each pixel, moving from 80420 * left to right across each row, then down each column. Retina and other 80421 * high density displays will have more pixels[] (by a factor of 80422 * pixelDensity^2). 80423 * For example, if the image is 100Ã100 pixels, there will be 40,000. On a 80424 * retina display, there will be 160,000. 80425 * 80426 * The first four values (indices 0-3) in the array will be the R, G, B, A 80427 * values of the pixel at (0, 0). The second four values (indices 4-7) will 80428 * contain the R, G, B, A values of the pixel at (1, 0). More generally, to 80429 * set values for a pixel at (x, y): 80430 * ```javascript 80431 * let d = pixelDensity(); 80432 * for (let i = 0; i < d; i++) { 80433 * for (let j = 0; j < d; j++) { 80434 * // loop over
80435 * index = 4 * ((y * d + j) * width * d + (x * d + i)); 80436 * pixels[index] = r; 80437 * pixels[index+1] = g; 80438 * pixels[index+2] = b; 80439 * pixels[index+3] = a; 80440 * } 80441 * } 80442 * ``` 80443 * While the above method is complex, it is flexible enough to work with 80444 * any pixelDensity. Note that <a href="#/p5/set">set()</a> will automatically take care of 80445 * setting all the appropriate values in <a href="#/p5/pixels">pixels[]</a> for a given (x, y) at 80446 * any pixelDensity, but the performance may not be as fast when lots of 80447 * modifications are made to the pixel array. 80448 * 80449 * Before accessing this array, the data must loaded with the <a href="#/p5/loadPixels">loadPixels()</a> 80450 * function. After the array data has been modified, the <a href="#/p5/updatePixels">updatePixels()</a> 80451 * function must be run to update the changes. 80452 * 80453 * Note that this is not a standard javascript array. This means that 80454 * standard javascript functions such as <a href="#/p5/slice">slice()</a> or 80455 * <a href="#/p5/arrayCopy">arrayCopy()</a> do not 80456 * work. 80457 * 80458 * @property {Number[]} pixels 80459 * @example 80460 * <div> 80461 * <code> 80462 * let pink = color(255, 102, 204); 80463 * loadPixels(); 80464 * let d = pixelDensity(); 80465 * let halfImage = 4 * (width * d) * (height / 2 * d); 80466 * for (let i = 0; i < halfImage; i += 4) { 80467 * pixels[i] = red(pink); 80468 * pixels[i + 1] = green(pink); 80469 * pixels[i + 2] = blue(pink); 80470 * pixels[i + 3] = alpha(pink); 80471 * } 80472 * updatePixels(); 80473 * </code> 80474 * </div> 80475 * 80476 * @alt 80477 * top half of canvas pink, bottom grey 80478 */ 80479 80480 _main.default.prototype.pixels = [ 80481 ]; 80482 /** 80483 * Copies a region of pixels from one image to another, using a specified 80484 * blend mode to do the operation. 80485 * 80486 * @method blend 80487 * @param {p5.Image} srcImage source image 80488 * @param {Integer} sx X coordinate of the source's upper left corner 80489 * @param {Integer} sy Y coordinate of the source's upper left corner 80490 * @param {Integer} sw source image width 80491 * @param {Integer} sh source image height 80492 * @param {Integer} dx X coordinate of the destination's upper left corner 80493 * @param {Integer} dy Y coordinate of the destination's upper left corner 80494 * @param {Integer} dw destination image width 80495 * @param {Integer} dh destination image height 80496 * @param {Constant} blendMode the blend mode. either 80497 * BLEND, DARKEST, LIGHTEST, DIFFERENCE, 80498 * MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, 80499 * SOFT_LIGHT, DODGE, BURN, ADD or NORMAL. 80500 * 80501 * @example 80502 * <div><code> 80503 * let img0; 80504 * let img1; 80505 * 80506 * function preload() { 80507 * img0 = loadImage('assets/rockies.jpg'); 80508 * img1 = loadImage('assets/bricks_third.jpg'); 80509 * } 80510 * 80511 * function setup() { 80512 * background(img0); 80513 * image(img1, 0, 0); 80514 * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST); 80515 * } 80516 * </code></div> 80517 * <div><code> 80518 * let img0; 80519 * let img1; 80520 * 80521 * function preload() { 80522 * img0 = loadImage('assets/rockies.jpg'); 80523 * img1 = loadImage('assets/bricks_third.jpg'); 80524 * } 80525 * 80526 * function setup() { 80527 * background(img0); 80528 * image(img1, 0, 0); 80529 * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST); 80530 * } 80531 * </code></div> 80532 * <div><code> 80533 * let img0; 80534 * let img1; 80535 * 80536 * function preload() { 80537 * img0 = loadImage('assets/rockies.jpg'); 80538 * img1 = loadImage('assets/bricks_third.jpg'); 80539 * } 80540 * 80541 * function setup() { 80542 * background(img0); 80543 * image(img1, 0, 0); 80544 * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD); 80545 * } 80546 * </code></div> 80547 * 80548 * @alt 80549 * image of rocky mountains. Brick images on left and right. Right overexposed 80550 * image of rockies. Brickwall images on left and right. Right mortar transparent 80551 * image of rockies. Brickwall images on left and right. Right translucent 80552 * 80553 */ 80554 /** 80555 * @method blend 80556 * @param {Integer} sx 80557 * @param {Integer} sy 80558 * @param {Integer} sw 80559 * @param {Integer} sh 80560 * @param {Integer} dx 80561 * @param {Integer} dy 80562 * @param {Integer} dw 80563 * @param {Integer} dh 80564 * @param {Constant} blendMode 80565 */ 80566 _main.default.prototype.blend = function () { 80567 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 80568 args[_key] = arguments[_key]; 80569 } 80570 _main.default._validateParameters('blend', args); 80571 if (this._renderer) { 80572 var _this$_renderer; 80573 (_this$_renderer = this._renderer).blend.apply(_this$_renderer, args); 80574 } else { 80575 _main.default.Renderer2D.prototype.blend.apply(this, args); 80576 } 80577 }; 80578 /** 80579 * Copies a region of the canvas to another region of the canvas 80580 * and copies a region of pixels from an image used as the srcImg parameter 80581 * into the canvas srcImage is specified this is used as the source. If 80582 * the source and destination regions aren't the same size, it will 80583 * automatically resize source pixels to fit the specified 80584 * target region. 80585 * 80586 * @method copy 80587 * @param {p5.Image|p5.Element} srcImage source image 80588 * @param {Integer} sx X coordinate of the source's upper left corner 80589 * @param {Integer} sy Y coordinate of the source's upper left corner 80590 * @param {Integer} sw source image width 80591 * @param {Integer} sh source image height 80592 * @param {Integer} dx X coordinate of the destination's upper left corner 80593 * @param {Integer} dy Y coordinate of the destination's upper left corner 80594 * @param {Integer} dw destination image width 80595 * @param {Integer} dh destination image height 80596 * 80597 * @example 80598 * <div><code> 80599 * let img; 80600 * 80601 * function preload() { 80602 * img = loadImage('assets/rockies.jpg'); 80603 * } 80604 * 80605 * function setup() { 80606 * background(img); 80607 * copy(img, 7, 22, 10, 10, 35, 25, 50, 50);
80608 * stroke(255); 80609 * noFill(); 80610 * // Rectangle shows area being copied 80611 * rect(7, 22, 10, 10); 80612 * } 80613 * </code></div> 80614 * 80615 * @alt 80616 * image of rocky mountains. Brick images on left and right. Right overexposed 80617 * image of rockies. Brickwall images on left and right. Right mortar transparent 80618 * image of rockies. Brickwall images on left and right. Right translucent 80619 */ 80620 /** 80621 * @method copy 80622 * @param {Integer} sx 80623 * @param {Integer} sy 80624 * @param {Integer} sw 80625 * @param {Integer} sh 80626 * @param {Integer} dx 80627 * @param {Integer} dy 80628 * @param {Integer} dw 80629 * @param {Integer} dh 80630 */ 80631 _main.default.prototype.copy = function () { 80632 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 80633 args[_key2] = arguments[_key2]; 80634 } 80635 _main.default._validateParameters('copy', args); 80636 var srcImage, 80637 sx, 80638 sy, 80639 sw, 80640 sh, 80641 dx, 80642 dy, 80643 dw, 80644 dh; 80645 if (args.length === 9) { 80646 srcImage = args[0]; 80647 sx = args[1]; 80648 sy = args[2]; 80649 sw = args[3]; 80650 sh = args[4]; 80651 dx = args[5]; 80652 dy = args[6]; 80653 dw = args[7]; 80654 dh = args[8]; 80655 } else if (args.length === 8) { 80656 srcImage = this; 80657 sx = args[0]; 80658 sy = args[1]; 80659 sw = args[2]; 80660 sh = args[3]; 80661 dx = args[4]; 80662 dy = args[5]; 80663 dw = args[6]; 80664 dh = args[7]; 80665 } else { 80666 throw new Error('Signature not supported'); 80667 } 80668 _main.default.prototype._copyHelper(this, srcImage, sx, sy, sw, sh, dx, dy, dw, dh); 80669 }; 80670 _main.default.prototype._copyHelper = function (dstImage, srcImage, sx, sy, sw, sh, dx, dy, dw, dh) { 80671 srcImage.loadPixels(); 80672 var s = srcImage.canvas.width / srcImage.width; // adjust coord system for 3D when renderer 80673 // ie top-left = -width/2, -height/2 80674 var sxMod = 0; 80675 var syMod = 0; 80676 if (srcImage._renderer && srcImage._renderer.isP3D) { 80677 sxMod = srcImage.width / 2; 80678 syMod = srcImage.height / 2; 80679 } 80680 if (dstImage._renderer && dstImage._renderer.isP3D) { 80681 _main.default.RendererGL.prototype.image.call(dstImage._renderer, srcImage, sx + sxMod, sy + syMod, sw, sh, dx, dy, dw, dh); 80682 } else { 80683 dstImage.drawingContext.drawImage(srcImage.canvas, s * (sx + sxMod), s * (sy + syMod), s * sw, s * sh, dx, dy, dw, dh); 80684 } 80685 }; 80686 /** 80687 * Applies a filter to the canvas. The presets options are: 80688 * 80689 * THRESHOLD 80690 * Converts the image to black and white pixels depending if they are above or 80691 * below the threshold defined by the level parameter. The parameter must be 80692 * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used. 80693 * 80694 * GRAY 80695 * Converts any colors in the image to grayscale equivalents. No parameter 80696 * is used. 80697 * 80698 * OPAQUE 80699 * Sets the alpha channel to entirely opaque. No parameter is used. 80700 * 80701 * INVERT 80702 * Sets each pixel to its inverse value. No parameter is used. 80703 * 80704 * POSTERIZE 80705 * Limits each channel of the image to the number of colors specified as the 80706 * parameter. The parameter can be set to values between 2 and 255, but 80707 * results are most noticeable in the lower ranges. 80708 * 80709 * BLUR 80710 * Executes a Gaussian blur with the level parameter specifying the extent 80711 * of the blurring. If no parameter is used, the blur is equivalent to 80712 * Gaussian blur of radius 1. Larger values increase the blur. 80713 * 80714 * ERODE 80715 * Reduces the light areas. No parameter is used. 80716 * 80717 * DILATE 80718 * Increases the light areas. No parameter is used. 80719 * 80720 * filter() does not work in WEBGL mode. 80721 * A similar effect can be achieved in WEBGL mode using custom 80722 * shaders. Adam Ferriss has written 80723 * a <a href="https://github.com/aferriss/p5jsShaderExamples" 80724 * target='_blank'>selection of shader examples</a> that contains many 80725 * of the effects present in the filter examples. 80726 * 80727 * @method filter 80728 * @param {Constant} filterType either THRESHOLD, GRAY, OPAQUE, INVERT, 80729 * POSTERIZE, BLUR, ERODE, DILATE or BLUR. 80730 * See Filters.js for docs on 80731 * each available filter 80732 * @param {Number} [filterParam] an optional parameter unique 80733 * to each filter, see above 80734 * 80735 * @example 80736 * <div> 80737 * <code> 80738 * let img; 80739 * function preload() { 80740 * img = loadImage('assets/bricks.jpg'); 80741 * } 80742 * function setup() { 80743 * image(img, 0, 0); 80744 * filter(THRESHOLD); 80745 * } 80746 * </code> 80747 * </div> 80748 * 80749 * <div> 80750 * <code> 80751 * let img; 80752 * function preload() { 80753 * img = loadImage('assets/bricks.jpg'); 80754 * } 80755 * function setup() { 80756 * image(img, 0, 0); 80757 * filter(GRAY); 80758 * } 80759 * </code> 80760 * </div> 80761 * 80762 * <div> 80763 * <code> 80764 * let img; 80765 * function preload() { 80766 * img = loadImage('assets/bricks.jpg'); 80767 * } 80768 * function setup() { 80769 * image(img, 0, 0); 80770 * filter(OPAQUE); 80771 * } 80772 * </code> 80773 * </div> 80774 * 80775 * <div> 80776 * <code> 80777 * let img; 80778 * function preload() { 80779 * img = loadImage('assets/bricks.jpg'); 80780 * } 80781 * function setup() { 80782 * image(img, 0, 0); 80783 * filter(INVERT); 80784 * } 80785 * </code> 80786 * </div> 80787 * 80788 * <div> 80789 * <code> 80790 * let img; 80791 * function preload() { 80792 * img = loadImage('assets/bricks.jpg'); 80793 * } 80794 * function setup() { 80795 * image(img, 0, 0); 80796 * filter(POSTERIZE, 3); 80797 * } 80798 * </code> 80799 * </div> 80800 * 80801 * <div> 80802 * <code> 80803 * let img; 80804 * function preload() { 80805 * img = loadImage('assets/bricks.jpg'); 80806 * } 80807 * function setup() { 80808 * image(img, 0, 0); 80809 * filter(DILATE); 80810 * } 80811 * </code> 80812 * </div> 80813 * 80814 * <div> 80815 * <code> 80816 * let img; 80817 * function preload() { 80818 * img = loadImage('assets/bricks.jpg'); 80819 * } 80820 * function setup() { 80821 * image(img, 0, 0);
80822 * filter(BLUR, 3); 80823 * } 80824 * </code> 80825 * </div> 80826 * 80827 * <div> 80828 * <code> 80829 * let img; 80830 * function preload() { 80831 * img = loadImage('assets/bricks.jpg'); 80832 * } 80833 * function setup() { 80834 * image(img, 0, 0); 80835 * filter(ERODE); 80836 * } 80837 * </code> 80838 * </div> 80839 * 80840 * @alt 80841 * black and white image of a brick wall. 80842 * greyscale image of a brickwall 80843 * image of a brickwall 80844 * jade colored image of a brickwall 80845 * red and pink image of a brickwall 80846 * image of a brickwall 80847 * blurry image of a brickwall 80848 * image of a brickwall 80849 * image of a brickwall with less detail 80850 */ 80851 _main.default.prototype.filter = function (operation, value) { 80852 _main.default._validateParameters('filter', arguments); 80853 if (this.canvas !== undefined) { 80854 _filters.default.apply(this.canvas, _filters.default[operation], value); 80855 } else { 80856 _filters.default.apply(this.elt, _filters.default[operation], value); 80857 } 80858 }; 80859 /** 80860 * Get a region of pixels, or a single pixel, from the canvas. 80861 * 80862 * Returns an array of [R,G,B,A] values for any pixel or grabs a section of 80863 * an image. If no parameters are specified, the entire image is returned. 80864 * Use the x and y parameters to get the value of one pixel. Get a section of 80865 * the display window by specifying additional w and h parameters. When 80866 * getting an image, the x and y parameters define the coordinates for the 80867 * upper-left corner of the image, regardless of the current <a href="#/p5/imageMode">imageMode()</a>. 80868 * 80869 * Getting the color of a single pixel with get(x, y) is easy, but not as fast 80870 * as grabbing the data directly from <a href="#/p5/pixels">pixels[]</a>. The equivalent statement to 80871 * get(x, y) using <a href="#/p5/pixels">pixels[]</a> with pixel density d is 80872 * ```javascript 80873 * let x, y, d; // set these to the coordinates 80874 * let off = (y * width + x) * d * 4; 80875 * let components = [ 80876 * pixels[off], 80877 * pixels[off + 1], 80878 * pixels[off + 2], 80879 * pixels[off + 3] 80880 * ]; 80881 * print(components); 80882 * ``` 80883 * See the reference for <a href="#/p5/pixels">pixels[]</a> for more information. 80884 * 80885 * If you want to extract an array of colors or a subimage from an p5.Image object, 80886 * take a look at <a href="#/p5.Image/get">p5.Image.get()</a> 80887 * 80888 * @method get 80889 * @param {Number} x x-coordinate of the pixel 80890 * @param {Number} y y-coordinate of the pixel 80891 * @param {Number} w width 80892 * @param {Number} h height 80893 * @return {p5.Image} the rectangle <a href="#/p5.Image">p5.Image</a> 80894 * @example 80895 * <div> 80896 * <code> 80897 * let img; 80898 * function preload() { 80899 * img = loadImage('assets/rockies.jpg'); 80900 * } 80901 * function setup() { 80902 * image(img, 0, 0); 80903 * let c = get(); 80904 * image(c, width / 2, 0); 80905 * } 80906 * </code> 80907 * </div> 80908 * 80909 * <div> 80910 * <code> 80911 * let img; 80912 * function preload() { 80913 * img = loadImage('assets/rockies.jpg'); 80914 * } 80915 * function setup() { 80916 * image(img, 0, 0); 80917 * let c = get(50, 90); 80918 * fill(c); 80919 * noStroke(); 80920 * rect(25, 25, 50, 50); 80921 * } 80922 * </code> 80923 * </div> 80924 * 80925 * @alt 80926 * 2 images of the rocky mountains, side-by-side 80927 * Image of the rocky mountains with 50Ã50 green rect in center of canvas 80928 */ 80929 /** 80930 * @method get 80931 * @return {p5.Image} the whole <a href="#/p5.Image">p5.Image</a> 80932 */ 80933 /** 80934 * @method get 80935 * @param {Number} x 80936 * @param {Number} y 80937 * @return {Number[]} color of pixel at x,y in array format [R, G, B, A] 80938 */ 80939 _main.default.prototype.get = function (x, y, w, h) { 80940 var _this$_renderer2; 80941 _main.default._validateParameters('get', arguments); 80942 return (_this$_renderer2 = this._renderer).get.apply(_this$_renderer2, arguments); 80943 }; 80944 /** 80945 * Loads the pixel data for the display window into the <a href="#/p5/pixels">pixels[]</a> array. This 80946 * function must always be called before reading from or writing to <a href="#/p5/pixels">pixels[]</a>. 80947 * Note that only changes made with <a href="#/p5/set">set()</a> or direct manipulation of <a href="#/p5/pixels">pixels[]</a> 80948 * will occur. 80949 * 80950 * @method loadPixels 80951 * @example 80952 * <div> 80953 * <code> 80954 * let img; 80955 * function preload() { 80956 * img = loadImage('assets/rockies.jpg'); 80957 * } 80958 * 80959 * function setup() { 80960 * image(img, 0, 0, width, height); 80961 * let d = pixelDensity(); 80962 * let halfImage = 4 * (width * d) * (height * d / 2); 80963 * loadPixels(); 80964 * for (let i = 0; i < halfImage; i++) { 80965 * pixels[i + halfImage] = pixels[i]; 80966 * } 80967 * updatePixels(); 80968 * } 80969 * </code> 80970 * </div> 80971 * 80972 * @alt 80973 * two images of the rocky mountains. one on top, one on bottom of canvas. 80974 */ 80975 _main.default.prototype.loadPixels = function () { 80976 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 80977 args[_key3] = arguments[_key3]; 80978 } 80979 _main.default._validateParameters('loadPixels', args); 80980 this._renderer.loadPixels(); 80981 }; 80982 /** 80983 * Changes the color of any pixel, or writes an image directly to the 80984 * display window. 80985 * The x and y parameters specify the pixel to change and the c parameter 80986 * specifies the color value. This can be a <a href="#/p5.Color">p5.Color</a> object, or [R, G, B, A] 80987 * pixel array. It can also be a single grayscale value. 80988 * When setting an image, the x and y parameters define the coordinates for 80989 * the upper-left corner of the image, regardless of the current <a href="#/p5/imageMode">imageMode()</a>. 80990 *
80991 * After using <a href="#/p5/set">set()</a>, you must call <a href="#/p5/updatePixels">updatePixels()</a> for your changes to appear. 80992 * This should be called once all pixels have been set, and must be called before 80993 * calling .<a href="#/p5/get">get()</a> or drawing the image. 80994 * 80995 * Setting the color of a single pixel with set(x, y) is easy, but not as 80996 * fast as putting the data directly into <a href="#/p5/pixels">pixels[]</a>. Setting the <a href="#/p5/pixels">pixels[]</a> 80997 * values directly may be complicated when working with a retina display, 80998 * but will perform better when lots of pixels need to be set directly on 80999 * every loop. See the reference for <a href="#/p5/pixels">pixels[]</a> for more information. 81000 * 81001 * @method set 81002 * @param {Number} x x-coordinate of the pixel 81003 * @param {Number} y y-coordinate of the pixel 81004 * @param {Number|Number[]|Object} c insert a grayscale value | a pixel array | 81005 * a <a href="#/p5.Color">p5.Color</a> object | a <a href="#/p5.Image">p5.Image</a> to copy 81006 * @example 81007 * <div> 81008 * <code> 81009 * let black = color(0); 81010 * set(30, 20, black); 81011 * set(85, 20, black); 81012 * set(85, 75, black); 81013 * set(30, 75, black); 81014 * updatePixels(); 81015 * </code> 81016 * </div> 81017 * 81018 * <div> 81019 * <code> 81020 * for (let i = 30; i < width - 15; i++) { 81021 * for (let j = 20; j < height - 25; j++) { 81022 * let c = color(204 - j, 153 - i, 0); 81023 * set(i, j, c); 81024 * } 81025 * } 81026 * updatePixels(); 81027 * </code> 81028 * </div> 81029 * 81030 * <div> 81031 * <code> 81032 * let img; 81033 * function preload() { 81034 * img = loadImage('assets/rockies.jpg'); 81035 * } 81036 * 81037 * function setup() { 81038 * set(0, 0, img); 81039 * updatePixels(); 81040 * line(0, 0, width, height); 81041 * line(0, height, width, 0); 81042 * } 81043 * </code> 81044 * </div> 81045 * 81046 * @alt 81047 * 4 black points in the shape of a square middle-right of canvas. 81048 * square with orangey-brown gradient lightening at bottom right. 81049 * image of the rocky mountains. with lines like an 'x' through the center. 81050 */ 81051 _main.default.prototype.set = function (x, y, imgOrCol) { 81052 this._renderer.set(x, y, imgOrCol); 81053 }; 81054 /** 81055 * Updates the display window with the data in the <a href="#/p5/pixels">pixels[]</a> array. 81056 * Use in conjunction with <a href="#/p5/loadPixels">loadPixels()</a>. If you're only reading pixels from 81057 * the array, there's no need to call <a href="#/p5/updatePixels">updatePixels()</a> â updating is only 81058 * necessary to apply changes. <a href="#/p5/updatePixels">updatePixels()</a> should be called anytime the 81059 * pixels array is manipulated or <a href="#/p5/set">set()</a> is called, and only changes made with 81060 * <a href="#/p5/set">set()</a> or direct changes to <a href="#/p5/pixels">pixels[]</a> will occur. 81061 * 81062 * @method updatePixels 81063 * @param {Number} [x] x-coordinate of the upper-left corner of region 81064 * to update 81065 * @param {Number} [y] y-coordinate of the upper-left corner of region 81066 * to update 81067 * @param {Number} [w] width of region to update 81068 * @param {Number} [h] height of region to update 81069 * @example 81070 * <div> 81071 * <code> 81072 * let img; 81073 * function preload() { 81074 * img = loadImage('assets/rockies.jpg'); 81075 * } 81076 * 81077 * function setup() { 81078 * image(img, 0, 0, width, height); 81079 * let d = pixelDensity(); 81080 * let halfImage = 4 * (width * d) * (height * d / 2); 81081 * loadPixels(); 81082 * for (let i = 0; i < halfImage; i++) { 81083 * pixels[i + halfImage] = pixels[i]; 81084 * } 81085 * updatePixels(); 81086 * } 81087 * </code> 81088 * </div> 81089 * @alt 81090 * two images of the rocky mountains. one on top, one on bottom of canvas. 81091 */ 81092 _main.default.prototype.updatePixels = function (x, y, w, h) { 81093 _main.default._validateParameters('updatePixels', arguments); // graceful fail - if loadPixels() or set() has not been called, pixel 81094 // array will be empty, ignore call to updatePixels() 81095 if (this.pixels.length === 0) { 81096 return; 81097 } 81098 this._renderer.updatePixels(x, y, w, h); 81099 }; 81100 var _default = _main.default; 81101 exports.default = _default; 81102 }, 81103 { 81104 '../color/p5.Color': 276, 81105 '../core/main': 290, 81106 './filters': 311, 81107 'core-js/modules/es.array.filter': 171 81108 } 81109 ], 81110 316: [
81111 function (_dereq_, module, exports) { 81112 'use strict'; 81113 _dereq_('core-js/modules/es.symbol'); 81114 _dereq_('core-js/modules/es.symbol.description'); 81115 _dereq_('core-js/modules/es.symbol.iterator'); 81116 _dereq_('core-js/modules/es.array.concat'); 81117 _dereq_('core-js/modules/es.array.includes'); 81118 _dereq_('core-js/modules/es.array.index-of'); 81119 _dereq_('core-js/modules/es.array.iterator'); 81120 _dereq_('core-js/modules/es.array.last-index-of'); 81121 _dereq_('core-js/modules/es.array.slice'); 81122 _dereq_('core-js/modules/es.array.splice'); 81123 _dereq_('core-js/modules/es.function.name'); 81124 _dereq_('core-js/modules/es.object.to-string'); 81125 _dereq_('core-js/modules/es.promise'); 81126 _dereq_('core-js/modules/es.regexp.exec'); 81127 _dereq_('core-js/modules/es.regexp.to-string'); 81128 _dereq_('core-js/modules/es.string.includes'); 81129 _dereq_('core-js/modules/es.string.iterator'); 81130 _dereq_('core-js/modules/es.string.replace'); 81131 _dereq_('core-js/modules/es.string.split'); 81132 _dereq_('core-js/modules/es.typed-array.uint8-array'); 81133 _dereq_('core-js/modules/es.typed-array.copy-within'); 81134 _dereq_('core-js/modules/es.typed-array.every'); 81135 _dereq_('core-js/modules/es.typed-array.fill'); 81136 _dereq_('core-js/modules/es.typed-array.filter'); 81137 _dereq_('core-js/modules/es.typed-array.find'); 81138 _dereq_('core-js/modules/es.typed-array.find-index'); 81139 _dereq_('core-js/modules/es.typed-array.for-each'); 81140 _dereq_('core-js/modules/es.typed-array.includes'); 81141 _dereq_('core-js/modules/es.typed-array.index-of'); 81142 _dereq_('core-js/modules/es.typed-array.iterator'); 81143 _dereq_('core-js/modules/es.typed-array.join'); 81144 _dereq_('core-js/modules/es.typed-array.last-index-of'); 81145 _dereq_('core-js/modules/es.typed-array.map'); 81146 _dereq_('core-js/modules/es.typed-array.reduce'); 81147 _dereq_('core-js/modules/es.typed-array.reduce-right'); 81148 _dereq_('core-js/modules/es.typed-array.reverse'); 81149 _dereq_('core-js/modules/es.typed-array.set'); 81150 _dereq_('core-js/modules/es.typed-array.slice'); 81151 _dereq_('core-js/modules/es.typed-array.some'); 81152 _dereq_('core-js/modules/es.typed-array.sort'); 81153 _dereq_('core-js/modules/es.typed-array.subarray'); 81154 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 81155 _dereq_('core-js/modules/es.typed-array.to-string'); 81156 _dereq_('core-js/modules/web.dom-collections.iterator'); 81157 _dereq_('core-js/modules/web.url'); 81158 function _typeof2(obj) { 81159 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 81160 _typeof2 = function _typeof2(obj) { 81161 return typeof obj; 81162 }; 81163 } else { 81164 _typeof2 = function _typeof2(obj) { 81165 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 81166 }; 81167 } 81168 return _typeof2(obj); 81169 } 81170 _dereq_('core-js/modules/es.symbol'); 81171 _dereq_('core-js/modules/es.symbol.description'); 81172 _dereq_('core-js/modules/es.symbol.iterator'); 81173 _dereq_('core-js/modules/es.array.concat'); 81174 _dereq_('core-js/modules/es.array.includes'); 81175 _dereq_('core-js/modules/es.array.index-of'); 81176 _dereq_('core-js/modules/es.array.iterator'); 81177 _dereq_('core-js/modules/es.array.last-index-of'); 81178 _dereq_('core-js/modules/es.array.slice'); 81179 _dereq_('core-js/modules/es.array.splice'); 81180 _dereq_('core-js/modules/es.function.name'); 81181 _dereq_('core-js/modules/es.object.to-string'); 81182 _dereq_('core-js/modules/es.promise'); 81183 _dereq_('core-js/modules/es.regexp.exec'); 81184 _dereq_('core-js/modules/es.regexp.to-string'); 81185 _dereq_('core-js/modules/es.string.includes'); 81186 _dereq_('core-js/modules/es.string.iterator'); 81187 _dereq_('core-js/modules/es.string.replace'); 81188 _dereq_('core-js/modules/es.string.split'); 81189 _dereq_('core-js/modules/es.typed-array.uint8-array'); 81190 _dereq_('core-js/modules/es.typed-array.copy-within'); 81191 _dereq_('core-js/modules/es.typed-array.every'); 81192 _dereq_('core-js/modules/es.typed-array.fill'); 81193 _dereq_('core-js/modules/es.typed-array.filter'); 81194 _dereq_('core-js/modules/es.typed-array.find'); 81195 _dereq_('core-js/modules/es.typed-array.find-index'); 81196 _dereq_('core-js/modules/es.typed-array.for-each'); 81197 _dereq_('core-js/modules/es.typed-array.includes'); 81198 _dereq_('core-js/modules/es.typed-array.index-of'); 81199 _dereq_('core-js/modules/es.typed-array.iterator'); 81200 _dereq_('core-js/modules/es.typed-array.join'); 81201 _dereq_('core-js/modules/es.typed-array.last-index-of'); 81202 _dereq_('core-js/modules/es.typed-array.map'); 81203 _dereq_('core-js/modules/es.typed-array.reduce'); 81204 _dereq_('core-js/modules/es.typed-array.reduce-right'); 81205 _dereq_('core-js/modules/es.typed-array.reverse'); 81206 _dereq_('core-js/modules/es.typed-array.set'); 81207 _dereq_('core-js/modules/es.typed-array.slice'); 81208 _dereq_('core-js/modules/es.typed-array.some'); 81209 _dereq_('core-js/modules/es.typed-array.sort'); 81210 _dereq_('core-js/modules/es.typed-array.subarray'); 81211 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 81212 _dereq_('core-js/modules/es.typed-array.to-string'); 81213 _dereq_('core-js/modules/web.dom-collections.iterator'); 81214 _dereq_('core-js/modules/web.url'); 81215 Object.defineProperty(exports, '__esModule', { 81216 value: true 81217 }); 81218 exports.default = void 0; 81219 var _main = _interopRequireDefault(_dereq_('../core/main')); 81220 _dereq_('whatwg-fetch'); 81221 _dereq_('es6-promise/auto'); 81222 var _fetchJsonp = _interopRequireDefault(_dereq_('fetch-jsonp')); 81223 var _fileSaver = _interopRequireDefault(_dereq_('file-saver')); 81224 _dereq_('../core/friendly_errors/validate_params'); 81225 _dereq_('../core/friendly_errors/file_errors'); 81226 _dereq_('../core/friendly_errors/fes_core'); 81227 function _interopRequireDefault(obj) { 81228 return obj && obj.__esModule ? obj : { 81229 default: 81230 obj 81231 }; 81232 } 81233 function _typeof(obj) { 81234 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 81235 _typeof = function _typeof(obj) { 81236 return _typeof2(obj); 81237 }; 81238 } else { 81239 _typeof = function _typeof(obj) { 81240 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
81240ypeof2(obj); 81241 }; 81242 } 81243 return _typeof(obj); 81244 } /** 81245 * Loads a JSON file from a file or a URL, and returns an Object. 81246 * Note that even if the JSON file contains an Array, an Object will be 81247 * returned with index numbers as keys. 81248 * 81249 * This method is asynchronous, meaning it may not finish before the next 81250 * line in your sketch is executed. JSONP is supported via a polyfill and you 81251 * can pass in as the second argument an object with definitions of the json 81252 * callback following the syntax specified <a href="https://github.com/camsong/ 81253 * fetch-jsonp">here</a>. 81254 * 81255 * This method is suitable for fetching files up to size of 64MB. 81256 * @method loadJSON 81257 * @param {String} path name of the file or url to load 81258 * @param {Object} [jsonpOptions] options object for jsonp related settings 81259 * @param {String} [datatype] "json" or "jsonp" 81260 * @param {function} [callback] function to be executed after 81261 * <a href="#/p5/loadJSON">loadJSON()</a> completes, data is passed 81262 * in as first argument 81263 * @param {function} [errorCallback] function to be executed if 81264 * there is an error, response is passed 81265 * in as first argument 81266 * @return {Object|Array} JSON data 81267 * @example 81268 * 81269 * Calling <a href="#/p5/loadJSON">loadJSON()</a> inside <a href="#/p5/preload">preload()</a> guarantees to complete the 81270 * operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called. 81271 * 81272 * <div><code> 81273 * // Examples use USGS Earthquake API: 81274 * // https://earthquake.usgs.gov/fdsnws/event/1/#methods 81275 * let earthquakes; 81276 * function preload() { 81277 * // Get the most recent earthquake in the database 81278 * let url = 81279 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' + 81280 * 'summary/all_day.geojson'; 81281 * earthquakes = loadJSON(url); 81282 * } 81283 * 81284 * function setup() { 81285 * noLoop(); 81286 * } 81287 * 81288 * function draw() { 81289 * background(200); 81290 * // Get the magnitude and name of the earthquake out of the loaded JSON 81291 * let earthquakeMag = earthquakes.features[0].properties.mag; 81292 * let earthquakeName = earthquakes.features[0].properties.place; 81293 * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); 81294 * textAlign(CENTER); 81295 * text(earthquakeName, 0, height - 30, width, 30); 81296 * describe(`50Ã50 ellipse that changes from black to white 81297 * depending on the current humidity`); 81298 * } 81299 * </code></div> 81300 * 81301 * Outside of preload(), you may supply a callback function to handle the 81302 * object: 81303 * <div><code> 81304 * function setup() { 81305 * noLoop(); 81306 * let url = 81307 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' + 81308 * 'summary/all_day.geojson'; 81309 * loadJSON(url, drawEarthquake); 81310 * } 81311 * 81312 * function draw() { 81313 * background(200); 81314 * describe(`50Ã50 ellipse that changes from black to white 81315 * depending on the current humidity`); 81316 * } 81317 * 81318 * function drawEarthquake(earthquakes) { 81319 * // Get the magnitude and name of the earthquake out of the loaded JSON 81320 * let earthquakeMag = earthquakes.features[0].properties.mag; 81321 * let earthquakeName = earthquakes.features[0].properties.place; 81322 * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); 81323 * textAlign(CENTER); 81324 * text(earthquakeName, 0, height - 30, width, 30); 81325 * } 81326 * </code></div> 81327 */ 81328 /** 81329 * @method loadJSON 81330 * @param {String} path 81331 * @param {String} datatype 81332 * @param {function} [callback] 81333 * @param {function} [errorCallback] 81334 * @return {Object|Array} 81335 */ 81336 /** 81337 * @method loadJSON 81338 * @param {String} path 81339 * @param {function} callback 81340 * @param {function} [errorCallback] 81341 * @return {Object|Array} 81342 */ 81343 81344 _main.default.prototype.loadJSON = function () { 81345 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 81346 args[_key] = arguments[_key]; 81347 } 81348 _main.default._validateParameters('loadJSON', args); 81349 var path = args[0]; 81350 var callback; 81351 var errorCallback; 81352 var options; 81353 var ret = { 81354 }; // object needed for preload 81355 var t = 'json'; // check for explicit data type argument 81356 for (var i = 1; i < args.length; i++) { 81357 var arg = args[i]; 81358 if (typeof arg === 'string') { 81359 if (arg === 'jsonp' || arg === 'json') { 81360 t = arg; 81361 } 81362 } else if (typeof arg === 'function') { 81363 if (!callback) { 81364 callback = arg; 81365 } else { 81366 errorCallback = arg; 81367 } 81368 } else if (_typeof(arg) === 'object' && (arg.hasOwnProperty('jsonpCallback') || arg.hasOwnProperty('jsonpCallbackFunction'))) { 81369 t = 'jsonp'; 81370 options = arg; 81371 } 81372 } 81373 var self = this; 81374 this.httpDo(path, 'GET', options, t, function (resp) { 81375 for (var k in resp) { 81376 ret[k] = resp[k]; 81377 } 81378 if (typeof callback !== 'undefined') { 81379 callback(resp); 81380 } 81381 self._decrementPreload(); 81382 }, function (err) { 81383 // Error handling 81384 _main.default._friendlyFileLoadError(5, path); 81385 if (errorCallback) { 81386 errorCallback(err); 81387 } else { 81388 throw err; 81389 } 81390 }); 81391 return ret; 81392 }; 81393 /** 81394 * Reads the contents of a file and creates a String array of its individual 81395 * lines. If the name of the file is used as the parameter, as in the above 81396 * example, the file must be located in the sketch directory/folder. 81397 * 81398 * Alternatively, the file maybe be loaded from anywhere on the local 81399 * computer using an absolute path (something that starts with / on Unix and 81400 * Linux, or a drive letter on Windows), or the filename parameter can be a 81401 * URL for a file found on a network. 81402 * 81403 * This method is asynchronous, meaning it may not finish before the next 81404 * line in your sketch is executed. 81405 * 81406 * This method is suitable for fetching files up to size of 64MB. 81407 * @method loadStrings 81408 * @param {String} filename name of the file or url to load 81409 * @param {function} [callback] function to be executed after <a href="#/p5/loadStrings">loadStrings()</a> 81410 * completes, Array is passed in as first 81411 * argument 81412 * @param {function} [errorCallback] function to be executed if 81413 * there is an error, response is passed 81414 * in as first argument 81415 * @return {String[]} Array of Strings 81416 * @example 81417 * 81418 * Calling loadStrings() inside <a href="#/p5/preload">preload()</a> guarantees to complete the 81419 * operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called. 81420 * 81421 * <div><code> 81422 * let result; 81423 * function preload() { 81424 * result = loadStrings('assets/test.txt'); 81425 * } 81426 81427 * function setup() { 81428 * background(200); 81429 * text(random(result), 10, 10, 80, 80); 81430 * describe(`randomly generated text from a file, 81431 * for example "i smell like butter"`); 81432 * } 81433 * </code></div> 81434 * 81435 * Outside of preload(), you may supply a callback function to handle the 81436 * object: 81437 * 81438 * <div><code> 81439 * function setup() { 81440 * loadStrings('assets/test.txt', pickString); 81441 * describe(`randomly generated text from a file, 81442 * for example "i have three feet"`); 81443 * } 81444 * 81445 * function pickString(result) { 81446 * background(200); 81447 * text(random(result), 10, 10, 80, 80); 81448 * } 81449 * </code></div> 81450 */ 81451 _main.default.prototype.loadStrings = function () { 81452 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 81453 args[_key2] = arguments[_key2]; 81454 } 81455 _main.default._validateParameters('loadStrings', args); 81456 var ret = [ 81457 ]; 81458 var callback, 81459 errorCallback; 81460 for (var i = 1; i < args.length; i++) { 81461 var arg = args[i]; 81462 if (typeof arg === 'function') { 81463 if (typeof callback === 'undefined') { 81464 callback = arg; 81465 } else if (typeof errorCallback === 'undefined') { 81466 errorCallback = arg; 81467 } 81468 } 81469 } 81470 var self = this; 81471 _main.default.prototype.httpDo.call(this, args[0], 'GET', 'text', function (data) { 81472 // split lines handling mac/windows/linux endings 81473 var lines = data.replace(/\r\n/g, '\r').replace(/\n/g, '\r').split(/\r/); // safe insert approach which will not blow up stack when inserting 81474 // >100k lines, but still be faster than iterating line-by-line. based on 81475 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#Examples 81476 var QUANTUM = 32768; 81477 for (var _i = 0, len = lines.length; _i < len; _i += QUANTUM) { 81478 Array.prototype.push.apply(ret, lines.slice(_i, Math.min(_i + QUANTUM, len))); 81479 } 81480 if (typeof callback !== 'undefined') { 81481 callback(ret); 81482 } 81483 self._decrementPreload(); 81484 }, function (err) { 81485 // Error handling 81486 _main.default._friendlyFileLoadError(3, arguments[0]); 81487 if (errorCallback) { 81488 errorCallback(err); 81489 } else { 81490 throw err; 81491 } 81492 }); 81493 return ret; 81494 }; 81495 /** 81496 * Reads the contents of a file or URL and creates a <a href="#/p5.Table">p5.Table</a> object with 81497 * its values. If a file is specified, it must be located in the sketch's 81498 * "data" folder. The filename parameter can also be a URL to a file found 81499 * online. By default, the file is assumed to be comma-separated (in CSV 81500 * format). Table only looks for a header row if the 'header' option is 81501 * included. 81502 * 81503 * This method is asynchronous, meaning it may not finish before the next 81504 * line in your sketch is executed. Calling <a href="#/p5/loadTable">loadTable()</a> inside <a href="#/p5/preload">preload()</a> 81505 * guarantees to complete the operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called. 81506 * Outside of <a href="#/p5/preload">preload()</a>, you may supply a callback function to handle the 81507 * object: 81508 * 81509 * All files loaded and saved use UTF-8 encoding. This method is suitable for fetching files up to size of 64MB. 81510 * @method loadTable 81511 * @param {String} filename name of the file or URL to load 81512 * @param {String} [extension] parse the table by comma-separated values "csv", semicolon-separated 81513 * values "ssv", or tab-separated values "tsv" 81514 * @param {String} [header] "header" to indicate table has header row 81515 * @param {function} [callback] function to be executed after 81516 * <a href="#/p5/loadTable">loadTable()</a> completes. On success, the 81517 * <a href="#/p5.Table">Table</a> object is passed in as the 81518 * first argument. 81519 * @param {function} [errorCallback] function to be executed if 81520 * there is an error, response is passed 81521 * in as first argument 81522 * @return {Object} <a href="#/p5.Table">Table</a>
81522 object containing data 81523 * 81524 * @example 81525 * <div class='norender'> 81526 * <code> 81527 * // Given the following CSV file called "mammals.csv" 81528 * // located in the project's "assets" folder: 81529 * // 81530 * // id,species,name 81531 * // 0,Capra hircus,Goat 81532 * // 1,Panthera pardus,Leopard 81533 * // 2,Equus zebra,Zebra 81534 * 81535 * let table; 81536 * 81537 * function preload() { 81538 * //my table is comma separated value "csv" 81539 * //and has a header specifying the columns labels 81540 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 81541 * //the file can be remote 81542 * //table = loadTable("http://p5js.org/reference/assets/mammals.csv", 81543 * // "csv", "header"); 81544 * } 81545 * 81546 * function setup() { 81547 * //count the columns 81548 * print(table.getRowCount() + ' total rows in table'); 81549 * print(table.getColumnCount() + ' total columns in table'); 81550 * 81551 * print(table.getColumn('name')); 81552 * //["Goat", "Leopard", "Zebra"] 81553 * 81554 * //cycle through the table 81555 * for (let r = 0; r < table.getRowCount(); r++) 81556 * for (let c = 0; c < table.getColumnCount(); c++) { 81557 * print(table.getString(r, c)); 81558 * } 81559 * describe(`randomly generated text from a file, 81560 * for example "i smell like butter"`); 81561 * } 81562 * </code> 81563 * </div> 81564 */ 81565 _main.default.prototype.loadTable = function (path) { 81566 // p5._validateParameters('loadTable', arguments); 81567 var callback; 81568 var errorCallback; 81569 var options = [ 81570 ]; 81571 var header = false;
81572 var ext = path.substring(path.lastIndexOf('.') + 1, path.length); 81573 var sep; 81574 if (ext === 'csv') { 81575 sep = ','; 81576 } else if (ext === 'ssv') { 81577 sep = ';'; 81578 } else if (ext === 'tsv') { 81579 sep = '\t'; 81580 } 81581 for (var i = 1; i < arguments.length; i++) { 81582 if (typeof arguments[i] === 'function') { 81583 if (typeof callback === 'undefined') { 81584 callback = arguments[i]; 81585 } else if (typeof errorCallback === 'undefined') { 81586 errorCallback = arguments[i]; 81587 } 81588 } else if (typeof arguments[i] === 'string') { 81589 options.push(arguments[i]); 81590 if (arguments[i] === 'header') { 81591 header = true; 81592 } 81593 if (arguments[i] === 'csv') { 81594 sep = ','; 81595 } else if (arguments[i] === 'ssv') { 81596 sep = ';'; 81597 } else if (arguments[i] === 'tsv') { 81598 sep = '\t'; 81599 } 81600 } 81601 } 81602 var t = new _main.default.Table(); 81603 var self = this; 81604 this.httpDo(path, 'GET', 'table', function (resp) { 81605 var state = { 81606 }; // define constants 81607 var PRE_TOKEN = 0, 81608 MID_TOKEN = 1, 81609 POST_TOKEN = 2, 81610 POST_RECORD = 4; 81611 var QUOTE = '"', 81612 CR = '\r', 81613 LF = '\n'; 81614 var records = [ 81615 ]; 81616 var offset = 0; 81617 var currentRecord = null; 81618 var currentChar; 81619 var tokenBegin = function tokenBegin() { 81620 state.currentState = PRE_TOKEN; 81621 state.token = ''; 81622 }; 81623 var tokenEnd = function tokenEnd() { 81624 currentRecord.push(state.token); 81625 tokenBegin(); 81626 }; 81627 var recordBegin = function recordBegin() { 81628 state.escaped = false; 81629 currentRecord = [ 81630 ]; 81631 tokenBegin(); 81632 }; 81633 var recordEnd = function recordEnd() { 81634 state.currentState = POST_RECORD; 81635 records.push(currentRecord); 81636 currentRecord = null; 81637 }; 81638 for (; ; ) { 81639 currentChar = resp[offset++]; // EOF 81640 if (currentChar == null) { 81641 if (state.escaped) { 81642 throw new Error('Unclosed quote in file.'); 81643 } 81644 if (currentRecord) { 81645 tokenEnd(); 81646 recordEnd(); 81647 break; 81648 } 81649 } 81650 if (currentRecord === null) { 81651 recordBegin(); 81652 } // Handle opening quote 81653 81654 if (state.currentState === PRE_TOKEN) { 81655 if (currentChar === QUOTE) { 81656 state.escaped = true; 81657 state.currentState = MID_TOKEN; 81658 continue; 81659 } 81660 state.currentState = MID_TOKEN; 81661 } // mid-token and escaped, look for sequences and end quote 81662 81663 if (state.currentState === MID_TOKEN && state.escaped) { 81664 if (currentChar === QUOTE) { 81665 if (resp[offset] === QUOTE) { 81666 state.token += QUOTE; 81667 offset++; 81668 } else { 81669 state.escaped = false; 81670 state.currentState = POST_TOKEN; 81671 } 81672 } else if (currentChar === CR) { 81673 continue; 81674 } else { 81675 state.token += currentChar; 81676 } 81677 continue; 81678 } // fall-through: mid-token or post-token, not escaped 81679 81680 if (currentChar === CR) { 81681 if (resp[offset] === LF) { 81682 offset++; 81683 } 81684 tokenEnd(); 81685 recordEnd(); 81686 } else if (currentChar === LF) { 81687 tokenEnd(); 81688 recordEnd(); 81689 } else if (currentChar === sep) { 81690 tokenEnd(); 81691 } else if (state.currentState === MID_TOKEN) { 81692 state.token += currentChar; 81693 } 81694 } // set up column names 81695 81696 if (header) { 81697 t.columns = records.shift(); 81698 } else { 81699 for (var _i2 = 0; _i2 < records[0].length; _i2++) { 81700 t.columns[_i2] = 'null';
81701 } 81702 } 81703 var row; 81704 for (var _i3 = 0; _i3 < records.length; _i3++) { 81705 //Handles row of 'undefined' at end of some CSVs 81706 if (records[_i3].length === 1) { 81707 if (records[_i3][0] === 'undefined' || records[_i3][0] === '') { 81708 continue; 81709 } 81710 } 81711 row = new _main.default.TableRow(); 81712 row.arr = records[_i3]; 81713 row.obj = makeObject(records[_i3], t.columns); 81714 t.addRow(row); 81715 } 81716 if (typeof callback === 'function') { 81717 callback(t); 81718 } 81719 self._decrementPreload(); 81720 }, function (err) { 81721 // Error handling 81722 _main.default._friendlyFileLoadError(2, path); 81723 if (errorCallback) { 81724 errorCallback(err); 81725 } else { 81726 console.error(err); 81727 } 81728 }); 81729 return t; 81730 }; // helper function to turn a row into a JSON object 81731 function makeObject(row, headers) { 81732 var ret = { 81733 }; 81734 headers = headers || [ 81735 ]; 81736 if (typeof headers === 'undefined') { 81737 for (var j = 0; j < row.length; j++) { 81738 headers[j.toString()] = j; 81739 } 81740 } 81741 for (var i = 0; i < headers.length; i++) { 81742 var key = headers[i]; 81743 var val = row[i]; 81744 ret[key] = val; 81745 } 81746 return ret; 81747 } /** 81748 * Reads the contents of a file and creates an XML object with its values. 81749 * If the name of the file is used as the parameter, as in the above example, 81750 * the file must be located in the sketch directory/folder. 81751 * 81752 * Alternatively, the file maybe be loaded from anywhere on the local 81753 * computer using an absolute path (something that starts with / on Unix and 81754 * Linux, or a drive letter on Windows), or the filename parameter can be a 81755 * URL for a file found on a network. 81756 * 81757 * This method is asynchronous, meaning it may not finish before the next 81758 * line in your sketch is executed. Calling <a href="#/p5/loadXML">loadXML()</a> inside <a href="#/p5/preload">preload()</a> 81759 * guarantees to complete the operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called. 81760 * 81761 * Outside of <a href="#/p5/preload">preload()</a>, you may supply a callback function to handle the 81762 * object. 81763 * 81764 * This method is suitable for fetching files up to size of 64MB. 81765 * @method loadXML 81766 * @param {String} filename name of the file or URL to load 81767 * @param {function} [callback] function to be executed after <a href="#/p5/loadXML">loadXML()</a> 81768 * completes, XML object is passed in as 81769 * first argument 81770 * @param {function} [errorCallback] function to be executed if 81771 * there is an error, response is passed 81772 * in as first argument 81773 * @return {Object} XML object containing data 81774 * @example 81775 * <div class='norender'><code> 81776 * // The following short XML file called "mammals.xml" is parsed 81777 * // in the code below. 81778 * // 81779 * // <?xml version="1.0"?> 81780 * // <mammals> 81781 * // <animal id="0" species="Capra hircus">Goat</animal> 81782 * // <animal id="1" species="Panthera pardus">Leopard</animal> 81783 * // <animal id="2" species="Equus zebra">Zebra</animal> 81784 * // </mammals> 81785 * 81786 * let xml; 81787 * 81788 * function preload() { 81789 * xml = loadXML('assets/mammals.xml'); 81790 * } 81791 * 81792 * function setup() { 81793 * let children = xml.getChildren('animal'); 81794 * 81795 * for (let i = 0; i < children.length; i++) { 81796 * let id = children[i].getNum('id'); 81797 * let coloring = children[i].getString('species'); 81798 * let name = children[i].getContent(); 81799 * print(id + ', ' + coloring + ', ' + name); 81800 * } 81801 * describe('no image displayed'); 81802 * } 81803 * 81804 * // Sketch prints: 81805 * // 0, Capra hircus, Goat 81806 * // 1, Panthera pardus, Leopard 81807 * // 2, Equus zebra, Zebra 81808 * </code></div> 81809 */ 81810 81811 _main.default.prototype.loadXML = function () { 81812 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 81813 args[_key3] = arguments[_key3]; 81814 } 81815 var ret = new _main.default.XML(); 81816 var callback, 81817 errorCallback; 81818 for (var i = 1; i < args.length; i++) { 81819 var arg = args[i]; 81820 if (typeof arg === 'function') { 81821 if (typeof callback === 'undefined') { 81822 callback = arg; 81823 } else if (typeof errorCallback === 'undefined') { 81824 errorCallback = arg; 81825 } 81826 } 81827 } 81828 var self = this; 81829 this.httpDo(args[0], 'GET', 'xml', function (xml) { 81830 for (var key in xml) { 81831 ret[key] = xml[key]; 81832 } 81833 if (typeof callback !== 'undefined') { 81834 callback(ret); 81835 } 81836 self._decrementPreload(); 81837 }, function (err) { 81838 // Error handling 81839 _main.default._friendlyFileLoadError(1, arguments[0]); 81840 if (errorCallback) { 81841 errorCallback(err); 81842 } else { 81843 throw err; 81844 } 81845 }); 81846 return ret; 81847 }; 81848 /** 81849 * This method is suitable for fetching files up to size of 64MB. 81850 * @method loadBytes 81851 * @param {string} file name of the file or URL to load 81852 * @param {function} [callback] function to be executed after <a href="#/p5/loadBytes">loadBytes()</a> 81853 * completes 81854 * @param {function} [errorCallback] function to be executed if there 81855 * is an error 81856 * @returns {Object} an object whose 'bytes' property will be the loaded buffer 81857 * 81858 * @example 81859 * <div class='norender'><code> 81860 * let data; 81861 * 81862 * function preload() { 81863 * data = loadBytes('assets/mammals.xml'); 81864 * } 81865 * 81866 * function setup() { 81867 * for (let i = 0; i < 5; i++) { 81868 * console.log(data.bytes[i].toString(16)); 81869 * } 81870 * describe('no image displayed'); 81871 * } 81872 * </code></div> 81873 */ 81874 _main.default.prototype.loadBytes = function (file, callback, errorCallback) { 81875 var ret = { 81876 }; 81877 var self = this; 81878 this.httpDo(file, 'GET', 'arrayBuffer', function (arrayBuffer) { 81879 ret.bytes = new Uint8Array(arrayBuffer); 81880 if (typeof callback === 'function') { 81881 callback(ret); 81882 } 81883 self._decrementPreload(); 81884 }, function (err) { 81885 // Error handling 81886 _main.default._friendlyFileLoadError(6, file); 81887 if (errorCallback) { 81888 errorCallback(err); 81889 } else { 81890 throw err; 81891 } 81892 }); 81893 return ret; 81894 }; 81895 /** 81896 * Method for executing an HTTP GET request. If data type is not specified, 81897 * p5 will try to guess based on the URL, defaulting to text. This is equivalent to 81898 * calling <code>httpDo(path, 'GET')</code>. The 'binary' datatype will return 81899 * a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer 81900 * which can be used to initialize typed arrays (such as Uint8Array). 81901 * 81902 * @method httpGet 81903 * @param {String} path name of the file or url to load 81904 * @param {String} [datatype] "json", "jsonp", "binary", "arrayBuffer", 81905 * "xml", or "text" 81906 * @param {Object|Boolean} [data] param data passed sent with request 81907 * @param {function} [callback] function to be executed after 81908 * <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in 81909 * as first argument 81910 * @param {function} [errorCallback] function to be executed if 81911 * there is an error, response is passed 81912 * in as first argument 81913 * @return {Promise} A promise that resolves with the data when the operation 81914 * completes successfully or rejects with the error after 81915 * one occurs. 81916 * @example 81917 * <div class='norender'><code> 81918 * // Examples use USGS Earthquake API: 81919 * // https://earthquake.usgs.gov/fdsnws/event/1/#methods 81920 * let earthquakes; 81921 * function preload() { 81922 * // Get the most recent earthquake in the database 81923 * let url = 81924 'https://earthquake.usgs.gov/fdsnws/event/1/query?' + 81925 * 'format=geojson&limit=1&orderby=time'; 81926 * httpGet(url, 'jsonp', false, function(response) { 81927 * // when the HTTP request completes, populate the variable that holds the 81928 * // earthquake data used in the visualization. 81929 * earthquakes = response; 81930 * }); 81931 * } 81932 * 81933 * function draw() { 81934 * if (!earthquakes) { 81935 * // Wait until the earthquake data has loaded before drawing. 81936 * return; 81937 * } 81938 * background(200); 81939 * // Get the magnitude and name of the earthquake out of the loaded JSON 81940 * let earthquakeMag = earthquakes.features[0].properties.mag; 81941 * let earthquakeName = earthquakes.features[0].properties.place; 81942 * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); 81943 * textAlign(CENTER);
81944 * text(earthquakeName, 0, height - 30, width, 30); 81945 * noLoop(); 81946 * } 81947 * </code></div> 81948 */ 81949 /** 81950 * @method httpGet 81951 * @param {String} path 81952 * @param {Object|Boolean} data 81953 * @param {function} [callback] 81954 * @param {function} [errorCallback] 81955 * @return {Promise} 81956 */ 81957 /** 81958 * @method httpGet 81959 * @param {String} path 81960 * @param {function} callback 81961 * @param {function} [errorCallback] 81962 * @return {Promise} 81963 */ 81964 _main.default.prototype.httpGet = function () { 81965 _main.default._validateParameters('httpGet', arguments); 81966 var args = Array.prototype.slice.call(arguments); 81967 args.splice(1, 0, 'GET'); 81968 return _main.default.prototype.httpDo.apply(this, args); 81969 }; 81970 /** 81971 * Method for executing an HTTP POST request. If data type is not specified, 81972 * p5 will try to guess based on the URL, defaulting to text. This is equivalent to 81973 * calling <code>httpDo(path, 'POST')</code>. 81974 * 81975 * @method httpPost 81976 * @param {String} path name of the file or url to load 81977 * @param {String} [datatype] "json", "jsonp", "xml", or "text". 81978 * If omitted, <a href="#/p5/httpPost">httpPost()</a> will guess. 81979 * @param {Object|Boolean} [data] param data passed sent with request 81980 * @param {function} [callback] function to be executed after 81981 * <a href="#/p5/httpPost">httpPost()</a> completes, data is passed in 81982 * as first argument 81983 * @param {function} [errorCallback] function to be executed if 81984 * there is an error, response is passed 81985 * in as first argument 81986 * @return {Promise} A promise that resolves with the data when the operation 81987 * completes successfully or rejects with the error after 81988 * one occurs. 81989 * 81990 * @example 81991 * <div> 81992 * <code> 81993 * // Examples use jsonplaceholder.typicode.com for a Mock Data API 81994 * 81995 * let url = 'https://jsonplaceholder.typicode.com/posts'; 81996 * let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is very cool.' }; 81997 * 81998 * function setup() { 81999 * createCanvas(100, 100); 82000 * background(200); 82001 * } 82002 * 82003 * function mousePressed() { 82004 * httpPost(url, 'json', postData, function(result) { 82005 * strokeWeight(2); 82006 * text(result.body, mouseX, mouseY); 82007 * }); 82008 * } 82009 * </code> 82010 * </div> 82011 * 82012 * <div><code> 82013 * let url = 'ttps://invalidURL'; // A bad URL that will cause errors 82014 * let postData = { title: 'p5 Clicked!', body: 'p5.js is very cool.' }; 82015 * 82016 * function setup() { 82017 * createCanvas(100, 100); 82018 * background(200); 82019 * } 82020 * 82021 * function mousePressed() { 82022 * httpPost( 82023 * url, 82024 * 'json', 82025 * postData, 82026 * function(result) { 82027 * // ... won't be called 82028 * }, 82029 * function(error) { 82030 * strokeWeight(2); 82031 * text(error.toString(), mouseX, mouseY); 82032 * } 82033 * ); 82034 * } 82035 * </code></div> 82036 */ 82037 /** 82038 * @method httpPost 82039 * @param {String} path 82040 * @param {Object|Boolean} data 82041 * @param {function} [callback] 82042 * @param {function} [errorCallback] 82043 * @return {Promise} 82044 */ 82045 /** 82046 * @method httpPost 82047 * @param {String} path 82048 * @param {function} callback 82049 * @param {function} [errorCallback] 82050 * @return {Promise} 82051 */ 82052 _main.default.prototype.httpPost = function () { 82053 _main.default._validateParameters('httpPost', arguments); 82054 var args = Array.prototype.slice.call(arguments); 82055 args.splice(1, 0, 'POST'); 82056 return _main.default.prototype.httpDo.apply(this, args); 82057 }; 82058 /** 82059 * Method for executing an HTTP request. If data type is not specified, 82060 * p5 will try to guess based on the URL, defaulting to text.<br><br> 82061 * For more advanced use, you may also pass in the path as the first argument 82062 * and a object as the second argument, the signature follows the one specified 82063 * in the Fetch API specification. 82064 * This method is suitable for fetching files up to size of 64MB when "GET" is used. 82065 * 82066 * @method httpDo 82067 * @param {String} path name of the file or url to load 82068 * @param {String} [method] either "GET", "POST", or "PUT", 82069 * defaults to "GET" 82070 * @param {String} [datatype] "json", "jsonp", "xml", or "text" 82071 * @param {Object} [data] param data passed sent with request 82072 * @param {function} [callback] function to be executed after 82073 * <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in 82074 * as first argument 82075 * @param {function} [errorCallback] function to be executed if 82076 * there is an error, response is passed 82077 * in as first argument 82078 * @return {Promise} A promise that resolves with the data when the operation 82079 * completes successfully or rejects with the error after 82080 * one occurs. 82081 * 82082 * @example 82083 * <div> 82084 * <code> 82085 * // Examples use USGS Earthquake API: 82086 * // https://earthquake.usgs.gov/fdsnws/event/1/#methods 82087 * 82088 * // displays an animation of all USGS earthquakes 82089 * let earthquakes; 82090 * let eqFeatureIndex = 0; 82091 * 82092 * function preload() { 82093 * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson'; 82094 * httpDo( 82095 * url, 82096 * { 82097 * method: 'GET', 82098 * // Other Request options, like special headers for apis 82099 * headers: { authorization: 'Bearer secretKey' } 82100 * }, 82101 * function(res) { 82102 * earthquakes = res; 82103 * } 82104 * ); 82105 * } 82106 * 82107 * function draw() { 82108 * // wait until the data is loaded 82109 * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) { 82110 * return; 82111 * } 82112 * clear(); 82113 * 82114 * let feature = earthquakes.features[eqFeatureIndex]; 82115 * let mag = feature.properties.mag; 82116 * let rad = mag / 11 * ((width + height) / 2); 82117 * fill(255, 0, 0, 100); 82118 * ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad); 82119 * 82120 * if (eqFeatureIndex >= earthquakes.features.length) { 82121 * eqFeatureIndex = 0; 82122 * } else { 82123 * eqFeatureIndex += 1; 82124 * } 82125 * } 82126 * </code> 82127 * </div> 82128 */ 82129 /** 82130 * @method httpDo 82131 * @param {String} path 82132 * @param {Object} options Request object options as documented in the 82133 * "fetch" API 82134 * <a href="https://developer.mozilla.org/en/docs/Web/API/Fetch_API">reference</a> 82135 * @param {function} [callback] 82136 * @param {function} [errorCallback] 82137 * @return {Promise} 82138 */ 82139 _main.default.prototype.httpDo = function () { 82140 var type; 82141 var callback; 82142 var errorCallback; 82143 var request; 82144 var promise; 82145 var jsonpOptions = { 82146 }; 82147 var cbCount = 0; 82148 var contentType = 'text/plain'; // Trim the callbacks off the end to get an idea of how many arguments are passed 82149 for (var i = arguments.length - 1; i > 0; i--) { 82150 if (typeof (i < 0 || arguments.length <= i ? undefined : arguments[i]) === 'function') { 82151 cbCount++; 82152 } else { 82153 break; 82154 } 82155 } // The number of arguments minus callbacks 82156 82157 var argsCount = arguments.length - cbCount; 82158 var path = arguments.length <= 0 ? undefined : arguments[0]; 82159 if (argsCount === 2 && typeof path === 'string' && _typeof(arguments.length <= 1 ? undefined : arguments[1]) === 'object') { 82160 // Intended for more advanced use, pass in Request parameters directly
82161 request = new Request(path, arguments.length <= 1 ? undefined : arguments[1]); 82162 callback = arguments.length <= 2 ? undefined : arguments[2]; 82163 errorCallback = arguments.length <= 3 ? undefined : arguments[3]; 82164 } else { 82165 // Provided with arguments 82166 var method = 'GET'; 82167 var data; 82168 for (var j = 1; j < arguments.length; j++) { 82169 var a = j < 0 || arguments.length <= j ? undefined : arguments[j]; 82170 if (typeof a === 'string') { 82171 if (a === 'GET' || a === 'POST' || a === 'PUT' || a === 'DELETE') { 82172 method = a; 82173 } else if (a === 'json' || a === 'jsonp' || a === 'binary' || a === 'arrayBuffer' || a === 'xml' || a === 'text' || a === 'table') { 82174 type = a; 82175 } else { 82176 data = a; 82177 } 82178 } else if (typeof a === 'number') { 82179 data = a.toString(); 82180 } else if (_typeof(a) === 'object') { 82181 if (a.hasOwnProperty('jsonpCallback') || a.hasOwnProperty('jsonpCallbackFunction')) { 82182 for (var attr in a) { 82183 jsonpOptions[attr] = a[attr]; 82184 } 82185 } else if (a instanceof _main.default.XML) { 82186 data = a.serialize(); 82187 contentType = 'application/xml'; 82188 } else { 82189 data = JSON.stringify(a); 82190 contentType = 'application/json'; 82191 } 82192 } else if (typeof a === 'function') { 82193 if (!callback) { 82194 callback = a; 82195 } else { 82196 errorCallback = a; 82197 } 82198 } 82199 } 82200 var headers = method === 'GET' ? new Headers() : new Headers({ 82201 'Content-Type': contentType 82202 }); 82203 request = new Request(path, { 82204 method: method, 82205 mode: 'cors', 82206 body: data, 82207 headers: headers 82208 }); 82209 } // do some sort of smart type checking 82210 82211 if (!type) { 82212 if (path.includes('json')) { 82213 type = 'json'; 82214 } else if (path.includes('xml')) { 82215 type = 'xml'; 82216 } else { 82217 type = 'text'; 82218 } 82219 } 82220 if (type === 'jsonp') { 82221 promise = (0, _fetchJsonp.default) (path, jsonpOptions); 82222 } else { 82223 promise = fetch(request); 82224 } 82225 promise = promise.then(function (res) { 82226 if (!res.ok) { 82227 var err = new Error(res.body); 82228 err.status = res.status; 82229 err.ok = false; 82230 throw err; 82231 } else { 82232 var fileSize = 0; 82233 if (type !== 'jsonp') { 82234 fileSize = res.headers.get('content-length'); 82235 } 82236 if (fileSize && fileSize > 64000000) { 82237 _main.default._friendlyFileLoadError(7, path); 82238 } 82239 switch (type) { 82240 case 'json': 82241 case 'jsonp': 82242 return res.json(); 82243 case 'binary': 82244 return res.blob(); 82245 case 'arrayBuffer': 82246 return res.arrayBuffer(); 82247 case 'xml': 82248 return res.text().then(function (text) { 82249 var parser = new DOMParser(); 82250 var xml = parser.parseFromString(text, 'text/xml'); 82251 return new _main.default.XML(xml.documentElement); 82252 }); 82253 default: 82254 return res.text(); 82255 } 82256 } 82257 }); 82258 promise.then(callback || function () { 82259 }); 82260 promise.catch(errorCallback || console.error); 82261 return promise; 82262 }; 82263 /** 82264 * @module IO 82265 * @submodule Output 82266 * @for p5 82267 */ 82268 window.URL = window.URL || window.webkitURL; // private array of p5.PrintWriter objects 82269 _main.default.prototype._pWriters = [ 82270 ]; 82271 /** 82272 * @method createWriter 82273 * @param {String} name name of the file to be created 82274 * @param {String} [extension] 82275 * @return {p5.PrintWriter} 82276 * @example 82277 * <div> 82278 * <code> 82279 * function setup() { 82280 * createCanvas(100, 100); 82281 * background(200); 82282 * text('click here to save', 10, 10, 70, 80); 82283 * } 82284 * 82285 * function mousePressed() { 82286 * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { 82287 * const writer = createWriter('squares.txt'); 82288 * for (let i = 0; i < 10; i++) { 82289 * writer.print(i * i); 82290 * } 82291 * writer.close(); 82292 * writer.clear(); 82293 * } 82294 * } 82295 * </code> 82296 * </div> 82297 */ 82298 _main.default.prototype.createWriter = function (name, extension) { 82299 var newPW; // check that it doesn't already exist 82300 for (var i in _main.default.prototype._pWriters) { 82301 if (_main.default.prototype._pWriters[i].name === name) { 82302 // if a p5.PrintWriter w/ this name already exists... 82303 // return p5.prototype._pWriters[i]; // return it w/ contents intact. 82304 // or, could return a new, empty one with a unique name: 82305 newPW = new _main.default.PrintWriter(name + this.millis(), extension); 82306 _main.default.prototype._pWriters.push(newPW); 82307 return newPW; 82308 } 82309 } 82310 newPW = new _main.default.PrintWriter(name, extension); 82311 _main.default.prototype._pWriters.push(newPW); 82312 return newPW; 82313 }; 82314 /** 82315 * @class p5.PrintWriter 82316 * @param {String} filename 82317 * @param {String} [extension] 82318 */ 82319 _main.default.PrintWriter = function (filename, extension) { 82320 var self = this; 82321 this.name = filename; 82322 this.content = ''; //Changed to write because it was being overloaded by function below. 82323 /** 82324 * Writes data to the PrintWriter stream 82325 * @method write 82326 * @param {Array} data all data to be written by the PrintWriter 82327 * @example 82328 * <div class="norender notest"> 82329 * <code> 82330 * // creates a file called 'newFile.txt' 82331 * let writer = createWriter('newFile.txt'); 82332 * // write 'Hello world!'' to the file 82333 * writer.write(['Hello world!']); 82334 * // close the PrintWriter and save the file 82335 * writer.close(); 82336 * </code> 82337 * </div> 82338 * <div class='norender notest'> 82339 * <code> 82340 * // creates a file called 'newFile2.txt' 82341 * let writer = createWriter('newFile2.txt'); 82342 * // write 'apples,bananas,123' to the file 82343 * writer.write(['apples', 'bananas', 123]); 82344 * // close the PrintWriter and save the file 82345 * writer.close(); 82346 * </code> 82347 * </div> 82348 * <div class='norender notest'> 82349 * <code> 82350 * // creates a file called 'newFile3.txt' 82351 * let writer = createWriter('newFile3.txt'); 82352 * // write 'My name is: Teddy' to the file 82353 * writer.write('My name is:'); 82354 * writer.write(' Teddy'); 82355 * // close the PrintWriter and save the file 82356 * writer.close(); 82357 * </code> 82358 * </div> 82359 * <div> 82360 * <code> 82361 * function setup() { 82362 * createCanvas(100, 100); 82363 * button = createButton('SAVE FILE'); 82364 * button.position(21, 40); 82365 * button.mousePressed(createFile); 82366 * } 82367 * 82368 * function createFile() { 82369 * // creates a file called 'newFile.txt' 82370 * let writer = createWriter('newFile.txt'); 82371 * // write 'Hello world!'' to the file 82372 * writer.write(['Hello world!']); 82373 * // close the PrintWriter and save the file 82374 * writer.close(); 82375 * } 82376 * </code> 82377 * </div> 82378 */ 82379 this.write = function (data) { 82380 this.content += data; 82381 }; 82382 /** 82383 * Writes data to the PrintWriter stream, and adds a new line at the end 82384 * @method print 82385 * @param {Array} data all data to be printed by the PrintWriter 82386 * @example 82387 * <div class='norender notest'> 82388 * <code> 82389 * // creates a file called 'newFile.txt' 82390 * let writer = createWriter('newFile.txt'); 82391 * // creates a file containing 82392 * // My name is: 82393 * // Teddy 82394 * writer.print('My name is:'); 82395 * writer.print('Teddy'); 82396 * // close the PrintWriter and save the file 82397 * writer.close(); 82398 * </code> 82399 * </div> 82400 * <div class='norender notest'> 82401 * <code> 82402 * let writer; 82403 * 82404 * function setup() { 82405 * createCanvas(400, 400); 82406 * // create a PrintWriter 82407 * writer = createWriter('newFile.txt'); 82408 * } 82409 * 82410 * function draw() { 82411 * writer.print([mouseX, mouseY]); 82412 * } 82413 * 82414 * function mouseClicked() { 82415 * writer.close(); 82416 * } 82417 * </code> 82418 * </div> 82419 */ 82420 this.print = function (data) { 82421 this.content += ''.concat(data, '\n'); 82422 }; 82423 /** 82424 * Clears the data already written to the PrintWriter object 82425 * @method clear 82426 * @example 82427 * <div class ="norender notest"><code> 82428 * // create writer object 82429 * let writer = createWriter('newFile.txt'); 82430 * writer.write(['clear me']); 82431 * // clear writer object here 82432 * writer.clear(); 82433 * // close writer 82434 * writer.close(); 82435 * </code></div> 82436 * <div> 82437 * <code> 82438 * function setup() { 82439 * button = createButton('CLEAR ME'); 82440 * button.position(21, 40); 82441 * button.mousePressed(createFile); 82442 * } 82443 * 82444 * function createFile() { 82445 * let writer = createWriter('newFile.txt'); 82446 * writer.write(['clear me']); 82447 * writer.clear(); 82448 * writer.close(); 82449 * } 82450 * </code> 82451 * </div> 82452 * 82453 */ 82454 this.clear = function () { 82455 this.content = ''; 82456 }; 82457 /** 82458 * Closes the PrintWriter 82459 * @method close 82460 * @example 82461 * <div class="norender notest"> 82462 * <code> 82463 * // create a file called 'newFile.txt' 82464 * let writer = createWriter('newFile.txt'); 82465 * // close the PrintWriter and save the file 82466 * writer.close(); 82467 * </code> 82468 * </div> 82469 * <div class='norender notest'> 82470 * <code> 82471 * // create a file called 'newFile2.txt' 82472 * let writer = createWriter('newFile2.txt'); 82473 * // write some data to the file 82474 * writer.write([100, 101, 102]); 82475 * // close the PrintWriter and save the file 82476 * writer.close(); 82477 * </code> 82478 * </div> 82479 */ 82480 this.close = function () { 82481 // convert String to Array for the writeFile Blob 82482 var arr = [ 82483 ]; 82484 arr.push(this.content); 82485 _main.default.prototype.writeFile(arr, filename, extension); // remove from _pWriters array and delete self 82486 for (var i in _main.default.prototype._pWriters) { 82487 if (_main.default.prototype._pWriters[i].name === this.name) { 82488 // remove from _pWriters array 82489 _main.default.prototype._pWriters.splice(i, 1); 82490 } 82491 } 82492 self.clear(); 82493 self = { 82494 }; 82495 }; 82496 }; 82497 /** 82498 * @module IO 82499 * @submodule Output 82500 * @for p5 82501 */ 82502 // object, filename, options --> saveJSON, saveStrings, 82503 // filename, [extension] [canvas] --> saveImage 82504 /** 82505 * Saves a given element(image, text, json, csv, wav, or html) to the client's 82506 * computer. The first parameter can be a pointer to element we want to save. 82507 * The element can be one of <a href="#/p5.Element">p5.Element</a>,an Array of 82508 * Strings, an Array of JSON, a JSON object, a <a href="#/p5.Table">p5.Table 82509 * </a>, a <a href="#/p5.Image">p5.Image</a>, or a p5.SoundFile (requires 82510 * p5.sound). The second parameter is a filename (including extension).The 82511 * third parameter is for options specific to this type of object. This method 82512 * will save a file that fits the given parameters. 82513 * If it is called without specifying an element, by default it will save the 82514 * whole canvas as an image file. You can optionally specify a filename as 82515 * the first parameter in such a case. 82516 * **Note that it is not recommended to 82517 * call this method within draw, as it will open a new save dialog on every 82518 * render.** 82519 * 82520 * @method save 82521 * @param {Object|String} [objectOrFilename] If filename is provided, will 82522 * save canvas as an image with 82523 * either png or jpg extension 82524 * depending on the filename. 82525 * If object is provided, will 82526 * save depending on the object 82527 * and filename (see examples 82528 * above). 82529 * @param {String} [filename] If an object is provided as the first 82530 * parameter, then the second parameter 82531 * indicates the filename, 82532 * and should include an appropriate 82533 * file extension (see examples above). 82534 * @param {Boolean|String} [options] Additional options depend on 82535 * filetype. For example, when saving JSON, 82536 * <code>true</code> indicates that the 82537 * output will be optimized for filesize, 82538 * rather than readability. 82539 * 82540 * @example 82541 * <div class="norender"><code> 82542 * // Saves the canvas as an image 82543 * cnv = createCanvas(300, 300); 82544 * save(cnv, 'myCanvas.jpg'); 82545 * 82546 * // Saves the canvas as an image by default 82547 * save('myCanvas.jpg'); 82548 * describe('An example for saving a canvas as an image.'); 82549 * </code></div> 82550 * 82551 * <div class="norender"><code> 82552 * // Saves p5.Image as an image 82553 * img = createImage(10, 10); 82554 * save(img, 'myImage.png'); 82555 * describe('An example for saving a p5.Image element as an image.'); 82556 * </code></div> 82557 * 82558 * <div class="norender"><code> 82559 * // Saves p5.Renderer object as an image 82560 * obj = createGraphics(100, 100); 82561 * save(obj, 'myObject.png'); 82562 * describe('An example for saving a p5.Renderer element.'); 82563 * </code></div> 82564 * 82565 * <div class="norender"><code> 82566 * let myTable = new p5.Table(); 82567 * // Saves table as html file 82568 * save(myTable, 'myTable.html'); 82569 * 82570 * // Comma Separated Values 82571 * save(myTable, 'myTable.csv'); 82572 * 82573 * // Tab Separated Values 82574 * save(myTable, 'myTable.tsv'); 82575 * 82576 * describe(`An example showing how to save a table in formats of 82577 * HTML, CSV and TSV.`); 82578 * </code></div> 82579 * 82580 * <div class="norender"><code> 82581 * let myJSON = { a: 1, b: true }; 82582 * 82583 * // Saves pretty JSON 82584 * save(myJSON, 'my.json'); 82585 * 82586 * // Optimizes JSON filesize 82587 * save(myJSON, 'my.json', true); 82588 * 82589 * describe('An example for saving JSON to a txt file with some extra arguments.'); 82590 * </code></div> 82591 * 82592 * <div class="norender"><code>
82593 * // Saves array of strings to text file with line breaks after each item 82594 * let arrayOfStrings = ['a', 'b']; 82595 * save(arrayOfStrings, 'my.txt'); 82596 * describe(`An example for saving an array of strings to text file 82597 * with line breaks.`); 82598 * </code></div> 82599 */ 82600 _main.default.prototype.save = function (object, _filename, _options) { 82601 // parse the arguments and figure out which things we are saving 82602 var args = arguments; // ================================================= 82603 // OPTION 1: saveCanvas... 82604 // if no arguments are provided, save canvas 82605 var cnv = this._curElement ? this._curElement.elt : this.elt; 82606 if (args.length === 0) { 82607 _main.default.prototype.saveCanvas(cnv); 82608 return; 82609 } else if (args[0] instanceof _main.default.Renderer || args[0] instanceof _main.default.Graphics) { 82610 // otherwise, parse the arguments 82611 // if first param is a p5Graphics, then saveCanvas 82612 _main.default.prototype.saveCanvas(args[0].elt, args[1], args[2]); 82613 return; 82614 } else if (args.length === 1 && typeof args[0] === 'string') { 82615 // if 1st param is String and only one arg, assume it is canvas filename 82616 _main.default.prototype.saveCanvas(cnv, args[0]); 82617 } else { 82618 // ================================================= 82619 // OPTION 2: extension clarifies saveStrings vs. saveJSON 82620 var extension = _checkFileExtension(args[1], args[2]) [1]; 82621 switch (extension) { 82622 case 'json': 82623 _main.default.prototype.saveJSON(args[0], args[1], args[2]); 82624 return; 82625 case 'txt': 82626 _main.default.prototype.saveStrings(args[0], args[1], args[2]); 82627 return; 82628 // ================================================= 82629 // OPTION 3: decide based on object... 82630 default: 82631 if (args[0] instanceof Array) { 82632 _main.default.prototype.saveStrings(args[0], args[1], args[2]); 82633 } else if (args[0] instanceof _main.default.Table) { 82634 _main.default.prototype.saveTable(args[0], args[1], args[2]); 82635 } else if (args[0] instanceof _main.default.Image) { 82636 _main.default.prototype.saveCanvas(args[0].canvas, args[1]); 82637 } else if (args[0] instanceof _main.default.SoundFile) { 82638 _main.default.prototype.saveSound(args[0], args[1], args[2], args[3]); 82639 } 82640 } 82641 } 82642 }; 82643 /** 82644 * Writes the contents of an Array or a JSON object to a .json file. 82645 * The file saving process and location of the saved file will 82646 * vary between web browsers. 82647 * 82648 * @method saveJSON 82649 * @param {Array|Object} json 82650 * @param {String} filename 82651 * @param {Boolean} [optimize] If true, removes line breaks 82652 * and spaces from the output 82653 * file to optimize filesize 82654 * (but not readability). 82655 * @example 82656 * <div><code> 82657 * let json = {}; // new JSON Object 82658 * 82659 * json.id = 0; 82660 * json.species = 'Panthera leo'; 82661 * json.name = 'Lion'; 82662 * 82663 * function setup() { 82664 * createCanvas(100, 100); 82665 * background(200); 82666 * text('click here to save', 10, 10, 70, 80); 82667 * describe('no image displayed'); 82668 * } 82669 * 82670 * function mousePressed() { 82671 * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { 82672 * saveJSON(json, 'lion.json'); 82673 * } 82674 * } 82675 * 82676 * // saves the following to a file called "lion.json": 82677 * // { 82678 * // "id": 0, 82679 * // "species": "Panthera leo", 82680 * // "name": "Lion" 82681 * // } 82682 * </code></div> 82683 */ 82684 _main.default.prototype.saveJSON = function (json, filename, opt) { 82685 _main.default._validateParameters('saveJSON', arguments); 82686 var stringify; 82687 if (opt) { 82688 stringify = JSON.stringify(json); 82689 } else { 82690 stringify = JSON.stringify(json, undefined, 2); 82691 } 82692 this.saveStrings(stringify.split('\n'), filename, 'json'); 82693 }; 82694 _main.default.prototype.saveJSONObject = _main.default.prototype.saveJSON; 82695 _main.default.prototype.saveJSONArray = _main.default.prototype.saveJSON; 82696 /** 82697 * Writes an array of Strings to a text file, one line per String. 82698 * The file saving process and location of the saved file will 82699 * vary between web browsers. 82700 * 82701 * @method saveStrings 82702 * @param {String[]}
82702 list string array to be written 82703 * @param {String} filename filename for output 82704 * @param {String} [extension] the filename's extension 82705 * @param {Boolean} [isCRLF] if true, change line-break to CRLF 82706 * @example 82707 * <div><code> 82708 * let words = 'apple bear cat dog'; 82709 * 82710 * // .split() outputs an Array 82711 * let list = split(words, ' '); 82712 * 82713 * function setup() { 82714 * createCanvas(100, 100); 82715 * background(200); 82716 * text('click here to save', 10, 10, 70, 80); 82717 * describe('no image displayed'); 82718 * } 82719 * 82720 * function mousePressed() { 82721 * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { 82722 * saveStrings(list, 'nouns.txt'); 82723 * } 82724 * } 82725 * 82726 * // Saves the following to a file called 'nouns.txt': 82727 * // 82728 * // apple 82729 * // bear 82730 * // cat 82731 * // dog 82732 * </code></div> 82733 */ 82734 _main.default.prototype.saveStrings = function (list, filename, extension, isCRLF) { 82735 _main.default._validateParameters('saveStrings', arguments); 82736 var ext = extension || 'txt'; 82737 var pWriter = this.createWriter(filename, ext); 82738 for (var i = 0; i < list.length; i++) { 82739 isCRLF ? pWriter.write(list[i] + '\r\n') : pWriter.write(list[i] + '\n'); 82740 } 82741 pWriter.close(); 82742 pWriter.clear(); 82743 }; // ======= 82744 // HELPERS 82745 // ======= 82746 function escapeHelper(content) { 82747 return content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '''); 82748 } /** 82749 * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a 82750 * text file with comma-separated-values ('csv') but can also 82751 * use tab separation ('tsv'), or generate an HTML table ('html'). 82752 * The file saving process and location of the saved file will 82753 * vary between web browsers. 82754 * 82755 * @method saveTable 82756 * @param {p5.Table} Table the <a href="#/p5.Table">Table</a> object to save to a file 82757 * @param {String} filename the filename to which the Table should be saved 82758 * @param {String} [options] can be one of "tsv", "csv", or "html" 82759 * @example 82760 * <div><code> 82761 * let table; 82762 * 82763 * function setup() { 82764 * table = new p5.Table(); 82765 * 82766 * table.addColumn('id'); 82767 * table.addColumn('species'); 82768 * table.addColumn('name'); 82769 * 82770 * let newRow = table.addRow(); 82771 * newRow.setNum('id', table.getRowCount() - 1); 82772 * newRow.setString('species', 'Panthera leo'); 82773 * newRow.setString('name', 'Lion'); 82774 * 82775 * // To save, un-comment next line then click 'run' 82776 * // saveTable(table, 'new.csv'); 82777 * 82778 * describe('no image displayed'); 82779 * } 82780 * 82781 * // Saves the following to a file called 'new.csv': 82782 * // id,species,name 82783 * // 0,Panthera leo,Lion 82784 * </code></div> 82785 */ 82786 82787 _main.default.prototype.saveTable = function (table, filename, options) { 82788 _main.default._validateParameters('saveTable', arguments); 82789 var ext; 82790 if (options === undefined) { 82791 ext = filename.substring(filename.lastIndexOf('.') + 1, filename.length); 82792 } else { 82793 ext = options; 82794 } 82795 var pWriter = this.createWriter(filename, ext); 82796 var header = table.columns; 82797 var sep = ','; // default to CSV 82798 if (ext === 'tsv') { 82799 sep = '\t'; 82800 } 82801 if (ext !== 'html') { 82802 // make header if it has values 82803 if (header[0] !== '0') { 82804 for (var h = 0; h < header.length; h++) { 82805 if (h < header.length - 1) { 82806 pWriter.write(header[h] + sep); 82807 } else { 82808 pWriter.write(header[h]); 82809 } 82810 } 82811 pWriter.write('\n'); 82812 } // make rows 82813 82814 for (var i = 0; i < table.rows.length; i++) { 82815 var j = void 0; 82816 for (j = 0; j < table.rows[i].arr.length; j++) { 82817 if (j < table.rows[i].arr.length - 1) { 82818 //double quotes should be inserted in csv only if contains comma separated single value 82819 if (ext === 'csv' && String(table.rows[i].arr[j]).includes(',')) { 82820 pWriter.write('"' + table.rows[i].arr[j] + '"' + sep); 82821 } else { 82822 pWriter.write(table.rows[i].arr[j] + sep); 82823 } 82824 } else { 82825 //double quotes should be inserted in csv only if c
82825ontains comma separated single value 82826 if (ext === 'csv' && String(table.rows[i].arr[j]).includes(',')) { 82827 pWriter.write('"' + table.rows[i].arr[j] + '"'); 82828 } else { 82829 pWriter.write(table.rows[i].arr[j]); 82830 } 82831 } 82832 } 82833 pWriter.write('\n'); 82834 } 82835 } else { 82836 // otherwise, make HTML 82837 pWriter.print('<html>'); 82838 pWriter.print('<head>'); 82839 var str = ' <meta http-equiv="content-type" content'; 82840 str += '="text/html;charset=utf-8" />'; 82841 pWriter.print(str); 82842 pWriter.print('</head>'); 82843 pWriter.print('<body>'); 82844 pWriter.print(' <table>'); // make header if it has values 82845 if (header[0] !== '0') { 82846 pWriter.print(' <tr>'); 82847 for (var k = 0; k < header.length; k++) { 82848 var e = escapeHelper(header[k]); 82849 pWriter.print(' <td>'.concat(e)); 82850 pWriter.print(' </td>'); 82851 } 82852 pWriter.print(' </tr>'); 82853 } // make rows 82854 82855 for (var row = 0; row < table.rows.length; row++) { 82856 pWriter.print(' <tr>'); 82857 for (var col = 0; col < table.columns.length; col++) { 82858 var entry = table.rows[row].getString(col); 82859 var htmlEntry = escapeHelper(entry); 82860 pWriter.print(' <td>'.concat(htmlEntry)); 82861 pWriter.print(' </td>'); 82862 } 82863 pWriter.print(' </tr>'); 82864 } 82865 pWriter.print(' </table>'); 82866 pWriter.print('</body>'); 82867 pWriter.print('</html>'); 82868 } // close and clear the pWriter 82869 82870 pWriter.close(); 82871 pWriter.clear(); 82872 }; // end saveTable() 82873 /** 82874 * Generate a blob of file data as a url to prepare for download. 82875 * Accepts an array of data, a filename, and an extension (optional). 82876 * This is a private function because it does not do any formatting, 82877 * but it is used by <a href="#/p5/saveStrings">
82877saveStrings</a>, <a href="#/p5/saveJSON">saveJSON</a>, <a href="#/p5/saveTable">saveTable</a> etc. 82878 * 82879 * @param {Array} dataToDownload 82880 * @param {String} filename 82881 * @param {String} [extension] 82882 * @private 82883 */ 82884 _main.default.prototype.writeFile = function (dataToDownload, filename, extension) { 82885 var type = 'application/octet-stream'; 82886 if (_main.default.prototype._isSafari()) { 82887 type = 'text/plain'; 82888 } 82889 var blob = new Blob(dataToDownload, { 82890 type: type 82891 }); 82892 _main.default.prototype.downloadFile(blob, filename, extension); 82893 }; 82894 /** 82895 * Forces download. Accepts a url to filedata/blob, a filename, 82896 * and an extension (optional). 82897 * This is a private function because it does not do any formatting, 82898 * but it is used by <a href="#/p5/saveStrings">saveStrings</a>, <a href="#/p5/saveJSON">saveJSON</a>, <a href="#/p5/saveTable">saveTable</a> etc. 82899 * 82900 * @method downloadFile 82901 * @private 82902 * @param {String|Blob} data either an href generated by createObjectURL, 82903 * or a Blob object containing the data 82904 * @param {String} [filename] 82905 * @param {String} [extension] 82906 */ 82907 _main.default.prototype.downloadFile = function (data, fName, extension) { 82908 var fx = _checkFileExtension(fName, extension); 82909 var filename = fx[0]; 82910 if (data instanceof Blob) { 82911 _fileSaver.default.saveAs(data, filename); 82912 return; 82913 } 82914 var a = document.createElement('a'); 82915 a.href = data; 82916 a.download = filename; // Firefox requires the link to be added to the DOM before click() 82917 a.onclick = function (e) { 82918 destroyClickedElement(e); 82919 e.stopPropagation(); 82920 }; 82921 a.style.display = 'none'; 82922 document.body.appendChild(a); // Safari will open this file in the same page as a confusing Blob. 82923 if (_main.default.prototype._isSafari()) { 82924 var aText = 'Hello, Safari user! To download this file...\n'; 82925 aText += '1. Go to File --> Save As.\n'; 82926 aText += '2. Choose "Page Source" as the Format.\n'; 82927 aText += '3. Name it with this extension: ."'.concat(fx[1], '"'); 82928 alert(aText); 82929 } 82930 a.click(); 82931 }; 82932 /** 82933 * Returns a file extension, or another string 82934 * if the provided parameter has no extension. 82935 * 82936 * @param {String} filename 82937 * @param {String} [extension] 82938 * @return {String[]} [fileName, fileExtension] 82939 * 82940 * @private 82941 */ 82942 function _checkFileExtension(filename, extension) { 82943 if (!extension || extension === true || extension === 'true') { 82944 extension = ''; 82945 } 82946 if (!filename) { 82947 filename = 'untitled'; 82948 } 82949 var ext = ''; // make sure the file will have a name, see if filename needs extension 82950 if (filename && filename.includes('.')) { 82951 ext = filename.split('.').pop(); 82952 } // append extension if it doesn't exist 82953 82954 if (extension) { 82955 if (ext !== extension) { 82956 ext = extension; 82957 filename = ''.concat(filename, '.').concat(ext); 82958 } 82959 } 82960 return [filename, 82961 ext]; 82962 } 82963 _main.default.prototype._checkFileExtension = _checkFileExtension; 82964 /** 82965 * Returns true if the browser is Safari, false if not. 82966 * Safari makes trouble for downloading files. 82967 * 82968 * @return {Boolean} [description] 82969 * @private 82970 */ 82971 _main.default.prototype._isSafari = function () { 82972 var x = Object.prototype.toString.call(window.HTMLElement); 82973 return x.indexOf('Constructor') > 0; 82974 }; 82975 /** 82976 * Helper function, a callback for download that deletes 82977 * an invisible anchor element from the DOM once the file 82978 * has been automatically downloaded. 82979 * 82980 * @private 82981 */ 82982 function destroyClickedElement(event) { 82983 document.body.removeChild(event.target); 82984 } 82985 var _default = _main.default; 82986 exports.default = _default; 82987 }, 82988 { 82989 '../core/friendly_errors/fes_core': 281, 82990 '../core/friendly_errors/file_errors': 282, 82991 '../core/friendly_errors/validate_params': 285, 82992 '../core/main': 290,
82993 'core-js/modules/es.array.concat': 167, 82994 'core-js/modules/es.array.includes': 174, 82995 'core-js/modules/es.array.index-of': 175, 82996 'core-js/modules/es.array.iterator': 176, 82997 'core-js/modules/es.array.last-index-of': 178, 82998 'core-js/modules/es.array.slice': 180, 82999 'core-js/modules/es.array.splice': 182, 83000 'core-js/modules/es.function.name': 183, 83001 'core-js/modules/es.object.to-string': 195, 83002 'core-js/modules/es.promise': 196, 83003 'core-js/modules/es.regexp.exec': 199, 83004 'core-js/modules/es.regexp.to-string': 200, 83005 'core-js/modules/es.string.includes': 203, 83006 'core-js/modules/es.string.iterator': 204, 83007 'core-js/modules/es.string.replace': 207, 83008 'core-js/modules/es.string.split': 209, 83009 'core-js/modules/es.symbol': 214, 83010 'core-js/modules/es.symbol.description': 212, 83011 'core-js/modules/es.symbol.iterator': 213, 83012 'core-js/modules/es.typed-array.copy-within': 215, 83013 'core-js/modules/es.typed-array.every': 216, 83014 'core-js/modules/es.typed-array.fill': 217, 83015 'core-js/modules/es.typed-array.filter': 218, 83016 'core-js/modules/es.typed-array.find': 220, 83017 'core-js/modules/es.typed-array.find-index': 219, 83018 'core-js/modules/es.typed-array.for-each': 223, 83019 'core-js/modules/es.typed-array.includes': 224, 83020 'core-js/modules/es.typed-array.index-of': 225, 83021 'core-js/modules/es.typed-array.iterator': 228, 83022 'core-js/modules/es.typed-array.join': 229, 83023 'core-js/modules/es.typed-array.last-index-of': 230, 83024 'core-js/modules/es.typed-array.map': 231, 83025 'core-js/modules/es.typed-array.reduce': 233, 83026 'core-js/modules/es.typed-array.reduce-right': 232, 83027 'core-js/modules/es.typed-array.reverse': 234, 83028 'core-js/modules/es.typed-array.set': 235, 83029 'core-js/modules/es.typed-array.slice': 236, 83030 'core-js/modules/es.typed-array.some': 237, 83031 'core-js/modules/es.typed-array.sort': 238, 83032 'core-js/modules/es.typed-array.subarray': 239, 83033 'core-js/modules/es.typed-array.to-locale-string': 240, 83034 'core-js/modules/es.typed-array.to-string': 241, 83035 'core-js/modules/es.typed-array.uint8-array': 244, 83036 'core-js/modules/web.dom-collections.iterator': 248, 83037 'core-js/modules/web.url': 250, 83038 'es6-promise/auto': 251, 83039 'fetch-jsonp': 253, 83040 'file-saver': 254, 83041 'whatwg-fetch': 267 83042 } 83043 ], 83044 317: [ 83045 function (_dereq_, module, exports) { 83046 'use strict'; 83047 _dereq_('core-js/modules/es.array.concat'); 83048 _dereq_('core-js/modules/es.array.index-of'); 83049 _dereq_('core-js/modules/es.array.join'); 83050 _dereq_('core-js/modules/es.array.splice'); 83051 _dereq_('core-js/modules/es.regexp.constructor'); 83052 _dereq_('core-js/modules/es.regexp.exec'); 83053 _dereq_('core-js/modules/es.regexp.to-string'); 83054 _dereq_('core-js/modules/es.string.match'); 83055 _dereq_('core-js/modules/es.string.replace'); 83056 _dereq_('core-js/modules/es.string.trim'); 83057 _dereq_('core-js/modules/es.array.concat'); 83058 _dereq_('core-js/modules/es.array.index-of'); 83059 _dereq_('core-js/modules/es.array.join'); 83060 _dereq_('core-js/modules/es.array.splice'); 83061 _dereq_('core-js/modules/es.regexp.constructor'); 83062 _dereq_('core-js/modules/es.regexp.exec'); 83063 _dereq_('core-js/modules/es.regexp.to-string'); 83064 _dereq_('core-js/modules/es.string.match'); 83065 _dereq_('core-js/modules/es.string.replace'); 83066 _dereq_('core-js/modules/es.string.trim'); 83067 Object.defineProperty(exports, '__esModule', { 83068 value: true 83069 }); 83070 exports.default = void 0; 83071 var _main = _interopRequireDefault(_dereq_('../core/main')); 83072 function _interopRequireDefault(obj) { 83073 return obj && obj.__esModule ? obj : { 83074 default: 83075 obj 83076 }; 83077 } /** 83078 * @module IO 83079 * @submodule Table 83080 * @requires core 83081 */ 83082 /** 83083 * Table Options 83084 * Generic class for handling tabular data, typically from a 83085 * CSV, TSV, or other sort of spreadsheet file. 83086 * CSV files are 83087 * <a href="http://en.wikipedia.org/wiki/Comma-separated_values"> 83088 * comma separated values</a>, often with the data in quotes. TSV 83089 * files use tabs as separators, and usually don't bother with the 83090 * quotes. 83091 * File names should end with .csv if they're comma separated. 83092 * A rough "spec" for CSV can be found 83093 * <a href="http://tools.ietf.org/html/rfc4180">here</a>. 83094 * To load files, use the <a href="#/p5/loadTable">loadTable</a> method. 83095 * To save tables to your computer, use the <a href="#/p5/save">save</a> method 83096 * or the <a href="#/p5/saveTable">saveTable</a> method. 83097 * 83098 * Possible options include: 83099 * <ul> 83100 * <li>csv - parse the table as comma-separated values 83101 * <li>tsv - parse the table as tab-separated values 83102 * <li>header - this table has a header (title) row 83103 * </ul> 83104 */ 83105 /** 83106 * <a href="#/p5.Table">Table</a> objects store data with multiple rows and columns, much 83107 * like in a traditional spreadsheet. Tables can be generated from 83108 * scratch, dynamically, or using data from an existing file. 83109 * 83110 * @class p5.Table 83111 * @constructor 83112 * @param {p5.TableRow[]} [rows] An array of p5.TableRow objects 83113 */ 83114 83115 _main.default.Table = function (rows) { 83116 /** 83117 * An array containing the names of the columns in the table, if the "header" the table is 83118 * loaded with the "header" parameter. 83119 * @property columns {String[]} 83120 * @example 83121 * <div class="norender"> 83122 * <code> 83123 * // Given the CSV file "mammals.csv" 83124 * // in the project's "assets" folder: 83125 * // 83126 * // id,species,name 83127 * // 0,Capra hircus,Goat 83128 * // 1,Panthera pardus,Leopard 83129 * // 2,Equus zebra,Zebra 83130 * 83131 * let table; 83132 * 83133 * function preload() { 83134 * //my table is comma separated value "csv" 83135 * //and has a header specifying the columns labels 83136 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83137 * } 83138 * 83139 * function setup() { 83140 * //print the column names 83141 * for (let c = 0; c < table.getColumnCount(); c++) { 83142 * print('column ' + c + ' is named ' + table.columns[c]); 83143 * } 83144 * } 83145 * </code> 83146 * </div> 83147 */ 83148 this.columns = [ 83149 ]; 83150 /** 83151 * An array containing the <a href="#/p5.Table">p5.TableRow</a> objects that make up the 83152 * rows of the table. The same result as calling <a href="#/p5/getRows">getRows()</a> 83153 * @property rows {p5.TableRow[]} 83154 */ 83155 this.rows = [ 83156 ]; 83157 }; 83158 /** 83159 * Use <a href="#/p5/addRow">addRow()</a> to add a new row of data to a <a href="#/p5.Table">p5.Table</a> object. By default, 83160 * an empty row is created. Typically, you would store a reference to 83161 * the new row in a TableRow object (see newRow in the example above), 83162 * and then set individual values using <a href="#/p5/set">set()</a>. 83163 * 83164 * If a <a href="#/p5.TableRow">p5.TableRow</a> object is included as a parameter, then that row is 83165 * duplicated and added to the table. 83166 * 83167 * @method addRow 83168 * @param {p5.TableRow} [row] row to be added to the table 83169 * @return {p5.TableRow} the row that was added 83170 * 83171 * @example 83172 * <div class="norender"> 83173 * <code> 83174 * // Given the CSV file "mammals.csv" 83175 * // in the project's "assets" folder: 83176 * // 83177 * // id,species,name 83178 * // 0,Capra hircus,Goat 83179 * // 1,Panthera pardus,Leopard 83180 * // 2,Equus zebra,Zebra 83181 * 83182 * let table; 83183 * 83184 * function preload() { 83185 * //my table is comma separated value "csv" 83186 * //and has a header specifying the columns labels 83187 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83188 * } 83189 * 83190 * function setup() { 83191 * //add a row 83192 * let newRow = table.addRow(); 83193 * newRow.setString('id', table.getRowCount() - 1); 83194 * newRow.setString('species', 'Canis Lupus'); 83195 * newRow.setString('name', 'Wolf'); 83196 * 83197 * //print the results 83198 * for (let r = 0; r < table.getRowCount(); r++) 83199 * for (let c = 0; c < table.getColumnCount(); c++) 83200 * print(table.getString(r, c)); 83201 * 83202 * describe('no image displayed'); 83203 * } 83204 * </code> 83205 * </div> 83206 */ 83207 _main.default.Table.prototype.addRow = function (row) { 83208 // make sure it is a valid TableRow 83209 var r = row || new _main.default.TableRow(); 83210 if (typeof r.arr === 'undefined' || typeof r.obj === 'undefined') { 83211 //r = new p5.prototype.TableRow(r); 83212 throw new Error('invalid TableRow: '.concat(r)); 83213 } 83214 r.table = this; 83215 this.rows.push(r); 83216 return r; 83217 }; 83218 /** 83219 * Removes a row from the table object. 83220 * 83221 * @method removeRow 83222 * @param {Integer} id ID number of the row to remove 83223 * 83224 * @example 83225 * <div class="norender"> 83226 * <code> 83227 * // Given the CSV file "mammals.csv" 83228 * // in the project's "assets" folder: 83229 * // 83230 * // id,species,name 83231 * // 0,Capra hircus,Goat 83232 * // 1,Panthera pardus,Leopard 83233 * // 2,Equus zebra,Zebra 83234 * 83235 * let table; 83236 * 83237 * function preload() { 83238 * //my table is comma separated value "csv" 83239 * //and has a header specifying the columns labels 83240 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83241 * } 83242 * 83243 * function setup() { 83244 * //remove the first row 83245 * table.removeRow(0); 83246 * 83247 * //print the results 83248 * for (let r = 0; r < table.getRowCount(); r++) 83249 * for (let c = 0; c < table.getColumnCount(); c++) 83250 * print(table.getString(r, c)); 83251 * 83252 * describe('no image displayed'); 83253 * } 83254 * </code> 83255 * </div> 83256 */ 83257 _main.default.Table.prototype.removeRow = function (id) { 83258 this.rows[id].table = null; // remove reference to table 83259 var chunk = this.rows.splice(id + 1, this.rows.length); 83260 this.rows.pop(); 83261 this.rows = this.rows.concat(chunk); 83262 }; 83263 /** 83264 * Returns a reference to the specified <a href="#/p5.TableRow">p5.TableRow</a>. The reference 83265 * can then be used to get and set values of the selected row. 83266 * 83267 * @method getRow 83268 * @param {Integer} rowID ID number of the row to get 83269 * @return {p5.TableRow} <a href="#/p5.TableRow">p5.TableRow</a> object 83270 * 83271 * @example 83272 * <div class="norender"> 83273 * <code> 83274 * // Given the CSV file "mammals.csv" 83275 * // in the project's "assets" folder: 83276 * // 83277 * // id,species,name 83278 * // 0,Capra hircus,Goat 83279 * // 1,Panthera pardus,Leopard 83280 * // 2,Equus zebra,Zebra 83281 * 83282 * let table; 83283 * 83284 * function preload() { 83285 * //my table is comma separated value "csv" 83286 * //and has a header specifying the columns labels 83287 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83288 * } 83289 * 83290 * function setup() { 83291 * let row = table.getRow(1); 83292 * //print it column by column 83293 * //note: a row is an object, not an array 83294 * for (let c = 0; c < table.getColumnCount(); c++) { 83295 * print(row.getString(c)); 83296 * } 83297 * 83298 * describe('no image displayed'); 83299 * } 83300 * </code> 83301 * </div> 83302 */ 83303 _main.default.Table.prototype.getRow = function (r) { 83304 return this.rows[r]; 83305 }; 83306 /** 83307 * Gets all rows from the table. Returns an array of <a href="#/p5.TableRow">p5.TableRow</a>s. 83308 * 83309 * @method getRows 83310 * @return {p5.TableRow[]} Array of <a href="#/p5.TableRow">p5.TableRow</a>s 83311 * 83312 * @example 83313 * <div class="norender"> 83314 * <code> 83315 * // Given the CSV file "mammals.csv" 83316 * // in the project's "assets" folder: 83317 * // 83318 * // id,species,name 83319 * // 0,Capra hircus,Goat 83320 * // 1,Panthera pardus,Leopard 83321 * // 2,Equus zebra,Zebra 83322 * 83323 * let table; 83324 * 83325 * function preload() { 83326 * //my table is comma separated value "csv" 83327 * //and has a header specifying the columns labels 83328 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83329 * } 83330 * 83331 * function setup() { 83332 * let rows = table.getRows(); 83333 * 83334 * //warning: rows is an array of objects 83335 * for (let r = 0; r < rows.length; r++) { 83336 * rows[r].set('name', 'Unicorn'); 83337 * } 83338 * 83339 * //print the results 83340 * for (let r = 0; r < table.getRowCount(); r++) 83341 * for (let c = 0; c < table.getColumnCount(); c++) 83342 * print(table.getString(r, c)); 83343 * 83344 * describe('no image displayed'); 83345 * } 83346 * </code> 83347 * </div> 83348 */ 83349 _main.default.Table.prototype.getRows = function () { 83350 return this.rows; 83351 }; 83352 /** 83353 * Finds the first row in the Table that contains the value 83354 * provided, and returns a reference to that row. Even if 83355 * multiple rows are possible matches, only the first matching 83356 * row is returned. The column to search may be specified by 83357 * either its ID or title. 83358 * 83359 * @method findRow 83360 * @param {String} value The value to match 83361 * @param {Integer|String} column ID number or title of the 83362 * column to search 83363 * @return {p5.TableRow} 83364 * 83365 * @example 83366 * <div class="norender"> 83367 * <code> 83368 * // Given the CSV file "mammals.csv" 83369 * // in the project's "assets" folder: 83370 * // 83371 * // id,species,name 83372 * // 0,Capra hircus,Goat 83373 * // 1,Panthera pardus,Leopard 83374 * // 2,Equus zebra,Zebra 83375 * 83376 * let table; 83377 * 83378 * function preload() { 83379 * //my table is comma separated value "csv" 83380 * //and has a header specifying the columns labels 83381 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83382 * } 83383 * 83384 * function setup() { 83385 * //find the animal named zebra 83386 * let row = table.findRow('Zebra', 'name'); 83387 * //find the corresponding species 83388 * print(row.getString('species')); 83389 * describe('no image displayed'); 83390 * } 83391 * </code> 83392 * </div> 83393 */ 83394 _main.default.Table.prototype.findRow = function (value, column) { 83395 // try the Object 83396 if (typeof column === 'string') { 83397 for (var i = 0; i < this.rows.length; i++) { 83398 if (this.rows[i].obj[column] === value) { 83399 return this.rows[i]; 83400 } 83401 } 83402 } else { 83403 // try the Array 83404 for (var j = 0; j < this.rows.length; j++) { 83405 if (this.rows[j].arr[column] === value) { 83406 return this.rows[j]; 83407 } 83408 } 83409 } // otherwise... 83410 83411 return null; 83412 }; 83413 /** 83414 * Finds the rows in the Table that contain the value 83415 * provided, and returns references to those rows. Returns an 83416 * Array, so for must be used to iterate through all the rows, 83417 * as shown in the example above. The column to search may be 83418 * specified by either its ID or title. 83419 * 83420 * @method findRows 83421 * @param {String} value The value to match 83422 * @param {Integer|String} column ID number or title of the 83423 * column to search 83424 * @return {p5.TableRow[]} An Array of TableRow objects 83425 * 83426 * @example 83427 * <div class="norender"> 83428 * <code> 83429 * // Given the CSV file "mammals.csv" 83430 * // in the project's "assets" folder: 83431 * // 83432 * // id,species,name 83433 * // 0,Capra hircus,Goat 83434 * // 1,Panthera pardus,Leopard 83435 * // 2,Equus zebra,Zebra 83436 * 83437 * let table; 83438 * 83439 * function preload() { 83440 * //my table is comma separated value "csv" 83441 * //and has a header specifying the columns labels 83442 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83443 * } 83444 * 83445 * function setup() { 83446 * //add another goat 83447 * let newRow = table.addRow(); 83448 * newRow.setString('id', table.getRowCount() - 1); 83449 * newRow.setString('species', 'Scape Goat'); 83450 * newRow.setString('name', 'Goat'); 83451 * 83452 * //find the rows containing animals named Goat 83453 * let rows = table.findRows('Goat', 'name'); 83454 * print(rows.length + ' Goats found'); 83455 * describe('no image displayed'); 83456 * } 83457 * </code> 83458 * </div> 83459 */ 83460 _main.default.Table.prototype.findRows = function (value, column) { 83461 var ret = [ 83462 ]; 83463 if (typeof column === 'string') { 83464 for (var i = 0; i < this.rows.length; i++) { 83465 if (this.rows[i].obj[column] === value) {
83466 ret.push(this.rows[i]); 83467 } 83468 } 83469 } else { 83470 // try the Array 83471 for (var j = 0; j < this.rows.length; j++) { 83472 if (this.rows[j].arr[column] === value) { 83473 ret.push(this.rows[j]); 83474 } 83475 } 83476 } 83477 return ret; 83478 }; 83479 /** 83480 * Finds the first row in the Table that matches the regular 83481 * expression provided, and returns a reference to that row. 83482 * Even if multiple rows are possible matches, only the first 83483 * matching row is returned. The column to search may be 83484 * specified by either its ID or title. 83485 * 83486 * @method matchRow 83487 * @param {String|RegExp} regexp The regular expression to match 83488 * @param {String|Integer} column The column ID (number) or 83489 * title (string) 83490 * @return {p5.TableRow} TableRow object 83491 * 83492 * @example 83493 * <div class="norender"> 83494 * <code> 83495 * // Given the CSV file "mammals.csv" 83496 * // in the project's "assets" folder: 83497 * // 83498 * // id,species,name 83499 * // 0,Capra hircus,Goat 83500 * // 1,Panthera pardus,Leopard 83501 * // 2,Equus zebra,Zebra 83502 * 83503 * let table; 83504 * 83505 * function preload() { 83506 * //my table is comma separated value "csv" 83507 * //and has a header specifying the columns labels 83508 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83509 * } 83510 * 83511 * function setup() { 83512 * //Search using specified regex on a given column, return TableRow object 83513 * let mammal = table.matchRow(new RegExp('ant'), 1); 83514 * print(mammal.getString(1)); 83515 * //Output "Panthera pardus" 83516 * } 83517 * </code> 83518 * </div> 83519 */ 83520 _main.default.Table.prototype.matchRow = function (regexp, column) { 83521 if (typeof column === 'number') { 83522 for (var j = 0; j < this.rows.length; j++) { 83523 if (this.rows[j].arr[column].match(regexp)) { 83524 return this.rows[j]; 83525 } 83526 } 83527 } else { 83528 for (var i = 0; i < this.rows.length; i++) { 83529 if (this.rows[i].obj[column].match(regexp)) { 83530 return this.rows[i]; 83531 } 83532 } 83533 } 83534 return null; 83535 }; 83536 /** 83537 * Finds the rows in the Table that match the regular expression provided, 83538 * and returns references to those rows. Returns an array, so for must be 83539 * used to iterate through all the rows, as shown in the example. The 83540 * column to search may be specified by either its ID or title. 83541 * 83542 * @method matchRows 83543 * @param {String} regexp The regular expression to match 83544 * @param {String|Integer} [column] The column ID (number) or 83545 * title (string) 83546 * @return {p5.TableRow[]} An Array of TableRow objects 83547 * @example 83548 * <div class="norender"> 83549 * <code> 83550 * let table; 83551 * 83552 * function setup() { 83553 * table = new p5.Table(); 83554 * 83555 * table.addColumn('name'); 83556 * table.addColumn('type'); 83557 * 83558 * let newRow = table.addRow(); 83559 * newRow.setString('name', 'Lion'); 83560 * newRow.setString('type', 'Mammal'); 83561 * 83562 * newRow = table.addRow(); 83563 * newRow.setString('name', 'Snake'); 83564 * newRow.setString('type', 'Reptile'); 83565 * 83566 * newRow = table.addRow(); 83567 * newRow.setString('name', 'Mosquito'); 83568 * newRow.setString('type', 'Insect'); 83569 * 83570 * newRow = table.addRow(); 83571 * newRow.setString('name', 'Lizard'); 83572 * newRow.setString('type', 'Reptile'); 83573 * 83574 * let rows = table.matchRows('R.*', 'type'); 83575 * for (let i = 0; i < rows.length; i++) { 83576 * print(rows[i].getString('name') + ': ' + rows[i].getString('type')); 83577 * } 83578 * } 83579 * // Sketch prints: 83580 * // Snake: Reptile 83581 * // Lizard: Reptile 83582 * </code> 83583 * </div> 83584 */ 83585 _main.default.Table.prototype.matchRows = function (regexp, column) { 83586 var ret = [ 83587 ]; 83588 if (typeof column === 'number') { 83589 for (var j = 0; j < this.rows.length; j++) { 83590 if (this.rows[j].arr[column].match(regexp)) { 83591 ret.push(this.rows[j]); 83592 } 83593 } 83594 } else { 83595 for (var i = 0; i < this.rows.length; i++) { 83596 if (this.rows[i].obj[column].match(regexp)) {
83597 ret.push(this.rows[i]); 83598 } 83599 } 83600 } 83601 return ret; 83602 }; 83603 /** 83604 * Retrieves all values in the specified column, and returns them 83605 * as an array. The column may be specified by either its ID or title. 83606 * 83607 * @method getColumn 83608 * @param {String|Number} column String or Number of the column to return 83609 * @return {Array} Array of column values 83610 * 83611 * @example 83612 * <div class="norender"> 83613 * <code> 83614 * // Given the CSV file "mammals.csv" 83615 * // in the project's "assets" folder: 83616 * // 83617 * // id,species,name 83618 * // 0,Capra hircus,Goat 83619 * // 1,Panthera pardus,Leopard 83620 * // 2,Equus zebra,Zebra 83621 * 83622 * let table; 83623 * 83624 * function preload() { 83625 * //my table is comma separated value "csv" 83626 * //and has a header specifying the columns labels 83627 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83628 * } 83629 * 83630 * function setup() { 83631 * //getColumn returns an array that can be printed directly 83632 * print(table.getColumn('species')); 83633 * //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"] 83634 * describe('no image displayed'); 83635 * } 83636 * </code> 83637 * </div> 83638 */ 83639 _main.default.Table.prototype.getColumn = function (value) { 83640 var ret = [ 83641 ]; 83642 if (typeof value === 'string') { 83643 for (var i = 0; i < this.rows.length; i++) { 83644 ret.push(this.rows[i].obj[value]); 83645 } 83646 } else { 83647 for (var j = 0; j < this.rows.length; j++) { 83648 ret.push(this.rows[j].arr[value]); 83649 } 83650 } 83651 return ret; 83652 }; 83653 /** 83654 * Removes all rows from a Table. While all rows are removed, 83655 * columns and column titles are maintained. 83656 * 83657 * @method clearRows 83658 * 83659 * @example 83660 * <div class="norender"> 83661 * <code> 83662 * // Given the CSV file "mammals.csv" 83663 * // in the project's "assets" folder: 83664 * // 83665 * // id,species,name 83666 * // 0,Capra hircus,Goat 83667 * // 1,Panthera pardus,Leopard 83668 * // 2,Equus zebra,Zebra 83669 * 83670 * let table; 83671 * 83672 * function preload() { 83673 * //my table is comma separated value "csv" 83674 * //and has a header specifying the columns labels 83675 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83676 * } 83677 * 83678 * function setup() { 83679 * table.clearRows(); 83680 * print(table.getRowCount() + ' total rows in table'); 83681 * print(table.getColumnCount() + ' total columns in table'); 83682 * describe('no image displayed'); 83683 * } 83684 * </code> 83685 * </div> 83686 */ 83687 _main.default.Table.prototype.clearRows = function () { 83688 delete this.rows; 83689 this.rows = [ 83690 ]; 83691 }; 83692 /** 83693 * Use <a href="#/p5/addColumn">addColumn()</a> to add a new column to a <a href="#/p5.Table">Table</a> object. 83694 * Typically, you will want to specify a title, so the column 83695 * may be easily referenced later by name. (If no title is 83696 * specified, the new column's title will be null.) 83697 * 83698 * @method addColumn 83699 * @param {String} [title] title of the given column 83700 * 83701 * @example 83702 * <div class="norender"> 83703 * <code> 83704 * // Given the CSV file "mammals.csv" 83705 * // in the project's "assets" folder: 83706 * // 83707 * // id,species,name 83708 * // 0,Capra hircus,Goat 83709 * // 1,Panthera pardus,Leopard 83710 * // 2,Equus zebra,Zebra 83711 * 83712 * let table; 83713 * 83714 * function preload() { 83715 * //my table is comma separated value "csv" 83716 * //and has a header specifying the columns labels 83717 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83718 * } 83719 * 83720 * function setup() { 83721 * table.addColumn('carnivore'); 83722 * table.set(0, 'carnivore', 'no'); 83723 * table.set(1, 'carnivore', 'yes'); 83724 * table.set(2, 'carnivore', 'no'); 83725 * 83726 * //print the results 83727 * for (let r = 0; r < table.getRowCount(); r++) 83728 * for (let c = 0; c < table.getColumnCount(); c++) 83729 * print(table.getString(r, c)); 83730 * 83731 * describe('no image displayed'); 83732 * } 83733 * </code> 83734 * </div> 83735 */ 83736 _main.default.Table.prototype.addColumn = function (title) { 83737 var t = title || null; 83738 this.columns.push(t); 83739 }; 83740 /** 83741 * Returns the total number of columns in a Table. 83742 * 83743 * @method getColumnCount 83744 * @return {Integer} Number of columns in this table 83745 * @example 83746 * <div> 83747 * <code> 83748 * // given the cvs file "blobs.csv" in /assets directory 83749 * // ID, Name, Flavor, Shape, Color 83750 * // Blob1, Blobby, Sweet, Blob, Pink 83751 * // Blob2, Saddy, Savory, Blob, Blue 83752 * 83753 * let table; 83754 * 83755 * function preload() { 83756 * table = loadTable('assets/blobs.csv'); 83757 * } 83758 * 83759 * function setup() { 83760 * createCanvas(200, 100); 83761 * textAlign(CENTER); 83762 * background(255); 83763 * } 83764 * 83765 * function draw() { 83766 * let numOfColumn = table.getColumnCount(); 83767 * text('There are ' + numOfColumn + ' columns in the table.', 100, 50); 83768 * } 83769 * </code> 83770 * </div> 83771 */ 83772 _main.default.Table.prototype.getColumnCount = function () { 83773 return this.columns.length; 83774 }; 83775 /** 83776 * Returns the total number of rows in a Table. 83777 * 83778 * @method getRowCount 83779 * @return {Integer} Number of rows in this table 83780 * @example 83781 * <div> 83782 * <code> 83783 * // given the cvs file "blobs.csv" in /assets directory 83784 * // 83785 * // ID, Name, Flavor, Shape, Color 83786 * // Blob1, Blobby, Sweet, Blob, Pink 83787 * // Blob2, Saddy, Savory, Blob, Blue 83788 * 83789 * let table; 83790 * 83791 * function preload() { 83792 * table = loadTable('assets/blobs.csv'); 83793 * } 83794 * 83795 * function setup() { 83796 * createCanvas(200, 100); 83797 * textAlign(CENTER); 83798 * background(255); 83799 * } 83800 * 83801 * function draw() { 83802 * text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50); 83803 * } 83804 * </code> 83805 * </div> 83806 */ 83807 _main.default.Table.prototype.getRowCount = function () { 83808 return this.rows.length; 83809 }; 83810 /** 83811 * Removes any of the specified characters (or "tokens"). 83812 * 83813 * If no column is specified, then the values in all columns and 83814 * rows are processed. A specific column may be referenced by 83815 * either its ID or title. 83816 * 83817 * @method removeTokens 83818 * @param {String} chars String listing characters to be removed 83819 * @param {String|Integer} [column] Column ID (number) 83820 * or name (string) 83821 * 83822 * @example 83823 * <div class="norender"><code> 83824 * function setup() { 83825 * let table = new p5.Table(); 83826 * 83827 * table.addColumn('name'); 83828 * table.addColumn('type'); 83829 * 83830 * let newRow = table.addRow(); 83831 * newRow.setString('name', ' $Lion ,'); 83832 * newRow.setString('type', ',,,Mammal'); 83833 * 83834 * newRow = table.addRow(); 83835 * newRow.setString('name', '$Snake '); 83836 * newRow.setString('type', ',,,Reptile'); 83837 * 83838 * table.removeTokens(',$ '); 83839 * print(table.getArray()); 83840 * } 83841 * 83842 * // prints:
83843 * // 0 "Lion" "Mamal" 83844 * // 1 "Snake" "Reptile" 83845 * </code></div> 83846 */ 83847 _main.default.Table.prototype.removeTokens = function (chars, column) { 83848 var escape = function escape(s) { 83849 return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); 83850 }; 83851 var charArray = [ 83852 ]; 83853 for (var i = 0; i < chars.length; i++) { 83854 charArray.push(escape(chars.charAt(i))); 83855 } 83856 var regex = new RegExp(charArray.join('|'), 'g'); 83857 if (typeof column === 'undefined') { 83858 for (var c = 0; c < this.columns.length; c++) { 83859 for (var d = 0; d < this.rows.length; d++) { 83860 var s = this.rows[d].arr[c]; 83861 s = s.replace(regex, ''); 83862 this.rows[d].arr[c] = s; 83863 this.rows[d].obj[this.columns[c]] = s; 83864 } 83865 } 83866 } else if (typeof column === 'string') { 83867 for (var j = 0; j < this.rows.length; j++) { 83868 var val = this.rows[j].obj[column]; 83869 val = val.replace(regex, ''); 83870 this.rows[j].obj[column] = val; 83871 var pos = this.columns.indexOf(column); 83872 this.rows[j].arr[pos] = val; 83873 } 83874 } else { 83875 for (var k = 0; k < this.rows.length; k++) { 83876 var str = this.rows[k].arr[column]; 83877 str = str.replace(regex, ''); 83878 this.rows[k].arr[column] = str; 83879 this.rows[k].obj[this.columns[column]] = str; 83880 } 83881 } 83882 }; 83883 /** 83884 * Trims leading and trailing whitespace, such as spaces and tabs, 83885 * from String table values. If no column is specified, then the 83886 * values in all columns and rows are trimmed. A specific column 83887 * may be referenced by either its ID or title. 83888 * 83889 * @method trim 83890 * @param {String|Integer} [column] Column ID (number) 83891 * or name (string) 83892 * @example 83893 * <div class="norender"><code> 83894 * function setup() { 83895 * let table = new p5.Table(); 83896 * 83897 * table.addColumn('name'); 83898 * table.addColumn('type'); 83899 * 83900 * let newRow = table.addRow(); 83901 * newRow.setString('name', ' Lion ,'); 83902 * newRow.setString('type', ' Mammal '); 83903 * 83904 * newRow = table.addRow(); 83905 * newRow.setString('name', ' Snake '); 83906 * newRow.setString('type', ' Reptile '); 83907 * 83908 * table.trim(); 83909 * print(table.getArray()); 83910 * } 83911 * 83912 * // prints: 83913 * // 0 "Lion" "Mamal" 83914 * // 1 "Snake" "Reptile" 83915 * </code></div> 83916 */ 83917 _main.default.Table.prototype.trim = function (column) { 83918 var regex = new RegExp(' ', 'g'); 83919 if (typeof column === 'undefined') { 83920 for (var c = 0; c < this.columns.length; c++) { 83921 for (var d = 0; d < this.rows.length; d++) { 83922 var s = this.rows[d].arr[c]; 83923 s = s.replace(regex, ''); 83924 this.rows[d].arr[c] = s; 83925 this.rows[d].obj[this.columns[c]] = s; 83926 } 83927 } 83928 } else if (typeof column === 'string') { 83929 for (var j = 0; j < this.rows.length; j++) { 83930 var val = this.rows[j].obj[column]; 83931 val = val.replace(regex, ''); 83932 this.rows[j].obj[column] = val; 83933 var pos = this.columns.indexOf(column); 83934 this.rows[j].arr[pos] = val; 83935 } 83936 } else { 83937 for (var k = 0; k < this.rows.length; k++) { 83938 var str = this.rows[k].arr[column]; 83939 str = str.replace(regex, ''); 83940 this.rows[k].arr[column] = str; 83941 this.rows[k].obj[this.columns[column]] = str; 83942 } 83943 } 83944 }; 83945 /** 83946 * Use <a href="#/p5/removeColumn">removeColumn()</a> to remove an existing column from a Table 83947 * object. The column to be removed may be identified by either 83948 * its title (a String) or its index value (an int). 83949 * removeColumn(0) would remove the first column, removeColumn(1) 83950 * would remove the second column, and so on. 83951 * 83952 * @method removeColumn 83953 * @param {String|Integer} column columnName (string) or ID (number) 83954 * 83955 * @example 83956 * <div class="norender"> 83957 * <code> 83958 * // Given the CSV file "mammals.csv" 83959 * // in the project's "assets" folder: 83960 * // 83961 * // id,species,name 83962 * // 0,Capra hircus,Goat 83963 * // 1,Panthera pardus,Leopard 83964 * // 2,Equus zebra,Zebra 83965 * 83966 * let table; 83967 * 83968 * function preload() { 83969 * //my table is comma separated value "csv" 83970 * //and has a header specifying the columns labels 83971 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 83972 * } 83973 * 83974 * function setup() { 83975 * table.removeColumn('id'); 83976 * print(table.getColumnCount()); 83977 * describe('no image displayed'); 83978 * } 83979 * </code> 83980 * </div> 83981 */ 83982 _main.default.Table.prototype.removeColumn = function (c) { 83983 var cString; 83984 var cNumber; 83985 if (typeof c === 'string') { 83986 // find the position of c in the columns 83987 cString = c; 83988 cNumber = this.columns.indexOf(c); 83989 } else { 83990 cNumber = c; 83991 cString = this.columns[c]; 83992 } 83993 var chunk = this.columns.splice(cNumber + 1, this.columns.length); 83994 this.columns.pop(); 83995 this.columns = this.columns.concat(chunk); 83996 for (var i = 0; i < this.rows.length; i++) { 83997 var tempR = this.rows[i].arr; 83998 var chip = tempR.splice(cNumber + 1, tempR.length); 83999 tempR.pop(); 84000 this.rows[i].arr = tempR.concat(chip); 84001 delete this.rows[i].obj[cString]; 84002 } 84003 }; 84004 /** 84005 * Stores a value in the Table's specified row and column. 84006 * The row is specified by its ID, while the column may be specified 84007 * by either its ID or title. 84008 * 84009 * @method set 84010 * @param {Integer} row row ID 84011 * @param {String|Integer} column column ID (Number) 84012 * or title (String) 84013 * @param {String|Number} value value to assign 84014 * 84015 * @example 84016 * <div class="norender"> 84017 * <code> 84018 * // Given the CSV file "mammals.csv" 84019 * // in the project's "assets" folder: 84020 * // 84021 * // id,species,name 84022 * // 0,Capra hircus,Goat 84023 * // 1,Panthera pardus,Leopard 84024 * // 2,Equus zebra,Zebra 84025 * 84026 * let table; 84027 * 84028 * function preload() { 84029 * //my table is comma separated value "csv" 84030 * //and has a header specifying the columns labels 84031 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84032 * } 84033 * 84034 * function setup() { 84035 * table.set(0, 'species', 'Canis Lupus'); 84036 * table.set(0, 'name', 'Wolf'); 84037 * 84038 * //print the results 84039 * for (let r = 0; r < table.getRowCount(); r++) 84040 * for (let c = 0; c < table.getColumnCount(); c++) 84041 * print(table.getString(r, c)); 84042 * 84043 * describe('no image displayed'); 84044 * } 84045 * </code> 84046 * </div> 84047 */ 84048 _main.default.Table.prototype.set = function (row, column, value) { 84049 this.rows[row].set(column, value); 84050 }; 84051 /** 84052 * Stores a Float value in the Table's specified row and column. 84053 * The row is specified by its ID, while the column may be specified 84054 * by either its ID or title. 84055 * 84056 * @method setNum 84057 * @param {Integer} row row ID 84058 * @param {String|Integer} column column ID (Number) 84059 * or title (String) 84060 * @param {Number} value value to assign 84061 * 84062 * @example 84063 * <div class="norender"> 84064 * <code> 84065 * // Given the CSV file "mammals.csv" 84066 * // in the project's "assets" folder: 84067 * // 84068 * // id,species,name 84069 * // 0,Capra hircus,Goat 84070 * // 1,Panthera pardus,Leopard 84071 * // 2,Equus zebra,Zebra 84072 * 84073 * let table; 84074 * 84075 * function preload() { 84076 * //my table is comma separated value "csv" 84077 * //and has a header specifying the columns labels 84078 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84079 * } 84080 * 84081 * function setup() { 84082 * table.setNum(1, 'id', 1); 84083 * 84084 * print(table.getColumn(0)); 84085 * //["0", 1, "2"] 84086 * 84087 * describe('no image displayed'); 84088 * } 84089 * </code> 84090 * </div> 84091 */ 84092 _main.default.Table.prototype.setNum = function (row, column, value) { 84093 this.rows[row].setNum(column, value); 84094 }; 84095 /** 84096 * Stores a String value in the Table's specified row and column. 84097 * The row is specified by its ID, while the column may be specified 84098 * by either its ID or title. 84099 * 84100 * @method setString 84101 * @param {Integer} row row ID 84102 * @param {String|Integer} column column ID (Number) 84103 * or title (String) 84104 * @param {String} value value to assign 84105 * @example 84106 * <div class="norender"><code> 84107 * // Given the CSV file "mammals.csv" in the project's "assets" folder: 84108 * // 84109 * // id,species,name 84110 * // 0,Capra hircus,Goat 84111 * // 1,Panthera pardus,Leopard 84112 * // 2,Equus zebra,Zebra 84113 * 84114 * let table; 84115 * 84116 * function preload() { 84117 * //my table is comma separated value "csv" 84118 * //and has a header specifying the columns labels 84119 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84120 * } 84121 * 84122 * function setup() { 84123 * //add a row 84124 * let newRow = table.addRow(); 84125 * newRow.setString('id', table.getRowCount() - 1); 84126 * newRow.setString('species', 'Canis Lupus'); 84127 * newRow.setString('name', 'Wolf'); 84128 * 84129 * print(table.getArray()); 84130 * 84131 * describe('no image displayed'); 84132 * } 84133 * </code></div> 84134 */ 84135 _main.default.Table.prototype.setString = function (row, column, value) { 84136 this.rows[row].setString(column, value); 84137 }; 84138 /** 84139 * Retrieves a value from the Table's specified row and column. 84140 * The row is specified by its ID, while the column may be specified by 84141 * either its ID or title. 84142 * 84143 * @method get 84144 * @param {Integer} row row ID 84145 * @param {String|Integer} column columnName (string) or 84146 * ID (number) 84147 * @return {String|Number} 84148 * 84149 * @example 84150 * <div class="norender"> 84151 * <code> 84152 * // Given the CSV file "mammals.csv" 84153 * // in the project's "assets" folder: 84154 * // 84155 * // id,species,name 84156 * // 0,Capra hircus,Goat 84157 * // 1,Panthera pardus,Leopard 84158 * // 2,Equus zebra,Zebra 84159 * 84160 * let table; 84161 * 84162 * function preload() { 84163 * //my table is comma separated value "csv" 84164 * //and has a header specifying the columns labels 84165 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84166 * } 84167 * 84168 * function setup() { 84169 * print(table.get(0, 1)); 84170 * //Capra hircus 84171 * print(table.get(0, 'species')); 84172 * //Capra hircus 84173 * describe('no image displayed'); 84174 * } 84175 * </code> 84176 * </div> 84177 */ 84178 _main.default.Table.prototype.get = function (row, column) { 84179 return this.rows[row].get(column); 84180 }; 84181 /** 84182 * Retrieves a Float value from the Table's specified row and column. 84183 * The row is specified by its ID, while the column may be specified by 84184 * either its ID or title. 84185 * 84186 * @method getNum 84187 * @param {Integer} row row ID 84188 * @param {String|Integer} column columnName (string) or 84189 * ID (number) 84190 * @return {Number} 84191 * 84192 * @example 84193 * <div class="norender"> 84194 * <code> 84195 * // Given the CSV file "mammals.csv" 84196 * // in the project's "assets" folder: 84197 * // 84198 * // id,species,name 84199 * // 0,Capra hircus,Goat 84200 * // 1,Panthera pardus,Leopard 84201 * // 2,Equus zebra,Zebra 84202 * 84203 * let table; 84204 * 84205 * function preload() { 84206 * //my table is comma separated value "csv" 84207 * //and has a header specifying the columns labels 84208 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84209 * } 84210 * 84211 * function setup() { 84212 * print(table.getNum(1, 0) + 100); 84213 * //id 1 + 100 = 101 84214 * describe('no image displayed'); 84215 * } 84216 * </code> 84217 * </div> 84218 */ 84219 _main.default.Table.prototype.getNum = function (row, column) { 84220 return this.rows[row].getNum(column); 84221 }; 84222 /** 84223 * Retrieves a String value from the Table's specified row and column. 84224 * The row is specified by its ID, while the column may be specified by 84225 * either its ID or title. 84226 * 84227 * @method getString 84228 * @param {Integer} row row ID 84229 * @param {String|Integer} column columnName (string) or 84230 * ID (number) 84231 * @return {String} 84232 * 84233 * @example 84234 * <div class="norender"> 84235 * <code> 84236 * // Given the CSV file "mammals.csv" 84237 * // in the project's "assets" folder: 84238 * // 84239 * // id,species,name 84240 * // 0,Capra hircus,Goat 84241 * // 1,Panthera pardus,Leopard 84242 * // 2,Equus zebra,Zebra 84243 * 84244 * let table; 84245 * 84246 * function preload() { 84247 * // table is comma separated value "CSV" 84248 * // and has specifiying header for column labels 84249 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84250 * } 84251 * 84252 * function setup() { 84253 * print(table.getString(0, 0)); // 0 84254 * print(table.getString(0, 1)); // Capra hircus 84255 * print(table.getString(0, 2)); // Goat 84256 * print(table.getString(1, 0)); // 1 84257 * print(table.getString(1, 1)); // Panthera pardus 84258 * print(table.getString(1, 2)); // Leopard 84259 * print(table.getString(2, 0)); // 2 84260 * print(table.getString(2, 1)); // Equus zebra 84261 * print(table.getString(2, 2)); // Zebra 84262 * describe('no image displayed'); 84263 * } 84264 * </code> 84265 * </div> 84266 */ 84267 _main.default.Table.prototype.getString = function (row, column) { 84268 return this.rows[row].getString(column); 84269 }; 84270 /** 84271 * Retrieves all table data and returns as an object. If a column name is 84272 * passed in, each row object will be stored with that attribute as its 84273 * title. 84274 * 84275 * @method getObject 84276 * @param {String} [headerColumn] Name of the column which should be used to 84277 * title each row object (optional) 84278 * @return {Object} 84279 * 84280 * @example 84281 * <div class="norender"> 84282 * <code> 84283 * // Given the CSV file "mammals.csv" 84284 * // in the project's "assets" folder: 84285 * // 84286 * // id,species,name 84287 * // 0,Capra hircus,Goat 84288 * // 1,Panthera pardus,Leopard 84289 * // 2,Equus zebra,Zebra 84290 * 84291 * let table; 84292 * 84293 * function preload() { 84294 * //my table is comma separated value "csv" 84295 * //and has a header specifying the columns labels 84296 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84297 * } 84298 * 84299 * function setup() { 84300 * let tableObject = table.getObject(); 84301 * 84302 * print(tableObject); 84303 * //outputs an object 84304 * 84305 * describe('no image displayed'); 84306 * } 84307 * </code> 84308 * </div> 84309 */ 84310 _main.default.Table.prototype.getObject = function (headerColumn) { 84311 var tableObject = { 84312 }; 84313 var obj, 84314 cPos, 84315 index; 84316 for (var i = 0; i < this.rows.length; i++) { 84317 obj = this.rows[i].obj; 84318 if (typeof headerColumn === 'string') { 84319 cPos = this.columns.indexOf(headerColumn); // index of columnID 84320 if (cPos >= 0) { 84321 index = obj[headerColumn]; 84322 tableObject[index] = obj; 84323 } else { 84324 throw new Error('This table has no column named "'.concat(headerColumn, '"')); 84325 } 84326 } else { 84327 tableObject[i] = this.rows[i].obj; 84328 } 84329 } 84330 return tableObject; 84331 }; 84332 /** 84333 * Retrieves all table data and returns it as a multidimensional array. 84334 * 84335 * @method getArray 84336 * @return {Array} 84337 * 84338 * @example 84339 * <div class="norender"> 84340 * <code> 84341 * // Given the CSV file "mammals.csv" 84342 * // in the project's "assets" folder 84343 * // 84344 * // id,species,name 84345 * // 0,Capra hircus,Goat 84346 * // 1,Panthera pardus,Leoperd 84347 * // 2,Equus zebra,Zebra 84348 * 84349 * let table; 84350 * 84351 * function preload() { 84352 * // table is comma separated value "CSV" 84353 * // and has specifiying header for column labels 84354 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84355 * } 84356 * 84357 * function setup() { 84358 * let tableArray = table.getArray(); 84359 * for (let i = 0; i < tableArray.length; i++) { 84360 * print(tableArray[i]); 84361 * } 84362 * describe('no image displayed'); 84363 * } 84364 * </code> 84365 * </div> 84366 */ 84367 _main.default.Table.prototype.getArray = function () { 84368 var tableArray = [ 84369 ]; 84370 for (var i = 0; i < this.rows.length; i++) { 84371 tableArray.push(this.rows[i].arr); 84372 } 84373 return tableArray; 84374 }; 84375 var _default = _main.default; 84376 exports.default = _default; 84377 }, 84378 { 84379 '../core/main': 290,
84380 'core-js/modules/es.array.concat': 167, 84381 'core-js/modules/es.array.index-of': 175, 84382 'core-js/modules/es.array.join': 177, 84383 'core-js/modules/es.array.splice': 182, 84384 'core-js/modules/es.regexp.constructor': 198, 84385 'core-js/modules/es.regexp.exec': 199, 84386 'core-js/modules/es.regexp.to-string': 200, 84387 'core-js/modules/es.string.match': 205, 84388 'core-js/modules/es.string.replace': 207, 84389 'core-js/modules/es.string.trim': 211 84390 } 84391 ], 84392 318: [ 84393 function (_dereq_, module, exports) { 84394 'use strict'; 84395 _dereq_('core-js/modules/es.array.index-of'); 84396 _dereq_('core-js/modules/es.object.to-string'); 84397 _dereq_('core-js/modules/es.regexp.exec'); 84398 _dereq_('core-js/modules/es.regexp.to-string'); 84399 _dereq_('core-js/modules/es.string.split'); 84400 _dereq_('core-js/modules/es.array.index-of'); 84401 _dereq_('core-js/modules/es.object.to-string'); 84402 _dereq_('core-js/modules/es.regexp.exec'); 84403 _dereq_('core-js/modules/es.regexp.to-string'); 84404 _dereq_('core-js/modules/es.string.split'); 84405 Object.defineProperty(exports, '__esModule', { 84406 value: true 84407 }); 84408 exports.default = void 0; 84409 var _main = _interopRequireDefault(_dereq_('../core/main')); 84410 function _interopRequireDefault(obj) { 84411 return obj && obj.__esModule ? obj : { 84412 default: 84413 obj 84414 }; 84415 } /** 84416 * @module IO 84417 * @submodule Table 84418 * @requires core 84419 */ 84420 /** 84421 * A TableRow object represents a single row of data values, 84422 * stored in columns, from a table. 84423 * 84424 * A Table Row contains both an ordered array, and an unordered 84425 * JSON object. 84426 * 84427 * @class p5.TableRow 84428 * @constructor 84429 * @param {String} [str] optional: populate the row with a 84430 * string of values, separated by the 84431 * separator 84432 * @param {String} [separator] comma separated values (csv) by default 84433 */ 84434 84435 _main.default.TableRow = function (str, separator) { 84436 var arr = [ 84437 ]; 84438 var obj = { 84439 }; 84440 if (str) { 84441 separator = separator || ','; 84442 arr = str.split(separator); 84443 } 84444 for (var i = 0; i < arr.length; i++) { 84445 var key = i; 84446 var val = arr[i]; 84447 obj[key] = val; 84448 } 84449 this.arr = arr; 84450 this.obj = obj; 84451 this.table = null; 84452 }; 84453 /** 84454 * Stores a value in the TableRow's specified column. 84455 * The column may be specified by either its ID or title. 84456 * 84457 * @method set 84458 * @param {String|Integer} column Column ID (Number) 84459 * or Title (String) 84460 * @param {String|Number} value The value to be stored 84461 * 84462 * @example 84463 * <div class="norender"><code> 84464 * // Given the CSV file "mammals.csv" in the project's "assets" folder: 84465 * // 84466 * // id,species,name 84467 * // 0,Capra hircus,Goat 84468 * // 1,Panthera pardus,Leopard 84469 * // 2,Equus zebra,Zebra 84470 * 84471 * let table; 84472 * 84473 * function preload() { 84474 * //my table is comma separated value "csv" 84475 * //and has a header specifying the columns labels 84476 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84477 * } 84478 * 84479 * function setup() { 84480 * let rows = table.getRows(); 84481 * for (let r = 0; r < rows.length; r++) { 84482 * rows[r].set('name', 'Unicorn'); 84483 * } 84484 * 84485 * //print the results 84486 * print(table.getArray()); 84487 * 84488 * describe('no image displayed'); 84489 * } 84490 * </code></div> 84491 */ 84492 _main.default.TableRow.prototype.set = function (column, value) { 84493 // if typeof column is string, use .obj 84494 if (typeof column === 'string') { 84495 var cPos = this.table.columns.indexOf(column); // index of columnID 84496 if (cPos >= 0) { 84497 this.obj[column] = value; 84498 this.arr[cPos] = value; 84499 } else { 84500 throw new Error('This table has no column named "'.concat(column, '"')); 84501 } 84502 } else { 84503 // if typeof column is number, use .arr 84504 if (column < this.table.columns.length) { 84505 this.arr[column] = value; 84506 var cTitle = this.table.columns[column]; 84507 this.obj[cTitle] = value; 84508 } else { 84509 throw new Error('Column #'.concat(column, ' is out of the range of this table')); 84510 } 84511 } 84512 }; 84513 /** 84514 * Stores a Float value in the TableRow's specified column. 84515 * The column may be specified by either its ID or title. 84516 * 84517 * @method setNum 84518 * @param {String|Integer} column Column ID (Number) 84519 * or Title (String) 84520 * @param {Number|String} value The value to be stored 84521 * as a Float 84522 * @example 84523 * <div class="norender"><code> 84524 * // Given the CSV file "mammals.csv" in the project's "assets" folder: 84525 * // 84526 * // id,species,name 84527 * // 0,Capra hircus,Goat 84528 * // 1,Panthera pardus,Leopard 84529 * // 2,Equus zebra,Zebra 84530 * 84531 * let table; 84532 * 84533 * function preload() { 84534 * //my table is comma separated value "csv" 84535 * //and has a header specifying the columns labels 84536 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84537 * } 84538 * 84539 * function setup() { 84540 * let rows = table.getRows(); 84541 * for (let r = 0; r < rows.length; r++) { 84542 * rows[r].setNum('id', r + 10); 84543 * } 84544 * 84545 * print(table.getArray()); 84546 * 84547 * describe('no image displayed'); 84548 * } 84549 * </code></div> 84550 */ 84551 _main.default.TableRow.prototype.setNum = function (column, value) { 84552 var floatVal = parseFloat(value); 84553 this.set(column, floatVal); 84554 }; 84555 /** 84556 * Stores a String value in the TableRow's specified column. 84557 * The column may be specified by either its ID or title. 84558 * 84559 * @method setString 84560 * @param {String|Integer} column Column ID (Number) 84561 * or Title (String) 84562 * @param {String|Number|Boolean|Object} value The value to be stored 84563 * as a String 84564 * @example 84565 * <div class="norender"><code> 84566 * // Given the CSV file "mammals.csv" in the project's "assets" folder: 84567 * // 84568 * // id,species,name 84569 * // 0,Capra hircus,Goat 84570 * // 1,Panthera pardus,Leopard 84571 * // 2,Equus zebra,Zebra 84572 * 84573 * let table; 84574 * 84575 * function preload() { 84576 * //my table is comma separated value "csv" 84577 * //and has a header specifying the columns labels 84578 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84579 * } 84580 * 84581 * function setup() { 84582 * let rows = table.getRows(); 84583 * for (let r = 0; r < rows.length; r++) { 84584 * let name = rows[r].getString('name'); 84585 * rows[r].setString('name', 'A ' + name + ' named George'); 84586 * } 84587 * 84588 * print(table.getArray()); 84589 * 84590 * describe('no image displayed'); 84591 * } 84592 * </code></div> 84593 */ 84594 _main.default.TableRow.prototype.setString = function (column, value) { 84595 var stringVal = value.toString(); 84596 this.set(column, stringVal); 84597 }; 84598 /** 84599 * Retrieves a value from the TableRow's specified column. 84600 * The column may be specified by either its ID or title. 84601 * 84602 * @method get 84603 * @param {String|Integer} column columnName (string) or 84604 * ID (number) 84605 * @return {String|Number} 84606 * 84607 * @example 84608 * <div class="norender"><code> 84609 * // Given the CSV file "mammals.csv" in the project's "assets" folder: 84610 * // 84611 * // id,species,name 84612 * // 0,Capra hircus,Goat 84613 * // 1,Panthera pardus,Leopard 84614 * // 2,Equus zebra,Zebra 84615 * 84616 * let table; 84617 * 84618 * function preload() { 84619 * //my table is comma separated value "csv" 84620 * //and has a header specifying the columns labels 84621 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84622 * } 84623 * 84624 * function setup() { 84625 * let names = []; 84626 * let rows = table.getRows(); 84627 * for (let r = 0; r < rows.length; r++) { 84628 * names.push(rows[r].get('name')); 84629 * } 84630 * 84631 * print(names); 84632 * 84633 * describe('no image displayed'); 84634 * } 84635 * </code></div> 84636 */ 84637 _main.default.TableRow.prototype.get = function (column) { 84638 if (typeof column === 'string') { 84639 return this.obj[column]; 84640 } else { 84641 return this.arr[column]; 84642 } 84643 }; 84644 /** 84645 * Retrieves a Float value from the TableRow's specified 84646 * column. The column may be specified by either its ID or 84647 * title. 84648 * 84649 * @method getNum 84650 * @param {String|Integer} column columnName (string) or 84651 * ID (number) 84652 * @return {Number} Float Floating point number 84653 * @example 84654 * <div class="norender"><code> 84655 * // Given the CSV file "mammals.csv" in the project's "assets" folder: 84656 * // 84657 * // id,species,name 84658 * // 0,Capra hircus,Goat 84659 * // 1,Panthera pardus,Leopard 84660 * // 2,Equus zebra,Zebra 84661 * 84662 * let table; 84663 * 84664 * function preload() { 84665 * //my table is comma separated value "csv" 84666 * //and has a header specifying the columns labels 84667 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84668 * } 84669 * 84670 * function setup() { 84671 * let rows = table.getRows(); 84672 * let minId = Infinity; 84673 * let maxId = -Infinity; 84674 * for (let r = 0; r < rows.length; r++) { 84675 * let id = rows[r].getNum('id'); 84676 * minId = min(minId, id); 84677 * maxId = min(maxId, id); 84678 * } 84679 * print('minimum id = ' + minId + ', maximum id = ' + maxId); 84680 * describe('no image displayed'); 84681 * } 84682 * </code></div> 84683 */ 84684 _main.default.TableRow.prototype.getNum = function (column) { 84685 var ret; 84686 if (typeof column === 'string') { 84687 ret = parseFloat(this.obj[column]); 84688 } else { 84689 ret = parseFloat(this.arr[column]); 84690 } 84691 if (ret.toString() === 'NaN') { 84692 throw 'Error: '.concat(this.obj[column], ' is NaN (Not a Number)'); 84693 } 84694 return ret; 84695 }; 84696 /** 84697 * Retrieves an String value from the TableRow's specified 84698 * column. The column may be specified by either its ID or 84699 * title. 84700 * 84701 * @method getString 84702 * @param {String|Integer} column columnName (string) or 84703 * ID (number) 84704 * @return {String} String 84705 * @example 84706 * <div class="norender"><code> 84707 * // Given the CSV file "mammals.csv" in the project's "assets" folder: 84708 * // 84709 * // id,species,name 84710 * // 0,Capra hircus,Goat 84711 * // 1,Panthera pardus,Leopard 84712 * // 2,Equus zebra,Zebra 84713 * 84714 * let table; 84715 * 84716 * function preload() { 84717 * //my table is comma separated value "csv" 84718 * //and has a header specifying the columns labels 84719 * table = loadTable('assets/mammals.csv', 'csv', 'header'); 84720 * } 84721 * 84722 * function setup() { 84723 * let rows = table.getRows(); 84724 * let longest = ''; 84725 * for (let r = 0; r < rows.length; r++) { 84726 * let species = rows[r].getString('species'); 84727 * if (longest.length < species.length) { 84728 * longest = species; 84729 * } 84730 * } 84731 * 84732 * print('longest: ' + longest); 84733 * 84734 * describe('no image displayed'); 84735 * } 84736 * </code></div> 84737 */ 84738 _main.default.TableRow.prototype.getString = function (column) { 84739 if (typeof column === 'string') { 84740 return this.obj[column].toString(); 84741 } else { 84742 return this.arr[column].toString(); 84743 } 84744 }; 84745 var _default = _main.default; 84746 exports.default = _default; 84747 }, 84748 { 84749 '../core/main': 290, 84750 'core-js/modules/es.array.index-of': 175, 84751 'core-js/modules/es.object.to-string': 195, 84752 'core-js/modules/es.regexp.exec': 199, 84753 'core-js/modules/es.regexp.to-string': 200, 84754 'core-js/modules/es.string.split': 209 84755 } 84756 ], 84757 319: [
84758 function (_dereq_, module, exports) { 84759 'use strict'; 84760 _dereq_('core-js/modules/es.symbol'); 84761 _dereq_('core-js/modules/es.symbol.description'); 84762 _dereq_('core-js/modules/es.symbol.iterator'); 84763 _dereq_('core-js/modules/es.array.iterator'); 84764 _dereq_('core-js/modules/es.number.constructor'); 84765 _dereq_('core-js/modules/es.object.to-string'); 84766 _dereq_('core-js/modules/es.regexp.exec'); 84767 _dereq_('core-js/modules/es.string.iterator'); 84768 _dereq_('core-js/modules/es.string.replace'); 84769 _dereq_('core-js/modules/web.dom-collections.iterator'); 84770 _dereq_('core-js/modules/es.symbol'); 84771 _dereq_('core-js/modules/es.symbol.description'); 84772 _dereq_('core-js/modules/es.symbol.iterator'); 84773 _dereq_('core-js/modules/es.array.iterator'); 84774 _dereq_('core-js/modules/es.number.constructor'); 84775 _dereq_('core-js/modules/es.object.to-string'); 84776 _dereq_('core-js/modules/es.regexp.exec'); 84777 _dereq_('core-js/modules/es.string.iterator'); 84778 _dereq_('core-js/modules/es.string.replace'); 84779 _dereq_('core-js/modules/web.dom-collections.iterator'); 84780 Object.defineProperty(exports, '__esModule', { 84781 value: true 84782 }); 84783 exports.default = void 0; 84784 var _main = _interopRequireDefault(_dereq_('../core/main')); 84785 function _interopRequireDefault(obj) { 84786 return obj && obj.__esModule ? obj : { 84787 default: 84788 obj 84789 }; 84790 } /** 84791 * @module IO 84792 * @submodule Input 84793 * @requires core 84794 */ 84795 /** 84796 * XML is a representation of an XML object, able to parse XML code. Use 84797 * <a href="#/p5/loadXML">loadXML()</a> to load external XML files and create XML objects. 84798 * 84799 * @class p5.XML 84800 * @constructor 84801 * @example 84802 * <div class='norender'><code> 84803 * // The following short XML file called "mammals.xml" is parsed 84804 * // in the code below. 84805 * // 84806 * // <?xml version="1.0"?> 84807 * // <mammals> 84808 * // <animal id="0" species="Capra hircus">Goat</animal> 84809 * // <animal id="1" species="Panthera pardus">Leopard</animal> 84810 * // <animal id="2" species="Equus zebra">Zebra</animal> 84811 * // </mammals> 84812 * 84813 * let xml; 84814 * 84815 * function preload() { 84816 * xml = loadXML('assets/mammals.xml'); 84817 * } 84818 * 84819 * function setup() { 84820 * let children = xml.getChildren('animal'); 84821 * 84822 * for (let i = 0; i < children.length; i++) { 84823 * let id = children[i].getNum('id'); 84824 * let coloring = children[i].getString('species'); 84825 * let name = children[i].getContent(); 84826 * print(id + ', ' + coloring + ', ' + name); 84827 * } 84828 * 84829 * describe('no image displayed'); 84830 * } 84831 * 84832 * // Sketch prints: 84833 * // 0, Capra hircus, Goat 84834 * // 1, Panthera pardus, Leopard 84835 * // 2, Equus zebra, Zebra 84836 * </code></div> 84837 */ 84838 84839 _main.default.XML = function (DOM) { 84840 if (!DOM) { 84841 var xmlDoc = document.implementation.createDocument(null, 'doc'); 84842 this.DOM = xmlDoc.createElement('root'); 84843 } else { 84844 this.DOM = DOM; 84845 } 84846 }; 84847 /** 84848 * Gets a copy of the element's parent. Returns the parent as another 84849 * <a href="#/p5.XML">p5.XML</a> object. 84850 * 84851 * @method getParent 84852 * @return {p5.XML} element parent 84853 * @example 84854 * <div class='norender'><code> 84855 * // The following short XML file called "mammals.xml" is parsed 84856 * // in the code below. 84857 * // 84858 * // <?xml version="1.0"?> 84859 * // <mammals> 84860 * // <animal id="0" species="Capra hircus">Goat</animal> 84861 * // <animal id="1" species="Panthera pardus">Leopard</animal> 84862 * // <animal id="2" species="Equus zebra">Zebra</animal> 84863 * // </mammals> 84864 * 84865 * let xml; 84866 * 84867 * function preload() { 84868 * xml = loadXML('assets/mammals.xml'); 84869 * } 84870 * 84871 * function setup() { 84872 * let children = xml.getChildren('animal'); 84873 * let parent = children[1].getParent(); 84874 * print(parent.getName()); 84875 * } 84876 * 84877 * // Sketch prints: 84878 * // mammals 84879 * </code></div> 84880 */ 84881 _main.default.XML.prototype.getParent = function () { 84882 return new _main.default.XML(this.DOM.parentElement); 84883 }; 84884 /** 84885 * Gets the element's full name, which is returned as a String. 84886 * 84887 * @method getName 84888 * @return {String} the name of the node 84889 * @example<animal 84890 * <div class='norender'><code> 84891 * // The following short XML file called "mammals.xml" is parsed 84892 * // in the code below. 84893 * // 84894 * // <?xml version="1.0"?> 84895 * // <mammals> 84896 * // <animal id="0" species="Capra hircus">Goat</animal> 84897 * // <animal id="1" species="Panthera pardus">Leopard</animal> 84898 * // <animal id="2" species="Equus zebra">
84898Zebra</animal> 84899 * // </mammals> 84900 * 84901 * let xml; 84902 * 84903 * function preload() { 84904 * xml = loadXML('assets/mammals.xml'); 84905 * } 84906 * 84907 * function setup() { 84908 * print(xml.getName()); 84909 * } 84910 * 84911 * // Sketch prints: 84912 * // mammals 84913 * </code></div> 84914 */ 84915 _main.default.XML.prototype.getName = function () { 84916 return this.DOM.tagName; 84917 }; 84918 /** 84919 * Sets the element's name, which is specified as a String. 84920 * 84921 * @method setName 84922 * @param {String} the new name of the node 84923 * @example<animal 84924 * <div class='norender'><code> 84925 * // The following short XML file called "mammals.xml" is parsed 84926 * // in the code below. 84927 * // 84928 * // <?xml version="1.0"?> 84929 * // <mammals> 84930 * // <animal id="0" species="Capra hircus">Goat</animal> 84931 * // <animal id="1" species="Panthera pardus">Leopard</animal> 84932 * // <animal id="2" species="Equus zebra">Zebra</animal> 84933 * // </mammals> 84934 * 84935 * let xml; 84936 * 84937 * function preload() { 84938 * xml = loadXML('assets/mammals.xml'); 84939 * } 84940 * 84941 * function setup() { 84942 * print(xml.getName()); 84943 * xml.setName('fish'); 84944 * print(xml.getName()); 84945 * } 84946 * 84947 * // Sketch prints: 84948 * // mammals 84949 * // fish 84950 * </code></div> 84951 */ 84952 _main.default.XML.prototype.setName = function (name) { 84953 var content = this.DOM.innerHTML; 84954 var attributes = this.DOM.attributes; 84955 var xmlDoc = document.implementation.createDocument(null, 'default'); 84956 var newDOM = xmlDoc.createElement(name); 84957 newDOM.innerHTML = content; 84958 for (var i = 0; i < attributes.length; i++) { 84959 newDOM.setAttribute(attributes[i].nodeName, attributes.nodeValue); 84960 } 84961 this.DOM = newDOM; 84962 }; 84963 /** 84964 * Checks whether or not the element has any children, and returns the result 84965 * as a boolean. 84966 * 84967 * @method hasChildren 84968 * @return {boolean} 84969 * @example<animal 84970 * <div class='norender'><code> 84971 * // The following short XML file called "mammals.xml" is parsed 84972 * // in the code below. 84973 * // 84974 * // <?xml version="1.0"?> 84975 * // <mammals> 84976 * // <animal id="0" species="Capra hircus">Goat</animal> 84977 * // <animal id="1" species="Panthera pardus">Leopard</animal> 84978 * // <animal id="2" species="Equus zebra">Zebra</animal> 84979 * // </mammals> 84980 * 84981 * let xml; 84982 * 84983 * function preload() { 84984 * xml = loadXML('assets/mammals.xml'); 84985 * } 84986 * 84987 * function setup() { 84988 * print(xml.hasChildren()); 84989 * } 84990 * 84991 * // Sketch prints: 84992 * // true 84993 * </code></div> 84994 */ 84995 _main.default.XML.prototype.hasChildren = function () { 84996 return this.DOM.children.length > 0; 84997 }; 84998 /** 84999 * Get the names of all of the element's children, and returns the names as an 85000 * array of Strings. This is the same as looping through and calling <a href="#/p5.XML/getName">getName()</a> 85001 * on each child element individually. 85002 * 85003 * @method listChildren 85004 * @return {String[]} names of the children of the element 85005 * @example<animal 85006 * <div class='norender'><code> 85007 * // The following short XML file called "mammals.xml" is parsed 85008 * // in the code below. 85009 * // 85010 * // <?xml version="1.0"?> 85011 * // <mammals> 85012 * // <animal id="0" species="Capra hircus">Goat</animal> 85013 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85014 * // <animal id="2" species="Equus zebra">Zebra</animal> 85015 * // </mammals> 85016 * 85017 * let xml; 85018 * 85019 * function preload() { 85020 * xml = loadXML('assets/mammals.xml'); 85021 * } 85022 * 85023 * function setup() { 85024 * print(xml.listChildren()); 85025 * } 85026 * 85027 * // Sketch prints: 85028 * // ["animal", "animal", "animal"] 85029 * </code></div> 85030 */ 85031 _main.default.XML.prototype.listChildren = function () { 85032 var arr = [ 85033 ]; 85034 for (var i = 0; i < this.DOM.childNodes.length; i++) { 85035 arr.push(this.DOM.childNodes[i].nodeName); 85036 } 85037 return arr; 85038 }; 85039 /** 85040 * Returns all of the element's children as an array of <a href="#/p5.XML">p5.XML</a> objects. When 85041 * the name parameter is specified, then it will return all children that match 85042 * that name. 85043 * 85044 * @method getChildren 85045 * @param {String} [name] element name 85046 * @return {p5.XML[]} children of the element 85047 * @example<animal 85048 * <div class='norender'><code> 85049 * // The following short XML file called "mammals.xml" is parsed 85050 * // in the code below. 85051 * // 85052 * // <?xml version="1.0"?> 85053 * // <mammals> 85054 * // <animal id="0" species="Capra hircus">Goat</animal> 85055 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85056 * // <animal id="2" species="Equus zebra">
85056Zebra</animal> 85057 * // </mammals> 85058 * 85059 * let xml; 85060 * 85061 * function preload() { 85062 * xml = loadXML('assets/mammals.xml'); 85063 * } 85064 * 85065 * function setup() { 85066 * let animals = xml.getChildren('animal'); 85067 * 85068 * for (let i = 0; i < animals.length; i++) { 85069 * print(animals[i].getContent()); 85070 * } 85071 * } 85072 * 85073 * // Sketch prints: 85074 * // "Goat" 85075 * // "Leopard" 85076 * // "Zebra" 85077 * </code></div> 85078 */ 85079 _main.default.XML.prototype.getChildren = function (param) { 85080 if (param) { 85081 return elementsToP5XML(this.DOM.getElementsByTagName(param)); 85082 } else { 85083 return elementsToP5XML(this.DOM.children); 85084 } 85085 }; 85086 function elementsToP5XML(elements) { 85087 var arr = [ 85088 ]; 85089 for (var i = 0; i < elements.length; i++) { 85090 arr.push(new _main.default.XML(elements[i])); 85091 } 85092 return arr; 85093 } /** 85094 * Returns the first of the element's children that matches the name parameter 85095 * or the child of the given index.It returns undefined if no matching 85096 * child is found. 85097 * 85098 * @method getChild 85099 * @param {String|Integer} name element name or index 85100 * @return {p5.XML} 85101 * @example<animal 85102 * <div class='norender'><code> 85103 * // The following short XML file called "mammals.xml" is parsed 85104 * // in the code below. 85105 * // 85106 * // <?xml version="1.0"?> 85107 * // <mammals> 85108 * // <animal id="0" species="Capra hircus">Goat</animal> 85109 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85110 * // <animal id="2" species="Equus zebra">Zebra</animal> 85111 * // </mammals> 85112 * 85113 * let xml; 85114 * 85115 * function preload() { 85116 * xml = loadXML('assets/mammals.xml'); 85117 * } 85118 * 85119 * function setup() { 85120 * let firstChild = xml.getChild('animal'); 85121 * print(firstChild.getContent()); 85122 * } 85123 * 85124 * // Sketch prints: 85125 * // "Goat" 85126 * </code></div> 85127 * <div class='norender'><code> 85128 * let xml; 85129 * 85130 * function preload() { 85131 * xml = loadXML('assets/mammals.xml'); 85132 * } 85133 * 85134 * function setup() { 85135 * let secondChild = xml.getChild(1); 85136 * print(secondChild.getContent()); 85137 * } 85138 * 85139 * // Sketch prints: 85140 * // "Leopard" 85141 * </code></div> 85142 */ 85143 85144 _main.default.XML.prototype.getChild = function (param) { 85145 if (typeof param === 'string') { 85146 var _iteratorNormalCompletion = true; 85147 var _didIteratorError = false; 85148 var _iteratorError = undefined; 85149 try { 85150 for (var _iterator = this.DOM.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 85151 var child = _step.value; 85152 if (child.tagName === param) return new _main.default.XML(child); 85153 } 85154 } catch (err) { 85155 _didIteratorError = true; 85156 _iteratorError = err; 85157 } finally { 85158 try { 85159 if (!_iteratorNormalCompletion && _iterator.return != null) { 85160 _iterator.return(); 85161 } 85162 } finally { 85163 if (_didIteratorError) { 85164 throw _iteratorError; 85165 } 85166 } 85167 } 85168 } else { 85169 return new _main.default.XML(this.DOM.children[param]); 85170 } 85171 }; 85172 /** 85173 * Appends a new child to the element. The child can be specified with 85174 * either a String, which will be used as the new tag's name, or as a 85175 * reference to an existing <a href="#/p5.XML">p5.XML</a> object. 85176 * A reference to the newly created child is returned as an <a href="#/p5.XML">p5.XML</a> object. 85177 * 85178 * @method addChild 85179 * @param {p5.XML} node a <a href="#/p5.XML">p5.XML</a> Object which will be the child to be added 85180 * @example 85181 * <div class='norender'><code> 85182 * // The following short XML file called "mammals.xml" is parsed 85183 * // in the code below. 85184 * // 85185 * // <?xml version="1.0"?> 85186 * // <mammals> 85187 * // <animal id="0" species="Capra hircus">Goat</animal> 85188 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85189 * // <animal id="2" species="Equus zebra">
85189Zebra</animal> 85190 * // </mammals> 85191 * 85192 * let xml; 85193 * 85194 * function preload() { 85195 * xml = loadXML('assets/mammals.xml'); 85196 * } 85197 * 85198 * function setup() { 85199 * let child = new p5.XML(); 85200 * child.setName('animal'); 85201 * child.setAttribute('id', '3'); 85202 * child.setAttribute('species', 'Ornithorhynchus anatinus'); 85203 * child.setContent('Platypus'); 85204 * xml.addChild(child); 85205 * 85206 * let animals = xml.getChildren('animal'); 85207 * print(animals[animals.length - 1].getContent()); 85208 * } 85209 * 85210 * // Sketch prints: 85211 * // "Goat" 85212 * // "Leopard" 85213 * // "Zebra" 85214 * </code></div> 85215 */ 85216 _main.default.XML.prototype.addChild = function (node) { 85217 if (node instanceof _main.default.XML) { 85218 this.DOM.appendChild(node.DOM); 85219 } else { // PEND 85220 } 85221 }; 85222 /** 85223 * Removes the element specified by name or index. 85224 * 85225 * @method removeChild 85226 * @param {String|Integer} name element name or index 85227 * @example 85228 * <div class='norender'><code> 85229 * // The following short XML file called "mammals.xml" is parsed 85230 * // in the code below. 85231 * // 85232 * // <?xml version="1.0"?> 85233 * // <mammals> 85234 * // <animal id="0" species="Capra hircus">Goat</animal> 85235 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85236 * // <animal id="2" species="Equus zebra">Zebra</animal> 85237 * // </mammals> 85238 * 85239 * let xml; 85240 * 85241 * function preload() { 85242 * xml = loadXML('assets/mammals.xml'); 85243 * } 85244 * 85245 * function setup() { 85246 * xml.removeChild('animal'); 85247 * let children = xml.getChildren(); 85248 * for (let i = 0; i < children.length; i++) { 85249 * print(children[i].getContent()); 85250 * } 85251 * } 85252 * 85253 * // Sketch prints: 85254 * // "Leopard" 85255 * // "Zebra" 85256 * </code></div> 85257 * <div class='norender'><code> 85258 * let xml; 85259 * 85260 * function preload() { 85261 * xml = loadXML('assets/mammals.xml'); 85262 * } 85263 * 85264 * function setup() { 85265 * xml.removeChild(1); 85266 * let children = xml.getChildren(); 85267 * for (let i = 0; i < children.length; i++) { 85268 * print(children[i].getContent()); 85269 * } 85270 * } 85271 * 85272 * // Sketch prints: 85273 * // "Goat" 85274 * // "Zebra" 85275 * </code></div> 85276 */ 85277 _main.default.XML.prototype.removeChild = function (param) { 85278 var ind = - 1; 85279 if (typeof param === 'string') { 85280 for (var i = 0; i < this.DOM.children.length; i++) { 85281 if (this.DOM.children[i].tagName === param) { 85282 ind = i; 85283 break; 85284 } 85285 } 85286 } else { 85287 ind = param; 85288 } 85289 if (ind !== - 1) { 85290 this.DOM.removeChild(this.DOM.children[ind]); 85291 } 85292 }; 85293 /** 85294 * Counts the specified element's number of attributes, returned as an Number. 85295 * 85296 * @method getAttributeCount 85297 * @return {Integer} 85298 * @example 85299 * <div class='norender'><code> 85300 * // The following short XML file called "mammals.xml" is parsed 85301 * // in the code below. 85302 * // 85303 * // <?xml version="1.0"?> 85304 * // <mammals> 85305 * // <animal id="0" species="Capra hircus">Goat</animal> 85306 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85307 * // <animal id="2" species="Equus zebra">Zebra</animal> 85308 * // </mammals> 85309 * 85310 * let xml; 85311 * 85312 * function preload() { 85313 * xml = loadXML('assets/mammals.xml'); 85314 * } 85315 * 85316 * function setup() { 85317 * let firstChild = xml.getChild('animal'); 85318 * print(firstChild.getAttributeCount()); 85319 * } 85320 * 85321 * // Sketch prints: 85322 * // 2 85323 * </code></div> 85324 */ 85325 _main.default.XML.prototype.getAttributeCount = function () { 85326 return this.DOM.attributes.length; 85327 }; 85328 /** 85329 * Gets all of the specified element's attributes, and returns them as an 85330 * array of Strings. 85331 * 85332 * @method listAttributes 85333 * @return {String[]} an array of strings containing the names of attributes 85334 * @example 85335 * <div class='norender'><code> 85336 * // The following short XML file called "mammals.xml" is parsed 85337 * // in the code below. 85338 * // 85339 * // <?xml version="1.0"?> 85340 * // <mammals> 85341 * // <animal id="0" species="Capra hircus">Goat</animal> 85342 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85343 * // <animal id="2" species="Equus zebra">
85343Zebra</animal> 85344 * // </mammals> 85345 * 85346 * let xml; 85347 * 85348 * function preload() { 85349 * xml = loadXML('assets/mammals.xml'); 85350 * } 85351 * 85352 * function setup() { 85353 * let firstChild = xml.getChild('animal'); 85354 * print(firstChild.listAttributes()); 85355 * } 85356 * 85357 * // Sketch prints: 85358 * // ["id", "species"] 85359 * </code></div> 85360 */ 85361 _main.default.XML.prototype.listAttributes = function () { 85362 var arr = [ 85363 ]; 85364 var _iteratorNormalCompletion2 = true; 85365 var _didIteratorError2 = false; 85366 var _iteratorError2 = undefined; 85367 try { 85368 for (var _iterator2 = this.DOM.attributes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 85369 var attribute = _step2.value; 85370 arr.push(attribute.nodeName); 85371 } 85372 } catch (err) { 85373 _didIteratorError2 = true; 85374 _iteratorError2 = err; 85375 } finally { 85376 try { 85377 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 85378 _iterator2.return(); 85379 } 85380 } finally { 85381 if (_didIteratorError2) { 85382 throw _iteratorError2; 85383 } 85384 } 85385 } 85386 return arr; 85387 }; 85388 /** 85389 * Checks whether or not an element has the specified attribute. 85390 * 85391 * @method hasAttribute 85392 * @param {String} the attribute to be checked 85393 * @return {boolean} true if attribute found else false 85394 * @example 85395 * <div class='norender'><code> 85396 * // The following short XML file called "mammals.xml" is parsed 85397 * // in the code below. 85398 * // 85399 * // <?xml version="1.0"?> 85400 * // <mammals> 85401 * // <animal id="0" species="Capra hircus">Goat</animal> 85402 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85403 * // <animal id="2" species="Equus zebra">Zebra</animal> 85404 * // </mammals> 85405 * 85406 * let xml; 85407 * 85408 * function preload() { 85409 * xml = loadXML('assets/mammals.xml'); 85410 * } 85411 * 85412 * function setup() { 85413 * let firstChild = xml.getChild('animal'); 85414 * print(firstChild.hasAttribute('species')); 85415 * print(firstChild.hasAttribute('color')); 85416 * } 85417 * 85418 * // Sketch prints: 85419 * // true 85420 * // false 85421 * </code></div> 85422 */ 85423 _main.default.XML.prototype.hasAttribute = function (name) { 85424 var obj = { 85425 }; 85426 var _iteratorNormalCompletion3 = true; 85427 var _didIteratorError3 = false; 85428 var _iteratorError3 = undefined; 85429 try { 85430 for (var _iterator3 = this.DOM.attributes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 85431 var attribute = _step3.value; 85432 obj[attribute.nodeName] = attribute.nodeValue; 85433 } 85434 } catch (err) { 85435 _didIteratorError3 = true; 85436 _iteratorError3 = err; 85437 } finally { 85438 try { 85439 if (!_iteratorNormalCompletion3 && _iterator3.return != null) { 85440 _iterator3.return(); 85441 } 85442 } finally { 85443 if (_didIteratorError3) { 85444 throw _iteratorError3; 85445 } 85446 } 85447 } 85448 return obj[name] ? true : false; 85449 }; 85450 /** 85451 * Returns an attribute value of the element as an Number. If the defaultValue 85452 * parameter is specified and the attribute doesn't exist, then defaultValue 85453 * is returned. If no defaultValue is specified and the attribute doesn't 85454 * exist, the value 0 is returned. 85455 * 85456 * @method getNum 85457 * @param {String} name the non-null full name of the attribute 85458 * @param {Number} [defaultValue] the default value of the attribute 85459 * @return {Number} 85460 * @example 85461 * <div class='norender'><code> 85462 * // The following short XML file called "mammals.xml" is parsed 85463 * // in the code below. 85464 * // 85465 * // <?xml version="1.0"?> 85466 * // <mammals> 85467 * // <animal id="0" species="Capra hircus">Goat</animal> 85468 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85469 * // <animal id="2" species="Equus zebra">
85469Zebra</animal> 85470 * // </mammals> 85471 * 85472 * let xml; 85473 * 85474 * function preload() { 85475 * xml = loadXML('assets/mammals.xml'); 85476 * } 85477 * 85478 * function setup() { 85479 * let firstChild = xml.getChild('animal'); 85480 * print(firstChild.getNum('id')); 85481 * } 85482 * 85483 * // Sketch prints: 85484 * // 0 85485 * </code></div> 85486 */ 85487 _main.default.XML.prototype.getNum = function (name, defaultValue) { 85488 var obj = { 85489 }; 85490 var _iteratorNormalCompletion4 = true; 85491 var _didIteratorError4 = false; 85492 var _iteratorError4 = undefined; 85493 try { 85494 for (var _iterator4 = this.DOM.attributes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { 85495 var attribute = _step4.value; 85496 obj[attribute.nodeName] = attribute.nodeValue; 85497 } 85498 } catch (err) { 85499 _didIteratorError4 = true; 85500 _iteratorError4 = err; 85501 } finally { 85502 try { 85503 if (!_iteratorNormalCompletion4 && _iterator4.return != null) { 85504 _iterator4.return(); 85505 } 85506 } finally { 85507 if (_didIteratorError4) { 85508 throw _iteratorError4; 85509 } 85510 } 85511 } 85512 return Number(obj[name]) || defaultValue || 0; 85513 }; 85514 /** 85515 * Returns an attribute value of the element as an String. If the defaultValue 85516 * parameter is specified and the attribute doesn't exist, then defaultValue 85517 * is returned. If no defaultValue is specified and the attribute doesn't 85518 * exist, null is returned. 85519 * 85520 * @method getString 85521 * @param {String} name the non-null full name of the attribute 85522 * @param {Number} [defaultValue] the default value of the attribute 85523 * @return {String} 85524 * @example 85525 * <div class='norender'><code> 85526 * // The following short XML file called "mammals.xml" is parsed 85527 * // in the code below. 85528 * // 85529 * // <?xml version="1.0"?> 85530 * // <mammals> 85531 * // <animal id="0" species="Capra hircus">Goat</animal> 85532 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85533 * // <animal id="2" species="Equus zebra">Zebra</animal> 85534 * // </mammals> 85535 * 85536 * let xml; 85537 * 85538 * function preload() { 85539 * xml = loadXML('assets/mammals.xml'); 85540 * } 85541 * 85542 * function setup() { 85543 * let firstChild = xml.getChild('animal'); 85544 * print(firstChild.getString('species')); 85545 * } 85546 * 85547 * // Sketch prints: 85548 * // "Capra hircus" 85549 * </code></div> 85550 */ 85551 _main.default.XML.prototype.getString = function (name, defaultValue) { 85552 var obj = { 85553 }; 85554 var _iteratorNormalCompletion5 = true; 85555 var _didIteratorError5 = false; 85556 var _iteratorError5 = undefined; 85557 try { 85558 for (var _iterator5 = this.DOM.attributes[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { 85559 var attribute = _step5.value; 85560 obj[attribute.nodeName] = attribute.nodeValue; 85561 } 85562 } catch (err) { 85563 _didIteratorError5 = true; 85564 _iteratorError5 = err; 85565 } finally { 85566 try { 85567 if (!_iteratorNormalCompletion5 && _iterator5.return != null) { 85568 _iterator5.return(); 85569 } 85570 } finally { 85571 if (_didIteratorError5) { 85572 throw _iteratorError5; 85573 } 85574 } 85575 } 85576 return obj[name] ? String(obj[name]) : defaultValue || null; 85577 }; 85578 /** 85579 * Sets the content of an element's attribute. The first parameter specifies 85580 * the attribute name, while the second specifies the new content. 85581 * 85582 * @method setAttribute 85583 * @param {String} name the full name of the attribute 85584 * @param {Number|String|Boolean} value the value of the attribute 85585 * @example 85586 * <div class='norender'><code> 85587 * // The following short XML file called "mammals.xml" is parsed 85588 * // in the code below. 85589 * // 85590 * // <?xml version="1.0"?> 85591 * // <mammals> 85592 * // <animal id="0" species="Capra hircus">Goat</animal> 85593 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85594 * // <animal id="2" species="Equus zebra">
85594Zebra</animal> 85595 * // </mammals> 85596 * 85597 * let xml; 85598 * 85599 * function preload() { 85600 * xml = loadXML('assets/mammals.xml'); 85601 * } 85602 * 85603 * function setup() { 85604 * let firstChild = xml.getChild('animal'); 85605 * print(firstChild.getString('species')); 85606 * firstChild.setAttribute('species', 'Jamides zebra'); 85607 * print(firstChild.getString('species')); 85608 * } 85609 * 85610 * // Sketch prints: 85611 * // "Capra hircus" 85612 * // "Jamides zebra" 85613 * </code></div> 85614 */ 85615 _main.default.XML.prototype.setAttribute = function (name, value) { 85616 this.DOM.setAttribute(name, value); 85617 }; 85618 /** 85619 * Returns the content of an element. If there is no such content, 85620 * defaultValue is returned if specified, otherwise null is returned. 85621 * 85622 * @method getContent 85623 * @param {String} [defaultValue] value returned if no content is found 85624 * @return {String} 85625 * @example 85626 * <div class='norender'><code> 85627 * // The following short XML file called "mammals.xml" is parsed 85628 * // in the code below. 85629 * // 85630 * // <?xml version="1.0"?> 85631 * // <mammals> 85632 * // <animal id="0" species="Capra hircus">Goat</animal> 85633 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85634 * // <animal id="2" species="Equus zebra">Zebra</animal> 85635 * // </mammals> 85636 * 85637 * let xml; 85638 * 85639 * function preload() { 85640 * xml = loadXML('assets/mammals.xml'); 85641 * } 85642 * 85643 * function setup() { 85644 * let firstChild = xml.getChild('animal'); 85645 * print(firstChild.getContent()); 85646 * } 85647 * 85648 * // Sketch prints: 85649 * // "Goat" 85650 * </code></div> 85651 */ 85652 _main.default.XML.prototype.getContent = function (defaultValue) { 85653 var str; 85654 str = this.DOM.textContent; 85655 str = str.replace(/\s\s+/g, ','); 85656 return str || defaultValue || null; 85657 }; 85658 /** 85659 * Sets the element's content. 85660 * 85661 * @method setContent 85662 * @param {String} text the new content 85663 * @example 85664 * <div class='norender'><code> 85665 * // The following short XML file called "mammals.xml" is parsed 85666 * // in the code below. 85667 * // 85668 * // <?xml version="1.0"?> 85669 * // <mammals> 85670 * // <animal id="0" species="Capra hircus">Goat</animal> 85671 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85672 * // <animal id="2" species="Equus zebra">Zebra</animal> 85673 * // </mammals> 85674 * 85675 * let xml; 85676 * 85677 * function preload() { 85678 * xml = loadXML('assets/mammals.xml'); 85679 * } 85680 * 85681 * function setup() { 85682 * let firstChild = xml.getChild('animal'); 85683 * print(firstChild.getContent()); 85684 * firstChild.setContent('Mountain Goat'); 85685 * print(firstChild.getContent()); 85686 * } 85687 * 85688 * // Sketch prints: 85689 * // "Goat" 85690 * // "Mountain Goat" 85691 * </code></div> 85692 */ 85693 _main.default.XML.prototype.setContent = function (content) { 85694 if (!this.DOM.children.length) { 85695 this.DOM.textContent = content; 85696 } 85697 }; 85698 /** 85699 * Serializes the element into a string. This function is useful for preparing 85700 * the content to be sent over a http request or saved to file. 85701 * 85702 * @method serialize 85703 * @return {String} Serialized string of the element 85704 * @example 85705 * <div class='norender'><code> 85706 * let xml; 85707 * 85708 * function preload() { 85709 * xml = loadXML('assets/mammals.xml'); 85710 * } 85711 * 85712 * function setup() { 85713 * print(xml.serialize()); 85714 * } 85715 * 85716 * // Sketch prints: 85717 * // <mammals> 85718 * // <animal id="0" species="Capra hircus">Goat</animal> 85719 * // <animal id="1" species="Panthera pardus">Leopard</animal> 85720 * // <animal id="2" species="Equus zebra">Zebra</animal> 85721 * // </mammals> 85722 * </code></div> 85723 */ 85724 _main.default.XML.prototype.serialize = function () { 85725 var xmlSerializer = new XMLSerializer(); 85726 return xmlSerializer.serializeToString(this.DOM); 85727 }; 85728 var _default = _main.default; 85729 exports.default = _default; 85730 }, 85731 { 85732 '../core/main': 290, 85733 'core-js/modules/es.array.iterator': 176, 85734 'core-js/modules/es.number.constructor': 187, 85735 'core-js/modules/es.object.to-string': 195, 85736 'core-js/modules/es.regexp.exec': 199, 85737 'core-js/modules/es.string.iterator': 204, 85738 'core-js/modules/es.string.replace': 207, 85739 'core-js/modules/es.symbol': 214, 85740 'core-js/modules/es.symbol.description': 212, 85741 'core-js/modules/es.symbol.iterator': 213, 85742 'core-js/modules/web.dom-collections.iterator': 248 85743 } 85744 ], 85745 320: [
85746 function (_dereq_, module, exports) { 85747 'use strict'; 85748 _dereq_('core-js/modules/es.array.includes'); 85749 _dereq_('core-js/modules/es.array.index-of'); 85750 _dereq_('core-js/modules/es.array.map'); 85751 _dereq_('core-js/modules/es.array.slice'); 85752 _dereq_('core-js/modules/es.math.hypot'); 85753 _dereq_('core-js/modules/es.number.constructor'); 85754 _dereq_('core-js/modules/es.string.includes'); 85755 _dereq_('core-js/modules/es.array.includes'); 85756 _dereq_('core-js/modules/es.array.index-of'); 85757 _dereq_('core-js/modules/es.array.map'); 85758 _dereq_('core-js/modules/es.array.slice'); 85759 _dereq_('core-js/modules/es.math.hypot'); 85760 _dereq_('core-js/modules/es.number.constructor'); 85761 _dereq_('core-js/modules/es.string.includes'); 85762 Object.defineProperty(exports, '__esModule', { 85763 value: true 85764 }); 85765 exports.default = void 0; 85766 var _main = _interopRequireDefault(_dereq_('../core/main')); 85767 function _interopRequireDefault(obj) { 85768 return obj && obj.__esModule ? obj : { 85769 default: 85770 obj 85771 }; 85772 } /** 85773 * @module Math 85774 * @submodule Calculation 85775 * @for p5 85776 * @requires core 85777 */ 85778 /** 85779 * Calculates the absolute value (magnitude) of a number. Maps to Math.abs(). 85780 * The absolute value of a number is always positive. 85781 * 85782 * @method abs 85783 * @param {Number} n number to compute 85784 * @return {Number} absolute value of given number 85785 * @example 85786 * <div class = "norender"><code> 85787 * function setup() { 85788 * let x = -3; 85789 * let y = abs(x); 85790 * 85791 * print(x); // -3 85792 * print(y); // 3 85793 * 85794 * describe('no image displayed'); 85795 * } 85796 * </code></div> 85797 */ 85798 85799 _main.default.prototype.abs = Math.abs; 85800 /** 85801 * Calculates the closest int value that is greater than or equal to the 85802 * value of the parameter. Maps to Math.ceil(). For example, ceil(9.03) 85803 * returns the value 10. 85804 * 85805 * @method ceil 85806 * @param {Number} n number to round up 85807 * @return {Integer} rounded up number 85808 * @example 85809 * <div><code> 85810 * function draw() { 85811 * background(200); 85812 * // map, mouseX between 0 and 5. 85813 * let ax = map(mouseX, 0, 100, 0, 5); 85814 * let ay = 66; 85815 * 85816 * //Get the ceiling of the mapped number. 85817 * let bx = ceil(map(mouseX, 0, 100, 0, 5)); 85818 * let by = 33; 85819 * 85820 * // Multiply the mapped numbers by 20 to more easily 85821 * // see the changes. 85822 * stroke(0); 85823 * fill(0); 85824 * line(0, ay, ax * 20, ay); 85825 * line(0, by, bx * 20, by); 85826 * 85827 * // Reformat the float returned by map and draw it. 85828 * noStroke(); 85829 * text(nfc(ax, 2), ax, ay - 5); 85830 * text(nfc(bx, 1), bx, by - 5); 85831 * 85832 * describe(`2 horizontal lines & number sets. increase with 85833 * mouse x. bottom to 2 decimals`); 85834 * } 85835 * </code></div> 85836 */ 85837 _main.default.prototype.ceil = Math.ceil; 85838 /** 85839 * Constrains a value between a minimum and maximum value. 85840 * 85841 * @method constrain 85842 * @param {Number} n number to constrain 85843 * @param {Number} low minimum limit 85844 * @param {Number} high maximum limit 85845 * @return {Number} constrained number 85846 * @example 85847 * <div><code> 85848 * function draw() { 85849 * background(200); 85850 * 85851 * let leftWall = 25; 85852 * let rightWall = 75; 85853 * 85854 * // xm is just the mouseX, while 85855 * // xc is the mouseX, but constrained 85856 * // between the leftWall and rightWall! 85857 * let xm = mouseX; 85858 * let xc = constrain(mouseX, leftWall, rightWall); 85859 * 85860 * // Draw the walls. 85861 * stroke(150); 85862 * line(leftWall, 0, leftWall, height); 85863 * line(rightWall, 0, rightWall, height); 85864 * 85865 * // Draw xm and xc as circles. 85866 * noStroke(); 85867 * fill(150); 85868 * ellipse(xm, 33, 9, 9); // Not Constrained 85869 * fill(0); 85870 * ellipse(xc, 66, 9, 9); // Constrained 85871 * 85872 * describe(`2 vertical lines. 2 ellipses move with mouse X, 85873 * 1 does not move past lines`); 85874 * } 85875 * </code></div> 85876 */ 85877 _main.default.prototype.constrain = function (n, low, high) { 85878 _main.default._validateParameters('constrain', arguments); 85879 return Math.max(Math.min(n, high), low); 85880 }; 85881 /** 85882 * Calculates the distance between two points, in either two or three dimensions. 85883 * If you looking for distance between two vectors see <a herf="#/p5.Vector/dist">p5.Vector.dist()</a> 85884 * 85885 * @method dist 85886 * @param {Number} x1 x-coordinate of the first point 85887 * @param {Number} y1 y-coordinate of the first point 85888 * @param {Number} x2 x-coordinate of the second point 85889 * @param {Number} y2 y-coordinate of the second point 85890 * @return {Number} distance between the two points 85891 * 85892 * @example 85893 * <div><code> 85894 * // Move your mouse inside the canvas to see the 85895 * // change in distance between two points! 85896 * function draw() { 85897 * background(200); 85898 * fill(0); 85899 * 85900 * let x1 = 10; 85901 * let y1 = 90; 85902 * let x2 = mouseX; 85903 * let y2 = mouseY; 85904 * 85905 * line(x1, y1, x2, y2); 85906 * ellipse(x1, y1, 7, 7); 85907 * ellipse(x2, y2, 7, 7); 85908 * 85909 * // d is the length of the line 85910 * // the distance from point 1 to point 2. 85911 * let d = dist(x1, y1, x2, y2); 85912 * 85913 * // Let's write d along the line we are drawing! 85914 * push(); 85915 * translate((x1 + x2) / 2, (y1 + y2) / 2); 85916 * rotate(atan2(y2 - y1, x2 - x1));
85917 * text(nfc(d, 1), 0, -5); 85918 * pop(); 85919 * // Fancy! 85920 * 85921 * describe(`2 ellipses joined by line. 1 ellipse moves with 85922 * mouse X&Y. Distance displayed.`); 85923 * } 85924 * </code></div> 85925 */ 85926 /** 85927 * @method dist 85928 * @param {Number} x1 85929 * @param {Number} y1 85930 * @param {Number} z1 z-coordinate of the first point 85931 * @param {Number} x2 85932 * @param {Number} y2 85933 * @param {Number} z2 z-coordinate of the second point 85934 * @return {Number} distance between the two points 85935 */ 85936 _main.default.prototype.dist = function () { 85937 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 85938 args[_key] = arguments[_key]; 85939 } 85940 _main.default._validateParameters('dist', args); 85941 if (args.length === 4) { 85942 //2D 85943 return hypot(args[2] - args[0], args[3] - args[1]); 85944 } else if (args.length === 6) { 85945 //3D 85946 return hypot(args[3] - args[0], args[4] - args[1], args[5] - args[2]); 85947 } 85948 }; 85949 /** 85950 * Returns Euler's number e (2.71828...) raised to the power of the n 85951 * parameter. Maps to Math.exp(). 85952 * 85953 * @method exp 85954 * @param {Number} n exponent to raise 85955 * @return {Number} e^n 85956 * @example 85957 * <div><code> 85958 * function draw() { 85959 * background(200); 85960 * 85961 * // Compute the exp() function with a value between 0 and 2 85962 * let xValue = map(mouseX, 0, width, 0, 2); 85963 * let yValue = exp(xValue); 85964 * 85965 * let y = map(yValue, 0, 8, height, 0); 85966 * 85967 * let legend = 'exp (' + nfc(xValue, 3) + ')\n= ' + nf(yValue, 1, 4); 85968 * stroke(150); 85969 * line(mouseX, y, mouseX, height); 85970 * fill(0); 85971 * text(legend, 5, 15); 85972 * noStroke(); 85973 * ellipse(mouseX, y, 7, 7); 85974 * 85975 * // Draw the exp(x) curve, 85976 * // over the domain of x from 0 to 2 85977 * noFill(); 85978 * stroke(0); 85979 * beginShape(); 85980 * for (let x = 0; x < width; x++) { 85981 * xValue = map(x, 0, width, 0, 2); 85982 * yValue = exp(xValue); 85983 * y = map(yValue, 0, 8, height, 0); 85984 * vertex(x, y); 85985 * } 85986 * 85987 * endShape(); 85988 * line(0, 0, 0, height); 85989 * line(0, height - 1, width, height - 1); 85990 * 85991 * describe('ellipse moves along a curve with mouse x. e^n displayed.'); 85992 * } 85993 * </code></div> 85994 */ 85995 _main.default.prototype.exp = Math.exp; 85996 /** 85997 * Calculates the closest int value that is less than or equal to the 85998 * value of the parameter. Maps to Math.floor(). 85999 * 86000 * @method floor 86001 * @param {Number} n number to round down 86002 * @return {Integer} rounded down number 86003 * @example 86004 * <div><code> 86005 * function draw() { 86006 * background(200); 86007 * //map, mouseX between 0 and 5. 86008 * let ax = map(mouseX, 0, 100, 0, 5); 86009 * let ay = 66; 86010 * 86011 * //Get the floor of the mapped number. 86012 * let bx = floor(map(mouseX, 0, 100, 0, 5)); 86013 * let by = 33; 86014 * 86015 * // Multiply the mapped numbers by 20 to more easily 86016 * // see the changes. 86017 * stroke(0); 86018 * fill(0); 86019 * line(0, ay, ax * 20, ay); 86020 * line(0, by, bx * 20, by); 86021 * 86022 * // Reformat the float returned by map and draw it. 86023 * noStroke(); 86024 * text(nfc(ax, 2), ax, ay - 5); 86025 * text(nfc(bx, 1), bx, by - 5); 86026 * 86027 * describe(`2 horizontal lines & number sets. 86028 * increase with mouse x. bottom to 2 decimals`); 86029 * } 86030 * </code></div> 86031 */ 86032 _main.default.prototype.floor = Math.floor; 86033 /** 86034 * Calculates a number between two numbers at a specific increment. The amt 86035 * parameter is the amount to interpolate between the two values where 0.0 86036 * is equal to the first point, 0.1 is very near the first point, 0.5 is 86037 * half-way in between, and 1.0 is equal to the second point. If the 86038 * value of amt is more than 1.0 or less than 0.0, the number will be 86039 * calculated accordingly in the ratio of the two given numbers. The lerp() 86040 * function is convenient for creating motion along a straight 86041 * path and for drawing dotted lines. 86042 * 86043 * @method lerp 86044 * @param {Number} start first value 86045 * @param {Number} stop second value 86046 * @param {Number} amt number 86047 * @return {Number} lerped value 86048 * @example 86049 * <div><code> 86050 * function setup() { 86051 * background(200); 86052 * let a = 20; 86053 * let b = 80; 86054 * let c = lerp(a, b, 0.2); 86055 * let d = lerp(a, b, 0.5); 86056 * let e = lerp(a, b, 0.8); 86057 * 86058 * let y = 50; 86059 * 86060 * strokeWeight(5); 86061 * stroke(0); // Draw the original points in black 86062 * point(a, y); 86063 * point(b, y); 86064 * 86065 * stroke(100); // Draw the lerp points in gray 86066 * point(c, y); 86067 * point(d, y); 86068 * point(e, y); 86069 * 86070 * describe(`5 points horizontally staggered mid-canvas. 86071 * mid 3 are grey, outer black`); 86072 * } 86073 * </code></div> 86074 */ 86075 _main.default.prototype.lerp = function (start, stop, amt) { 86076 _main.default._validateParameters('lerp', arguments); 86077 return amt * (stop - start) + start; 86078 }; 86079 /** 86080 * Calculates the natural logarithm (the base-e logarithm) of a number. This 86081 * function expects the n parameter to be a value greater than 0.0. Maps to 86082 * Math.log(). 86083 * 86084 * @method log 86085 * @param {Number} n number greater than 0 86086 * @return {Number} natural logarithm of n 86087 * @example 86088 * <div><code> 86089 * function draw() { 86090 * background(200); 86091 * let maxX = 2.8; 86092 * let maxY = 1.5; 86093 * 86094 * // Compute the natural log of a value between 0 and maxX 86095 * let xValue = map(mouseX, 0, width, 0, maxX); 86096 * let yValue, y; 86097 * if (xValue > 0) { 86098 // Cannot take the log of a negative number. 86099 * yValue = log(xValue); 86100 * y = map(yValue, -maxY, maxY, height, 0); 86101 * 86102 * // Display the calculation occurring. 86103 * let legend = 'log(' + nf(xValue, 1, 2) + ')\n= ' + nf(yValue, 1, 3); 86104 * stroke(150); 86105 * line(mouseX, y, mouseX, height); 86106 * fill(0); 86107 * text(legend, 5, 15); 86108 * noStroke(); 86109 * ellipse(mouseX, y, 7, 7); 86110 * } 86111 * 86112 * // Draw the log(x) curve, 86113 * // over the domain of x from 0 to maxX 86114 * noFill(); 86115 * stroke(0); 86116 * beginShape(); 86117 * for (let x = 0; x < width; x++) { 86118 * xValue = map(x, 0, width, 0, maxX); 86119 * yValue = log(xValue); 86120 * y = map(yValue, -maxY, maxY, height, 0); 86121 * vertex(x, y); 86122 * } 86123 * endShape(); 86124 * line(0, 0, 0, height); 86125 * line(0, height / 2, width, height / 2); 86126 * 86127 * describe(`ellipse moves along a curve with mouse x. 86128 * natural logarithm of n displayed.`); 86129 * } 86130 * </code></div> 86131 */ 86132 _main.default.prototype.log = Math.log; 86133 /** 86134 * Calculates the magnitude (or length) of a vector. A vector is a direction 86135 * in space commonly used in computer graphics and linear algebra. Because it 86136 * has no "start" position, the magnitude of a vector can be thought of as 86137 * the distance from the coordinate 0,0 to its x,y value. Therefore, <a href="#/p5/mag">mag()</a> is 86138 * a shortcut for writing dist(0, 0, x, y). 86139 * 86140 * @method mag 86141 * @param {Number} a first value 86142 * @param {Number} b second value 86143 * @return {Number} magnitude of vector from (0,0) to (a,b) 86144 * @example 86145 * <div><code> 86146 * function setup() { 86147 * let x1 = 20; 86148 * let x2 = 80; 86149 * let y1 = 30; 86150 * let y2 = 70; 86151 * 86152 * line(0, 0, x1, y1); 86153 * print(mag(x1, y1)); // Prints "36.05551275463989" 86154 * line(0, 0, x2, y1); 86155 * print(mag(x2, y1)); // Prints "85.44003745317531" 86156 * line(0, 0, x1, y2); 86157 * print(mag(x1, y2)); // Prints "72.80109889280519" 86158 * line(0, 0, x2, y2); 86159 * print(mag(x2, y2)); // Prints "106.3014581273465" 86160 * 86161 * describe('4 lines of different length radiate from top left of canvas.'); 86162 * } 86163 * </code></div> 86164 */ 86165 _main.default.prototype.mag = function (x, y) { 86166 _main.default._validateParameters('mag', arguments); 86167 return hypot(x, y); 86168 }; 86169 /** 86170 * Re-maps a number from one range to another. 86171 * 86172 * In the first example above, the number 25 is converted from a value in the 86173 * range of 0 to 100 into a value that ranges from the left edge of the 86174 * window (0) to the right edge (width). 86175 * 86176 * @method map 86177 * @param {Number} value the incoming value to be converted 86178 * @param {Number} start1 lower bound of the value's current range 86179 * @param {Number} stop1 upper bound of the value's current range 86180 * @param {Number} start2 lower bound of the value's target range 86181 * @param {Number} stop2 upper bound of the value's target range 86182 * @param {Boolean} [withinBounds] constrain the value to the newly mapped range 86183 * @return {Number} remapped number 86184 * @example 86185 * <div><code> 86186 * let value = 25; 86187 * let m = map(value, 0, 100, 0, width); 86188 * ellipse(m, 50, 10, 10); 86189 * describe('10Ã10 white ellipse with in mid left canvas'); 86190</code></div> 86191 * 86192 * <div><code> 86193 * function setup() { 86194 * noStroke(); 86195 * } 86196 * 86197 * function draw() { 86198 * background(204); 86199 * let x1 = map(mouseX, 0, width, 25, 75); 86200 * ellipse(x1, 25, 25, 25); 86201 * //This ellipse is constrained to the 0-100 range 86202 * //after setting withinBounds to true 86203 * let x2 = map(mouseX, 0, width, 0, 100, true); 86204 * ellipse(x2, 75, 25, 25); 86205 * 86206 * describe(`Two 25Ã25 white ellipses move with mouse x. 86207 * Bottom has more range from X`); 86208 * } 86209</code></div> 86210 */ 86211 _main.default.prototype.map = function (n, start1, stop1, start2, stop2, withinBounds) { 86212 _main.default._validateParameters('map', arguments); 86213 var newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2; 86214 if (!withinBounds) { 86215 return newval; 86216 } 86217 if (start2 < stop2) { 86218 return this.constrain(newval, start2, stop2); 86219 } else { 86220 return this.constrain(newval, stop2, start2); 86221 } 86222 }; 86223 /** 86224 * Determines the largest value in a sequence of numbers, and then returns 86225 * that value. <a href="#/p5/max">max()</a> accepts any number of Number parameters, or an Array 86226 * of any length. 86227 * 86228 * @method max 86229 * @param {Number} n0 Number to compare 86230 * @param {Number} n1 Number to compare 86231 * @return {Number} maximum Number 86232 * @example 86233 * <div><code> 86234 * function setup() { 86235 * // Change the elements in the array and run the sketch 86236 * // to show how max() works! 86237 * let numArray = [2, 1, 5, 4, 8, 9]; 86238 * fill(0); 86239 * noStroke(); 86240 * text('Array Elements', 0, 10); 86241 * // Draw all numbers in the array 86242 * let spacing = 15; 86243 * let elemsY = 25; 86244 * for (let i = 0; i < numArray.length; i++) { 86245 * text(numArray[i], i * spacing, elemsY); 86246 * } 86247 * let maxX = 33; 86248 * let maxY = 80; 86249 * // Draw the Maximum value in the array. 86250 * textSize(32); 86251 * text(max(numArray), maxX, maxY); 86252 * 86253 * describe(`Small text at top reads: Array Elements 2 1 5 4 8 9. 86254 * Large text at center: 9`); 86255 * } 86256 * </code></div> 86257 */ 86258 /** 86259 * @method max 86260 * @param {Number[]} nums Numbers to compare 86261 * @return {Number} 86262 */ 86263 _main.default.prototype.max = function () { 86264 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 86265 args[_key2] = arguments[_key2]; 86266 } 86267 if (args[0] instanceof Array) { 86268 return Math.max.apply(null, args[0]); 86269 } else {
86270 return Math.max.apply(null, args); 86271 } 86272 }; 86273 /** 86274 * Determines the smallest value in a sequence of numbers, and then returns 86275 * that value. <a href="#/p5/min">min()</a> accepts any number of Number parameters, or an Array 86276 * of any length. 86277 * 86278 * @method min 86279 * @param {Number} n0 Number to compare 86280 * @param {Number} n1 Number to compare 86281 * @return {Number} minimum Number 86282 * @example 86283 * <div><code> 86284 * function setup() { 86285 * // Change the elements in the array and run the sketch 86286 * // to show how min() works! 86287 * let numArray = [2, 1, 5, 4, 8, 9]; 86288 * fill(0); 86289 * noStroke(); 86290 * text('Array Elements', 0, 10); 86291 * // Draw all numbers in the array 86292 * let spacing = 15; 86293 * let elemsY = 25; 86294 * for (let i = 0; i < numArray.length; i++) { 86295 * text(numArray[i], i * spacing, elemsY); 86296 * } 86297 * let maxX = 33; 86298 * let maxY = 80; 86299 * // Draw the Minimum value in the array. 86300 * textSize(32); 86301 * text(min(numArray), maxX, maxY); 86302 * 86303 * describe(`Small text at top reads: Array Elements 2 1 5 4 8 9. 86304 * Large text at center: 1`); 86305 * } 86306 * </code></div> 86307 */ 86308 /** 86309 * @method min 86310 * @param {Number[]} nums Numbers to compare 86311 * @return {Number} 86312 */ 86313 _main.default.prototype.min = function () { 86314 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 86315 args[_key3] = arguments[_key3]; 86316 } 86317 if (args[0] instanceof Array) { 86318 return Math.min.apply(null, args[0]); 86319 } else { 86320 return Math.min.apply(null, args); 86321 } 86322 }; 86323 /** 86324 * Normalizes a number from another range into a value between 0 and 1. 86325 * Identical to map(value, low, high, 0, 1). 86326 * Numbers outside of the range are not clamped to 0 and 1, because 86327 * out-of-range values are often intentional and useful. (See the example above.) 86328 * 86329 * @method norm 86330 * @param {Number} value incoming value to be normalized 86331 * @param {Number} start lower bound of the value's current range 86332 * @param {Number} stop upper bound of the value's current range 86333 * @return {Number} normalized number 86334 * @example 86335 * <div><code> 86336 * function draw() { 86337 * background(200); 86338 * let currentNum = mouseX; 86339 * let lowerBound = 0; 86340 * let upperBound = width; //100; 86341 * let normalized = norm(currentNum, lowerBound, upperBound); 86342 * let lineY = 70; 86343 * stroke(3); 86344 * line(0, lineY, width, lineY); 86345 * //Draw an ellipse mapped to the non-normalized value. 86346 * noStroke(); 86347 * fill(50); 86348 * let s = 7; // ellipse size 86349 * ellipse(currentNum, lineY, s, s); 86350 * 86351 * // Draw the guide 86352 * let guideY = lineY + 15; 86353 * text('0', 0, guideY); 86354 * textAlign(RIGHT); 86355 * text('100', width, guideY); 86356 * 86357 * // Draw the normalized value 86358 * textAlign(LEFT); 86359 * fill(0); 86360 * textSize(32); 86361 * let normalY = 40; 86362 * let normalX = 20; 86363 * text(normalized, normalX, normalY); 86364 * 86365 * describe(`ellipse moves with mouse. 0 shown left, 100 right, 86366 * and updating values center`); 86367 * } 86368 * </code></div> 86369 */ 86370 _main.default.prototype.norm = function (n, start, stop) { 86371 _main.default._validateParameters('norm', arguments); 86372 return this.map(n, start, stop, 0, 1); 86373 }; 86374 /** 86375 * Facilitates exponential expressions. The <a href="#/p5/pow">pow()</a> function is an efficient 86376 * way of multiplying numbers by themselves (or their reciprocals) in large 86377 * quantities. For example, pow(3, 5) is equivalent to the expression 86378 * 3 × 3 × 3 × 3 × 3 and pow(3, -5) is equivalent to 1 / 86379 * 3 × 3 × 3 × 3 × 3. Maps to 86380 * Math.pow(). 86381 * 86382 * @method pow 86383 * @param {Number} n base of the exponential expression 86384 * @param {Number} e power by which to raise the base 86385 * @return {Number} n^e 86386 * @example 86387 * <div><code> 86388 * function setup() { 86389 * //Exponentially increase the size of an ellipse. 86390 * let eSize = 3; // Original Size 86391 * let eLoc = 10; // Original Location 86392 * 86393 * ellipse(eLoc, eLoc, eSize, eSize); 86394 * 86395 * ellipse(eLoc * 2, eLoc * 2, pow(eSize, 2), pow(eSize, 2)); 86396 * 86397 * ellipse(eLoc * 4, eLoc * 4, pow(eSize, 3), pow(eSize, 3)); 86398 * 86399 * ellipse(eLoc * 8, eLoc * 8, pow(eSize, 4), pow(eSize, 4)); 86400 * 86401 * describe('small to large ellipses radiating from top left of canvas'); 86402 * } 86403 * </code></div> 86404 */ 86405 _main.default.prototype.pow = Math.pow; 86406 /** 86407 * Calculates the integer closest to the n parameter. For example, 86408 * round(133.8) returns the value 134. Maps to Math.round(). 86409 * 86410 * @method round 86411 * @param {Number} n number to round 86412 * @param {Number} [decimals] number of decimal places to round to, default is 0 86413 * @return {Integer} rounded number 86414 * @example 86415 * <div><code> 86416 * let x = round(3.7); 86417 * text(x, width / 2, height / 2); 86418 * describe('"4" written in middle of canvas'); 86419 * </code></div> 86420 * <div><code> 86421 * let x = round(12.782383, 2); 86422 * text(x, width / 2, height / 2); 86423 * describe('"12.78" written in middle of canvas'); 86424 * </code></div> 86425 * <div><code> 86426 * function draw() { 86427 * background(200); 86428 * //map, mouseX between 0 and 5. 86429 * let ax = map(mouseX, 0, 100, 0, 5); 86430 * let ay = 66; 86431 * 86432 * // Round the mapped number. 86433 * let bx = round(map(mouseX, 0, 100, 0, 5)); 86434 * let by = 33; 86435 * 86436 * // Multiply the mapped numbers by 20 to more easily 86437 * // see the changes. 86438 * stroke(0); 86439 * fill(0); 86440 * line(0, ay, ax * 20, ay); 86441 * line(0, by, bx * 20, by); 86442 * 86443 * // Reformat the float returned by map and draw it. 86444 * noStroke(); 86445 * text(nfc(ax, 2), ax, ay - 5); 86446 * text(nfc(bx, 1), bx, by - 5); 86447 * 86448 * describe('two horizontal lines rounded values displayed on top.'); 86449 * } 86450 * </code></div> 86451 */ 86452 _main.default.prototype.round = function (n, decimals) { 86453 if (!decimals) { 86454 return Math.round(n); 86455 } 86456 var multiplier = Math.pow(10, decimals); 86457 return Math.round(n * multiplier) / multiplier; 86458 }; 86459 /** 86460 * Squares a number (multiplies a number by itself). The result is always a 86461 * positive number, as multiplying two negative numbers always yields a 86462 * positive result. For example, -1 * -1 = 1. 86463 * 86464 * @method sq 86465 * @param {Number} n number to square 86466 * @return {Number} squared number 86467 * @example 86468 * <div><code> 86469 * function draw() { 86470 * background(200); 86471 * let eSize = 7; 86472 * let x1 = map(mouseX, 0, width, 0, 10); 86473 * let y1 = 80; 86474 * let x2 = sq(x1); 86475 * let y2 = 20; 86476 * 86477 * // Draw the non-squared. 86478 * line(0, y1, width, y1); 86479 * ellipse(x1, y1, eSize, eSize); 86480 * 86481 * // Draw the squared. 86482 * line(0, y2, width, y2); 86483 * ellipse(x2, y2, eSize, eSize); 86484 * 86485 * // Draw dividing line. 86486 * stroke(100); 86487 * line(0, height / 2, width, height / 2); 86488 * 86489 * // Draw text. 86490 * let spacing = 15; 86491 * noStroke(); 86492 * fill(0); 86493 * text('x = ' + x1, 0, y1 + spacing); 86494 * text('sq(x) = ' + x2, 0, y2 + spacing); 86495 * 86496 * describe(`horizontal center line squared values displayed on 86497 * top and regular on bottom.`); 86498 * } 86499 * </code></div> 86500 */ 86501 _main.default.prototype.sq = function (n) { 86502 return n * n; 86503 }; 86504 /** 86505 * Calculates the square root of a number. The square root of a number is 86506 * always positive, even though there may be a valid negative root. The 86507 * square root s of number a is such that s*s = a. It is the opposite of 86508 * squaring. Maps to Math.sqrt(). 86509 * 86510 * @method sqrt 86511 * @param {Number} n non-negative number to square root 86512 * @return {Number} square root of number 86513 * @example 86514 * <div><code> 86515 * function draw() { 86516 * background(200); 86517 * let eSize = 7; 86518 * let x1 = mouseX; 86519 * let y1 = 80; 86520 * let x2 = sqrt(x1); 86521 * let y2 = 20; 86522 * 86523 * // Draw the non-squared. 86524 * line(0, y1, width, y1); 86525 * ellipse(x1, y1, eSize, eSize); 86526 * 86527 * // Draw the squared. 86528 * line(0, y2, width, y2); 86529 * ellipse(x2, y2, eSize, eSize); 86530 * 86531 * // Draw dividing line. 86532 * stroke(100); 86533 * line(0, height / 2, width, height / 2); 86534 * 86535 * // Draw text. 86536 * noStroke(); 86537 * fill(0); 86538 * let spacing = 15; 86539 * text('x = ' + x1, 0, y1 + spacing); 86540 * text('sqrt(x) = ' + x2, 0, y2 + spacing); 86541 * 86542 * describe(`horizontal center line squareroot values displayed on 86543 * top and regular on bottom.`); 86544 * } 86545 * </code></div> 86546 */ 86547 _main.default.prototype.sqrt = Math.sqrt; // Calculate the length of the hypotenuse of a right triangle 86548 // This won't under- or overflow in intermediate steps 86549 // https://en.wikipedia.org/wiki/Hypot 86550 function hypot(x, y, z) { 86551 // Use the native implementation if it's available 86552 if (typeof Math.hypot === 'function') { 86553 return Math.hypot.apply(null, arguments); 86554 } // Otherwise use the V8 implementation 86555 // https://github.com/v8/v8/blob/8cd3cf297287e581a49e487067f5cbd991b27123/src/js/math.js#L217 86556 86557 var length = arguments.length; 86558 var args = [ 86559 ]; 86560 var max = 0; 86561 for (var i = 0; i < length; i++) { 86562 var n = arguments[i]; 86563 n = + n; 86564 if (n === Infinity || n === - Infinity) { 86565 return Infinity; 86566 } 86567 n = Math.abs(n); 86568 if (n > max) { 86569 max = n; 86570 } 86571 args[i] = n; 86572 } 86573 if (max === 0) { 86574 max = 1; 86575 } 86576 var sum = 0; 86577 var compensation = 0; 86578 for (var j = 0; j < length; j++) { 86579 var m = args[j] / max; 86580 var summand = m * m - compensation; 86581 var preliminary = sum + summand; 86582 compensation = preliminary - sum - summand; 86583 sum = preliminary; 86584 } 86585 return Math.sqrt(sum) * max; 86586 } /** 86587 * Calculates the fractional part of a number. 86588 * 86589 * @method fract 86590 * @param {Number} num Number whose fractional part needs to be found out 86591 * @returns {Number} fractional part of x, i.e, {x} 86592 * @example 86593 * <div><code> 86594 * text(7345.73472742, 10, 25); 86595 * text(fract(7345.73472742), 10, 75); 86596 * describe(`first row having a number and the second having 86597 * the fractional part of the number`); 86598 * </code></div> 86599 * 86600 * <div><code> 86601 * text(1.4215e-15, 10, 25); 86602 * text(fract(1.4215e-15), 10, 75); 86603 * describe(`first row having a number expressed in scientific 86604 * notation and the second having the fractional part of the number`); 86605 * </code></div> 86606 */ 86607 86608 _main.default.prototype.fract = function (toConvert) { 86609 _main.default._validateParameters('fract', arguments); 86610 var sign = 0; 86611 var num = Number(toConvert); 86612 if (isNaN(num) || Math.abs(num) === Infinity) { 86613 return num; 86614 } else if (num < 0) { 86615 num = - num; 86616 sign = 1; 86617 } 86618 if (String(num).includes('.') && !String(num).includes('e')) { 86619 var toFract = String(num); 86620 toFract = Number('0' + toFract.slice(toFract.indexOf('.'))); 86621 return Math.abs(sign - toFract); 86622 } else if (num < 1) { 86623 return Math.abs(sign - num); 86624 } else { 86625 return 0; 86626 } 86627 }; 86628 var _default = _main.default; 86629 exports.default = _default; 86630 }, 86631 { 86632 '../core/main': 290, 86633 'core-js/modules/es.array.includes': 174, 86634 'core-js/modules/es.array.index-of': 175, 86635 'core-js/modules/es.array.map': 179, 86636 'core-js/modules/es.array.slice': 180, 86637 'core-js/modules/es.math.hypot': 185, 86638 'core-js/modules/es.number.constructor': 187, 86639 'core-js/modules/es.string.includes': 203 86640 } 86641 ], 86642 321: [
86643 function (_dereq_, module, exports) { 86644 'use strict'; 86645 _dereq_('core-js/modules/es.array.concat'); 86646 _dereq_('core-js/modules/es.array.slice'); 86647 _dereq_('core-js/modules/es.object.to-string'); 86648 _dereq_('core-js/modules/es.reflect.construct'); 86649 _dereq_('core-js/modules/es.regexp.to-string'); 86650 _dereq_('core-js/modules/es.array.concat'); 86651 _dereq_('core-js/modules/es.array.slice'); 86652 _dereq_('core-js/modules/es.object.to-string'); 86653 _dereq_('core-js/modules/es.reflect.construct'); 86654 _dereq_('core-js/modules/es.regexp.to-string'); 86655 Object.defineProperty(exports, '__esModule', { 86656 value: true 86657 }); 86658 exports.default = void 0; 86659 var _main = _interopRequireDefault(_dereq_('../core/main')); 86660 function _interopRequireDefault(obj) { 86661 return obj && obj.__esModule ? obj : { 86662 default: 86663 obj 86664 }; 86665 } 86666 function isNativeReflectConstruct() { 86667 if (typeof Reflect === 'undefined' || !Reflect.construct) return false; 86668 if (Reflect.construct.sham) return false; 86669 if (typeof Proxy === 'function') return true; 86670 try { 86671 Date.prototype.toString.call(Reflect.construct(Date, [ 86672 ], function () { 86673 })); 86674 return true; 86675 } catch (e) { 86676 return false; 86677 } 86678 } 86679 function _construct(Parent, args, Class) { 86680 if (isNativeReflectConstruct()) { 86681 _construct = Reflect.construct; 86682 } else { 86683 _construct = function _construct(Parent, args, Class) { 86684 var a = [ 86685 null 86686 ]; 86687 a.push.apply(a, args); 86688 var Constructor = Function.bind.apply(Parent, a); 86689 var instance = new Constructor(); 86690 if (Class) _setPrototypeOf(instance, Class.prototype); 86691 return instance; 86692 }; 86693 } 86694 return _construct.apply(null, arguments); 86695 } 86696 function _setPrototypeOf(o, p) { 86697 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { 86698 o.__proto__ = p; 86699 return o; 86700 }; 86701 return _setPrototypeOf(o, p); 86702 } /** 86703 * Creates a new <a href="#/p5.Vector">p5.Vector</a> (the datatype for storing vectors). This provides a 86704 * two or three-dimensional vector, specifically a Euclidean (also known as 86705 * geometric) vector. A vector is an entity that has both magnitude and 86706 * direction. 86707 * 86708 * @method createVector 86709 * @param {Number} [x] x component of the vector 86710 * @param {Number} [y] y component of the vector 86711 * @param {Number} [z] z component of the vector 86712 * @return {p5.Vector} 86713 * @example 86714 * <div><code> 86715 * let v1; 86716 * function setup() { 86717 * createCanvas(100, 100); 86718 * stroke(255, 0, 255); 86719 * v1 = createVector(width / 2, height / 2); 86720 * } 86721 * 86722 * function draw() { 86723 * background(255); 86724 * line(v1.x, v1.y, mouseX, mouseY); 86725 * describe('draws a line from center of canvas to mouse pointer position.'); 86726 * } 86727 * </code></div> 86728 */ 86729 86730 _main.default.prototype.createVector = function (x, y, z) { 86731 if (this instanceof _main.default) { 86732 return _construct(_main.default.Vector, [ 86733 this._fromRadians.bind(this), 86734 this._toRadians.bind(this) 86735 ].concat(Array.prototype.slice.call(arguments))); 86736 } else { 86737 return new _main.default.Vector(x, y, z); 86738 } 86739 }; 86740 var _default = _main.default; 86741 exports.default = _default; 86742 }, 86743 { 86744 '../core/main': 290, 86745 'core-js/modules/es.array.concat': 167, 86746 'core-js/modules/es.array.slice': 180, 86747 'core-js/modules/es.object.to-string': 195, 86748 'core-js/modules/es.reflect.construct': 197, 86749 'core-js/modules/es.regexp.to-string': 200 86750 } 86751 ], 86752 322: [ 86753 function (_dereq_, module, exports) { 86754 'use strict'; 86755 Object.defineProperty(exports, '__esModule', { 86756 value: true 86757 }); 86758 exports.default = void 0; 86759 var _main = _interopRequireDefault(_dereq_('../core/main')); 86760 function _interopRequireDefault(obj) { 86761 return obj && obj.__esModule ? obj : { 86762 default: 86763 obj 86764 }; 86765 } ////////////////////////////////////////////////////////////// 86766 // http://mrl.nyu.edu/~perlin/noise/ 86767 // Adapting from PApplet.java 86768 // which was adapted from toxi 86769 // which was adapted from the german demo group farbrausch 86770 // as used in their demo "art": http://www.farb-rausch.de/fr010src.zip 86771 // someday we might consider using "improved noise" 86772 // http://mrl.nyu.edu/~perlin/paper445.pdf 86773 // See: https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/ 86774 // blob/main/introduction/Noise1D/noise.js 86775 /** 86776 * @module Math 86777 * @submodule Noise 86778 * @for p5 86779 * @requires core 86780 */ 86781 86782 var PERLIN_YWRAPB = 4; 86783 var PERLIN_YWRAP = 1 << PERLIN_YWRAPB; 86784 var PERLIN_ZWRAPB = 8; 86785 var PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB; 86786 var PERLIN_SIZE = 4095; 86787 var perlin_octaves = 4; // default to medium smooth 86788 var perlin_amp_falloff = 0.5; // 50% reduction/octave 86789 var scaled_cosine = function scaled_cosine(i) { 86790 return 0.5 * (1 - Math.cos(i * Math.PI)); 86791 }; 86792 var perlin; // will be initialized lazily by noise() or noiseSeed() 86793 /** 86794 * Returns the Perlin noise value at specified coordinates. Perlin noise is 86795 * a random sequence generator producing a more naturally ordered, harmonic 86796 * succession of numbers compared to the standard <a href="#/p5/random">random()</a> function.
86797 * It was invented by Ken Perlin in the 1980s and been used since in 86798 * graphical applications to produce procedural textures, natural motion, 86799 * shapes, terrains etc.<br /><br /> The main difference to the 86800 * <a href="#/p5/random">random()</a> function is that Perlin noise is defined in an infinite 86801 * n-dimensional space where each pair of coordinates corresponds to a 86802 * fixed semi-random value (fixed only for the lifespan of the program; see 86803 * the <a href="#/p5/noiseSeed">noiseSeed()</a> function). p5.js can compute 1D, 2D and 3D noise, 86804 * depending on the number of coordinates given. The resulting value will 86805 * always be between 0.0 and 1.0. The noise value can be animated by moving 86806 * through the noise space as demonstrated in the example above. The 2nd 86807 * and 3rd dimensions can also be interpreted as time.<br /><br />The actual 86808 * noise is structured similar to an audio signal, in respect to the 86809 * function's use of frequencies. Similar to the concept of harmonics in 86810 * physics, Perlin noise is computed over several octaves which are added 86811 * together for the final result. <br /><br />Another way to adjust the 86812 * character of the resulting sequence is the scale of the input 86813 * coordinates. As the function works within an infinite space the value of 86814 * the coordinates doesn't matter as such, only the distance between 86815 * successive coordinates does (eg. when using <a href="#/p5/noise">noise()</a> within a 86816 * loop). As a general rule the smaller the difference between coordinates, 86817 * the smoother the resulting noise sequence will be. Steps of 0.005-0.03 86818 * work best for most applications, but this will differ depending on use. 86819 * 86820 * @method noise 86821 * @param {Number} x x-coordinate in noise space 86822 * @param {Number} [y] y-coordinate in noise space 86823 * @param {Number} [z] z-coordinate in noise space 86824 * @return {Number} Perlin noise value (between 0 and 1) at specified 86825 * coordinates 86826 * @example 86827 * <div> 86828 * <code> 86829 * let xoff = 0.0; 86830 * 86831 * function draw() { 86832 * background(204); 86833 * xoff = xoff + 0.01; 86834 * let n = noise(xoff) * width; 86835 * line(n, 0, n, height); 86836 * describe(`vertical line moves left to right with updating 86837 * noise values.`); 86838 * } 86839 * </code> 86840 * </div> 86841 * <div> 86842 * <code>let noiseScale=0.02; 86843 * 86844 * function draw() { 86845 * background(0); 86846 * for (let x=0; x < width; x++) { 86847 * let noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale); 86848 * stroke(noiseVal*255); 86849 * line(x, mouseY+noiseVal*80, x, height); 86850 * } 86851 * describe(`horizontal wave pattern effected by mouse x-position 86852 * & updating noise values.`); 86853 * } 86854 * </code> 86855 * </div> 86856 */ 86857 _main.default.prototype.noise = function (x) { 86858 var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; 86859 var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; 86860 if (perlin == null) { 86861 perlin = new Array(PERLIN_SIZE + 1); 86862 for (var i = 0; i < PERLIN_SIZE + 1; i++) { 86863 perlin[i] = Math.random(); 86864 } 86865 } 86866 if (x < 0) { 86867 x = - x; 86868 } 86869 if (y < 0) { 86870 y = - y; 86871 } 86872 if (z < 0) { 86873 z = - z; 86874 } 86875 var xi = Math.floor(x), 86876 yi = Math.floor(y), 86877 zi = Math.floor(z); 86878 var xf = x - xi; 86879 var yf = y - yi; 86880 var zf = z - zi; 86881 var rxf, 86882 ryf; 86883 var r = 0; 86884 var ampl = 0.5; 86885 var n1, 86886 n2, 86887 n3; 86888 for (var o = 0; o < perlin_octaves; o++) { 86889 var of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB); 86890 rxf = scaled_cosine(xf); 86891 ryf = scaled_cosine(yf); 86892 n1 = perlin[of & PERLIN_SIZE]; 86893 n1 += rxf * (perlin[of + 1 & PERLIN_SIZE] - n1); 86894 n2 = perlin[of + PERLIN_YWRAP & PERLIN_SIZE]; 86895 n2 += rxf * (perlin[of + PERLIN_YWRAP + 1 & PERLIN_SIZE] - n2); 86896 n1 += ryf * (n2 - n1); 86897 of += PERLIN_ZWRAP; 86898 n2 = perlin[of & PERLIN_SIZE]; 86899 n2 += rxf * (perlin[of + 1 & PERLIN_SIZE] - n2); 86900 n3 = perlin[of + PERLIN_YWRAP & PERLIN_SIZE]; 86901 n3 += rxf * (perlin[of + PERLIN_YWRAP + 1 & PERLIN_SIZE] - n3); 86902 n2 += ryf * (n3 - n2); 86903 n1 += scaled_cosine(zf) * (n2 - n1); 86904 r += n1 * ampl; 86905 ampl *= perlin_amp_falloff; 86906 xi <<= 1; 86907 xf *= 2; 86908 yi <<= 1; 86909 yf *= 2; 86910 zi <<= 1; 86911 zf *= 2; 86912 if (xf >= 1) { 86913 xi++; 86914 xf--; 86915 } 86916 if (yf >= 1) { 86917 yi++; 86918 yf--; 86919 } 86920 if (zf >= 1) { 86921 zi++; 86922 zf--; 86923 } 86924 } 86925 return r; 86926 }; 86927 /** 86928 * 86929 * Adjusts the character and level of detail produced by the Perlin noise 86930 * function. Similar to harmonics in physics, noise is computed over 86931 * several octaves. Lower octaves contribute more to the output signal and 86932 * as such define the overall intensity of the noise, whereas higher octaves 86933 * create finer-grained details in the noise sequence. 86934 * 86935 * By default, noise is computed over 4 octaves with each octave contributing 86936 * exactly half as much as its predecessor, starting at 50% strength for the 1st 86937 * octave. This falloff amount can be changed by adding an additional function 86938 * parameter. Eg. a falloff factor of 0.75 means each octave will now have 86939 * 75% impact (25% less) of the previous lower octave. Any value between 86940 * 0.0 and 1.0 is valid, however, note that values greater than 0.5 might 86941 * result in greater than 1.0 values returned by <a href="#/p5/noise">noise()</a>. 86942 * 86943 * By changing these parameters, the signal created by the <a href="#/p5/noise">noise()</a> 86944 * function can be adapted to fit very specific needs and characteristics. 86945 * 86946 * @method noiseDetail 86947 * @param {Number} lod number of octaves to be used by the noise 86948 * @param {Number} falloff falloff factor for each octave 86949 * @example 86950 * <div> 86951 * <code> 86952 * let noiseVal; 86953 * let noiseScale = 0.02; 86954 * 86955 * function setup() { 86956 * createCanvas(100, 100); 86957 * } 86958 * 86959 * function draw() { 86960 * background(0); 86961 * for (let y = 0; y < height; y++) { 86962 * for (let x = 0; x < width / 2; x++) { 86963 * noiseDetail(2, 0.2); 86964 * noiseVal = noise((mouseX + x) * noiseScale, (mouseY + y) * noiseScale); 86965 * stroke(noiseVal * 255); 86966 * point(x, y); 86967 * noiseDetail(8, 0.65); 86968 * noiseVal = noise( 86969 * (mouseX + x + width / 2) * noiseScale, 86970 * (mouseY + y) * noiseScale 86971 * ); 86972 * stroke(noiseVal * 255); 86973 * point(x + width / 2, y); 86974 * } 86975 * } 86976 * describe(`2 vertical grey smokey patterns affected by 86977 * mouse x-position and noise.`); 86978 * } 86979 * </code> 86980 * </div> 86981 */ 86982 _main.default.prototype.noiseDetail = function (lod, falloff) { 86983 if (lod > 0) { 86984 perlin_octaves = lod; 86985 } 86986 if (falloff > 0) { 86987 perlin_amp_falloff = falloff; 86988 } 86989 }; 86990 /** 86991 * Sets the seed value for <a href="#/p5/noise">noise()</a>. By default, 86992 * <a href="#/p5/noise">noise()</a> produces different results each time 86993 * the program is run. Set the `seed` parameter to a constant to return
86994 * the same pseudo-random numbers each time the software is run. 86995 * 86996 * @method noiseSeed 86997 * @param {Number} seed the seed value 86998 * @example 86999 * <div> 87000 * <code>let xoff = 0.0; 87001 * 87002 * function setup() { 87003 * noiseSeed(99); 87004 * stroke(0, 10); 87005 * } 87006 * 87007 * function draw() { 87008 * xoff = xoff + .01; 87009 * let n = noise(xoff) * width; 87010 * line(n, 0, n, height); 87011 * describe(`vertical grey lines drawing in pattern affected by noise.`); 87012 * } 87013 * </code> 87014 * </div> 87015 */ 87016 _main.default.prototype.noiseSeed = function (seed) { 87017 // Linear Congruential Generator 87018 // Variant of a Lehman Generator 87019 var lcg = function () { 87020 // Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes 87021 // m is basically chosen to be large (as it is the max period) 87022 // and for its relationships to a and c 87023 var m = 4294967296; // a - 1 should be divisible by m's prime factors 87024 var a = 1664525; // c and m should be co-prime 87025 var c = 1013904223; 87026 var seed, 87027 z; 87028 return { 87029 setSeed: function setSeed(val) { 87030 // pick a random seed if val is undefined or null 87031 // the >>> 0 casts the seed to an unsigned 32-bit integer 87032 z = seed = (val == null ? Math.random() * m : val) >>> 0; 87033 }, 87034 getSeed: function getSeed() { 87035 return seed; 87036 }, 87037 rand: function rand() { 87038 // define the recurrence relationship 87039 z = (a * z + c) % m; // return a float in [0, 1) 87040 // if z = m then z / m = 0 therefore (z % m) / m < 1 always 87041 return z / m; 87042 } 87043 }; 87044 }(); 87045 lcg.setSeed(seed); 87046 perlin = new Array(PERLIN_SIZE + 1); 87047 for (var i = 0; i < PERLIN_SIZE + 1; i++) { 87048 perlin[i] = lcg.rand(); 87049 } 87050 }; 87051 var _default = _main.default; 87052 exports.default = _default; 87053 }, 87054 { 87055 '../core/main': 290 87056 } 87057 ], 87058 323: [ 87059 function (_dereq_, module, exports) { 87060 'use strict'; 87061 _dereq_('core-js/modules/es.symbol'); 87062 _dereq_('core-js/modules/es.symbol.description'); 87063 _dereq_('core-js/modules/es.symbol.iterator'); 87064 _dereq_('core-js/modules/es.array.concat'); 87065 _dereq_('core-js/modules/es.array.every'); 87066 _dereq_('core-js/modules/es.array.iterator'); 87067 _dereq_('core-js/modules/es.array.slice'); 87068 _dereq_('core-js/modules/es.array.some'); 87069 _dereq_('core-js/modules/es.math.sign'); 87070 _dereq_('core-js/modules/es.number.constructor'); 87071 _dereq_('core-js/modules/es.number.is-finite'); 87072 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 87073 _dereq_('core-js/modules/es.object.to-string'); 87074 _dereq_('core-js/modules/es.regexp.to-string'); 87075 _dereq_('core-js/modules/es.string.iterator'); 87076 _dereq_('core-js/modules/es.string.sub'); 87077 _dereq_('core-js/modules/es.weak-map'); 87078 _dereq_('core-js/modules/web.dom-collections.iterator'); 87079 function _typeof2(obj) { 87080 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 87081 _typeof2 = function _typeof2(obj) { 87082 return typeof obj; 87083 }; 87084 } else { 87085 _typeof2 = function _typeof2(obj) { 87086 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 87087 }; 87088 } 87089 return _typeof2(obj); 87090 } 87091 function _typeof(obj) { 87092 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 87093 _typeof = function _typeof(obj) { 87094 return _typeof2(obj); 87095 }; 87096 } else { 87097 _typeof = function _typeof(obj) { 87098 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 87099 }; 87100 } 87101 return _typeof(obj); 87102 }
87103 _dereq_('core-js/modules/es.array.concat'); 87104 _dereq_('core-js/modules/es.array.every'); 87105 _dereq_('core-js/modules/es.array.slice'); 87106 _dereq_('core-js/modules/es.array.some'); 87107 _dereq_('core-js/modules/es.math.sign'); 87108 _dereq_('core-js/modules/es.number.constructor'); 87109 _dereq_('core-js/modules/es.number.is-finite'); 87110 _dereq_('core-js/modules/es.object.to-string'); 87111 _dereq_('core-js/modules/es.regexp.to-string'); 87112 _dereq_('core-js/modules/es.string.sub'); 87113 Object.defineProperty(exports, '__esModule', { 87114 value: true 87115 }); 87116 exports.default = void 0; 87117 var _main = _interopRequireDefault(_dereq_('../core/main')); 87118 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 87119 function _getRequireWildcardCache() { 87120 if (typeof WeakMap !== 'function') return null; 87121 var cache = new WeakMap(); 87122 _getRequireWildcardCache = function _getRequireWildcardCache() { 87123 return cache; 87124 }; 87125 return cache; 87126 } 87127 function _interopRequireWildcard(obj) { 87128 if (obj && obj.__esModule) { 87129 return obj; 87130 } 87131 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 87132 return { 87133 default: 87134 obj 87135 }; 87136 } 87137 var cache = _getRequireWildcardCache(); 87138 if (cache && cache.has(obj)) { 87139 return cache.get(obj); 87140 } 87141 var newObj = { 87142 }; 87143 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 87144 for (var key in obj) { 87145 if (Object.prototype.hasOwnProperty.call(obj, key)) { 87146 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 87147 if (desc && (desc.get || desc.set)) { 87148 Object.defineProperty(newObj, key, desc); 87149 } else { 87150 newObj[key] = obj[key]; 87151 } 87152 } 87153 } 87154 newObj.default = obj; 87155 if (cache) { 87156 cache.set(obj, newObj); 87157 } 87158 return newObj; 87159 } 87160 function _interopRequireDefault(obj) { 87161 return obj && obj.__esModule ? obj : { 87162 default: 87163 obj 87164 }; 87165 } /** 87166 * @module Math 87167 * @submodule Vector 87168 * @requires constants 87169 */ 87170 /** 87171 * A class to describe a two or three-dimensional vector, specifically 87172 * a Euclidean (also known as geometric) vector. A vector is an entity 87173 * that has both magnitude and direction. The datatype, however, stores 87174 * the components of the vector (`x`, `y` for 2D; or `x`, `y`, `z` for 3D). The magnitude 87175 * and direction can be accessed via the methods <a href="#/p5.Vector/mag">p5.Vector.mag()</a> and <a href="#/p5.Vector/heading">heading()</a>. 87176 * 87177 * In many of the p5.js examples, you will see <a href="#/p5.Vector">p5.Vector</a> used to describe a 87178 * position, velocity, or acceleration. For example, if you consider a rectangle 87179 * moving across the screen, at any given instant it has a position (a vector 87180 * that points from the origin to its location), a velocity (the rate at which 87181 * the object's position changes per time unit, expressed as a vector), and 87182 * acceleration (the rate at which the object's velocity changes per time 87183 * unit, expressed as a vector). 87184 * 87185 * Since vectors represent groupings of values, we cannot simply use 87186 * traditional addition/multiplication/etc. Instead, we'll need to do some 87187 * "vector" math, which is made easy by the methods inside the <a href="#/p5.Vector">p5.Vector</a> class. 87188 * 87189 * @class p5.Vector 87190 * @constructor 87191 * @param {Number} [x] x component of the vector 87192 * @param {Number} [y] y component of the vector 87193 * @param {Number} [z] z component of the vector 87194 * @example 87195 * <div> 87196 * <code> 87197 * let v1 = createVector(40, 50); 87198 * let v2 = createVector(40, 50); 87199 * 87200 * ellipse(v1.x, v1.y, 50, 50); 87201 * ellipse(v2.x, v2.y, 50, 50); 87202 * v1.add(v2); 87203 * ellipse(v1.x, v1.y, 50, 50); 87204 * 87205 * describe(`2 white ellipses. One center-left the other 87206 * bottom right and off canvas`); 87207 * </code> 87208 * </div> 87209 */ 87210 87211 _main.default.Vector = function Vector() { 87212 var x, 87213 y, 87214 z; // This is how it comes in with createVector() 87215 // This check if the first argument is a function 87216 if ({ 87217 }.toString.call(arguments[0]) === '[object Function]') { 87218 // In this case the vector have an associated p5 instance 87219 this.isPInst = true; 87220 this._fromRadians = arguments[0]; 87221 this._toRadians = arguments[1]; 87222 x = arguments[2] || 0; 87223 y = arguments[3] || 0; 87224 z = arguments[4] || 0; // This is what we'll get with new p5.Vector() 87225 } else { 87226 x = arguments[0] || 0; 87227 y = arguments[1] || 0; 87228 z = arguments[2] || 0; 87229 } /** 87230 * The x component of the vector 87231 * @property x {Number} 87232 */ 87233 87234 this.x = x; 87235 /** 87236 * The y component of the vector 87237 * @property y {Number} 87238 */ 87239 this.y = y; 87240 /** 87241 * The z component of the vector 87242 * @property z {Number} 87243 */ 87244 this.z = z; 87245 }; 87246 /** 87247 * Returns a string representation of a vector `v` by calling `String(v)` 87248 * or `v.toString()`. This method is useful for logging vectors in the 87249 * console. 87250 * @method toString 87251 * @return {String} 87252 * @example 87253 * <div class = "norender"> 87254 * <code> 87255 * function setup() { 87256 * let v = createVector(20, 30); 87257 * print(String(v)); // prints "p5.Vector Object : [20, 30, 0]" 87258 * } 87259 * </code> 87260 * </div> 87261 * 87262 * <div> 87263 * <code> 87264 * function draw() { 87265 * background(240); 87266 * 87267 * let v0 = createVector(0, 0); 87268 * let v1 = createVector(mouseX, mouseY); 87269 * drawArrow(v0, v1, 'black'); 87270 * 87271 * noStroke(); 87272 * text(v1.toString(), 10, 25, 90, 75); 87273 * } 87274 * 87275 * // draw an arrow for a vector at a given base position 87276 * function drawArrow(base, vec, myColor) { 87277 * push(); 87278 * stroke(myColor); 87279 * strokeWeight(3); 87280 * fill(myColor); 87281 * translate(base.x, base.y); 87282 * line(0, 0, vec.x, vec.y); 87283 * rotate(vec.heading()); 87284 * let arrowSize = 7; 87285 * translate(vec.mag() - arrowSize, 0); 87286 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 87287 * pop(); 87288 * } 87289 * </code> 87290 * </div> 87291 */ 87292 _main.default.Vector.prototype.toString = function p5VectorToString() { 87293 return 'p5.Vector Object : ['.concat(this.x, ', ').concat(this.y, ', ').concat(this.z, ']'); 87294 }; 87295 /** 87296 * Sets the `x`, `y`, and `z` components of the vector using two or three separate 87297 * variables, the data from a <a href="#/p5.Vector">p5.Vector</a>, or the values from a float array. 87298 * @method set 87299 * @param {Number} [x] The x component of the vector 87300 * @param {Number} [y] The y component of the vector 87301 * @param {Number} [z] The z component of the vector 87302 * @chainable 87303 * @example 87304 * <div class="norender"> 87305 * <code> 87306 * function setup() { 87307 * let v = createVector(1, 2, 3);
87308 * v.set(4, 5, 6); // Sets vector to [4, 5, 6] 87309 * 87310 * let v1 = createVector(0, 0, 0); 87311 * let arr = [1, 2, 3]; 87312 * v1.set(arr); // Sets vector to [1, 2, 3] 87313 * } 87314 * </code> 87315 * </div> 87316 * 87317 * <div> 87318 * <code> 87319 * let v0, v1; 87320 * function setup() { 87321 * createCanvas(100, 100); 87322 * 87323 * v0 = createVector(0, 0); 87324 * v1 = createVector(50, 50); 87325 * } 87326 * 87327 * function draw() { 87328 * background(240); 87329 * 87330 * drawArrow(v0, v1, 'black'); 87331 * v1.set(v1.x + random(-1, 1), v1.y + random(-1, 1)); 87332 * 87333 * noStroke(); 87334 * text('x: ' + round(v1.x) + ' y: ' + round(v1.y), 20, 90); 87335 * } 87336 * 87337 * // draw an arrow for a vector at a given base position 87338 * function drawArrow(base, vec, myColor) { 87339 * push(); 87340 * stroke(myColor); 87341 * strokeWeight(3); 87342 * fill(myColor); 87343 * translate(base.x, base.y); 87344 * line(0, 0, vec.x, vec.y); 87345 * rotate(vec.heading()); 87346 * let arrowSize = 7; 87347 * translate(vec.mag() - arrowSize, 0); 87348 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 87349 * pop(); 87350 * } 87351 * </code> 87352 * </div> 87353 */ 87354 /** 87355 * @method set 87356 * @param {p5.Vector|Number[]} value The vector to set 87357 * @chainable 87358 */ 87359 _main.default.Vector.prototype.set = function set(x, y, z) { 87360 if (x instanceof _main.default.Vector) { 87361 this.x = x.x || 0; 87362 this.y = x.y || 0; 87363 this.z = x.z || 0; 87364 return this; 87365 } 87366 if (x instanceof Array) { 87367 this.x = x[0] || 0; 87368 this.y = x[1] || 0; 87369 this.z = x[2] || 0; 87370 return this; 87371 } 87372 this.x = x || 0; 87373 this.y = y || 0; 87374 this.z = z || 0; 87375 return this; 87376 }; 87377 /** 87378 * Gets a copy of the vector, returns a <a href="#/p5.Vector">p5.Vector</a> object. 87379 * 87380 * @method copy 87381 * @return {p5.Vector} A copy of the <a href="#/p5.Vector">p5.Vector</a> object 87382 * @example 87383 * <div class="norender"> 87384 * <code> 87385 * let v1 = createVector(1, 2, 3); 87386 * let v2 = v1.copy(); 87387 * print(v1.x === v2.x && v1.y === v2.y && v1.z === v2.z); 87388 * // Prints "true" 87389 * </code> 87390 * </div> 87391 */ 87392 _main.default.Vector.prototype.copy = function copy() { 87393 if (this.isPInst) { 87394 return new _main.default.Vector(this._fromRadians, this._toRadians, this.x, this.y, this.z); 87395 } else { 87396 return new _main.default.Vector(this.x, this.y, this.z); 87397 } 87398 }; 87399 /** 87400 * Adds `x`, `y`, and `z` components to a vector, adds one vector to another, or
87401 * adds two independent vectors together. The version of the method that adds 87402 * two vectors together is a static method and returns a <a href="#/p5.Vector">p5.Vector</a>, the others 87403 * act directly on the vector. Additionally, you may provide arguments to this method as an array. 87404 * See the examples for more context. 87405 * 87406 * @method add 87407 * @param {Number} x The x component of the vector to be added 87408 * @param {Number} [y] The y component of the vector to be added 87409 * @param {Number} [z] The z component of the vector to be added 87410 * @chainable 87411 * @example 87412 * <div class="norender"> 87413 * <code> 87414 * let v = createVector(1, 2, 3); 87415 * v.add(4, 5, 6); 87416 * // v's components are set to [5, 7, 9] 87417 * </code> 87418 * </div> 87419 * 87420 * <div class="norender"> 87421 * <code> 87422 * let v = createVector(1, 2, 3); 87423 * // Provide arguments as an array 87424 * let arr = [4, 5, 6]; 87425 * v.add(arr); 87426 * // v's components are set to [5, 7, 9] 87427 * </code> 87428 * </div> 87429 * 87430 * <div class="norender"> 87431 * <code> 87432 * // Static method 87433 * let v1 = createVector(1, 2, 3); 87434 * let v2 = createVector(2, 3, 4); 87435 * 87436 * let v3 = p5.Vector.add(v1, v2); 87437 * // v3 has components [3, 5, 7] 87438 * print(v3); 87439 * </code> 87440 * </div> 87441 * 87442 * <div> 87443 * <code> 87444 * // red vector + blue vector = purple vector 87445 * function draw() { 87446 * background(240); 87447 * 87448 * let v0 = createVector(0, 0); 87449 * let v1 = createVector(mouseX, mouseY); 87450 * drawArrow(v0, v1, 'red'); 87451 * 87452 * let v2 = createVector(-30, 20); 87453 * drawArrow(v1, v2, 'blue'); 87454 * 87455 * let v3 = p5.Vector.add(v1, v2); 87456 * drawArrow(v0, v3, 'purple'); 87457 * } 87458 * 87459 * // draw an arrow for a vector at a given base position 87460 * function drawArrow(base, vec, myColor) { 87461 * push(); 87462 * stroke(myColor); 87463 * strokeWeight(3); 87464 * fill(myColor); 87465 * translate(base.x, base.y); 87466 * line(0, 0, vec.x, vec.y); 87467 * rotate(vec.heading()); 87468 * let arrowSize = 7; 87469 * translate(vec.mag() - arrowSize, 0); 87470 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 87471 * pop(); 87472 * } 87473 * </code> 87474 * </div> 87475 */ 87476 /** 87477 * @method add 87478 * @param {p5.Vector|Number[]} value The vector to add 87479 * @chainable 87480 */ 87481 _main.default.Vector.prototype.add = function add(x, y, z) { 87482 if (x instanceof _main.default.Vector) { 87483 this.x += x.x || 0; 87484 this.y += x.y || 0; 87485 this.z += x.z || 0; 87486 return this; 87487 } 87488 if (x instanceof Array) { 87489 this.x += x[0] || 0; 87490 this.y += x[1] || 0; 87491 this.z += x[2] || 0; 87492 return this; 87493 } 87494 this.x += x || 0; 87495 this.y += y || 0; 87496 this.z += z || 0; 87497 return this; 87498 }; /// HELPERS FOR REMAINDER METHOD 87499 var calculateRemainder2D = function calculateRemainder2D(xComponent, yComponent) { 87500 if (xComponent !== 0) { 87501 this.x = this.x % xComponent; 87502 } 87503 if (yComponent !== 0) { 87504 this.y = this.y % yComponent; 87505 } 87506 return this; 87507 }; 87508 var calculateRemainder3D = function calculateRemainder3D(xComponent, yComponent, zComponent) { 87509 if (xComponent !== 0) { 87510 this.x = this.x % xComponent; 87511 } 87512 if (yComponent !== 0) { 87513 this.y = this.y % yComponent; 87514 } 87515 if (zComponent !== 0) { 87516 this.z = this.z % zComponent; 87517 } 87518 return this; 87519 }; 87520 /** 87521 * Gives the remainder of a vector when it is divided by another vector. 87522 * See examples for more context. 87523 * 87524 * @method rem 87525 * @param {Number} x The x component of divisor vector 87526 * @param {Number} y The y component of divisor vector 87527 * @param {Number} z The z component of divisor vector 87528 * @chainable 87529 * @example 87530 * <div class='norender'> 87531 * <code> 87532 * let v = createVector(3, 4, 5); 87533 * v.rem(2, 3, 4); 87534 * // v's components are set to [1, 1, 1] 87535 * </code> 87536 * </div> 87537 * <div class="norender"> 87538 * <code> 87539 * // Static method 87540 * let v1 = createVector(3, 4, 5); 87541 * let v2 = createVector(2, 3, 4); 87542 * 87543 * let v3 = p5.Vector.rem(v1, v2); 87544 * // v3 has components [1, 1, 1] 87545 * print(v3); 87546 * </code> 87547 * </div> 87548 */ 87549 /** 87550 * @method rem 87551 * @param {p5.Vector | Number[]} value The divisor vector 87552 * @chainable 87553 */ 87554 _main.default.Vector.prototype.rem = function rem(x, y, z) { 87555 if (x instanceof _main.default.Vector) { 87556 if (Number.isFinite(x.x) && Number.isFinite(x.y) && Number.isFinite(x.z)) { 87557 var xComponent = parseFloat(x.x); 87558 var yComponent = parseFloat(x.y); 87559 var zComponent = parseFloat(x.z); 87560 return calculateRemainder3D.call(this, xComponent, yComponent, zComponent); 87561 } 87562 } else if (x instanceof Array) { 87563 if (x.every(function (element) { 87564 return Number.isFinite(element); 87565 })) { 87566 if (x.length === 2) { 87567 return calculateRemainder2D.call(this, x[0], x[1]); 87568 } 87569 if (x.length === 3) { 87570 return calculateRemainder3D.call(this, x[0], x[1], x[2]); 87571 } 87572 } 87573 } else if (arguments.length === 1) { 87574 if (Number.isFinite(arguments[0]) && arguments[0] !== 0) { 87575 this.x = this.x % arguments[0]; 87576 this.y = this.y % arguments[0]; 87577 this.z = this.z % arguments[0]; 87578 return this; 87579 } 87580 } else if (arguments.length === 2) { 87581 var vectorComponents = Array.prototype.slice.call(arguments); 87582 if (vectorComponents.every(function (element) { 87583 return Number.isFinite(element); 87584 })) { 87585 if (vectorComponents.length === 2) { 87586 return calculateRemainder2D.call(this, vectorComponents[0], vectorComponents[1]); 87587 } 87588 } 87589 } else if (arguments.length === 3) { 87590 var _vectorComponents = Array.prototype.slice.call(arguments); 87591 if (_vectorComponents.every(function (element) { 87592 return Number.isFinite(element); 87593 })) { 87594 if (_vectorComponents.length === 3) { 87595 return calculateRemainder3D.call(this, _vectorComponents[0], _vectorComponents[1], _vectorComponents[2]); 87596 } 87597 } 87598 } 87599 }; 87600 /** 87601 * Subtracts `x`, `y`, and `z` components from a vector, subtracts one vector from 87602 * another, or subtracts two independent vectors. The version of the method 87603 * that subtracts two vectors is a static method and returns a <a href="#/p5.Vector">p5.Vector</a>, the 87604 * others act directly on the vector. Additionally, you may provide arguments to this method as an array.
87605 * See the examples for more context. 87606 * 87607 * @method sub 87608 * @param {Number} x The x component of the vector to subtract 87609 * @param {Number} [y] The y component of the vector to subtract 87610 * @param {Number} [z] The z component of the vector to subtract 87611 * @chainable 87612 * @example 87613 * <div class="norender"> 87614 * <code> 87615 * let v = createVector(4, 5, 6); 87616 * v.sub(1, 1, 1); 87617 * // v's components are set to [3, 4, 5] 87618 * </code> 87619 * </div> 87620 * 87621 * <div class="norender"> 87622 * <code> 87623 * let v = createVector(4, 5, 6); 87624 * // Provide arguments as an array 87625 * let arr = [1, 1, 1]; 87626 * v.sub(arr); 87627 * // v's components are set to [3, 4, 5] 87628 * </code> 87629 * </div> 87630 * 87631 * <div class="norender"> 87632 * <code> 87633 * // Static method 87634 * let v1 = createVector(2, 3, 4); 87635 * let v2 = createVector(1, 2, 3); 87636 * 87637 * let v3 = p5.Vector.sub(v1, v2); 87638 * // v3 has components [1, 1, 1] 87639 * print(v3); 87640 * </code> 87641 * </div> 87642 * 87643 * <div> 87644 * <code> 87645 * // red vector - blue vector = purple vector 87646 * function draw() { 87647 * background(240); 87648 * 87649 * let v0 = createVector(0, 0); 87650 * let v1 = createVector(70, 50); 87651 * drawArrow(v0, v1, 'red'); 87652 * 87653 * let v2 = createVector(mouseX, mouseY); 87654 * drawArrow(v0, v2, 'blue'); 87655 * 87656 * let v3 = p5.Vector.sub(v1, v2); 87657 * drawArrow(v2, v3, 'purple'); 87658 * } 87659 * 87660 * // draw an arrow for a vector at a given base position 87661 * function drawArrow(base, vec, myColor) { 87662 * push(); 87663 * stroke(myColor); 87664 * strokeWeight(3); 87665 * fill(myColor); 87666 * translate(base.x, base.y); 87667 * line(0, 0, vec.x, vec.y); 87668 * rotate(vec.heading()); 87669 * let arrowSize = 7; 87670 * translate(vec.mag() - arrowSize, 0); 87671 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 87672 * pop(); 87673 * } 87674 * </code> 87675 * </div> 87676 */ 87677 /** 87678 * @method sub 87679 * @param {p5.Vector|Number[]} value the vector to subtract 87680 * @chainable 87681 */ 87682 _main.default.Vector.prototype.sub = function sub(x, y, z) { 87683 if (x instanceof _main.default.Vector) { 87684 this.x -= x.x || 0; 87685 this.y -= x.y || 0; 87686 this.z -= x.z || 0; 87687 return this; 87688 } 87689 if (x instanceof Array) { 87690 this.x -= x[0] || 0; 87691 this.y -= x[1] || 0; 87692 this.z -= x[2] || 0; 87693 return this; 87694 } 87695 this.x -= x || 0; 87696 this.y -= y || 0; 87697 this.z -= z || 0; 87698 return this; 87699 }; 87700 /** 87701 * Multiplies the vector by a scalar, multiplies the `x`, `y`, and `z` components from a vector, or multiplies 87702 * the `x`, `y`, and `z` components of two independent vectors. When multiplying a vector by a scalar, the `x`, `y`, 87703 * and `z` components of the vector are all multiplied by the scalar. When multiplying a vector by a vector, 87704 * the `x`, `y`, `z` components of both vectors are multiplied by each other 87705 * (for example, with two vectors `a` and `b`: `a.x * b.x`, `a.y * b.y`, `a.z * b.z`). The static version of this method 87706 * creates a new <a href="#/p5.Vector">p5.Vector</a> while the non-static version acts on the vector 87707 * directly. Additionally, you may provide arguments to this function as an array. 87708 * See the examples for more context. 87709 * 87710 * @method mult 87711 * @param {Number} n The number to multiply with the vector 87712 * @chainable 87713 * @example 87714 * <div class="norender"> 87715 * <code> 87716 * let v = createVector(1, 2, 3); 87717 * v.mult(2); 87718 * // v's components are set to [2, 4, 6] 87719 * </code> 87720 * </div> 87721 * 87722 * <div class="norender"> 87723 * <code> 87724 * let v0 = createVector(1, 2, 3); 87725 * let v1 = createVector(2, 3, 4); 87726 * v0.mult(v1); // v0's components are set to [2, 6, 12] 87727 * </code> 87728 * </div> 87729 * 87730 * <div class="norender"> 87731 * <code> 87732 * let v0 = createVector(1, 2, 3); 87733 * // Provide arguments as an array 87734 * let arr = [2, 3, 4]; 87735 * v0.mult(arr); // v0's components are set to [2, 6, 12] 87736 * </code> 87737 * </div> 87738 * 87739 * <div class="norender"> 87740 * <code> 87741 * let v0 = createVector(1, 2, 3); 87742 * let v1 = createVector(2, 3, 4); 87743 * const result = p5.Vector.mult(v0, v1); 87744 * print(result); // result's components are set to [2, 6, 12] 87745 * </code> 87746 * </div> 87747 * 87748 * <div class="norender"> 87749 * <code> 87750 * // Static method 87751 * let v1 = createVector(1, 2, 3); 87752 * let v2 = p5.Vector.mult(v1, 2); 87753 * // v2 has components [2, 4, 6] 87754 * print(v2); 87755 * </code> 87756 * </div> 87757 * 87758 * <div> 87759 * <code> 87760 * function draw() { 87761 * background(240); 87762 * 87763 * let v0 = createVector(50, 50); 87764 * let v1 = createVector(25, -25); 87765 * drawArrow(v0, v1, 'red'); 87766 * 87767 * let num = map(mouseX, 0, width, -2, 2, true); 87768 * let v2 = p5.Vector.mult(v1, num); 87769 * drawArrow(v0, v2, 'blue'); 87770 * 87771 * noStroke(); 87772 * text('multiplied by ' + num.toFixed(2), 5, 90); 87773 * } 87774 * 87775 * // draw an arrow for a vector at a given base position 87776 * function drawArrow(base, vec, myColor) { 87777 * push(); 87778 * stroke(myColor); 87779 * strokeWeight(3); 87780 * fill(myColor); 87781 * translate(base.x, base.y); 87782 * line(0, 0, vec.x, vec.y); 87783 * rotate(vec.heading()); 87784 * let arrowSize = 7; 87785 * translate(vec.mag() - arrowSize, 0); 87786 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 87787 * pop(); 87788 * } 87789 * </code> 87790 * </div> 87791 */ 87792 /** 87793 * @method mult 87794 * @param {Number} x The number to multiply with the x component of the vector 87795 * @param {Number} y The number to multiply with the y component of the vector 87796 * @param {Number} [z] The number to multiply with the z component of the vector 87797 * @chainable 87798 */ 87799 /** 87800 * @method mult 87801 * @param {Number[]} arr The array to multiply with the components of the vector 87802 * @chainable 87803 */ 87804 /** 87805 * @method mult 87806 * @param {p5.Vector} v The vector to multiply with the components of the original vector 87807 * @chainable 87808 */ 87809 _main.default.Vector.prototype.mult = function mult(x, y, z) { 87810 if (x instanceof _main.default.Vector) { 87811 // new p5.Vector will check that values are valid upon construction but it's possible 87812 // that someone could change the value of a component after creation, which is why we still 87813 // perform this check 87814 if (Number.isFinite(x.x) && Number.isFinite(x.y) && Number.isFinite(x.z) && typeof x.x === 'number' && typeof x.y === 'number' && typeof x.z === 'number') { 87815 this.x *= x.x; 87816 this.y *= x.y; 87817 this.z *= x.z; 87818 } else { 87819 console.warn('p5.Vector.prototype.mult:', 'x contains components that are either undefined or not finite numbers'); 87820 } 87821 return this; 87822 } 87823 if (x instanceof Array) { 87824 if (x.every(function (element) { 87825 return Number.isFinite(element); 87826 }) && x.every(function (element) { 87827 return typeof element === 'number'; 87828 })) { 87829 if (x.length === 1) { 87830 this.x *= x[0]; 87831 this.y *= x[0]; 87832 this.z *= x[0]; 87833 } else if (x.length === 2) { 87834 this.x *= x[0]; 87835 this.y *= x[1]; 87836 } else if (x.length === 3) { 87837 this.x *= x[0]; 87838 this.y *= x[1]; 87839 this.z *= x[2]; 87840 } 87841 } else { 87842 console.warn('p5.Vector.prototype.mult:', 'x contains elements that are either undefined or not finite numbers'); 87843 } 87844 return this; 87845 } 87846 var vectorComponents = Array.prototype.slice.call(arguments); 87847 if (vectorComponents.every(function (element) { 87848 return Number.isFinite(element); 87849 }) && vectorComponents.every(function (element) { 87850 return typeof element === 'number'; 87851 })) { 87852 if (arguments.length === 1) { 87853 this.x *= x; 87854 this.y *= x; 87855 this.z *= x; 87856 } 87857 if (arguments.length === 2) { 87858 this.x *= x; 87859 this.y *= y; 87860 } 87861 if (arguments.length === 3) { 87862 this.x *= x; 87863 this.y *= y; 87864 this.z *= z; 87865 } 87866 } else { 87867 console.warn('p5.Vector.prototype.mult:', 'x, y, or z arguments are either undefined or not a finite number'); 87868 } 87869 return this; 87870 }; 87871 /** 87872 * Divides the vector by a scalar, divides a vector by the `x`, `y`, and `z` arguments, or divides the `x`, `y`, and 87873 * `z` components of two vectors against each other. When dividing a vector by a scalar, the `x`, `y`, 87874 * and `z` components of the vector are all divided by the scalar. When dividing a vector by a vector, 87875 * the `x`, `y`, `z` components of the source vector are treated as the dividend, and the `x`, `y`, `z` components 87876 * of the argument is treated as the divisor. (For example, with two vectors 87877 * `a` and `b`: `a.x / b.x`, `a.y / b.y`, `a.z / b.z`.) If any component of the second vector is 0, a division by 0 87878 * error will be logged, unless both two vectors have 0 in their `z` components, in which case only the `x` and `y` 87879 * components will be divided. 87880 * The static version of this method creates a 87881 * new <a href="#/p5.Vector">p5.Vector</a> while the non-static version acts on the vector directly. 87882 * Additionally, you may provide arguments to this method as an array.
87883 * See the examples for more context. 87884 * 87885 * @method div 87886 * @param {number} n The number to divide the vector by 87887 * @chainable 87888 * @example 87889 * <div class="norender"> 87890 * <code> 87891 * let v = createVector(6, 4, 2); 87892 * v.div(2); //v's components are set to [3, 2, 1] 87893 * </code> 87894 * </div> 87895 * 87896 * <div class="norender"> 87897 * <code> 87898 * let v0 = createVector(9, 4, 2); 87899 * let v1 = createVector(3, 2, 4); 87900 * v0.div(v1); // v0's components are set to [3, 2, 0.5] 87901 * </code> 87902 * </div> 87903 * 87904 * <div class="norender"> 87905 * <code> 87906 * let v0 = createVector(9, 4, 2); 87907 * // Provide arguments as an array 87908 * let arr = [3, 2, 4]; 87909 * v0.div(arr); // v0's components are set to [3, 2, 0.5] 87910 * </code> 87911 * </div> 87912 * 87913 * <div class="norender"> 87914 * <code> 87915 * let v0 = createVector(9, 4, 2); 87916 * let v1 = createVector(3, 2, 4); 87917 * let result = p5.Vector.div(v0, v1); 87918 * print(result); // result's components are set to [3, 2, 0.5] 87919 * </code> 87920 * </div> 87921 * 87922 * <div class="norender"> 87923 * <code> 87924 * // Static method 87925 * let v1 = createVector(6, 4, 2); 87926 * let v2 = p5.Vector.div(v1, 2); 87927 * // v2 has components [3, 2, 1] 87928 * print(v2); 87929 * </code> 87930 * </div> 87931 * 87932 * <div> 87933 * <code> 87934 * function draw() { 87935 * background(240); 87936 * 87937 * let v0 = createVector(0, 100); 87938 * let v1 = createVector(50, -50); 87939 * drawArrow(v0, v1, 'red'); 87940 * 87941 * let num = map(mouseX, 0, width, 10, 0.5, true); 87942 * let v2 = p5.Vector.div(v1, num); 87943 * drawArrow(v0, v2, 'blue'); 87944 * 87945 * noStroke(); 87946 * text('divided by ' + num.toFixed(2), 10, 90); 87947 * } 87948 * 87949 * // draw an arrow for a vector at a given base position 87950 * function drawArrow(base, vec, myColor) { 87951 * push(); 87952 * stroke(myColor); 87953 * strokeWeight(3); 87954 * fill(myColor); 87955 * translate(base.x, base.y); 87956 * line(0, 0, vec.x, vec.y); 87957 * rotate(vec.heading()); 87958 * let arrowSize = 7; 87959 * translate(vec.mag() - arrowSize, 0); 87960 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 87961 * pop(); 87962 * } 87963 * </code> 87964 * </div> 87965 */ 87966 /** 87967 * @method div 87968 * @param {Number} x The number to divide with the x component of the vector 87969 * @param {Number} y The number to divide with the y component of the vector 87970 * @param {Number} [z] The number to divide with the z component of the vector 87971 * @chainable 87972 */ 87973 /** 87974 * @method div 87975 * @param {Number[]} arr The array to divide the components of the vector by 87976 * @chainable 87977 */ 87978 /** 87979 * @method div 87980 * @param {p5.Vector} v The vector to divide the components of the original vector by 87981 * @chainable 87982 */ 87983 _main.default.Vector.prototype.div = function div(x, y, z) { 87984 if (x instanceof _main.default.Vector) { 87985 // new p5.Vector will check that values are valid upon construction but it's possible 87986 // that someone could change the value of a component after creation, which is why we still 87987 // perform this check 87988 if (Number.isFinite(x.x) && Number.isFinite(x.y) && Number.isFinite(x.z) && typeof x.x === 'number' && typeof x.y === 'number' && typeof x.z === 'number') { 87989 var isLikely2D = x.z === 0 && this.z === 0; 87990 if (x.x === 0 || x.y === 0 || !isLikely2D && x.z === 0) { 87991 console.warn('p5.Vector.prototype.div:', 'divide by 0'); 87992 return this; 87993 } 87994 this.x /= x.x; 87995 this.y /= x.y; 87996 if (!isLikely2D) { 87997 this.z /= x.z; 87998 } 87999 } else { 88000 console.warn('p5.Vector.prototype.div:', 'x contains components that are either undefined or not finite numbers'); 88001 } 88002 return this; 88003 } 88004 if (x instanceof Array) { 88005 if (x.every(function (element) { 88006 return Number.isFinite(element); 88007 }) && x.every(function (element) { 88008 return typeof element === 'number'; 88009 })) { 88010 if (x.some(function (element) { 88011 return element === 0; 88012 })) { 88013 console.warn('p5.Vector.prototype.div:', 'divide by 0'); 88014 return this; 88015 } 88016 if (x.length === 1) { 88017 this.x /= x[0]; 88018 this.y /= x[0]; 88019 this.z /= x[0]; 88020 } else if (x.length === 2) { 88021 this.x /= x[0]; 88022 this.y /= x[1]; 88023 } else if (x.length === 3) { 88024 this.x /= x[0]; 88025 this.y /= x[1]; 88026 this.z /= x[2]; 88027 } 88028 } else { 88029 console.warn('p5.Vector.prototype.div:', 'x contains components that are either undefined or not finite numbers'); 88030 } 88031 return this; 88032 } 88033 var vectorComponents = Array.prototype.slice.call(arguments); 88034 if (vectorComponents.every(function (element) { 88035 return Number.isFinite(element); 88036 }) && vectorComponents.every(function (element) { 88037 return typeof element === 'number'; 88038 })) { 88039 if (vectorComponents.some(function (element) { 88040 return element === 0; 88041 })) {
88042 console.warn('p5.Vector.prototype.div:', 'divide by 0'); 88043 return this; 88044 } 88045 if (arguments.length === 1) { 88046 this.x /= x; 88047 this.y /= x; 88048 this.z /= x; 88049 } 88050 if (arguments.length === 2) { 88051 this.x /= x; 88052 this.y /= y; 88053 } 88054 if (arguments.length === 3) { 88055 this.x /= x; 88056 this.y /= y; 88057 this.z /= z; 88058 } 88059 } else { 88060 console.warn('p5.Vector.prototype.div:', 'x, y, or z arguments are either undefined or not a finite number'); 88061 } 88062 return this; 88063 }; 88064 /** 88065 * Calculates the magnitude (length) of the vector and returns the result as 88066 * a float. (This is simply the equation `sqrt(x*x + y*y + z*z)`.) 88067 * 88068 * @method mag 88069 * @return {Number} The magnitude of the vector 88070 * @example 88071 * <div> 88072 * <code> 88073 * function draw() { 88074 * background(240); 88075 * 88076 * let v0 = createVector(0, 0); 88077 * let v1 = createVector(mouseX, mouseY); 88078 * drawArrow(v0, v1, 'black'); 88079 * 88080 * noStroke(); 88081 * text('vector length: ' + v1.mag().toFixed(2), 10, 70, 90, 30); 88082 * } 88083 * 88084 * // draw an arrow for a vector at a given base position 88085 * function drawArrow(base, vec, myColor) { 88086 * push(); 88087 * stroke(myColor); 88088 * strokeWeight(3); 88089 * fill(myColor); 88090 * translate(base.x, base.y); 88091 * line(0, 0, vec.x, vec.y); 88092 * rotate(vec.heading()); 88093 * let arrowSize = 7; 88094 * translate(vec.mag() - arrowSize, 0); 88095 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88096 * pop(); 88097 * } 88098 * </code> 88099 * </div> 88100 * <div class="norender"> 88101 * <code> 88102 * let v = createVector(20.0, 30.0, 40.0); 88103 * let m = v.mag(); 88104 * print(m); // Prints "53.85164807134504" 88105 * </code> 88106 * </div> 88107 */ 88108 _main.default.Vector.prototype.mag = function mag() { 88109 return Math.sqrt(this.magSq()); 88110 }; 88111 /** 88112 * Calculates the squared magnitude of the vector and returns the result 88113 * as a float. (This is simply the equation `x*x + y*y + z*z`.) 88114 * Faster if the real length is not required in the 88115 * case of comparing vectors, etc. 88116 * 88117 * @method magSq 88118 * @return {number} The squared magnitude of the vector 88119 * @example 88120 * <div class="norender"> 88121 * <code> 88122 * // Static method 88123 * let v1 = createVector(6, 4, 2); 88124 * print(v1.magSq()); // Prints "56" 88125 * </code> 88126 * </div> 88127 * 88128 * <div> 88129 * <code> 88130 * function draw() { 88131 * background(240); 88132 * 88133 * let v0 = createVector(0, 0); 88134 * let v1 = createVector(mouseX, mouseY); 88135 * drawArrow(v0, v1, 'black'); 88136 * 88137 * noStroke(); 88138 * text('vector length squared: ' + v1.magSq().toFixed(2), 10, 45, 90, 55); 88139 * } 88140 * 88141 * // draw an arrow for a vector at a given base position 88142 * function drawArrow(base, vec, myColor) { 88143 * push(); 88144 * stroke(myColor); 88145 * strokeWeight(3); 88146 * fill(myColor); 88147 * translate(base.x, base.y); 88148 * line(0, 0, vec.x, vec.y); 88149 * rotate(vec.heading()); 88150 * let arrowSize = 7; 88151 * translate(vec.mag() - arrowSize, 0); 88152 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88153 * pop(); 88154 * } 88155 * </code> 88156 * </div> 88157 */ 88158 _main.default.Vector.prototype.magSq = function magSq() { 88159 var x = this.x; 88160 var y = this.y; 88161 var z = this.z; 88162 return x * x + y * y + z * z; 88163 }; 88164 /** 88165 * Calculates the dot product of two vectors. The version of the method 88166 * that computes the dot product of two independent vectors is a static 88167 * method. See the examples for more context. 88168 * 88169 * @method dot 88170 * @param {Number} x The x component of the vector 88171 * @param {Number} [y] The y component of the vector 88172 * @param {Number} [z] The z component of the vector 88173 * @return {Number} The dot product 88174 * 88175 * @example 88176 * <div class="norender"> 88177 * <code> 88178 * let v1 = createVector(1, 2, 3); 88179 * let v2 = createVector(2, 3, 4); 88180 * 88181 * print(v1.dot(v2)); // Prints "20" 88182 * </code> 88183 * </div> 88184 * 88185 * <div class="norender"> 88186 * <code> 88187 * //Static method 88188 * let v1 = createVector(1, 2, 3); 88189 * let v2 = createVector(3, 2, 1); 88190 * print(p5.Vector.dot(v1, v2)); // Prints "10" 88191 * </code> 88192 * </div> 88193 */ 88194 /** 88195 * @method dot 88196 * @param {p5.Vector} value value component of the vector or a <a href="#/p5.Vector">p5.Vector</a> 88197 * @return {Number} 88198 */ 88199 _main.default.Vector.prototype.dot = function dot(x, y, z) { 88200 if (x instanceof _main.default.Vector) { 88201 return this.dot(x.x, x.y, x.z); 88202 } 88203 return this.x * (x || 0) + this.y * (y || 0) + this.z * (z || 0); 88204 }; 88205 /** 88206 * Calculates and returns a vector composed of the cross product between 88207 * two vectors. Both the static and non-static methods return a new <a href="#/p5.Vector">p5.Vector</a>. 88208 * See the examples for more context. 88209 * 88210 * @method cross 88211 * @param {p5.Vector} v <a href="#/p5.Vector">p5.Vector</a> to be crossed 88212 * @return {p5.Vector} <a href="#/p5.Vector">p5.Vector</a> composed of cross product 88213 * @example 88214 * <div class="norender"> 88215 * <code> 88216 * let v1 = createVector(1, 2, 3); 88217 * let v2 = createVector(1, 2, 3); 88218 * 88219 * let v = v1.cross(v2); // v's components are [0, 0, 0] 88220 * print(v); 88221 * </code> 88222 * </div> 88223 * 88224 * <div class="norender"> 88225 * <code> 88226 * // Static method 88227 * let v1 = createVector(1, 0, 0); 88228 * let v2 = createVector(0, 1, 0); 88229 *
88230 * let crossProduct = p5.Vector.cross(v1, v2); 88231 * // crossProduct has components [0, 0, 1] 88232 * print(crossProduct); 88233 * </code> 88234 * </div> 88235 */ 88236 _main.default.Vector.prototype.cross = function cross(v) { 88237 var x = this.y * v.z - this.z * v.y; 88238 var y = this.z * v.x - this.x * v.z; 88239 var z = this.x * v.y - this.y * v.x; 88240 if (this.isPInst) { 88241 return new _main.default.Vector(this._fromRadians, this._toRadians, x, y, z); 88242 } else { 88243 return new _main.default.Vector(x, y, z); 88244 } 88245 }; 88246 /** 88247 * Calculates the Euclidean distance between two points (considering a 88248 * point as a vector object). 88249 * If you are looking to calculate distance between 2 points see <a href="#/p5/dist">dist()</a> 88250 * 88251 * @method dist 88252 * @param {p5.Vector} v The x, y, and z coordinates of a <a href="#/p5.Vector">p5.Vector</a> 88253 * @return {Number} The distance 88254 * @example 88255 * <div class="norender"> 88256 * <code> 88257 * let v1 = createVector(1, 0, 0); 88258 * let v2 = createVector(0, 1, 0); 88259 * 88260 * let distance = v1.dist(v2); // distance is 1.4142... 88261 * print(distance); 88262 * </code> 88263 * </div> 88264 * 88265 * <div class="norender"> 88266 * <code> 88267 * // Static method 88268 * let v1 = createVector(1, 0, 0); 88269 * let v2 = createVector(0, 1, 0); 88270 * 88271 * let distance = p5.Vector.dist(v1, v2); 88272 * // distance is 1.4142... 88273 * print(distance); 88274 * </code> 88275 * </div> 88276 * 88277 * <div> 88278 * <code> 88279 * function draw() { 88280 * background(240); 88281 * 88282 * let v0 = createVector(0, 0); 88283 * 88284 * let v1 = createVector(70, 50); 88285 * drawArrow(v0, v1, 'red'); 88286 * 88287 * let v2 = createVector(mouseX, mouseY); 88288 * drawArrow(v0, v2, 'blue'); 88289 * 88290 * noStroke(); 88291 * text('distance between vectors: ' + v2.dist(v1).toFixed(2), 5, 50, 95, 50); 88292 * } 88293 * 88294 * // draw an arrow for a vector at a given base position 88295 * function drawArrow(base, vec, myColor) { 88296 * push(); 88297 * stroke(myColor); 88298 * strokeWeight(3); 88299 * fill(myColor); 88300 * translate(base.x, base.y); 88301 * line(0, 0, vec.x, vec.y); 88302 * rotate(vec.heading()); 88303 * let arrowSize = 7; 88304 * translate(vec.mag() - arrowSize, 0); 88305 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88306 * pop(); 88307 * } 88308 * </code> 88309 * </div> 88310 */ 88311 _main.default.Vector.prototype.dist = function dist(v) { 88312 return v.copy().sub(this).mag(); 88313 }; 88314 /** 88315 * Normalize the vector to length 1 (make it a unit vector). 88316 * 88317 * @method normalize 88318 * @return {p5.Vector} The normalized <a href="#/p5.Vector">p5.Vector</a> 88319 * @example 88320 * <div class="norender"> 88321 * <code> 88322 * let v = createVector(10, 20, 2); 88323 * // v has components [10.0, 20.0, 2.0] 88324 * v.normalize(); 88325 * // v's components are set to 88326 * // [0.4454354, 0.8908708, 0.089087084] 88327 * </code> 88328 * </div> 88329 * 88330 * <div class="norender"> 88331 * <code> 88332 * // Static method 88333 * let v_initial = createVector(10, 20, 2); 88334 * // v_initial has components [10.0, 20.0, 2.0] 88335 * let v_normalized = p5.Vector.normalize(v_initial); 88336 * print(v_normalized); 88337 * // returns a new vector with components set to 88338 * // [0.4454354, 0.8908708, 0.089087084] 88339 * // v_initial remains unchanged 88340 * </code> 88341 * </div> 88342 * 88343 * <div> 88344 * <code> 88345 * function draw() { 88346 * background(240); 88347 * 88348 * let v0 = createVector(50, 50); 88349 * let v1 = createVector(mouseX - 50, mouseY - 50); 88350 * 88351 * drawArrow(v0, v1, 'red'); 88352 * v1.normalize(); 88353 * drawArrow(v0, v1.mult(35), 'blue'); 88354 * 88355 * noFill(); 88356 * ellipse(50, 50, 35 * 2); 88357 * } 88358 * 88359 * // draw an arrow for a vector at a given base position 88360 * function drawArrow(base, vec, myColor) { 88361 * push(); 88362 * stroke(myColor); 88363 * strokeWeight(3); 88364 * fill(myColor); 88365 * translate(base.x, base.y); 88366 * line(0, 0, vec.x, vec.y); 88367 * rotate(vec.heading()); 88368 * let arrowSize = 7; 88369 * translate(vec.mag() - arrowSize, 0); 88370 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88371 * pop(); 88372 * } 88373 * </code> 88374 * </div> 88375 */ 88376 _main.default.Vector.prototype.normalize = function normalize() { 88377 var len = this.mag(); // here we multiply by the reciprocal instead of calling 'div()' 88378 // since div duplicates this zero check. 88379 if (len !== 0) this.mult(1 / len); 88380 return this; 88381 }; 88382 /** 88383 * Limit the magnitude of this vector to the value used for the `max` 88384 * parameter. 88385 * 88386 * @method limit 88387 * @param {Number} max The maximum magnitude for the vector 88388 * @chainable 88389 * @example 88390 * <div class="norender"> 88391 * <code> 88392 * let v = createVector(10, 20, 2); 88393 * // v has components [10.0, 20.0, 2.0] 88394 * v.limit(5); 88395 * // v's components are set to 88396 * // [2.2271771, 4.4543543, 0.4454354] 88397 * </code> 88398 * </div> 88399 * <div> 88400 * <code> 88401 * function draw() { 88402 * background(240); 88403 * 88404 * let v0 = createVector(50, 50); 88405 * let v1 = createVector(mouseX - 50, mouseY - 50); 88406 * 88407 * drawArrow(v0, v1, 'red'); 88408 * drawArrow(v0, v1.limit(35), 'blue'); 88409 * 88410 * noFill(); 88411 * ellipse(50, 50, 35 * 2); 88412 * } 88413 * 88414 * // draw an arrow for a vector at a given base position 88415 * function drawArrow(base, vec, myColor) { 88416 * push(); 88417 * stroke(myColor); 88418 * strokeWeight(3); 88419 * fill(myColor); 88420 * translate(base.x, base.y); 88421 * line(0, 0, vec.x, vec.y); 88422 * rotate(vec.heading()); 88423 * let arrowSize = 7; 88424 * translate(vec.mag() - arrowSize, 0); 88425 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88426 * pop(); 88427 * } 88428 * </code> 88429 * </div> 88430 */ 88431 _main.default.Vector.prototype.limit = function limit(max) { 88432 var mSq = this.magSq(); 88433 if (mSq > max * max) { 88434 this.div(Math.sqrt(mSq)) //normalize it 88435 .mult(max); 88436 } 88437 return this; 88438 }; 88439 /** 88440 * Set the magnitude of this vector to the value used for the `len` 88441 * parameter. 88442 * 88443 * @method setMag 88444 * @param {number} len The new length for this vector 88445 * @chainable 88446 * @example 88447 * <div class="norender"> 88448 * <code> 88449 * let v = createVector(3, 4, 0); 88450 * // v has components [3.0, 4.0, 0.0] 88451 * v.setMag(10); 88452 * // v's components are set to [6.0, 8.0, 0.0] 88453 * </code> 88454 * </div> 88455 * 88456 * <div> 88457 * <code> 88458 * function draw() { 88459 * background(240); 88460 * 88461 * let v0 = createVector(0, 0); 88462 * let v1 = createVector(50, 50); 88463 * 88464 * drawArrow(v0, v1, 'red'); 88465 * 88466 * let length = map(mouseX, 0, width, 0, 141, true); 88467 * v1.setMag(length); 88468 * drawArrow(v0, v1, 'blue'); 88469 * 88470 * noStroke(); 88471 * text('magnitude set to: ' + length.toFixed(2), 10, 70, 90, 30); 88472 * } 88473 * 88474 * // draw an arrow for a vector at a given base position 88475 * function drawArrow(base, vec, myColor) { 88476 * push(); 88477 * stroke(myColor); 88478 * strokeWeight(3); 88479 * fill(myColor); 88480 * translate(base.x, base.y); 88481 * line(0, 0, vec.x, vec.y); 88482 * rotate(vec.heading()); 88483 * let arrowSize = 7; 88484 * translate(vec.mag() - arrowSize, 0); 88485 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88486 * pop(); 88487 * } 88488 * </code> 88489 * </div> 88490 */ 88491 _main.default.Vector.prototype.setMag = function setMag(n) { 88492 return this.normalize().mult(n); 88493 }; 88494 /** 88495 * Calculate the angle of rotation for this vector (only 2D vectors). 88496 * p5.Vectors created using <a href="#/p5/createVector">createVector()</a> 88497 * will take the current <a href="#/p5/angleMode">angleMode()</a> into 88498 * consideration, and give the angle in radians or degrees accordingly. 88499 * 88500 * @method heading 88501 * @return {Number} The angle of rotation 88502 * @example 88503 * <div class = "norender"> 88504 * <code> 88505 * function setup() { 88506 * let v1 = createVector(30, 50); 88507 * print(v1.heading()); // 1.0303768265243125 88508 * 88509 * v1 = createVector(40, 50); 88510 * print(v1.heading());
88510 // 0.8960553845713439 88511 * 88512 * v1 = createVector(30, 70); 88513 * print(v1.heading()); // 1.1659045405098132 88514 * } 88515 * </code> 88516 * </div> 88517 * 88518 * <div> 88519 * <code> 88520 * function draw() { 88521 * background(240); 88522 * 88523 * let v0 = createVector(50, 50); 88524 * let v1 = createVector(mouseX - 50, mouseY - 50); 88525 * 88526 * drawArrow(v0, v1, 'black'); 88527 * 88528 * let myHeading = v1.heading(); 88529 * noStroke(); 88530 * text( 88531 * 'vector heading: ' + 88532 * myHeading.toFixed(2) + 88533 * ' radians or ' + 88534 * degrees(myHeading).toFixed(2) + 88535 * ' degrees', 88536 * 10, 88537 * 50, 88538 * 90, 88539 * 50 88540 * ); 88541 * } 88542 * 88543 * // draw an arrow for a vector at a given base position 88544 * function drawArrow(base, vec, myColor) { 88545 * push(); 88546 * stroke(myColor); 88547 * strokeWeight(3); 88548 * fill(myColor); 88549 * translate(base.x, base.y); 88550 * line(0, 0, vec.x, vec.y); 88551 * rotate(vec.heading()); 88552 * let arrowSize = 7; 88553 * translate(vec.mag() - arrowSize, 0); 88554 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88555 * pop(); 88556 * } 88557 * </code> 88558 * </div> 88559 */ 88560 _main.default.Vector.prototype.heading = function heading() { 88561 var h = Math.atan2(this.y, this.x); 88562 if (this.isPInst) return this._fromRadians(h); 88563 return h; 88564 }; 88565 /** 88566 * Rotate the vector to a specific angle (only 2D vectors); magnitude remains the 88567 * same. 88568 * 88569 * @method setHeading 88570 * @param {number} angle The angle of rotation 88571 * @chainable 88572 * @example 88573 * <div class="norender"> 88574 * <code> 88575 * let v = createVector(10.0, 20.0); 88576 * // result of v.heading() is 1.1071487177940904 88577 * v.setHeading(Math.PI); 88578 * // result of v.heading() is now 3.141592653589793 88579 * </code> 88580 * </div> 88581 */ 88582 _main.default.Vector.prototype.setHeading = function setHeading(a) { 88583 if (this.isPInst) a = this._toRadians(a); 88584 var m = this.mag(); 88585 this.x = m * Math.cos(a); 88586 this.y = m * Math.sin(a); 88587 return this; 88588 }; 88589 /** 88590 * Rotate the vector by an angle (only 2D vectors); magnitude remains the 88591 * same. 88592 * 88593 * @method rotate 88594 * @param {number} angle The angle of rotation 88595 * @chainable 88596 * @example 88597 * <div class="norender"> 88598 * <code> 88599 * let v = createVector(10.0, 20.0); 88600 * // v has components [10.0, 20.0, 0.0] 88601 * v.rotate(HALF_PI); 88602 * // v's components are set to [-20.0, 9.999999, 0.0] 88603 * </code> 88604 * </div> 88605 * 88606 * <div class="norender"> 88607 * <code> 88608 * // static function implementation 88609 * let v = createVector(10.0, 20.0); 88610 * // v has components [10.0, 20.0, 0.0] 88611 * let rotated_v = p5.Vector.rotate(v, HALF_PI); 88612 * console.log(rotated_v); 88613 * // rotated_v's components are set to [-20.0, 9.999999, 0.0] 88614 * console.log(v); 88615 * // v's components remains the same (i.e, [10.0, 20.0, 0.0]) 88616 * </code> 88617 * </div> 88618 * 88619 * <div> 88620 * <code> 88621 * let angle = 0; 88622 * function draw() { 88623 * background(240); 88624 * 88625 * let v0 = createVector(50, 50); 88626 * let v1 = createVector(50, 0); 88627 * 88628 * drawArrow(v0, v1.rotate(angle), 'black'); 88629 * angle += 0.01; 88630 * } 88631 * 88632 * // draw an arrow for a vector at a given base position 88633 * function drawArrow(base, vec, myColor) { 88634 * push(); 88635 * stroke(myColor); 88636 * strokeWeight(3); 88637 * fill(myColor); 88638 * translate(base.x, base.y); 88639 * line(0, 0, vec.x, vec.y); 88640 * rotate(vec.heading()); 88641 * let arrowSize = 7; 88642 * translate(vec.mag() - arrowSize, 0); 88643 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88644 * pop(); 88645 * } 88646 * </code> 88647 * </div> 88648 */ 88649 _main.default.Vector.prototype.rotate = function rotate(a) { 88650 var newHeading = this.heading() + a; 88651 if (this.isPInst) newHeading = this._toRadians(newHeading); 88652 var mag = this.mag(); 88653 this.x = Math.cos(newHeading) * mag; 88654 this.y = Math.sin(newHeading) * mag; 88655 return this; 88656 }; 88657 /** 88658 * Calculates and returns the angle between two vectors. This method will take 88659 * the current <a href="#/p5/angleMode">angleMode</a> into consideration, and 88660 * give the angle in radians or degrees accordingly. 88661 * 88662 * @method angleBetween 88663 * @param {p5.Vector} value The x, y, and z components of a <a href="#/p5.Vector">p5.Vector</a> 88664 * @return {Number} The angle between 88665 * @example 88666 * <div class="norender"> 88667 * <code> 88668 * let v1 = createVector(1, 0, 0); 88669 * let v2 = createVector(0, 1, 0); 88670 * 88671 * let angle = v1.angleBetween(v2); 88672 * // angle is PI/2 88673 * print(angle); 88674 * </code> 88675 * </div> 88676 * 88677 * <div> 88678 * <code> 88679 * function draw() { 88680 * background(240); 88681 * let v0 = createVector(50, 50); 88682 * 88683 * let v1 = createVector(50, 0); 88684 * drawArrow(v0, v1, 'red'); 88685 * 88686 * let v2 = createVector(mouseX - 50, mouseY - 50); 88687 * drawArrow(v0, v2, 'blue'); 88688 * 88689 * let angleBetween = v1.angleBetween(v2); 88690 * noStroke(); 88691 * text( 88692 * 'angle between: ' + 88693 * angleBetween.toFixed(2) + 88694 * ' radians or ' + 88695 * degrees(angleBetween).toFixed(2) + 88696 * ' degrees', 88697 * 10, 88698 * 50, 88699 * 90, 88700 * 50 88701 * ); 88702 * } 88703 * 88704 * // draw an arrow for a vector at a given base position 88705 * function drawArrow(base, vec, myColor) { 88706 * push(); 88707 * stroke(myColor); 88708 * strokeWeight(3); 88709 * fill(myColor); 88710 * translate(base.x, base.y); 88711 * line(0, 0, vec.x, vec.y); 88712 * rotate(vec.heading()); 88713 * let arrowSize = 7; 88714 * translate(vec.mag() - arrowSize, 0); 88715 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88716 * pop(); 88717 * } 88718 * </code> 88719 * </div> 88720 */ 88721 _main.default.Vector.prototype.angleBetween = function angleBetween(v) { 88722 var dotmagmag = this.dot(v) / (this.mag() * v.mag()); // Mathematically speaking: the dotmagmag variable will be between -1 and 1 88723 // inclusive. Practically though it could be slightly outside this range due 88724 // to floating-point rounding issues. This can make Math.acos return NaN. 88725 // 88726 // Solution: we'll clamp the value to the -1,1 range 88727 var angle; 88728 angle = Math.acos(Math.min(1, Math.max( - 1, dotmagmag))); 88729 angle = angle * Math.sign(this.cross(v).z || 1); 88730 if (this.isPInst) { 88731 angle = this._fromRadians(angle); 88732 } 88733 return angle; 88734 }; 88735 /** 88736 * Linear interpolate the vector to another vector. 88737 * 88738 * @method lerp 88739 * @param {Number} x The x component 88740 * @param {Number} y The y component 88741 * @param {Number} z The z component 88742 * @param {Number} amt The amount of interpolation; some value between 0.0 88743 * (old vector) and 1.0 (new vector). 0.9 is very near 88744 * the new vector. 0.5 is halfway in between. 88745 * @chainable 88746 * 88747 * @example 88748 * <div class="norender"> 88749 * <code> 88750 * let v = createVector(1, 1, 0); 88751 * 88752 * v.lerp(3, 3, 0, 0.5); // v now has components [2,2,0] 88753 * </code> 88754 * </div> 88755 * 88756 * <div class="norender"> 88757 * <code> 88758 * let v1 = createVector(0, 0, 0); 88759 * let v2 = createVector(100, 100, 0); 88760 * 88761 * let v3 = p5.Vector.lerp(v1, v2, 0.5); 88762 * // v3 has components [50,50,0] 88763 * print(v3); 88764 * </code> 88765 * </div> 88766 * 88767 * <div> 88768 * <code> 88769 * let step = 0.01; 88770 * let amount = 0; 88771 * 88772 * function draw() { 88773 * background(240); 88774 * let v0 = createVector(0, 0); 88775 * 88776 * let v1 = createVector(mouseX, mouseY); 88777 * drawArrow(v0, v1, 'red'); 88778 * 88779 * let v2 = createVector(90, 90); 88780 * drawArrow(v0, v2, 'blue'); 88781 * 88782 * if (amount > 1 || amount < 0) { 88783 * step *= -1; 88784 * } 88785 * amount += step; 88786 * let v3 = p5.Vector.lerp(v1, v2, amount); 88787 * 88788 * drawArrow(v0, v3, 'purple'); 88789 * } 88790 * 88791 * // draw an arrow for a vector at a given base position 88792 * function drawArrow(base, vec, myColor) { 88793 * push(); 88794 * stroke(myColor); 88795 * strokeWeight(3); 88796 * fill(myColor); 88797 * translate(base.x, base.y); 88798 * line(0, 0, vec.x, vec.y); 88799 * rotate(vec.heading()); 88800 * let arrowSize = 7; 88801 * translate(vec.mag() - arrowSize, 0); 88802 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88803 * pop(); 88804 * } 88805 * </code> 88806 * </div> 88807 */ 88808 /** 88809 * @method lerp 88810 * @param {p5.Vector} v The <a href="#/p5.Vector">p5.Vector</a> to lerp to 88811 * @param {Number} amt 88812 * @chainable 88813 */ 88814 _main.default.Vector.prototype.lerp = function lerp(x, y, z, amt) { 88815 if (x instanceof _main.default.Vector) { 88816 return this.lerp(x.x, x.y, x.z, y); 88817 } 88818 this.x += (x - this.x) * amt || 0; 88819 this.y += (y - this.y) * amt || 0; 88820 this.z += (z - this.z) * amt || 0; 88821 return this; 88822 }; 88823 /** 88824 * Reflect a vector about a normal to a line in 2D, or about a normal to a 88825 * plane in 3D. 88826 * 88827 * @method reflect 88828 * @param {p5.Vector} surfaceNormal the <a href="#/p5.Vector">p5.Vector</a> 88829 * to reflect about. 88830 * @chainable 88831 * @example 88832 * <div class="norender"> 88833 * <code> 88834 * let v = createVector(4, 6); // incoming vector, this example vector is heading to the right and downward 88835 * let n = createVector(0, -1); // surface normal to a plane (this example normal points directly upwards) 88836 * v.reflect(n); // v is reflected about the surface normal n. v's components are now set to [4, -6] 88837 * </code> 88838 * </div> 88839 * 88840 * <div> 88841 * <code> 88842 * function draw() { 88843 * background(240); 88844 * 88845 * let v0 = createVector(0, 0); 88846 * let v1 = createVector(mouseX, mouseY); 88847 * drawArrow(v0, v1, 'red'); 88848 * 88849 * let n = createVector(0, -30); 88850 * drawArrow(v1, n, 'blue'); 88851 * 88852 * let r = v1.copy(); 88853 * r.reflect(n); 88854 * drawArrow(v1, r, 'purple'); 88855 * } 88856 * 88857 * // draw an arrow for a vector at a given base position 88858 * function drawArrow(base, vec, myColor) { 88859 * push(); 88860 * stroke(myColor); 88861 * strokeWeight(3); 88862 * fill(myColor); 88863 * translate(base.x, base.y); 88864 * line(0, 0, vec.x, vec.y); 88865 * rotate(vec.heading()); 88866 * let arrowSize = 7; 88867 * translate(vec.mag() - arrowSize, 0); 88868 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 88869 * pop(); 88870 * } 88871 * </code> 88872 * </div> 88873 */ 88874 _main.default.Vector.prototype.reflect = function reflect(surfaceNormal) { 88875 surfaceNormal.normalize(); 88876 return this.sub(surfaceNormal.mult(2 * this.dot(surfaceNormal))); 88877 }; 88878 /** 88879 * Return a representation of this vector as a float array. This is only 88880 * for temporary use. If used in any other fashion, the contents should be 88881 * copied by using the <b>p5.Vector.<a href="#/p5.Vector/copy">copy()</a></b> 88882 * method to copy into your own vector. 88883 * 88884 * @method array 88885 * @return {Number[]} An Array with the 3 values 88886 * @example 88887 * <div class = "norender"> 88888 * <code> 88889 * function setup() { 88890 * let v = createVector(20, 30); 88891 * print(v.array()); // Prints : Array [20, 30, 0] 88892 * } 88893 * </code> 88894 * </div> 88895 * 88896 * <div class="norender"> 88897 * <code> 88898 * let v = createVector(10.0, 20.0, 30.0); 88899 * let f = v.array(); 88900 * print(f[0]); // Prints "10.0" 88901 * print(f[1]); // Prints "20.0" 88902 * print(f[2]); // Prints "30.0" 88903 * </code> 88904 * </div> 88905 */ 88906 _main.default.Vector.prototype.array = function array() { 88907 return [this.x || 0, 88908 this.y || 0, 88909 this.z || 0]; 88910 }; 88911 /** 88912 * Equality check against a <a href="#/p5.Vector">p5.Vector</a>. 88913 * 88914 * @method equals 88915 * @param {Number} [x] The x component of the vector 88916 * @param {Number} [y] The y component of the vector 88917 * @param {Number} [z] The z component of the vector 88918 * @return {Boolean} Whether the vectors are equal 88919 * @example 88920 * <div class = "norender"> 88921 * <code> 88922 * let v1 = createVector(5, 10, 20); 88923 * let v2 = createVector(5, 10, 20); 88924 * let v3 = createVector(13, 10, 19); 88925 * 88926 * print(v1.equals(v2.x, v2.y, v2.z)); // true 88927 * print(v1.equals(v3.x, v3.y, v3.z)); // false 88928 * </code> 88929 * </div> 88930 * 88931 * <div class="norender"> 88932 * <code> 88933 * let v1 = createVector(10.0, 20.0, 30.0); 88934 * let v2 = createVector(10.0, 20.0, 30.0); 88935 * let v3 = createVector(0.0, 0.0, 0.0); 88936 * print(v1.equals(v2)); // true 88937 * print(v1.equals(v3)); // false 88938 * </code> 88939 * </div> 88940 */ 88941 /** 88942 * @method equals 88943 * @param {p5.Vector|Array} value The vector to compare 88944 * @return {Boolean} 88945 */ 88946 _main.default.Vector.prototype.equals = function equals(x, y, z) { 88947 var a, 88948 b, 88949 c; 88950 if (x instanceof _main.default.Vector) { 88951 a = x.x || 0; 88952 b = x.y || 0; 88953 c = x.z || 0; 88954 } else if (x instanceof Array) { 88955 a = x[0] || 0; 88956 b = x[1] || 0; 88957 c = x[2] || 0; 88958 } else { 88959 a = x || 0; 88960 b = y || 0; 88961 c = z || 0; 88962 } 88963 return this.x === a && this.y === b && this.z === c; 88964 }; // Static Methods 88965 /** 88966 * Make a new 2D vector from an angle. 88967 * 88968 * @method fromAngle
88969 * @static 88970 * @param {Number} angle The desired angle, in radians (unaffected by <a href="#/p5/angleMode">angleMode</a>) 88971 * @param {Number} [length] The length of the new vector (defaults to 1) 88972 * @return {p5.Vector} The new <a href="#/p5.Vector">p5.Vector</a> object 88973 * @example 88974 * <div> 88975 * <code> 88976 * function draw() { 88977 * background(200); 88978 * 88979 * // Create a variable, proportional to the mouseX, 88980 * // varying from 0-360, to represent an angle in degrees. 88981 * let myDegrees = map(mouseX, 0, width, 0, 360); 88982 * 88983 * // Display that variable in an onscreen text. 88984 * // (Note the nfc() function to truncate additional decimal places, 88985 * // and the "\xB0" character for the degree symbol.) 88986 * let readout = 'angle = ' + nfc(myDegrees, 1) + '\xB0'; 88987 * noStroke(); 88988 * fill(0); 88989 * text(readout, 5, 15); 88990 * 88991 * // Create a p5.Vector using the fromAngle function, 88992 * // and extract its x and y components. 88993 * let v = p5.Vector.fromAngle(radians(myDegrees), 30); 88994 * let vx = v.x; 88995 * let vy = v.y; 88996 * 88997 * push(); 88998 * translate(width / 2, height / 2); 88999 * noFill(); 89000 * stroke(150); 89001 * line(0, 0, 30, 0); 89002 * stroke(0); 89003 * line(0, 0, vx, vy); 89004 * pop(); 89005 * } 89006 * </code> 89007 * </div> 89008 */ 89009 _main.default.Vector.fromAngle = function fromAngle(angle, length) { 89010 if (typeof length === 'undefined') { 89011 length = 1; 89012 } 89013 return new _main.default.Vector(length * Math.cos(angle), length * Math.sin(angle), 0); 89014 }; 89015 /** 89016 * Make a new 3D vector from a pair of ISO spherical angles. 89017 * 89018 * @method fromAngles 89019 * @static 89020 * @param {Number} theta The polar angle, in radians (zero is up) 89021 * @param {Number} phi The azimuthal angle, in radians 89022 * (zero is out of the screen) 89023 * @param {Number} [length] The length of the new vector (defaults to 1) 89024 * @return {p5.Vector} A new <a href="#/p5.Vector">p5.Vector</a> object 89025 * @example 89026 * <div modernizr='webgl'> 89027 * <code> 89028 * function setup() { 89029 * createCanvas(100, 100, WEBGL); 89030 * fill(255); 89031 * noStroke(); 89032 * } 89033 * function draw() { 89034 * background(255); 89035 * 89036 * let t = millis() / 1000; 89037 * 89038 * // add three point lights 89039 * pointLight(color('#f00'), p5.Vector.fromAngles(t * 1.0, t * 1.3, 100)); 89040 * pointLight(color('#0f0'), p5.Vector.fromAngles(t * 1.1, t * 1.2, 100)); 89041 * pointLight(color('#00f'), p5.Vector.fromAngles(t * 1.2, t * 1.1, 100)); 89042 * 89043 * sphere(35); 89044 * } 89045 * </code> 89046 * </div> 89047 */ 89048 _main.default.Vector.fromAngles = function (theta, phi, length) { 89049 if (typeof length === 'undefined') { 89050 length = 1; 89051 } 89052 var cosPhi = Math.cos(phi); 89053 var sinPhi = Math.sin(phi); 89054 var cosTheta = Math.cos(theta); 89055 var sinTheta = Math.sin(theta); 89056 return new _main.default.Vector(length * sinTheta * sinPhi, - length * cosTheta, length * sinTheta * cosPhi); 89057 }; 89058 /** 89059 * Make a new 2D unit vector from a random angle. 89060 * 89061 * @method random2D 89062 * @static 89063 * @return {p5.Vector} A new <a href="#/p5.Vector">p5.Vector</a> object 89064 * @example 89065 * <div class="norender"> 89066 * <code> 89067 * let v = p5.Vector.random2D(); 89068 * // May make v's attributes something like: 89069 * // [0.61554617, -0.51195765, 0.0] or 89070 * // [-0.4695841, -0.14366731, 0.0] or 89071 * // [0.6091097, -0.22805278, 0.0] 89072 * print(v); 89073 * </code> 89074 * </div> 89075 * 89076 * <div> 89077 * <code> 89078 * function setup() { 89079 * frameRate(1); 89080 * } 89081 * 89082 * function draw() { 89083 * background(240); 89084 * 89085 * let v0 = createVector(50, 50); 89086 * let v1 = p5.Vector.random2D(); 89087 * drawArrow(v0, v1.mult(50), 'black'); 89088 * } 89089 * 89090 * // draw an arrow for a vector at a given base position 89091 * function drawArrow(base, vec, myColor) { 89092 * push(); 89093 * stroke(myColor); 89094 * strokeWeight(3); 89095 * fill(myColor); 89096 * translate(base.x, base.y); 89097 * line(0, 0, vec.x, vec.y); 89098 * rotate(vec.heading()); 89099 * let arrowSize = 7; 89100 * translate(vec.mag() - arrowSize, 0); 89101 * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); 89102 * pop(); 89103 * } 89104 * </code> 89105 * </div> 89106 */ 89107 _main.default.Vector.random2D = function random2D() { 89108 return this.fromAngle(Math.random() * constants.TWO_PI); 89109 }; 89110 /** 89111 * Make a new random 3D unit vector. 89112 * 89113 * @method random3D 89114 * @static 89115 * @return {p5.Vector} A new <a href="#/p5.Vector">p5.Vector</a> object 89116 * @example 89117 * <div class="norender"> 89118 * <code> 89119 * let v = p5.Vector.random3D(); 89120 * // May make v's attributes something like: 89121 * // [0.61554617, -0.51195765, 0.599168] or
89122 * // [-0.4695841, -0.14366731, -0.8711202] or 89123 * // [0.6091097, -0.22805278, -0.7595902] 89124 * print(v); 89125 * </code> 89126 * </div> 89127 */ 89128 _main.default.Vector.random3D = function random3D() { 89129 var angle = Math.random() * constants.TWO_PI; 89130 var vz = Math.random() * 2 - 1; 89131 var vzBase = Math.sqrt(1 - vz * vz); 89132 var vx = vzBase * Math.cos(angle); 89133 var vy = vzBase * Math.sin(angle); 89134 return new _main.default.Vector(vx, vy, vz); 89135 }; // Returns a copy of a vector. 89136 /** 89137 * @method copy 89138 * @static 89139 * @param {p5.Vector} v the <a href="#/p5.Vector">p5.Vector</a> to create a copy of 89140 * @return {p5.Vector} the copy of the <a href="#/p5.Vector">p5.Vector</a> object 89141 */ 89142 _main.default.Vector.copy = function copy(v) { 89143 return v.copy(v); 89144 }; // Adds two vectors together and returns a new one. 89145 /** 89146 * @method add 89147 * @static 89148 * @param {p5.Vector} v1 A <a href="#/p5.Vector">p5.Vector</a> to add 89149 * @param {p5.Vector} v2 A <a href="#/p5.Vector">p5.Vector</a> to add 89150 * @param {p5.Vector} [target] The vector to receive the result 89151 * @return {p5.Vector} The resulting <a href="#/p5.Vector">p5.Vector</a> 89152 */ 89153 _main.default.Vector.add = function add(v1, v2, target) { 89154 if (!target) { 89155 target = v1.copy(); 89156 if (arguments.length === 3) { 89157 _main.default._friendlyError('The target parameter is undefined, it should be of type p5.Vector', 'p5.Vector.add'); 89158 } 89159 } else { 89160 target.set(v1); 89161 } 89162 target.add(v2); 89163 return target; 89164 }; // Returns a vector remainder when it is divided by another vector 89165 /** 89166 * @method rem 89167 * @static 89168 * @param {p5.Vector} v1 The dividend <a href="#/p5.Vector">p5.Vector</a> 89169 * @param {p5.Vector} v2 The divisor <a href="#/p5.Vector">p5.Vector</a> 89170 */ 89171 /** 89172 * @method rem 89173 * @static 89174 * @param {p5.Vector} v1 89175 * @param {p5.Vector} v2 89176 * @return {p5.Vector} The resulting <a href="#/p5.Vector">p5.Vector</a> 89177 */ 89178 _main.default.Vector.rem = function rem(v1, v2) { 89179 if (v1 instanceof _main.default.Vector && v2 instanceof _main.default.Vector) { 89180 var target = v1.copy(); 89181 target.rem(v2); 89182 return target; 89183 } 89184 }; 89185 /* 89186 * Subtracts one <a href="#/p5.Vector">p5.Vector</a> from another and returns a new one. The second 89187 * vector (`v2`) is subtracted from the first (`v1`), resulting in `v1-v2`. 89188 */ 89189 /** 89190 * @method sub 89191 * @static 89192 * @param {p5.Vector} v1 A <a href="#/p5.Vector">p5.Vector</a> to subtract from 89193 * @param {p5.Vector} v2 A <a href="#/p5.Vector">p5.Vector</a> to subtract 89194 * @param {p5.Vector} [target] The vector to receive the result 89195 * @return {p5.Vector} The resulting <a href="#/p5.Vector">p5.Vector</a> 89196 */ 89197 _main.default.Vector.sub = function sub(v1, v2, target) { 89198 if (!target) { 89199 target = v1.copy(); 89200 if (arguments.length === 3) { 89201 _main.default._friendlyError('The target parameter is undefined, it should be of type p5.Vector', 'p5.Vector.sub'); 89202 } 89203 } else { 89204 target.set(v1); 89205 } 89206 target.sub(v2); 89207 return target; 89208 }; 89209 /** 89210 * Multiplies a vector by a scalar and returns a new vector. 89211 */ 89212 /** 89213 * @method mult 89214 * @static 89215 * @param {Number} x 89216 * @param {Number} y 89217 * @param {Number} [z] 89218 * @return {p5.Vector} The resulting new <a href="#/p5.Vector">p5.Vector</a> 89219 */ 89220 /** 89221 * @method mult 89222 * @static 89223 * @param {p5.Vector} v 89224 * @param {Number} n 89225 * @param {p5.Vector} [target] the vector to receive the result 89226 */ 89227 /** 89228 * @method mult 89229 * @static 89230 * @param {p5.Vector} v0 89231 * @param {p5.Vector} v1 89232 * @param {p5.Vector} [target] 89233 */ 89234 /** 89235 * @method mult 89236 * @static 89237 * @param {p5.Vector} v0 89238 * @param {Number[]} arr 89239 * @param {p5.Vector} [target] 89240 */ 89241 _main.default.Vector.mult = function mult(v, n, target) { 89242 if (!target) { 89243 target = v.copy(); 89244 if (arguments.length === 3) { 89245 _main.default._friendlyError('The target parameter is undefined, it should be of type p5.Vector', 'p5.Vector.mult'); 89246 } 89247 } else { 89248 target.set(v); 89249 } 89250 target.mult(n); 89251 return target; 89252 }; 89253 /** 89254 * Rotates the vector (only 2D vectors) by the given angle; magnitude remains the same. Returns a new vector. 89255 */ 89256 /** 89257 * @method rotate
89258 * @static 89259 * @param {p5.Vector} v 89260 * @param {Number} angle 89261 * @param {p5.Vector} [target] The vector to receive the result 89262 */ 89263 _main.default.Vector.rotate = function rotate(v, a, target) { 89264 if (arguments.length === 2) { 89265 target = v.copy(); 89266 } else { 89267 if (!(target instanceof _main.default.Vector)) { 89268 _main.default._friendlyError('The target parameter should be of type p5.Vector', 'p5.Vector.rotate'); 89269 } 89270 target.set(v); 89271 } 89272 target.rotate(a); 89273 return target; 89274 }; 89275 /** 89276 * Divides a vector by a scalar and returns a new vector. 89277 */ 89278 /** 89279 * @method div 89280 * @static 89281 * @param {Number} x 89282 * @param {Number} y 89283 * @param {Number} [z] 89284 * @return {p5.Vector} The resulting new <a href="#/p5.Vector">p5.Vector</a> 89285 */ 89286 /** 89287 * @method div 89288 * @static 89289 * @param {p5.Vector} v 89290 * @param {Number} n 89291 * @param {p5.Vector} [target] The vector to receive the result 89292 */ 89293 /** 89294 * @method div 89295 * @static 89296 * @param {p5.Vector} v0 89297 * @param {p5.Vector} v1 89298 * @param {p5.Vector} [target] 89299 */ 89300 /** 89301 * @method div 89302 * @static 89303 * @param {p5.Vector} v0 89304 * @param {Number[]} arr 89305 * @param {p5.Vector} [target] 89306 */ 89307 _main.default.Vector.div = function div(v, n, target) { 89308 if (!target) { 89309 target = v.copy(); 89310 if (arguments.length === 3) { 89311 _main.default._friendlyError('The target parameter is undefined, it should be of type p5.Vector', 'p5.Vector.div'); 89312 } 89313 } else { 89314 target.set(v); 89315 } 89316 target.div(n); 89317 return target; 89318 }; 89319 /** 89320 * Calculates the dot product of two vectors. 89321 */ 89322 /** 89323 * @method dot 89324 * @static 89325 * @param {p5.Vector} v1 The first <a href="#/p5.Vector">p5.Vector</a> 89326 * @param {p5.Vector} v2 The second <a href="#/p5.Vector">p5.Vector</a> 89327 * @return {Number} The dot product 89328 */ 89329 _main.default.Vector.dot = function dot(v1, v2) { 89330 return v1.dot(v2); 89331 }; 89332 /** 89333 * Calculates the cross product of two vectors. 89334 */ 89335 /** 89336 * @method cross 89337 * @static 89338 * @param {p5.Vector} v1 The first <a href="#/p5.Vector">p5.Vector</a> 89339 * @param {p5.Vector} v2 The second <a href="#/p5.Vector">p5.Vector</a> 89340 * @return {Number} The cross product 89341 */ 89342 _main.default.Vector.cross = function cross(v1, v2) { 89343 return v1.cross(v2); 89344 }; 89345 /** 89346 * Calculates the Euclidean distance between two points (considering a 89347 * point as a vector object). 89348 */ 89349 /** 89350 * @method dist 89351 * @static 89352 * @param {p5.Vector} v1 The first <a href="#/p5.Vector">p5.Vector</a> 89353 * @param {p5.Vector} v2 The second <a href="#/p5.Vector">p5.Vector</a> 89354 * @return {Number} The distance 89355 */ 89356 _main.default.Vector.dist = function dist(v1, v2) { 89357 return v1.dist(v2); 89358 }; 89359 /** 89360 * Linear interpolate a vector to another vector and return the result as a 89361 * new vector. 89362 */ 89363 /** 89364 * @method lerp 89365 * @static 89366 * @param {p5.Vector} v1 89367 * @param {p5.Vector} v2 89368 * @param {Number} amt 89369 * @param {p5.Vector} [target] The vector to receive the result 89370 * @return {p5.Vector} The lerped value 89371 */ 89372 _main.default.Vector.lerp = function lerp(v1, v2, amt, target) { 89373 if (!target) { 89374 target = v1.copy(); 89375 if (arguments.length === 4) { 89376 _main.default._friendlyError('The target parameter is undefined, it should be of type p5.Vector', 'p5.Vector.lerp'); 89377 } 89378 } else { 89379 target.set(v1); 89380 } 89381 target.lerp(v2, amt); 89382 return target; 89383 }; 89384 /** 89385 * Calculates the magnitude (length) of the vector and returns the result as 89386 * a float (this is simply the equation `sqrt(x*x + y*y + z*z)`.) 89387 */ 89388 /** 89389 * @method mag 89390 * @static 89391 * @param {p5.Vector} vecT The vector to return the magnitude of 89392 * @return {Number} The magnitude of vecT 89393 */ 89394 _main.default.Vector.mag = function mag(vecT) { 89395 return vecT.mag(); 89396 }; 89397 /** 89398 * Calculates the squared magnitude of the vector and returns the result 89399 * as a float (this is simply the equation <em>(x\*x + y\*y + z\*z)</em>.) 89400 * Faster if the real length is not required in the 89401 * case of comparing vectors, etc. 89402 */ 89403 /** 89404 * @method magSq 89405 * @static 89406 * @param {p5.Vector} vecT the vector to return the squared magnitude of 89407 * @return {Number} the squared magnitude of vecT 89408 */ 89409 _main.default.Vector.magSq = function magSq(vecT) { 89410 return vecT.magSq(); 89411 }; 89412 /** 89413 * Normalize the vector to length 1 (make it a unit vector). 89414 */ 89415 /** 89416 * @method normalize 89417 * @static 89418 * @param {p5.Vector} v The vector to normalize 89419 * @param {p5.Vector} [target] The vector to receive the result 89420 * @return {p5.Vector} The vector v, normalized to a length of 1 89421 */ 89422 _main.default.Vector.normalize = function normalize(v, target) { 89423 if (arguments.length < 2) { 89424 target = v.copy(); 89425 } else { 89426 if (!(target instanceof _main.default.Vector)) { 89427 _main.default._friendlyError('The target parameter should be of type p5.Vector', 'p5.Vector.normalize'); 89428 } 89429 target.set(v); 89430 } 89431 return target.normalize(); 89432 }; 89433 /** 89434 * Limit the magnitude of the vector to the value used for the <b>max</b> 89435 * parameter. 89436 */ 89437 /** 89438 * @method limit 89439 * @static 89440 * @param {p5.Vector} v the vector to limit 89441 * @param {Number} max 89442 * @param {p5.Vector} [target] the vector to receive the result (Optional) 89443 * @return {p5.Vector} v with a magnitude limited to max 89444 */ 89445 _main.default.Vector.limit = function limit(v, max, target) { 89446 if (arguments.length < 3) { 89447 target = v.copy(); 89448 } else { 89449 if (!(target instanceof _main.default.Vector)) { 89450 _main.default._friendlyError('The target parameter should be of type p5.Vector', 'p5.Vector.limit'); 89451 } 89452 target.set(v); 89453 } 89454 return target.limit(max); 89455 }; 89456 /** 89457 * Set the magnitude of the vector to the value used for the <b>len</b> 89458 * parameter. 89459 */ 89460 /** 89461 * @method setMag 89462 * @static 89463 * @param {p5.Vector} v the vector to set the magnitude of 89464 * @param {number} len 89465 * @param {p5.Vector} [target] the vector to receive the result (Optional) 89466 * @return {p5.Vector} v with a magnitude set to len 89467 */ 89468 _main.default.Vector.setMag = function setMag(v, len, target) { 89469 if (arguments.length < 3) { 89470 target = v.copy(); 89471 } else { 89472 if (!(target instanceof _main.default.Vector)) { 89473 _main.default._friendlyError('The target parameter should be of type p5.Vector', 'p5.Vector.setMag'); 89474 } 89475 target.set(v); 89476 } 89477 return target.setMag(len); 89478 }; 89479 /** 89480 * Calculate the angle of rotation for this vector (only 2D vectors). 89481 * p5.Vectors created using <a href="#/p5/createVector">createVector()</a> 89482 * will take the current <a href="#/p5/angleMode">angleMode</a> into 89483 * consideration, and give the angle in radians or degrees accordingly. 89484 */ 89485 /** 89486 * @method heading
89487 * @static 89488 * @param {p5.Vector} v the vector to find the angle of 89489 * @return {Number} the angle of rotation 89490 */ 89491 _main.default.Vector.heading = function heading(v) { 89492 return v.heading(); 89493 }; 89494 /** 89495 * Calculates and returns the angle between two vectors. This function will take 89496 * the <a href="#/p5/angleMode">angleMode</a> on v1 into consideration, and 89497 * give the angle in radians or degrees accordingly. 89498 */ 89499 /** 89500 * @method angleBetween 89501 * @static 89502 * @param {p5.Vector} v1 the first vector 89503 * @param {p5.Vector} v2 the second vector 89504 * @return {Number} the angle between the two vectors 89505 */ 89506 _main.default.Vector.angleBetween = function angleBetween(v1, v2) { 89507 return v1.angleBetween(v2); 89508 }; 89509 /** 89510 * Reflect a vector about a normal to a line in 2D, or about a normal to a 89511 * plane in 3D. 89512 */ 89513 /** 89514 * @method reflect 89515 * @static 89516 * @param {p5.Vector} incidentVector vector to be reflected 89517 * @param {p5.Vector} surfaceNormal 89518 * @param {p5.Vector} [target] the vector to receive the result (Optional) 89519 * @return {p5.Vector} the reflected vector 89520 */ 89521 _main.default.Vector.reflect = function reflect(incidentVector, surfaceNormal, target) { 89522 if (arguments.length < 3) { 89523 target = incidentVector.copy(); 89524 } else { 89525 if (!(target instanceof _main.default.Vector)) { 89526 _main.default._friendlyError('The target parameter should be of type p5.Vector', 'p5.Vector.reflect'); 89527 } 89528 target.set(incidentVector); 89529 } 89530 return target.reflect(surfaceNormal); 89531 }; 89532 /** 89533 * Return a representation of this vector as a float array. This is only 89534 * for temporary use. If used in any other fashion, the contents should be 89535 * copied by using the <b>p5.Vector.<a href="#/p5.Vector/copy">copy()</a></b> 89536 * method to copy into your own vector. 89537 */ 89538 /** 89539 * @method array 89540 * @static 89541 * @param {p5.Vector} v the vector to convert to an array 89542 * @return {Number[]} an Array with the 3 values 89543 */ 89544 _main.default.Vector.array = function array(v) { 89545 return v.array(); 89546 }; 89547 /** 89548 * Equality check against a <a href="#/p5.Vector">p5.Vector</a> 89549 */ 89550 /** 89551 * @method equals 89552 * @static 89553 * @param {p5.Vector|Array} v1 the first vector to compare 89554 * @param {p5.Vector|Array} v2 the second vector to compare 89555 * @return {Boolean} 89556 */ 89557 _main.default.Vector.equals = function equals(v1, v2) { 89558 var v; 89559 if (v1 instanceof _main.default.Vector) { 89560 v = v1; 89561 } else if (v1 instanceof Array) { 89562 v = new _main.default.Vector().set(v1); 89563 } else { 89564 _main.default._friendlyError('The v1 parameter should be of type Array or p5.Vector', 'p5.Vector.equals'); 89565 } 89566 return v.equals(v2); 89567 }; 89568 var _default = _main.default.Vector; 89569 exports.default = _default; 89570 }, 89571 { 89572 '../core/constants': 278, 89573 '../core/main': 290, 89574 'core-js/modules/es.array.concat': 167, 89575 'core-js/modules/es.array.every': 169, 89576 'core-js/modules/es.array.iterator': 176, 89577 'core-js/modules/es.array.slice': 180, 89578 'core-js/modules/es.array.some': 181, 89579 'core-js/modules/es.math.sign': 186, 89580 'core-js/modules/es.number.constructor': 187, 89581 'core-js/modules/es.number.is-finite': 188, 89582 'core-js/modules/es.object.get-own-property-descriptor': 191, 89583 'core-js/modules/es.object.to-string': 195, 89584 'core-js/modules/es.regexp.to-string': 200, 89585 'core-js/modules/es.string.iterator': 204, 89586 'core-js/modules/es.string.sub': 210, 89587 'core-js/modules/es.symbol': 214, 89588 'core-js/modules/es.symbol.description': 212, 89589 'core-js/modules/es.symbol.iterator': 213, 89590 'core-js/modules/es.weak-map': 246, 89591 'core-js/modules/web.dom-collections.iterator': 248 89592 } 89593 ], 89594 324: [ 89595 function (_dereq_, module, exports) { 89596 'use strict'; 89597 Object.defineProperty(exports, '__esModule', { 89598 value: true 89599 }); 89600 exports.default = void 0; 89601 var _main = _interopRequireDefault(_dereq_('../core/main')); 89602 function _interopRequireDefault(obj) { 89603 return obj && obj.__esModule ? obj : { 89604 default: 89605 obj 89606 }; 89607 } /** 89608 * @module Math 89609 * @submodule Random 89610 * @for p5 89611 * @requires core 89612 */ 89613 // variables used for random number generators 89614 89615 var randomStateProp = '_lcg_random_state'; // Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes 89616 // m is basically chosen to be large (as it is the max period) 89617 // and for its relationships to a and c 89618 var m = 4294967296; // a - 1 should be divisible by m's prime factors 89619 var a = 1664525; // c and m should be co-prime 89620 var c = 1013904223; 89621 var y2 = 0; // Linear Congruential Generator that stores its state at instance[stateProperty] 89622 _main.default.prototype._lcg = function (stateProperty) { 89623 // define the recurrence relationship 89624 this[stateProperty] = (a * this[stateProperty] + c) % m; // return a float in [0, 1) 89625 // we've just used % m, so / m is always < 1 89626 return this[stateProperty] / m; 89627 }; 89628 _main.default.prototype._lcgSetSeed = function (stateProperty, val) { 89629 // pick a random seed if val is undefined or null 89630 // the >>> 0 casts the seed to an unsigned 32-bit integer 89631 this[stateProperty] = (val == null ? Math.random() * m : val) >>> 0; 89632 }; 89633 /** 89634 * Sets the seed value for <a href="#/p5/random">random()</a>. 89635 * 89636 * By default, <a href="#/p5/random">random()</a> produces different results each time the program 89637 * is run. Set the seed parameter to a constant to return the same
89638 * pseudo-random numbers each time the software is run. 89639 * 89640 * @method randomSeed 89641 * @param {Number} seed the seed value 89642 * @example 89643 * <div> 89644 * <code> 89645 * randomSeed(99); 89646 * for (let i = 0; i < 100; i++) { 89647 * let r = random(0, 255); 89648 * stroke(r); 89649 * line(i, 0, i, 100); 89650 * } 89651 * describe('many vertical lines drawn in white, black, or grey.'); 89652 * </code> 89653 * </div> 89654 */ 89655 _main.default.prototype.randomSeed = function (seed) { 89656 this._lcgSetSeed(randomStateProp, seed); 89657 this._gaussian_previous = false; 89658 }; 89659 /** 89660 * Return a random floating-point number. 89661 * 89662 * Takes either 0, 1 or 2 arguments. 89663 * 89664 * If no argument is given, returns a random number from 0 89665 * up to (but not including) 1. 89666 * 89667 * If one argument is given and it is a number, returns a random number from 0 89668 * up to (but not including) the number. 89669 * 89670 * If one argument is given and it is an array, returns a random element from 89671 * that array. 89672 * 89673 * If two arguments are given, returns a random number from the 89674 * first argument up to (but not including) the second argument. 89675 * 89676 * @method random 89677 * @param {Number} [min] the lower bound (inclusive) 89678 * @param {Number} [max] the upper bound (exclusive) 89679 * @return {Number} the random number 89680 * @example 89681 * <div> 89682 * <code> 89683 * for (let i = 0; i < 100; i++) { 89684 * let r = random(50); 89685 * stroke(r * 5); 89686 * line(50, i, 50 + r, i); 89687 * } 89688 * describe(`100 horizontal lines from center canvas to right. 89689 * The size and fill change each time.`); 89690 * </code> 89691 * </div> 89692 * <div> 89693 * <code> 89694 * for (let i = 0; i < 100; i++) { 89695 * let r = random(-50, 50); 89696 * line(50, i, 50 + r, i); 89697 * } 89698 * describe(`100 horizontal lines from center of canvas. 89699 * The height & side change each render.`); 89700 * </code> 89701 * </div> 89702 * <div> 89703 * <code> 89704 * // Get a random element from an array using the random(Array) syntax 89705 * let words = ['apple', 'bear', 'cat', 'dog']; 89706 * let word = random(words); // select random word 89707 * text(word, 10, 50); // draw the word 89708 * describe('word displayed at random. Either apple, bear, cat, or dog.'); 89709 * </code> 89710 * </div> 89711 */ 89712 /** 89713 * @method random 89714 * @param {Array} choices the array to choose from 89715 * @return {*} the random element from the array 89716 * @example 89717 */ 89718 _main.default.prototype.random = function (min, max) { 89719 _main.default._validateParameters('random', arguments); 89720 var rand; 89721 if (this[randomStateProp] != null) { 89722 rand = this._lcg(randomStateProp); 89723 } else { 89724 rand = Math.random(); 89725 } 89726 if (typeof min === 'undefined') { 89727 return rand; 89728 } else if (typeof max === 'undefined') { 89729 if (min instanceof Array) { 89730 return min[Math.floor(rand * min.length)]; 89731 } else { 89732 return rand * min; 89733 } 89734 } else { 89735 if (min > max) { 89736 var tmp = min; 89737 min = max; 89738 max = tmp; 89739 } 89740 return rand * (max - min) + min; 89741 } 89742 }; 89743 /** 89744 * 89745 * Returns a random number fitting a Gaussian, or 89746 * normal, distribution. There is theoretically no minimum or maximum 89747 * value that <a href="#/p5/randomGaussian">randomGaussian()</a> might return. Rather, there is 89748 * just a very low probability that values far from the mean will be 89749 * returned; and a higher probability that numbers near the mean will 89750 * be returned. 89751 * 89752 * Takes either 0, 1 or 2 arguments.<br> 89753 * If no args, the mean is 0 and the standard deviation is 1.<br> 89754 * If one arg, that arg is the mean and the standard deviation is 1.<br> 89755 * If two args, the first arg is the mean and the second is the standard deviation. 89756 * 89757 * @method randomGaussian 89758 * @param {Number} [mean] the mean 89759 * @param {Number} [sd] the standard deviation 89760 * @return {Number} the random number 89761 * @example 89762 * <div> 89763 * <code> 89764 * for (let y = 0; y < 100; y++) { 89765 * let x = randomGaussian(50, 15); 89766 * line(50, y, x, y); 89767 * } 89768 * describe(`100 horizontal lines from center of canvas. 89769 * The height & side change each render.`); 89770 * </code> 89771 * </div> 89772 * <div> 89773 * <code> 89774 * let distribution = new Array(360); 89775 * 89776 * function setup() { 89777 * createCanvas(100, 100); 89778 * for (let i = 0; i < distribution.length; i++) { 89779 * distribution[i] = floor(randomGaussian(0, 15)); 89780 * } 89781 * } 89782 * 89783 * function draw() { 89784 * background(204); 89785 * 89786 * translate(width / 2, width / 2); 89787 * 89788 * for (let i = 0; i < distribution.length; i++) { 89789 * rotate(TWO_PI / distribution.length); 89790 * stroke(0); 89791 * let dist = abs(distribution[i]); 89792 * line(0, 0, dist, 0); 89793 * } 89794 * 89795 * describe(`black lines radiate from center of canvas. 89796 * The size changes each render.`); 89797 * } 89798 * </code> 89799 * </div> 89800 */ 89801 _main.default.prototype.randomGaussian = function (mean) { 89802 var sd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; 89803 var y1, 89804 x1, 89805 x2, 89806 w; 89807 if (this._gaussian_previous) { 89808 y1 = y2; 89809 this._gaussian_previous = false;
89810 } else { 89811 do { 89812 x1 = this.random(2) - 1; 89813 x2 = this.random(2) - 1; 89814 w = x1 * x1 + x2 * x2; 89815 } while (w >= 1); 89816 w = Math.sqrt( - 2 * Math.log(w) / w); 89817 y1 = x1 * w; 89818 y2 = x2 * w; 89819 this._gaussian_previous = true; 89820 } 89821 var m = mean || 0; 89822 return y1 * sd + m; 89823 }; 89824 var _default = _main.default; 89825 exports.default = _default; 89826 }, 89827 { 89828 '../core/main': 290 89829 } 89830 ], 89831 325: [ 89832 function (_dereq_, module, exports) { 89833 'use strict'; 89834 _dereq_('core-js/modules/es.symbol'); 89835 _dereq_('core-js/modules/es.symbol.description'); 89836 _dereq_('core-js/modules/es.symbol.iterator'); 89837 _dereq_('core-js/modules/es.array.iterator'); 89838 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 89839 _dereq_('core-js/modules/es.object.to-string'); 89840 _dereq_('core-js/modules/es.string.iterator'); 89841 _dereq_('core-js/modules/es.weak-map'); 89842 _dereq_('core-js/modules/web.dom-collections.iterator'); 89843 function _typeof2(obj) { 89844 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 89845 _typeof2 = function _typeof2(obj) { 89846 return typeof obj; 89847 }; 89848 } else { 89849 _typeof2 = function _typeof2(obj) { 89850 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 89851 }; 89852 } 89853 return _typeof2(obj); 89854 } 89855 function _typeof(obj) { 89856 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 89857 _typeof = function _typeof(obj) { 89858 return _typeof2(obj); 89859 }; 89860 } else { 89861 _typeof = function _typeof(obj) { 89862 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 89863 }; 89864 } 89865 return _typeof(obj); 89866 } 89867 Object.defineProperty(exports, '__esModule', { 89868 value: true 89869 }); 89870 exports.default = void 0; 89871 var _main = _interopRequireDefault(_dereq_('../core/main')); 89872 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 89873 function _getRequireWildcardCache() { 89874 if (typeof WeakMap !== 'function') return null; 89875 var cache = new WeakMap(); 89876 _getRequireWildcardCache = function _getRequireWildcardCache() { 89877 return cache; 89878 }; 89879 return cache; 89880 } 89881 function _interopRequireWildcard(obj) { 89882 if (obj && obj.__esModule) { 89883 return obj; 89884 } 89885 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 89886 return { 89887 default: 89888 obj 89889 }; 89890 } 89891 var cache = _getRequireWildcardCache(); 89892 if (cache && cache.has(obj)) { 89893 return cache.get(obj); 89894 } 89895 var newObj = { 89896 }; 89897 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 89898 for (var key in obj) { 89899 if (Object.prototype.hasOwnProperty.call(obj, key)) { 89900 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 89901 if (desc && (desc.get || desc.set)) { 89902 Object.defineProperty(newObj, key, desc); 89903 } else { 89904 newObj[key] = obj[key]; 89905 } 89906 } 89907 } 89908 newObj.default = obj; 89909 if (cache) { 89910 cache.set(obj, newObj); 89911 } 89912 return newObj; 89913 } 89914 function _interopRequireDefault(obj) { 89915 return obj && obj.__esModule ? obj : { 89916 default: 89917 obj 89918 }; 89919 } /** 89920 * @module Math 89921 * @submodule Trigonometry 89922 * @for p5 89923 * @requires core 89924 * @requires constants 89925 */ 89926 /* 89927 * all DEGREES/RADIANS conversion should be done in the p5 instance 89928 * if possible, using the p5._toRadians(), p5._fromRadians() methods. 89929 */ 89930 89931 _main.default.prototype._angleMode = constants.RADIANS; 89932 /** 89933 * The inverse of <a href="#/p5/cos">cos()</a>, returns the arc cosine of a value. 89934 * This function expects the values in the range of -1 to 1 and values are returned in 89935 * the range 0 to PI (3.1415927) if the <a href="#/p5/angleMode">angleMode()</a> is RADIANS 89936 * or 0 to 180 if the <a href="#/p5/angleMode">angleMode()</a> is DEGREES.
89937 * 89938 * @method acos 89939 * @param {Number} value the value whose arc cosine is to be returned 89940 * @return {Number} the arc cosine of the given value 89941 * 89942 * @example 89943 * <div class= ânorender"> 89944 * <code> 89945 * let a = PI; 89946 * let c = cos(a); 89947 * let ac = acos(c); 89948 * // Prints: "3.1415927 : -1.0 : 3.1415927" 89949 * print(a + ' : ' + c + ' : ' + ac); 89950 * </code> 89951 * </div> 89952 * 89953 * <div class= ânorender"> 89954 * <code> 89955 * let a = PI + PI / 4.0; 89956 * let c = cos(a); 89957 * let ac = acos(c); 89958 * // Prints: "3.926991 : -0.70710665 : 2.3561943" 89959 * print(a + ' : ' + c + ' : ' + ac); 89960 * </code> 89961 * </div> 89962 */ 89963 _main.default.prototype.acos = function (ratio) { 89964 return this._fromRadians(Math.acos(ratio)); 89965 }; 89966 /** 89967 * The inverse of <a href="#/p5/sin">sin()</a>, returns the arc sine of a value. 89968 * This function expects the values in the range of -1 to 1 and values are returned 89969 * in the range -PI/2 to PI/2 if the angleMode is RADIANS or -90 to 90 if the angle 89970 * mode is DEGREES. 89971 * 89972 * @method asin 89973 * @param {Number} value the value whose arc sine is to be returned 89974 * @return {Number} the arc sine of the given value 89975 * 89976 * @example 89977 * <div class= ânorender"> 89978 * <code> 89979 * let a = PI / 3.0; 89980 * let s = sin(a); 89981 * let as = asin(s); 89982 * // Prints: "1.0471975 : 0.86602540 : 1.0471975" 89983 * print(a + ' : ' + s + ' : ' + as); 89984 * </code> 89985 * </div> 89986 * 89987 * <div class= ânorender"> 89988 * <code> 89989 * let a = PI + PI / 3.0; 89990 * let s = sin(a); 89991 * let as = asin(s); 89992 * // Prints: "4.1887902 : -0.86602540 : -1.0471975" 89993 * print(a + ' : ' + s + ' : ' + as); 89994 * </code> 89995 * </div> 89996 */ 89997 _main.default.prototype.asin = function (ratio) { 89998 return this._fromRadians(Math.asin(ratio)); 89999 }; 90000 /** 90001 * The inverse of <a href="#/p5/tan">tan()</a>, returns the arc tangent of a value. 90002 * This function expects the values in the range of -Infinity to Infinity (exclusive) and 90003 * values are returned in the range -PI/2 to PI/2 if the angleMode is RADIANS or 90004 * -90 to 90 if the angle mode is DEGREES. 90005 * 90006 * @method atan 90007 * @param {Number} value the value whose arc tangent is to be returned 90008 * @return {Number} the arc tangent of the given value 90009 * 90010 * @example 90011 * <div class= ânorender"> 90012 * <code> 90013 * let a = PI / 3.0; 90014 * let t = tan(a); 90015 * let at = atan(t); 90016 * // Prints: "1.0471975 : 1.7320508 : 1.0471975" 90017 * print(a + ' : ' + t + ' : ' + at); 90018 * </code> 90019 * </div> 90020 * 90021 * <div class= ânorender"> 90022 * <code> 90023 * let a = PI + PI / 3.0; 90024 * let t = tan(a); 90025 * let at = atan(t); 90026 * // Prints: "4.1887902 : 1.7320508 : 1.0471975" 90027 * print(a + ' : ' + t + ' : ' + at); 90028 * </code> 90029 * </div> 90030 */ 90031 _main.default.prototype.atan = function (ratio) { 90032 return this._fromRadians(Math.atan(ratio)); 90033 }; 90034 /** 90035 * Calculates the angle (in radians) from a specified point to the coordinate 90036 * origin as measured from the positive x-axis. Values are returned as a 90037 * float in the range from PI to -PI if the <a href="#/p5/angleMode">angleMode()</a> 90038 * is RADIANS or 180 to -180 if the <a href="#/p5/angleMode">angleMode()</a> is DEGREES. 90039 * The <a href="#/p5/">atan2()</a> function is most often used for orienting geometry 90040 * to the position of the cursor. 90041 * 90042 * Note: The y-coordinate of the point is the first parameter, and the 90043 * x-coordinate is the second parameter, due to the structure of calculating 90044 * the tangent. 90045 * 90046 * @method atan2 90047 * @param {Number} y y-coordinate of the point 90048 * @param {Number} x x-coordinate of the point 90049 * @return {Number} the arc tangent of the given point 90050 * 90051 * @example 90052 * <div> 90053 * <code> 90054 * function draw() { 90055 * background(204); 90056 * translate(width / 2, height / 2); 90057 * let a = atan2(mouseY - height / 2, mouseX - width / 2); 90058 * rotate(a); 90059 * rect(-30, -5, 60, 10); 90060 * describe('60Ã10 rect at center of canvas rotates with mouse movements'); 90061 * } 90062 * </code> 90063 * </div> 90064 */ 90065 _main.default.prototype.atan2 = function (y, x) { 90066 return this._fromRadians(Math.atan2(y, x)); 90067 }; 90068 /** 90069 * Calculates the cosine of an angle. This function takes into account the 90070 * current <a href="#/p5/angleMode">angleMode</a>. Values are returned in the range -1 to 1. 90071 * 90072 * @method cos 90073 * @param {Number} angle the angle 90074 * @return {Number} the cosine of the angle 90075 * 90076 * @example 90077 * <div> 90078 * <code> 90079 * let a = 0.0; 90080 * let inc = TWO_PI / 25.0; 90081 * for (let i = 0; i < 25; i++) { 90082 * line(i * 4, 50, i * 4, 50 + cos(a) * 40.0); 90083 * a = a + inc; 90084 * } 90085 * describe(`vertical black lines form wave patterns, extend-down on 90086 * left and right side`); 90087 * </code> 90088 * </div> 90089 */ 90090 _main.default.prototype.cos = function (angle) { 90091 return Math.cos(this._toRadians(angle)); 90092 }; 90093 /** 90094 * Calculates the sine of an angle. This function takes into account the 90095 * current <a href="#/p5/angleMode">angleMode</a>. Values are returned in the range -1 to 1. 90096 * 90097 * @method sin 90098 * @param {Number} angle the angle 90099 * @return {Number} the sine of the angle 90100 * 90101 * @example 90102 * <div> 90103 * <code> 90104 * let a = 0.0; 90105 * let inc = TWO_PI / 25.0; 90106 * for (let i = 0; i < 25; i++) { 90107 * line(i * 4, 50, i * 4, 50 + sin(a) * 40.0); 90108 * a = a + inc; 90109 * } 90110 * describe(`vertical black lines extend down and up from center 90111 * to form wave pattern.`); 90112 * </code> 90113 * </div> 90114 */ 90115 _main.default.prototype.sin = function (angle) { 90116 return Math.sin(this._toRadians(angle)); 90117 }; 90118 /** 90119 * Calculates the tangent of an angle. This function takes into account 90120 * the current <a href="#/p5/angleMode">angleMode</a>. Values are returned in the range of all real numbers. 90121 * 90122 * @method tan 90123 * @param {Number} angle the angle 90124 * @return {Number} the tangent of the angle 90125 * 90126 * @example 90127 * <div> 90128 * <code> 90129 * let a = 0.0; 90130 * let inc = TWO_PI / 50.0; 90131 * for (let i = 0; i < 100; i = i + 2) { 90132 * line(i, 50, i, 50 + tan(a) * 2.0); 90133 * a = a + inc; 90134 * } 90135 * describe(`vertical black lines end down and up from center to 90136 * form spike pattern.`); 90137 * </code> 90138 */ 90139 _main.default.prototype.tan = function (angle) { 90140 return Math.tan(this._toRadians(angle)); 90141 }; 90142 /** 90143 * Converts a radian measurement to its corresponding value in degrees. 90144 * Radians and degrees are two ways of measuring the same thing. There are 90145 * 360 degrees in a circle and 2*PI radians in a circle. For example, 90146 * 90° = PI/2 = 1.5707964. This function does not take into account the 90147 * current <a href="#/p5/angleMode">angleMode()</a>. 90148 * 90149 * @method degrees 90150 * @param {Number} radians the radians value to convert to degrees 90151 * @return {Number} the converted angle 90152 * 90153 * @example 90154 * <div class= ânorender"> 90155 * <code> 90156 * let rad = PI / 4; 90157 * let deg = degrees(rad); 90158 * print(rad + ' radians is ' + deg + ' degrees'); 90159 * // Prints: 0.7853981633974483 radians is 45 degrees 90160 * </code> 90161 * </div> 90162 */ 90163 _main.default.prototype.degrees = function (angle) { 90164 return angle * constants.RAD_TO_DEG; 90165 }; 90166 /** 90167 * Converts a degree measurement to its corresponding value in radians. 90168 * Radians and degrees are two ways of measuring the same thing. There are 90169 * 360 degrees in a circle and 2*PI radians in a circle. For example, 90170 * 90° = PI/2 = 1.5707964. This function does not take into account the 90171 * current <a href="#/p5/angleMode">angleMode</a>. 90172 * 90173 * @method radians 90174 * @param {Number} degrees the degree value to convert to radians 90175 * @return {Number} the converted angle 90176 * 90177 * @example 90178 * <div class= ânorender"> 90179 * <code> 90180 * let deg = 45.0; 90181 * let rad = radians(deg); 90182 * print(deg + ' degrees is ' + rad + ' radians'); 90183 * // Prints: 45 degrees is 0.7853981633974483 radians 90184 * </code> 90185 * </div> 90186 */ 90187 _main.default.prototype.radians = function (angle) { 90188 return angle * constants.DEG_TO_RAD; 90189 }; 90190 /** 90191 * Sets the current mode of p5 to the given mode. Default mode is RADIANS. 90192 * 90193 * Calling <a href="#/p5/angleMode">angleMode()</a> with no arguments returns current anglemode. 90194 * @method angleMode 90195 * @param {Constant} mode either RADIANS or DEGREES 90196 * @example 90197 * <div> 90198 * <code> 90199 * function draw() { 90200 * background(204); 90201 * angleMode(DEGREES); // Change the mode to DEGREES
90202 * let a = atan2(mouseY - height / 2, mouseX - width / 2); 90203 * translate(width / 2, height / 2); 90204 * push(); 90205 * rotate(a); 90206 * rect(-20, -5, 40, 10); // Larger rectangle is rotating in degrees 90207 * pop(); 90208 * angleMode(RADIANS); // Change the mode to RADIANS 90209 * rotate(a); // variable a stays the same 90210 * rect(-40, -5, 20, 10); // Smaller rectangle is rotating in radians 90211 * describe(`40Ã10 rect in center rotates with mouse moves. 90212 * 20Ã10 rect moves faster.`); 90213 * } 90214 * </code> 90215 * </div> 90216 * 90217 */ 90218 /** 90219 * @method angleMode 90220 * @return {Constant} mode either RADIANS or DEGREES 90221 */ 90222 _main.default.prototype.angleMode = function (mode) { 90223 _main.default._validateParameters('angleMode', arguments); 90224 if (typeof mode === 'undefined') { 90225 return this._angleMode; 90226 } else if (mode === constants.DEGREES || mode === constants.RADIANS) { 90227 this._angleMode = mode; 90228 } 90229 }; 90230 /** 90231 * converts angles from the current angleMode to RADIANS 90232 * 90233 * @method _toRadians 90234 * @private 90235 * @param {Number} angle 90236 * @returns {Number} 90237 */ 90238 _main.default.prototype._toRadians = function (angle) { 90239 if (this._angleMode === constants.DEGREES) { 90240 return angle * constants.DEG_TO_RAD; 90241 } 90242 return angle; 90243 }; 90244 /** 90245 * converts angles from the current angleMode to DEGREES 90246 * 90247 * @method _toDegrees 90248 * @private 90249 * @param {Number} angle 90250 * @returns {Number} 90251 */ 90252 _main.default.prototype._toDegrees = function (angle) { 90253 if (this._angleMode === constants.RADIANS) { 90254 return angle * constants.RAD_TO_DEG; 90255 } 90256 return angle; 90257 }; 90258 /** 90259 * converts angles from RADIANS into the current angleMode 90260 * 90261 * @method _fromRadians 90262 * @private 90263 * @param {Number} angle 90264 * @returns {Number} 90265 */ 90266 _main.default.prototype._fromRadians = function (angle) { 90267 if (this._angleMode === constants.DEGREES) { 90268 return angle * constants.RAD_TO_DEG; 90269 } 90270 return angle; 90271 }; 90272 var _default = _main.default; 90273 exports.default = _default; 90274 }, 90275 { 90276 '../core/constants': 278, 90277 '../core/main': 290, 90278 'core-js/modules/es.array.iterator': 176, 90279 'core-js/modules/es.object.get-own-property-descriptor': 191, 90280 'core-js/modules/es.object.to-string': 195, 90281 'core-js/modules/es.string.iterator': 204, 90282 'core-js/modules/es.symbol': 214, 90283 'core-js/modules/es.symbol.description': 212, 90284 'core-js/modules/es.symbol.iterator': 213, 90285 'core-js/modules/es.weak-map': 246, 90286 'core-js/modules/web.dom-collections.iterator': 248 90287 } 90288 ], 90289 326: [ 90290 function (_dereq_, module, exports) { 90291 'use strict'; 90292 Object.defineProperty(exports, '__esModule', { 90293 value: true 90294 }); 90295 exports.default = void 0; 90296 var _main = _interopRequireDefault(_dereq_('../core/main')); 90297 function _interopRequireDefault(obj) { 90298 return obj && obj.__esModule ? obj : { 90299 default: 90300 obj 90301 }; 90302 } /** 90303 * @module Typography 90304 * @submodule Attributes 90305 * @for p5 90306 * @requires core 90307 * @requires constants 90308 */ 90309 /** 90310 * Sets the current alignment for drawing text. Accepts two 90311 * arguments: horizAlign (LEFT, CENTER, or RIGHT) and 90312 * vertAlign (TOP, BOTTOM, CENTER, or BASELINE). 90313 * 90314 * The horizAlign parameter is in reference to the x value 90315 * of the <a href="#/p5/text">text()</a> function, while the vertAlign parameter 90316 * is in reference to the y value. 90317 * 90318 * So if you write textAlign(LEFT), you are aligning the left 90319 * edge of your text to the x value you give in <a href="#/p5/text">text()</a>. 90320 * If you write textAlign(RIGHT, TOP), you are aligning the right edge 90321 * of your text to the x value and the top edge of the text 90322 * to the y value. 90323 * 90324 * @method textAlign 90325 * @param {Constant} horizAlign horizontal alignment, either LEFT, 90326 * CENTER, or RIGHT 90327 * @param {Constant} [vertAlign] vertical alignment, either TOP, 90328 * BOTTOM, CENTER, or BASELINE 90329 * @chainable 90330 * @example 90331 * <div> 90332 * <code> 90333 * textSize(16); 90334 * textAlign(RIGHT); 90335 * text('ABCD', 50, 30); 90336 * textAlign(CENTER); 90337 * text('EFGH', 50, 50); 90338 * textAlign(LEFT); 90339 * text('IJKL', 50, 70); 90340 * describe(`Letters ABCD displayed at top left, EFGH at center, and 90341 * IJKL at bottom right.`); 90342 * </code> 90343 * </div> 90344 * 90345 * <div> 90346 * <code> 90347 * textSize(16); 90348 * strokeWeight(0.5); 90349 * 90350 * line(0, 12, width, 12); 90351 * textAlign(CENTER, TOP); 90352 * text('TOP', 0, 12, width); 90353 * 90354 * line(0, 37, width, 37); 90355 * textAlign(CENTER, CENTER); 90356 * text('CENTER', 0, 37, width); 90357 * 90358 * line(0, 62, width, 62); 90359 * textAlign(CENTER, BASELINE); 90360 * text('BASELINE', 0, 62, width); 90361 * 90362 * line(0, 87, width, 87); 90363 * textAlign(CENTER, BOTTOM); 90364 * text('BOTTOM', 0, 87, width); 90365 * 90366 * describe(`The names of the four vertical alignments (TOP, CENTER, BASELINE, 90367 * and BOTTOM) rendered each showing that alignment's placement relative to a 90368 * horizontal line.`); 90369 * </code> 90370 * </div> 90371 */ 90372 /** 90373 * @method textAlign 90374 * @return {Object} 90375 */ 90376 90377 _main.default.prototype.textAlign = function (horizAlign, vertAlign) { 90378 var _this$_renderer; 90379 _main.default._validateParameters('textAlign', arguments); 90380 return (_this$_renderer = this._renderer).textAlign.apply(_this$_renderer, arguments); 90381 }; 90382 /** 90383 * Sets/gets the spacing, in pixels, between lines of text. This setting will be 90384 * used in all subsequent calls to the <a href="#/p5/text">text()</a> function. 90385 * 90386 * @method textLeading 90387 * @param {Number} leading the size in pixels for spacing between lines 90388 * @chainable 90389 * 90390 * @example 90391 * <div> 90392 * <code> 90393 * let lines = 'L1\nL2\nL3'; // "\n" is a "new line" character 90394 * textSize(12); 90395 * 90396 * textLeading(10); 90397 * text(lines, 10, 25); 90398 * 90399 * textLeading(20); 90400 * text(lines, 40, 25); 90401 * 90402 * textLeading(30); 90403 * text(lines, 70, 25); 90404 * 90405 * describe(`A set of L1, L2, and L3, displayed vertically 3 times. 90406 * Spacing increases for each set.`); 90407 * </code> 90408 * </div> 90409 */ 90410 /** 90411 * @method textLeading 90412 * @return {Number} 90413 */ 90414 _main.default.prototype.textLeading = function (theLeading) { 90415 var _this$_renderer2; 90416 _main.default._validateParameters('textLeading', arguments); 90417 return (_this$_renderer2 = this._renderer).textLeading.apply(_this$_renderer2, arguments); 90418 }; 90419 /** 90420 * Sets/gets the current font size. This size will be used in all subsequent 90421 * calls to the <a href="#/p5/text">text()</a> function. Font size is measured in pixels. 90422 * 90423 * @method textSize 90424 * @param {Number} theSize the size of the letters in units of pixels 90425 * @chainable 90426 * 90427 * @example 90428 * <div> 90429 * <code> 90430 * textSize(12); 90431 * text('Font Size 12', 10, 30); 90432 * textSize(14); 90433 * text('Font Size 14', 10, 60); 90434 * textSize(16); 90435 * text('Font Size 16', 10, 90); 90436 * 90437 * describe(`'Font Size 12' displayed small, 90438 * 'Font Size 14' medium, and 90439 * 'Font Size 16' large`); 90440 * </code> 90441 * </div> 90442 */ 90443 /** 90444 * @method textSize 90445 * @return {Number} 90446 */ 90447 _main.default.prototype.textSize = function (theSize) { 90448 var _this$_renderer3; 90449 _main.default._validateParameters('textSize', arguments); 90450 return (_this$_renderer3 = this._renderer).textSize.apply(_this$_renderer3, arguments); 90451 }; 90452 /** 90453 * Sets/gets the style of the text for system fonts to NORMAL, ITALIC, BOLD or BOLDITALIC. 90454 * Note: this may be is overridden by CSS styling. For non-system fonts 90455 * (opentype, truetype, etc.) please load styled fonts instead. 90456 * 90457 * @method textStyle 90458 * @param {Constant} theStyle styling for text, either NORMAL, 90459 * ITALIC, BOLD or BOLDITALIC 90460 * @chainable 90461 * @example 90462 * <div> 90463 * <code> 90464 * strokeWeight(0); 90465 * textSize(12); 90466 * textStyle(NORMAL); 90467 * text('Font Style Normal', 10, 15); 90468 * textStyle(ITALIC); 90469 * text('Font Style Italic', 10, 40); 90470 * textStyle(BOLD); 90471 * text('Font Style Bold', 10, 65); 90472 * textStyle(BOLDITALIC); 90473 * text('Font Style Bold Italic', 10, 90);
90474 * describe(`The words âFont Style Normalâ displayed normally, 90475 * âFont Style Italicâ in italic, 90476 * âFont Style Boldâ in bold, and 90477 * âFont Style Bold Italicâ in bold italics.`); 90478 * </code> 90479 * </div> 90480 */ 90481 /** 90482 * @method textStyle 90483 * @return {String} 90484 */ 90485 _main.default.prototype.textStyle = function (theStyle) { 90486 var _this$_renderer4; 90487 _main.default._validateParameters('textStyle', arguments); 90488 return (_this$_renderer4 = this._renderer).textStyle.apply(_this$_renderer4, arguments); 90489 }; 90490 /** 90491 * Calculates and returns the width of any character or text string. 90492 * 90493 * @method textWidth 90494 * @param {String} theText the String of characters to measure 90495 * @return {Number} the calculated width 90496 * @example 90497 * <div> 90498 * <code> 90499 * textSize(28); 90500 * 90501 * let aChar = 'P'; 90502 * let cWidth = textWidth(aChar); 90503 * text(aChar, 0, 40); 90504 * line(cWidth, 0, cWidth, 50); 90505 * 90506 * let aString = 'p5.js'; 90507 * let sWidth = textWidth(aString); 90508 * text(aString, 0, 85); 90509 * line(sWidth, 50, sWidth, 100); 90510 * 90511 * describe('Letter P and p5.js are displayed with vertical lines at end.'); 90512 * </code> 90513 * </div> 90514 */ 90515 _main.default.prototype.textWidth = function () { 90516 var _this$_renderer5; 90517 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 90518 args[_key] = arguments[_key]; 90519 } 90520 args[0] += ''; 90521 _main.default._validateParameters('textWidth', args); 90522 if (args[0].length === 0) { 90523 return 0; 90524 } 90525 return (_this$_renderer5 = this._renderer).textWidth.apply(_this$_renderer5, args); 90526 }; 90527 /** 90528 * Returns the ascent of the current font at its current size. The ascent 90529 * represents the distance, in pixels, of the tallest character above 90530 * the baseline. 90531 * @method textAscent 90532 * @return {Number} 90533 * @example 90534 * <div> 90535 * <code> 90536 * let base = height * 0.75; 90537 * let scalar = 0.8; // Different for each font 90538 * 90539 * textSize(32); // Set initial text size 90540 * let asc = textAscent() * scalar; // Calc ascent 90541 * line(0, base - asc, width, base - asc); 90542 * text('dp', 0, base); // Draw text on baseline 90543 * 90544 * textSize(64); // Increase text size 90545 * asc = textAscent() * scalar; // Recalc ascent 90546 * line(40, base - asc, width, base - asc); 90547 * text('dp', 40, base); // Draw text on baseline 90548 * </code> 90549 * </div> 90550 */ 90551 _main.default.prototype.textAscent = function () { 90552 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 90553 args[_key2] = arguments[_key2]; 90554 } 90555 _main.default._validateParameters('textAscent', args); 90556 return this._renderer.textAscent(); 90557 }; 90558 /** 90559 * Returns the descent of the current font at its current size. The descent 90560 * represents the distance, in pixels, of the character with the longest 90561 * descender below the baseline. 90562 * @method textDescent 90563 * @return {Number} 90564 * @example 90565 * <div> 90566 * <code> 90567 * let base = height * 0.75; 90568 * let scalar = 0.8; // Different for each font 90569 * 90570 * textSize(32); // Set initial text size 90571 * let desc = textDescent() * scalar; // Calc descent 90572 * line(0, base + desc, width, base + desc); 90573 * text('dp', 0, base); // Draw text on baseline 90574 * 90575 * textSize(64); // Increase text size 90576 * desc = textDescent() * scalar; // Recalc descent 90577 * line(40, base + desc, width, base + desc); 90578 * text('dp', 40, base); // Draw text on baseline 90579 * </code> 90580 * </div> 90581 */ 90582 _main.default.prototype.textDescent = function () { 90583 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 90584 args[_key3] = arguments[_key3]; 90585 } 90586 _main.default._validateParameters('textDescent', args); 90587 return this._renderer.textDescent(); 90588 }; 90589 /** 90590 * Helper function to measure ascent and descent. 90591 */ 90592 _main.default.prototype._updateTextMetrics = function () { 90593 return this._renderer._updateTextMetrics(); 90594 }; 90595 /** 90596 * Specifies how lines of text are wrapped within a text box. This requires a max-width set on the text area, specified in <a href="#/p5/text">text()</a> as parameter `x2`. 90597 *
90598 * WORD wrap style only breaks lines at spaces. A single string without spaces that exceeds the boundaries of the canvas or text area is not truncated, and will overflow the desired area, disappearing at the canvas edge. 90599 * 90600 * CHAR wrap style breaks lines wherever needed to stay within the text box. 90601 * 90602 * WORD is the default wrap style, and both styles will still break lines at any line breaks (`\n`) specified in the original text. The text area max-height parameter (`y2`) also still applies to wrapped text in both styles, lines of text that do not fit within the text area will not be drawn to the screen. 90603 * 90604 * @method textWrap 90605 * @param {Constant} wrapStyle text wrapping style, either WORD or CHAR 90606 * @return {String} wrapStyle 90607 * @example 90608 * <div> 90609 * <code> 90610 * textSize(20); 90611 * textWrap(WORD); 90612 * text('Have a wonderful day', 0, 10, 100); 90613 * </code> 90614 * </div> 90615 * <div> 90616 * <code> 90617 * textSize(20); 90618 * textWrap(CHAR); 90619 * text('Have a wonderful day', 0, 10, 100); 90620 * </code> 90621 * </div> 90622 * <div> 90623 * <code> 90624 * textSize(20); 90625 * textWrap(CHAR); 90626 * text('ç¥ä½ æç¾å¥½çä¸å¤©', 0, 10, 100); 90627 * </code> 90628 * </div> 90629 * <div> 90630 * <code> 90631 * const scream = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; 90632 * textSize(20); 90633 * textWrap(WORD); 90634 * text(scream, 0, 0, 100); 90635 * fill(0, 0, 0, 75); 90636 * text(scream, 0, 20, 100); 90637 * fill(0, 0, 0, 50); 90638 * text(scream, 0, 40, 100); 90639 * fill(0, 0, 0, 25); 90640 * text(scream, 0, 60, 100); 90641 * strokeWeight(2); 90642 * ellipseMode(CENTER); 90643 * fill(255); 90644 * ellipse(15, 50, 15, 15); 90645 * fill(0); 90646 * ellipse(11, 47, 1, 1); 90647 * ellipse(19, 47, 1, 1); 90648 * ellipse(15, 52, 5, 5); 90649 * line(15, 60, 15, 70); 90650 * line(15, 65, 5, 55); 90651 * line(15, 65, 25, 55); 90652 * line(15, 70, 10, 80); 90653 * line(15, 70, 20, 80); 90654 * </code> 90655 * </div> 90656 */ 90657 _main.default.prototype.textWrap = function (wrapStyle) { 90658 if (wrapStyle !== 'WORD' && wrapStyle !== 'CHAR') { 90659 throw 'Error: textWrap accepts only WORD or CHAR'; 90660 } 90661 return this._renderer.textWrap(wrapStyle); 90662 }; 90663 var _default = _main.default; 90664 exports.default = _default; 90665 }, 90666 { 90667 '../core/main': 290 90668 } 90669 ], 90670 327: [ 90671 function (_dereq_, module, exports) { 90672 'use strict'; 90673 _dereq_('core-js/modules/es.symbol'); 90674 _dereq_('core-js/modules/es.symbol.description'); 90675 _dereq_('core-js/modules/es.symbol.iterator'); 90676 _dereq_('core-js/modules/es.array.concat'); 90677 _dereq_('core-js/modules/es.array.includes'); 90678 _dereq_('core-js/modules/es.array.iterator'); 90679 _dereq_('core-js/modules/es.array.last-index-of'); 90680 _dereq_('core-js/modules/es.array.slice'); 90681 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 90682 _dereq_('core-js/modules/es.object.to-string'); 90683 _dereq_('core-js/modules/es.regexp.exec'); 90684 _dereq_('core-js/modules/es.string.iterator'); 90685 _dereq_('core-js/modules/es.string.split'); 90686 _dereq_('core-js/modules/es.weak-map'); 90687 _dereq_('core-js/modules/web.dom-collections.iterator'); 90688 function _typeof2(obj) { 90689 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 90690 _typeof2 = function _typeof2(obj) { 90691 return typeof obj; 90692 }; 90693 } else { 90694 _typeof2 = function _typeof2(obj) { 90695 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 90696 }; 90697 } 90698 return _typeof2(obj); 90699 } 90700 function _typeof(obj) { 90701 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 90702 _typeof = function _typeof(obj) { 90703 return _typeof2(obj); 90704 }; 90705 } else { 90706 _typeof = function _typeof(obj) { 90707 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 90708 }; 90709 } 90710 return _typeof(obj); 90711 } 90712 _dereq_('core-js/modules/es.array.concat'); 90713 _dereq_('core-js/modules/es.array.includes'); 90714 _dereq_('core-js/modules/es.array.last-index-of'); 90715 _dereq_('core-js/modules/es.array.slice'); 90716 _dereq_('core-js/modules/es.regexp.exec'); 90717 _dereq_('core-js/modules/es.string.split'); 90718 Object.defineProperty(exports, '__esModule', { 90719 value: true 90720 }); 90721 exports.default = void 0; 90722 var _main = _interopRequireDefault(_dereq_('../core/main')); 90723 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 90724 var opentype = _interopRequireWildcard(_dereq_('opentype.js')); 90725 _dereq_('../core/friendly_errors/validate_params'); 90726 _dereq_('../core/friendly_errors/file_errors'); 90727 _dereq_('../core/friendly_errors/fes_core'); 90728 function _getRequireWildcardCache() { 90729 if (typeof WeakMap !== 'function') return null; 90730 var cache = new WeakMap(); 90731 _getRequireWildcardCache = function _getRequireWildcardCache() { 90732 return cache; 90733 }; 90734 return cache; 90735 } 90736 function _interopRequireWildcard(obj) { 90737 if (obj && obj.__esModule) { 90738 return obj; 90739 } 90740 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 90741 return { 90742 default: 90743 obj 90744 }; 90745 } 90746 var cache = _getRequireWildcardCache(); 90747 if (cache && cache.has(obj)) { 90748 return cache.get(obj); 90749 } 90750 var newObj = { 90751 }; 90752 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 90753 for (var key in obj) { 90754 if (Object.prototype.hasOwnProperty.call(obj, key)) { 90755 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 90756 if (desc && (desc.get || desc.set)) { 90757 Object.defineProperty(newObj, key, desc); 90758 } else { 90759 newObj[key] = obj[key]; 90760 } 90761 } 90762 } 90763 newObj.default = obj; 90764 if (cache) { 90765 cache.set(obj, newObj); 90766 } 90767 return newObj; 90768 } 90769 function _interopRequireDefault(obj) { 90770 return obj && obj.__esModule ? obj : { 90771 default: 90772 obj 90773 }; 90774 } /** 90775 * @module Typography 90776 * @submodule Loading & Displaying 90777 * @for p5 90778 * @requires core 90779 */ 90780 /** 90781 * Loads an opentype font file (.otf, .ttf) from a file or a URL, 90782 * and returns a <a href="#/p5.Font">p5.Font</a> object. This function 90783 * is asynchronous, meaning it may not finish before the next line in 90784 * your sketch is executed. 90785 * 90786 * The path to the font should be relative to the HTML file 90787 * that links in your sketch. Loading fonts from a URL or other 90788 * remote location may be blocked due to your browser's built-in 90789 * security. 90790 * 90791 * @method loadFont 90792 * @param {String} path name of the file or url to load 90793 * @param {Function} [callback] function to be executed after 90794 * <a href="#/p5/loadFont">loadFont()</a> completes 90795 * @param {Function} [onError] function to be executed if 90796 * an error occurs 90797 * @return {p5.Font} <a href="#/p5.Font">p5.Font</a> object 90798 * @example 90799 * 90800 * Calling loadFont() inside <a href="#/p5/preload">preload()</a> guarantees 90801 * that the load operation will have completed before <a href="#/p5/setup">setup()</a> 90802 * and <a href="#/p5/draw">draw()</a> are called. 90803 * 90804 * <div><code> 90805 * let myFont; 90806 * function preload() { 90807 * myFont = loadFont('assets/inconsolata.otf'); 90808 * } 90809 * 90810 * function setup() {
90811 * fill('#ED225D'); 90812 * textFont(myFont); 90813 * textSize(36); 90814 * text('p5*js', 10, 50); 90815 * } 90816 * </code></div> 90817 * 90818 * Outside of <a href="#/p5/preload">preload()</a>, you may supply a 90819 * callback function to handle the object: 90820 * 90821 * <div><code> 90822 * function setup() { 90823 * loadFont('assets/inconsolata.otf', drawText); 90824 * } 90825 * 90826 * function drawText(font) { 90827 * fill('#ED225D'); 90828 * textFont(font, 36); 90829 * text('p5*js', 10, 50); 90830 * } 90831 * </code></div> 90832 * 90833 * You can also use the font filename string (without the file extension) to 90834 * style other HTML elements. 90835 * 90836 * <div><code> 90837 * function preload() { 90838 * loadFont('assets/inconsolata.otf'); 90839 * } 90840 * 90841 * function setup() { 90842 * let myDiv = createDiv('hello there'); 90843 * myDiv.style('font-family', 'Inconsolata'); 90844 * } 90845 * </code></div> 90846 * 90847 * @alt 90848 * p5*js in p5's theme dark pink 90849 * p5*js in p5's theme dark pink 90850 */ 90851 90852 _main.default.prototype.loadFont = function (path, onSuccess, onError) { 90853 _main.default._validateParameters('loadFont', arguments); 90854 var p5Font = new _main.default.Font(this); 90855 var self = this; 90856 opentype.load(path, function (err, font) { 90857 if (err) { 90858 _main.default._friendlyFileLoadError(4, path); 90859 if (typeof onError !== 'undefined') { 90860 return onError(err); 90861 } 90862 console.error(err, path); 90863 return; 90864 } 90865 p5Font.font = font; 90866 if (typeof onSuccess !== 'undefined') { 90867 onSuccess(p5Font); 90868 } 90869 self._decrementPreload(); // check that we have an acceptable font type 90870 var validFontTypes = [ 90871 'ttf', 90872 'otf', 90873 'woff', 90874 'woff2' 90875 ]; 90876 var fileNoPath = path.split('\\').pop().split('/').pop(); 90877 var lastDotIdx = fileNoPath.lastIndexOf('.'); 90878 var fontFamily; 90879 var newStyle; 90880 var fileExt = lastDotIdx < 1 ? null : fileNoPath.slice(lastDotIdx + 1); // if so, add it to the DOM (name-only) for use with DOM module 90881 if (validFontTypes.includes(fileExt)) { 90882 fontFamily = fileNoPath.slice(0, lastDotIdx !== - 1 ? lastDotIdx : 0); 90883 newStyle = document.createElement('style'); 90884 newStyle.appendChild(document.createTextNode('\n@font-face {\nfont-family: '.concat(fontFamily, ';\nsrc: url(').concat(path, ');\n}\n'))); 90885 document.head.appendChild(newStyle); 90886 } 90887 }); 90888 return p5Font; 90889 }; 90890 /** 90891 * Draws text to the screen. Displays the information specified in the first 90892 * parameter on the screen in the position specified by the additional 90893 * parameters. A default font will be used unless a font is set with the 90894 * <a href="#/p5/textFont">textFont()</a> function and a default size will be 90895 * used unless a font is set with <a href="#/p5/textSize">textSize()</a>. Change 90896 * the color of the text with the <a href="#/p5/fill">fill()</a> function. Change 90897 * the outline of the text with the <a href="#/p5/stroke">stroke()</a> and 90898 * <a href="#/p5/strokeWeight">
90898strokeWeight()</a> functions. 90899 * 90900 * The text displays in relation to the <a href="#/p5/textAlign">textAlign()</a> 90901 * function, which gives the option to draw to the left, right, and center of the 90902 * coordinates. 90903 * 90904 * The x2 and y2 parameters define a rectangular area to display within and 90905 * may only be used with string data. When these parameters are specified, 90906 * they are interpreted based on the current <a href="#/p5/rectMode">rectMode()</a> 90907 * setting. Text that does not fit completely within the rectangle specified will 90908 * not be drawn to the screen. If x2 and y2 are not specified, the baseline 90909 * alignment is the default, which means that the text will be drawn upwards 90910 * from x and y. 90911 * 90912 * <b>WEBGL</b>: Only opentype/truetype fonts are supported. You must load a font 90913 * using the <a href="#/p5/loadFont">loadFont()</a> method (see the example above). 90914 * <a href="#/p5/stroke">stroke()</a> currently has no effect in webgl mode. 90915 * Learn more about working with text in webgl mode on the 90916 * <a href="https://github.com/processing/p5.js/wiki/Getting-started-with-WebGL-in-p5#text">wiki</a>. 90917 * 90918 * @method text 90919 * @param {String|Object|Array|Number|Boolean} str the alphanumeric 90920 * symbols to be displayed 90921 * @param {Number} x x-coordinate of text 90922 * @param {Number} y y-coordinate of text 90923 * @param {Number} [x2] by default, the width of the text box, 90924 * see <a href="#/p5/rectMode">rectMode()</a> for more info 90925 * @param {Number} [y2] by default, the height of the text box, 90926 * see <a href="#/p5/rectMode">rectMode()</a> for more info 90927 * @chainable 90928 * @example 90929 * <div> 90930 * <code> 90931 * textSize(32); 90932 * text('word', 10, 30); 90933 * fill(0, 102, 153); 90934 * text('word', 10, 60); 90935 * fill(0, 102, 153, 51); 90936 * text('word', 10, 90); 90937 * </code> 90938 * </div> 90939 * <div> 90940 * <code> 90941 * let s = 'The quick brown fox jumped over the lazy dog.'; 90942 * fill(50); 90943 * text(s, 10, 10, 70, 80); // Text wraps within text box 90944 * </code> 90945 * </div> 90946 * 90947 * <div modernizr='webgl'> 90948 * <code> 90949 * let inconsolata; 90950 * function preload() { 90951 * inconsolata = loadFont('assets/inconsolata.otf'); 90952 * } 90953 * function setup() { 90954 * createCanvas(100, 100, WEBGL); 90955 * textFont(inconsolata); 90956 * textSize(width / 3); 90957 * textAlign(CENTER, CENTER); 90958 * } 90959 * function draw() { 90960 * background(0); 90961 * let time = millis(); 90962 * rotateX(time / 1000); 90963 * rotateZ(time / 1234); 90964 * text('p5.js', 0, 0); 90965 * } 90966 * </code> 90967 * </div> 90968 * 90969 * @alt 90970 * 'word' displayed 3 times going from black, blue to translucent blue 90971 * The text 'The quick brown fox jumped over the lazy dog' displayed. 90972 * The text 'p5.js' spinning in 3d 90973 */ 90974 _main.default.prototype.text = function (str, x, y, maxWidth, maxHeight) { 90975 var _this$_renderer; 90976 _main.default._validateParameters('text', arguments); 90977 return !(this._renderer._doFill || this._renderer._doStroke) ? this : (_this$_renderer = this._renderer).text.apply(_this$_renderer, arguments); 90978 }; 90979 /** 90980 * Sets the current font that will be drawn with the <a href="#/p5/text">text()</a> function. 90981 * If textFont() is called without any argument, it will return the current font if one has 90982 * been set already. If not, it will return the name of the default font as a string. 90983 * If textFont() is called with a font to use, it will return the p5 object. 90984 * 90985 * <b>WEBGL</b>: Only fonts loaded via <a href="#/p5/loadFont">loadFont()</a> are supported. 90986 * 90987 * @method textFont 90988 * @return {Object} the current font / p5 Object 90989 * 90990 * @example 90991 * <div> 90992 * <code> 90993 * fill(0); 90994 * textSize(12); 90995 * textFont('Georgia'); 90996 * text('Georgia', 12, 30); 90997 * textFont('Helvetica'); 90998 * text('Helvetica', 12, 60); 90999 * </code> 91000 * </div> 91001 * <div> 91002 * <code> 91003 * let fontRegular, fontItalic, fontBold; 91004 * function preload() { 91005 * fontRegular = loadFont('assets/Regular.otf'); 91006 * fontItalic = loadFont('assets/Italic.ttf'); 91007 * fontBold = loadFont('assets/Bold.ttf'); 91008 * } 91009 * function setup() { 91010 * background(210); 91011 * fill(0) 91012 .strokeWeight(0) 91013 .textSize(10); 91014 * textFont(fontRegular); 91015 * text('Font Style Normal', 10, 30); 91016 * textFont(fontItalic); 91017 * text('Font Style Italic', 10, 50); 91018 * textFont(fontBold); 91019 * text('Font Style Bold', 10, 70); 91020 * } 91021 * </code> 91022 * </div> 91023 * 91024 * @alt 91025 * word 'Georgia' displayed in font Georgia and 'Helvetica' in font Helvetica 91026 * words Font Style Normal displayed normally, Italic in italic and bold in bold 91027 */ 91028 /** 91029 * @method textFont 91030 * @param {Object|String} font a font loaded via <a href="#/p5/loadFont">loadFont()</a>, 91031 * or a String representing a <a href="https://mzl.la/2dOw8WD">web safe font</a> 91032 * (a font that is generally available across all systems) 91033 * @param {Number} [size] the font size to use 91034 * @chainable 91035 */ 91036 _main.default.prototype.textFont = function (theFont, theSize) { 91037 _main.default._validateParameters('textFont', arguments); 91038 if (arguments.length) { 91039 if (!theFont) { 91040 throw new Error('null font passed to textFont'); 91041 } 91042 this._renderer._setProperty('_textFont', theFont); 91043 if (theSize) { 91044 this._renderer._setProperty('_textSize', theSize); 91045 if (!this._renderer._leadingSet) { 91046 // only use a default value if not previously set (#5181) 91047 this._renderer._setProperty('_textLeading', theSize * constants._DEFAULT_LEADMULT); 91048 } 91049 } 91050 return this._renderer._applyTextProperties(); 91051 } 91052 return this._renderer._textFont; 91053 }; 91054 var _default = _main.default; 91055 exports.default = _default; 91056 }, 91057 { 91058 '../core/constants': 278, 91059 '../core/friendly_errors/fes_core': 281, 91060 '../core/friendly_errors/file_errors': 282, 91061 '../core/friendly_errors/validate_params': 285, 91062 '../core/main': 290,
91063 'core-js/modules/es.array.concat': 167, 91064 'core-js/modules/es.array.includes': 174, 91065 'core-js/modules/es.array.iterator': 176, 91066 'core-js/modules/es.array.last-index-of': 178, 91067 'core-js/modules/es.array.slice': 180, 91068 'core-js/modules/es.object.get-own-property-descriptor': 191, 91069 'core-js/modules/es.object.to-string': 195, 91070 'core-js/modules/es.regexp.exec': 199, 91071 'core-js/modules/es.string.iterator': 204, 91072 'core-js/modules/es.string.split': 209, 91073 'core-js/modules/es.symbol': 214, 91074 'core-js/modules/es.symbol.description': 212, 91075 'core-js/modules/es.symbol.iterator': 213, 91076 'core-js/modules/es.weak-map': 246, 91077 'core-js/modules/web.dom-collections.iterator': 248, 91078 'opentype.js': 263 91079 } 91080 ], 91081 328: [ 91082 function (_dereq_, module, exports) { 91083 'use strict'; 91084 _dereq_('core-js/modules/es.symbol'); 91085 _dereq_('core-js/modules/es.symbol.description'); 91086 _dereq_('core-js/modules/es.symbol.iterator'); 91087 _dereq_('core-js/modules/es.array.concat'); 91088 _dereq_('core-js/modules/es.array.fill'); 91089 _dereq_('core-js/modules/es.array.iterator'); 91090 _dereq_('core-js/modules/es.array.join'); 91091 _dereq_('core-js/modules/es.array.slice'); 91092 _dereq_('core-js/modules/es.array.splice'); 91093 _dereq_('core-js/modules/es.function.name'); 91094 _dereq_('core-js/modules/es.number.to-fixed'); 91095 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 91096 _dereq_('core-js/modules/es.object.to-string'); 91097 _dereq_('core-js/modules/es.regexp.exec'); 91098 _dereq_('core-js/modules/es.string.iterator'); 91099 _dereq_('core-js/modules/es.string.split'); 91100 _dereq_('core-js/modules/es.weak-map'); 91101 _dereq_('core-js/modules/web.dom-collections.iterator'); 91102 function _typeof2(obj) { 91103 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 91104 _typeof2 = function _typeof2(obj) { 91105 return typeof obj; 91106 }; 91107 } else { 91108 _typeof2 = function _typeof2(obj) { 91109 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 91110 }; 91111 } 91112 return _typeof2(obj); 91113 } 91114 _dereq_('core-js/modules/es.symbol'); 91115 _dereq_('core-js/modules/es.symbol.description'); 91116 _dereq_('core-js/modules/es.symbol.iterator'); 91117 _dereq_('core-js/modules/es.array.concat'); 91118 _dereq_('core-js/modules/es.array.fill'); 91119 _dereq_('core-js/modules/es.array.iterator'); 91120 _dereq_('core-js/modules/es.array.join'); 91121 _dereq_('core-js/modules/es.array.slice'); 91122 _dereq_('core-js/modules/es.array.splice'); 91123 _dereq_('core-js/modules/es.function.name'); 91124 _dereq_('core-js/modules/es.number.to-fixed'); 91125 _dereq_('core-js/modules/es.object.to-string'); 91126 _dereq_('core-js/modules/es.regexp.exec'); 91127 _dereq_('core-js/modules/es.string.iterator'); 91128 _dereq_('core-js/modules/es.string.split'); 91129 _dereq_('core-js/modules/web.dom-collections.iterator'); 91130 Object.defineProperty(exports, '__esModule', { 91131 value: true 91132 }); 91133 exports.default = void 0; 91134 var _main = _interopRequireDefault(_dereq_('../core/main')); 91135 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 91136 function _getRequireWildcardCache() { 91137 if (typeof WeakMap !== 'function') return null; 91138 var cache = new WeakMap(); 91139 _getRequireWildcardCache = function _getRequireWildcardCache() { 91140 return cache; 91141 }; 91142 return cache; 91143 } 91144 function _interopRequireWildcard(obj) { 91145 if (obj && obj.__esModule) { 91146 return obj; 91147 } 91148 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 91149 return { 91150 default: 91151 obj 91152 }; 91153 } 91154 var cache = _getRequireWildcardCache(); 91155 if (cache && cache.has(obj)) { 91156 return cache.get(obj); 91157 } 91158 var newObj = { 91159 }; 91160 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 91161 for (var key in obj) { 91162 if (Object.prototype.hasOwnProperty.call(obj, key)) { 91163 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 91164 if (desc && (desc.get || desc.set)) { 91165 Object.defineProperty(newObj, key, desc); 91166 } else { 91167 newObj[key] = obj[key]; 91168 } 91169 } 91170 } 91171 newObj.default = obj; 91172 if (cache) { 91173 cache.set(obj, newObj); 91174 } 91175 return newObj; 91176 } 91177 function _interopRequireDefault(obj) { 91178 return obj && obj.__esModule ? obj : { 91179 default: 91180 obj 91181 }; 91182 } 91183 function _typeof(obj) { 91184 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 91185 _typeof = function _typeof(obj) { 91186 return _typeof2(obj); 91187 }; 91188 } else { 91189 _typeof = function _typeof(obj) { 91190 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
91190ypeof2(obj); 91191 }; 91192 } 91193 return _typeof(obj); 91194 } /** 91195 * Base class for font handling 91196 * @class p5.Font 91197 * @constructor 91198 * @param {p5} [pInst] pointer to p5 instance 91199 */ 91200 91201 _main.default.Font = function (p) { 91202 this.parent = p; 91203 this.cache = { 91204 }; 91205 /** 91206 * Underlying opentype font implementation 91207 * @property font 91208 */ 91209 this.font = undefined; 91210 }; 91211 /** 91212 * Returns a tight bounding box for the given text string using this 91213 * font 91214 * 91215 * @method textBounds 91216 * @param {String} line a line of text 91217 * @param {Number} x x-position 91218 * @param {Number} y y-position 91219 * @param {Number} [fontSize] font size to use (optional) Default is 12. 91220 * @param {Object} [options] opentype options (optional) 91221 * opentype fonts contains alignment and baseline options. 91222 * Default is 'LEFT' and 'alphabetic' 91223 * 91224 * @return {Object} a rectangle object with properties: x, y, w, h 91225 * 91226 * @example 91227 * <div> 91228 * <code> 91229 * let font; 91230 * let textString = 'Lorem ipsum dolor sit amet.'; 91231 * function preload() { 91232 * font = loadFont('./assets/Regular.otf'); 91233 * } 91234 * function setup() { 91235 * background(210); 91236 * 91237 * let bbox = font.textBounds(textString, 10, 30, 12); 91238 * fill(255); 91239 * stroke(0); 91240 * rect(bbox.x, bbox.y, bbox.w, bbox.h); 91241 * fill(0); 91242 * noStroke(); 91243 * 91244 * textFont(font); 91245 * textSize(12); 91246 * text(textString, 10, 30); 91247 * 91248 * describe(`Words âLorem ipsum dolâ go off canvas and 91249 * contained by white bounding box`); 91250 * } 91251 * </code> 91252 * </div> 91253 */ 91254 _main.default.Font.prototype.textBounds = function (str) { 91255 var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; 91256 var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; 91257 var fontSize = arguments.length > 3 ? arguments[3] : undefined; 91258 var opts = arguments.length > 4 ? arguments[4] : undefined; // Check cache for existing bounds. Take into consideration the text alignment 91259 // settings. Default alignment should match opentype's origin: left-aligned & 91260 // alphabetic baseline. 91261 var p = opts && opts.renderer && opts.renderer._pInst || this.parent; 91262 var ctx = p._renderer.drawingContext; 91263 var alignment = ctx.textAlign || constants.LEFT; 91264 var baseline = ctx.textBaseline || constants.BASELINE; 91265 var cacheResults = false; 91266 var result; 91267 var key; 91268 fontSize = fontSize || p._renderer._textSize; // NOTE: cache disabled for now pending further discussion of #3436 91269 if (cacheResults) { 91270 key = cacheKey('textBounds', str, x, y, fontSize, alignment, baseline); 91271 result = this.cache[key]; 91272 } 91273 if (!result) { 91274 var minX = [ 91275 ]; 91276 var minY; 91277 var maxX = [ 91278 ]; 91279 var maxY; 91280 var pos; 91281 var xCoords = [ 91282 ]; 91283 xCoords[0] = [ 91284 ]; 91285 var yCoords = [ 91286 ]; 91287 var scale = this._scale(fontSize); 91288 var lineHeight = p._renderer.textLeading(); 91289 var lineCount = 0; 91290 this.font.forEachGlyph(str, x, y, fontSize, opts, function (glyph, gX, gY, gFontSize) { 91291 var gm = glyph.getMetrics(); 91292 if (glyph.index === 0 || glyph.index === 10) { 91293 lineCount += 1; 91294 xCoords[lineCount] = [ 91295 ]; 91296 } else { 91297 xCoords[lineCount].push(gX + gm.xMin * scale); 91298 xCoords[lineCount].push(gX + gm.xMax * scale); 91299 yCoords.push(gY + lineCount * lineHeight + - gm.yMin * scale); 91300 yCoords.push(gY + lineCount * lineHeight + - gm.yMax * scale); 91301 } 91302 }); 91303 if (xCoords[lineCount].length > 0) { 91304 minX[lineCount] = Math.min.apply(null, xCoords[lineCount]); 91305 maxX[lineCount] = Math.max.apply(null, xCoords[lineCount]); 91306 } 91307 var finalMaxX = 0; 91308 for (var i = 0; i <= lineCount; i++) { 91309 minX[i] = Math.min.apply(null, xCoords[i]); 91310 maxX[i] = Math.max.apply(null, xCoords[i]); 91311 var lineLength = maxX[i] - minX[i]; 91312 if (lineLength > finalMaxX) { 91313 finalMaxX = lineLength; 91314 } 91315 } 91316 var finalMinX = Math.min.apply(null, minX); 91317 minY = Math.min.apply(null, yCoords); 91318 maxY = Math.max.apply(null, yCoords); 91319 result = { 91320 x: finalMinX, 91321 y: minY, 91322 h: maxY - minY, 91323 w: finalMaxX, 91324 advance: finalMinX - x 91325 }; // Bounds are now calculated, so shift the x & y to match alignment settings 91326 pos = this._handleAlignment(p._renderer, str, result.x, result.y, result.w + result.advance); 91327 result.x = pos.x; 91328 result.y = pos.y; 91329 if (cacheResults) { 91330 this.cache[key] = result; 91331 } 91332 } 91333 return result; 91334 }; 91335 /** 91336 * Computes an array of points following the path for specified text 91337 * 91338 * @method textToPoints 91339 * @param {String} txt a line of text 91340 * @param {Number} x x-position 91341 * @param {Number} y y-position 91342 * @param {Number} fontSize font size to use (optional) 91343 * @param {Object} [options] an (optional) object that can contain: 91344 * 91345 * <br>sampleFactor - the ratio of path-length to number of samples 91346 * (default=.1); higher values yield more points and are therefore 91347 * more precise 91348 * 91349 * <br>simplifyThreshold - if set to a non-zero value, collinear points will be 91350 * be removed from the polygon; the value represents the threshold angle to use 91351 * when determining whether two edges are collinear 91352 * 91353 * @return {Array} an array of points, each with x, y, alpha (the path angle) 91354 * @example 91355 * <div> 91356 * <code> 91357 * let font; 91358 * function preload() { 91359 * font = loadFont('assets/inconsolata.otf'); 91360 * } 91361 * 91362 * let points; 91363 * let bounds; 91364 * function setup() { 91365 * createCanvas(100, 100); 91366 * stroke(0); 91367 * fill(255, 104, 204); 91368 * 91369 * points = font.textToPoints('p5', 0, 0, 10, { 91370 * sampleFactor: 5, 91371 * simplifyThreshold: 0 91372 * }); 91373 * bounds = font.textBounds(' p5 ', 0, 0, 10); 91374 * } 91375 * 91376 * function draw() { 91377 * background(255); 91378 * beginShape(); 91379 * translate(-bounds.x * width / bounds.w, -bounds.y * height / bounds.h); 91380 * for (let i = 0; i < points.length; i++) { 91381 * let p = points[i]; 91382 * vertex( 91383 * p.x * width / bounds.w +
91384 * sin(20 * p.y / bounds.h + millis() / 1000) * width / 30, 91385 * p.y * height / bounds.h 91386 * ); 91387 * } 91388 * endShape(CLOSE); 91389 * } 91390 * </code> 91391 * </div> 91392 */ 91393 _main.default.Font.prototype.textToPoints = function (txt, x, y, fontSize, options) { 91394 var xoff = 0; 91395 var result = [ 91396 ]; 91397 var glyphs = this._getGlyphs(txt); 91398 function isSpace(i) { 91399 return glyphs[i].name && glyphs[i].name === 'space' || txt.length === glyphs.length && txt[i] === ' ' //|| 91400 //(glyphs[i].index && glyphs[i].index === 3) 91401 ; 91402 } 91403 fontSize = fontSize || this.parent._renderer._textSize; 91404 for (var i = 0; i < glyphs.length; i++) { 91405 if (!isSpace(i)) { 91406 // fix to #1817, #2069 91407 var gpath = glyphs[i].getPath(x, y, fontSize), 91408 paths = splitPaths(gpath.commands); 91409 for (var j = 0; j < paths.length; j++) { 91410 var pts = pathToPoints(paths[j], options); 91411 for (var k = 0; k < pts.length; k++) { 91412 pts[k].x += xoff; 91413 result.push(pts[k]); 91414 } 91415 } 91416 } 91417 xoff += glyphs[i].advanceWidth * this._scale(fontSize); 91418 } 91419 return result; 91420 }; // ----------------------------- End API ------------------------------ 91421 /** 91422 * Returns the set of opentype glyphs for the supplied string. 91423 * 91424 * Note that there is not a strict one-to-one mapping between characters 91425 * and glyphs, so the list of returned glyphs can be larger or smaller 91426 * than the length of the given string. 91427 * 91428 * @private 91429 * @param {String} str the string to be converted 91430 * @return {Array} the opentype glyphs 91431 */ 91432 _main.default.Font.prototype._getGlyphs = function (str) { 91433 return this.font.stringToGlyphs(str); 91434 }; 91435 /** 91436 * Returns an opentype path for the supplied string and position. 91437 * 91438 * @private 91439 * @param {String} line a line of text 91440 * @param {Number} x x-position 91441 * @param {Number} y y-position 91442 * @param {Object} options opentype options (optional) 91443 * @return {Object} the opentype path 91444 */ 91445 _main.default.Font.prototype._getPath = function (line, x, y, options) { 91446 var p = options && options.renderer && options.renderer._pInst || this.parent, 91447 renderer = p._renderer, 91448 pos = this._handleAlignment(renderer, line, x, y); 91449 return this.font.getPath(line, pos.x, pos.y, renderer._textSize, options); 91450 }; 91451 /* 91452 * Creates an SVG-formatted path-data string 91453 * (See http://www.w3.org/TR/SVG/paths.html#PathData) 91454 * from the given opentype path or string/position 91455 * 91456 * @param {Object} path an opentype path, OR the following: 91457 * 91458 * @param {String} line a line of text 91459 * @param {Number} x x-position 91460 * @param {Number} y y-position 91461 * @param {Object} options opentype options (optional), set options.decimals 91462 * to set the decimal precision of the path-data 91463 * 91464 * @return {Object} this p5.Font object 91465 */ 91466 _main.default.Font.prototype._getPathData = function (line, x, y, options) { 91467 var decimals = 3; // create path from string/position 91468 if (typeof line === 'string' && arguments.length > 2) { 91469 line = this._getPath(line, x, y, options); 91470 } else if (_typeof(x) === 'object') { 91471 // handle options specified in 2nd arg 91472 options = x; 91473 } // handle svg arguments 91474 91475 if (options && typeof options.decimals === 'number') { 91476 decimals = options.decimals; 91477 } 91478 return line.toPathData(decimals); 91479 }; 91480 /* 91481 * Creates an SVG <path> element, as a string, 91482 * from the given opentype path or string/position 91483 * 91484 * @param {Object} path an opentype path, OR the following: 91485 * 91486 * @param {String} line a line of text 91487 * @param {Number} x x-position 91488 * @param {Number} y y-position 91489 * @param {Object} options opentype options (optional), set options.decimals 91490 * to set the decimal precision of the path-data in the <path> element, 91491 * options.fill to set the fill color for the <path> element, 91492 * options.stroke to set the stroke color for the <path> element, 91493 * options.strokeWidth to set the strokeWidth for the <path> element. 91494 * 91495 * @return {Object} this p5.Font object 91496 */ 91497 _main.default.Font.prototype._getSVG = function (line, x, y, options) { 91498 var decimals = 3; // create path from string/position 91499 if (typeof line === 'string' && arguments.length > 2) { 91500 line = this._getPath(line, x, y, options); 91501 } else if (_typeof(x) === 'object') { 91502 // handle options specified in 2nd arg 91503 options = x; 91504 } // handle svg arguments 91505 91506 if (options) { 91507 if (typeof options.decimals === 'number') { 91508 decimals = options.decimals; 91509 } 91510 if (typeof options.strokeWidth === 'number') { 91511 line.strokeWidth = options.strokeWidth; 91512 } 91513 if (typeof options.fill !== 'undefined') { 91514 line.fill = options.fill; 91515 } 91516 if (typeof options.stroke !== 'undefined') { 91517 line.stroke = options.stroke; 91518 } 91519 } 91520 return line.toSVG(decimals); 91521 }; 91522 /* 91523 * Renders an opentype path or string/position 91524 * to the current graphics context 91525 * 91526 * @param {Object} path an opentype path, OR the following: 91527 * 91528 * @param {String} line a line of text 91529 * @param {Number} x x-position 91530 * @param {Number} y y-position 91531 * @param {Object} options opentype options (optional) 91532 * 91533 * @return {p5.Font} this p5.Font object 91534 */ 91535 _main.default.Font.prototype._renderPath = function (line, x, y, options) { 91536 var pdata; 91537 var pg = options && options.renderer || this.parent._renderer; 91538 var ctx = pg.drawingContext; 91539 if (_typeof(line) === 'object' && line.commands) { 91540 pdata = line.commands; 91541 } else { 91542 //pos = handleAlignment(p, ctx, line, x, y); 91543 pdata = this._getPath(line, x, y, options).commands; 91544 } 91545 ctx.beginPath(); 91546 var _iteratorNormalCompletion = true; 91547 var _didIteratorError = false;
91548 var _iteratorError = undefined; 91549 try { 91550 for (var _iterator = pdata[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 91551 var cmd = _step.value; 91552 if (cmd.type === 'M') { 91553 ctx.moveTo(cmd.x, cmd.y); 91554 } else if (cmd.type === 'L') { 91555 ctx.lineTo(cmd.x, cmd.y); 91556 } else if (cmd.type === 'C') { 91557 ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); 91558 } else if (cmd.type === 'Q') { 91559 ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y); 91560 } else if (cmd.type === 'Z') { 91561 ctx.closePath(); 91562 } 91563 } // only draw stroke if manually set by user 91564 91565 } catch (err) { 91566 _didIteratorError = true; 91567 _iteratorError = err; 91568 } finally { 91569 try { 91570 if (!_iteratorNormalCompletion && _iterator.return != null) { 91571 _iterator.return(); 91572 } 91573 } finally { 91574 if (_didIteratorError) { 91575 throw _iteratorError; 91576 } 91577 } 91578 } 91579 if (pg._doStroke && pg._strokeSet) { 91580 ctx.stroke(); 91581 } 91582 if (pg._doFill) { 91583 // if fill hasn't been set by user, use default-text-fill 91584 if (!pg._fillSet) { 91585 pg._setFill(constants._DEFAULT_TEXT_FILL); 91586 } 91587 ctx.fill(); 91588 } 91589 return this; 91590 }; 91591 _main.default.Font.prototype._textWidth = function (str, fontSize) { 91592 return this.font.getAdvanceWidth(str, fontSize); 91593 }; 91594 _main.default.Font.prototype._textAscent = function (fontSize) { 91595 return this.font.ascender * this._scale(fontSize); 91596 }; 91597 _main.default.Font.prototype._textDescent = function (fontSize) { 91598 return - this.font.descender * this._scale(fontSize); 91599 }; 91600 _main.default.Font.prototype._scale = function (fontSize) { 91601 return 1 / this.font.unitsPerEm * (fontSize || this.parent._renderer._textSize); 91602 }; 91603 _main.default.Font.prototype._handleAlignment = function (renderer, line, x, y, textWidth) { 91604 var fontSize = renderer._textSize; 91605 if (typeof textWidth === 'undefined') { 91606 textWidth = this._textWidth(line, fontSize); 91607 } 91608 switch (renderer._textAlign) { 91609 case constants.CENTER: 91610 x -= textWidth / 2; 91611 break; 91612 case constants.RIGHT: 91613 x -= textWidth; 91614 break; 91615 } 91616 switch (renderer._textBaseline) { 91617 case constants.TOP: 91618 y += this._textAscent(fontSize); 91619 break; 91620 case constants.CENTER: 91621 y += this._textAscent(fontSize) / 2; 91622 break; 91623 case constants.BOTTOM: 91624 y -= this._textDescent(fontSize); 91625 break; 91626 } 91627 return { 91628 x: x, 91629 y: y 91630 }; 91631 }; // path-utils 91632 function pathToPoints(cmds, options) { 91633 var opts = parseOpts(options, { 91634 sampleFactor: 0.1, 91635 simplifyThreshold: 0 91636 }); 91637 var // total-length 91638 len = pointAtLength(cmds, 0, 1), 91639 t = len / (len * opts.sampleFactor), 91640 pts = [ 91641 ]; 91642 for (var i = 0; i < len; i += t) { 91643 pts.push(pointAtLength(cmds, i)); 91644 } 91645 if (opts.simplifyThreshold) { 91646 simplify(pts, opts.simplifyThreshold); 91647 } 91648 return pts; 91649 } 91650 function simplify(pts) { 91651 var angle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; 91652 var num = 0; 91653 for (var i = pts.length - 1; pts.length > 3 && i >= 0; --i) { 91654 if (collinear(at(pts, i - 1), at(pts, i), at(pts, i + 1), angle)) { 91655 // Remove the middle point 91656 pts.splice(i % pts.length, 1); 91657 num++; 91658 } 91659 } 91660 return num; 91661 } 91662 function splitPaths(cmds) { 91663 var paths = [ 91664 ]; 91665 var current; 91666 for (var i = 0; i < cmds.length; i++) { 91667 if (cmds[i].type === 'M') { 91668 if (current) { 91669 paths.push(current); 91670 } 91671 current = [ 91672 ]; 91673 } 91674 current.push(cmdToArr(cmds[i])); 91675 } 91676 paths.push(current); 91677 return paths; 91678 } 91679 function cmdToArr(cmd) { 91680 var arr = [ 91681 cmd.type 91682 ]; 91683 if (cmd.type === 'M' || cmd.type === 'L') { 91684 // moveto or lineto 91685 arr.push(cmd.x, cmd.y); 91686 } else if (cmd.type === 'C') { 91687 arr.push(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); 91688 } else if (cmd.type === 'Q') { 91689 arr.push(cmd.x1, cmd.y1, cmd.x, cmd.y); 91690 } // else if (cmd.type === 'Z') { /* no-op */ } 91691 91692 return arr; 91693 } 91694 function parseOpts(options, defaults) { 91695 if (_typeof(options) !== 'object') { 91696 options = defaults; 91697 } else { 91698 for (var key in defaults) { 91699 if (typeof options[key] === 'undefined') { 91700 options[key] = defaults[key]; 91701 } 91702 } 91703 } 91704 return options; 91705 } //////////////////////// Helpers //////////////////////////// 91706 91707 function at(v, i) { 91708 var s = v.length; 91709 return v[i < 0 ? i % s + s : i % s]; 91710 } 91711 function collinear(a, b, c, thresholdAngle) { 91712 if (!thresholdAngle) { 91713 return areaTriangle(a, b, c) === 0; 91714 } 91715 if (typeof collinear.tmpPoint1 === 'undefined') { 91716 collinear.tmpPoint1 = [ 91717 ]; 91718 collinear.tmpPoint2 = [ 91719 ]; 91720 } 91721 var ab = collinear.tmpPoint1, 91722 bc = collinear.tmpPoint2; 91723 ab.x = b.x - a.x; 91724 ab.y = b.y - a.y; 91725 bc.x = c.x - b.x; 91726 bc.y = c.y - b.y; 91727 var dot = ab.x * bc.x + ab.y * bc.y, 91728 magA = Math.sqrt(ab.x * ab.x + ab.y * ab.y), 91729 magB = Math.sqrt(bc.x * bc.x + bc.y * bc.y), 91730 angle = Math.acos(dot / (magA * magB)); 91731 return angle < thresholdAngle; 91732 } 91733 function areaTriangle(a, b, c) { 91734 return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]); 91735 } // Portions of below code copyright 2008 Dmitry Baranovskiy (via MIT license) 91736 91737 function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { 91738 var t1 = 1 - t; 91739 var t13 = Math.pow(t1, 3); 91740 var t12 = Math.pow(t1, 2); 91741 var t2 = t * t; 91742 var t3 = t2 * t; 91743 var x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x; 91744 var y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y; 91745 var mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x); 91746 var my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y); 91747 var nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x); 91748 var ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y); 91749 var ax = t1 * p1x + t * c1x; 91750 var ay = t1 * p1y + t * c1y; 91751 var cx = t1 * c2x + t * p2x; 91752 var cy = t1 * c2y + t * p2y; 91753 var alpha = 90 - Math.atan2(mx - nx, my - ny) * 180 / Math.PI; 91754 if (mx > nx || my < ny) { 91755 alpha += 180; 91756 } 91757 return { 91758 x: x, 91759 y: y, 91760 m: { 91761 x: mx, 91762 y: my 91763 }, 91764 n: { 91765 x: nx, 91766 y: ny 91767 }, 91768 start: { 91769 x: ax, 91770 y: ay 91771 }, 91772 end: { 91773 x: cx, 91774 y: cy 91775 }, 91776 alpha: alpha 91777 }; 91778 } 91779 function getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) { 91780 return length == null ? bezlen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) : findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, getTatLen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length)); 91781 } 91782 function pointAtLength(path, length, istotal) { 91783 path = path2curve(path); 91784 var x; 91785 var y; 91786 var p; 91787 var l; 91788 var sp = ''; 91789 var subpaths = { 91790 }; 91791 var point; 91792 var len = 0; 91793 for (var i = 0, ii = path.length; i < ii; i++) { 91794 p = path[i]; 91795 if (p[0] === 'M') { 91796 x = + p[1]; 91797 y = + p[2]; 91798 } else { 91799 l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]); 91800 if (len + l > length) { 91801 if (!istotal) { 91802 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len); 91803 return { 91804 x: point.x, 91805 y: point.y, 91806 alpha: point.alpha 91807 }; 91808 } 91809 } 91810 len += l; 91811 x = + p[5]; 91812 y = + p[6]; 91813 } 91814 sp += p.shift() + p; 91815 } 91816 subpaths.end = sp; 91817 point = istotal ? len : findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1); 91818 if (point.alpha) { 91819 point = { 91820 x: point.x, 91821 y: point.y, 91822 alpha: point.alpha 91823 }; 91824 } 91825 return point; 91826 } 91827 function pathToAbsolute(pathArray) { 91828 var res = [ 91829 ], 91830 x = 0, 91831 y = 0, 91832 mx = 0, 91833 my = 0, 91834 start = 0; 91835 if (!pathArray) { 91836 // console.warn("Unexpected state: undefined pathArray"); // shouldn't happen 91837 return res; 91838 } 91839 if (pathArray[0][0] === 'M') { 91840 x = + pathArray[0][1]; 91841 y = + pathArray[0][2]; 91842 mx = x; 91843 my = y; 91844 start++; 91845 res[0] = [ 91846 'M', 91847 x, 91848 y 91849 ]; 91850 } 91851 var dots; 91852 var crz = pathArray.length === 3 && pathArray[0][0] === 'M' && pathArray[1][0].toUpperCase() === 'R' && pathArray[2][0].toUpperCase() === 'Z'; 91853 for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) { 91854 res.push(r = [ 91855 ]); 91856 pa = pathArray[i]; 91857 if (pa[0] !== String.prototype.toUpperCase.call(pa[0])) { 91858 r[0] = String.prototype.toUpperCase.call(pa[0]); 91859 switch (r[0]) { 91860 case 'A': 91861 r[1] = pa[1]; 91862 r[2] = pa[2]; 91863 r[3] = pa[3]; 91864 r[4] = pa[4]; 91865 r[5] = pa[5]; 91866 r[6] = + (pa[6] + x); 91867 r[7] = + (pa[7] + y); 91868 break; 91869 case 'V': 91870 r[1] = + pa[1] + y; 91871 break; 91872 case 'H': 91873 r[1] = + pa[1] + x; 91874 break; 91875 case 'R': 91876 dots = [ 91877 x, 91878 y 91879 ].concat(pa.slice(1)); 91880 for (var j = 2, jj = dots.length; j < jj; j++) { 91881 dots[j] = + dots[j] + x; 91882 dots[++j] = + dots[j] + y; 91883 } 91884 res.pop(); 91885 res = res.concat(catmullRom2bezier(dots, crz)); 91886 break; 91887 case 'M': 91888 mx = + pa[1] + x; 91889 my = + pa[2] + y; 91890 break; 91891 default: 91892 for (var _j = 1, _jj = pa.length; _j < _jj; _j++) { 91893 r[_j] = + pa[_j] + (_j % 2 ? x : y); 91894 } 91895 } 91896 } else if (pa[0] === 'R') { 91897 dots = [ 91898 x, 91899 y 91900 ].concat(pa.slice(1)); 91901 res.pop(); 91902 res = res.concat(catmullRom2bezier(dots, crz)); 91903 r = [ 91904 'R' 91905 ].concat(pa.slice( - 2)); 91906 } else { 91907 for (var k = 0, kk = pa.length; k < kk; k++) { 91908 r[k] = pa[k]; 91909 } 91910 } 91911 switch (r[0]) { 91912 case 'Z': 91913 x = mx; 91914 y = my; 91915 break; 91916 case 'H': 91917 x = r[1]; 91918 break; 91919 case 'V': 91920 y = r[1]; 91921 break; 91922 case 'M': 91923 mx = r[r.length - 2]; 91924 my = r[r.length - 1]; 91925 break; 91926 default: 91927 x = r[r.length - 2]; 91928 y = r[r.length - 1]; 91929 } 91930 } 91931 return res; 91932 } 91933 function path2curve(path, path2) { 91934 var p = pathToAbsolute(path), 91935 p2 = path2 && pathToAbsolute(path2); 91936 var attrs = { 91937 x: 0, 91938 y: 0, 91939 bx: 0, 91940 by: 0, 91941 X: 0, 91942 Y: 0, 91943 qx: null, 91944 qy: null 91945 }; 91946 var attrs2 = { 91947 x: 0, 91948 y: 0, 91949 bx: 0, 91950 by: 0, 91951 X: 0, 91952 Y: 0, 91953 qx: null, 91954 qy: null 91955 }; 91956 var pcoms1 = [ 91957 ]; // path commands of original path p 91958 var pcoms2 = [ 91959 ]; // path commands of original path p2 91960 var ii; 91961 var processPath = function processPath(path, d, pcom) { 91962 var nx; 91963 var ny; 91964 var tq = { 91965 T: 1, 91966 Q: 1 91967 }; 91968 if (!path) { 91969 return ['C', 91970 d.x, 91971 d.y, 91972 d.x, 91973 d.y, 91974 d.x, 91975 d.y]; 91976 } 91977 if (!(path[0] in tq)) { 91978 d.qx = d.qy = null; 91979 } 91980 switch (path[0]) { 91981 case 'M': 91982 d.X = path[1]; 91983 d.Y = path[2]; 91984 break; 91985 case 'A': 91986 path = [ 91987 'C' 91988 ].concat(a2c.apply(0, [ 91989 d.x, 91990 d.y 91991 ].concat(path.slice(1)))); 91992 break; 91993 case 'S': 91994 if (pcom === 'C' || pcom === 'S') { 91995 nx = d.x * 2 - d.bx; 91996 ny = d.y * 2 - d.by; 91997 } else { 91998 nx = d.x; 91999 ny = d.y; 92000 } 92001 path = [ 92002 'C', 92003 nx, 92004 ny 92005 ].concat(path.slice(1)); 92006 break; 92007 case 'T': 92008 if (pcom === 'Q' || pcom === 'T') { 92009 d.qx = d.x * 2 - d.qx; 92010 d.qy = d.y * 2 - d.qy; 92011 } else { 92012 d.qx = d.x; 92013 d.qy = d.y; 92014 } 92015 path = [ 92016 'C' 92017 ].concat(q2c(d.x, d.y, d.qx, d.qy, path[1], path[2])); 92018 break; 92019 case 'Q': 92020 d.qx = path[1]; 92021 d.qy = path[2]; 92022 path = [ 92023 'C' 92024 ].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4])); 92025 break; 92026 case 'L': 92027 path = [ 92028 'C' 92029 ].concat(l2c(d.x, d.y, path[1], path[2])); 92030 break; 92031 case 'H': 92032 path = [ 92033 'C' 92034 ].concat(l2c(d.x, d.y, path[1], d.y)); 92035 break; 92036 case 'V': 92037 path = [ 92038 'C' 92039 ].concat(l2c(d.x, d.y, d.x, path[1])); 92040 break; 92041 case 'Z': 92042 path = [ 92043 'C' 92044 ].concat(l2c(d.x, d.y, d.X, d.Y)); 92045 break; 92046 } 92047 return path; 92048 }, 92049 fixArc = function fixArc(pp, i) { 92050 if (pp[i].length > 7) { 92051 pp[i].shift(); 92052 var pi = pp[i]; 92053 while (pi.length) { 92054 pcoms1[i] =
92054'A'; 92055 if (p2) { 92056 pcoms2[i] = 'A'; 92057 } 92058 pp.splice(i++, 0, [ 92059 'C' 92060 ].concat(pi.splice(0, 6))); 92061 } 92062 pp.splice(i, 1); 92063 ii = Math.max(p.length, p2 && p2.length || 0); 92064 } 92065 }, 92066 fixM = function fixM(path1, path2, a1, a2, i) { 92067 if (path1 && path2 && path1[i][0] === 'M' && path2[i][0] !== 'M') { 92068 path2.splice(i, 0, [ 92069 'M', 92070 a2.x, 92071 a2.y 92072 ]); 92073 a1.bx = 0; 92074 a1.by = 0; 92075 a1.x = path1[i][1]; 92076 a1.y = path1[i][2]; 92077 ii = Math.max(p.length, p2 && p2.length || 0); 92078 } 92079 }; 92080 var pfirst = ''; // temporary holder for original path command 92081 var pcom = ''; // holder for previous path command of original path 92082 ii = Math.max(p.length, p2 && p2.length || 0); 92083 for (var i = 0; i < ii; i++) { 92084 if (p[i]) { 92085 pfirst = p[i][0]; 92086 } // save current path command 92087 92088 if (pfirst !== 'C') { 92089 pcoms1[i] = pfirst; // Save current path command 92090 if (i) { 92091 pcom = pcoms1[i - 1]; 92092 } // Get previous path command pcom 92093 92094 } 92095 p[i] = processPath(p[i], attrs, pcom); 92096 if (pcoms1[i] !== 'A' && pfirst === 'C') { 92097 pcoms1[i] = 'C'; 92098 } 92099 fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1 92100 if (p2) { 92101 // the same procedures is done to p2 92102 if (p2[i]) { 92103 pfirst = p2[i][0]; 92104 } 92105 if (pfirst !== 'C') { 92106 pcoms2[i] = pfirst; 92107 if (i) { 92108 pcom = pcoms2[i - 1]; 92109 } 92110 } 92111 p2[i] = processPath(p2[i], attrs2, pcom); 92112 if (pcoms2[i] !== 'A' && pfirst === 'C') { 92113 pcoms2[i] = 'C'; 92114 } 92115 fixArc(p2, i); 92116 } 92117 fixM(p, p2, attrs, attrs2, i); 92118 fixM(p2, p, attrs2, attrs, i); 92119 var seg = p[i], 92120 seg2 = p2 && p2[i], 92121 seglen = seg.length, 92122 seg2len = p2 && seg2.length; 92123 attrs.x = seg[seglen - 2]; 92124 attrs.y = seg[seglen - 1]; 92125 attrs.bx = parseFloat(seg[seglen - 4]) || attrs.x; 92126 attrs.by = parseFloat(seg[seglen - 3]) || attrs.y; 92127 attrs2.bx = p2 && (parseFloat(seg2[seg2len - 4]) || attrs2.x); 92128 attrs2.by = p2 && (parseFloat(seg2[seg2len - 3]) || attrs2.y); 92129 attrs2.x = p2 && seg2[seg2len - 2]; 92130 attrs2.y = p2 && seg2[seg2len - 1]; 92131 } 92132 return p2 ? [ 92133 p, 92134 p2 92135 ] : p; 92136 } 92137 function a2c(x1, y1, rx, ry, angle, lac, sweep_flag, x2, y2, recursive) { 92138 // for more information of where this Math came from visit: 92139 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes 92140 var PI = Math.PI; 92141 var _120 = PI * 120 / 180; 92142 var f1; 92143 var f2; 92144 var cx; 92145 var cy; 92146 var rad = PI / 180 * ( + angle || 0); 92147 var res = [ 92148 ]; 92149 var xy; 92150 var rotate = function rotate(x, y, rad) { 92151 var X = x * Math.cos(rad) - y * Math.sin(rad), 92152 Y = x * Math.sin(rad) + y * Math.cos(rad); 92153 return { 92154 x: X, 92155 y: Y 92156 }; 92157 }; 92158 if (!recursive) { 92159 xy = rotate(x1, y1, - rad); 92160 x1 = xy.x; 92161 y1 = xy.y; 92162 xy = rotate(x2, y2, - rad); 92163 x2 = xy.x; 92164 y2 = xy.y; 92165 var x = (x1 - x2) / 2; 92166 var y = (y1 - y2) / 2; 92167 var h = x * x / (rx * rx) + y * y / (ry * ry); 92168 if (h > 1) { 92169 h = Math.sqrt(h); 92170 rx = h * rx; 92171 ry = h * ry; 92172 } 92173 var rx2 = rx * rx, 92174 ry2 = ry * ry; 92175 var k = (lac === sweep_flag ? - 1 : 1) * Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))); 92176 cx = k * rx * y / ry + (x1 + x2) / 2; 92177 cy = k * - ry * x / rx + (y1 + y2) / 2; 92178 f1 = Math.asin(((y1 - cy) / ry).toFixed(9)); 92179 f2 = Math.asin(((y2 - cy) / ry).toFixed(9)); 92180 f1 = x1 < cx ? PI - f1 : f1; 92181 f2 = x2 < cx ? PI - f2 : f2; 92182 if (f1 < 0) { 92183 f1 = PI * 2 + f1; 92184 } 92185 if (f2 < 0) { 92186 f2 = PI * 2 + f2; 92187 } 92188 if (sweep_flag && f1 > f2) { 92189 f1 = f1 - PI * 2; 92190 } 92191 if (!sweep_flag && f2 > f1) { 92192 f2 = f2 - PI * 2; 92193 } 92194 } else { 92195 f1 = recursive[0]; 92196 f2 = recursive[1]; 92197 cx = recursive[2]; 92198 cy = recursive[3]; 92199 } 92200 var df = f2 - f1; 92201 if (Math.abs(df) > _120) { 92202 var f2old = f2, 92203 x2old = x2, 92204 y2old = y2; 92205 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : - 1); 92206 x2 = cx + rx * Math.cos(f2); 92207 y2 = cy + ry * Math.sin(f2); 92208 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [ 92209 f2, 92210 f2old, 92211 cx, 92212 cy 92213 ]); 92214 } 92215 df = f2 - f1; 92216 var c1 = Math.cos(f1), 92217 s1 = Math.sin(f1),
92218 c2 = Math.cos(f2), 92219 s2 = Math.sin(f2), 92220 t = Math.tan(df / 4), 92221 hx = 4 / 3 * rx * t, 92222 hy = 4 / 3 * ry * t, 92223 m1 = [ 92224 x1, 92225 y1 92226 ], 92227 m2 = [ 92228 x1 + hx * s1, 92229 y1 - hy * c1 92230 ], 92231 m3 = [ 92232 x2 + hx * s2, 92233 y2 - hy * c2 92234 ], 92235 m4 = [ 92236 x2, 92237 y2 92238 ]; 92239 m2[0] = 2 * m1[0] - m2[0]; 92240 m2[1] = 2 * m1[1] - m2[1]; 92241 if (recursive) { 92242 return [m2, 92243 m3, 92244 m4].concat(res); 92245 } else { 92246 res = [ 92247 m2, 92248 m3, 92249 m4 92250 ].concat(res).join().split(','); 92251 var newres = [ 92252 ]; 92253 for (var i = 0, ii = res.length; i < ii; i++) { 92254 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; 92255 } 92256 return newres; 92257 } 92258 } // http://schepers.cc/getting-to-the-point 92259 92260 function catmullRom2bezier(crp, z) { 92261 var d = [ 92262 ]; 92263 for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) { 92264 var p = [ 92265 { 92266 x: + crp[i - 2], 92267 y: + crp[i - 1] 92268 }, 92269 { 92270 x: + crp[i], 92271 y: + crp[i + 1] 92272 }, 92273 { 92274 x: + crp[i + 2], 92275 y: + crp[i + 3] 92276 }, 92277 { 92278 x: + crp[i + 4], 92279 y: + crp[i + 5] 92280 } 92281 ]; 92282 if (z) { 92283 if (!i) { 92284 p[0] = { 92285 x: + crp[iLen - 2], 92286 y: + crp[iLen - 1] 92287 }; 92288 } else if (iLen - 4 === i) { 92289 p[3] = { 92290 x: + crp[0], 92291 y: + crp[1] 92292 }; 92293 } else if (iLen - 2 === i) { 92294 p[2] = { 92295 x: + crp[0], 92296 y: + crp[1] 92297 }; 92298 p[3] = { 92299 x: + crp[2], 92300 y: + crp[3] 92301 }; 92302 } 92303 } else { 92304 if (iLen - 4 === i) { 92305 p[3] = p[2]; 92306 } else if (!i) { 92307 p[0] = { 92308 x: + crp[i], 92309 y: + crp[i + 1] 92310 }; 92311 } 92312 } 92313 d.push(['C', 92314 ( - p[0].x + 6 * p[1].x + p[2].x) / 6, 92315 ( - p[0].y + 6 * p[1].y + p[2].y) / 6, 92316 (p[1].x + 6 * p[2].x - p[3].x) / 6, 92317 (p[1].y + 6 * p[2].y - p[3].y) / 6, 92318 p[2].x, 92319 p[2].y]); 92320 } 92321 return d; 92322 } 92323 function l2c(x1, y1, x2, y2) { 92324 return [x1, 92325 y1, 92326 x2, 92327 y2, 92328 x2, 92329 y2]; 92330 } 92331 function q2c(x1, y1, ax, ay, x2, y2) { 92332 var _13 = 1 / 3, 92333 _23 = 2 / 3; 92334 return [_13 * x1 + _23 * ax, 92335 _13 * y1 + _23 * ay, 92336 _13 * x2 + _23 * ax, 92337 _13 * y2 + _23 * ay, 92338 x2, 92339 y2]; 92340 } 92341 function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) { 92342 if (z == null) { 92343 z = 1; 92344 } 92345 z = z > 1 ? 1 : z < 0 ? 0 : z; 92346 var z2 = z / 2; 92347 var n = 12; 92348 var Tvalues = [ 92349 - 0.1252, 92350 0.1252, 92351 - 0.3678, 92352 0.3678, 92353 - 0.5873, 92354 0.5873, 92355 - 0.7699, 92356 0.7699, 92357 - 0.9041, 92358 0.9041, 92359 - 0.9816, 92360 0.9816 92361 ]; 92362 var sum = 0; 92363 var Cvalues = [ 92364 0.2491, 92365 0.2491, 92366 0.2335, 92367 0.2335, 92368 0.2032, 92369 0.2032, 92370 0.1601, 92371 0.1601, 92372 0.1069, 92373 0.1069, 92374 0.0472, 92375 0.0472 92376 ]; 92377 for (var i = 0; i < n; i++) { 92378 var ct = z2 * Tvalues[i] + z2, 92379 xbase = base3(ct, x1, x2, x3, x4), 92380 ybase = base3(ct, y1, y2, y3, y4), 92381 comb = xbase * xbase + ybase * ybase; 92382 sum += Cvalues[i] * Math.sqrt(comb); 92383 } 92384 return z2 * sum; 92385 } 92386 function getTatLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) { 92387 if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) { 92388 return; 92389 } 92390 var t = 1; 92391 var step = t / 2; 92392 var t2 = t - step; 92393 var l; 92394 var e = 0.01; 92395 l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2); 92396 while (Math.abs(l - ll) > e) { 92397 step /= 2; 92398 t2 += (l < ll ? 1 : - 1) * step; 92399 l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2); 92400 } 92401 return t2; 92402 } 92403 function base3(t, p1, p2, p3, p4) { 92404 var t1 = - 3 * p1 + 9 * p2 - 9 * p3 + 3 * p4, 92405 t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3; 92406 return t * t2 - 3 * p1 + 3 * p2; 92407 } 92408 function cacheKey() { 92409 var hash = ''; 92410 for (var i = arguments.length - 1; i >= 0; --i) { 92411 hash += 'ï¼'.concat(i < 0 || arguments.length <= i ? undefined : arguments[i]); 92412 } 92413 return hash; 92414 } 92415 var _default = _main.default; 92416 exports.default = _default; 92417 }, 92418 { 92419 '../core/constants': 278, 92420 '../core/main': 290,
92421 'core-js/modules/es.array.concat': 167, 92422 'core-js/modules/es.array.fill': 170, 92423 'core-js/modules/es.array.iterator': 176, 92424 'core-js/modules/es.array.join': 177, 92425 'core-js/modules/es.array.slice': 180, 92426 'core-js/modules/es.array.splice': 182, 92427 'core-js/modules/es.function.name': 183, 92428 'core-js/modules/es.number.to-fixed': 189, 92429 'core-js/modules/es.object.get-own-property-descriptor': 191, 92430 'core-js/modules/es.object.to-string': 195, 92431 'core-js/modules/es.regexp.exec': 199, 92432 'core-js/modules/es.string.iterator': 204, 92433 'core-js/modules/es.string.split': 209, 92434 'core-js/modules/es.symbol': 214, 92435 'core-js/modules/es.symbol.description': 212, 92436 'core-js/modules/es.symbol.iterator': 213, 92437 'core-js/modules/es.weak-map': 246, 92438 'core-js/modules/web.dom-collections.iterator': 248 92439 } 92440 ], 92441 329: [ 92442 function (_dereq_, module, exports) { 92443 'use strict'; 92444 _dereq_('core-js/modules/es.array.concat'); 92445 _dereq_('core-js/modules/es.array.slice'); 92446 _dereq_('core-js/modules/es.array.splice'); 92447 _dereq_('core-js/modules/es.array-buffer.constructor'); 92448 _dereq_('core-js/modules/es.object.to-string'); 92449 _dereq_('core-js/modules/es.array.concat'); 92450 _dereq_('core-js/modules/es.array.slice'); 92451 _dereq_('core-js/modules/es.array.splice'); 92452 _dereq_('core-js/modules/es.array-buffer.constructor'); 92453 _dereq_('core-js/modules/es.object.to-string'); 92454 Object.defineProperty(exports, '__esModule', { 92455 value: true 92456 }); 92457 exports.default = void 0; 92458 var _main = _interopRequireDefault(_dereq_('../core/main')); 92459 function _interopRequireDefault(obj) { 92460 return obj && obj.__esModule ? obj : { 92461 default: 92462 obj 92463 }; 92464 } /** 92465 * @module Data 92466 * @submodule Array Functions 92467 * @for p5 92468 * @requires core 92469 */ 92470 /** 92471 * Adds a value to the end of an array. Extends the length of 92472 * the array by one. Maps to Array.push(). 92473 * 92474 * @method append 92475 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push">array.push(value)</a> instead. 92476 * @param {Array} array Array to append 92477 * @param {any} value to be added to the Array 92478 * @return {Array} the array that was appended to 92479 * @example 92480 * <div class='norender'><code> 92481 * function setup() { 92482 * let myArray = ['Mango', 'Apple', 'Papaya']; 92483 * print(myArray); // ['Mango', 'Apple', 'Papaya'] 92484 * 92485 * append(myArray, 'Peach'); 92486 * print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach'] 92487 * } 92488 * </code></div> 92489 */ 92490 92491 _main.default.prototype.append = function (array, value) { 92492 array.push(value); 92493 return array; 92494 }; 92495 /** 92496 * Copies an array (or part of an array) to another array. The src array is 92497 * copied to the dst array, beginning at the position specified by 92498 * srcPosition and into the position specified by dstPosition. The number of 92499 * elements to copy is determined by length. Note that copying values 92500 * overwrites existing values in the destination array. To append values 92501 * instead of overwriting them, use <a href="#/p5/concat">concat()</a>. 92502 * 92503 * The simplified version with only two arguments, arrayCopy(src, dst), 92504 * copies an entire array to another of the same size. It is equivalent to 92505 * arrayCopy(src, 0, dst, 0, src.length). 92506 * 92507 * Using this function is far more efficient for copying array data than 92508 * iterating through a for() loop and copying each element individually. 92509 * 92510 * @method arrayCopy 92511 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin">arr1.copyWithin(arr2)</a> instead. 92512 * @param {Array} src the source Array 92513 * @param {Integer} srcPosition starting position in the source Array 92514 * @param {Array} dst the destination Array 92515 * @param {Integer} dstPosition starting position in the destination Array 92516 * @param {Integer} length number of Array elements to be copied 92517 * 92518 * @example 92519 * <div class='norender'><code> 92520 * let src = ['A', 'B', 'C']; 92521 * let dst = [1, 2, 3]; 92522 * let srcPosition = 1; 92523 * let dstPosition = 0; 92524 * let length = 2; 92525 * 92526 * print(src); // ['A', 'B', 'C'] 92527 * print(dst); // [ 1 , 2 , 3 ] 92528 * 92529 * arrayCopy(src, srcPosition, dst, dstPosition, length); 92530 * print(dst); // ['B', 'C', 3] 92531 * </code></div> 92532 */ 92533 /** 92534 * @method arrayCopy 92535 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin">arr1.copyWithin(arr2)</a> instead. 92536 * @param {Array} src 92537 * @param {Array} dst 92538 * @param {Integer} [length] 92539 */ 92540 _main.default.prototype.arrayCopy = function (src, srcPosition, dst, dstPosition, length) { 92541 // the index to begin splicing from dst array 92542 var start; 92543 var end; 92544 if (typeof length !== 'undefined') { 92545 end = Math.min(length, src.length); 92546 start = dstPosition;
92547 src = src.slice(srcPosition, end + srcPosition); 92548 } else { 92549 if (typeof dst !== 'undefined') { 92550 // src, dst, length 92551 // rename so we don't get confused 92552 end = dst; 92553 end = Math.min(end, src.length); 92554 } else { 92555 // src, dst 92556 end = src.length; 92557 } 92558 start = 0; // rename so we don't get confused 92559 dst = srcPosition; 92560 src = src.slice(0, end); 92561 } // Since we are not returning the array and JavaScript is pass by reference 92562 // we must modify the actual values of the array 92563 // instead of reassigning arrays 92564 92565 Array.prototype.splice.apply(dst, [ 92566 start, 92567 end 92568 ].concat(src)); 92569 }; 92570 /** 92571 * Concatenates two arrays, maps to Array.concat(). Does not modify the 92572 * input arrays. 92573 * 92574 * @method concat 92575 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat">arr1.concat(arr2)</a> instead. 92576 * @param {Array} a first Array to concatenate 92577 * @param {Array} b second Array to concatenate 92578 * @return {Array} concatenated array 92579 * 92580 * @example 92581 * <div class = 'norender'><code> 92582 * function setup() { 92583 * let arr1 = ['A', 'B', 'C']; 92584 * let arr2 = [1, 2, 3]; 92585 * 92586 * print(arr1); // ['A','B','C'] 92587 * print(arr2); // [1,2,3] 92588 * 92589 * let arr3 = concat(arr1, arr2); 92590 * 92591 * print(arr1); // ['A','B','C'] 92592 * print(arr2); // [1, 2, 3] 92593 * print(arr3); // ['A','B','C', 1, 2, 3] 92594 * } 92595 * </code></div> 92596 */ 92597 _main.default.prototype.concat = function (list0, list1) { 92598 return list0.concat(list1); 92599 }; 92600 /** 92601 * Reverses the order of an array, maps to Array.reverse() 92602 * 92603 * @method reverse 92604 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse">array.reverse()</a> instead. 92605 * @param {Array} list Array to reverse 92606 * @return {Array} the reversed list 92607 * @example 92608 * <div class='norender'><code> 92609 * function setup() { 92610 * let myArray = ['A', 'B', 'C']; 92611 * print(myArray); // ['A','B','C'] 92612 * 92613 * reverse(myArray); 92614 * print(myArray); // ['C','B','A'] 92615 * } 92616 * </code></div> 92617 */ 92618 _main.default.prototype.reverse = function (list) { 92619 return list.reverse(); 92620 }; 92621 /** 92622 * Decreases an array by one element and returns the shortened array, 92623 * maps to Array.pop(). 92624 * 92625 * @method shorten 92626 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop">array.pop()</a> instead. 92627 * @param {Array} list Array to shorten 92628 * @return {Array} shortened Array 92629 * @example 92630 * <div class = 'norender'><code> 92631 * function setup() { 92632 * let myArray = ['A', 'B', 'C']; 92633 * print(myArray); // ['A', 'B', 'C'] 92634 * let newArray = shorten(myArray); 92635 * print(myArray); // ['A','B','C'] 92636 * print(newArray); // ['A','B'] 92637 * } 92638 * </code></div> 92639 */ 92640 _main.default.prototype.shorten = function (list) { 92641 list.pop(); 92642 return list; 92643 }; 92644 /** 92645 * Randomizes the order of the elements of an array. Implements 92646 * <a href='http://Bost.Ocks.org/mike/shuffle/' target=_blank> 92647 * Fisher-Yates Shuffle Algorithm</a>. 92648 * 92649 * @method shuffle 92650 * @param {Array} array Array to shuffle 92651 * @param {Boolean} [bool] modify passed array 92652 * @return {Array} shuffled Array 92653 * @example 92654 * <div><code> 92655 * function setup() { 92656 * let regularArr = ['ABC', 'def', createVector(), TAU, Math.E]; 92657 * print(regularArr); 92658 * shuffle(regularArr, true); // force modifications to passed array 92659 * print(regularArr); 92660 * 92661 * // By default shuffle() returns a shuffled cloned array: 92662 * let newArr = shuffle(regularArr); 92663 * print(regularArr); 92664 * print(newArr); 92665 * } 92666 * </code></div> 92667 */ 92668 _main.default.prototype.shuffle = function (arr, bool) { 92669 var isView = ArrayBuffer && ArrayBuffer.isView && ArrayBuffer.isView(arr); 92670 arr = bool || isView ? arr : arr.slice(); 92671 var rnd, 92672 tmp, 92673 idx = arr.length; 92674 while (idx > 1) { 92675 rnd = this.random(0, 1) * idx | 0; 92676 tmp = arr[--idx]; 92677 arr[idx] = arr[rnd]; 92678 arr[rnd] = tmp; 92679 } 92680 return arr; 92681 }; 92682 /** 92683 * Sorts an array of numbers from smallest to largest, or puts an array of 92684 * words in alphabetical order. The original array is not modified; a 92685 * re-ordered array is returned. The count parameter states the number of 92686 * elements to sort. For example, if there are 12 elements in an array and 92687 * count is set to 5, only the first 5 elements in the array will be sorted. 92688 * 92689 * @method sort 92690 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">array.sort()</a> instead. 92691 * @param {Array} list Array to sort 92692 * @param {Integer} [count] number of elements to sort, starting from 0 92693 * @return {Array} the sorted list 92694 * 92695 * @example 92696 * <div class = 'norender'><code> 92697 * function setup() { 92698 * let words = ['banana', 'apple', 'pear', 'lime']; 92699 * print(words); // ['banana', 'apple', 'pear', 'lime'] 92700 * let count = 4; // length of array 92701 * 92702 * words = sort(words, count); 92703 * print(words); // ['apple', 'banana', 'lime', 'pear'] 92704 * } 92705 * </code></div> 92706 * <div class = 'norender'><code> 92707 * function setup() { 92708 * let numbers = [2, 6, 1, 5, 14, 9, 8, 12]; 92709 * print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12] 92710 * let count = 5; // Less than the length of the array 92711 * 92712 * numbers = sort(numbers, count); 92713 * print(numbers); // [1,2,5,6,14,9,8,12] 92714 * } 92715 * </code></div> 92716 */ 92717 _main.default.prototype.sort = function (list, count) { 92718 var arr = count ? list.slice(0, Math.min(count, list.length)) : list; 92719 var rest = count ? list.slice(Math.min(count, list.length)) : [ 92720 ]; 92721 if (typeof arr[0] === 'string') { 92722 arr = arr.sort(); 92723 } else { 92724 arr = arr.sort(function (a, b) { 92725 return a - b; 92726 }); 92727 } 92728 return arr.concat(rest); 92729 }; 92730 /** 92731 * Inserts a value or an array of values into an existing array. The first 92732 * parameter specifies the initial array to be modified, and the second 92733 * parameter defines the data to be inserted. The third parameter is an index 92734 * value which specifies the array position from which to insert data. 92735 * (Remember that array index numbering starts at zero, so the first position 92736 * is 0, the second position is 1, and so on.) 92737 * 92738 * @method splice 92739 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice">array.splice()</a> instead. 92740 * @param {Array} list Array to splice into 92741 * @param {any} value value to be spliced in 92742 * @param {Integer} position in the array from which to insert data 92743 * @return {Array} the list 92744 * 92745 * @example 92746 * <div class = 'norender'><code> 92747 * function setup() { 92748 * let myArray = [0, 1, 2, 3, 4]; 92749 * let insArray = ['A', 'B', 'C']; 92750 * print(myArray); // [0, 1, 2, 3, 4] 92751 * print(insArray); // ['A','B','C'] 92752 * 92753 * splice(myArray, insArray, 3); 92754 * print(myArray); // [0,1,2,'A','B','C',3,4] 92755 * } 92756 * </code></div> 92757 */ 92758 _main.default.prototype.splice = function (list, value, index) { 92759 // note that splice returns spliced elements and not an array 92760 Array.prototype.splice.apply(list, [ 92761 index, 92762 0 92763 ].concat(value)); 92764 return list; 92765 }; 92766 /** 92767 * Extracts an array of elements from an existing array. The list parameter 92768 * defines the array from which the elements will be copied, and the start 92769 * and count parameters specify which elements to extract. If no count is 92770 * given, elements will be extracted from the start to the end of the array. 92771 * When specifying the start, remember that the first array element is 0. 92772 * This function does not change the source array. 92773 * 92774 * @method subset 92775 * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice">array.slice()</a> instead. 92776 * @param {Array} list Array to extract from 92777 * @param {Integer} start position to begin 92778 * @param {Integer} [count] number of values to extract 92779 * @return {Array} Array of extracted elements 92780 * 92781 * @example 92782 * <div class = 'norender'><code> 92783 * function setup() { 92784 * let myArray = [1, 2, 3, 4, 5]; 92785 * print(myArray); // [1, 2, 3, 4, 5] 92786 * 92787 * let sub1 = subset(myArray, 0, 3); 92788 * let sub2 = subset(myArray, 2, 2); 92789 * print(sub1); // [1,2,3] 92790 * print(sub2); // [3,4] 92791 * } 92792 * </code></div> 92793 */ 92794 _main.default.prototype.subset = function (list, start, count) { 92795 if (typeof count !== 'undefined') { 92796 return list.slice(start, start + count); 92797 } else { 92798 return list.slice(start, list.length); 92799 } 92800 }; 92801 var _default = _main.default; 92802 exports.default = _default; 92803 }, 92804 { 92805 '../core/main': 290, 92806 'core-js/modules/es.array-buffer.constructor': 166,
92807 'core-js/modules/es.array.concat': 167, 92808 'core-js/modules/es.array.slice': 180, 92809 'core-js/modules/es.array.splice': 182, 92810 'core-js/modules/es.object.to-string': 195 92811 } 92812 ], 92813 330: [ 92814 function (_dereq_, module, exports) { 92815 'use strict'; 92816 _dereq_('core-js/modules/es.array.map'); 92817 _dereq_('core-js/modules/es.number.constructor'); 92818 _dereq_('core-js/modules/es.object.to-string'); 92819 _dereq_('core-js/modules/es.regexp.to-string'); 92820 _dereq_('core-js/modules/es.string.repeat'); 92821 _dereq_('core-js/modules/es.array.map'); 92822 _dereq_('core-js/modules/es.number.constructor'); 92823 _dereq_('core-js/modules/es.object.to-string'); 92824 _dereq_('core-js/modules/es.regexp.to-string'); 92825 _dereq_('core-js/modules/es.string.repeat'); 92826 Object.defineProperty(exports, '__esModule', { 92827 value: true 92828 }); 92829 exports.default = void 0; 92830 var _main = _interopRequireDefault(_dereq_('../core/main')); 92831 function _interopRequireDefault(obj) { 92832 return obj && obj.__esModule ? obj : { 92833 default: 92834 obj 92835 }; 92836 } /** 92837 * @module Data 92838 * @submodule Conversion 92839 * @for p5 92840 * @requires core 92841 */ 92842 /** 92843 * Converts a string to its floating point representation. The contents of a 92844 * string must resemble a number, or NaN (not a number) will be returned. 92845 * For example, float("1234.56") evaluates to 1234.56, but float("giraffe") 92846 * will return NaN. 92847 * 92848 * When an array of values is passed in, then an array of floats of the same 92849 * length is returned. 92850 * 92851 * @method float 92852 * @param {String} str float string to parse 92853 * @return {Number} floating point representation of string 92854 * @example 92855 * <div><code> 92856 * let str = '20'; 92857 * let diameter = float(str); 92858 * ellipse(width / 2, height / 2, diameter, diameter); 92859 * </code></div> 92860 * <div class='norender'><code> 92861 * print(float('10.31')); // 10.31 92862 * print(float('Infinity')); // Infinity 92863 * print(float('-Infinity')); // -Infinity 92864 * </code></div> 92865 * 92866 * @alt 92867 * 20 by 20 white ellipse in the center of the canvas 92868 */ 92869 92870 _main.default.prototype.float = function (str) { 92871 if (str instanceof Array) { 92872 return str.map(parseFloat); 92873 } 92874 return parseFloat(str); 92875 }; 92876 /** 92877 * Converts a boolean, string, or float to its integer representation. 92878 * When an array of values is passed in, then an int array of the same length 92879 * is returned. 92880 * 92881 * @method int 92882 * @param {String|Boolean|Number} n value to parse 92883 * @param {Integer} [radix] the radix to convert to (default: 10) 92884 * @return {Number} integer representation of value 92885 * 92886 * @example 92887 * <div class='norender'><code> 92888 * print(int('10')); // 10 92889 * print(int(10.31)); // 10 92890 * print(int(-10)); // -10 92891 * print(int(true)); // 1 92892 * print(int(false)); // 0 92893 * print(int([false, true, '10.3', 9.8])); // [0, 1, 10, 9] 92894 * print(int(Infinity)); // Infinity 92895 * print(int('-Infinity')); // -Infinity 92896 * </code></div> 92897 */ 92898 /** 92899 * @method int 92900 * @param {Array} ns values to parse 92901 * @param {Integer} [radix] 92902 * @return {Number[]} integer representation of values 92903 */ 92904 _main.default.prototype.int = function (n) { 92905 var radix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; 92906 if (n === Infinity || n === 'Infinity') { 92907 return Infinity; 92908 } else if (n === - Infinity || n === '-Infinity') { 92909 return - Infinity; 92910 } else if (typeof n === 'string') { 92911 return parseInt(n, radix); 92912 } else if (typeof n === 'number') { 92913 return n | 0; 92914 } else if (typeof n === 'boolean') { 92915 return n ? 1 : 0; 92916 } else if (n instanceof Array) { 92917 return n.map(function (n) { 92918 return _main.default.prototype.int(n, radix); 92919 }); 92920 } 92921 }; 92922 /** 92923 * Converts a boolean, string or number to its string representation.
92924 * When an array of values is passed in, then an array of strings of the same 92925 * length is returned. 92926 * 92927 * @method str 92928 * @param {String|Boolean|Number|Array} n value to parse 92929 * @return {String} string representation of value 92930 * @example 92931 * <div class='norender'><code> 92932 * print(str('10')); // "10" 92933 * print(str(10.31)); // "10.31" 92934 * print(str(-10)); // "-10" 92935 * print(str(true)); // "true" 92936 * print(str(false)); // "false" 92937 * print(str([true, '10.3', 9.8])); // [ "true", "10.3", "9.8" ] 92938 * </code></div> 92939 */ 92940 _main.default.prototype.str = function (n) { 92941 if (n instanceof Array) { 92942 return n.map(_main.default.prototype.str); 92943 } else { 92944 return String(n); 92945 } 92946 }; 92947 /** 92948 * Converts a number or string to its boolean representation. 92949 * For a number, any non-zero value (positive or negative) evaluates to true, 92950 * while zero evaluates to false. For a string, the value "true" evaluates to 92951 * true, while any other value evaluates to false. When an array of number or 92952 * string values is passed in, then a array of booleans of the same length is 92953 * returned. 92954 * 92955 * @method boolean 92956 * @param {String|Boolean|Number|Array} n value to parse 92957 * @return {Boolean} boolean representation of value 92958 * @example 92959 * <div class='norender'><code> 92960 * print(boolean(0)); // false 92961 * print(boolean(1)); // true 92962 * print(boolean('true')); // true 92963 * print(boolean('abcd')); // false 92964 * print(boolean([0, 12, 'true'])); // [false, true, true] 92965 * </code></div> 92966 */ 92967 _main.default.prototype.boolean = function (n) { 92968 if (typeof n === 'number') { 92969 return n !== 0; 92970 } else if (typeof n === 'string') { 92971 return n.toLowerCase() === 'true'; 92972 } else if (typeof n === 'boolean') { 92973 return n; 92974 } else if (n instanceof Array) { 92975 return n.map(_main.default.prototype.boolean); 92976 } 92977 }; 92978 /** 92979 * Converts a number, string representation of a number, or boolean to its byte 92980 * representation. A byte can be only a whole number between -128 and 127, so 92981 * when a value outside of this range is converted, it wraps around to the 92982 * corresponding byte representation. When an array of number, string or boolean 92983 * values is passed in, then an array of bytes the same length is returned. 92984 * 92985 * @method byte 92986 * @param {String|Boolean|Number} n value to parse 92987 * @return {Number} byte representation of value 92988 * 92989 * @example 92990 * <div class='norender'><code> 92991 * print(byte(127)); // 127 92992 * print(byte(128)); // -128 92993 * print(byte(23.4)); // 23 92994 * print(byte('23.4')); // 23 92995 * print(byte('hello')); // NaN 92996 * print(byte(true)); // 1 92997 * print(byte([0, 255, '100'])); // [0, -1, 100] 92998 * </code></div> 92999 */ 93000 /** 93001 * @method byte 93002 * @param {Array} ns values to parse 93003 * @return {Number[]} array of byte representation of values 93004 */ 93005 _main.default.prototype.byte = function (n) { 93006 var nn = _main.default.prototype.int(n, 10); 93007 if (typeof nn === 'number') { 93008 return (nn + 128) % 256 - 128; 93009 } else if (nn instanceof Array) { 93010 return nn.map(_main.default.prototype.byte); 93011 } 93012 }; 93013 /** 93014 * Converts a number or string to its corresponding single-character 93015 * string representation. If a string parameter is provided, it is first 93016 * parsed as an integer and then translated into a single-character string. 93017 * When an array of number or string values is passed in, then an array of 93018 * single-character strings of the same length is returned. 93019 * 93020 * @method char 93021 * @param {String|Number} n value to parse 93022 * @return {String} string representation of value 93023 * 93024 * @example 93025 * <div class='norender'><code> 93026 * print(char(65)); // "A" 93027 * print(char('65')); // "A" 93028 * print(char([65, 66, 67])); // [ "A", "B", "C" ] 93029 * print(join(char([65, 66, 67]), '')); // "ABC" 93030 * </code></div> 93031 */ 93032 /** 93033 * @method char 93034 * @param {Array} ns values to parse 93035 * @return {String[]}
93035 array of string representation of values 93036 */ 93037 _main.default.prototype.char = function (n) { 93038 if (typeof n === 'number' && !isNaN(n)) { 93039 return String.fromCharCode(n); 93040 } else if (n instanceof Array) { 93041 return n.map(_main.default.prototype.char); 93042 } else if (typeof n === 'string') { 93043 return _main.default.prototype.char(parseInt(n, 10)); 93044 } 93045 }; 93046 /** 93047 * Converts a single-character string to its corresponding integer 93048 * representation. When an array of single-character string values is passed 93049 * in, then an array of integers of the same length is returned. 93050 * 93051 * @method unchar 93052 * @param {String} n value to parse 93053 * @return {Number} integer representation of value 93054 * 93055 * @example 93056 * <div class='norender'><code> 93057 * print(unchar('A')); // 65 93058 * print(unchar(['A', 'B', 'C'])); // [ 65, 66, 67 ] 93059 * print(unchar(split('ABC', ''))); // [ 65, 66, 67 ] 93060 * </code></div> 93061 */ 93062 /** 93063 * @method unchar 93064 * @param {Array} ns values to parse 93065 * @return {Number[]} integer representation of values 93066 */ 93067 _main.default.prototype.unchar = function (n) { 93068 if (typeof n === 'string' && n.length === 1) { 93069 return n.charCodeAt(0); 93070 } else if (n instanceof Array) { 93071 return n.map(_main.default.prototype.unchar); 93072 } 93073 }; 93074 /** 93075 * Converts a number to a string in its equivalent hexadecimal notation. If a 93076 * second parameter is passed, it is used to set the number of characters to 93077 * generate in the hexadecimal notation. When an array is passed in, an 93078 * array of strings in hexadecimal notation of the same length is returned. 93079 * 93080 * @method hex 93081 * @param {Number} n value to parse 93082 * @param {Number} [digits] 93083 * @return {String} hexadecimal string representation of value 93084 * 93085 * @example 93086 * <div class='norender'><code> 93087 * print(hex(255)); // "000000FF" 93088 * print(hex(255, 6)); // "0000FF" 93089 * print(hex([0, 127, 255], 6)); // [ "000000", "00007F", "0000FF" ] 93090 * print(Infinity); // "FFFFFFFF" 93091 * print(-Infinity); // "00000000" 93092 * </code></div> 93093 */ 93094 /** 93095 * @method hex 93096 * @param {Number[]} ns array of values to parse 93097 * @param {Number} [digits] 93098 * @return {String[]} hexadecimal string representation of values 93099 */ 93100 _main.default.prototype.hex = function (n, digits) { 93101 digits = digits === undefined || digits === null ? digits = 8 : digits; 93102 if (n instanceof Array) { 93103 return n.map(function (n) { 93104 return _main.default.prototype.hex(n, digits); 93105 }); 93106 } else if (n === Infinity || n === - Infinity) { 93107 var c = n === Infinity ? 'F' : '0'; 93108 return c.repeat(digits); 93109 } else if (typeof n === 'number') { 93110 if (n < 0) { 93111 n = 4294967295 + n + 1; 93112 } 93113 var hex = Number(n).toString(16).toUpperCase(); 93114 while (hex.length < digits) { 93115 hex = '0'.concat(hex); 93116 } 93117 if (hex.length >= digits) { 93118 hex = hex.substring(hex.length - digits, hex.length); 93119 } 93120 return hex; 93121 } 93122 }; 93123 /** 93124 * Converts a string representation of a hexadecimal number to its equivalent 93125 * integer value. When an array of strings in hexadecimal notation is passed 93126 * in, an array of integers of the same length is returned. 93127 * 93128 * @method unhex 93129 * @param {String} n value to parse 93130 * @return {Number} integer representation of hexadecimal value 93131 * 93132 * @example 93133 * <div class='norender'><code> 93134 * print(unhex('A')); // 10 93135 * print(unhex('FF')); // 255 93136 * print(unhex(['FF', 'AA', '00'])); // [ 255, 170, 0 ] 93137 * </code></div> 93138 */ 93139 /** 93140 * @method unhex 93141 * @param {Array} ns values to parse 93142 * @return {Number[]} integer representations of hexadecimal value 93143 */ 93144 _main.default.prototype.unhex = function (n) { 93145 if (n instanceof Array) { 93146 return n.map(_main.default.prototype.unhex); 93147 } else { 93148 return parseInt('0x'.concat(n), 16); 93149 } 93150 }; 93151 var _default = _main.default; 93152 exports.default = _default; 93153 }, 93154 { 93155 '../core/main': 290, 93156 'core-js/modules/es.array.map': 179, 93157 'core-js/modules/es.number.constructor': 187, 93158 'core-js/modules/es.object.to-string': 195, 93159 'core-js/modules/es.regexp.to-string': 200, 93160 'core-js/modules/es.string.repeat': 206 93161 } 93162 ], 93163 331: [
93164 function (_dereq_, module, exports) { 93165 'use strict'; 93166 _dereq_('core-js/modules/es.array.filter'); 93167 _dereq_('core-js/modules/es.array.index-of'); 93168 _dereq_('core-js/modules/es.array.join'); 93169 _dereq_('core-js/modules/es.array.map'); 93170 _dereq_('core-js/modules/es.array.slice'); 93171 _dereq_('core-js/modules/es.object.to-string'); 93172 _dereq_('core-js/modules/es.regexp.constructor'); 93173 _dereq_('core-js/modules/es.regexp.exec'); 93174 _dereq_('core-js/modules/es.regexp.to-string'); 93175 _dereq_('core-js/modules/es.string.match'); 93176 _dereq_('core-js/modules/es.string.replace'); 93177 _dereq_('core-js/modules/es.string.split'); 93178 _dereq_('core-js/modules/es.string.trim'); 93179 _dereq_('core-js/modules/es.array.filter'); 93180 _dereq_('core-js/modules/es.array.index-of'); 93181 _dereq_('core-js/modules/es.array.join'); 93182 _dereq_('core-js/modules/es.array.map'); 93183 _dereq_('core-js/modules/es.array.slice'); 93184 _dereq_('core-js/modules/es.object.to-string'); 93185 _dereq_('core-js/modules/es.regexp.constructor'); 93186 _dereq_('core-js/modules/es.regexp.exec'); 93187 _dereq_('core-js/modules/es.regexp.to-string'); 93188 _dereq_('core-js/modules/es.string.match'); 93189 _dereq_('core-js/modules/es.string.replace'); 93190 _dereq_('core-js/modules/es.string.split'); 93191 _dereq_('core-js/modules/es.string.trim'); 93192 Object.defineProperty(exports, '__esModule', { 93193 value: true 93194 }); 93195 exports.default = void 0; 93196 var _main = _interopRequireDefault(_dereq_('../core/main')); 93197 _dereq_('../core/friendly_errors/validate_params'); 93198 _dereq_('../core/friendly_errors/file_errors'); 93199 _dereq_('../core/friendly_errors/fes_core'); 93200 function _interopRequireDefault(obj) { 93201 return obj && obj.__esModule ? obj : { 93202 default: 93203 obj 93204 }; 93205 } /** 93206 * @module Data 93207 * @submodule String Functions 93208 * @for p5 93209 * @requires core 93210 */ 93211 //return p5; //LM is this a mistake? 93212 /** 93213 * Combines an array of Strings into one String, each separated by the 93214 * character(s) used for the separator parameter. To join arrays of ints or 93215 * floats, it's necessary to first convert them to Strings using <a href="#/p5/nf">nf()</a> or 93216 * nfs(). 93217 * 93218 * @method join 93219 * @param {Array} list array of Strings to be joined 93220 * @param {String} separator String to be placed between each item 93221 * @return {String} joined String 93222 * @example 93223 * <div> 93224 * <code> 93225 * let array = ['Hello', 'world!']; 93226 * let separator = ' '; 93227 * let message = join(array, separator); 93228 * text(message, 5, 50); 93229 * </code> 93230 * </div> 93231 * 93232 * @alt 93233 * "hello world!" displayed middle left of canvas. 93234 */ 93235 93236 _main.default.prototype.join = function (list, separator) { 93237 _main.default._validateParameters('join', arguments); 93238 return list.join(separator); 93239 }; 93240 /** 93241 * This function is used to apply a regular expression to a piece of text, 93242 * and return matching groups (elements found inside parentheses) as a 93243 * String array. If there are no matches, a null value will be returned. 93244 * If no groups are specified in the regular expression, but the sequence 93245 * matches, an array of length 1 (with the matched text as the first element 93246 * of the array) will be returned. 93247 * 93248 * To use the function, first check to see if the result is null. If the 93249 * result is null, then the sequence did not match at all. If the sequence 93250 * did match, an array is returned. 93251 * 93252 * If there are groups (specified by sets of parentheses) in the regular 93253 * expression, then the contents of each will be returned in the array. 93254 * Element [0] of a regular expression match returns the entire matching 93255 * string, and the match groups start at element [1] (the first group is [1], 93256 * the second [2], and so on). 93257 * 93258 * @method match 93259 * @param {String} str the String to be searched 93260 * @param {String} regexp the regexp to be used for matching 93261 * @return {String[]} Array of Strings found 93262 * @example 93263 * <div> 93264 * <code> 93265 * let string = 'Hello p5js*!'; 93266 * let regexp = 'p5js\\*'; 93267 * let m = match(string, regexp); 93268 * text(m, 5, 50); 93269 * </code> 93270 * </div> 93271 * 93272 * @alt 93273 * "p5js*" displayed middle left of canvas. 93274 */ 93275 _main.default.prototype.match = function (str, reg) { 93276 _main.default._validateParameters('match', arguments); 93277 return str.match(reg); 93278 }; 93279 /** 93280 * This function is used to apply a regular expression to a piece of text, 93281 * and return a list of matching groups (elements found inside parentheses)
93282 * as a two-dimensional String array. If there are no matches, a null value 93283 * will be returned. If no groups are specified in the regular expression, 93284 * but the sequence matches, a two dimensional array is still returned, but 93285 * the second dimension is only of length one. 93286 * 93287 * To use the function, first check to see if the result is null. If the 93288 * result is null, then the sequence did not match at all. If the sequence 93289 * did match, a 2D array is returned. 93290 * 93291 * If there are groups (specified by sets of parentheses) in the regular 93292 * expression, then the contents of each will be returned in the array. 93293 * Assuming a loop with counter variable i, element [i][0] of a regular 93294 * expression match returns the entire matching string, and the match groups 93295 * start at element [i][1] (the first group is [i][1], the second [i][2], 93296 * and so on). 93297 * 93298 * @method matchAll 93299 * @param {String} str the String to be searched 93300 * @param {String} regexp the regexp to be used for matching 93301 * @return {String[]} 2d Array of Strings found 93302 * @example 93303 * <div class="norender"> 93304 * <code> 93305 * let string = 'Hello p5js*! Hello world!'; 93306 * let regexp = 'Hello'; 93307 * matchAll(string, regexp); 93308 * </code> 93309 * </div> 93310 */ 93311 _main.default.prototype.matchAll = function (str, reg) { 93312 _main.default._validateParameters('matchAll', arguments); 93313 var re = new RegExp(reg, 'g'); 93314 var match = re.exec(str); 93315 var matches = [ 93316 ]; 93317 while (match !== null) { 93318 matches.push(match); // matched text: match[0] 93319 // match start: match.index 93320 // capturing group n: match[n] 93321 match = re.exec(str); 93322 } 93323 return matches; 93324 }; 93325 /** 93326 * Utility function for formatting numbers into strings. There are two 93327 * versions: one for formatting floats, and one for formatting ints. 93328 * 93329 * The values for the digits, left, and right parameters should always 93330 * be positive integers. 93331 * 93332 * (NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter 93333 * if greater than the current length of the number. 93334 * 93335 * For example if number is 123.2 and left parameter passed is 4 which is greater than length of 123 93336 * (integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than 93337 * the result will be 123.200. 93338 * 93339 * @method nf 93340 * @param {Number|String} num the Number to format 93341 * @param {Integer|String} [left] number of digits to the left of the 93342 * decimal point 93343 * @param {Integer|String} [right] number of digits to the right of the 93344 * decimal point 93345 * @return {String} formatted String 93346 * 93347 * @example 93348 * <div> 93349 * <code> 93350 * function setup() { 93351 * background(200); 93352 * let num1 = 321; 93353 * let num2 = -1321; 93354 * 93355 * noStroke(); 93356 * fill(0); 93357 * textSize(16); 93358 * 93359 * text(nf(num1, 4, 2), 10, 30); 93360 * text(nf(num2, 4, 2), 10, 80); 93361 * // Draw dividing line 93362 * stroke(120); 93363 * line(0, 50, width, 50); 93364 * } 93365 * </code> 93366 * </div> 93367 * 93368 * @alt 93369 * "0321.00" middle top, -1321.00" middle bottom canvas 93370 */ 93371 /** 93372 * @method nf 93373 * @param {Array} nums the Numbers to format 93374 * @param {Integer|String} [left] 93375 * @param {Integer|String} [right] 93376 * @return {String[]} formatted Strings 93377 */ 93378 _main.default.prototype.nf = function (nums, left, right) { 93379 _main.default._validateParameters('nf', arguments); 93380 if (nums instanceof Array) { 93381 return nums.map(function (x) { 93382 return doNf(x, left, right); 93383 }); 93384 } else { 93385 var typeOfFirst = Object.prototype.toString.call(nums); 93386 if (typeOfFirst === '[object Arguments]') { 93387 if (nums.length === 3) { 93388 return this.nf(nums[0], nums[1], nums[2]); 93389 } else if (nums.length === 2) { 93390 return this.nf(nums[0], nums[1]); 93391 } else { 93392 return this.nf(nums[0]); 93393 } 93394 } else { 93395 return doNf(nums, left, right); 93396 } 93397 } 93398 }; 93399 function doNf(num, left, right) { 93400 var neg = num < 0; 93401 var n = neg ? num.toString().substring(1) : num.toString(); 93402 var decimalInd = n.indexOf('.'); 93403 var intPart = decimalInd !== - 1 ? n.substring(0, decimalInd) : n; 93404 var decPart = decimalInd !== - 1 ? n.substring(decimalInd + 1) : ''; 93405 var str = neg ? '-' : ''; 93406 if (typeof right !== 'undefined') { 93407 var decimal = ''; 93408 if (decimalInd !== - 1 || right - decPart.length > 0) { 93409 decimal = '.'; 93410 } 93411 if (decPart.length > right) { 93412 decPart = decPart.substring(0, right); 93413 } 93414 for (var i = 0; i < left - intPart.length; i++) { 93415 str += '0'; 93416 } 93417 str += intPart; 93418 str += decimal; 93419 str += decPart; 93420 for (var j = 0; j < right - decPart.length; j++) { 93421 str += '0'; 93422 } 93423 return str; 93424 } else { 93425 for (var k = 0; k < Math.max(left - intPart.length, 0); k++) { 93426 str += '0'; 93427 } 93428 str += n; 93429 return str; 93430 } 93431 } /** 93432 * Utility function for formatting numbers into strings and placing 93433 * appropriate commas to mark units of 1000. There are two versions: one 93434 * for formatting ints, and one for formatting an array of ints. The value 93435 * for the right parameter should always be a positive integer. 93436 * 93437 * @method nfc 93438 * @param {Number|String} num the Number to format 93439 * @param {Integer|String} [right] number of digits to the right of the 93440 * decimal point 93441 * @return {String} formatted String 93442 * 93443 * @example 93444 * <div> 93445 * <code> 93446 * function setup() { 93447 * background(200); 93448 * let num = 11253106.115; 93449 * let numArr = [1, 1, 2]; 93450 * 93451 * noStroke(); 93452 * fill(0); 93453 * textSize(12); 93454 * 93455 * // Draw formatted numbers 93456 * text(nfc(num, 4), 10, 30); 93457 * text(nfc(numArr, 2), 10, 80); 93458 * 93459 * // Draw dividing line 93460 * stroke(120); 93461 * line(0, 50, width, 50); 93462 * } 93463 * </code> 93464 * </div> 93465 * 93466 * @alt 93467 * "11,253,106.115" top middle and "1.00,1.00,2.00" displayed bottom mid 93468 */ 93469 /** 93470 * @method nfc 93471 * @param {Array} nums the Numbers to format 93472 * @param {Integer|String} [right] 93473 * @return {String[]} formatted Strings 93474 */ 93475 93476 _main.default.prototype.nfc = function (num, right) { 93477 _main.default._validateParameters('nfc', arguments); 93478 if (num instanceof Array) { 93479 return num.map(function (x) { 93480 return doNfc(x, right); 93481 }); 93482 } else { 93483 return doNfc(num, right); 93484 } 93485 }; 93486 function doNfc(num, right) { 93487 num = num.toString(); 93488 var dec = num.indexOf('.'); 93489 var rem = dec !== - 1 ? num.substring(dec) : ''; 93490 var n = dec !== - 1 ? num.substring(0, dec) : num; 93491 n = n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); 93492 if (right === 0) { 93493 rem = ''; 93494 } else if (typeof right !== 'undefined') { 93495 if (right > rem.length) { 93496 rem += dec === - 1 ? '.' : ''; 93497 var len = right - rem.length + 1; 93498 for (var i = 0; i < len; i++) { 93499 rem += '0'; 93500 } 93501 } else { 93502 rem = rem.substring(0, right + 1); 93503 } 93504 } 93505 return n + rem; 93506 } /** 93507 * Utility function for formatting numbers into strings. Similar to <a href="#/p5/nf">nf()</a> but 93508 * puts a "+" in front of positive numbers and a "-" in front of negative 93509 * numbers. There are two versions: one for formatting floats, and one for 93510 * formatting ints. The values for left, and right parameters 93511 * should always be positive integers. 93512 * 93513 * @method nfp 93514 * @param {Number} num the Number to format 93515 * @param {Integer} [left] number of digits to the left of the decimal 93516 * point 93517 * @param {Integer} [right] number of digits to the right of the 93518 * decimal point 93519 * @return {String} formatted String 93520 * 93521 * @example 93522 * <div> 93523 * <code> 93524 * function setup() { 93525 * background(200); 93526 * let num1 = 11253106.115; 93527 * let num2 = -11253106.115; 93528 * 93529 * noStroke(); 93530 * fill(0); 93531 * textSize(12); 93532 * 93533 * // Draw formatted numbers 93534 * text(nfp(num1, 4, 2), 10, 30); 93535 * text(nfp(num2, 4, 2), 10, 80); 93536 * 93537 * // Draw dividing line 93538 * stroke(120); 93539 * line(0, 50, width, 50); 93540 * } 93541 * </code> 93542 * </div> 93543 * 93544 * @alt 93545 * "+11253106.11" top middle and "-11253106.11" displayed bottom middle 93546 */ 93547 /** 93548 * @method nfp 93549 * @param {Number[]} nums the Numbers to format 93550 * @param {Integer} [left] 93551 * @param {Integer} [right] 93552 * @return {String[]} formatted Strings 93553 */ 93554 93555 _main.default.prototype.nfp = function () { 93556 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 93557 args[_key] = arguments[_key]; 93558 }
93559 _main.default._validateParameters('nfp', args); 93560 var nfRes = _main.default.prototype.nf.apply(this, args); 93561 if (nfRes instanceof Array) { 93562 return nfRes.map(addNfp); 93563 } else { 93564 return addNfp(nfRes); 93565 } 93566 }; 93567 function addNfp(num) { 93568 return parseFloat(num) > 0 ? '+'.concat(num.toString()) : num.toString(); 93569 } /** 93570 * Utility function for formatting numbers into strings. Similar to <a href="#/p5/nf">nf()</a> but 93571 * puts an additional "_" (space) in front of positive numbers just in case to align it with negative 93572 * numbers which includes "-" (minus) sign. 93573 * 93574 * The main usecase of nfs() can be seen when one wants to align the digits (place values) of a non-negative 93575 * number with some negative number (See the example to get a clear picture). 93576 * There are two versions: one for formatting float, and one for formatting int. 93577 * 93578 * The values for the digits, left, and right parameters should always be positive integers. 93579 * 93580 * (IMP): The result on the canvas basically the expected alignment can vary based on the typeface you are using. 93581 * 93582 * (NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter 93583 * if greater than the current length of the number. 93584 * 93585 * For example if number is 123.2 and left parameter passed is 4 which is greater than length of 123 93586 * (integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than 93587 * the result will be 123.200. 93588 * 93589 * @method nfs 93590 * @param {Number} num the Number to format 93591 * @param {Integer} [left] number of digits to the left of the decimal 93592 * point 93593 * @param {Integer} [right] number of digits to the right of the 93594 * decimal point 93595 * @return {String} formatted String 93596 * 93597 * @example 93598 * <div> 93599 * <code> 93600 * function setup() { 93601 * background(200); 93602 * let num1 = 321; 93603 * let num2 = -1321; 93604 * 93605 * noStroke(); 93606 * fill(0); 93607 * textSize(16); 93608 * 93609 * // nfs() aligns num1 (positive number) with num2 (negative number) by 93610 * // adding a blank space in front of the num1 (positive number) 93611 * // [left = 4] in num1 add one 0 in front, to align the digits with num2 93612 * // [right = 2] in num1 and num2 adds two 0's after both numbers 93613 * // To see the differences check the example of nf() too. 93614 * text(nfs(num1, 4, 2), 10, 30); 93615 * text(nfs(num2, 4, 2), 10, 80); 93616 * // Draw dividing line 93617 * stroke(120); 93618 * line(0, 50, width, 50); 93619 * } 93620 * </code> 93621 * </div> 93622 * 93623 * @alt 93624 * "0321.00" top middle and "-1321.00" displayed bottom middle 93625 */ 93626 /** 93627 * @method nfs 93628 * @param {Array} nums the Numbers to format 93629 * @param {Integer} [left] 93630 * @param {Integer} [right] 93631 * @return {String[]} formatted Strings 93632 */ 93633 93634 _main.default.prototype.nfs = function () { 93635 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 93636 args[_key2] = arguments[_key2]; 93637 } 93638 _main.default._validateParameters('nfs', args); 93639 var nfRes = _main.default.prototype.nf.apply(this, args); 93640 if (nfRes instanceof Array) { 93641 return nfRes.map(addNfs); 93642 } else { 93643 return addNfs(nfRes); 93644 } 93645 }; 93646 function addNfs(num) { 93647 return parseFloat(num) >= 0 ? ' '.concat(num.toString()) : num.toString(); 93648 } /** 93649 * The <a href="#/p5/split">split()</a> function maps to String.split(), it breaks a String into 93650 * pieces using a character or string as the delimiter. The delim parameter 93651 * specifies the character or characters that mark the boundaries between 93652 * each piece. A String[] array is returned that contains each of the pieces. 93653 * 93654 * The <a href="#/p5/splitTokens">splitTokens()</a> function works in a similar fashion, except that it 93655 * splits using a range of characters instead of a specific character or 93656 * sequence. 93657 * 93658 * @method split 93659 * @param {String} value the String to be split 93660 * @param {String} delim the String used to separate the data 93661 * @return {String[]} Array of Strings 93662 * @example 93663 * <div> 93664 * <code> 93665 * let names = 'Pat,Xio,Alex'; 93666 * let splitString = split(names, ',');
93667 * text(splitString[0], 5, 30); 93668 * text(splitString[1], 5, 50); 93669 * text(splitString[2], 5, 70); 93670 * </code> 93671 * </div> 93672 * 93673 * @alt 93674 * "pat" top left, "Xio" mid left and "Alex" displayed bottom left 93675 */ 93676 93677 _main.default.prototype.split = function (str, delim) { 93678 _main.default._validateParameters('split', arguments); 93679 return str.split(delim); 93680 }; 93681 /** 93682 * The <a href="#/p5/splitTokens">splitTokens()</a> function splits a String at one or many character 93683 * delimiters or "tokens." The delim parameter specifies the character or 93684 * characters to be used as a boundary. 93685 * 93686 * If no delim characters are specified, any whitespace character is used to 93687 * split. Whitespace characters include tab (\t), line feed (\n), carriage 93688 * return (\r), form feed (\f), and space. 93689 * 93690 * @method splitTokens 93691 * @param {String} value the String to be split 93692 * @param {String} [delim] list of individual Strings that will be used as 93693 * separators 93694 * @return {String[]} Array of Strings 93695 * @example 93696 * <div class = "norender"> 93697 * <code> 93698 * function setup() { 93699 * let myStr = 'Mango, Banana, Lime'; 93700 * let myStrArr = splitTokens(myStr, ','); 93701 * 93702 * print(myStrArr); // prints : ["Mango"," Banana"," Lime"] 93703 * } 93704 * </code> 93705 * </div> 93706 */ 93707 _main.default.prototype.splitTokens = function (value, delims) { 93708 _main.default._validateParameters('splitTokens', arguments); 93709 var d; 93710 if (typeof delims !== 'undefined') { 93711 var str = delims; 93712 var sqc = /\]/g.exec(str); 93713 var sqo = /\[/g.exec(str); 93714 if (sqo && sqc) { 93715 str = str.slice(0, sqc.index) + str.slice(sqc.index + 1); 93716 sqo = /\[/g.exec(str); 93717 str = str.slice(0, sqo.index) + str.slice(sqo.index + 1); 93718 d = new RegExp('[\\['.concat(str, '\\]]'), 'g'); 93719 } else if (sqc) { 93720 str = str.slice(0, sqc.index) + str.slice(sqc.index + 1); 93721 d = new RegExp('['.concat(str, '\\]]'), 'g'); 93722 } else if (sqo) { 93723 str = str.slice(0, sqo.index) + str.slice(sqo.index + 1); 93724 d = new RegExp('['.concat(str, '\\[]'), 'g'); 93725 } else { 93726 d = new RegExp('['.concat(str, ']'), 'g'); 93727 } 93728 } else { 93729 d = /\s/g; 93730 } 93731 return value.split(d).filter(function (n) { 93732 return n; 93733 }); 93734 }; 93735 /** 93736 * Removes whitespace characters from the beginning and end of a String. In 93737 * addition to standard whitespace characters such as space, carriage return, 93738 * and tab, this function also removes the Unicode "nbsp" character. 93739 * 93740 * @method trim 93741 * @param {String} str a String to be trimmed 93742 * @return {String} a trimmed String 93743 * 93744 * @example 93745 * <div> 93746 * <code> 93747 * let string = trim(' No new lines\n '); 93748 * text(string + ' here', 2, 50); 93749 * </code> 93750 * </div> 93751 * 93752 * @alt 93753 * "No new lines here" displayed center canvas 93754 */ 93755 /** 93756 * @method trim 93757 * @param {Array} strs an Array of Strings to be trimmed 93758 * @return {String[]} an Array of trimmed Strings 93759 */ 93760 _main.default.prototype.trim = function (str) { 93761 _main.default._validateParameters('trim', arguments); 93762 if (str instanceof Array) { 93763 return str.map(this.trim); 93764 } else { 93765 return str.trim(); 93766 } 93767 }; 93768 var _default = _main.default; 93769 exports.default = _default; 93770 }, 93771 { 93772 '../core/friendly_errors/fes_core': 281, 93773 '../core/friendly_errors/file_errors': 282, 93774 '../core/friendly_errors/validate_params': 285, 93775 '../core/main': 290, 93776 'core-js/modules/es.array.filter': 171, 93777 'core-js/modules/es.array.index-of': 175, 93778 'core-js/modules/es.array.join': 177, 93779 'core-js/modules/es.array.map': 179, 93780 'core-js/modules/es.array.slice': 180, 93781 'core-js/modules/es.object.to-string': 195, 93782 'core-js/modules/es.regexp.constructor': 198, 93783 'core-js/modules/es.regexp.exec': 199, 93784 'core-js/modules/es.regexp.to-string': 200, 93785 'core-js/modules/es.string.match': 205, 93786 'core-js/modules/es.string.replace': 207, 93787 'core-js/modules/es.string.split': 209, 93788 'core-js/modules/es.string.trim': 211 93789 } 93790 ], 93791 332: [
93792 function (_dereq_, module, exports) { 93793 'use strict'; 93794 Object.defineProperty(exports, '__esModule', { 93795 value: true 93796 }); 93797 exports.default = void 0; 93798 var _main = _interopRequireDefault(_dereq_('../core/main')); 93799 function _interopRequireDefault(obj) { 93800 return obj && obj.__esModule ? obj : { 93801 default: 93802 obj 93803 }; 93804 } /** 93805 * @module IO 93806 * @submodule Time & Date 93807 * @for p5 93808 * @requires core 93809 */ 93810 /** 93811 * p5.js communicates with the clock on your computer. The <a href="#/p5/day">day()</a> function 93812 * returns the current day as a value from 1 - 31. 93813 * 93814 * @method day 93815 * @return {Integer} the current day 93816 * @example 93817 * <div> 93818 * <code> 93819 * let d = day(); 93820 * text('Current day: \n' + d, 5, 50); 93821 * </code> 93822 * </div> 93823 * 93824 * @alt 93825 * Current day is displayed 93826 */ 93827 93828 _main.default.prototype.day = function () { 93829 return new Date().getDate(); 93830 }; 93831 /** 93832 * p5.js communicates with the clock on your computer. The <a href="#/p5/hour">hour()</a> function 93833 * returns the current hour as a value from 0 - 23. 93834 * 93835 * @method hour 93836 * @return {Integer} the current hour 93837 * @example 93838 * <div> 93839 * <code> 93840 * let h = hour(); 93841 * text('Current hour:\n' + h, 5, 50); 93842 * </code> 93843 * </div> 93844 * 93845 * @alt 93846 * Current hour is displayed 93847 */ 93848 _main.default.prototype.hour = function () { 93849 return new Date().getHours(); 93850 }; 93851 /** 93852 * p5.js communicates with the clock on your computer. The <a href="#/p5/minute">minute()</a> function 93853 * returns the current minute as a value from 0 - 59. 93854 * 93855 * @method minute 93856 * @return {Integer} the current minute 93857 * @example 93858 * <div> 93859 * <code> 93860 * let m = minute(); 93861 * text('Current minute: \n' + m, 5, 50); 93862 * </code> 93863 * </div> 93864 * 93865 * @alt 93866 * Current minute is displayed 93867 */ 93868 _main.default.prototype.minute = function () { 93869 return new Date().getMinutes(); 93870 }; 93871 /** 93872 * Returns the number of milliseconds (thousandths of a second) since 93873 * starting the sketch (when `setup()` is called). This information is often 93874 * used for timing events and animation sequences. 93875 * 93876 * @method millis 93877 * @return {Number} the number of milliseconds since starting the sketch 93878 * @example 93879 * <div> 93880 * <code> 93881 * let millisecond = millis(); 93882 * text('Milliseconds \nrunning: \n' + millisecond, 5, 40); 93883 * </code> 93884 * </div> 93885 * 93886 * @alt 93887 * number of milliseconds since sketch has started displayed 93888 */ 93889 _main.default.prototype.millis = function () { 93890 if (this._millisStart === - 1) { 93891 // Sketch has not started 93892 return 0; 93893 } else { 93894 return window.performance.now() - this._millisStart; 93895 } 93896 }; 93897 /** 93898 * p5.js communicates with the clock on your computer. The <a href="#/p5/month">month()</a> function 93899 * returns the current month as a value from 1 - 12. 93900 * 93901 * @method month 93902 * @return {Integer} the current month 93903 * @example 93904 * <div> 93905 * <code> 93906 * let m = month(); 93907 * text('Current month: \n' + m, 5, 50); 93908 * </code> 93909 * </div> 93910 * 93911 * @alt 93912 * Current month is displayed 93913 */ 93914 _main.default.prototype.month = function () { 93915 //January is 0! 93916 return new Date().getMonth() + 1; 93917 }; 93918 /** 93919 * p5.js communicates with the clock on your computer. The <a href="#/p5/second">second()</a> function 93920 * returns the current second as a value from 0 - 59. 93921 * 93922 * @method second 93923 * @return {Integer} the current second 93924 * @example 93925 * <div> 93926 * <code> 93927 * let s = second(); 93928 * text('Current second: \n' + s, 5, 50); 93929 * </code> 93930 * </div> 93931 * 93932 * @alt 93933 * Current second is displayed 93934 */ 93935 _main.default.prototype.second = function () { 93936 return new Date().getSeconds(); 93937 }; 93938 /** 93939 * p5.js communicates with the clock on your computer. The <a href="#/p5/year">year()</a> function 93940 * returns the current year as an integer (2014, 2015, 2016, etc). 93941 * 93942 * @method year 93943 * @return {Integer} the current year 93944 * @example 93945 * <div> 93946 * <code> 93947 * let y = year(); 93948 * text('Current year: \n' + y, 5, 50); 93949 * </code> 93950 * </div> 93951 * 93952 * @alt 93953 * Current year is displayed 93954 */ 93955 _main.default.prototype.year = function () { 93956 return new Date().getFullYear(); 93957 }; 93958 var _default = _main.default; 93959 exports.default = _default; 93960 }, 93961 { 93962 '../core/main': 290 93963 } 93964 ], 93965 333: [
93966 function (_dereq_, module, exports) { 93967 'use strict'; 93968 _dereq_('core-js/modules/es.symbol'); 93969 _dereq_('core-js/modules/es.symbol.description'); 93970 _dereq_('core-js/modules/es.symbol.iterator'); 93971 _dereq_('core-js/modules/es.array.concat'); 93972 _dereq_('core-js/modules/es.array.iterator'); 93973 _dereq_('core-js/modules/es.array.slice'); 93974 _dereq_('core-js/modules/es.math.hypot'); 93975 _dereq_('core-js/modules/es.number.to-fixed'); 93976 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 93977 _dereq_('core-js/modules/es.object.to-string'); 93978 _dereq_('core-js/modules/es.string.iterator'); 93979 _dereq_('core-js/modules/es.weak-map'); 93980 _dereq_('core-js/modules/web.dom-collections.iterator'); 93981 function _typeof2(obj) { 93982 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 93983 _typeof2 = function _typeof2(obj) { 93984 return typeof obj; 93985 }; 93986 } else { 93987 _typeof2 = function _typeof2(obj) { 93988 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 93989 }; 93990 } 93991 return _typeof2(obj); 93992 } 93993 function _typeof(obj) { 93994 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 93995 _typeof = function _typeof(obj) { 93996 return _typeof2(obj); 93997 }; 93998 } else { 93999 _typeof = function _typeof(obj) { 94000 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 94001 }; 94002 } 94003 return _typeof(obj); 94004 } 94005 _dereq_('core-js/modules/es.symbol'); 94006 _dereq_('core-js/modules/es.symbol.description'); 94007 _dereq_('core-js/modules/es.symbol.iterator'); 94008 _dereq_('core-js/modules/es.array.concat'); 94009 _dereq_('core-js/modules/es.array.iterator'); 94010 _dereq_('core-js/modules/es.array.slice'); 94011 _dereq_('core-js/modules/es.math.hypot'); 94012 _dereq_('core-js/modules/es.number.to-fixed'); 94013 _dereq_('core-js/modules/es.object.to-string'); 94014 _dereq_('core-js/modules/es.string.iterator'); 94015 _dereq_('core-js/modules/web.dom-collections.iterator'); 94016 Object.defineProperty(exports, '__esModule', { 94017 value: true 94018 }); 94019 exports.default = void 0; 94020 var _main = _interopRequireDefault(_dereq_('../core/main')); 94021 _dereq_('./p5.Geometry'); 94022 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 94023 function _getRequireWildcardCache() { 94024 if (typeof WeakMap !== 'function') return null; 94025 var cache = new WeakMap(); 94026 _getRequireWildcardCache = function _getRequireWildcardCache() { 94027 return cache; 94028 }; 94029 return cache; 94030 } 94031 function _interopRequireWildcard(obj) { 94032 if (obj && obj.__esModule) { 94033 return obj; 94034 } 94035 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 94036 return { 94037 default: 94038 obj 94039 }; 94040 } 94041 var cache = _getRequireWildcardCache(); 94042 if (cache && cache.has(obj)) { 94043 return cache.get(obj); 94044 } 94045 var newObj = { 94046 }; 94047 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 94048 for (var key in obj) { 94049 if (Object.prototype.hasOwnProperty.call(obj, key)) { 94050 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 94051 if (desc && (desc.get || desc.set)) { 94052 Object.defineProperty(newObj, key, desc); 94053 } else { 94054 newObj[key] = obj[key]; 94055 } 94056 } 94057 } 94058 newObj.default = obj; 94059 if (cache) { 94060 cache.set(obj, newObj); 94061 } 94062 return newObj; 94063 } 94064 function _interopRequireDefault(obj) { 94065 return obj && obj.__esModule ? obj : { 94066 default: 94067 obj 94068 }; 94069 } /** 94070 * @module Shape 94071 * @submodule 3D Primitives 94072 * @for p5 94073 * @requires core 94074 * @requires p5.Geometry 94075 */ 94076 /** 94077 * Draw a plane with given a width and height 94078 * @method plane 94079 * @param {Number} [width] width of the plane 94080 * @param {Number} [height] height of the plane 94081 * @param {Integer} [detailX] Optional number of triangle 94082 * subdivisions in x-dimension 94083 * @param {Integer} [detailY] Optional number of triangle 94084 * subdivisions in y-dimension 94085 * @chainable 94086 * @example 94087 * <div> 94088 * <code> 94089 * // draw a plane 94090 * // with width 50 and height 50 94091 * function setup() { 94092 * createCanvas(100, 100, WEBGL); 94093 * describe('a white plane with black wireframe lines'); 94094 * } 94095 * 94096 * function draw() { 94097 * background(200); 94098 * plane(50, 50); 94099 * } 94100 * </code> 94101 * </div> 94102 * 94103 * @alt 94104 * Nothing displayed on canvas 94105 * Rotating interior view of a box with sides that change color. 94106 * 3d red and green gradient. 94107 * Rotating interior view of a cylinder with sides that change color. 94108 * Rotating view of a cylinder with sides that change color. 94109 * 3d red and green gradient. 94110 * rotating view of a multi-colored cylinder with concave sides. 94111 */ 94112 94113 _main.default.prototype.plane = function (width, height, detailX, detailY) { 94114 this._assert3d('plane'); 94115 _main.default._validateParameters('plane', arguments); 94116 if (typeof width === 'undefined') { 94117 width = 50; 94118 } 94119 if (typeof height === 'undefined') { 94120 height = width; 94121 } 94122 if (typeof detailX === 'undefined') { 94123 detailX = 1; 94124 } 94125 if (typeof detailY === 'undefined') { 94126 detailY = 1; 94127 } 94128 var gId = 'plane|'.concat(detailX, '|').concat(detailY); 94129 if (!this._renderer.geometryInHash(gId)) { 94130 var _plane = function _plane() { 94131 var u, 94132 v, 94133 p; 94134 for (var i = 0; i <= this.detailY; i++) { 94135 v = i / this.detailY; 94136 for (var j = 0; j <= this.detailX; j++) { 94137 u = j / this.detailX; 94138 p = new _main.default.Vector(u - 0.5, v - 0.5, 0); 94139 this.vertices.push(p); 94140 this.uvs.push(u, v); 94141 } 94142 } 94143 }; 94144 var planeGeom = new _main.default.Geometry(detailX, detailY, _plane); 94145 planeGeom.computeFaces().computeNormals(); 94146 if (detailX <= 1 && detailY <= 1) { 94147 planeGeom._makeTriangleEdges()._edgesToVertices(); 94148 } else if (this._renderer._doStroke) { 94149 console.log('Cannot draw stroke on plane objects with more' + ' than 1 detailX or 1 detailY'); 94150 } 94151 this._renderer.createBuffers(gId, planeGeom); 94152 } 94153 this._renderer.drawBuffersScaled(gId, width, height, 1); 94154 return this; 94155 }; 94156 /** 94157 * Draw a box with given width, height and depth 94158 * @method box 94159 * @param {Number} [width] width of the box 94160 * @param {Number} [height] height of the box 94161 * @param {Number} [depth] depth of the box 94162 * @param {Integer} [detailX] Optional number of triangle 94163 * subdivisions in x-dimension 94164 * @param {Integer} [detailY] Optional number of triangle 94165 * subdivisions in y-dimension 94166 * @chainable 94167 * @example 94168 * <div> 94169 * <code> 94170 * // draw a spinning box 94171 * // with width, height and depth of 50 94172 * function setup() { 94173 * createCanvas(100, 100, WEBGL); 94174 * describe('a white box rotating in 3D space'); 94175 * } 94176 * 94177 * function draw() { 94178 * background(200); 94179 * rotateX(frameCount * 0.01); 94180 * rotateY(frameCount * 0.01); 94181 * box(50); 94182 * } 94183 * </code> 94184 * </div> 94185 */ 94186 _main.default.prototype.box = function (width, height, depth, detailX, detailY) { 94187 this._assert3d('box'); 94188 _main.default._validateParameters('box', arguments); 94189 if (typeof width === 'undefined') { 94190 width = 50; 94191 } 94192 if (typeof height === 'undefined') { 94193 height = width; 94194 } 94195 if (typeof depth === 'undefined') { 94196 depth = height; 94197 } 94198 var perPixelLighting = this._renderer.attributes && this._renderer.attributes.perPixelLighting; 94199 if (typeof detailX === 'undefined') { 94200 detailX = perPixelLighting ? 1 : 4; 94201 } 94202 if (typeof detailY === 'undefined') { 94203 detailY = perPixelLighting ? 1 : 4; 94204 } 94205 var gId = 'box|'.concat(detailX, '|').concat(detailY); 94206 if (!this._renderer.geometryInHash(gId)) { 94207 var _box = function _box() { 94208 var cubeIndices = [ 94209 [0, 94210 4, 94211 2, 94212 6], // -1, 0, 0],// -x 94213 [ 94214 1, 94215 3, 94216 5, 94217 7 94218 ], // +1, 0, 0],// +x 94219 [ 94220 0, 94221 1, 94222 4, 94223 5 94224 ], // 0, -1, 0],// -y 94225 [ 94226 2, 94227 6, 94228 3, 94229 7 94230 ], // 0, +1, 0],// +y 94231 [ 94232 0, 94233 2, 94234 1, 94235 3 94236 ], // 0, 0, -1],// -z 94237 [ 94238 4, 94239 5, 94240 6, 94241 7 94242 ] // 0, 0, +1] // +z 94243 ]; //using strokeIndices instead of faces for strokes 94244 //to avoid diagonal stroke lines across face of box 94245 this.strokeIndices = [ 94246 [0, 94247 1], 94248 [ 94249 1, 94250 3 94251 ], 94252 [ 94253 3, 94254 2 94255 ], 94256 [ 94257 6, 94258 7 94259 ], 94260 [ 94261 8, 94262 9 94263 ], 94264 [ 94265 9, 94266 11 94267 ], 94268 [ 94269 14, 94270 15 94271 ], 94272 [ 94273 16, 94274 17 94275 ], 94276 [ 94277 17, 94278 19 94279 ], 94280 [ 94281 18, 94282 19 94283 ], 94284 [ 94285 20, 94286 21 94287 ], 94288 [ 94289 22, 94290 23 94291 ] 94292 ]; 94293 for (var i = 0; i < cubeIndices.length; i++) { 94294 var cubeIndex = cubeIndices[i]; 94295 var v = i * 4; 94296 for (var j = 0; j < 4; j++) { 94297 var d = cubeIndex[j]; //inspired by lightgl: 94298 //https://github.com/evanw/lightgl.js 94299 //octants:https://en.wikipedia.org/wiki/Octant_(solid_geometry) 94300 var octant = new _main.default.Vector(((d & 1) * 2 - 1) / 2, ((d & 2) - 1) / 2, ((d & 4) / 2 - 1) / 2); 94301 this.vertices.push(octant); 94302 this.uvs.push(j & 1, (j & 2) / 2); 94303 } 94304 this.faces.push([v, 94305 v + 1, 94306 v + 2]); 94307 this.faces.push([v + 2, 94308 v + 1, 94309 v + 3]); 94310 } 94311 }; 94312 var boxGeom = new _main.default.Geometry(detailX, detailY, _box); 94313 boxGeom.computeNormals(); 94314 if (detailX <= 4 && detailY <= 4) { 94315 boxGeom._makeTriangleEdges()._edgesToVertices(); 94316 } else if (this._renderer._doStroke) { 94317 console.log('Cannot draw stroke on box objects with more' + ' than 4 detailX or 4 detailY'); 94318 } //initialize our geometry buffer with 94319 //the key val pair: 94320 //geometry Id, Geom object 94321 94322 this._renderer.createBuffers(gId, boxGeom); 94323 } 94324 this._renderer.drawBuffersScaled(gId, width, height, depth); 94325 return this; 94326 }; 94327 /** 94328 * Draw a sphere with given radius. 94329 * 94330 * DetailX and detailY determines the number of subdivisions in the x-dimension 94331 * and the y-dimension of a sphere. More subdivisions make the sphere seem 94332 * smoother. The recommended maximum values are both 24. Using a value greater 94333 * than 24 may cause a warning or slow down the browser. 94334 * @method sphere 94335 * @param {Number} [radius] radius of circle 94336 * @param {Integer} [detailX] optional number of subdivisions in x-dimension 94337 * @param {Integer} [detailY] optional number of subdivisions in y-dimension 94338 * 94339 * @chainable 94340 * @example 94341 * <div> 94342 * <code> 94343 * // draw a sphere with radius 40 94344 * function setup() { 94345 * createCanvas(100, 100, WEBGL); 94346 * describe('a white sphere with black wireframe lines'); 94347 * } 94348 * 94349 * function draw() { 94350 * background(205, 102, 94); 94351 * sphere(40); 94352 * } 94353 * </code> 94354 * </div> 94355 * 94356 * @example 94357 * <div> 94358 * <code> 94359 * let detailX; 94360 * // slide to see how detailX works 94361 * function setup() { 94362 * createCanvas(100, 100, WEBGL); 94363 * detailX = createSlider(3, 24, 3); 94364 * detailX.position(10, height + 5); 94365 * detailX.style('width', '80px'); 94366 * describe( 94367 * 'a white sphere with low detail on the x-axis, including a slider to adjust detailX' 94368 * ); 94369 * } 94370 * 94371 * function draw() { 94372 * background(205, 105, 94); 94373 * rotateY(millis() / 1000);
94374 * sphere(40, detailX.value(), 16); 94375 * } 94376 * </code> 94377 * </div> 94378 * 94379 * @example 94380 * <div> 94381 * <code> 94382 * let detailY; 94383 * // slide to see how detailY works 94384 * function setup() { 94385 * createCanvas(100, 100, WEBGL); 94386 * detailY = createSlider(3, 16, 3); 94387 * detailY.position(10, height + 5); 94388 * detailY.style('width', '80px'); 94389 * describe( 94390 * 'a white sphere with low detail on the y-axis, including a slider to adjust detailY' 94391 * ); 94392 * } 94393 * 94394 * function draw() { 94395 * background(205, 105, 94); 94396 * rotateY(millis() / 1000); 94397 * sphere(40, 16, detailY.value()); 94398 * } 94399 * </code> 94400 * </div> 94401 */ 94402 _main.default.prototype.sphere = function (radius, detailX, detailY) { 94403 this._assert3d('sphere'); 94404 _main.default._validateParameters('sphere', arguments); 94405 if (typeof radius === 'undefined') { 94406 radius = 50; 94407 } 94408 if (typeof detailX === 'undefined') { 94409 detailX = 24; 94410 } 94411 if (typeof detailY === 'undefined') { 94412 detailY = 16; 94413 } 94414 this.ellipsoid(radius, radius, radius, detailX, detailY); 94415 return this; 94416 }; 94417 /** 94418 * @private 94419 * Helper function for creating both cones and cylinders 94420 * Will only generate well-defined geometry when bottomRadius, height > 0 94421 * and topRadius >= 0 94422 * If topRadius == 0, topCap should be false 94423 */ 94424 var _truncatedCone = function _truncatedCone(bottomRadius, topRadius, height, detailX, detailY, bottomCap, topCap) { 94425 bottomRadius = bottomRadius <= 0 ? 1 : bottomRadius; 94426 topRadius = topRadius < 0 ? 0 : topRadius; 94427 height = height <= 0 ? bottomRadius : height; 94428 detailX = detailX < 3 ? 3 : detailX; 94429 detailY = detailY < 1 ? 1 : detailY; 94430 bottomCap = bottomCap === undefined ? true : bottomCap; 94431 topCap = topCap === undefined ? topRadius !== 0 : topCap; 94432 var start = bottomCap ? - 2 : 0; 94433 var end = detailY + (topCap ? 2 : 0); //ensure constant slant for interior vertex normals 94434 var slant = Math.atan2(bottomRadius - topRadius, height); 94435 var sinSlant = Math.sin(slant); 94436 var cosSlant = Math.cos(slant); 94437 var yy, 94438 ii, 94439 jj; 94440 for (yy = start; yy <= end; ++yy) { 94441 var v = yy / detailY; 94442 var y = height * v; 94443 var ringRadius = void 0; 94444 if (yy < 0) { 94445 //for the bottomCap edge 94446 y = 0; 94447 v = 0; 94448 ringRadius = bottomRadius; 94449 } else if (yy > detailY) { 94450 //for the topCap edge 94451 y = height; 94452 v = 1; 94453 ringRadius = topRadius; 94454 } else { 94455 //for the middle 94456 ringRadius = bottomRadius + (topRadius - bottomRadius) * v; 94457 } 94458 if (yy === - 2 || yy === detailY + 2) { 94459 //center of bottom or top caps 94460 ringRadius = 0; 94461 } 94462 y -= height / 2; //shift coordiate origin to the center of object 94463 for (ii = 0; ii < detailX; ++ii) { 94464 var u = ii / (detailX - 1); 94465 var ur = 2 * Math.PI * u; 94466 var sur = Math.sin(ur); 94467 var cur = Math.cos(ur); //VERTICES 94468 this.vertices.push(new _main.default.Vector(sur * ringRadius, y, cur * ringRadius)); //VERTEX NORMALS 94469 var vertexNormal = void 0; 94470 if (yy < 0) { 94471 vertexNormal = new _main.default.Vector(0, - 1, 0); 94472 } else if (yy > detailY && topRadius) { 94473 vertexNormal = new _main.default.Vector(0, 1, 0); 94474 } else { 94475 vertexNormal = new _main.default.Vector(sur * cosSlant, sinSlant, cur * cosSlant); 94476 } 94477 this.vertexNormals.push(vertexNormal); //UVs 94478 this.uvs.push(u, v); 94479 } 94480 } 94481 var startIndex = 0; 94482 if (bottomCap) { 94483 for (jj = 0; jj < detailX; ++jj) { 94484 var nextjj = (jj + 1) % detailX; 94485 this.faces.push([startIndex + jj, 94486 startIndex + detailX + nextjj, 94487 startIndex + detailX + jj]); 94488 } 94489 startIndex += detailX * 2; 94490 } 94491 for (yy = 0; yy < detailY; ++yy) { 94492 for (ii = 0; ii < detailX; ++ii) { 94493 var nextii = (ii + 1) % detailX; 94494 this.faces.push([startIndex + ii, 94495 startIndex + nextii, 94496 startIndex + detailX + nextii]); 94497 this.faces.push([startIndex + ii, 94498 startIndex + detailX + nextii, 94499 startIndex + detailX + ii]); 94500 } 94501 startIndex += detailX; 94502 } 94503 if (topCap) { 94504 startIndex += detailX; 94505 for (ii = 0; ii < detailX; ++ii) { 94506 this.faces.push([startIndex + ii, 94507 startIndex + (ii + 1) % detailX, 94508 startIndex + detailX]); 94509 } 94510 } 94511 }; 94512 /** 94513 * Draw a cylinder with given radius and height 94514 * 94515 * DetailX and detailY determines the number of subdivisions in the x-dimension 94516 * and the y-dimension of a cylinder. More subdivisions make the cylinder seem smoother. 94517 * The recommended maximum value for detailX is 24. Using a value greater than 24 94518 * may cause a warning or slow down the browser. 94519 * 94520 * @method cylinder 94521 * @param {Number} [radius] radius of the surface 94522 * @param {Number} [height] height of the cylinder 94523 * @param {Integer} [detailX] number of subdivisions in x-dimension; 94524 * default is 24 94525 * @param {Integer} [detailY] number of subdivisions in y-dimension; 94526 * default is 1 94527 * @param {Boolean} [bottomCap] whether to draw the bottom of the cylinder 94528 * @param {Boolean} [topCap] whether to draw the top of the cylinder 94529 * @chainable 94530 * @example 94531 * <div> 94532 * <code> 94533 * // draw a spinning cylinder 94534 * // with radius 20 and height 50 94535 * function setup() { 94536 * createCanvas(100, 100, WEBGL); 94537 * describe('a rotating white cylinder'); 94538 * } 94539 * 94540 * function draw() { 94541 * background(205, 105, 94); 94542 * rotateX(frameCount * 0.01); 94543 * rotateZ(frameCount * 0.01); 94544 * cylinder(20, 50); 94545 * } 94546 * </code> 94547 * </div> 94548 * 94549 * @example 94550 * <div> 94551 * <code> 94552 * // slide to see how detailX works 94553 * let detailX; 94554 * function setup() { 94555 * createCanvas(100, 100, WEBGL); 94556 * detailX = createSlider(3, 24, 3); 94557 * detailX.position(10, height + 5); 94558 * detailX.style('width', '80px'); 94559 * describe( 94560 * 'a rotating white cylinder with limited X detail, with a slider that adju
94560sts detailX' 94561 * ); 94562 * } 94563 * 94564 * function draw() { 94565 * background(205, 105, 94); 94566 * rotateY(millis() / 1000); 94567 * cylinder(20, 75, detailX.value(), 1); 94568 * } 94569 * </code> 94570 * </div> 94571 * 94572 * @example 94573 * <div> 94574 * <code> 94575 * // slide to see how detailY works 94576 * let detailY; 94577 * function setup() { 94578 * createCanvas(100, 100, WEBGL); 94579 * detailY = createSlider(1, 16, 1); 94580 * detailY.position(10, height + 5); 94581 * detailY.style('width', '80px'); 94582 * describe( 94583 * 'a rotating white cylinder with limited Y detail, with a slider that adjusts detailY' 94584 * ); 94585 * } 94586 * 94587 * function draw() { 94588 * background(205, 105, 94); 94589 * rotateY(millis() / 1000); 94590 * cylinder(20, 75, 16, detailY.value()); 94591 * } 94592 * </code> 94593 * </div> 94594 */ 94595 _main.default.prototype.cylinder = function (radius, height, detailX, detailY, bottomCap, topCap) { 94596 this._assert3d('cylinder'); 94597 _main.default._validateParameters('cylinder', arguments); 94598 if (typeof radius === 'undefined') { 94599 radius = 50; 94600 } 94601 if (typeof height === 'undefined') { 94602 height = radius; 94603 } 94604 if (typeof detailX === 'undefined') { 94605 detailX = 24; 94606 } 94607 if (typeof detailY === 'undefined') { 94608 detailY = 1; 94609 } 94610 if (typeof topCap === 'undefined') { 94611 topCap = true; 94612 } 94613 if (typeof bottomCap === 'undefined') { 94614 bottomCap = true; 94615 } 94616 var gId = 'cylinder|'.concat(detailX, '|').concat(detailY, '|').concat(bottomCap, '|').concat(topCap); 94617 if (!this._renderer.geometryInHash(gId)) { 94618 var cylinderGeom = new _main.default.Geometry(detailX, detailY); 94619 _truncatedCone.call(cylinderGeom, 1, 1, 1, detailX, detailY, bottomCap, topCap); // normals are computed in call to _truncatedCone 94620 if (detailX <= 24 && detailY <= 16) { 94621 cylinderGeom._makeTriangleEdges()._edgesToVertices(); 94622 } else if (this._renderer._doStroke) { 94623 console.log('Cannot draw stroke on cylinder objects with more' + ' than 24 detailX or 16 detailY'); 94624 } 94625 this._renderer.createBuffers(gId, cylinderGeom); 94626 } 94627 this._renderer.drawBuffersScaled(gId, radius, height, radius); 94628 return this; 94629 }; 94630 /** 94631 * Draw a cone with given radius and height 94632 * 94633 * DetailX and detailY determine the number of subdivisions in the x-dimension and 94634 * the y-dimension of a cone. More subdivisions make the cone seem smoother. The 94635 * recommended maximum value for detailX is 24. Using a value greater than 24 94636 * may cause a warning or slow down the browser. 94637 * @method cone 94638 * @param {Number} [radius] radius of the bottom surface 94639 * @param {Number} [height] height of the cone 94640 * @param {Integer} [detailX] number of segments, 94641 * the more segments the smoother geometry 94642 * default is 24 94643 * @param {Integer} [detailY] number of segments, 94644 * the more segments the smoother geometry 94645 * default is 1 94646 * @param {Boolean} [cap] whether to draw the base of the cone 94647 * @chainable 94648 * @example 94649 * <div> 94650 * <code> 94651 * // draw a spinning cone 94652 * // with radius 40 and height 70 94653 * function setup() { 94654 * createCanvas(100, 100, WEBGL); 94655 * describe('a rotating white cone'); 94656 * } 94657 * 94658 * function draw() { 94659 * background(200); 94660 * rotateX(frameCount * 0.01); 94661 * rotateZ(frameCount * 0.01); 94662 * cone(40, 70); 94663 * } 94664 * </code> 94665 * </div> 94666 * 94667 * @example 94668 * <div> 94669 * <code> 94670 * // slide to see how detailx works 94671 * let detailX; 94672 * function setup() { 94673 * createCanvas(100, 100, WEBGL); 94674 * detailX = createSlider(3, 16, 3); 94675 * detailX.position(10, height + 5); 94676 * detailX.style('width', '80px'); 94677 * describe( 94678 * 'a rotating white cone with limited X detail, with a slider that adjusts detailX' 94679 * ); 94680 * } 94681 * 94682 * function draw() { 94683 * background(205, 102, 94); 94684 * rotateY(millis() / 1000); 94685 * cone(30, 65, detailX.value(), 16); 94686 * } 94687 * </code> 94688 * </div> 94689 * 94690 * @example 94691 * <div> 94692 * <code> 94693 * // slide to see how detailY works 94694 * let detailY; 94695 * function setup() { 94696 * createCanvas(100, 100, WEBGL); 94697 * detailY = createSlider(3, 16, 3); 94698 * detailY.position(10, height + 5); 94699 * detailY.style('width', '80px'); 94700 * describe( 94701 * 'a rotating white cone with limited Y detail, with a slider that adju
94701sts detailY' 94702 * ); 94703 * } 94704 * 94705 * function draw() { 94706 * background(205, 102, 94); 94707 * rotateY(millis() / 1000); 94708 * cone(30, 65, 16, detailY.value()); 94709 * } 94710 * </code> 94711 * </div> 94712 */ 94713 _main.default.prototype.cone = function (radius, height, detailX, detailY, cap) { 94714 this._assert3d('cone'); 94715 _main.default._validateParameters('cone', arguments); 94716 if (typeof radius === 'undefined') { 94717 radius = 50; 94718 } 94719 if (typeof height === 'undefined') { 94720 height = radius; 94721 } 94722 if (typeof detailX === 'undefined') { 94723 detailX = 24; 94724 } 94725 if (typeof detailY === 'undefined') { 94726 detailY = 1; 94727 } 94728 if (typeof cap === 'undefined') { 94729 cap = true; 94730 } 94731 var gId = 'cone|'.concat(detailX, '|').concat(detailY, '|').concat(cap); 94732 if (!this._renderer.geometryInHash(gId)) { 94733 var coneGeom = new _main.default.Geometry(detailX, detailY); 94734 _truncatedCone.call(coneGeom, 1, 0, 1, detailX, detailY, cap, false); 94735 if (detailX <= 24 && detailY <= 16) { 94736 coneGeom._makeTriangleEdges()._edgesToVertices(); 94737 } else if (this._renderer._doStroke) { 94738 console.log('Cannot draw stroke on cone objects with more' + ' than 24 detailX or 16 detailY'); 94739 } 94740 this._renderer.createBuffers(gId, coneGeom); 94741 } 94742 this._renderer.drawBuffersScaled(gId, radius, height, radius); 94743 return this; 94744 }; 94745 /** 94746 * Draw an ellipsoid with given radius 94747 * 94748 * DetailX and detailY determine the number of subdivisions in the x-dimension and 94749 * the y-dimension of a cone. More subdivisions make the ellipsoid appear to be smoother. 94750 * Avoid detail number above 150, it may crash the browser. 94751 * @method ellipsoid 94752 * @param {Number} [radiusx] x-radius of ellipsoid 94753 * @param {Number} [radiusy] y-radius of ellipsoid 94754 * @param {Number} [radiusz] z-radius of ellipsoid 94755 * @param {Integer} [detailX] number of segments, 94756 * the more segments the smoother geometry 94757 * default is 24. Avoid detail number above 94758 * 150, it may crash the browser. 94759 * @param {Integer} [detailY] number of segments, 94760 * the more segments the smoother geometry 94761 * default is 16. Avoid detail number above 94762 * 150, it may crash the browser. 94763 * @chainable 94764 * @example 94765 * <div> 94766 * <code> 94767 * // draw an ellipsoid 94768 * // with radius 30, 40 and 40. 94769 * function setup() { 94770 * createCanvas(100, 100, WEBGL); 94771 * describe('a white 3d ellipsoid'); 94772 * } 94773 * 94774 * function draw() { 94775 * background(205, 105, 94); 94776 * ellipsoid(30, 40, 40); 94777 * } 94778 * </code> 94779 * </div> 94780 * 94781 * @example 94782 * <div> 94783 * <code> 94784 * // slide to see how detailX works 94785 * let detailX; 94786 * function setup() { 94787 * createCanvas(100, 100, WEBGL); 94788 * detailX = createSlider(2, 24, 12); 94789 * detailX.position(10, height + 5); 94790 * detailX.style('width', '80px'); 94791 * describe( 94792 * 'a rotating white ellipsoid with limited X detail, with a slider that adjusts detailX' 94793 * ); 94794 * } 94795 * 94796 * function draw() { 94797 * background(205, 105, 94); 94798 * rotateY(millis() / 1000); 94799 * ellipsoid(30, 40, 40, detailX.value(), 8); 94800 * } 94801 * </code> 94802 * </div> 94803 * 94804 * @example 94805 * <div> 94806 * <code> 94807 * // slide to see how detailY works 94808 * let detailY; 94809 * function setup() { 94810 * createCanvas(100, 100, WEBGL); 94811 * detailY = createSlider(2, 24, 6); 94812 * detailY.position(10, height + 5); 94813 * detailY.style('width', '80px'); 94814 * describe( 94815 * 'a rotating white ellipsoid with limited Y detail, with a slider that adjusts detailY' 94816 * ); 94817 * } 94818 * 94819 * function draw() { 94820 * background(205, 105, 9); 94821 * rotateY(millis() / 1000); 94822 * ellipsoid(30, 40, 40, 12, detailY.value()); 94823 * } 94824 * </code> 94825 * </div> 94826 */ 94827 _main.default.prototype.ellipsoid = function (radiusX, radiusY, radiusZ, detailX, detailY) { 94828 this._assert3d('ellipsoid'); 94829 _main.default._validateParameters('ellipsoid', arguments); 94830 if (typeof radiusX === 'undefined') { 94831 radiusX = 50; 94832 } 94833 if (typeof radiusY === 'undefined') { 94834 radiusY = radiusX; 94835 } 94836 if (typeof radiusZ === 'undefined') {
94837 radiusZ = radiusX; 94838 } 94839 if (typeof detailX === 'undefined') { 94840 detailX = 24; 94841 } 94842 if (typeof detailY === 'undefined') { 94843 detailY = 16; 94844 } 94845 var gId = 'ellipsoid|'.concat(detailX, '|').concat(detailY); 94846 if (!this._renderer.geometryInHash(gId)) { 94847 var _ellipsoid = function _ellipsoid() { 94848 for (var i = 0; i <= this.detailY; i++) { 94849 var v = i / this.detailY; 94850 var phi = Math.PI * v - Math.PI / 2; 94851 var cosPhi = Math.cos(phi); 94852 var sinPhi = Math.sin(phi); 94853 for (var j = 0; j <= this.detailX; j++) { 94854 var u = j / this.detailX; 94855 var theta = 2 * Math.PI * u; 94856 var cosTheta = Math.cos(theta); 94857 var sinTheta = Math.sin(theta); 94858 var p = new _main.default.Vector(cosPhi * sinTheta, sinPhi, cosPhi * cosTheta); 94859 this.vertices.push(p); 94860 this.vertexNormals.push(p); 94861 this.uvs.push(u, v); 94862 } 94863 } 94864 }; 94865 var ellipsoidGeom = new _main.default.Geometry(detailX, detailY, _ellipsoid); 94866 ellipsoidGeom.computeFaces(); 94867 if (detailX <= 24 && detailY <= 24) { 94868 ellipsoidGeom._makeTriangleEdges()._edgesToVertices(); 94869 } else if (this._renderer._doStroke) { 94870 console.log('Cannot draw stroke on ellipsoids with more' + ' than 24 detailX or 24 detailY'); 94871 } 94872 this._renderer.createBuffers(gId, ellipsoidGeom); 94873 } 94874 this._renderer.drawBuffersScaled(gId, radiusX, radiusY, radiusZ); 94875 return this; 94876 }; 94877 /** 94878 * Draw a torus with given radius and tube radius 94879 * 94880 * DetailX and detailY determine the number of subdivisions in the x-dimension and 94881 * the y-dimension of a torus. More subdivisions make the torus appear to be smoother. 94882 * The default and maximum values for detailX and detailY are 24 and 16, respectively. 94883 * Setting them to relatively small values like 4 and 6 allows you to create new 94884 * shapes other than a torus. 94885 * @method torus 94886 * @param {Number} [radius] radius of the whole ring 94887 * @param {Number} [tubeRadius] radius of the tube 94888 * @param {Integer} [detailX] number of segments in x-dimension, 94889 * the more segments the smoother geometry 94890 * default is 24 94891 * @param {Integer} [detailY] number of segments in y-dimension, 94892 * the more segments the smoother geometry 94893 * default is 16 94894 * @chainable 94895 * @example 94896 * <div> 94897 * <code> 94898 * // draw a spinning torus 94899 * // with ring radius 30 and tube radius 15 94900 * function setup() { 94901 * createCanvas(100, 100, WEBGL); 94902 * describe('a rotating white torus'); 94903 * } 94904 * 94905 * function draw() { 94906 * background(205, 102, 94); 94907 * rotateX(frameCount * 0.01); 94908 * rotateY(frameCount * 0.01); 94909 * torus(30, 15); 94910 * } 94911 * </code> 94912 * </div> 94913 * 94914 * @example 94915 * <div> 94916 * <code> 94917 * // slide to see how detailX works 94918 * let detailX; 94919 * function setup() { 94920 * createCanvas(100, 100, WEBGL); 94921 * detailX = createSlider(3, 24, 3); 94922 * detailX.position(10, height + 5); 94923 * detailX.style('width', '80px'); 94924 * describe( 94925 * 'a rotating white torus with limited X detail, with a slider that adjusts detailX' 94926 * ); 94927 * } 94928 * 94929 * function draw() { 94930 * background(205, 102, 94); 94931 * rotateY(millis() / 1000); 94932 * torus(30, 15, detailX.value(), 12); 94933 * } 94934 * </code> 94935 * </div> 94936 * 94937 * @example 94938 * <div> 94939 * <code> 94940 * // slide to see how detailY works 94941 * let detailY; 94942 * function setup() { 94943 * createCanvas(100, 100, WEBGL); 94944 * detailY = createSlider(3, 16, 3); 94945 * detailY.position(10, height + 5); 94946 * detailY.style('width', '80px'); 94947 * describe( 94948 * 'a rotating white torus with limited Y detail, with a slider that adjusts detailY' 94949 * ); 94950 * } 94951 * 94952 * function draw() { 94953 * background(205, 102, 94); 94954 * rotateY(millis() / 1000); 94955 * torus(30, 15, 16, detailY.value()); 94956 * } 94957 * </code> 94958 * </div> 94959 */ 94960 _main.default.prototype.torus = function (radius, tubeRadius, detailX, detailY) { 94961 this._assert3d('torus'); 94962 _main.default._validateParameters('torus', arguments); 94963 if (typeof radius === 'undefined') { 94964 radius = 50; 94965 } else if (!radius) { 94966 return; // nothing to draw 94967 } 94968 if (typeof tubeRadius === 'undefined') { 94969 tubeRadius = 10; 94970 } else if (!tubeRadius) { 94971 return; // nothing to draw 94972 } 94973 if (typeof detailX === 'undefined') { 94974 detailX = 24; 94975 } 94976 if (typeof detailY === 'undefined') { 94977 detailY = 16; 94978 } 94979 var tubeRatio = (tubeRadius / radius).toPrecision(4); 94980 var gId = 'torus|'.concat(tubeRatio, '|').concat(detailX, '|').concat(detailY); 94981 if (!this._renderer.geometryInHash(gId)) { 94982 var _torus = function _torus() { 94983 for (var i = 0; i <= this.detailY; i++) { 94984 var v = i / this.detailY; 94985 var phi = 2 * Math.PI * v; 94986 var cosPhi = Math.cos(phi);
94987 var sinPhi = Math.sin(phi); 94988 var r = 1 + tubeRatio * cosPhi; 94989 for (var j = 0; j <= this.detailX; j++) { 94990 var u = j / this.detailX; 94991 var theta = 2 * Math.PI * u; 94992 var cosTheta = Math.cos(theta); 94993 var sinTheta = Math.sin(theta); 94994 var p = new _main.default.Vector(r * cosTheta, r * sinTheta, tubeRatio * sinPhi); 94995 var n = new _main.default.Vector(cosPhi * cosTheta, cosPhi * sinTheta, sinPhi); 94996 this.vertices.push(p); 94997 this.vertexNormals.push(n); 94998 this.uvs.push(u, v); 94999 } 95000 } 95001 }; 95002 var torusGeom = new _main.default.Geometry(detailX, detailY, _torus); 95003 torusGeom.computeFaces(); 95004 if (detailX <= 24 && detailY <= 16) { 95005 torusGeom._makeTriangleEdges()._edgesToVertices(); 95006 } else if (this._renderer._doStroke) { 95007 console.log('Cannot draw strokes on torus object with more' + ' than 24 detailX or 16 detailY'); 95008 } 95009 this._renderer.createBuffers(gId, torusGeom); 95010 } 95011 this._renderer.drawBuffersScaled(gId, radius, radius, radius); 95012 return this; 95013 }; /////////////////////// 95014 /// 2D primitives
95015 ///////////////////////// 95016 /** 95017 * Draws a point, a coordinate in space at the dimension of one pixel, 95018 * given x, y and z coordinates. The color of the point is determined 95019 * by the current stroke, while the point size is determined by current 95020 * stroke weight. 95021 * @private 95022 * @param {Number} x x-coordinate of point 95023 * @param {Number} y y-coordinate of point 95024 * @param {Number} z z-coordinate of point 95025 * @chainable 95026 * @example 95027 * <div> 95028 * <code> 95029 * function setup() { 95030 * createCanvas(100, 100, WEBGL); 95031 * } 95032 * 95033 * function draw() { 95034 * background(50); 95035 * stroke(255); 95036 * strokeWeight(4); 95037 * point(25, 0); 95038 * strokeWeight(3); 95039 * point(-25, 0); 95040 * strokeWeight(2); 95041 * point(0, 25); 95042 * strokeWeight(1); 95043 * point(0, -25); 95044 * } 95045 * </code> 95046 * </div> 95047 */ 95048 _main.default.RendererGL.prototype.point = function (x, y, z) { 95049 if (typeof z === 'undefined') { 95050 z = 0; 95051 } 95052 var _vertex = [ 95053 ]; 95054 _vertex.push(new _main.default.Vector(x, y, z)); 95055 this._drawPoints(_vertex, this.immediateMode.buffers.point); 95056 return this; 95057 }; 95058 _main.default.RendererGL.prototype.triangle = function (args) { 95059 var x1 = args[0], 95060 y1 = args[1]; 95061 var x2 = args[2], 95062 y2 = args[3]; 95063 var x3 = args[4], 95064 y3 = args[5]; 95065 var gId = 'tri'; 95066 if (!this.geometryInHash(gId)) { 95067 var _triangle = function _triangle() { 95068 var vertices = [ 95069 ]; 95070 vertices.push(new _main.default.Vector(0, 0, 0)); 95071 vertices.push(new _main.default.Vector(1, 0, 0)); 95072 vertices.push(new _main.default.Vector(0, 1, 0)); 95073 this.strokeIndices = [ 95074 [0, 95075 1], 95076 [ 95077 1, 95078 2 95079 ], 95080 [ 95081 2, 95082 0 95083 ] 95084 ]; 95085 this.vertices = vertices; 95086 this.faces = [ 95087 [0, 95088 1, 95089 2] 95090 ]; 95091 this.uvs = [ 95092 0, 95093 0, 95094 1, 95095 0, 95096 1, 95097 1 95098 ]; 95099 }; 95100 var triGeom = new _main.default.Geometry(1, 1, _triangle); 95101 triGeom._makeTriangleEdges()._edgesToVertices(); 95102 triGeom.computeNormals(); 95103 this.createBuffers(gId, triGeom); 95104 } // only one triangle is cached, one point is at the origin, and the 95105 // two adjacent sides are tne unit vectors along the X & Y axes. 95106 // 95107 // this matrix multiplication transforms those two unit vectors 95108 // onto the required vector prior to rendering, and moves the 95109 // origin appropriately. 95110 95111 var uMVMatrix = this.uMVMatrix.copy(); 95112 try { 95113 var mult = new _main.default.Matrix([x2 - x1, 95114 y2 - y1, 95115 0, 95116 0, // the resulting unit X-axis 95117 x3 - x1, 95118 y3 - y1, 95119 0, 95120 0, // the resulting unit Y-axis 95121 0, 95122 0, 95123 1, 95124 0, // the resulting unit Z-axis (unchanged) 95125 x1, 95126 y1, 95127 0, 95128 1 // the resulting origin 95129 ]).mult(this.uMVMatrix); 95130 this.uMVMatrix = mult; 95131 this.drawBuffers(gId); 95132 } finally { 95133 this.uMVMatrix = uMVMatrix; 95134 } 95135 return this; 95136 }; 95137 _main.default.RendererGL.prototype.ellipse = function (args) { 95138 this.arc(args[0], args[1], args[2], args[3], 0, constants.TWO_PI, constants.OPEN, args[4]); 95139 }; 95140 _main.default.RendererGL.prototype.arc = function (args) { 95141 var x = arguments[0]; 95142 var y = arguments[1]; 95143 var width = arguments[2]; 95144 var height = arguments[3]; 95145 var start = arguments[4]; 95146 var stop = arguments[5]; 95147 var mode = arguments[6]; 95148 var detail = arguments[7] || 25; 95149 var shape; 95150 var gId; // check if it is an ellipse or an arc 95151 if (Math.abs(stop - start) >= constants.TWO_PI) { 95152 shape = 'ellipse'; 95153 gId = ''.concat(shape, '|').concat(detail, '|'); 95154 } else { 95155 shape = 'arc'; 95156 gId = ''.concat(shape, '|').concat(start, '|').concat(stop, '|').concat(mode, '|').concat(detail, '|'); 95157 } 95158 if (!this.geometryInHash(gId)) { 95159 var _arc = function _arc() { 95160 this.strokeIndices = [ 95161 ]; // if the start and stop angles are not the same, push vertices to the array 95162 if (start.toFixed(10) !== stop.toFixed(10)) { 95163 // if the mode specified is PIE or null, push the mid point of the arc in vertices 95164 if (mode === constants.PIE || typeof mode === 'undefined') { 95165 this.vertices.push(new _main.default.Vector(0.5, 0.5, 0)); 95166 this.uvs.push([0.5, 95167 0.5]); 95168 } // vertices for the perimeter of the circle 95169 95170 for (var i = 0; i <= detail; i++) { 95171 var u = i / detail; 95172 var theta = (stop - start) * u + start;
95173 var _x = 0.5 + Math.cos(theta) / 2; 95174 var _y = 0.5 + Math.sin(theta) / 2; 95175 this.vertices.push(new _main.default.Vector(_x, _y, 0)); 95176 this.uvs.push([_x, 95177 _y]); 95178 if (i < detail - 1) { 95179 this.faces.push([0, 95180 i + 1, 95181 i + 2]); 95182 this.strokeIndices.push([i + 1, 95183 i + 2]); 95184 } 95185 } // check the mode specified in order to push vertices and faces, different for each mode 95186 95187 switch (mode) { 95188 case constants.PIE: 95189 this.faces.push([0, 95190 this.vertices.length - 2, 95191 this.vertices.length - 1]); 95192 this.strokeIndices.push([0, 95193 1]); 95194 this.strokeIndices.push([this.vertices.length - 2, 95195 this.vertices.length - 1]); 95196 this.strokeIndices.push([0, 95197 this.vertices.length - 1]); 95198 break; 95199 case constants.CHORD: 95200 this.strokeIndices.push([0, 95201 1]); 95202 this.strokeIndices.push([0, 95203 this.vertices.length - 1]); 95204 break; 95205 case constants.OPEN: 95206 this.strokeIndices.push([0, 95207 1]); 95208 break; 95209 default: 95210 this.faces.push([0, 95211 this.vertices.length - 2, 95212 this.vertices.length - 1]); 95213 this.strokeIndices.push([this.vertices.length - 2, 95214 this.vertices.length - 1]); 95215 } 95216 } 95217 }; 95218 var arcGeom = new _main.default.Geometry(detail, 1, _arc); 95219 arcGeom.computeNormals(); 95220 if (detail <= 50) { 95221 arcGeom._makeTriangleEdges()._edgesToVertices(arcGeom); 95222 } else if (this._doStroke) { 95223 console.log('Cannot apply a stroke to an '.concat(shape, ' with more than 50 detail')); 95224 } 95225 this.createBuffers(gId, arcGeom); 95226 } 95227 var uMVMatrix = this.uMVMatrix.copy(); 95228 try { 95229 this.uMVMatrix.translate([x, 95230 y, 95231 0]); 95232 this.uMVMatrix.scale(width, height, 1); 95233 this.drawBuffers(gId); 95234 } finally { 95235 this.uMVMatrix = uMVMatrix; 95236 } 95237 return this; 95238 }; 95239 _main.default.RendererGL.prototype.rect = function (args) { 95240 var x = args[0]; 95241 var y = args[1]; 95242 var width = args[2]; 95243 var height = args[3]; 95244 if (typeof args[4] === 'undefined') { 95245 // Use the retained mode for drawing rectangle, 95246 // if args for rounding rectangle is not provided by user. 95247 var perPixelLighting = this._pInst._glAttributes.perPixelLighting; 95248 var detailX = args[4] || (perPixelLighting ? 1 : 24); 95249 var detailY = args[5] || (perPixelLighting ? 1 : 16); 95250 var gId = 'rect|'.concat(detailX, '|').concat(detailY); 95251 if (!this.geometryInHash(gId)) { 95252 var _rect = function _rect() { 95253 for (var i = 0; i <= this.detailY; i++) { 95254 var v = i / this.detailY; 95255 for (var j = 0; j <= this.detailX; j++) { 95256 var u = j / this.detailX; 95257 var p = new _main.default.Vector(u, v, 0); 95258 this.vertices.push(p); 95259 this.uvs.push(u, v); 95260 } 95261 } // using stroke indices to avoid stroke over face(s) of rectangle 95262 95263 if (detailX > 0 && detailY > 0) { 95264 this.strokeIndices = [ 95265 [0, 95266 detailX], 95267 [ 95268 detailX, 95269 (detailX + 1) * (detailY + 1) - 1 95270 ], 95271 [ 95272 (detailX + 1) * (detailY + 1) - 1, 95273 (detailX + 1) * detailY 95274 ], 95275 [ 95276 (detailX + 1) * detailY, 95277 0 95278 ] 95279 ]; 95280 } 95281 }; 95282 var rectGeom = new _main.default.Geometry(detailX, detailY, _rect); 95283 rectGeom.computeFaces().computeNormals()._makeTriangleEdges()._edgesToVertices(); 95284 this.createBuffers(gId, rectGeom); 95285 } // only a single rectangle (of a given detail) is cached: a square with 95286 // opposite corners at (0,0) & (1,1). 95287 // 95288 // before rendering, this square is scaled & moved to the required location. 95289 95290 var uMVMatrix = this.uMVMatrix.copy(); 95291 try { 95292 this.uMVMatrix.translate([x,
95293 y, 95294 0]); 95295 this.uMVMatrix.scale(width, height, 1); 95296 this.drawBuffers(gId); 95297 } finally { 95298 this.uMVMatrix = uMVMatrix; 95299 } 95300 } else { 95301 // Use Immediate mode to round the rectangle corner, 95302 // if args for rounding corners is provided by user 95303 var tl = args[4]; 95304 var tr = typeof args[5] === 'undefined' ? tl : args[5]; 95305 var br = typeof args[6] === 'undefined' ? tr : args[6]; 95306 var bl = typeof args[7] === 'undefined' ? br : args[7]; 95307 var a = x; 95308 var b = y; 95309 var c = width; 95310 var d = height; 95311 c += a; 95312 d += b; 95313 if (a > c) { 95314 var temp = a; 95315 a = c; 95316 c = temp; 95317 } 95318 if (b > d) { 95319 var _temp = b; 95320 b = d; 95321 d = _temp; 95322 } 95323 var maxRounding = Math.min((c - a) / 2, (d - b) / 2); 95324 if (tl > maxRounding) tl = maxRounding; 95325 if (tr > maxRounding) tr = maxRounding; 95326 if (br > maxRounding) br = maxRounding; 95327 if (bl > maxRounding) bl = maxRounding; 95328 var x1 = a; 95329 var y1 = b; 95330 var x2 = c; 95331 var y2 = d; 95332 this.beginShape(); 95333 if (tr !== 0) { 95334 this.vertex(x2 - tr, y1); 95335 this.quadraticVertex(x2, y1, x2, y1 + tr); 95336 } else { 95337 this.vertex(x2, y1); 95338 } 95339 if (br !== 0) { 95340 this.vertex(x2, y2 - br); 95341 this.quadraticVertex(x2, y2, x2 - br, y2); 95342 } else { 95343 this.vertex(x2, y2); 95344 } 95345 if (bl !== 0) { 95346 this.vertex(x1 + bl, y2); 95347 this.quadraticVertex(x1, y2, x1, y2 - bl); 95348 } else { 95349 this.vertex(x1, y2); 95350 } 95351 if (tl !== 0) { 95352 this.vertex(x1, y1 + tl); 95353 this.quadraticVertex(x1, y1, x1 + tl, y1); 95354 } else { 95355 this.vertex(x1, y1); 95356 } 95357 this.immediateMode.geometry.uvs.length = 0; 95358 var _iteratorNormalCompletion = true; 95359 var _didIteratorError = false; 95360 var _iteratorError = undefined; 95361 try { 95362 for (var _iterator = this.immediateMode.geometry.vertices[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 95363 var vert = _step.value; 95364 var u = (vert.x - x1) / width; 95365 var v = (vert.y - y1) / height; 95366 this.immediateMode.geometry.uvs.push(u, v); 95367 } 95368 } catch (err) { 95369 _didIteratorError = true; 95370 _iteratorError = err; 95371 } finally { 95372 try { 95373 if (!_iteratorNormalCompletion && _iterator.return != null) { 95374 _iterator.return(); 95375 } 95376 } finally { 95377 if (_didIteratorError) { 95378 throw _iteratorError; 95379 } 95380 } 95381 } 95382 this.endShape(constants.CLOSE); 95383 } 95384 return this; 95385 }; 95386 /* eslint-disable max-len */ 95387 _main.default.RendererGL.prototype.quad = function (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, detailX, detailY) { 95388 /* eslint-enable max-len */ 95389 if (typeof detailX === 'undefined') { 95390 detailX = 2; 95391 } 95392 if (typeof detailY === 'undefined') { 95393 detailY = 2; 95394 } 95395 var gId = 'quad|'.concat(x1, '|').concat(y1, '|').concat(z1, '|').concat(x2, '|').concat(y2, '|').concat(z2, '|').concat(x3, '|').concat(y3, '|').concat(z3, '|').concat(x4, '|').concat(y4, '|').concat(z4, '|').concat(detailX, '|').concat(detailY); 95396 if (!this.geometryInHash(gId)) { 95397 var quadGeom = new _main.default.Geometry(detailX, detailY, function () { 95398 //algorithm adapted from c++ to js 95399 //https://stackoverflow.com/questions/16989181/whats-the-correct-way-to-draw-a-distorted-plane-in-opengl/16993202#16993202 95400 var xRes = 1 / (this.detailX - 1); 95401 var yRes = 1 / (this.detailY - 1); 95402 for (var y = 0; y < this.detailY; y++) { 95403 for (var x = 0; x < this.detailX; x++) { 95404 var pctx = x * xRes; 95405 var pcty = y * yRes;
95406 var linePt0x = (1 - pcty) * x1 + pcty * x4; 95407 var linePt0y = (1 - pcty) * y1 + pcty * y4; 95408 var linePt0z = (1 - pcty) * z1 + pcty * z4; 95409 var linePt1x = (1 - pcty) * x2 + pcty * x3; 95410 var linePt1y = (1 - pcty) * y2 + pcty * y3; 95411 var linePt1z = (1 - pcty) * z2 + pcty * z3; 95412 var ptx = (1 - pctx) * linePt0x + pctx * linePt1x; 95413 var pty = (1 - pctx) * linePt0y + pctx * linePt1y; 95414 var ptz = (1 - pctx) * linePt0z + pctx * linePt1z; 95415 this.vertices.push(new _main.default.Vector(ptx, pty, ptz)); 95416 this.uvs.push([pctx, 95417 pcty]); 95418 } 95419 } 95420 }); 95421 quadGeom.faces = [ 95422 ]; 95423 for (var y = 0; y < detailY - 1; y++) { 95424 for (var x = 0; x < detailX - 1; x++) { 95425 var pt0 = x + y * detailX; 95426 var pt1 = x + 1 + y * detailX; 95427 var pt2 = x + 1 + (y + 1) * detailX; 95428 var pt3 = x + (y + 1) * detailX; 95429 quadGeom.faces.push([pt0, 95430 pt1, 95431 pt2]); 95432 quadGeom.faces.push([pt0, 95433 pt2, 95434 pt3]); 95435 } 95436 } 95437 quadGeom.computeNormals()._makeTriangleEdges()._edgesToVertices(); 95438 this.createBuffers(gId, quadGeom); 95439 } 95440 this.drawBuffers(gId); 95441 return this; 95442 }; //this implementation of bezier curve 95443 //is based on Bernstein polynomial 95444 // pretier-ignore 95445 _main.default.RendererGL.prototype.bezier = function (x1, y1, z1, // x2 95446 x2, // y2 95447 y2, // x3 95448 z2, // y3 95449 x3, // x4 95450 y3, // y4 95451 z3, x4, y4, z4) { 95452 if (arguments.length === 8) { 95453 y4 = y3; 95454 x4 = x3; 95455 y3 = z2; 95456 x3 = y2; 95457 y2 = x2; 95458 x2 = z1; 95459 z1 = z2 = z3 = z4 = 0; 95460 } 95461 var bezierDetail = this._pInst._bezierDetail || 20; //value of Bezier detail 95462 this.beginShape(); 95463 for (var i = 0; i <= bezierDetail; i++) { 95464 var c1 = Math.pow(1 - i / bezierDetail, 3); 95465 var c2 = 3 * (i / bezierDetail) * Math.pow(1 - i / bezierDetail, 2); 95466 var c3 = 3 * Math.pow(i / bezierDetail, 2) * (1 - i / bezierDetail); 95467 var c4 = Math.pow(i / bezierDetail, 3); 95468 this.vertex(x1 * c1 + x2 * c2 + x3 * c3 + x4 * c4, y1 * c1 + y2 * c2 + y3 * c3 + y4 * c4, z1 * c1 + z2 * c2 + z3 * c3 + z4 * c4); 95469 } 95470 this.endShape(); 95471 return this; 95472 }; // pretier-ignore 95473 _main.default.RendererGL.prototype.curve = function (x1, y1, z1, // x2 95474 x2, // y2 95475 y2, // x3 95476 z2, // y3 95477 x3, // x4 95478 y3, // y4 95479 z3, x4, y4, z4) { 95480 if (arguments.length === 8) { 95481 x4 = x3; 95482 y4 = y3; 95483 x3 = y2; 95484 y3 = x2; 95485 x2 = z1; 95486 y2 = x2; 95487 z1 = z2 = z3 = z4 = 0; 95488 } 95489 var curveDetail = this._pInst._curveDetail; 95490 this.beginShape(); 95491 for (var i = 0; i <= curveDetail; i++) { 95492 var c1 = Math.pow(i / curveDetail, 3) * 0.5; 95493 var c2 = Math.pow(i / curveDetail, 2) * 0.5; 95494 var c3 = i / curveDetail * 0.5; 95495 var c4 = 0.5; 95496 var vx = c1 * ( - x1 + 3 * x2 - 3 * x3 + x4) + c2 * (2 * x1 - 5 * x2 + 4 * x3 - x4) + c3 * ( - x1 + x3) + c4 * (2 * x2); 95497 var vy = c1 * ( - y1 + 3 * y2 - 3 * y3 + y4) + c2 * (2 * y1 - 5 * y2 + 4 * y3 - y4) + c3 * ( - y1 + y3) + c4 * (2 * y2); 95498 var vz = c1 * ( - z1 + 3 * z2 - 3 * z3 + z4) + c2 * (2 * z1 - 5 * z2 + 4 * z3 - z4) + c3 * ( - z1 + z3) + c4 * (2 * z2); 95499 this.vertex(vx, vy, vz); 95500 } 95501 this.endShape(); 95502 return this; 95503 }; 95504 /** 95505 * Draw a line given two points 95506 * @private 95507 * @param {Number} x0 x-coordinate of first vertex 95508 * @param {Number} y0 y-coordinate of first vertex 95509 * @param {Number} z0 z-coordinate of first vertex 95510 * @param {Number} x1 x-coordinate of second vertex 95511 * @param {Number} y1 y-coordinate of second vertex 95512 * @param {Number} z1 z-coordinate of second vertex 95513 * @chainable 95514 * @example 95515 * <div> 95516 * <code> 95517 * //draw a line 95518 * function setup() { 95519 * createCanvas(100, 100, WEBGL); 95520 * } 95521 * 95522 * function draw() { 95523 * background(200); 95524 * rotateX(frameCount * 0.01); 95525 * rotateY(frameCount * 0.01); 95526 * // Use fill instead of stroke to change the color of shape. 95527 * fill(255, 0, 0); 95528 * line(10, 10, 0, 60, 60, 20); 95529 * } 95530 * </code> 95531 * </div> 95532 */ 95533 _main.default.RendererGL.prototype.line = function () { 95534 if (arguments.length === 6) { 95535 this.beginShape(constants.LINES); 95536 this.vertex(arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1], arguments.length <= 2 ? undefined : arguments[2]); 95537 this.vertex(arguments.length <= 3 ? undefined : arguments[3], arguments.length <= 4 ? undefined : arguments[4], arguments.length <= 5 ? undefined : arguments[5]); 95538 this.endShape(); 95539 } else if (arguments.length === 4) { 95540 this.beginShape(constants.LINES); 95541 this.vertex(arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1], 0); 95542 this.vertex(arguments.length <= 2 ? undefined : arguments[2], arguments.length <= 3 ? undefined : arguments[3], 0); 95543 this.endShape(); 95544 } 95545 return this; 95546 }; 95547 _main.default.RendererGL.prototype.bezierVertex = function () { 95548 if (this.immediateMode._bezierVertex.length === 0) { 95549 throw Error('vertex() must be used once before calling bezierVertex()'); 95550 } else { 95551 var w_x = [ 95552 ];
95553 var w_y = [ 95554 ]; 95555 var w_z = [ 95556 ]; 95557 var t, 95558 _x, 95559 _y, 95560 _z, 95561 i, 95562 k, 95563 m; // variable i for bezierPoints, k for components, and m for anchor points. 95564 var argLength = arguments.length; 95565 t = 0; 95566 if (this._lookUpTableBezier.length === 0 || this._lutBezierDetail !== this._pInst._curveDetail) { 95567 this._lookUpTableBezier = [ 95568 ]; 95569 this._lutBezierDetail = this._pInst._curveDetail; 95570 var step = 1 / this._lutBezierDetail; 95571 var start = 0; 95572 var end = 1; 95573 var j = 0; 95574 while (start < 1) { 95575 t = parseFloat(start.toFixed(6)); 95576 this._lookUpTableBezier[j] = this._bezierCoefficients(t); 95577 if (end.toFixed(6) === step.toFixed(6)) { 95578 t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6)); 95579 ++j; 95580 this._lookUpTableBezier[j] = this._bezierCoefficients(t); 95581 break; 95582 } 95583 start += step; 95584 end -= step; 95585 ++j; 95586 } 95587 } 95588 var LUTLength = this._lookUpTableBezier.length; // fillColors[0]: start point color 95589 // fillColors[1],[2]: control point color 95590 // fillColors[3]: end point color 95591 var fillColors = [ 95592 ]; 95593 for (m = 0; m < 4; m++) { 95594 fillColors.push([]); 95595 } 95596 fillColors[0] = this.immediateMode.geometry.vertexColors.slice( - 4); 95597 fillColors[3] = this.curFillColor.slice(); // Do the same for strokeColor. 95598 var strokeColors = [ 95599 ]; 95600 for (m = 0; m < 4; m++) { 95601 strokeColors.push([]); 95602 } 95603 strokeColors[0] = this.immediateMode.geometry.vertexStrokeColors.slice( - 4); 95604 strokeColors[3] = this.curStrokeColor.slice(); 95605 if (argLength === 6) { 95606 this.isBezier = true; 95607 w_x = [ 95608 this.immediateMode._bezierVertex[0], 95609 arguments.length <= 0 ? undefined : arguments[0], 95610 arguments.length <= 2 ? undefined : arguments[2], 95611 arguments.length <= 4 ? undefined : arguments[4] 95612 ]; 95613 w_y = [ 95614 this.immediateMode._bezierVertex[1], 95615 arguments.length <= 1 ? undefined : arguments[1], 95616 arguments.length <= 3 ? undefined : arguments[3], 95617 arguments.length <= 5 ? undefined : arguments[5] 95618 ]; // The ratio of the distance between the start point, the two control- 95619 // points, and the end point determines the intermediate color. 95620 var d0 = Math.hypot(w_x[0] - w_x[1], w_y[0] - w_y[1]); 95621 var d1 = Math.hypot(w_x[1] - w_x[2], w_y[1] - w_y[2]); 95622 var d2 = Math.hypot(w_x[2] - w_x[3], w_y[2] - w_y[3]); 95623 var totalLength = d0 + d1 + d2; 95624 d0 /= totalLength; 95625 d2 /= totalLength; 95626 for (k = 0; k < 4; k++) { 95627 fillColors[1].push(fillColors[0][k] * (1 - d0) + fillColors[3][k] * d0); 95628 fillColors[2].push(fillColors[0][k] * d2 + fillColors[3][k] * (1 - d2)); 95629 strokeColors[1].push(strokeColors[0][k] * (1 - d0) + strokeColors[3][k] * d0); 95630 strokeColors[2].push(strokeColors[0][k] * d2 + strokeColors[3][k] * (1 - d2)); 95631 } 95632 for (i = 0; i < LUTLength; i++) { 95633 // Interpolate colors using control points 95634 this.curFillColor = [ 95635 0, 95636 0, 95637 0, 95638 0 95639 ]; 95640 this.curStrokeColor = [ 95641 0, 95642 0, 95643 0, 95644 0 95645 ]; 95646 _x = _y = 0; 95647 for (m = 0; m < 4; m++) { 95648 for (k = 0; k < 4; k++) { 95649 this.curFillColor[k] += this._lookUpTableBezier[i][m] * fillColors[m][k]; 95650 this.curStrokeColor[k] += this._lookUpTableBezier[i][m] * strokeColors[m][k]; 95651 } 95652 _x += w_x[m] * this._lookUpTableBezier[i][m]; 95653 _y += w_y[m] * this._lookUpTableBezier[i][m]; 95654 } 95655 this.vertex(_x, _y); 95656 } // so that we leave currentColor with the last value the user set it to 95657 95658 this.curFillColor = fillColors[3]; 95659 this.curStrokeColor = strokeColors[3]; 95660 this.immediateMode._bezierVertex[0] = arguments.length <= 4 ? undefined : arguments[4]; 95661 this.immediateMode._bezierVertex[1] = arguments.length <= 5 ? undefined : arguments[5]; 95662 } else if (argLength === 9) { 95663 this.isBezier = true; 95664 w_x = [ 95665 this.immediateMode._bezierVertex[0], 95666 arguments.length <= 0 ? undefined : arguments[0], 95667 arguments.length <= 3 ? undefined : arguments[3], 95668 arguments.length <= 6 ? undefined : arguments[6] 95669 ]; 95670 w_y = [ 95671 this.immediateMode._bezierVertex[1], 95672 arguments.length <= 1 ? undefined : arguments[1], 95673 arguments.length <= 4 ? undefined : arguments[4], 95674 arguments.length <= 7 ? undefined : arguments[7] 95675 ]; 95676 w_z = [ 95677 this.immediateMode._bezierVertex[2], 95678 arguments.length <= 2 ? undefined : arguments[2], 95679 arguments.length <= 5 ? undefined : arguments[5], 95680 arguments.length <= 8 ? undefined : arguments[8] 95681 ]; // The ratio of the distance between the start point, the two control- 95682 // points, and the end point determines the intermediate color. 95683 var _d = Math.hypot(w_x[0] - w_x[1], w_y[0] - w_y[1], w_z[0] - w_z[1]); 95684 var _d2 = Math.hypot(w_x[1] - w_x[2], w_y[1] - w_y[2], w_z[1] - w_z[2]); 95685 var _d3 = Math.hypot(w_x[2] - w_x[3], w_y[2] - w_y[3], w_z[2] - w_z[3]); 95686 var _totalLength = _d + _d2 + _d3; 95687 _d /= _totalLength; 95688 _d3 /= _totalLength; 95689 for (k = 0; k < 4; k++) { 95690 fillColors[1].push(fillColors[0][k] * (1 - _d) + fillColors[3][k] * _d); 95691 fillColors[2].push(fillColors[0][k] * _d3 + fillColors[3][k] * (1 - _d3)); 95692 strokeColors[1].push(strokeColors[0][k] * (1 - _d) + strokeColors[3][k] * _d); 95693 strokeColors[2].push(strokeColors[0][k] * _d3 + strokeColors[3][k] * (1 - _d3)); 95694 } 95695 for (i = 0; i < LUTLength; i++) { 95696 // Interpolate colors using control points 95697 this.curFillColor = [ 95698 0, 95699 0, 95700 0, 95701 0 95702 ]; 95703 this.curStrokeColor = [ 95704 0, 95705 0, 95706 0, 95707 0 95708 ]; 95709 _x = _y = _z = 0; 95710 for (m = 0; m < 4; m++) { 95711 for (k = 0; k < 4; k++) { 95712 this.curFillColor[k] += this._lookUpTableBezier[i][m] * fillColors[m][k]; 95713 this.curStrokeColor[k] += this._lookUpTableBezier[i][m] * strokeColors[m][k]; 95714 } 95715 _x += w_x[m] * this._lookUpTableBezier[i][m]; 95716 _y += w_y[m] * this._lookUpTableBezier[i][m]; 95717 _z += w_z[m] * this._lookUpTableBezier[i][m]; 95718 } 95719 this.vertex(_x, _y, _z); 95720 } // so that we leave currentColor with the last value the user set it to 95721 95722 this.curFillColor = fillColors[3]; 95723 this.curStrokeColor = strokeColors[3]; 95724 this.immediateMode._bezierVertex[0] = arguments.length <= 6 ? undefined : arguments[6]; 95725 this.immediateMode._bezierVertex[1] = arguments.length <= 7 ? undefined : arguments[7]; 95726 this.immediateMode._bezierVertex[2] = arguments.length <= 8 ? undefined : arguments[8]; 95727 } 95728 } 95729 }; 95730 _main.default.RendererGL.prototype.quadraticVertex = function () { 95731 if (this.immediateMode._quadraticVertex.length === 0) { 95732 throw Error('vertex() must be used once before calling quadraticVertex()'); 95733 } else { 95734 var w_x = [ 95735 ];
95736 var w_y = [ 95737 ]; 95738 var w_z = [ 95739 ]; 95740 var t, 95741 _x, 95742 _y, 95743 _z, 95744 i, 95745 k, 95746 m; // variable i for bezierPoints, k for components, and m for anchor points. 95747 var argLength = arguments.length; 95748 t = 0; 95749 if (this._lookUpTableQuadratic.length === 0 || this._lutQuadraticDetail !== this._pInst._curveDetail) { 95750 this._lookUpTableQuadratic = [ 95751 ]; 95752 this._lutQuadraticDetail = this._pInst._curveDetail; 95753 var step = 1 / this._lutQuadraticDetail; 95754 var start = 0; 95755 var end = 1; 95756 var j = 0; 95757 while (start < 1) { 95758 t = parseFloat(start.toFixed(6)); 95759 this._lookUpTableQuadratic[j] = this._quadraticCoefficients(t); 95760 if (end.toFixed(6) === step.toFixed(6)) { 95761 t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6)); 95762 ++j; 95763 this._lookUpTableQuadratic[j] = this._quadraticCoefficients(t); 95764 break; 95765 } 95766 start += step; 95767 end -= step; 95768 ++j; 95769 } 95770 } 95771 var LUTLength = this._lookUpTableQuadratic.length; // fillColors[0]: start point color 95772 // fillColors[1]: control point color 95773 // fillColors[2]: end point color 95774 var fillColors = [ 95775 ]; 95776 for (m = 0; m < 3; m++) { 95777 fillColors.push([]); 95778 } 95779 fillColors[0] = this.immediateMode.geometry.vertexColors.slice( - 4); 95780 fillColors[2] = this.curFillColor.slice(); // Do the same for strokeColor. 95781 var strokeColors = [ 95782 ]; 95783 for (m = 0; m < 3; m++) { 95784 strokeColors.push([]); 95785 } 95786 strokeColors[0] = this.immediateMode.geometry.vertexStrokeColors.slice( - 4); 95787 strokeColors[2] = this.curStrokeColor.slice(); 95788 if (argLength === 4) { 95789 this.isQuadratic = true; 95790 w_x = [ 95791 this.immediateMode._quadraticVertex[0], 95792 arguments.length <= 0 ? undefined : arguments[0], 95793 arguments.length <= 2 ? undefined : arguments[2] 95794 ]; 95795 w_y = [ 95796 this.immediateMode._quadraticVertex[1], 95797 arguments.length <= 1 ? undefined : arguments[1], 95798 arguments.length <= 3 ? undefined : arguments[3] 95799 ]; // The ratio of the distance between the start point, the control- 95800 // point, and the end point determines the intermediate color. 95801 var d0 = Math.hypot(w_x[0] - w_x[1], w_y[0] - w_y[1]); 95802 var d1 = Math.hypot(w_x[1] - w_x[2], w_y[1] - w_y[2]); 95803 var totalLength = d0 + d1; 95804 d0 /= totalLength; 95805 for (k = 0; k < 4; k++) { 95806 fillColors[1].push(fillColors[0][k] * (1 - d0) + fillColors[2][k] * d0); 95807 strokeColors[1].push(strokeColors[0][k] * (1 - d0) + strokeColors[2][k] * d0); 95808 } 95809 for (i = 0; i < LUTLength; i++) { 95810 // Interpolate colors using control points 95811 this.curFillColor = [ 95812 0, 95813 0, 95814 0, 95815 0 95816 ]; 95817 this.curStrokeColor = [ 95818 0, 95819 0, 95820 0, 95821 0 95822 ]; 95823 _x = _y = 0; 95824 for (m = 0; m < 3; m++) { 95825 for (k = 0; k < 4; k++) { 95826 this.curFillColor[k] += this._lookUpTableQuadratic[i][m] * fillColors[m][k]; 95827 this.curStrokeColor[k] += this._lookUpTableQuadratic[i][m] * strokeColors[m][k]; 95828 } 95829 _x += w_x[m] * this._lookUpTableQuadratic[i][m]; 95830 _y += w_y[m] * this._lookUpTableQuadratic[i][m]; 95831 } 95832 this.vertex(_x, _y); 95833 } // so that we leave currentColor with the last value the user set it to 95834 95835 this.curFillColor = fillColors[2]; 95836 this.curStrokeColor = strokeColors[2]; 95837 this.immediateMode._quadraticVertex[0] = arguments.length <= 2 ? undefined : arguments[2]; 95838 this.immediateMode._quadraticVertex[1] = arguments.length <= 3 ? undefined : arguments[3]; 95839 } else if (argLength === 6) { 95840 this.isQuadratic = true; 95841 w_x = [ 95842 this.immediateMode._quadraticVertex[0], 95843 arguments.length <= 0 ? undefined : arguments[0], 95844 arguments.length <= 3 ? undefined : arguments[3] 95845 ]; 95846 w_y = [ 95847 this.immediateMode._quadraticVertex[1], 95848 arguments.length <= 1 ? undefined : arguments[1], 95849 arguments.length <= 4 ? undefined : arguments[4] 95850 ]; 95851 w_z = [ 95852 this.immediateMode._quadraticVertex[2], 95853 arguments.length <= 2 ? undefined : arguments[2], 95854 arguments.length <= 5 ? undefined : arguments[5] 95855 ]; // The ratio of the distance between the start point, the control- 95856 // point, and the end point determines the intermediate color. 95857 var _d4 = Math.hypot(w_x[0] - w_x[1], w_y[0] - w_y[1], w_z[0] - w_z[1]); 95858 var _d5 = Math.hypot(w_x[1] - w_x[2], w_y[1] - w_y[2], w_z[1] - w_z[2]); 95859 var _totalLength2 = _d4 + _d5; 95860 _d4 /= _totalLength2; 95861 for (k = 0; k < 4; k++) { 95862 fillColors[1].push(fillColors[0][k] * (1 - _d4) + fillColors[2][k] * _d4); 95863 strokeColors[1].push(strokeColors[0][k] * (1 - _d4) + strokeColors[2][k] * _d4); 95864 } 95865 for (i = 0; i < LUTLength; i++) { 95866 // Interpolate colors using control points 95867 this.curFillColor = [ 95868 0, 95869 0, 95870 0, 95871 0 95872 ]; 95873 this.curStrokeColor = [ 95874 0, 95875 0, 95876 0, 95877 0 95878 ]; 95879 _x = _y = _z = 0; 95880 for (m = 0; m < 3; m++) { 95881 for (k = 0; k < 4; k++) { 95882 this.curFillColor[k] += this._lookUpTableQuadratic[i][m] * fillColors[m][k]; 95883 this.curStrokeColor[k] += this._lookUpTableQuadratic[i][m] * strokeColors[m][k]; 95884 } 95885 _x += w_x[m] * this._lookUpTableQuadratic[i][m]; 95886 _y += w_y[m] * this._lookUpTableQuadratic[i][m]; 95887 _z += w_z[m] * this._lookUpTableQuadratic[i][m]; 95888 } 95889 this.vertex(_x, _y, _z); 95890 } // so that we leave currentColor with the last value the user set it to 95891 95892 this.curFillColor = fillColors[2]; 95893 this.curStrokeColor = strokeColors[2]; 95894 this.immediateMode._quadraticVertex[0] = arguments.length <= 3 ? undefined : arguments[3]; 95895 this.immediateMode._quadraticVertex[1] = arguments.length <= 4 ? undefined : arguments[4]; 95896 this.immediateMode._quadraticVertex[2] = arguments.length <= 5 ? undefined : arguments[5]; 95897 } 95898 } 95899 }; 95900 _main.default.RendererGL.prototype.curveVertex = function () { 95901 var w_x = [ 95902 ];
95903 var w_y = [ 95904 ]; 95905 var w_z = [ 95906 ]; 95907 var t, 95908 _x, 95909 _y, 95910 _z, 95911 i; 95912 t = 0; 95913 var argLength = arguments.length; 95914 if (this._lookUpTableBezier.length === 0 || this._lutBezierDetail !== this._pInst._curveDetail) { 95915 this._lookUpTableBezier = [ 95916 ]; 95917 this._lutBezierDetail = this._pInst._curveDetail; 95918 var step = 1 / this._lutBezierDetail; 95919 var start = 0; 95920 var end = 1; 95921 var j = 0; 95922 while (start < 1) { 95923 t = parseFloat(start.toFixed(6)); 95924 this._lookUpTableBezier[j] = this._bezierCoefficients(t); 95925 if (end.toFixed(6) === step.toFixed(6)) { 95926 t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6)); 95927 ++j; 95928 this._lookUpTableBezier[j] = this._bezierCoefficients(t); 95929 break; 95930 } 95931 start += step; 95932 end -= step; 95933 ++j; 95934 } 95935 } 95936 var LUTLength = this._lookUpTableBezier.length; 95937 if (argLength === 2) { 95938 this.immediateMode._curveVertex.push(arguments.length <= 0 ? undefined : arguments[0]); 95939 this.immediateMode._curveVertex.push(arguments.length <= 1 ? undefined : arguments[1]); 95940 if (this.immediateMode._curveVertex.length === 8) { 95941 this.isCurve = true; 95942 w_x = this._bezierToCatmull([this.immediateMode._curveVertex[0], 95943 this.immediateMode._curveVertex[2], 95944 this.immediateMode._curveVertex[4], 95945 this.immediateMode._curveVertex[6]]); 95946 w_y = this._bezierToCatmull([this.immediateMode._curveVertex[1], 95947 this.immediateMode._curveVertex[3], 95948 this.immediateMode._curveVertex[5], 95949 this.immediateMode._curveVertex[7]]); 95950 for (i = 0; i < LUTLength; i++) { 95951 _x = w_x[0] * this._lookUpTableBezier[i][0] + w_x[1] * this._lookUpTableBezier[i][1] + w_x[2] * this._lookUpTableBezier[i][2] + w_x[3] * this._lookUpTableBezier[i][3]; 95952 _y = w_y[0] * this._lookUpTableBezier[i][0] + w_y[1] * this._lookUpTableBezier[i][1] + w_y[2] * this._lookUpTableBezier[i][2] + w_y[3] * this._lookUpTableBezier[i][3]; 95953 this.vertex(_x, _y); 95954 } 95955 for (i = 0; i < argLength; i++) { 95956 this.immediateMode._curveVertex.shift(); 95957 } 95958 } 95959 } else if (argLength === 3) { 95960 this.immediateMode._curveVertex.push(arguments.length <= 0 ? undefined : arguments[0]); 95961 this.immediateMode._curveVertex.push(arguments.length <= 1 ? undefined : arguments[1]); 95962 this.immediateMode._curveVertex.push(arguments.length <= 2 ? undefined : arguments[2]); 95963 if (this.immediateMode._curveVertex.length === 12) { 95964 this.isCurve = true; 95965 w_x = this._bezierToCatmull([this.immediateMode._curveVertex[0], 95966 this.immediateMode._curveVertex[3], 95967 this.immediateMode._curveVertex[6], 95968 this.immediateMode._curveVertex[9]]); 95969 w_y = this._bezierToCatmull([this.immediateMode._curveVertex[1], 95970 this.immediateMode._curveVertex[4], 95971 this.immediateMode._curveVertex[7], 95972 this.immediateMode._curveVertex[10]]); 95973 w_z = this._bezierToCatmull([this.immediateMode._curveVertex[2], 95974 this.immediateMode._curveVertex[5], 95975 this.immediateMode._curveVertex[8], 95976 this.immediateMode._curveVertex[11]]); 95977 for (i = 0; i < LUTLength; i++) { 95978 _x = w_x[0] * this._lookUpTableBezier[i][0] + w_x[1] * this._lookUpTableBezier[i][1] + w_x[2] * this._lookUpTableBezier[i][2] + w_x[3] * this._lookUpTableBezier[i][3]; 95979 _y = w_y[0] * this._lookUpTableBezier[i][0] + w_y[1] * this._lookUpTableBezier[i][1] + w_y[2] * this._lookUpTableBezier[i][2] + w_y[3] * this._lookUpTableBezier[i][3]; 95980 _z = w_z[0] * this._lookUpTableBezier[i][0] + w_z[1] * this._lookUpTableBezier[i][1] + w_z[2] * this._lookUpTableBezier[i][2] + w_z[3] * this._lookUpTableBezier[i][3]; 95981 this.vertex(_x, _y, _z); 95982 } 95983 for (i = 0; i < argLength; i++) { 95984 this.immediateMode._curveVertex.shift(); 95985 } 95986 } 95987 } 95988 }; 95989 _main.default.RendererGL.prototype.image = function (img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) { 95990 if (this._isErasing) { 95991 this.blendMode(this._cachedBlendMode); 95992 } 95993 this._pInst.push(); 95994 this._pInst.noLights(); 95995 this._pInst.noStroke(); 95996 this._pInst.texture(img); 95997 this._pInst.textureMode(constants.NORMAL); 95998 var u0 = 0; 95999 if (sx <= img.width) { 96000 u0 = sx / img.width; 96001 } 96002 var u1 = 1; 96003 if (sx + sWidth <= img.width) { 96004 u1 = (sx + sWidth) / img.width; 96005 } 96006 var v0 = 0; 96007 if (sy <= img.height) { 96008 v0 = sy / img.height; 96009 } 96010 var v1 = 1; 96011 if (sy + sHeight <= img.height) { 96012 v1 = (sy + sHeight) / img.height; 96013 } 96014 this.beginShape(); 96015 this.vertex(dx, dy, 0, u0, v0); 96016 this.vertex(dx + dWidth, dy, 0, u1, v0);
96017 this.vertex(dx + dWidth, dy + dHeight, 0, u1, v1); 96018 this.vertex(dx, dy + dHeight, 0, u0, v1); 96019 this.endShape(constants.CLOSE); 96020 this._pInst.pop(); 96021 if (this._isErasing) { 96022 this.blendMode(constants.REMOVE); 96023 } 96024 }; 96025 var _default = _main.default; 96026 exports.default = _default; 96027 }, 96028 { 96029 '../core/constants': 278, 96030 '../core/main': 290, 96031 './p5.Geometry': 339, 96032 'core-js/modules/es.array.concat': 167, 96033 'core-js/modules/es.array.iterator': 176, 96034 'core-js/modules/es.array.slice': 180, 96035 'core-js/modules/es.math.hypot': 185, 96036 'core-js/modules/es.number.to-fixed': 189, 96037 'core-js/modules/es.object.get-own-property-descriptor': 191, 96038 'core-js/modules/es.object.to-string': 195, 96039 'core-js/modules/es.string.iterator': 204, 96040 'core-js/modules/es.symbol': 214, 96041 'core-js/modules/es.symbol.description': 212, 96042 'core-js/modules/es.symbol.iterator': 213, 96043 'core-js/modules/es.weak-map': 246, 96044 'core-js/modules/web.dom-collections.iterator': 248 96045 } 96046 ], 96047 334: [ 96048 function (_dereq_, module, exports) { 96049 'use strict'; 96050 _dereq_('core-js/modules/es.symbol'); 96051 _dereq_('core-js/modules/es.symbol.description'); 96052 _dereq_('core-js/modules/es.symbol.iterator'); 96053 _dereq_('core-js/modules/es.array.iterator'); 96054 _dereq_('core-js/modules/es.array.splice'); 96055 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 96056 _dereq_('core-js/modules/es.object.to-string'); 96057 _dereq_('core-js/modules/es.regexp.to-string'); 96058 _dereq_('core-js/modules/es.string.iterator'); 96059 _dereq_('core-js/modules/es.weak-map'); 96060 _dereq_('core-js/modules/web.dom-collections.iterator'); 96061 function _typeof2(obj) { 96062 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 96063 _typeof2 = function _typeof2(obj) { 96064 return typeof obj; 96065 }; 96066 } else { 96067 _typeof2 = function _typeof2(obj) { 96068 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 96069 }; 96070 } 96071 return _typeof2(obj); 96072 } 96073 function _typeof(obj) { 96074 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 96075 _typeof = function _typeof(obj) { 96076 return _typeof2(obj); 96077 }; 96078 } else { 96079 _typeof = function _typeof(obj) { 96080 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 96081 }; 96082 } 96083 return _typeof(obj); 96084 } 96085 _dereq_('core-js/modules/es.array.splice'); 96086 _dereq_('core-js/modules/es.object.to-string'); 96087 _dereq_('core-js/modules/es.regexp.to-string'); 96088 Object.defineProperty(exports, '__esModule', { 96089 value: true 96090 }); 96091 exports.default = void 0; 96092 var _main = _interopRequireDefault(_dereq_('../core/main')); 96093 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 96094 function _getRequireWildcardCache() { 96095 if (typeof WeakMap !== 'function') return null; 96096 var cache = new WeakMap(); 96097 _getRequireWildcardCache = function _getRequireWildcardCache() { 96098 return cache; 96099 }; 96100 return cache; 96101 } 96102 function _interopRequireWildcard(obj) { 96103 if (obj && obj.__esModule) { 96104 return obj; 96105 } 96106 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 96107 return { 96108 default: 96109 obj 96110 }; 96111 } 96112 var cache = _getRequireWildcardCache(); 96113 if (cache && cache.has(obj)) { 96114 return cache.get(obj); 96115 } 96116 var newObj = { 96117 }; 96118 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 96119 for (var key in obj) { 96120 if (Object.prototype.hasOwnProperty.call(obj, key)) { 96121 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 96122 if (desc && (desc.get || desc.set)) { 96123 Object.defineProperty(newObj, key, desc); 96124 } else { 96125 newObj[key] = obj[key]; 96126 } 96127 } 96128 } 96129 newObj.default = obj; 96130 if (cache) { 96131 cache.set(obj, newObj); 96132 } 96133 return newObj; 96134 } 96135 function _interopRequireDefault(obj) { 96136 return obj && obj.__esModule ? obj : { 96137 default: 96138 obj 96139 }; 96140 } /** 96141 * @module 3D 96142 * @submodule Interaction 96143 * @for p5 96144 * @requires core 96145 */ 96146 /** 96147 * Allows movement around a 3D sketch using a mouse or trackpad. Left-clicking 96148 * and dragging will rotate the camera position about the center of the sketch, 96149 * right-clicking and dragging will pan the camera position without rotation, 96150 * and using the mouse wheel (scrolling) will move the camera closer or further 96151 * from the center of the sketch. This function can be called with parameters 96152 * dictating sensitivity to mouse movement along the X and Y axes. Calling 96153 * this function without parameters is equivalent to calling orbitControl(1,1). 96154 * To reverse direction of movement in either axis, enter a negative number 96155 * for sensitivity. 96156 * @method orbitControl 96157 * @for p5 96158 * @param {Number} [sensitivityX] sensitivity to mouse movement along X axis 96159 * @param {Number} [sensitivityY] sensitivity to mouse movement along Y axis 96160 * @param {Number} [sensitivityZ] sensitivity to scroll movement along Z axis 96161 * @chainable 96162 * @example 96163 * <div> 96164 * <code> 96165 * function setup() { 96166 * createCanvas(100, 100, WEBGL); 96167 * normalMaterial(); 96168 * describe( 96169 * 'Camera orbits around a box when mouse is hold-clicked & then moved.' 96170 * ); 96171 * } 96172 * function draw() { 96173 * background(200); 96174 * orbitControl(); 96175 * rotateY(0.5); 96176 * box(30, 50); 96177 * } 96178 * </code> 96179 * </div> 96180 * 96181 * @alt 96182 * Camera orbits around a box when mouse is hold-clicked & then moved. 96183 */ 96184 // implementation based on three.js 'orbitControls': 96185 // https://github.com/mrdoob/three.js/blob/dev/examples/js/control
96185s/OrbitControls.js 96186 96187 _main.default.prototype.orbitControl = function (sensitivityX, sensitivityY, sensitivityZ) { 96188 this._assert3d('orbitControl'); 96189 _main.default._validateParameters('orbitControl', arguments); // If the mouse is not in bounds of the canvas, disable all behaviors: 96190 var mouseInCanvas = this.mouseX < this.width && this.mouseX > 0 && this.mouseY < this.height && this.mouseY > 0; 96191 if (!mouseInCanvas) return; 96192 var cam = this._renderer._curCamera; 96193 if (typeof sensitivityX === 'undefined') { 96194 sensitivityX = 1; 96195 } 96196 if (typeof sensitivityY === 'undefined') { 96197 sensitivityY = sensitivityX; 96198 } 96199 if (typeof sensitivityZ === 'undefined') { 96200 sensitivityZ = 0.5; 96201 } // default right-mouse and mouse-wheel behaviors (context menu and scrolling, 96202 // respectively) are disabled here to allow use of those events for panning and 96203 // zooming 96204 // disable context menu for canvas element and add 'contextMenuDisabled' 96205 // flag to p5 instance 96206 96207 if (this.contextMenuDisabled !== true) { 96208 this.canvas.oncontextmenu = function () { 96209 return false; 96210 }; 96211 this._setProperty('contextMenuDisabled', true); 96212 } // disable default scrolling behavior on the canvas element and add 96213 // 'wheelDefaultDisabled' flag to p5 instance 96214 96215 if (this.wheelDefaultDisabled !== true) { 96216 this.canvas.onwheel = function () { 96217 return false; 96218 }; 96219 this._setProperty('wheelDefaultDisabled', true); 96220 } 96221 var scaleFactor = this.height < this.width ? this.height : this.width; // ZOOM if there is a change in mouseWheelDelta 96222 if (this._mouseWheelDeltaY !== this._pmouseWheelDeltaY) { 96223 // zoom according to direction of mouseWheelDeltaY rather than value 96224 if (this._mouseWheelDeltaY > 0) { 96225 this._renderer._curCamera._orbit(0, 0, sensitivityZ * scaleFactor); 96226 } else { 96227 this._renderer._curCamera._orbit(0, 0, - sensitivityZ * scaleFactor); 96228 } 96229 } 96230 if (this.mouseIsPressed) { 96231 // ORBIT BEHAVIOR 96232 if (this.mouseButton === this.LEFT) { 96233 var deltaTheta = - sensitivityX * (this.mouseX - this.pmouseX) / scaleFactor; 96234 var deltaPhi = sensitivityY * (this.mouseY - this.pmouseY) / scaleFactor; 96235 this._renderer._curCamera._orbit(deltaTheta, deltaPhi, 0); 96236 } else if (this.mouseButton === this.RIGHT) { 96237 // PANNING BEHAVIOR along X/Z camera axes and restricted to X/Z plane 96238 // in world space 96239 var local = cam._getLocalAxes(); // normalize portions along X/Z axes 96240 var xmag = Math.sqrt(local.x[0] * local.x[0] + local.x[2] * local.x[2]); 96241 if (xmag !== 0) { 96242 local.x[0] /= xmag; 96243 local.x[2] /= xmag; 96244 } // normalize portions along X/Z axes 96245 96246 var ymag = Math.sqrt(local.y[0] * local.y[0] + local.y[2] * local.y[2]); 96247 if (ymag !== 0) { 96248 local.y[0] /= ymag; 96249 local.y[2] /= ymag; 96250 } // move along those vectors by amount controlled by mouseX, pmouseY 96251 96252 var dx = - 1 * sensitivityX * (this.mouseX - this.pmouseX); 96253 var dz = - 1 * sensitivityY * (this.mouseY - this.pmouseY); // restrict movement to XZ plane in world space 96254 cam.setPosition(cam.eyeX + dx * local.x[0] + dz * local.z[0], cam.eyeY, cam.eyeZ + dx * local.x[2] + dz * local.z[2]); 96255 } 96256 } 96257 return this; 96258 }; 96259 /** 96260 * debugMode() helps visualize 3D space by adding a grid to indicate where the 96261 * âgroundâ is in a sketch and an axes icon which indicates the +X, +Y, and +Z 96262 * directions. This function can be called without parameters to create a 96263 * default grid and axes icon, or it can be called according to the examples 96264 * above to customize the size and position of the grid and/or axes icon. The 96265 * grid is drawn using the most recently set stroke color and weight. To 96266 * specify these parameters, add a call to stroke() and strokeWeight(
96266) 96267 * just before the end of the draw() loop. 96268 * 96269 * By default, the grid will run through the origin (0,0,0) of the sketch 96270 * along the XZ plane 96271 * and the axes icon will be offset from the origin. Both the grid and axes 96272 * icon will be sized according to the current canvas size. Note that because the 96273 * grid runs parallel to the default camera view, it is often helpful to use 96274 * debugMode along with orbitControl to allow full view of the grid. 96275 * @method debugMode 96276 * @example 96277 * <div> 96278 * <code> 96279 * function setup() { 96280 * createCanvas(100, 100, WEBGL); 96281 * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); 96282 * normalMaterial(); 96283 * debugMode(); 96284 * describe( 96285 * 'a 3D box is centered on a grid in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z. the grid and icon disappear when the spacebar is pressed.' 96286 * ); 96287 * } 96288 * 96289 * function draw() { 96290 * background(200); 96291 * orbitControl(); 96292 * box(15, 30); 96293 * // Press the spacebar to turn debugMode off! 96294 * if (keyIsDown(32)) { 96295 * noDebugMode(); 96296 * } 96297 * } 96298 * </code> 96299 * </div> 96300 * @alt 96301 * a 3D box is centered on a grid in a 3D sketch. an icon 96302 * indicates the direction of each axis: a red line points +X, 96303 * a green line +Y, and a blue line +Z. the grid and icon disappear when the 96304 * spacebar is pressed. 96305 * 96306 * @example 96307 * <div> 96308 * <code> 96309 * function setup() { 96310 * createCanvas(100, 100, WEBGL); 96311 * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); 96312 * normalMaterial(); 96313 * debugMode(GRID); 96314 * describe('a 3D box is centered on a grid in a 3D sketch.'); 96315 * } 96316 * 96317 * function draw() { 96318 * background(200); 96319 * orbitControl(); 96320 * box(15, 30); 96321 * } 96322 * </code> 96323 * </div> 96324 * @alt 96325 * a 3D box is centered on a grid in a 3D sketch. 96326 * 96327 * @example 96328 * <div> 96329 * <code> 96330 * function setup() { 96331 * createCanvas(100, 100, WEBGL); 96332 * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); 96333 * normalMaterial(); 96334 * debugMode(AXES); 96335 * describe( 96336 * 'a 3D box is centered in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z.' 96337 * ); 96338 * } 96339 * 96340 * function draw() { 96341 * background(200); 96342 * orbitControl(); 96343 * box(15, 30); 96344 * } 96345 * </code> 96346 * </div> 96347 * @alt 96348 * a 3D box is centered in a 3D sketch. an icon 96349 * indicates the direction of each axis: a red line points +X, 96350 * a green line +Y, and a blue line +Z. 96351 * 96352 * @example 96353 * <div> 96354 * <code> 96355 * function setup() { 96356 * createCanvas(100, 100, WEBGL); 96357 * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); 96358 * normalMaterial(); 96359 * debugMode(GRID, 100, 10, 0, 0, 0); 96360 * describe('a 3D box is centered on a grid in a 3D sketch'); 96361 * } 96362 * 96363 * function draw() { 96364 * background(200); 96365 * orbitControl(); 96366 * box(15, 30); 96367 * } 96368 * </code> 96369 * </div> 96370 * @alt 96371 * a 3D box is centered on a grid in a 3D sketch 96372 * 96373 * @example 96374 * <div> 96375 * <code> 96376 * function setup() { 96377 * createCanvas(100, 100, WEBGL); 96378 * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); 96379 * normalMaterial(); 96380 * debugMode(100, 10, 0, 0, 0, 20, 0, -40, 0); 96381 * describe( 96382 * 'a 3D box is centered on a grid in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z.' 96383 * ); 96384 * } 96385 * 96386 * function draw() { 96387 * noStroke(); 96388 * background(200); 96389 * orbitControl(); 96390 * box(15, 30); 96391 * // set the stroke color and weight for the grid! 96392 * stroke(255, 0, 150); 96393 * strokeWeight(0.8); 96394 * } 96395 * </code> 96396 * </div> 96397 * @alt 96398 * a 3D box is centered on a grid in a 3D sketch. an icon 96399 * indicates the direction of each axis: a red line points +X, 96400 * a green line +Y, and a blue line +Z. 96401 */ 96402 /** 96403 * @method debugMode 96404 * @param {Constant} mode either GRID or AXES 96405 */ 96406 /** 96407 * @method debugMode 96408 * @param {Constant} mode 96409 * @param {Number} [gridSize] size of one side of the grid 96410 * @param {Number} [gridDivisions] number of divisions in the grid 96411 * @param {Number} [xOff] X axis offset from origin (0,0,0) 96412 * @param {Number} [yOff] Y axis offset from origin (0,0,0) 96413 * @param {Number} [zOff] Z axis offset from origin (0,0,0) 96414 */ 96415 /** 96416 * @method debugMode 96417 * @param {Constant} mode 96418 * @param {Number} [axesSize] size of axes icon 96419 * @param {Number} [xOff] 96420 * @param {Number} [yOff] 96421 * @param {Number} [zOff] 96422 */ 96423 /** 96424 * @method debugMode 96425 * @param {Number} [gridSize] 96426 * @param {Number} [gridDivisions] 96427 * @param {Number} [gridXOff] 96428 * @param {Number} [gridYOff] 96429 * @param {Number} [gridZOff] 96430 * @param {Number} [axesSize] 96431 * @param {Number} [axesXOff] 96432 * @param {Number} [axesYOff] 96433 * @param {Number} [axesZOff] 96434 */ 96435 _main.default.prototype.debugMode = function () { 96436 this._assert3d('debugMode'); 96437 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 96438 args[_key] = arguments[_key]; 96439 } 96440 _main.default._validateParameters('debugMode', args); // start by removing existing 'post' registered debug methods 96441 for (var i = this._registeredMethods.post.length - 1; i >= 0; i--) { 96442 // test for equality... 96443 if (this._registeredMethods.post[i].toString() === this._grid().toString() || this._registeredMethods.post[i].toString() === this._axesIcon().toString()) { 96444 this._registeredMethods.post.splice(i, 1); 96445 } 96446 } // then add new debugMode functions according to the argument list 96447 96448 if (args[0] === constants.GRID) { 96449 this.registerMethod('post', this._grid.call(this, args[1], args[2], args[3], args[4], args[5])); 96450 } else if (args[0] === constants.AXES) { 96451 this.registerMethod('post', this._axesIcon.call(this, args[1], args[2], args[3], args[4])); 96452 } else { 96453 this.registerMethod('post', this._grid.call(this, args[0], args[1], args[2], args[3], args[4])); 96454 this.registerMethod('post', this._axesIcon.call(this, args[5], args[6], args[7], args[8])); 96455 } 96456 }; 96457 /** 96458 * Turns off debugMode() in a 3D sketch. 96459 * @method noDebugMode 96460 * @example 96461 * <div> 96462 * <code> 96463 * function setup() { 96464 * createCanvas(100, 100, WEBGL); 96465 * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); 96466 * normalMaterial(); 96467 * debugMode(); 96468 * describe( 96469 * 'a 3D box is centered on a grid in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z. the grid and icon disappear when the spacebar is pressed.' 96470 * ); 96471 * } 96472 * 96473 * function draw() { 96474 * background(200); 96475 * orbitControl(); 96476 * box(15, 30); 96477 * // Press the spacebar to turn debugMode off! 96478 * if (keyIsDown(32)) { 96479 * noDebugMode(); 96480 * } 96481 * } 96482 * </code> 96483 * </div> 96484 * @alt 96485 * a 3D box is centered on a grid in a 3D sketch. an icon 96486 * indicates the direction of each axis: a red line points +X, 96487 * a green line +Y, and a blue line +Z. the grid and icon disappear when the 96488 * spacebar is pressed. 96489 */ 96490 _main.default.prototype.noDebugMode = function () { 96491 this._assert3d('noDebugMode'); // start by removing existing 'post' registered debug methods 96492 for (var i = this._registeredMethods.post.length - 1; i >= 0; i--) { 96493 // test for equality... 96494 if (this._registeredMethods.post[i].toString() === this._grid().toString() || this._registeredMethods.post[i].toString() === this._axesIcon().toString()) { 96495 this._registeredMethods.post.splice(i, 1); 96496 } 96497 } 96498 }; 96499 /** 96500 * For use with debugMode 96501 * @private 96502 * @method _grid 96503 * @param {Number}
96503 [size] size of grid sides 96504 * @param {Number} [div] number of grid divisions 96505 * @param {Number} [xOff] offset of grid center from origin in X axis 96506 * @param {Number} [yOff] offset of grid center from origin in Y axis 96507 * @param {Number} [zOff] offset of grid center from origin in Z axis 96508 */ 96509 _main.default.prototype._grid = function (size, numDivs, xOff, yOff, zOff) { 96510 if (typeof size === 'undefined') { 96511 size = this.width / 2; 96512 } 96513 if (typeof numDivs === 'undefined') { 96514 // ensure at least 2 divisions 96515 numDivs = Math.round(size / 30) < 4 ? 4 : Math.round(size / 30); 96516 } 96517 if (typeof xOff === 'undefined') { 96518 xOff = 0; 96519 } 96520 if (typeof yOff === 'undefined') { 96521 yOff = 0; 96522 } 96523 if (typeof zOff === 'undefined') { 96524 zOff = 0; 96525 } 96526 var spacing = size / numDivs; 96527 var halfSize = size / 2; 96528 return function () { 96529 this.push(); 96530 this.stroke(this._renderer.curStrokeColor[0] * 255, this._renderer.curStrokeColor[1] * 255, this._renderer.curStrokeColor[2] * 255); 96531 this._renderer.uMVMatrix.set(this._renderer._curCamera.cameraMatrix.mat4[0], this._renderer._curCamera.cameraMatrix.mat4[1], this._renderer._curCamera.cameraMatrix.mat4[2], this._renderer._curCamera.cameraMatrix.mat4[3], this._renderer._curCamera.cameraMatrix.mat4[4], this._renderer._curCamera.cameraMatrix.mat4[5], this._renderer._curCamera.cameraMatrix.mat4[6], this._renderer._curCamera.cameraMatrix.mat4[7], this._renderer._curCamera.cameraMatrix.mat4[8], this._renderer._curCamera.cameraMatrix.mat4[9], this._renderer._curCamera.cameraMatrix.mat4[10], this._renderer._curCamera.cameraMatrix.mat4[11], this._renderer._curCamera.cameraMatrix.mat4[12], this._renderer._curCamera.cameraMatrix.mat4[13], this._renderer._curCamera.cameraMatrix.mat4[14], this._renderer._curCamera.cameraMatrix.mat4[15]); // Lines along X axis 96532 for (var q = 0; q <= numDivs; q++) { 96533 this.beginShape(this.LINES); 96534 this.vertex( - halfSize + xOff, yOff, q * spacing - halfSize + zOff); 96535 this.vertex( + halfSize + xOff, yOff, q * spacing - halfSize + zOff); 96536 this.endShape(); 96537 } // Lines along Z axis 96538 96539 for (var i = 0; i <= numDivs; i++) { 96540 this.beginShape(this.LINES); 96541 this.vertex(i * spacing - halfSize + xOff, yOff, - halfSize + zOff); 96542 this.vertex(i * spacing - halfSize + xOff, yOff, + halfSize + zOff); 96543 this.endShape(); 96544 } 96545 this.pop(); 96546 }; 96547 }; 96548 /** 96549 * For use with debugMode 96550 * @private 96551 * @method _axesIcon 96552 * @param {Number} [size] size of axes icon lines 96553 * @param {Number} [xOff] offset of icon from origin in X axis 96554 * @param {Number} [yOff] offset of icon from origin in Y axis 96555 * @param {Number} [zOff] offset of icon from origin in Z axis 96556 */ 96557 _main.default.prototype._axesIcon = function (size, xOff, yOff, zOff) { 96558 if (typeof size === 'undefined') { 96559 size = this.width / 20 > 40 ? this.width / 20 : 40; 96560 } 96561 if (typeof xOff === 'undefined') { 96562 xOff = - this.width / 4; 96563 } 96564 if (typeof yOff === 'undefined') { 96565 yOff = xOff; 96566 } 96567 if (typeof zOff === 'undefined') { 96568 zOff = xOff; 96569 } 96570 return function () { 96571 this.push(); 96572 this._renderer.uMVMatrix.set(this._renderer._curCamera.cameraMatrix.mat4[0], this._renderer._curCamera.cameraMatrix.mat4[1], this._renderer._curCamera.cameraMatrix.mat4[2], this._renderer._curCamera.cameraMatrix.mat4[3], this._renderer._curCamera.cameraMatrix.mat4[4], this._renderer._curCamera.cameraMatrix.mat4[5], this._renderer._curCamera.cameraMatrix.mat4[6], this._renderer._curCamera.cameraMatrix.mat4[7], this._renderer._curCamera.cameraMatrix.mat4[8], this._renderer._curCamera.cameraMatrix.mat4[9], this._renderer._curCamera.cameraMatrix.mat4[10], this._renderer._curCamera.cameraMatrix.mat4[11], this._renderer._curCamera.cameraMatrix.mat4[12], this._renderer._curCamera.cameraMatrix.mat4[13], this._renderer._curCamera.cameraMatrix.mat4[14], this._renderer._curCamera.cameraMatrix.mat4[15]); // X axis 96573 this.strokeWeight(2); 96574 this.stroke(255, 0, 0); 96575 this.beginShape(this.LINES); 96576 this.vertex(xOff, yOff, zOff); 96577 this.vertex(xOff + size, yOff, zOff); 96578 this.endShape(); // Y axis 96579 this.stroke(0, 255, 0); 96580 this.beginShape(this.LINES); 96581 this.vertex(xOff, yOff, zOff); 96582 this.vertex(xOff, yOff + size, zOff); 96583 this.endShape(); // Z axis 96584 this.stroke(0, 0, 255); 96585 this.beginShape(this.LINES); 96586 this.vertex(xOff, yOff, zOff); 96587 this.vertex(xOff, yOff, zOff + size); 96588 this.endShape(); 96589 this.pop(); 96590 }; 96591 }; 96592 var _default = _main.default; 96593 exports.default = _default; 96594 }, 96595 { 96596 '../core/constants': 278, 96597 '../core/main': 290, 96598 'core-js/modules/es.array.iterator': 176, 96599 'core-js/modules/es.array.splice': 182, 96600 'core-js/modules/es.object.get-own-property-descriptor': 191, 96601 'core-js/modules/es.object.to-string': 195, 96602 'core-js/modules/es.regexp.to-string': 200, 96603 'core-js/modules/es.string.iterator': 204, 96604 'core-js/modules/es.symbol': 214, 96605 'core-js/modules/es.symbol.description': 212, 96606 'core-js/modules/es.symbol.iterator': 213, 96607 'core-js/modules/es.weak-map': 246, 96608 'core-js/modules/web.dom-collections.iterator': 248 96609 } 96610 ], 96611 335: [
96612 function (_dereq_, module, exports) { 96613 'use strict'; 96614 _dereq_('core-js/modules/es.symbol'); 96615 _dereq_('core-js/modules/es.symbol.description'); 96616 _dereq_('core-js/modules/es.symbol.iterator'); 96617 _dereq_('core-js/modules/es.array.iterator'); 96618 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 96619 _dereq_('core-js/modules/es.object.to-string'); 96620 _dereq_('core-js/modules/es.string.iterator'); 96621 _dereq_('core-js/modules/es.weak-map'); 96622 _dereq_('core-js/modules/web.dom-collections.iterator'); 96623 function _typeof2(obj) { 96624 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 96625 _typeof2 = function _typeof2(obj) { 96626 return typeof obj; 96627 }; 96628 } else { 96629 _typeof2 = function _typeof2(obj) { 96630 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 96631 }; 96632 } 96633 return _typeof2(obj); 96634 } 96635 function _typeof(obj) { 96636 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 96637 _typeof = function _typeof(obj) { 96638 return _typeof2(obj); 96639 }; 96640 } else { 96641 _typeof = function _typeof(obj) { 96642 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 96643 }; 96644 } 96645 return _typeof(obj); 96646 } 96647 Object.defineProperty(exports, '__esModule', { 96648 value: true 96649 }); 96650 exports.default = void 0; 96651 var _main = _interopRequireDefault(_dereq_('../core/main')); 96652 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 96653 function _getRequireWildcardCache() { 96654 if (typeof WeakMap !== 'function') return null; 96655 var cache = new WeakMap(); 96656 _getRequireWildcardCache = function _getRequireWildcardCache() { 96657 return cache; 96658 }; 96659 return cache; 96660 } 96661 function _interopRequireWildcard(obj) { 96662 if (obj && obj.__esModule) { 96663 return obj; 96664 } 96665 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 96666 return { 96667 default: 96668 obj 96669 }; 96670 } 96671 var cache = _getRequireWildcardCache(); 96672 if (cache && cache.has(obj)) { 96673 return cache.get(obj); 96674 } 96675 var newObj = { 96676 }; 96677 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 96678 for (var key in obj) { 96679 if (Object.prototype.hasOwnProperty.call(obj, key)) { 96680 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 96681 if (desc && (desc.get || desc.set)) { 96682 Object.defineProperty(newObj, key, desc); 96683 } else { 96684 newObj[key] = obj[key]; 96685 } 96686 } 96687 } 96688 newObj.default = obj; 96689 if (cache) { 96690 cache.set(obj, newObj); 96691 } 96692 return newObj; 96693 } 96694 function _interopRequireDefault(obj) { 96695 return obj && obj.__esModule ? obj : { 96696 default: 96697 obj 96698 }; 96699 } /** 96700 * @module 3D 96701 * @submodule Lights 96702 * @for p5 96703 * @requires core 96704 */ 96705 /** 96706 * Creates an ambient light with the given color. 96707 * 96708 * Ambient light does not come from a specific direction. 96709 * Objects are evenly lit from all sides. Ambient lights are 96710 * almost always used in combination with other types of lights. 96711 * 96712 * Note: lights need to be called (whether directly or indirectly) 96713 * within draw() to remain persistent in a looping program. 96714 * Placing them in setup() will cause them to only have an effect 96715 * the first time through the loop. 96716 * 96717 * @method ambientLight 96718 * @param {Number} v1 red or hue value relative to 96719 * the current color range 96720 * @param {Number} v2 green or saturation value 96721 * relative to the current color range 96722 * @param {Number} v3 blue or brightness value 96723 * relative to the current color range 96724 * @param {Number} [alpha] alpha value relative to current 96725 * color range (default is 0-255) 96726 * @chainable 96727 * 96728 * @example 96729 * <div> 96730 * <code> 96731 * function setup() { 96732 * createCanvas(100, 100, WEBGL); 96733 * noStroke(); 96734 * describe('sphere with coral color under black light'); 96735 * } 96736 * function draw() { 96737 * background(100); 96738 * ambientLight(0); // black light (no light) 96739 * ambientMaterial(255, 127, 80); // coral material 96740 * sphere(40); 96741 * } 96742 * </code> 96743 * </div> 96744 * @alt 96745 * sphere with coral color under black light 96746 * 96747 * @example 96748 * <div> 96749 * <code> 96750 * function setup() { 96751 * createCanvas(100, 100, WEBGL); 96752 * noStroke(); 96753 * describe('sphere with coral color under white light'); 96754 * } 96755 * function draw() { 96756 * background(100); 96757 * ambientLight(255); // white light 96758 * ambientMaterial(255, 127, 80); // coral material 96759 * sphere(40); 96760 * } 96761 * </code> 96762 * </div> 96763 * @alt 96764 * sphere with coral color under white light 96765 */ 96766 /** 96767 * @method ambientLight 96768 * @param {Number} gray number specifying value between 96769 * white and black 96770 * @param {Number} [alpha] 96771 * @chainable 96772 */ 96773 /** 96774 * @method ambientLight 96775 * @param {String} value a color string 96776 * @chainable 96777 */ 96778 /** 96779 * @method ambientLight 96780 * @param {Number[]} values an array containing the red,green,blue & 96781 * and alpha components of the color 96782 * @chainable 96783 */ 96784 /** 96785 * @method ambientLight 96786 * @param {p5.Color} color color as a <a href="#/p5.Color">p5.Color</a> 96787 * @chainable 96788 */ 96789 96790 _main.default.prototype.ambientLight = function (v1, v2, v3, a) { 96791 this._assert3d('ambientLight'); 96792 _main.default._validateParameters('ambientLight', arguments); 96793 var color = this.color.apply(this, arguments); 96794 this._renderer.ambientLightColors.push(color._array[0], color._array[1], color._array[2]); 96795 this._renderer._enableLighting = true; 96796 return this; 96797 }; 96798 /** 96799 * Sets the color of the specular highlight of a non-ambient light 96800 * (i.e. all lights except <a href="#/p5/ambientLight">ambientLight()</a>). 96801 * 96802 * specularColor() affects only the lights which are created after 96803 * it in the code. 96804 * 96805 * This function is used in combination with 96806 * <a href="#/p5/specularMaterial">specularMaterial()</a>. 96807 * If a geometry does not use specularMaterial(), this function 96808 * will have no effect. 96809 *
96810 * The default color is white (255, 255, 255), which is used if 96811 * specularColor() is not explicitly called. 96812 * 96813 * Note: specularColor is equivalent to the Processing function 96814 * <a href="https://processing.org/reference/lightSpecular_.html">lightSpecular</a>. 96815 * 96816 * @method specularColor 96817 * @param {Number} v1 red or hue value relative to 96818 * the current color range 96819 * @param {Number} v2 green or saturation value 96820 * relative to the current color range 96821 * @param {Number} v3 blue or brightness value 96822 * relative to the current color range 96823 * @chainable 96824 * @example 96825 * <div> 96826 * <code> 96827 * let setRedSpecularColor = true; 96828 * 96829 * function setup() { 96830 * createCanvas(100, 100, WEBGL); 96831 * noStroke(); 96832 * describe( 96833 * 'Sphere with specular highlight. Clicking the mouse toggles the specular highlight color between red and the default white.' 96834 * ); 96835 * } 96836 * 96837 * function draw() { 96838 * background(0); 96839 * 96840 * ambientLight(60); 96841 * 96842 * // add a point light to showcase specular color 96843 * // -- use mouse location to position the light 96844 * let lightPosX = mouseX - width / 2; 96845 * let lightPosY = mouseY - height / 2; 96846 * // -- set the light's specular color 96847 * if (setRedSpecularColor) { 96848 * specularColor(255, 0, 0); // red specular highlight 96849 * } 96850 * // -- create the light 96851 * pointLight(200, 200, 200, lightPosX, lightPosY, 50); // white light 96852 * 96853 * // use specular material with high shininess 96854 * specularMaterial(150); 96855 * shininess(50); 96856 * 96857 * sphere(30, 64, 64); 96858 * } 96859 * 96860 * function mouseClicked() { 96861 * setRedSpecularColor = !setRedSpecularColor; 96862 * } 96863 * </code> 96864 * </div> 96865 * 96866 * @alt 96867 * Sphere with specular highlight. Clicking the mouse toggles the 96868 * specular highlight color between red and the default white. 96869 */ 96870 /** 96871 * @method specularColor 96872 * @param {Number} gray number specifying value between 96873 * white and black 96874 * @chainable 96875 */ 96876 /** 96877 * @method specularColor 96878 * @param {String} value color as a CSS string 96879 * @chainable 96880 */ 96881 /** 96882 * @method specularColor 96883 * @param {Number[]} values color as an array containing the 96884 * red, green, and blue components 96885 * @chainable 96886 */ 96887 /** 96888 * @method specularColor 96889 * @param {p5.Color} color color as a <a href="#/p5.Color">p5.Color</a> 96890 * @chainable 96891 */ 96892 _main.default.prototype.specularColor = function (v1, v2, v3) { 96893 this._assert3d('specularColor'); 96894 _main.default._validateParameters('specularColor', arguments); 96895 var color = this.color.apply(this, arguments); 96896 this._renderer.specularColors = [ 96897 color._array[0], 96898 color._array[1], 96899 color._array[2] 96900 ]; 96901 return this; 96902 }; 96903 /** 96904 * Creates a directional light with the given color and direction. 96905 * 96906 * Directional light comes from one direction. 96907 * The direction is specified as numbers inclusively between -1 and 1. 96908 * For example, setting the direction as (0, -1, 0) will cause the 96909 * geometry to be lit from below (since the light will be facing 96910 * directly upwards). Similarly, setting the direction as (1, 0, 0) 96911 * will cause the geometry to be lit from the left (since the light 96912 * will be facing directly rightwards). 96913 * 96914 * Directional lights do not have a specific point of origin, and 96915 * therefore cannot be positioned closer or farther away from a geometry. 96916 * 96917 * A maximum of **5** directional lights can be active at once. 96918 * 96919 * Note: lights need to be called (whether directly or indirectly) 96920 * within draw() to remain persistent in a looping program. 96921 * Placing them in setup() will cause them to only have an effect 96922 * the first time through the loop. 96923 * 96924 * @method directionalLight 96925 * @param {Number} v1 red or hue value relative to the current 96926 * color range 96927 * @param {Number} v2 green or saturation value relative to the 96928 * current color range 96929 * @param {Number} v3 blue or brightness value relative to the 96930 * current color range 96931 * @param {Number} x x component of direction (inclusive range of -1 to 1) 96932 * @param {Number} y y component of direction (inclusive range of -1 to 1) 96933 * @param {Number} z z component of direction (inclusive range of -1 to 1) 96934 * @chainable 96935 * @example 96936 * <div> 96937 * <code> 96938 * function setup() { 96939 * createCanvas(100, 100, WEBGL); 96940 * describe( 96941 * 'scene with sphere and directional light. The direction of the light is controlled with the mouse position.' 96942 * ); 96943 * } 96944 * function draw() { 96945 * background(0); 96946 * //move your mouse to change light direction 96947 * let dirX = (mouseX / width - 0.5) * 2; 96948 * let dirY = (mouseY / height - 0.5) * 2; 96949 * directionalLight(250, 250, 250, -dirX, -dirY, -1); 96950 * noStroke(); 96951 * sphere(40); 96952 * } 96953 * </code> 96954 * </div> 96955 * 96956 * @alt 96957 * scene with sphere and directional light. The direction of 96958 * the light is controlled with the mouse position. 96959 */ 96960 /** 96961 * @method directionalLight 96962 * @param {Number} v1 96963 * @param {Number} v2 96964 * @param {Number} v3 96965 * @param {p5.Vector} direction direction of light as a 96966 * <a href="#/p5.Vector">p5.Vector</a> 96967 * @chainable 96968 */ 96969 /** 96970 * @method directionalLight 96971 * @param {p5.Color|Number[]|String} color color as a <a href="#/p5.Color">p5.Color</a>, 96972 * as an array, or as a CSS string 96973 * @param {Number} x 96974 * @param {Number} y 96975 * @param {Number} z 96976 * @chainable 96977 */ 96978 /** 96979 * @method directionalLight 96980 * @param {p5.Color|Number[]|String} color 96981 * @param {p5.Vector} direction 96982 * @chainable 96983 */ 96984 _main.default.prototype.directionalLight = function (v1, v2, v3, x, y, z) { 96985 this._assert3d('directionalLight'); 96986 _main.default._validateParameters('directionalLight', arguments); //@TODO: check parameters number 96987 var color; 96988 if (v1 instanceof _main.default.Color) { 96989 color = v1; 96990 } else { 96991 color = this.color(v1, v2, v3); 96992 } 96993 var _x, 96994 _y, 96995 _z; 96996 var v = arguments[arguments.length - 1]; 96997 if (typeof v === 'number') { 96998 _x = arguments[arguments.length - 3]; 96999 _y = arguments[arguments.length - 2]; 97000 _z = arguments[arguments.length - 1]; 97001 } else { 97002 _x = v.x; 97003 _y = v.y; 97004 _z = v.z; 97005 } // normalize direction 97006 97007 var l = Math.sqrt(_x * _x + _y * _y + _z * _z); 97008 this._renderer.directionalLightDirections.push(_x / l, _y / l, _z / l); 97009 this._renderer.directionalLightDiffuseColors.push(color._array[0], color._array[1], color._array[2]); 97010 Array.prototype.push.apply(this._renderer.directionalLightSpecularColors, this._renderer.specularColors); 97011 this._renderer._enableLighting = true; 97012 return this; 97013 }; 97014 /** 97015 * Creates a point light with the given color and position. 97016 * 97017 * A point light emits light from a single point in all directions. 97018 * Because the light is emitted from a specific point (position), 97019 * it has a different effect when it is positioned farther vs. nearer 97020 * an object. 97021 * 97022 * A maximum of **5** point lights can be active at once. 97023 *
97024 * Note: lights need to be called (whether directly or indirectly) 97025 * within draw() to remain persistent in a looping program. 97026 * Placing them in setup() will cause them to only have an effect 97027 * the first time through the loop. 97028 * 97029 * @method pointLight 97030 * @param {Number} v1 red or hue value relative to the current 97031 * color range 97032 * @param {Number} v2 green or saturation value relative to the 97033 * current color range 97034 * @param {Number} v3 blue or brightness value relative to the 97035 * current color range 97036 * @param {Number} x x component of position 97037 * @param {Number} y y component of position 97038 * @param {Number} z z component of position 97039 * @chainable 97040 * @example 97041 * <div> 97042 * <code> 97043 * function setup() { 97044 * createCanvas(100, 100, WEBGL); 97045 * describe( 97046 * 'scene with sphere and point light. The position of the light is controlled with the mouse position.' 97047 * ); 97048 * } 97049 * function draw() { 97050 * background(0); 97051 * // move your mouse to change light position 97052 * let locX = mouseX - width / 2; 97053 * let locY = mouseY - height / 2; 97054 * // to set the light position, 97055 * // think of the world's coordinate as: 97056 * // -width/2,-height/2 ----------- width/2,-height/2 97057 * // | | 97058 * // | 0,0 | 97059 * // | | 97060 * // -width/2,height/2 ----------- width/2,height/2 97061 * pointLight(250, 250, 250, locX, locY, 50); 97062 * noStroke(); 97063 * sphere(40); 97064 * } 97065 * </code> 97066 * </div> 97067 * 97068 * @alt 97069 * scene with sphere and point light. The position of 97070 * the light is controlled with the mouse position. 97071 */ 97072 /** 97073 * @method pointLight 97074 * @param {Number} v1 97075 * @param {Number} v2 97076 * @param {Number} v3 97077 * @param {p5.Vector} position of light as a <a href="#/p5.Vector">p5.Vector</a> 97078 * @chainable 97079 */ 97080 /** 97081 * @method pointLight 97082 * @param {p5.Color|Number[]|String} color color as a <a href="#/p5.Color">p5.Color</a>, 97083 * as an array, or as a CSS string 97084 * @param {Number} x 97085 * @param {Number} y 97086 * @param {Number} z 97087 * @chainable 97088 */ 97089 /** 97090 * @method pointLight 97091 * @param {p5.Color|Number[]|String} color 97092 * @param {p5.Vector} position 97093 * @chainable 97094 */ 97095 _main.default.prototype.pointLight = function (v1, v2, v3, x, y, z) { 97096 this._assert3d('pointLight'); 97097 _main.default._validateParameters('pointLight', arguments); //@TODO: check parameters number 97098 var color; 97099 if (v1 instanceof _main.default.Color) { 97100 color = v1; 97101 } else { 97102 color = this.color(v1, v2, v3); 97103 } 97104 var _x, 97105 _y, 97106 _z; 97107 var v = arguments[arguments.length - 1]; 97108 if (typeof v === 'number') { 97109 _x = arguments[arguments.length - 3]; 97110 _y = arguments[arguments.length - 2]; 97111 _z = arguments[arguments.length - 1]; 97112 } else { 97113 _x = v.x; 97114 _y = v.y; 97115 _z = v.z; 97116 } 97117 this._renderer.pointLightPositions.push(_x, _y, _z); 97118 this._renderer.pointLightDiffuseColors.push(color._array[0], color._array[1], color._array[2]); 97119 Array.prototype.push.apply(this._renderer.pointLightSpecularColors, this._renderer.specularColors); 97120 this._renderer._enableLighting = true; 97121 return this; 97122 }; 97123 /** 97124 * Places an ambient and directional light in the scene. 97125 * The lights are set to ambientLight(128, 128, 128) and 97126 * directionalLight(128, 128, 128, 0, 0, -1). 97127 * 97128 * Note: lights need to be called (whether directly or indirectly) 97129 * within draw() to remain persistent in a looping program. 97130 * Placing them in setup() will cause them to only have an effect 97131 * the first time through the loop. 97132 * 97133 * @method lights 97134 * @chainable 97135 * @example 97136 * <div> 97137 * <code> 97138 * function setup() { 97139 * createCanvas(100, 100, WEBGL); 97140 * describe('the light is partially ambient and partially directional'); 97141 * } 97142 * function draw() { 97143 * background(0); 97144 * lights(); 97145 * rotateX(millis() / 1000); 97146 * rotateY(millis() / 1000); 97147 * rotateZ(millis() / 1000); 97148 * box(); 97149 * } 97150 * </code> 97151 * </div> 97152 * 97153 * @alt 97154 * the light is partially ambient and partially directional 97155 */ 97156 _main.default.prototype.lights = function () { 97157 this._assert3d('lights'); // only restore the colorMode to default if it is not in default already 97158 if (this._colorMode === constants.RGB) { 97159 this.ambientLight(128, 128, 128); 97160 this.directionalLight(128, 128, 128, 0, 0, - 1); 97161 } else { 97162 var maxBright = this._colorMaxes[this._colorMode][2]; 97163 this.ambientLight(0, 0, maxBright); 97164 this.directionalLight(0, 0, maxBright, 0, 0, - 1); 97165 } 97166 return this; 97167 }; 97168 /** 97169 * Sets the falloff rate for <a href="#/p5/pointLight">
97169pointLight()</a> 97170 * and <a href="#/p5/spotLight">spotLight()</a>. 97171 * 97172 * lightFalloff() affects only the lights which are created after it 97173 * in the code. 97174 * 97175 * The `constant`, `linear`, an `quadratic` parameters are used to calculate falloff as follows: 97176 * 97177 * d = distance from light position to vertex position 97178 * 97179 * falloff = 1 / (CONSTANT + d \* LINEAR + (d \* d) \* QUADRATIC) 97180 * 97181 * @method lightFalloff 97182 * @param {Number} constant CONSTANT value for determining falloff 97183 * @param {Number} linear LINEAR value for determining falloff 97184 * @param {Number} quadratic QUADRATIC value for determining falloff 97185 * @chainable 97186 * @example 97187 * <div> 97188 * <code> 97189 * function setup() { 97190 * createCanvas(100, 100, WEBGL); 97191 * noStroke(); 97192 * describe( 97193 * 'Two spheres with different falloff values show different intensity of light' 97194 * ); 97195 * } 97196 * function draw() { 97197 * ortho(); 97198 * background(0); 97199 * 97200 * let locX = mouseX - width / 2; 97201 * let locY = mouseY - height / 2; 97202 * locX /= 2; // half scale 97203 * 97204 * lightFalloff(1, 0, 0); 97205 * push(); 97206 * translate(-25, 0, 0); 97207 * pointLight(250, 250, 250, locX - 25, locY, 50); 97208 * sphere(20); 97209 * pop(); 97210 *
97211 * lightFalloff(0.97, 0.03, 0); 97212 * push(); 97213 * translate(25, 0, 0); 97214 * pointLight(250, 250, 250, locX + 25, locY, 50); 97215 * sphere(20); 97216 * pop(); 97217 * } 97218 * </code> 97219 * </div> 97220 * 97221 * @alt 97222 * Two spheres with different falloff values show different intensity of light 97223 */ 97224 _main.default.prototype.lightFalloff = function (constantAttenuation, linearAttenuation, quadraticAttenuation) { 97225 this._assert3d('lightFalloff'); 97226 _main.default._validateParameters('lightFalloff', arguments); 97227 if (constantAttenuation < 0) { 97228 constantAttenuation = 0; 97229 console.warn('Value of constant argument in lightFalloff() should be never be negative. Set to 0.'); 97230 } 97231 if (linearAttenuation < 0) { 97232 linearAttenuation = 0; 97233 console.warn('Value of linear argument in lightFalloff() should be never be negative. Set to 0.'); 97234 } 97235 if (quadraticAttenuation < 0) { 97236 quadraticAttenuation = 0; 97237 console.warn('Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.'); 97238 } 97239 if (constantAttenuation === 0 && linearAttenuation === 0 && quadraticAttenuation === 0) { 97240 constantAttenuation = 1; 97241 console.warn('Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.'); 97242 } 97243 this._renderer.constantAttenuation = constantAttenuation; 97244 this._renderer.linearAttenuation = linearAttenuation; 97245 this._renderer.quadraticAttenuation = quadraticAttenuation; 97246 return this; 97247 }; 97248 /** 97249 * Creates a spot light with the given color, position, 97250 * light direction, angle, and concentration. 97251 * 97252 * Like a <a href="#/p5/pointLight">pointLight()</a>, a spotLight() 97253 * emits light from a specific point (position). It has a different effect 97254 * when it is positioned farther vs. nearer an object. 97255 * 97256 * However, unlike a pointLight(), the light is emitted in **one direction** 97257 * along a conical shape. The shape of the cone can be controlled using 97258 * the `angle` and `concentration` parameters. 97259 * 97260 * The `angle` parameter is used to 97261 * determine the radius of the cone. And the `concentration` 97262 * parameter is used to focus the light towards the center of 97263 * the cone. Both parameters are optional, however if you want 97264 * to specify `concentration`, you must also specify `angle`. 97265 * The minimum concentration value is 1. 97266 * 97267 * A maximum of **5** spot lights can be active at once. 97268 * 97269 * Note: lights need to be called (whether directly or indirectly) 97270 * within draw() to remain persistent in a looping program. 97271 * Placing them in setup() will cause them to only have an effect 97272 * the first time through the loop. 97273 * 97274 * @method spotLight 97275 * @param {Number} v1 red or hue value relative to the current color range 97276 * @param {Number} v2 green or saturation value relative to the current color range 97277 * @param {Number} v3 blue or brightness value relative to the current color range 97278 * @param {Number} x x component of position 97279 * @param {Number} y y component of position 97280 * @param {Number} z z component of position 97281 * @param {Number} rx x component of light direction (inclusive range of -1 to 1) 97282 * @param {Number} ry y component of light direction (inclusive range of -1 to 1) 97283 * @param {Number} rz z component of light direction (inclusive range of -1 to 1) 97284 * @param {Number} [angle] angle of cone. Defaults to PI/3 97285 * @param {Number} [concentration] concentration of cone. Defaults to 100 97286 * @chainable 97287 * 97288 * @example 97289 * <div> 97290 * <code> 97291 * function setup() { 97292 * createCanvas(100, 100, WEBGL); 97293 * describe( 97294 * 'scene with sphere and spot light. The position of the light is controlled with the mouse position.' 97295 * ); 97296 * } 97297 * function draw() { 97298 * background(0); 97299 * // move your mouse to change light position 97300 * let locX = mouseX - width / 2;
97301 * let locY = mouseY - height / 2; 97302 * // to set the light position, 97303 * // think of the world's coordinate as: 97304 * // -width/2,-height/2 ----------- width/2,-height/2 97305 * // | | 97306 * // | 0,0 | 97307 * // | | 97308 * // -width/2,height/2 ----------- width/2,height/2 97309 * ambientLight(50); 97310 * spotLight(0, 250, 0, locX, locY, 100, 0, 0, -1, Math.PI / 16); 97311 * noStroke(); 97312 * sphere(40); 97313 * } 97314 * </code> 97315 * </div> 97316 * 97317 * @alt 97318 * scene with sphere and spot light. The position of 97319 * the light is controlled with the mouse position. 97320 */ 97321 /** 97322 * @method spotLight 97323 * @param {p5.Color|Number[]|String} color color as a <a href="#/p5.Color">p5.Color</a>, 97324 * as an array, or as a CSS string 97325 * @param {p5.Vector} position position of light as a <a href="#/p5.Vector">p5.Vector</a> 97326 * @param {p5.Vector} direction direction of light as a <a href="#/p5.Vector">p5.Vector</a> 97327 * @param {Number} [angle] 97328 * @param {Number} [concentration] 97329 */ 97330 /** 97331 * @method spotLight 97332 * @param {Number} v1 97333 * @param {Number} v2 97334 * @param {Number} v3 97335 * @param {p5.Vector} position 97336 * @param {p5.Vector} direction 97337 * @param {Number} [angle] 97338 * @param {Number} [concentration] 97339 */ 97340 /** 97341 * @method spotLight 97342 * @param {p5.Color|Number[]|String} color 97343 * @param {Number} x 97344 * @param {Number} y 97345 * @param {Number} z 97346 * @param {p5.Vector} direction 97347 * @param {Number} [angle] 97348 * @param {Number} [concentration] 97349 */ 97350 /** 97351 * @method spotLight 97352 * @param {p5.Color|Number[]|String} color 97353 * @param {p5.Vector} position 97354 * @param {Number} rx 97355 * @param {Number} ry 97356 * @param {Number} rz 97357 * @param {Number} [angle] 97358 * @param {Number} [concentration] 97359 */ 97360 /** 97361 * @method spotLight 97362 * @param {Number} v1 97363 * @param {Number} v2 97364 * @param {Number} v3 97365 * @param {Number} x 97366 * @param {Number} y 97367 * @param {Number} z 97368 * @param {p5.Vector} direction 97369 * @param {Number} [angle] 97370 * @param {Number} [concentration] 97371 */ 97372 /** 97373 * @method spotLight 97374 * @param {Number} v1 97375 * @param {Number} v2 97376 * @param {Number} v3 97377 * @param {p5.Vector} position 97378 * @param {Number} rx 97379 * @param {Number} ry 97380 * @param {Number} rz 97381 * @param {Number} [angle] 97382 * @param {Number} [concentration] 97383 */ 97384 /** 97385 * @method spotLight 97386 * @param {p5.Color|Number[]|String} color 97387 * @param {Number} x 97388 * @param {Number} y 97389 * @param {Number} z 97390 * @param {Number} rx 97391 * @param {Number} ry 97392 * @param {Number} rz 97393 * @param {Number} [angle] 97394 * @param {Number} [concentration] 97395 */ 97396 _main.default.prototype.spotLight = function (v1, v2, v3, x, y, z, nx, ny, nz, angle, concentration) { 97397 this._assert3d('spotLight'); 97398 _main.default._validateParameters('spotLight', arguments); 97399 var color, 97400 position, 97401 direction; 97402 var length = arguments.length; 97403 switch (length) { 97404 case 11: 97405 case 10: 97406 color = this.color(v1, v2, v3); 97407 position = new _main.default.Vector(x, y, z); 97408 direction = new _main.default.Vector(nx, ny, nz); 97409 break; 97410 case 9: 97411 if (v1 instanceof _main.default.Color) { 97412 color = v1; 97413 position = new _main.default.Vector(v2, v3, x); 97414 direction = new _main.default.Vector(y, z, nx); 97415 angle = ny; 97416 concentration = nz; 97417 } else if (x instanceof _main.default.Vector) { 97418 color = this.color(v1, v2, v3); 97419 position = x; 97420 direction = new _main.default.Vector(y, z, nx); 97421 angle = ny; 97422 concentration = nz; 97423 } else if (nx instanceof _main.default.Vector) { 97424 color = this.color(v1, v2, v3); 97425 position = new _main.default.Vector(x, y, z); 97426 direction = nx; 97427 angle = ny; 97428 concentration = nz; 97429 } else { 97430 color = this.color(v1, v2, v3); 97431 position = new _main.default.Vector(x, y, z); 97432 direction = new _main.default.Vector(nx, ny, nz); 97433 } 97434 break; 97435 case 8: 97436 if (v1 instanceof _main.default.Color) { 97437 color = v1; 97438 position = new _main.default.Vector(v2, v3, x); 97439 direction = new _main.default.Vector(y, z, nx); 97440 angle = ny; 97441 } else if (x instanceof _main.default.Vector) { 97442 color = this.color(v1, v2, v3); 97443 position = x; 97444 direction = new _main.default.Vector(y, z, nx); 97445 angle = ny; 97446 } else { 97447 color = this.color(v1, v2, v3); 97448 position = new _main.default.Vector(x, y, z); 97449 direction = nx; 97450 angle = ny; 97451 } 97452 break; 97453 case 7: 97454 if (v1 instanceof _main.default.Color && v2 instanceof _main.default.Vector) { 97455 color = v1; 97456 position = v2; 97457 direction = new _main.default.Vector(v3, x, y); 97458 angle = z; 97459 concentration = nx; 97460 } else if (v1 instanceof _main.default.Color && y instanceof _main.default.Vector) { 97461 color = v1; 97462 position = new _main.default.Vector(v2, v3, x); 97463 direction = y; 97464 angle = z; 97465 concentration = nx; 97466 } else if (x instanceof _main.default.Vector && y instanceof _main.default.Vector) { 97467 color = this.color(v1, v2, v3); 97468 position = x; 97469 direction = y; 97470 angle = z; 97471 concentration = nx; 97472 } else if (v1 instanceof _main.default.Color) { 97473 color = v1; 97474 position = new _main.default.Vector(v2, v3, x); 97475 direction = new _main.default.Vector(y, z, nx); 97476 } else if (x instanceof _main.default.Vector) { 97477 color = this.color(v1, v2, v3); 97478 position = x; 97479 direction = new _main.default.Vector(y, z, nx); 97480 } else { 97481 color = this.color(v1, v2, v3); 97482 position = new _main.default.Vector(x, y, z); 97483 direction = nx; 97484 } 97485 break; 97486 case 6: 97487 if (x instanceof _main.default.Vector && y instanceof _main.default.Vector) { 97488 color = this.color(v1, v2, v3); 97489 position = x; 97490 direction = y; 97491 angle = z; 97492 } else if (v1 instanceof _main.default.Color && y instanceof _main.default.Vector) { 97493 color = v1; 97494 position = new _main.default.Vector(v2, v3, x); 97495 direction = y; 97496 angle = z; 97497 } else if (v1 instanceof _main.default.Color && v2 instanceof _main.default.Vector) { 97498 color = v1; 97499 position = v2; 97500 direction = new _main.default.Vector(v3, x, y); 97501 angle = z; 97502 } 97503 break; 97504 case 5: 97505 if (v1 instanceof _main.default.Color && v2 instanceof _main.default.Vector && v3 instanceof _main.default.Vector) { 97506 color = v1; 97507 position = v2; 97508 direction = v3; 97509 angle = x; 97510 concentration = y; 97511 } else if (x instanceof _main.default.Vector && y instanceof _main.default.Vector) { 97512 color = this.color(v1, v2, v3); 97513 position = x; 97514 direction = y; 97515 } else if (v1 instanceof _main.default.Color && y instanceof _main.default.Vector) { 97516 color = v1; 97517 position = new _main.default.Vector(v2, v3, x); 97518 direction = y; 97519 } else if (v1 instanceof _main.default.Color && v2 instanceof _main.default.Vector) { 97520 color = v1; 97521 position = v2; 97522 direction = new _main.default.Vector(v3, x, y); 97523 } 97524 break; 97525 case 4: 97526 color = v1; 97527 position = v2; 97528 direction = v3; 97529 angle = x; 97530 break; 97531 case 3: 97532 color = v1; 97533 position = v2; 97534 direction = v3; 97535 break; 97536 default: 97537 console.warn('Sorry, input for spotlight() is not in prescribed format. Too '.concat(length < 3 ? 'few' : 'many', ' arguments were provided')); 97538 return this; 97539 } 97540 this._renderer.spotLightDiffuseColors.push(color._array[0], color._array[1], color._array[2]); 97541 Array.prototype.push.apply(this._renderer.spotLightSpecularColors, this._renderer.specularColors); 97542 this._renderer.spotLightPositions.push(position.x, position.y, position.z); 97543 direction.normalize(); 97544 this._renderer.spotLightDirections.push(direction.x, direction.y, direction.z); 97545 if (angle === undefined) { 97546 angle = Math.PI / 3; 97547 } 97548 if (concentration !== undefined && concentration < 1) { 97549 concentration = 1; 97550 console.warn('Value of concentration needs to be greater than 1. Setting it to 1'); 97551 } else if (concentration === undefined) { 97552 concentration = 100; 97553 } 97554 angle = this._renderer._pInst._toRadians(angle); 97555 this._renderer.spotLightAngle.push(Math.cos(angle)); 97556 this._renderer.spotLightConc.push(concentration); 97557 this._renderer._enableLighting = true; 97558 return this; 97559 }; 97560 /** 97561 * Removes all lights present in a sketch. 97562 * 97563 * All subsequent geometry is rendered without lighting (until a new 97564 * light is created with a call to one of the lighting functions 97565 * (<a href="#/p5/lights">lights()</a>, 97566 * <a href="#/p5/ambientLight">ambientLight()</a>, 97567 * <a href="#/p5/directionalLight">directionalLight()</a>, 97568 * <a href="#/p5/pointLight">
97568pointLight()</a>, 97569 * <a href="#/p5/spotLight">spotLight()</a>). 97570 * 97571 * @method noLights 97572 * @chainable 97573 * @example 97574 * <div> 97575 * <code> 97576 * function setup() { 97577 * createCanvas(100, 100, WEBGL); 97578 * describe( 97579 * 'Three white spheres. Each appears as a different color due to lighting.' 97580 * ); 97581 * } 97582 * function draw() { 97583 * background(200); 97584 * noStroke(); 97585 * 97586 * ambientLight(255, 0, 0); 97587 * translate(-30, 0, 0); 97588 * ambientMaterial(255); 97589 * sphere(13); 97590 * 97591 * noLights(); 97592 * translate(30, 0, 0); 97593 * ambientMaterial(255); 97594 * sphere(13); 97595 * 97596 * ambientLight(0, 255, 0); 97597 * translate(30, 0, 0); 97598 * ambientMaterial(255); 97599 * sphere(13); 97600 * } 97601 * </code> 97602 * </div> 97603 * 97604 * @alt 97605 * Three white spheres. Each appears as a different 97606 * color due to lighting. 97607 */ 97608 _main.default.prototype.noLights = function () { 97609 this._assert3d('noLights'); 97610 _main.default._validateParameters('noLights', arguments); 97611 this._renderer._enableLighting = false; 97612 this._renderer.ambientLightColors.length = 0; 97613 this._renderer.specularColors = [ 97614 1, 97615 1, 97616 1 97617 ]; 97618 this._renderer.directionalLightDirections.length = 0; 97619 this._renderer.directionalLightDiffuseColors.length = 0; 97620 this._renderer.directionalLightSpecularColors.length = 0; 97621 this._renderer.pointLightPositions.length = 0; 97622 this._renderer.pointLightDiffuseColors.length = 0; 97623 this._renderer.pointLightSpecularColors.length = 0; 97624 this._renderer.spotLightPositions.length = 0; 97625 this._renderer.spotLightDirections.length = 0; 97626 this._renderer.spotLightDiffuseColors.length = 0; 97627 this._renderer.spotLightSpecularColors.length = 0; 97628 this._renderer.spotLightAngle.length = 0; 97629 this._renderer.spotLightConc.length = 0; 97630 this._renderer.constantAttenuation = 1; 97631 this._renderer.linearAttenuation = 0; 97632 this._renderer.quadraticAttenuation = 0; 97633 this._renderer._useShininess = 1; 97634 return this; 97635 }; 97636 var _default = _main.default; 97637 exports.default = _default; 97638 }, 97639 { 97640 '../core/constants': 278, 97641 '../core/main': 290, 97642 'core-js/modules/es.array.iterator': 176, 97643 'core-js/modules/es.object.get-own-property-descriptor': 191, 97644 'core-js/modules/es.object.to-string': 195, 97645 'core-js/modules/es.string.iterator': 204, 97646 'core-js/modules/es.symbol': 214, 97647 'core-js/modules/es.symbol.description': 212, 97648 'core-js/modules/es.symbol.iterator': 213, 97649 'core-js/modules/es.weak-map': 246, 97650 'core-js/modules/web.dom-collections.iterator': 248 97651 } 97652 ], 97653 336: [ 97654 function (_dereq_, module, exports) { 97655 'use strict'; 97656 _dereq_('core-js/modules/es.array.concat'); 97657 _dereq_('core-js/modules/es.array.index-of'); 97658 _dereq_('core-js/modules/es.array.slice'); 97659 _dereq_('core-js/modules/es.array.splice'); 97660 _dereq_('core-js/modules/es.object.to-string'); 97661 _dereq_('core-js/modules/es.regexp.exec'); 97662 _dereq_('core-js/modules/es.string.match'); 97663 _dereq_('core-js/modules/es.string.split'); 97664 _dereq_('core-js/modules/es.string.trim'); 97665 _dereq_('core-js/modules/es.array.concat'); 97666 _dereq_('core-js/modules/es.array.index-of'); 97667 _dereq_('core-js/modules/es.array.slice'); 97668 _dereq_('core-js/modules/es.array.splice'); 97669 _dereq_('core-js/modules/es.object.to-string'); 97670 _dereq_('core-js/modules/es.regexp.exec'); 97671 _dereq_('core-js/modules/es.string.match'); 97672 _dereq_('core-js/modules/es.string.split'); 97673 _dereq_('core-js/modules/es.string.trim'); 97674 Object.defineProperty(exports, '__esModule', { 97675 value: true 97676 }); 97677 exports.default = void 0; 97678 var _main = _interopRequireDefault(_dereq_('../core/main')); 97679 _dereq_('./p5.Geometry'); 97680 function _interopRequireDefault(obj) { 97681 return obj && obj.__esModule ? obj : { 97682 default: 97683 obj 97684 }; 97685 } /** 97686 * @module Shape 97687 * @submodule 3D Models 97688 * @for p5 97689 * @requires core 97690 * @requires p5.Geometry 97691 */ 97692 /** 97693 * Load a 3d model from an OBJ or STL file. 97694 * 97695 * <a href="#/p5/loadModel">loadModel()</a> should be placed inside of <a href="#/p5/preload">preload()</a>. 97696 * This allows the model to load fully before the rest of your co
97696de is run. 97697 * 97698 * One of the limitations of the OBJ and STL format is that it doesn't have a built-in 97699 * sense of scale. This means that models exported from different programs might 97700 * be very different sizes. If your model isn't displaying, try calling 97701 * <a href="#/p5/loadModel">loadModel()</a> with the normalized parameter set to true. This will resize the 97702 * model to a scale appropriate for p5. You can also make additional changes to 97703 * the final size of your model with the <a href="#/p5/scale">scale()</a> function. 97704 * 97705 * Also, the support for colored STL files is not present. STL files with color will be 97706 * rendered without color properties. 97707 * 97708 * @method loadModel 97709 * @param {String} path Path of the model to be loaded 97710 * @param {Boolean} normalize If true, scale the model to a 97711 * standardized size when loading 97712 * @param {function(p5.Geometry)} [successCallback] Function to be called 97713 * once the model is loaded. Will be passed 97714 * the 3D model object. 97715 * @param {function(Event)} [failureCallback] called with event error if 97716 * the model fails to load. 97717 * @param {String} [fileType] The file extension of the model 97718 * (<code>.stl</code>, <code>.obj</code>). 97719 * @return {p5.Geometry} the <a href="#/p5.Geometry">p5.Geometry</a> object 97720 * 97721 * @example 97722 * <div> 97723 * <code> 97724 * //draw a spinning octahedron 97725 * let octahedron; 97726 * 97727 * function preload() { 97728 * octahedron = loadModel('assets/octahedron.obj'); 97729 * } 97730 * 97731 * function setup() { 97732 * createCanvas(100, 100, WEBGL); 97733 * describe('Vertically rotating 3-d octahedron.'); 97734 * } 97735 * 97736 * function draw() { 97737 * background(200); 97738 * rotateX(frameCount * 0.01); 97739 * rotateY(frameCount * 0.01); 97740 * model(octahedron); 97741 * } 97742 * </code> 97743 * </div> 97744 * 97745 * @alt 97746 * Vertically rotating 3-d octahedron. 97747 * 97748 * @example 97749 * <div> 97750 * <code> 97751 * //draw a spinning teapot 97752 * let teapot; 97753 * 97754 * function preload() { 97755 * // Load model with normalise parameter set to true 97756 * teapot = loadModel('assets/teapot.obj', true); 97757 * } 97758 * 97759 * function setup() { 97760 * createCanvas(100, 100, WEBGL); 97761 * describe('Vertically rotating 3-d teapot with red, green and blue gradient.'); 97762 * } 97763 * 97764 * function draw() { 97765 * background(200); 97766 * scale(0.4); // Scaled to make model fit into canvas 97767 * rotateX(frameCount * 0.01); 97768 * rotateY(frameCount * 0.01); 97769 * normalMaterial(); // For effect 97770 * model(teapot); 97771 * } 97772 * </code> 97773 * </div> 97774 * 97775 * @alt 97776 * Vertically rotating 3-d teapot with red, green and blue gradient. 97777 */ 97778 /** 97779 * @method loadModel 97780 * @param {String} path 97781 * @param {function(p5.Geometry)} [successCallback] 97782 * @param {function(Event)} [failureCallback] 97783 * @param {String} [fileType] 97784 * @return {p5.Geometry} the <a href="#/p5.Geometry">p5.Geometry</a> object 97785 */ 97786 97787 _main.default.prototype.loadModel = function (path) { 97788 _main.default._validateParameters('loadModel', arguments); 97789 var normalize; 97790 var successCallback; 97791 var failureCallback; 97792 var fileType = path.slice( - 4); 97793 if (typeof arguments[1] === 'boolean') { 97794 normalize = arguments[1]; 97795 successCallback = arguments[2]; 97796 failureCallback = arguments[3]; 97797 if (typeof arguments[4] !== 'undefined') { 97798 fileType = arguments[4]; 97799 } 97800 } else { 97801 normalize = false; 97802 successCallback = arguments[1]; 97803 failureCallback = arguments[2]; 97804 if (typeof arguments[3] !== 'undefined') { 97805 fileType = arguments[3]; 97806 } 97807 } 97808 var model = new _main.default.Geometry(); 97809 model.gid = ''.concat(path, '|').concat(normalize); 97810 var self = this; 97811 if (fileType.match(/\.stl$/i)) { 97812 this.httpDo(path, 'GET', 'arrayBuffer', function (arrayBuffer) { 97813 parseSTL(model, arrayBuffer); 97814 if (normalize) { 97815 model.normalize(); 97816 } 97817 self._decrementPreload(); 97818 if (typeof successCallback === 'function') { 97819 successCallback(model); 97820 } 97821 }, failureCallback); 97822 } else if (fileType.match(/\.obj$/i)) { 97823 this.loadStrings(path, function (strings) { 97824 parseObj(model, strings); 97825 if (normalize) { 97826 model.normalize(); 97827 } 97828 self._decrementPreload(); 97829 if (typeof successCallback === 'function') { 97830 successCallback(model); 97831 } 97832 }, failureCallback); 97833 } else { 97834 _main.default._friendlyFileLoadError(3, path); 97835 if (failureCallback) { 97836 failureCallback(); 97837 } else {
97838 console.error('Sorry, the file type is invalid. Only OBJ and STL files are supported.'); 97839 } 97840 } 97841 return model; 97842 }; 97843 /** 97844 * Parse OBJ lines into model. For reference, this is what a simple model of a 97845 * square might look like: 97846 * 97847 * v -0.5 -0.5 0.5 97848 * v -0.5 -0.5 -0.5 97849 * v -0.5 0.5 -0.5 97850 * v -0.5 0.5 0.5 97851 * 97852 * f 4 3 2 1 97853 */ 97854 function parseObj(model, lines) { 97855 // OBJ allows a face to specify an index for a vertex (in the above example), 97856 // but it also allows you to specify a custom combination of vertex, UV 97857 // coordinate, and vertex normal. So, "3/4/3" would mean, "use vertex 3 with 97858 // UV coordinate 4 and vertex normal 3". In WebGL, every vertex with different 97859 // parameters must be a different vertex, so loadedVerts is used to 97860 // temporarily store the parsed vertices, normals, etc., and indexedVerts is 97861 // used to map a specific combination (keyed on, for example, the string 97862 // "3/4/3"), to the actual index of the newly created vertex in the final 97863 // object. 97864 var loadedVerts = { 97865 v: [ 97866 ], 97867 vt: [ 97868 ], 97869 vn: [ 97870 ] 97871 }; 97872 var indexedVerts = { 97873 }; 97874 for (var line = 0; line < lines.length; ++line) { 97875 // Each line is a separate object (vertex, face, vertex normal, etc) 97876 // For each line, split it into tokens on whitespace. The first token 97877 // describes the type. 97878 var tokens = lines[line].trim().split(/\b\s+/); 97879 if (tokens.length > 0) { 97880 if (tokens[0] === 'v' || tokens[0] === 'vn') { 97881 // Check if this line describes a vertex or vertex normal. 97882 // It will have three numeric parameters. 97883 var vertex = new _main.default.Vector(parseFloat(tokens[1]), parseFloat(tokens[2]), parseFloat(tokens[3])); 97884 loadedVerts[tokens[0]].push(vertex); 97885 } else if (tokens[0] === 'vt') { 97886 // Check if this line describes a texture coordinate. 97887 // It will have two numeric parameters U and V (W is omitted). 97888 // Because of WebGL texture coordinates rendering behaviour, the V 97889 // coordinate is inversed. 97890 var texVertex = [ 97891 parseFloat(tokens[1]), 97892 1 - parseFloat(tokens[2]) 97893 ]; 97894 loadedVerts[tokens[0]].push(texVertex); 97895 } else if (tokens[0] === 'f') { 97896 // Check if this line describes a face. 97897 // OBJ faces can have more than three points. Triangulate points. 97898 for (var tri = 3; tri < tokens.length; ++tri) { 97899 var face = [ 97900 ]; 97901 var vertexTokens = [ 97902 1, 97903 tri - 1, 97904 tri 97905 ]; 97906 for (var tokenInd = 0; tokenInd < vertexTokens.length; ++tokenInd) { 97907 // Now, convert the given token into an index 97908 var vertString = tokens[vertexTokens[tokenInd]]; 97909 var vertIndex = 0; // TODO: Faces can technically use negative numbers to refer to the 97910 // previous nth vertex. I haven't seen this used in practice, but 97911 // it might be good to implement this in the future. 97912 if (indexedVerts[vertString] !== undefined) { 97913 vertIndex = indexedVerts[vertString]; 97914 } else { 97915 var vertParts = vertString.split('/'); 97916 for (var i = 0; i < vertParts.length; i++) { 97917 vertParts[i] = parseInt(vertParts[i]) - 1; 97918 } 97919 vertIndex = indexedVerts[vertString] = model.vertices.length; 97920 model.vertices.push(loadedVerts.v[vertParts[0]].copy()); 97921 if (loadedVerts.vt[vertParts[1]]) { 97922 model.uvs.push(loadedVerts.vt[vertParts[1]].slice()); 97923 } else { 97924 model.uvs.push([0, 97925 0]); 97926 } 97927 if (loadedVerts.vn[vertParts[2]]) { 97928 model.vertexNormals.push(loadedVerts.vn[vertParts[2]].copy()); 97929 } 97930 } 97931 face.push(vertIndex); 97932 } 97933 if (face[0] !== face[1] && face[0] !== face[2] && face[1] !== face[2]) { 97934 model.faces.push(face); 97935 } 97936 } 97937 } 97938 } 97939 } // If the model doesn't have normals, compute the normals 97940 97941 if (model.vertexNormals.length === 0) { 97942 model.computeNormals(); 97943 } 97944 return model; 97945 } /** 97946 * STL files can be of two types, ASCII and Binary, 97947 *
97948 * We need to convert the arrayBuffer to an array of strings, 97949 * to parse it as an ASCII file. 97950 */ 97951 97952 function parseSTL(model, buffer) { 97953 if (isBinary(buffer)) { 97954 parseBinarySTL(model, buffer); 97955 } else { 97956 var reader = new DataView(buffer); 97957 if (!('TextDecoder' in window)) { 97958 console.warn('Sorry, ASCII STL loading only works in browsers that support TextDecoder (https://caniuse.com/#feat=textencoder)'); 97959 return model; 97960 } 97961 var decoder = new TextDecoder('utf-8'); 97962 var lines = decoder.decode(reader); 97963 var lineArray = lines.split('\n'); 97964 parseASCIISTL(model, lineArray); 97965 } 97966 return model; 97967 } /** 97968 * This function checks if the file is in ASCII format or in Binary format 97969 * 97970 * It is done by searching keyword `solid` at the start of the file. 97971 * 97972 * An ASCII STL data must begin with `solid` as the first six bytes. 97973 * However, ASCII STLs lacking the SPACE after the `d` are known to be 97974 * plentiful. So, check the first 5 bytes for `solid`. 97975 * 97976 * Several encodings, such as UTF-8, precede the text with up to 5 bytes: 97977 * https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding 97978 * Search for `solid` to start anywhere after those prefixes. 97979 */ 97980 97981 function isBinary(data) { 97982 var reader = new DataView(data); // US-ASCII ordinal values for `s`, `o`, `l`, `i`, `d` 97983 var solid = [ 97984 115, 97985 111, 97986 108, 97987 105, 97988 100 97989 ]; 97990 for (var off = 0; off < 5; off++) { 97991 // If "solid" text is matched to the current offset, declare it to be an ASCII STL. 97992 if (matchDataViewAt(solid, reader, off)) return false; 97993 } // Couldn't find "solid" text at the beginning; it is binary STL. 97994 97995 return true; 97996 } /** 97997 * This function matches the `query` at the provided `offset` 97998 */ 97999 98000 function matchDataViewAt(query, reader, offset) { 98001 // Check if each byte in query matches the corresponding byte from the current offset 98002 for (var i = 0, il = query.length; i < il; i++) { 98003 if (query[i] !== reader.getUint8(offset + i, false)) return false; 98004 } 98005 return true; 98006 } /** 98007 * This function parses the Binary STL files. 98008 * https://en.wikipedia.org/wiki/STL_%28file_format%29#Binary_STL 98009 * 98010 * Currently there is no support for the colors provided in STL files. 98011 */ 98012 98013 function parseBinarySTL(model, buffer) { 98014 var reader = new DataView(buffer); // Number of faces is present following the header 98015 var faces = reader.getUint32(80, true); 98016 var r, 98017 g, 98018 b, 98019 hasColors = false, 98020 colors; 98021 var defaultR, 98022 defaultG, 98023 defaultB; // Binary files contain 80-byte header, which is generally ignored. 98024 for (var index = 0; index < 80 - 10; index++) { 98025 // Check for `COLOR=` 98026 if (reader.getUint32(index, false) === 1129270351 /*COLO*/ 98027 && reader.getUint8(index + 4) === 82 /*'R'*/ 98028 && reader.getUint8(index + 5) === 61 /*'='*/ 98029 ) { 98030 hasColors = true; 98031 colors = [ 98032 ]; 98033 defaultR = reader.getUint8(index + 6) / 255; 98034 defaultG = reader.getUint8(index + 7) / 255; 98035 defaultB = reader.getUint8(index + 8) / 255; // To be used when color support is added 98036 // alpha = reader.getUint8(index + 9) / 255; 98037 } 98038 } 98039 var dataOffset = 84; 98040 var faceLength = 12 * 4 + 2; // Iterate the faces 98041 for (var face = 0; face < faces; face++) { 98042 var start = dataOffset + face * faceLength; 98043 var normalX = reader.getFloat32(start, true); 98044 var normalY = reader.getFloat32(start + 4, true); 98045 var normalZ = reader.getFloat32(start + 8, true); 98046 if (hasColors) { 98047 var packedColor = reader.getUint16(start + 48, true); 98048 if ((packedColor & 32768) === 0) { 98049 // facet has its own unique color 98050 r = (packedColor & 31) / 31; 98051 g = (packedColor >> 5 & 31) / 31; 98052 b = (packedColor >> 10 & 31) / 31; 98053 } else { 98054 r = defaultR; 98055 g = defaultG; 98056 b = defaultB; 98057 } 98058 } 98059 var newNormal = new _main.default.Vector(normalX, normalY, normalZ); 98060 for (var i = 1; i <= 3; i++) { 98061 var vertexstart = start + i * 12; 98062 var newVertex = new _main.default.Vector(reader.getFloat32(vertexstart, true), reader.getFloat32(vertexstart + 4, true), reader.getFloat32(vertexstart + 8, true)); 98063 model.vertices.push(newVertex); 98064 model.vertexNormals.push(newNormal); 98065 if (hasColors) { 98066 colors.push(r, g, b); 98067 } 98068 } 98069 model.faces.push([3 * face, 98070 3 * face + 1, 98071 3 * face + 2]); 98072 model.uvs.push([0, 98073 0], [ 98074 0, 98075 0 98076 ], [ 98077 0, 98078 0 98079 ]); 98080 } 98081 if (hasColors) { // add support for colors here. 98082 } 98083 return model; 98084 } /** 98085 * ASCII STL file starts with `solid 'nameOfFile'`
98086 * Then contain the normal of the face, starting with `facet normal` 98087 * Next contain a keyword indicating the start of face vertex, `outer loop` 98088 * Next comes the three vertex, starting with `vertex x y z` 98089 * Vertices ends with `endloop` 98090 * Face ends with `endfacet` 98091 * Next face starts with `facet normal` 98092 * The end of the file is indicated by `endsolid` 98093 */ 98094 98095 function parseASCIISTL(model, lines) { 98096 var state = ''; 98097 var curVertexIndex = [ 98098 ]; 98099 var newNormal, 98100 newVertex; 98101 for (var iterator = 0; iterator < lines.length; ++iterator) { 98102 var line = lines[iterator].trim(); 98103 var parts = line.split(' '); 98104 for (var partsiterator = 0; partsiterator < parts.length; ++partsiterator) { 98105 if (parts[partsiterator] === '') { 98106 // Ignoring multiple whitespaces 98107 parts.splice(partsiterator, 1); 98108 } 98109 } 98110 if (parts.length === 0) { 98111 // Remove newline 98112 continue; 98113 } 98114 switch (state) { 98115 case '': 98116 // First run 98117 if (parts[0] !== 'solid') { 98118 // Invalid state 98119 console.error(line); 98120 console.error('Invalid state "'.concat(parts[0], '", should be "solid"')); 98121 return; 98122 } else { 98123 state = 'solid'; 98124 } 98125 break; 98126 case 'solid': 98127 // First face 98128 if (parts[0] !== 'facet' || parts[1] !== 'normal') { 98129 // Invalid state 98130 console.error(line); 98131 console.error('Invalid state "'.concat(parts[0], '", should be "facet normal"')); 98132 return; 98133 } else { 98134 // Push normal for first face 98135 newNormal = new _main.default.Vector(parseFloat(parts[2]), parseFloat(parts[3]), parseFloat(parts[4])); 98136 model.vertexNormals.push(newNormal, newNormal, newNormal); 98137 state = 'facet normal'; 98138 } 98139 break; 98140 case 'facet normal': 98141 // After normal is defined 98142 if (parts[0] !== 'outer' || parts[1] !== 'loop') { 98143 // Invalid State 98144 console.error(line); 98145 console.error('Invalid state "'.concat(parts[0], '", should be "outer loop"')); 98146 return; 98147 } else { 98148 // Next should be vertices 98149 state = 'vertex'; 98150 } 98151 break; 98152 case 'vertex': 98153 if (parts[0] === 'vertex') { 98154 //Vertex of triangle 98155 newVertex = new _main.default.Vector(parseFloat(parts[1]), parseFloat(parts[2]), parseFloat(parts[3])); 98156 model.vertices.push(newVertex); 98157 model.uvs.push([0, 98158 0]); 98159 curVertexIndex.push(model.vertices.indexOf(newVertex)); 98160 } else if (parts[0] === 'endloop') { 98161 // End of vertices 98162 model.faces.push(curVertexIndex); 98163 curVertexIndex = [ 98164 ]; 98165 state = 'endloop'; 98166 } else { 98167 // Invalid State 98168 console.error(line); 98169 console.error('Invalid state "'.concat(parts[0], '", should be "vertex" or "endloop"')); 98170 return; 98171 } 98172 break; 98173 case 'endloop': 98174 if (parts[0] !== 'endfacet') { 98175 // End of face 98176 console.error(line); 98177 console.error('Invalid state "'.concat(parts[0], '", should be "endfacet"')); 98178 return; 98179 } else { 98180 state = 'endfacet'; 98181 } 98182 break; 98183 case 'endfacet': 98184 if (parts[0] === 'endsolid') { // End of solid 98185 } else if (parts[0] === 'facet' && parts[1] === 'normal') { 98186 // Next face 98187 newNormal = new _main.default.Vector(parseFloat(parts[2]), parseFloat(parts[3]), parseFloat(parts[4])); 98188 model.vertexNormals.push(newNormal, newNormal, newNormal); 98189 state = 'facet normal'; 98190 } else { 98191 // Invalid State 98192 console.error(line); 98193 console.error('Invalid state "'.concat(parts[0], '", should be "endsolid" or "facet normal"')); 98194 return; 98195 } 98196 break; 98197 default: 98198 console.error('Invalid state "'.concat(state, '"')); 98199 break; 98200 } 98201 } 98202 return model; 98203 } /** 98204 * Render a 3d model to the screen. 98205 * 98206 * @method model 98207 * @param {p5.Geometry} model Loaded 3d model to be rendered 98208 * @example 98209 * <div> 98210 * <code> 98211 * //draw a spinning octahedron 98212 * let octahedron; 98213 * 98214 * function preload() { 98215 * octahedron = loadModel('assets/octahedron.obj'); 98216 * } 98217 * 98218 * function setup() { 98219 * createCanvas(100, 100, WEBGL); 98220 * describe('Vertically rotating 3-d octahedron.'); 98221 * } 98222 * 98223 * function draw() { 98224 * background(200); 98225 * rotateX(frameCount * 0.01); 98226 * rotateY(frameCount * 0.01); 98227 * model(octahedron); 98228 * } 98229 * </code> 98230 * </div> 98231 * 98232 * @alt 98233 * Vertically rotating 3-d octahedron. 98234 */ 98235 98236 _main.default.prototype.model = function (model) { 98237 this._assert3d('model'); 98238 _main.default._validateParameters('model', arguments); 98239 if (model.vertices.length > 0) { 98240 if (!this._renderer.geometryInHash(model.gid)) { 98241 model._makeTriangleEdges()._edgesToVertices(); 98242 this._renderer.createBuffers(model.gid, model); 98243 } 98244 this._renderer.drawBuffers(model.gid); 98245 } 98246 }; 98247 var _default = _main.default; 98248 exports.default = _default; 98249 }, 98250 { 98251 '../core/main': 290, 98252 './p5.Geometry': 339,
98253 'core-js/modules/es.array.concat': 167, 98254 'core-js/modules/es.array.index-of': 175, 98255 'core-js/modules/es.array.slice': 180, 98256 'core-js/modules/es.array.splice': 182, 98257 'core-js/modules/es.object.to-string': 195, 98258 'core-js/modules/es.regexp.exec': 199, 98259 'core-js/modules/es.string.match': 205, 98260 'core-js/modules/es.string.split': 209, 98261 'core-js/modules/es.string.trim': 211 98262 } 98263 ], 98264 337: [ 98265 function (_dereq_, module, exports) { 98266 'use strict'; 98267 _dereq_('core-js/modules/es.symbol'); 98268 _dereq_('core-js/modules/es.symbol.description'); 98269 _dereq_('core-js/modules/es.symbol.iterator'); 98270 _dereq_('core-js/modules/es.array.iterator'); 98271 _dereq_('core-js/modules/es.array.join'); 98272 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 98273 _dereq_('core-js/modules/es.object.to-string'); 98274 _dereq_('core-js/modules/es.string.iterator'); 98275 _dereq_('core-js/modules/es.weak-map'); 98276 _dereq_('core-js/modules/web.dom-collections.iterator'); 98277 function _typeof2(obj) { 98278 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 98279 _typeof2 = function _typeof2(obj) { 98280 return typeof obj; 98281 }; 98282 } else { 98283 _typeof2 = function _typeof2(obj) { 98284 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 98285 }; 98286 } 98287 return _typeof2(obj); 98288 } 98289 function _typeof(obj) { 98290 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 98291 _typeof = function _typeof(obj) { 98292 return _typeof2(obj); 98293 }; 98294 } else { 98295 _typeof = function _typeof(obj) { 98296 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 98297 }; 98298 } 98299 return _typeof(obj); 98300 } 98301 _dereq_('core-js/modules/es.array.join'); 98302 Object.defineProperty(exports, '__esModule', { 98303 value: true 98304 }); 98305 exports.default = void 0; 98306 var _main = _interopRequireDefault(_dereq_('../core/main')); 98307 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 98308 _dereq_('./p5.Texture'); 98309 function _getRequireWildcardCache() { 98310 if (typeof WeakMap !== 'function') return null; 98311 var cache = new WeakMap(); 98312 _getRequireWildcardCache = function _getRequireWildcardCache() { 98313 return cache; 98314 }; 98315 return cache; 98316 } 98317 function _interopRequireWildcard(obj) { 98318 if (obj && obj.__esModule) { 98319 return obj; 98320 } 98321 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 98322 return { 98323 default: 98324 obj 98325 }; 98326 } 98327 var cache = _getRequireWildcardCache(); 98328 if (cache && cache.has(obj)) { 98329 return cache.get(obj); 98330 } 98331 var newObj = { 98332 }; 98333 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 98334 for (var key in obj) { 98335 if (Object.prototype.hasOwnProperty.call(obj, key)) { 98336 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 98337 if (desc && (desc.get || desc.set)) { 98338 Object.defineProperty(newObj, key, desc); 98339 } else { 98340 newObj[key] = obj[key]; 98341 } 98342 } 98343 } 98344 newObj.default = obj; 98345 if (cache) { 98346 cache.set(obj, newObj); 98347 } 98348 return newObj; 98349 } 98350 function _interopRequireDefault(obj) { 98351 return obj && obj.__esModule ? obj : { 98352 default: 98353 obj 98354 }; 98355 } /** 98356 * @module 3D 98357 * @submodule Material 98358 * @for p5 98359 * @requires core 98360 */ 98361 /** 98362 * Creates a new <a href="#/p5.Shader">p5.Shader</a> object 98363 * from the provided vertex and fragment shader files. 98364 * 98365 * The shader files are loaded asynchronously in the 98366 * background, so this method should be used in <a href="#/p5/preload">preload()</a>. 98367 *
98368 * Note, shaders can only be used in WEBGL mode. 98369 * 98370 * @method loadShader 98371 * @param {String} vertFilename path to file containing vertex shader 98372 * source code 98373 * @param {String} fragFilename path to file containing fragment shader 98374 * source code 98375 * @param {function} [callback] callback to be executed after loadShader 98376 * completes. On success, the p5.Shader object is passed as the first argument. 98377 * @param {function} [errorCallback] callback to be executed when an error 98378 * occurs inside loadShader. On error, the error is passed as the first 98379 * argument. 98380 * @return {p5.Shader} a shader object created from the provided 98381 * vertex and fragment shader files. 98382 * 98383 * @example 98384 * <div modernizr='webgl'> 98385 * <code> 98386 * let mandel; 98387 * function preload() { 98388 * // load the shader definitions from files 98389 * mandel = loadShader('assets/shader.vert', 'assets/shader.frag'); 98390 * } 98391 * function setup() { 98392 * createCanvas(100, 100, WEBGL); 98393 * // use the shader 98394 * shader(mandel); 98395 * noStroke(); 98396 * mandel.setUniform('p', [-0.74364388703, 0.13182590421]); 98397 * describe('zooming Mandelbrot set. a colorful, infinitely detailed fractal.'); 98398 * } 98399 * 98400 * function draw() { 98401 * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000)))); 98402 * quad(-1, -1, 1, -1, 1, 1, -1, 1); 98403 * } 98404 * </code> 98405 * </div> 98406 * 98407 * @alt 98408 * zooming Mandelbrot set. a colorful, infinitely detailed fractal. 98409 */ 98410 98411 _main.default.prototype.loadShader = function (vertFilename, fragFilename, callback, errorCallback) { 98412 _main.default._validateParameters('loadShader', arguments); 98413 if (!errorCallback) { 98414 errorCallback = console.error; 98415 } 98416 var loadedShader = new _main.default.Shader(); 98417 var self = this; 98418 var loadedFrag = false; 98419 var loadedVert = false; 98420 var onLoad = function onLoad() { 98421 self._decrementPreload(); 98422 if (callback) { 98423 callback(loadedShader); 98424 } 98425 }; 98426 this.loadStrings(vertFilename, function (result) { 98427 loadedShader._vertSrc = result.join('\n'); 98428 loadedVert = true; 98429 if (loadedFrag) { 98430 onLoad(); 98431 } 98432 }, errorCallback); 98433 this.loadStrings(fragFilename, function (result) { 98434 loadedShader._fragSrc = result.join('\n'); 98435 loadedFrag = true; 98436 if (loadedVert) { 98437 onLoad(); 98438 } 98439 }, errorCallback); 98440 return loadedShader; 98441 }; 98442 /** 98443 * Creates a new <a href="#/p5.Shader">p5.Shader</a> object 98444 * from the provided vertex and fragment shader code. 98445 * 98446 * Note, shaders can only be used in WEBGL mode. 98447 * 98448 * @method createShader 98449 * @param {String} vertSrc source code for the vertex shader 98450 * @param {String} fragSrc source code for the fragment shader 98451 * @returns {p5.Shader} a shader object created from the provided 98452 * vertex and fragment shaders. 98453 * 98454 * @example 98455 * <div modernizr='webgl'> 98456 * <code> 98457 * // the 'varying's are shared between both vertex & fragment shaders 98458 * let varying = 'precision highp float; varying vec2 vPos;'; 98459 * 98460 * // the vertex shader is called for each vertex 98461 * let vs = 98462 * varying + 98463 * 'attribute vec3 aPosition;' + 98464 * 'void main() { vPos = (gl_Position = vec4(aPosition,1.0)).xy; }'; 98465 * 98466 * // the fragment shader is called for each pixel 98467 * let fs = 98468 * varying + 98469 * 'uniform vec2 p;' + 98470 * 'uniform float r;' + 98471 * 'const int I = 500;' + 98472 * 'void main() {' + 98473 * ' vec2 c = p + vPos * r, z = c;' + 98474 * ' float n = 0.0;' + 98475 * ' for (int i = I; i > 0; i --) {' + 98476 * ' if(z.x*z.x+z.y*z.y > 4.0) {' + 98477 * ' n = float(i)/float(I);' + 98478 * ' break;' + 98479 * ' }' + 98480 * ' z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c;' + 98481 * ' }' + 98482 * ' gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0);' + 98483 * '}'; 98484 * 98485 * let mandel; 98486 * function setup() { 98487 * createCanvas(100, 100, WEBGL); 98488 * 98489 * // create and initialize the shader 98490 * mandel = createShader(vs, fs); 98491 * shader(mandel); 98492 * noStroke(); 98493 * 98494 * // 'p' is the center point of the Mandelbrot image 98495 * mandel.setUniform('p', [-0.74364388703, 0.13182590421]); 98496 * describe('zooming Mandelbrot set. a colorful, infinitely detailed fractal.'); 98497 * } 98498 * 98499 * function draw() { 98500 * // 'r' is the size of the image in Mandelbrot-space 98501 * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000)))); 98502 * quad(-1, -1, 1, -1, 1, 1, -1, 1); 98503 * } 98504 * </code> 98505 * </div> 98506 * 98507 * @alt 98508 * zooming Mandelbrot set. a colorful, infinitely detailed fractal. 98509 */ 98510 _main.default.prototype.createShader = function (vertSrc, fragSrc) { 98511 this._assert3d('createShader'); 98512 _main.default._validateParameters('createShader', arguments); 98513 return new _main.default.Shader(this._renderer, vertSrc, fragSrc); 98514 }; 98515 /** 98516 * Sets the <a href="#/p5.Shader">p5.Shader</a> object to 98517 * be used to render subsequent shapes. 98518 * 98519 * Custom shaders can be created using the 98520 * <a href="#/p5/createShader">createShader()</a> and 98521 * <a href="#/p5/loadShader">loadShader()</a> functions. 98522 * 98523 * Use <a href="#/p5/resetShader">resetShader()</a> to 98524 * restore the default shaders. 98525 *
98526 * Note, shaders can only be used in WEBGL mode. 98527 * 98528 * @method shader 98529 * @chainable 98530 * @param {p5.Shader} s the <a href="#/p5.Shader">p5.Shader</a> object 98531 * to use for rendering shapes. 98532 * 98533 * @example 98534 * <div modernizr='webgl'> 98535 * <code> 98536 * // Click within the image to toggle 98537 * // the shader used by the quad shape 98538 * // Note: for an alternative approach to the same example, 98539 * // involving changing uniforms please refer to: 98540 * // https://p5js.org/reference/#/p5.Shader/setUniform 98541 * 98542 * let redGreen; 98543 * let orangeBlue; 98544 * let showRedGreen = false; 98545 * 98546 * function preload() { 98547 * // note that we are using two instances 98548 * // of the same vertex and fragment shaders 98549 * redGreen = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); 98550 * orangeBlue = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); 98551 * } 98552 * 98553 * function setup() { 98554 * createCanvas(100, 100, WEBGL); 98555 * 98556 * // initialize the colors for redGreen shader 98557 * shader(redGreen); 98558 * redGreen.setUniform('colorCenter', [1.0, 0.0, 0.0]); 98559 * redGreen.setUniform('colorBackground', [0.0, 1.0, 0.0]); 98560 * 98561 * // initialize the colors for orangeBlue shader 98562 * shader(orangeBlue); 98563 * orangeBlue.setUniform('colorCenter', [1.0, 0.5, 0.0]); 98564 * orangeBlue.setUniform('colorBackground', [0.226, 0.0, 0.615]); 98565 * 98566 * noStroke(); 98567 * 98568 * describe( 98569 * 'canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.' 98570 * ); 98571 * } 98572 * 98573 * function draw() { 98574 * // update the offset values for each shader, 98575 * // moving orangeBlue in vertical and redGreen 98576 * // in horizontal direction 98577 * orangeBlue.setUniform('offset', [0, sin(millis() / 2000) + 1]); 98578 * redGreen.setUniform('offset', [sin(millis() / 2000), 1]); 98579 * 98580 * if (showRedGreen === true) { 98581 * shader(redGreen); 98582 * } else { 98583 * shader(orangeBlue); 98584 * } 98585 * quad(-1, -1, 1, -1, 1, 1, -1, 1); 98586 * } 98587 * 98588 * function mouseClicked() { 98589 * showRedGreen = !showRedGreen; 98590 * } 98591 * </code> 98592 * </div> 98593 * 98594 * @alt 98595 * canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed. 98596 */ 98597 _main.default.prototype.shader = function (s) { 98598 this._assert3d('shader'); 98599 _main.default._validateParameters('shader', arguments); 98600 if (s._renderer === undefined) { 98601 s._renderer = this._renderer; 98602 } 98603 s.init(); 98604 if (s.isStrokeShader()) { 98605 this._renderer.userStrokeShader = s; 98606 } else { 98607 this._renderer.userFillShader = s; 98608 this._renderer._useNormalMaterial = false; 98609 } 98610 return this; 98611 }; 98612 /** 98613 * Restores the default shaders. Code that runs after resetShader() 98614 * will not be affected by the shader previously set by 98615 * <a href="#/p5/shader">shader()</a> 98616 * 98617 * @method resetShader 98618 * @chainable 98619 * @example 98620 * <div> 98621 * <code> 98622 * // This variable will hold our shader object 98623 * let shaderProgram; 98624 * 98625 * // This variable will hold our vertex shader source code 98626 * let vertSrc = ` 98627 * attribute vec3 aPosition; 98628 * attribute vec2 aTexCoord; 98629 * uniform mat4 uProjectionMatrix; 98630 * uniform mat4 uModelViewMatrix; 98631 * varying vec2 vTexCoord; 98632 * 98633 * void main() { 98634 * vTexCoord = aTexCoord;
98635 * vec4 position = vec4(aPosition, 1.0); 98636 * gl_Position = uProjectionMatrix * uModelViewMatrix * position; 98637 * } 98638 * `; 98639 * 98640 * // This variable will hold our fragment shader source code 98641 * let fragSrc = ` 98642 * precision mediump float; 98643 * 98644 * varying vec2 vTexCoord; 98645 * 98646 * void main() { 98647 * vec2 uv = vTexCoord; 98648 * vec3 color = vec3(uv.x, uv.y, min(uv.x + uv.y, 1.0)); 98649 * gl_FragColor = vec4(color, 1.0); 98650 * } 98651 * `; 98652 * 98653 * function setup() { 98654 * // Shaders require WEBGL mode to work 98655 * createCanvas(100, 100, WEBGL); 98656 * 98657 * // Create our shader 98658 * shaderProgram = createShader(vertSrc, fragSrc); 98659 * 98660 * describe( 98661 * 'Two rotating cubes. The left one is painted using a custom (user-defined) shader, while the right one is painted using the default fill shader.' 98662 * ); 98663 * } 98664 * 98665 * function draw() { 98666 * // Clear the scene 98667 * background(200); 98668 * 98669 * // Draw a box using our shader 98670 * // shader() sets the active shader with our shader 98671 * shader(shaderProgram); 98672 * push(); 98673 * translate(-width / 4, 0, 0); 98674 * rotateX(millis() * 0.00025); 98675 * rotateY(millis() * 0.0005); 98676 * box(width / 4); 98677 * pop(); 98678 * 98679 * // Draw a box using the default fill shader 98680 * // resetShader() restores the default fill shader 98681 * resetShader(); 98682 * fill(255, 0, 0); 98683 * push(); 98684 * translate(width / 4, 0, 0); 98685 * rotateX(millis() * 0.00025); 98686 * rotateY(millis() * 0.0005); 98687 * box(width / 4); 98688 * pop(); 98689 * } 98690 * </code> 98691 * </div> 98692 * @alt 98693 * Two rotating cubes. The left one is painted using a custom (user-defined) shader, 98694 * while the right one is painted using the default fill shader. 98695 */ 98696 _main.default.prototype.resetShader = function () { 98697 this._renderer.userFillShader = this._renderer.userStrokeShader = null; 98698 return this; 98699 }; 98700 /** 98701 * Sets the texture that will be used to render subsequent shapes. 98702 * 98703 * A texture is like a "skin" that wraps around a 3D geometry. Currently 98704 * supported textures are images, video, and offscreen renders. 98705 * 98706 * To texture a geometry created with <a href="#/p5/beginShape">beginShape()</a>, 98707 * you will need to specify uv coordinates in <a href="#/p5/vertex">vertex()</a>. 98708 * 98709 * Note, texture() can only be used in WEBGL mode. 98710 * 98711 * You can view more materials in this 98712 * <a href="https://p5js.org/examples/3d-materials.html">example</a>. 98713 * 98714 * @method texture 98715 * @param {p5.Image|p5.MediaElement|p5.Graphics|p5.Texture} tex image to use as texture 98716 * @chainable 98717 * @example 98718 * <div> 98719 * <code> 98720 * let img; 98721 * function preload() { 98722 * img = loadImage('assets/laDefense.jpg'); 98723 * } 98724 * 98725 * function setup() { 98726 * createCanvas(100, 100, WEBGL); 98727 * describe('spinning cube with a texture from an image'); 98728 * } 98729 * 98730 * function draw() { 98731 * background(0); 98732 * rotateZ(frameCount * 0.01); 98733 * rotateX(frameCount * 0.01); 98734 * rotateY(frameCount * 0.01); 98735 * //pass image as texture 98736 * texture(img); 98737 * box(width / 2); 98738 * } 98739 * </code> 98740 * </div> 98741 * @alt 98742 * spinning cube with a texture from an image 98743 * 98744 * @example 98745 * <div> 98746 * <code> 98747 * let pg; 98748 * 98749 * function setup() { 98750 * createCanvas(100, 100, WEBGL); 98751 * pg = createGraphics(200, 200); 98752 * pg.textSize(75); 98753 * describe('plane with a texture from an image created by createGraphics()'); 98754 * } 98755 * 98756 * function draw() { 98757 * background(0); 98758 * pg.background(255); 98759 * pg.text('hello!', 0, 100); 98760 * //pass image as texture 98761 * texture(pg); 98762 * rotateX(0.5); 98763 * noStroke(); 98764 * plane(50); 98765 * } 98766 * </code> 98767 * </div> 98768 * @alt 98769 * plane with a texture from an image created by createGraphics() 98770 * 98771 * @example 98772 * <div> 98773 * <code> 98774 * let vid; 98775 * function preload() { 98776 * vid = createVideo('assets/fingers.mov'); 98777 * vid.hide(); 98778 * } 98779 * function setup() { 98780 * createCanvas(100, 100, WEBGL); 98781 * describe('rectangle with video as texture'); 98782 * } 98783 * 98784 * function draw() { 98785 * background(0); 98786 * //pass video frame as texture 98787 * texture(vid); 98788 * rect(-40, -40, 80, 80); 98789 * } 98790 * 98791 * function mousePressed() { 98792 * vid.loop(); 98793 * } 98794 * </code> 98795 * </div> 98796 * 98797 * @alt 98798 * rectangle with video as texture 98799 * 98800 * @example 98801 * <div> 98802 * <code> 98803 * let img; 98804 * 98805 * function preload() { 98806 * img = loadImage('assets/laDefense.jpg'); 98807 * } 98808 * 98809 * function setup() { 98810 * createCanvas(100, 100, WEBGL); 98811 * describe('quad with a texture, mapped using normalized coordinates'); 98812 * } 98813 * 98814 * function draw() { 98815 * background(0); 98816 * texture(img); 98817 * textureMode(NORMAL); 98818 * beginShape(); 98819 * vertex(-40, -40, 0, 0); 98820 * vertex(40, -40, 1, 0); 98821 * vertex(40, 40, 1, 1); 98822 * vertex(-40, 40, 0, 1); 98823 * endShape(); 98824 * } 98825 * </code> 98826 * </div> 98827 * @alt 98828 * quad with a texture, mapped using normalized coordinates 98829 */ 98830 _main.default.prototype.texture = function (tex) { 98831 this._assert3d('texture'); 98832 _main.default._validateParameters('texture', arguments); 98833 if (tex.gifProperties) { 98834 tex._animateGif(this); 98835 } 98836 this._renderer.drawMode = constants.TEXTURE; 98837 this._renderer._useSpecularMaterial = false;
98838 this._renderer._useEmissiveMaterial = false; 98839 this._renderer._useNormalMaterial = false; 98840 this._renderer._tex = tex; 98841 this._renderer._setProperty('_doFill', true); 98842 return this; 98843 }; 98844 /** 98845 * Sets the coordinate space for texture mapping. The default mode is IMAGE 98846 * which refers to the actual coordinates of the image. 98847 * NORMAL refers to a normalized space of values ranging from 0 to 1. 98848 * 98849 * With IMAGE, if an image is 100Ã200 pixels, mapping the image onto the entire 98850 * size of a quad would require the points (0,0) (100, 0) (100,200) (0,200). 98851 * The same mapping in NORMAL is (0,0) (1,0) (1,1) (0,1). 98852 * @method textureMode 98853 * @param {Constant} mode either IMAGE or NORMAL 98854 * @example 98855 * <div> 98856 * <code> 98857 * let img; 98858 * 98859 * function preload() { 98860 * img = loadImage('assets/laDefense.jpg'); 98861 * } 98862 * 98863 * function setup() { 98864 * createCanvas(100, 100, WEBGL); 98865 * describe('quad with a texture, mapped using normalized coordinates'); 98866 * } 98867 * 98868 * function draw() { 98869 * texture(img); 98870 * textureMode(NORMAL); 98871 * beginShape(); 98872 * vertex(-50, -50, 0, 0); 98873 * vertex(50, -50, 1, 0); 98874 * vertex(50, 50, 1, 1); 98875 * vertex(-50, 50, 0, 1); 98876 * endShape(); 98877 * } 98878 * </code> 98879 * </div> 98880 * @alt 98881 * quad with a texture, mapped using normalized coordinates 98882 * 98883 * @example 98884 * <div> 98885 * <code> 98886 * let img; 98887 * 98888 * function preload() { 98889 * img = loadImage('assets/laDefense.jpg'); 98890 * } 98891 * 98892 * function setup() { 98893 * createCanvas(100, 100, WEBGL); 98894 * describe('quad with a texture, mapped using image coordinates'); 98895 * } 98896 * 98897 * function draw() { 98898 * texture(img); 98899 * textureMode(IMAGE); 98900 * beginShape(); 98901 * vertex(-50, -50, 0, 0); 98902 * vertex(50, -50, img.width, 0); 98903 * vertex(50, 50, img.width, img.height); 98904 * vertex(-50, 50, 0, img.height); 98905 * endShape(); 98906 * } 98907 * </code> 98908 * </div> 98909 * @alt 98910 * quad with a texture, mapped using image coordinates 98911 */ 98912 _main.default.prototype.textureMode = function (mode) { 98913 if (mode !== constants.IMAGE && mode !== constants.NORMAL) { 98914 console.warn('You tried to set '.concat(mode, ' textureMode only supports IMAGE & NORMAL ')); 98915 } else { 98916 this._renderer.textureMode = mode; 98917 } 98918 }; 98919 /** 98920 * Sets the global texture wrapping mode. This controls how textures behave 98921 * when their uv's go outside of the 0 to 1 range. There are three options: 98922 * CLAMP, REPEAT, and MIRROR. 98923 * 98924 * CLAMP causes the pixels at the edge of the texture to extend to the bounds. 98925 * REPEAT causes the texture to tile repeatedly until reaching the bounds. 98926 * MIRROR works similarly to REPEAT but it flips the texture with every new tile. 98927 * 98928 * REPEAT & MIRROR are only available if the texture 98929 * is a power of two size (128, 256, 512, 1024, etc.). 98930 * 98931 * This method will affect all textures in your sketch until a subsequent 98932 * textureWrap() call is made. 98933 * 98934 * If only one argument is provided, it will be applied to both the 98935 * horizontal and vertical axes. 98936 * @method textureWrap 98937 * @param {Constant} wrapX either CLAMP, REPEAT, or MIRROR 98938 * @param {Constant} [wrapY] either CLAMP, REPEAT, or MIRROR 98939 * @example 98940 * <div> 98941 * <code> 98942 * let img; 98943 * function preload() { 98944 * img = loadImage('assets/rockies128.jpg'); 98945 * } 98946 * 98947 * function setup() { 98948 * createCanvas(100, 100, WEBGL); 98949 * textureWrap(MIRROR); 98950 * describe('an image of the rocky mountains repeated in mirrored tiles'); 98951 * } 98952 * 98953 * function draw() { 98954 * background(0); 98955 * 98956 * let dX = mouseX; 98957 * let dY = mouseY; 98958 * 98959 * let u = lerp(1.0, 2.0, dX); 98960 * let v = lerp(1.0, 2.0, dY); 98961 * 98962 * scale(width / 2); 98963 * 98964 * texture(img); 98965 * 98966 * beginShape(TRIANGLES); 98967 * vertex(-1, -1, 0, 0, 0); 98968 * vertex(1, -1, 0, u, 0); 98969 * vertex(1, 1, 0, u, v); 98970 * 98971 * vertex(1, 1, 0, u, v); 98972 * vertex(-1, 1, 0, 0, v); 98973 * vertex(-1, -1, 0, 0, 0); 98974 * endShape(); 98975 * } 98976 * </code> 98977 * </div> 98978 * 98979 * @alt 98980 * an image of the rocky mountains repeated in mirrored tiles 98981 */ 98982 _main.default.prototype.textureWrap = function (wrapX) { 98983 var wrapY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : wrapX; 98984 this._renderer.textureWrapX = wrapX; 98985 this._renderer.textureWrapY = wrapY; 98986 var textures = this._renderer.textures; 98987 for (var i = 0; i < textures.length; i++) { 98988 textures[i].setWrapMode(wrapX, wrapY); 98989 } 98990 }; 98991 /** 98992 * Sets the current material as a normal material. 98993 * 98994 * A normal material is not affected by light. It is often used as 98995 * a placeholder material when debugging. 98996 * 98997 * Surfaces facing the X-axis become red, those facing the Y-axis 98998 * become green, and those facing the Z-axis become blue. 98999 * 99000 * You can view more materials in this 99001 * <a href="https://p5js.org/examples/3d-materials.html">example</a>. 99002 * 99003 * @method normalMaterial 99004 * @chainable 99005 * @example 99006 * <div> 99007 * <code> 99008 * function setup() { 99009 * createCanvas(100, 100, WEBGL); 99010 * describe('Sphere with normal material'); 99011 * } 99012 * 99013 * function draw() { 99014 * background(200); 99015 * normalMaterial(); 99016 * sphere(40); 99017 * } 99018 * </code> 99019 * </div> 99020 * @alt 99021 * Sphere with normal material 99022 */ 99023 _main.default.prototype.normalMaterial = function () { 99024 this._assert3d('normalMaterial'); 99025 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 99026 args[_key] = arguments[_key]; 99027 } 99028 _main.default._validateParameters('normalMaterial', args); 99029 this._renderer.drawMode = constants.FILL; 99030 this._renderer._useSpecularMaterial = false;
99031 this._renderer._useEmissiveMaterial = false; 99032 this._renderer._useNormalMaterial = true; 99033 this._renderer.curFillColor = [ 99034 1, 99035 1, 99036 1, 99037 1 99038 ]; 99039 this._renderer._setProperty('_doFill', true); 99040 this.noStroke(); 99041 return this; 99042 }; 99043 /** 99044 * Sets the ambient color of the material. 99045 * 99046 * The ambientMaterial() color is the color the object will reflect 99047 * under **any** lighting. 99048 * 99049 * Consider an ambientMaterial() with the color yellow (255, 255, 0). 99050 * If the light emits the color white (255, 255, 255), then the object 99051 * will appear yellow as it will reflect the red and green components 99052 * of the light. If the light emits the color red (255, 0, 0), then 99053 * the object will appear red as it will reflect the red component 99054 * of the light. If the light emits the color blue (0, 0, 255), 99055 * then the object will appear black, as there is no component of 99056 * the light that it can reflect. 99057 * 99058 * You can view more materials in this 99059 * <a href="https://p5js.org/examples/3d-materials.html">example</a>. 99060 * 99061 * @method ambientMaterial 99062 * @param {Number} v1 red or hue value relative to the current 99063 * color range 99064 * @param {Number} v2 green or saturation value relative to the 99065 * current color range 99066 * @param {Number} v3 blue or brightness value relative to the 99067 * current color range 99068 * @chainable 99069 * @example 99070 * <div> 99071 * <code> 99072 * function setup() { 99073 * createCanvas(100, 100, WEBGL); 99074 * describe('sphere reflecting red, blue, and green light'); 99075 * } 99076 * function draw() { 99077 * background(0); 99078 * noStroke(); 99079 * ambientLight(255); 99080 * ambientMaterial(70, 130, 230); 99081 * sphere(40); 99082 * } 99083 * </code> 99084 * </div> 99085 * @alt 99086 * sphere reflecting red, blue, and green light 99087 * 99088 * @example 99089 * <div> 99090 * <code> 99091 * // ambientLight is both red and blue (magenta), 99092 * // so object only reflects it's red and blue components 99093 * function setup() { 99094 * createCanvas(100, 100, WEBGL); 99095 * describe('box reflecting only red and blue light'); 99096 * } 99097 * function draw() { 99098 * background(70); 99099 * ambientLight(255, 0, 255); // magenta light 99100 * ambientMaterial(255); // white material 99101 * box(30); 99102 * } 99103 * </code> 99104 * </div> 99105 * @alt 99106 * box reflecting only red and blue light 99107 * 99108 * @example 99109 * <div> 99110 * <code> 99111 * // ambientLight is green. Since object does not contain 99112 * // green, it does not reflect any light 99113 * function setup() { 99114 * createCanvas(100, 100, WEBGL); 99115 * describe('box reflecting no light'); 99116 * } 99117 * function draw() { 99118 * background(70); 99119 * ambientLight(0, 255, 0); // green light 99120 * ambientMaterial(255, 0, 255); // magenta material 99121 * box(30); 99122 * } 99123 * </code> 99124 * </div> 99125 * @alt 99126 * box reflecting no light 99127 */ 99128 /** 99129 * @method ambientMaterial 99130 * @param {Number} gray number specifying value between 99131 * white and black 99132 * @chainable 99133 */ 99134 /** 99135 * @method ambientMaterial 99136 * @param {p5.Color|Number[]|String} color 99137 * color as a <a href="#/p5.Color">p5.Color</a>, 99138 * as an array, or as a CSS string 99139 * @chainable 99140 */ 99141 _main.default.prototype.ambientMaterial = function (v1, v2, v3) { 99142 this._assert3d('ambientMaterial'); 99143 _main.default._validateParameters('ambientMaterial', arguments); 99144 var color = _main.default.prototype.color.apply(this, arguments); 99145 this._renderer.curAmbientColor = color._array; 99146 this._renderer._useNormalMaterial = false; 99147 this._renderer._enableLighting = true; 99148 this._renderer._tex = null; 99149 this._renderer._setProperty('_doFill', true); 99150 return this; 99151 }; 99152 /** 99153 * Sets the emissive color of the material. 99154 * 99155 * An emissive material will display the emissive color at 99156 * full strength regardless of lighting. This can give the 99157 * appearance that the object is glowing. 99158 * 99159 * Note, "emissive" is a misnomer in the sense that the material 99160 * does not actually emit light that will affect surrounding objects. 99161 * 99162 * You can view more materials in this 99163 * <a href="https://p5js.org/examples/3d-materials.html">example</a>. 99164 * 99165 * @method emissiveMaterial 99166 * @param {Number} v1 red or hue value relative to the current 99167 * color range 99168 * @param {Number} v2 green or saturation value relative to the 99169 * current color range 99170 * @param {Number} v3 blue or brightness value relative to the 99171 * current color range 99172 * @param {Number} [alpha] alpha value relative to current color 99173 * range (default is 0-255) 99174 * @chainable 99175 * @example 99176 * <div> 99177 * <code> 99178 * function setup() { 99179 * createCanvas(100, 100, WEBGL); 99180 * describe('sphere with green emissive material'); 99181 * } 99182 * function draw() { 99183 * background(0); 99184 * noStroke(); 99185 * ambientLight(0); 99186 * emissiveMaterial(130, 230, 0); 99187 * sphere(40); 99188 * } 99189 * </code> 99190 * </div> 99191 * 99192 * @alt 99193 * sphere with green emissive material 99194 */ 99195 /** 99196 * @method emissiveMaterial 99197 * @param {Number} gray number specifying value between 99198 * white and black 99199 * @chainable 99200 */ 99201 /** 99202 * @method emissiveMaterial 99203 * @param {p5.Color|Number[]|String} color 99204 * color as a <a href="#/p5.Color">p5.Color</a>, 99205 * as an array, or as a CSS string 99206 * @chainable 99207 */ 99208 _main.default.prototype.emissiveMaterial = function (v1, v2, v3, a) { 99209 this._assert3d('emissiveMaterial'); 99210 _main.default._validateParameters('emissiveMaterial', arguments); 99211 var color = _main.default.prototype.color.apply(this, arguments); 99212 this._renderer.curEmissiveColor = color._array; 99213 this._renderer._useEmissiveMaterial = true; 99214 this._renderer._useNormalMaterial = false;
99215 this._renderer._enableLighting = true; 99216 this._renderer._tex = null; 99217 return this; 99218 }; 99219 /** 99220 * Sets the specular color of the material. 99221 * 99222 * A specular material is reflective (shiny). The shininess can be 99223 * controlled by the <a href="#/p5/shininess">shininess()</a> function. 99224 * 99225 * Like <a href="#/p5/ambientMaterial">ambientMaterial()</a>, 99226 * the specularMaterial() color is the color the object will reflect 99227 * under <a href="#/p5/ambientLight">ambientLight()</a>. 99228 * However unlike ambientMaterial(), for all other types of lights 99229 * (<a href="#/p5/directionalLight">directionalLight()</a>, 99230 * <a href="#/p5/pointLight">pointLight()</a>, 99231 * <a href="#/p5/spotLight">spotLight()</a>), 99232 * a specular material will reflect the **color of the light source**. 99233 * This is what gives it its "shiny" appearance. 99234 * 99235 * You can view more materials in this 99236 * <a href="https://p5js.org/examples/3d-materials.html">example</a>. 99237 * 99238 * @method specularMaterial 99239 * @param {Number} gray number specifying value between white and black. 99240 * @param {Number} [alpha] alpha value relative to current color range 99241 * (default is 0-255) 99242 * @chainable 99243 * 99244 * @example 99245 * <div> 99246 * <code> 99247 * function setup() { 99248 * createCanvas(100, 100, WEBGL); 99249 * noStroke(); 99250 * describe('torus with specular material'); 99251 * } 99252 * 99253 * function draw() { 99254 * background(0); 99255 * 99256 * ambientLight(60); 99257 * 99258 * // add point light to showcase specular material 99259 * let locX = mouseX - width / 2; 99260 * let locY = mouseY - height / 2; 99261 * pointLight(255, 255, 255, locX, locY, 50); 99262 * 99263 * specularMaterial(250); 99264 * shininess(50); 99265 * torus(30, 10, 64, 64); 99266 * } 99267 * </code> 99268 * </div> 99269 * @alt 99270 * torus with specular material 99271 */ 99272 /** 99273 * @method specularMaterial 99274 * @param {Number} v1 red or hue value relative to 99275 * the current color range 99276 * @param {Number} v2 green or saturation value 99277 * relative to the current color range 99278 * @param {Number} v3 blue or brightness value 99279 * relative to the current color range 99280 * @param {Number} [alpha] 99281 * @chainable 99282 */ 99283 /** 99284 * @method specularMaterial 99285 * @param {p5.Color|Number[]|String} color 99286 * color as a <a href="#/p5.Color">p5.Color</a>, 99287 * as an array, or as a CSS string 99288 * @chainable 99289 */ 99290 _main.default.prototype.specularMaterial = function (v1, v2, v3, alpha) { 99291 this._assert3d('specularMaterial'); 99292 _main.default._validateParameters('specularMaterial', arguments); 99293 var color = _main.default.prototype.color.apply(this, arguments); 99294 this._renderer.curSpecularColor = color._array; 99295 this._renderer._useSpecularMaterial = true; 99296 this._renderer._useNormalMaterial = false; 99297 this._renderer._enableLighting = true; 99298 this._renderer._tex = null; 99299 return this; 99300 }; 99301 /** 99302 * Sets the amount of gloss ("shininess") of a 99303 * <a href="#/p5/specularMaterial">specularMaterial()</a>. 99304 * 99305 * The default and minimum value is 1. 99306 * 99307 * @method shininess 99308 * @param {Number} shine degree of shininess 99309 * @chainable 99310 * @example 99311 * <div> 99312 * <code> 99313 * function setup() { 99314 * createCanvas(100, 100, WEBGL); 99315 * describe('two spheres, one more shiny than the other'); 99316 * } 99317 * function draw() { 99318 * background(0); 99319 * noStroke(); 99320 * let locX = mouseX - width / 2; 99321 * let locY = mouseY - height / 2; 99322 * ambientLight(60, 60, 60); 99323 * pointLight(255, 255, 255, locX, locY, 50); 99324 * specularMaterial(250); 99325 * translate(-25, 0, 0); 99326 * shininess(1); 99327 * sphere(20); 99328 * translate(50, 0, 0); 99329 * shininess(20); 99330 * sphere(20); 99331 * } 99332 * </code> 99333 * </div> 99334 * @alt 99335 * two spheres, one more shiny than the other 99336 */ 99337 _main.default.prototype.shininess = function (shine) { 99338 this._assert3d('shininess'); 99339 _main.default._validateParameters('shininess', arguments); 99340 if (shine < 1) { 99341 shine = 1; 99342 } 99343 this._renderer._useShininess = shine; 99344 return this; 99345 }; 99346 /** 99347 * @private blends colors according to color components. 99348 * If alpha value is less than 1, or non-standard blendMode 99349 * we need to enable blending on our gl context. 99350 * @param {Number[]} color [description] 99351 * @return {Number[]]} Normalized numbers array 99352 */ 99353 _main.default.RendererGL.prototype._applyColorBlend = function (colors) { 99354 var gl = this.GL; 99355 var isTexture = this.drawMode === constants.TEXTURE; 99356 var doBlend = this.userFillShader || this.userStrokeShader || this.userPointShader || isTexture || this.curBlendM
99356ode !== constants.BLEND || colors[colors.length - 1] < 1 || this._isErasing; 99357 if (doBlend !== this._isBlending) { 99358 if (doBlend || this.curBlendMode !== constants.BLEND && this.curBlendMode !== constants.ADD) { 99359 gl.enable(gl.BLEND); 99360 } else { 99361 gl.disable(gl.BLEND); 99362 } 99363 gl.depthMask(true); 99364 this._isBlending = doBlend; 99365 } 99366 this._applyBlendMode(); 99367 return colors; 99368 }; 99369 /** 99370 * @private sets blending in gl context to curBlendMode 99371 * @param {Number[]} color [description] 99372 * @return {Number[]]} Normalized numbers array 99373 */ 99374 _main.default.RendererGL.prototype._applyBlendMode = function () { 99375 if (this._cachedBlendMode === this.curBlendMode) { 99376 return; 99377 } 99378 var gl = this.GL; 99379 switch (this.curBlendMode) { 99380 case constants.BLEND: 99381 gl.blendEquation(gl.FUNC_ADD); 99382 gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); 99383 break; 99384 case constants.ADD: 99385 gl.blendEquation(gl.FUNC_ADD); 99386 gl.blendFunc(gl.ONE, gl.ONE); 99387 break; 99388 case constants.REMOVE: 99389 gl.blendEquation(gl.FUNC_ADD); 99390 gl.blendFunc(gl.ZERO, gl.ONE_MINUS_SRC_ALPHA); 99391 break; 99392 case constants.MULTIPLY: 99393 gl.blendEquation(gl.FUNC_ADD); 99394 gl.blendFunc(gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA); 99395 break; 99396 case constants.SCREEN: 99397 gl.blendEquation(gl.FUNC_ADD); 99398 gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR); 99399 break; 99400 case constants.EXCLUSION: 99401 gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD); 99402 gl.blendFuncSeparate(gl.ONE_MINUS_DST_COLOR, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE); 99403 break; 99404 case constants.REPLACE: 99405 gl.blendEquation(gl.FUNC_ADD); 99406 gl.blendFunc(gl.ONE, gl.ZERO); 99407 break; 99408 case constants.SUBTRACT: 99409 gl.blendEquationSeparate(gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD); 99410 gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); 99411 break; 99412 case constants.DARKEST: 99413 if (this.blendExt) { 99414 gl.blendEquationSeparate(this.blendExt.MIN_EXT, gl.FUNC_ADD); 99415 gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE); 99416 } else { 99417 console.warn('blendMode(DARKEST) does not work in your browser in WEBGL mode.'); 99418 } 99419 break; 99420 case constants.LIGHTEST: 99421 if (this.blendExt) { 99422 gl.blendEquationSeparate(this.blendExt.MAX_EXT, gl.FUNC_ADD); 99423 gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE); 99424 } else { 99425 console.warn('blendMode(LIGHTEST) does not work in your browser in WEBGL mode.'); 99426 } 99427 break; 99428 default: 99429 console.error('Oops! Somehow RendererGL set curBlendMode to an unsupported mode.'); 99430 break; 99431 } 99432 if (!this._isErasing) { 99433 this._cachedBlendMode = this.curBlendMode; 99434 } 99435 }; 99436 var _default = _main.default; 99437 exports.default = _default; 99438 }, 99439 { 99440 '../core/constants': 278, 99441 '../core/main': 290, 99442 './p5.Texture': 346, 99443 'core-js/modules/es.array.iterator': 176, 99444 'core-js/modules/es.array.join': 177, 99445 'core-js/modules/es.object.get-own-property-descriptor': 191, 99446 'core-js/modules/es.object.to-string': 195, 99447 'core-js/modules/es.string.iterator': 204, 99448 'core-js/modules/es.symbol': 214, 99449 'core-js/modules/es.symbol.description': 212, 99450 'core-js/modules/es.symbol.iterator': 213, 99451 'core-js/modules/es.weak-map': 246, 99452 'core-js/modules/web.dom-collections.iterator': 248 99453 } 99454 ], 99455 338: [ 99456 function (_dereq_, module, exports) { 99457 'use strict'; 99458 Object.defineProperty(exports, '__esModule', { 99459 value: true 99460 }); 99461 exports.default = void 0; 99462 var _main = _interopRequireDefault(_dereq_('../core/main')); 99463 function _interopRequireDefault(obj) { 99464 return obj && obj.__esModule ? obj : { 99465 default: 99466 obj 99467 }; 99468 } /** 99469 * @module 3D 99470 * @submodule Camera 99471 * @requires core 99472 */
99473 //////////////////////////////////////////////////////////////////////////////// 99474 // p5.Prototype Methods 99475 //////////////////////////////////////////////////////////////////////////////// 99476 /** 99477 * Sets the position of the current camera in a 3D sketch. 99478 * Parameters for this function define the camera's position, 99479 * the center of the sketch (where the camera is pointing), 99480 * and an up direction (the orientation of the camera). 99481 * 99482 * This function simulates the movements of the camera, allowing objects to be 99483 * viewed from various angles. Remember, it does not move the objects themselves 99484 * but the camera instead. For example when the centerX value is positive, 99485 * and the camera is rotating to the right side of the sketch, 99486 * the object will seem like it's moving to the left. 99487 * 99488 * See this <a href = "https://www.openprocessing.org/sketch/740258">example</a> 99489 * to view the position of your camera. 99490 * 99491 * If no parameters are given, the following default is used: 99492 * camera(0, 0, (height/2) / tan(PI/6), 0, 0, 0, 0, 1, 0) 99493 * @method camera 99494 * @constructor 99495 * @for p5 99496 * @param {Number} [x] camera position value on x axis 99497 * @param {Number} [y] camera position value on y axis 99498 * @param {Number} [z] camera position value on z axis 99499 * @param {Number} [centerX] x coordinate representing center of the sketch 99500 * @param {Number} [centerY] y coordinate representing center of the sketch 99501 * @param {Number} [centerZ] z coordinate representing center of the sketch 99502 * @param {Number} [upX] x component of direction 'up' from camera 99503 * @param {Number} [upY] y component of direction 'up' from camera 99504 * @param {Number} [upZ] z component of direction 'up' from camera 99505 * @chainable 99506 * @example 99507 * <div> 99508 * <code> 99509 * function setup() { 99510 * createCanvas(100, 100, WEBGL); 99511 * describe('a square moving closer and then away from the camera.'); 99512 * } 99513 * function draw() { 99514 * background(204); 99515 * //move the camera away from the plane by a sin wave 99516 * camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0); 99517 * plane(10, 10); 99518 * } 99519 * </code> 99520 * </div> 99521 * 99522 * @example 99523 * <div> 99524 * <code> 99525 * //move slider to see changes! 99526 * //sliders control the first 6 parameters of camera() 99527 * let sliderGroup = []; 99528 * let X; 99529 * let Y; 99530 * let Z; 99531 * let centerX; 99532 * let centerY; 99533 * let centerZ; 99534 * let h = 20; 99535 * 99536 * function setup() { 99537 * createCanvas(100, 100, WEBGL); 99538 * //create sliders 99539 * for (var i = 0; i < 6; i++) { 99540 * if (i === 2) { 99541 * sliderGroup[i] = createSlider(10, 400, 200); 99542 * } else { 99543 * sliderGroup[i] = createSlider(-400, 400, 0); 99544 * } 99545 * h = map(i, 0, 6, 5, 85); 99546 * sliderGroup[i].position(10, height + h); 99547 * sliderGroup[i].style('width', '80px'); 99548 * } 99549 * describe( 99550 * 'White square repeatedly grows to fill canvas and then shrinks. An interactive example of a red cube with 3 sliders for moving it across x, y, z axis and 3 sliders for shifting its center.' 99551 * ); 99552 * } 99553 * 99554 * function draw() { 99555 * background(60); 99556 * // assigning sliders' value to each parameters 99557 * X = sliderGroup[0].value(); 99558 * Y = sliderGroup[1].value(); 99559 * Z = sliderGroup[2].value(); 99560 * centerX = sliderGroup[3].value(); 99561 * centerY = sliderGroup[4].value(); 99562 * centerZ = sliderGroup[5].value(); 99563 * camera(X, Y, Z, centerX, centerY, centerZ, 0, 1, 0); 99564 * stroke(255); 99565 * fill(255, 102, 94); 99566 * box(85); 99567 * } 99568 * </code> 99569 * </div> 99570 * @alt 99571 * White square repeatedly grows to fill canvas and then shrinks. 99572 * An interactive example of a red cube with 3 sliders for moving it across x, y, 99573 * z axis and 3 sliders for shifting its center. 99574 */ 99575 99576 _main.default.prototype.camera = function () { 99577 var _this$_renderer$_curC; 99578 this._assert3d('camera'); 99579 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 99580 args[_key] = arguments[_key]; 99581 } 99582 _main.default._validateParameters('camera', args); 99583 (_this$_renderer$_curC = this._renderer._curCamera).camera.apply(_this$_renderer$_curC, args); 99584 return this; 99585 }; 99586 /** 99587 * Sets a perspective projection for the current camera in a 3D sketch. 99588 * This projection represents depth through foreshortening: objects 99589 * that are close to the camera appear their actual size while those 99590 * that are further away from the camera appear smaller. 99591 * 99592 * The parameters to this function define the viewing frustum 99593 * (the truncated pyramid within which objects are seen by the camera) through 99594 * vertical field of view, aspect ratio (usually width/height), and near and far 99595 * clipping planes. 99596 * 99597 * If no parameters are given, the following default is used: 99598 * perspective(PI/3, width/height, eyeZ/10, eyeZ*10), 99599 * where eyeZ is equal to ((height/2) / tan(PI/6)). 99600 * @method perspective 99601 * @for p5 99602 * @param {Number} [fovy] camera frustum vertical field of view, 99603 * from bottom to top of view, in <a href="#/p5/angleMode">angleMode</a> units 99604 * @param {Number} [aspect] camera frustum aspect ratio 99605 * @param {Number} [near] frustum near plane length 99606 * @param {Number} [far] frustum far plane length 99607 * @chainable 99608 * @example 99609 * <div> 99610 * <code> 99611 * //drag the mouse to look around! 99612 * function setup() { 99613 * createCanvas(100, 100, WEBGL); 99614 * perspective(PI / 3.0, width / height, 0.1, 500); 99615 * describe( 99616 * 'two colored 3D boxes move back and forth, rotating as mouse is dragged.' 99617 * ); 99618 * } 99619 * function draw() { 99620 * background(200); 99621 * orbitControl(); 99622 * normalMaterial(); 99623 * 99624 * rotateX(-0.3); 99625 * rotateY(-0.2); 99626 * translate(0, 0, -50); 99627 * 99628 * push(); 99629 * translate(-15, 0, sin(frameCount / 30) * 95); 99630 * box(30); 99631 * pop(); 99632 * push(); 99633 * translate(15, 0, sin(frameCount / 30 + PI) * 95); 99634 * box(30); 99635 * pop(); 99636 * } 99637 * </code> 99638 * </div> 99639 * 99640 * @alt 99641 * two colored 3D boxes move back and forth, rotating as mouse is dragged. 99642 */ 99643 _main.default.prototype.perspective = function () { 99644 var _this$_renderer$_curC2; 99645 this._assert3d('perspective'); 99646 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 99647 args[_key2] = arguments[_key2]; 99648 } 99649 _main.default._validateParameters('perspective', args); 99650 (_this$_renderer$_curC2 = this._renderer._curCamera).perspective.apply(_this$_renderer$_curC2, args); 99651 return this; 99652 }; 99653 /** 99654 * Sets an orthographic projection for the current camera in a 3D sketch 99655 * and defines a box-shaped viewing frustum within which objects are seen. 99656 * In this projection, all objects with the same dimension appear the same 99657 * size, regardless of whether they are near or far from the camera. 99658 * 99659 * The parameters to this function specify the viewing frustum where 99660 * left and right are the minimum and maximum x values, top and bottom are 99661 * the minimum and maximum y values, and near and far are the minimum and 99662 * maximum z values. 99663 * 99664 * If no parameters are given, the following default is used: 99665 * ortho(-width/2, width/2, -height/2, height/2). 99666 * @method ortho 99667 * @for p5 99668 * @param {Number} [left] camera frustum left plane 99669 * @param {Number} [right] camera frustum right plane 99670 * @param {Number} [bottom] camera frustum bottom plane 99671 * @param {Number} [top] camera frustum top plane 99672 * @param {Number} [near] camera frustum near plane 99673 * @param {Number} [far] camera frustum far plane 99674 * @chainable 99675 * @example 99676 * <div> 99677 * <code> 99678 * //drag the mouse to look around! 99679 * //there's no vanishing point 99680 * function setup() { 99681 * createCanvas(100, 100, WEBGL); 99682 * ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500); 99683 * describe( 99684 * 'two 3D boxes move back and forth along same plane, rotating as mouse is dragged.' 99685 * ); 99686 * } 99687 * function draw() { 99688 * background(200); 99689 * orbitControl(); 99690 * normalMaterial(); 99691 * 99692 * rotateX(0.2); 99693 * rotateY(-0.2); 99694 * push(); 99695 * translate(-15, 0, sin(frameCount / 30) * 65); 99696 * box(30); 99697 * pop(); 99698 * push(); 99699 * translate(15, 0, sin(frameCount / 30 + PI) * 65); 99700 * box(30); 99701 * pop(); 99702 * } 99703 * </code> 99704 * </div> 99705 * 99706 * @alt 99707 * two 3D boxes move back and forth along same plane, rotating as mouse is dragged. 99708 */ 99709 _main.default.prototype.ortho = function () { 99710 var _this$_renderer$_curC3; 99711 this._assert3d('ortho'); 99712 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 99713 args[_key3] = arguments[_key3]; 99714 } 99715 _main.default._validateParameters('ortho', args); 99716 (_this$_renderer$_curC3 = this._renderer._curCamera).ortho.apply(_this$_renderer$_curC3, args); 99717 return this; 99718 }; 99719 /** 99720 * Sets the frustum of the current camera as defined by 99721 * the parameters. 99722 * 99723 * A frustum is a geometric form: a pyramid with its top 99724 * cut off. With the viewer's eye at the imaginary top of
99725 * the pyramid, the six planes of the frustum act as clipping 99726 * planes when rendering a 3D view. Thus, any form inside the 99727 * clipping planes is visible; anything outside 99728 * those planes is not visible. 99729 * 99730 * Setting the frustum changes the perspective of the scene being rendered. 99731 * This can be achieved more simply in many cases by using 99732 * <a href="https://p5js.org/reference/#/p5/perspective">perspective()</a>. 99733 * 99734 * If no parameters are given, the following default is used: 99735 * frustum(-width/2, width/2, -height/2, height/2, 0, max(width, height)). 99736 * @method frustum 99737 * @for p5 99738 * @param {Number} [left] camera frustum left plane 99739 * @param {Number} [right] camera frustum right plane 99740 * @param {Number} [bottom] camera frustum bottom plane 99741 * @param {Number} [top] camera frustum top plane 99742 * @param {Number} [near] camera frustum near plane 99743 * @param {Number} [far] camera frustum far plane 99744 * @chainable 99745 * @example 99746 * <div> 99747 * <code> 99748 * function setup() { 99749 * createCanvas(100, 100, WEBGL); 99750 * setAttributes('antialias', true); 99751 * frustum(-0.1, 0.1, -0.1, 0.1, 0.1, 200); 99752 * describe( 99753 * 'two 3D boxes move back and forth along same plane, rotating as mouse is dragged.' 99754 * ); 99755 * } 99756 * function draw() { 99757 * background(200); 99758 * orbitControl(); 99759 * normalMaterial(); 99760 * 99761 * rotateY(-0.2); 99762 * rotateX(-0.3); 99763 * push(); 99764 * translate(-15, 0, sin(frameCount / 30) * 25); 99765 * box(30); 99766 * pop(); 99767 * push(); 99768 * translate(15, 0, sin(frameCount / 30 + PI) * 25); 99769 * box(30); 99770 * pop(); 99771 * } 99772 * </code> 99773 * </div> 99774 * 99775 * @alt 99776 * two 3D boxes move back and forth along same plane, rotating as mouse is dragged. 99777 */ 99778 _main.default.prototype.frustum = function () { 99779 var _this$_renderer$_curC4; 99780 this._assert3d('frustum'); 99781 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { 99782 args[_key4] = arguments[_key4]; 99783 } 99784 _main.default._validateParameters('frustum', args); 99785 (_this$_renderer$_curC4 = this._renderer._curCamera).frustum.apply(_this$_renderer$_curC4, args); 99786 return this; 99787 }; //////////////////////////////////////////////////////////////////////////////// 99788 // p5.Camera
99789 //////////////////////////////////////////////////////////////////////////////// 99790 /** 99791 * Creates a new <a href="#/p5.Camera">p5.Camera</a> object and sets it 99792 * as the current (active) camera. 99793 * 99794 * The new camera is initialized with a default position 99795 * (see <a href="#/p5.Camera/camera">camera()</a>) 99796 * and a default perspective projection 99797 * (see <a href="#/p5.Camera/perspective">perspective()</a>). 99798 * Its properties can be controlled with the <a href="#/p5.Camera">p5.Camera</a> 99799 * methods. 99800 * 99801 * Note: Every 3D sketch starts with a default camera initialized. 99802 * This camera can be controlled with the global methods 99803 * <a href="#/p5/camera">camera()</a>, 99804 * <a href="#/p5/perspective">perspective()</a>, <a href="#/p5/ortho">ortho()</a>, 99805 * and <a href="#/p5/frustum">frustum()</a> if it is the only camera 99806 * in the scene. 99807 * @method createCamera 99808 * @return {p5.Camera} The newly created camera object. 99809 * @for p5 99810 * @example 99811 * <div><code> 99812 * // Creates a camera object and animates it around a box. 99813 * let camera; 99814 * function setup() { 99815 * createCanvas(100, 100, WEBGL); 99816 * background(0); 99817 * camera = createCamera(); 99818 * describe('An example that creates a camera and moves it around the box.'); 99819 * } 99820 * 99821 * function draw() { 99822 * background(0); 99823 * // The camera will automatically 99824 * // rotate to look at [0, 0, 0]. 99825 * camera.lookAt(0, 0, 0); 99826 * 99827 * // The camera will move on the 99828 * // x axis. 99829 * camera.setPosition(sin(frameCount / 60) * 200, 0, 100); 99830 * box(20); 99831 * 99832 * // A 'ground' box to give the viewer 99833 * // a better idea of where the camera 99834 * // is looking. 99835 * translate(0, 50, 0); 99836 * rotateX(HALF_PI); 99837 * box(150, 150, 20); 99838 * } 99839 * </code></div> 99840 * 99841 * @alt 99842 * An example that creates a camera and moves it around the box. 99843 */ 99844 _main.default.prototype.createCamera = function () { 99845 this._assert3d('createCamera'); 99846 var _cam = new _main.default.Camera(this._renderer); // compute default camera settings, then set a default camera 99847 _cam._computeCameraDefaultSettings(); 99848 _cam._setDefaultCamera(); // set renderer current camera to the new camera 99849 this._renderer._curCamera = _cam; 99850 return _cam; 99851 }; 99852 /** 99853 * This class describes a camera for use in p5's 99854 * <a href="https://github.com/processing/p5.js/wiki/Getting-started-with-WebGL-in-p5"> 99855 * WebGL mode</a>. It contains camera position, orientation, and projection 99856 * information necessary for rendering a 3D scene. 99857 * 99858 * New p5.Camera objects can be made through the 99859 * <a href="#/p5/createCamera">createCamera()</a> function and controlled through 99860 * the methods described below. A camera created in this way will use a default 99861 * position in the scene and a default perspective projection until these 99862 * properties are changed through the various methods available. It is possible 99863 * to create multiple cameras, in which case the current camera 99864 * can be set through the <a href="#/p5/setCamera">setCamera()</a> method. 99865 * 99866 * Note: 99867 * The methods below operate in two coordinate systems: the 'world' coordinate 99868 * system describe positions in terms of their relationship to the origin along 99869 * the X, Y and Z axes whereas the camera's 'local' coordinate system 99870 * describes positions from the camera's point of view: left-right, up-down, 99871 * and forward-backward. The <a href="#/p5.Camera/move">move()</a> method, 99872 * for instance, moves the camera along its own axes, whereas the 99873 * <a href="#/p5.Camera/setPosition">setPosition()</a> 99874 * method sets the camera's position in world-space. 99875 * 99876 * The camera object propreties 99877 * <code>eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ</code> 99878 * which describes camera position, orientation, and projection 99879 * are also accessible via the camera object generated using 99880 * <a href="#/p5/createCamera">createCamera()</a> 99881 * 99882 * @class p5.Camera 99883 * @param {rendererGL} rendererGL instance of WebGL renderer 99884 * @example 99885 * <div> 99886 * <code> 99887 * let cam; 99888 * let delta = 0.01; 99889 * 99890 * function setup() { 99891 * createCanvas(100, 100, WEBGL); 99892 * normalMaterial(); 99893 * cam = createCamera(); 99894 * // set initial pan angle 99895 * cam.pan(-0.8); 99896 * describe( 99897 * 'camera view pans left and right across a series of rotating 3D boxes.' 99898 * ); 99899 * } 99900 * 99901 * function draw() { 99902 * background(200); 99903 * 99904 * // pan camera according to angle 'delta' 99905 * cam.pan(delta); 99906 * 99907 * // every 160 frames, switch direction 99908 * if (frameCount % 160 === 0) { 99909 * delta *= -1; 99910 * } 99911 * 99912 * rotateX(frameCount * 0.01); 99913 * translate(-100, 0, 0); 99914 * box(20); 99915 * translate(35, 0, 0); 99916 * box(20); 99917 * translate(35, 0, 0); 99918 * box(20); 99919 * translate(35, 0, 0); 99920 * box(20); 99921 * translate(35, 0, 0); 99922 * box(20); 99923 * translate(35, 0, 0); 99924 * box(20); 99925 * translate(35, 0, 0); 99926 * box(20); 99927 * } 99928 * </code> 99929 * </div> 99930 * 99931 * @alt 99932 * camera view pans left and right across a series of rotating 3D boxes. 99933 */ 99934 _main.default.Camera = function (renderer) { 99935 this._renderer = renderer; 99936 this.cameraType = 'default'; 99937 this.cameraMatrix = new _main.default.Matrix(); 99938 this.projMatrix = new _main.default.Matrix(); 99939 }; 99940 /** 99941 * camera position value on x axis 99942 * @property {Number} eyeX 99943 * @readonly 99944 * @example 99945 * 99946 * <div class='norender'><code> 99947 * let cam, div; 99948 * function setup() { 99949 * createCanvas(100, 100, WEBGL); 99950 * background(0); 99951 * cam = createCamera(); 99952 * div = createDiv(); 99953 * div.position(0, 0); 99954 * describe('An example showing the use of camera object properties'); 99955 * } 99956 * 99957 * function draw() { 99958 * orbitControl(); 99959 * box(10); 99960 * div.html('eyeX = ' + cam.eyeX); 99961 * } 99962 * </code></div> 99963 * 99964 * @alt 99965 * An example showing the use of camera object properties 99966 * 99967 */ 99968 /** 99969 * camera position value on y axis 99970 * @property {Number} eyeY 99971 * @readonly 99972 * @example 99973 * <div class='norender'><code> 99974 * let cam, div; 99975 * function setup() { 99976 * createCanvas(100, 100, WEBGL); 99977 * background(0); 99978 * cam = createCamera(); 99979 * div = createDiv(); 99980 * div.position(0, 0); 99981 * describe('An example showing the use of camera object properties'); 99982 * } 99983 * 99984 * function draw() { 99985 * orbitControl(); 99986 * box(10); 99987 * div.html('eyeY = ' + cam.eyeY); 99988 * } 99989 * </code></div> 99990 * 99991 * @alt 99992 * An example showing the use of camera object properties 99993 * 99994 */ 99995 /** 99996 * camera position value on z axis 99997 * @property {Number} eyeZ 99998 * @readonly 99999 * @example 100000 * <div class='norender'><code> 100001 * let cam, div; 100002 * function setup() { 100003 * createCanvas(100, 100, WEBGL); 100004 * background(0); 100005 * cam = createCamera(); 100006 * div = createDiv(); 100007 * div.position(0, 0); 100008 * describe('An example showing the use of camera object properties'); 100009 * } 100010 * 100011 * function draw() { 100012 * orbitControl(); 100013 * box(10); 100014 * div.html('eyeZ = ' + cam.eyeZ); 100015 * } 100016 * </code></div> 100017 * 100018 * @alt 100019 * An example showing the use of camera object properties 100020 * 100021 */ 100022 /** 100023 * x coordinate representing center of the sketch 100024 * @property {Number} centerX 100025 * @readonly 100026 * @example 100027 * <div class='norender'><code> 100028 * let cam, div; 100029 * function setup() { 100030 * createCanvas(100, 100, WEBGL); 100031 * background(255); 100032 * cam = createCamera(); 100033 * cam.lookAt(1, 0, 0); 100034 * div = createDiv('centerX = ' + cam.centerX); 100035 * div.position(0, 0); 100036 * div.style('color', 'white'); 100037 * describe('An example showing the use of camera object properties'); 100038 * } 100039 * 100040 * function draw() { 100041 * orbitControl(); 100042 * box(10); 100043 * } 100044 * </code></div> 100045 * 100046 * @alt 100047 * An example showing the use of camera object properties 100048 * 100049 */ 100050 /** 100051 * y coordinate representing center of the sketch 100052 * @property {Number} centerY 100053 * @readonly 100054 * @example 100055 * <div class='norender'><code> 100056 * let cam, div; 100057 * function setup() { 100058 * createCanvas(100, 100, WEBGL); 100059 * background(255); 100060 * cam = createCamera(); 100061 * cam.lookAt(0, 1, 0); 100062 * div = createDiv('centerY = ' + cam.centerY); 100063 * div.position(0, 0); 100064 * div.style('color', 'white'); 100065 * describe('An example showing the use of camera object properties'); 100066 * } 100067 * 100068 * function draw() { 100069 * orbitControl(); 100070 * box(10); 100071 * } 100072 * </code></div> 100073 * 100074 * @alt 100075 * An example showing the use of camera object properties 100076 * 100077 */ 100078 /** 100079 * z coordinate representing center of the sketch 100080 * @property {Number} centerZ 100081 * @readonly 100082 * @example 100083 * <div class='norender'><code> 100084 * let cam, div; 100085 * function setup() { 100086 * createCanvas(100, 100, WEBGL); 100087 * background(255); 100088 * cam = createCamera(); 100089 * cam.lookAt(0, 0, 1); 100090 * div = createDiv('centerZ = ' + cam.centerZ); 100091 * div.position(0, 0); 100092 * div.style('color', 'white'); 100093 * describe('An example showing the use of camera object properties'); 100094 * } 100095 * 100096 * function draw() { 100097 * orbitControl(); 100098 * box(10); 100099 * } 100100 * </code></div> 100101 * 100102 * @alt 100103 * An example showing the use of camera object properties 100104 * 100105 */ 100106 /** 100107 * x component of direction 'up' from camera 100108 * @property {Number} upX 100109 * @readonly 100110 * @example 100111 * <div class='norender'><code> 100112 * let cam, div; 100113 * function setup() { 100114 * createCanvas(100, 100, WEBGL); 100115 * background(255); 100116 * cam = createCamera(); 100117 * div = createDiv('upX = ' + cam.upX); 100118 * div.position(0, 0); 100119 * div.style('color', 'blue'); 100120 * div.style('font-size', '18px'); 100121 * describe('An example showing the use of camera object properties'); 100122 * } 100123 * </code></div> 100124 * 100125 * @alt 100126 * An example showing the use of camera object properties 100127 * 100128 */ 100129 /** 100130 * y component of direction 'up' from camera 100131 * @property {Number} upY 100132 * @readonly 100133 * @example 100134 * <div class='norender'><code> 100135 * let cam, div; 100136 * function setup() { 100137 * createCanvas(100, 100, WEBGL); 100138 * background(255); 100139 * cam = createCamera(); 100140 * div = createDiv('upY = ' + cam.upY); 100141 * div.position(0, 0); 100142 * div.style('color', 'blue'); 100143 * div.style('font-size', '18px'); 100144 * describe('An example showing the use of camera object properties'); 100145 * } 100146 * </code></div> 100147 * 100148 * @alt 100149 * An example showing the use of camera object properties 100150 * 100151 */ 100152 /** 100153 * z component of direction 'up' from camera 100154 * @property {Number} upZ 100155 * @readonly 100156 * @example 100157 * <div class='norender'><code> 100158 * let cam, div; 100159 * function setup() { 100160 * createCanvas(100, 100, WEBGL); 100161 * background(255); 100162 * cam = createCamera(); 100163 * div = createDiv('upZ = ' + cam.upZ); 100164 * div.position(0, 0); 100165 * div.style('color', 'blue'); 100166 * div.style('font-size', '18px'); 100167 * describe('An example showing the use of camera object properties'); 100168 * } 100169 * </code></div> 100170 * 100171 * @alt 100172 * An example showing the use of camera object properties 100173 * 100174 */
100175 //////////////////////////////////////////////////////////////////////////////// 100176 // Camera Projection Methods 100177 //////////////////////////////////////////////////////////////////////////////// 100178 /** 100179 * Sets a perspective projection. 100180 * Accepts the same parameters as the global 100181 * <a href="#/p5/perspective">perspective()</a>. 100182 * More information on this function can be found there. 100183 * @method perspective 100184 * @for p5.Camera 100185 * @example 100186 * <div> 100187 * <code> 100188 * // drag the mouse to look around! 100189 * 100190 * let cam; 100191 * 100192 * function setup() { 100193 * createCanvas(100, 100, WEBGL); 100194 * // create a camera 100195 * cam = createCamera(); 100196 * // give it a perspective projection 100197 * cam.perspective(PI / 3.0, width / height, 0.1, 500); 100198 * } 100199 * 100200 * function draw() { 100201 * background(200); 100202 * orbitControl(); 100203 * normalMaterial(); 100204 * 100205 * rotateX(-0.3); 100206 * rotateY(-0.2); 100207 * translate(0, 0, -50); 100208 * 100209 * push(); 100210 * translate(-15, 0, sin(frameCount / 30) * 95); 100211 * box(30); 100212 * pop(); 100213 * push(); 100214 * translate(15, 0, sin(frameCount / 30 + PI) * 95); 100215 * box(30); 100216 * pop(); 100217 * } 100218 * </code> 100219 * </div> 100220 * @alt 100221 * two colored 3D boxes move back and forth, rotating as mouse is dragged. 100222 */ 100223 _main.default.Camera.prototype.perspective = function (fovy, aspect, near, far) { 100224 this.cameraType = arguments.length > 0 ? 'custom' : 'default'; 100225 if (typeof fovy === 'undefined') { 100226 fovy = this.defaultCameraFOV; // this avoids issue where setting angleMode(DEGREES) before calling 100227 // perspective leads to a smaller than expected FOV (because 100228 // _computeCameraDefaultSettings computes in radians) 100229 this.cameraFOV = fovy; 100230 } else { 100231 this.cameraFOV = this._renderer._pInst._toRadians(fovy); 100232 } 100233 if (typeof aspect === 'undefined') { 100234 aspect = this.defaultAspectRatio; 100235 } 100236 if (typeof near === 'undefined') { 100237 near = this.defaultCameraNear; 100238 } 100239 if (typeof far === 'undefined') { 100240 far = this.defaultCameraFar; 100241 } 100242 if (near <= 0.0001) { 100243 near = 0.01; 100244 console.log('Avoid perspective near plane values close to or below 0. ' + 'Setting value to 0.01.'); 100245 } 100246 if (far < near) { 100247 console.log('Perspective far plane value is less than near plane value. ' + 'Nothing will be shown.'); 100248 } 100249 this.aspectRatio = aspect; 100250 this.cameraNear = near; 100251 this.cameraFar = far; 100252 this.projMatrix = _main.default.Matrix.identity(); 100253 var f = 1 / Math.tan(this.cameraFOV / 2); 100254 var nf = 1 / (this.cameraNear - this.cameraFar); 100255 /* eslint-disable indent */ 100256 this.projMatrix.set(f / aspect, 0, 0, 0, 0, - f, 0, 0, 0, 0, (far + near) * nf, - 1, 0, 0, 2 * far * near * nf, 0); 100257 /* eslint-enable indent */ 100258 if (this._isActive()) { 100259 this._renderer.uPMatrix.set(this.projMatrix.mat4[0], this.projMatrix.mat4[1], this.projMatrix.mat4[2], this.projMatrix.mat4[3], this.projMatrix.mat4[4], this.projMatrix.mat4[5], this.projMatrix.mat4[6], this.projMatrix.mat4[7], this.projMatrix.mat4[8], this.projMatrix.mat4[9], this.projMatrix.mat4[10], this.projMatrix.mat4[11], this.projMatrix.mat4[12], this.projMatrix.mat4[13], this.projMatrix.mat4[14], this.projMatrix.mat4[15]); 100260 } 100261 }; 100262 /** 100263 * Sets an orthographic projection. 100264 * Accepts the same parameters as the global 100265 * <a href="#/p5/ortho">ortho()</a>. 100266 * More information on this function can be found there. 100267 * @method ortho 100268 * @for p5.Camera 100269 * @example 100270 * <div> 100271 * <code> 100272 * // drag the mouse to look around! 100273 * // there's no vanishing point 100274 * 100275 * let cam; 100276 * 100277 * function setup() { 100278 * createCanvas(100, 100, WEBGL); 100279 * // create a camera 100280 * cam = createCamera(); 100281 * // give it an orthographic projection 100282 * cam.ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500); 100283 * } 100284 * function draw() { 100285 * background(200); 100286 * orbitControl(); 100287 * normalMaterial(); 100288 * 100289 * rotateX(0.2); 100290 * rotateY(-0.2); 100291 * push(); 100292 * translate(-15, 0, sin(frameCount / 30) * 65); 100293 * box(30); 100294 * pop(); 100295 * push(); 100296 * translate(15, 0, sin(frameCount / 30 + PI) * 65); 100297 * box(30); 100298 * pop(); 100299 * } 100300 * </code> 100301 * </div> 100302 * @alt 100303 * two 3D boxes move back and forth along same plane, rotating as mouse is dragged. 100304 */ 100305 _main.default.Camera.prototype.ortho = function (left, right, bottom, top, near, far) { 100306 if (left === undefined) left = - this._renderer.width / 2; 100307 if (right === undefined) right = + this._renderer.width / 2; 100308 if (bottom === undefined) bottom = - this._renderer.height / 2; 100309 if (top === undefined) top = + this._renderer.height / 2; 100310 if (near === undefined) near = 0; 100311 if (far === undefined) far = Math.max(this._renderer.width, this._renderer.height); 100312 var w = right - left; 100313 var h = top - bottom; 100314 var d = far - near; 100315 var x = + 2 / w; 100316 var y = + 2 / h; 100317 var z = - 2 / d; 100318 var tx = - (right + left) / w; 100319 var ty = - (top + bottom) / h; 100320 var tz = - (far + near) / d; 100321 this.projMatrix = _main.default.Matrix.identity(); 100322 /* eslint-disable indent */
100323 this.projMatrix.set(x, 0, 0, 0, 0, - y, 0, 0, 0, 0, z, 0, tx, ty, tz, 1); 100324 /* eslint-enable indent */ 100325 if (this._isActive()) { 100326 this._renderer.uPMatrix.set(this.projMatrix.mat4[0], this.projMatrix.mat4[1], this.projMatrix.mat4[2], this.projMatrix.mat4[3], this.projMatrix.mat4[4], this.projMatrix.mat4[5], this.projMatrix.mat4[6], this.projMatrix.mat4[7], this.projMatrix.mat4[8], this.projMatrix.mat4[9], this.projMatrix.mat4[10], this.projMatrix.mat4[11], this.projMatrix.mat4[12], this.projMatrix.mat4[13], this.projMatrix.mat4[14], this.projMatrix.mat4[15]); 100327 } 100328 this.cameraType = 'custom'; 100329 }; 100330 /** 100331 * Sets the camera's frustum. 100332 * Accepts the same parameters as the global 100333 * <a href="#/p5/frustum">frustum()</a>. 100334 * More information on this function can be found there. 100335 * @method frustum 100336 * @for p5.Camera 100337 * @example 100338 * <div> 100339 * <code> 100340 * let cam; 100341 * 100342 * function setup() { 100343 * x = createCanvas(100, 100, WEBGL); 100344 * setAttributes('antialias', true); 100345 * // create a camera 100346 * cam = createCamera(); 100347 * // set its frustum 100348 * cam.frustum(-0.1, 0.1, -0.1, 0.1, 0.1, 200); 100349 * } 100350 * 100351 * function draw() { 100352 * background(200); 100353 * orbitControl(); 100354 * normalMaterial(); 100355 * 100356 * rotateY(-0.2); 100357 * rotateX(-0.3); 100358 * push(); 100359 * translate(-15, 0, sin(frameCount / 30) * 25); 100360 * box(30); 100361 * pop(); 100362 * push(); 100363 * translate(15, 0, sin(frameCount / 30 + PI) * 25); 100364 * box(30); 100365 * pop(); 100366 * } 100367 * </code> 100368 * </div> 100369 * @alt 100370 * two 3D boxes move back and forth along same plane, rotating as mouse is dragged. 100371 */ 100372 _main.default.Camera.prototype.frustum = function (left, right, bottom, top, near, far) { 100373 if (left === undefined) left = - this._renderer.width / 2; 100374 if (right === undefined) right = + this._renderer.width / 2; 100375 if (bottom === undefined) bottom = - this._renderer.height / 2; 100376 if (top === undefined) top = + this._renderer.height / 2; 100377 if (near === undefined) near = 0; 100378 if (far === undefined) far = Math.max(this._renderer.width, this._renderer.height); 100379 var w = right - left; 100380 var h = top - bottom; 100381 var d = far - near; 100382 var x = + (2 * near) / w; 100383 var y = + (2 * near) / h; 100384 var z = - (2 * far * near) / d; 100385 var tx = (right + left) / w; 100386 var ty = (top + bottom) / h; 100387 var tz = - (far + near) / d; 100388 this.projMatrix = _main.default.Matrix.identity(); 100389 /* eslint-disable indent */ 100390 this.projMatrix.set(x, 0, 0, 0, 0, y, 0, 0, tx, ty, tz, - 1, 0, 0, z, 0); 100391 /* eslint-enable indent */ 100392 if (this._isActive()) { 100393 this._renderer.uPMatrix.set(this.projMatrix.mat4[0], this.projMatrix.mat4[1], this.projMatrix.mat4[2], this.projMatrix.mat4[3], this.projMatrix.mat4[4], this.projMatrix.mat4[5], this.projMatrix.mat4[6], this.projMatrix.mat4[7], this.projMatrix.mat4[8], this.projMatrix.mat4[9], this.projMatrix.mat4[10], this.projMatrix.mat4[11], this.projMatrix.mat4[12], this.projMatrix.mat4[13], this.projMatrix.mat4[14], this.projMatrix.mat4[15]); 100394 } 100395 this.cameraType = 'custom'; 100396 }; //////////////////////////////////////////////////////////////////////////////// 100397 // Camera Orientation Methods
100398 //////////////////////////////////////////////////////////////////////////////// 100399 /** 100400 * Rotate camera view about arbitrary axis defined by x,y,z 100401 * based on http://learnwebgl.brown37.net/07_cameras/camera_rotating_motion.html 100402 * @method _rotateView 100403 * @private 100404 */ 100405 _main.default.Camera.prototype._rotateView = function (a, x, y, z) { 100406 var centerX = this.centerX; 100407 var centerY = this.centerY; 100408 var centerZ = this.centerZ; // move center by eye position such that rotation happens around eye position 100409 centerX -= this.eyeX; 100410 centerY -= this.eyeY; 100411 centerZ -= this.eyeZ; 100412 var rotation = _main.default.Matrix.identity(this._renderer._pInst); 100413 rotation.rotate(this._renderer._pInst._toRadians(a), x, y, z); 100414 /* eslint-disable max-len */ 100415 var rotatedCenter = [ 100416 centerX * rotation.mat4[0] + centerY * rotation.mat4[4] + centerZ * rotation.mat4[8], 100417 centerX * rotation.mat4[1] + centerY * rotation.mat4[5] + centerZ * rotation.mat4[9], 100418 centerX * rotation.mat4[2] + centerY * rotation.mat4[6] + centerZ * rotation.mat4[10] 100419 ]; 100420 /* eslint-enable max-len */ 100421 // add eye position back into center 100422 rotatedCenter[0] += this.eyeX; 100423 rotatedCenter[1] += this.eyeY; 100424 rotatedCenter[2] += this.eyeZ; 100425 this.camera(this.eyeX, this.eyeY, this.eyeZ, rotatedCenter[0], rotatedCenter[1], rotatedCenter[2], this.upX, this.upY, this.upZ); 100426 }; 100427 /** 100428 * Panning rotates the camera view to the left and right. 100429 * @method pan 100430 * @param {Number} angle amount to rotate camera in current 100431 * <a href="#/p5/angleMode">angleMode</a> units. 100432 * Greater than 0 values rotate counterclockwise (to the left). 100433 * @example 100434 * <div> 100435 * <code> 100436 * let cam; 100437 * let delta = 0.01; 100438 * 100439 * function setup() { 100440 * createCanvas(100, 100, WEBGL); 100441 * normalMaterial(); 100442 * cam = createCamera(); 100443 * // set initial pan angle 100444 * cam.pan(-0.8); 100445 * } 100446 * 100447 * function draw() { 100448 * background(200); 100449 * 100450 * // pan camera according to angle 'delta' 100451 * cam.pan(delta); 100452 * 100453 * // every 160 frames, switch direction 100454 * if (frameCount % 160 === 0) { 100455 * delta *= -1; 100456 * } 100457 * 100458 * rotateX(frameCount * 0.01); 100459 * translate(-100, 0, 0); 100460 * box(20); 100461 * translate(35, 0, 0); 100462 * box(20); 100463 * translate(35, 0, 0); 100464 * box(20); 100465 * translate(35, 0, 0); 100466 * box(20); 100467 * translate(35, 0, 0); 100468 * box(20); 100469 * translate(35, 0, 0); 100470 * box(20); 100471 * translate(35, 0, 0); 100472 * box(20); 100473 * } 100474 * </code> 100475 * </div> 100476 * 100477 * @alt 100478 * camera view pans left and right across a series of rotating 3D boxes. 100479 */ 100480 _main.default.Camera.prototype.pan = function (amount) { 100481 var local = this._getLocalAxes(); 100482 this._rotateView(amount, local.y[0], local.y[1], local.y[2]); 100483 }; 100484 /** 100485 * Tilting rotates the camera view up and down. 100486 * @method tilt 100487 * @param {Number} angle amount to rotate camera in current 100488 * <a href="#/p5/angleMode">angleMode</a> units. 100489 * Greater than 0 values rotate counterclockwise (to the left). 100490 * @example 100491 * <div> 100492 * <code> 100493 * let cam; 100494 * let delta = 0.01; 100495 * 100496 * function setup() { 100497 * createCanvas(100, 100, WEBGL); 100498 * normalMaterial(); 100499 * cam = createCamera(); 100500 * // set initial tilt 100501 * cam.tilt(-0.8); 100502 * } 100503 * 100504 * function draw() { 100505 * background(200); 100506 * 100507 * // pan camera according to angle 'delta' 100508 * cam.tilt(delta); 100509 * 100510 * // every 160 frames, switch direction 100511 * if (frameCount % 160 === 0) { 100512 * delta *= -1; 100513 * } 100514 * 100515 * rotateY(frameCount * 0.01); 100516 * translate(0, -100, 0); 100517 * box(20); 100518 * translate(0, 35, 0); 100519 * box(20); 100520 * translate(0, 35, 0); 100521 * box(20); 100522 * translate(0, 35, 0); 100523 * box(20); 100524 * translate(0, 35, 0); 100525 * box(20); 100526 * translate(0, 35, 0); 100527 * box(20); 100528 * translate(0, 35, 0); 100529 * box(20); 100530 * } 100531 * </code> 100532 * </div> 100533 * 100534 * @alt 100535 * camera view tilts up and down across a series of rotating 3D boxes. 100536 */ 100537 _main.default.Camera.prototype.tilt = function (amount) { 100538 var local = this._getLocalAxes(); 100539 this._rotateView(amount, local.x[0], local.x[1], local.x[2]); 100540 }; 100541 /** 100542 * Reorients the camera to look at a position in world space. 100543 * @method lookAt 100544 * @for p5.Camera 100545 * @param {Number} x x position of a point in world space 100546 * @param {Number} y y position of a point in world space 100547 * @param {Number} z z position of a point in world space 100548 * @example 100549 * <div> 100550 * <code> 100551 * let cam; 100552 * 100553 * function setup() { 100554 * createCanvas(100, 100, WEBGL); 100555 * normalMaterial(); 100556 * cam = createCamera(); 100557 * } 100558 * 100559 * function draw() { 100560 * background(200); 100561 * 100562 * // look at a new random point every 60 frames 100563 * if (frameCount % 60 === 0) { 100564 * cam.lookAt(random(-100, 100), random(-50, 50), 0); 100565 * } 100566 * 100567 * rotateX(frameCount * 0.01); 100568 * translate(-100, 0, 0); 100569 * box(20); 100570 * translate(35, 0, 0); 100571 * box(20); 100572 * translate(35, 0, 0); 100573 * box(20); 100574 * translate(35, 0, 0); 100575 * box(20); 100576 * translate(35, 0, 0); 100577 * box(20); 100578 * translate(35, 0, 0); 100579 * box(20); 100580 * translate(35, 0, 0); 100581 * box(20); 100582 * } 100583 * </code> 100584 * </div> 100585 * 100586 * @alt 100587 * camera view of rotating 3D cubes changes to look at a new random 100588 * point every second . 100589 */ 100590 _main.default.Camera.prototype.lookAt = function (x, y, z) { 100591 this.camera(this.eyeX, this.eyeY, this.eyeZ, x, y, z, this.upX, this.upY, this.upZ); 100592 }; //////////////////////////////////////////////////////////////////////////////// 100593 // Camera Position Methods
100594 //////////////////////////////////////////////////////////////////////////////// 100595 /** 100596 * Sets the camera's position and orientation. 100597 * Accepts the same parameters as the global 100598 * <a href="#/p5/camera">camera()</a>. 100599 * More information on this function can be found there. 100600 * @method camera 100601 * @for p5.Camera 100602 * @example 100603 * <div> 100604 * <code> 100605 * let cam; 100606 * 100607 * function setup() { 100608 * createCanvas(100, 100, WEBGL); 100609 * // Create a camera. 100610 * // createCamera() sets the newly created camera as 100611 * // the current (active) camera. 100612 * cam = createCamera(); 100613 * } 100614 * 100615 * function draw() { 100616 * background(204); 100617 * // Move the camera away from the plane by a sin wave 100618 * cam.camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0); 100619 * plane(10, 10); 100620 * } 100621 * </code> 100622 * </div> 100623 * @alt 100624 * White square repeatedly grows to fill canvas and then shrinks. 100625 * 100626 * @example 100627 * <div> 100628 * <code> 100629 * // move slider to see changes! 100630 * // sliders control the first 6 parameters of camera() 100631 * 100632 * let sliderGroup = []; 100633 * let X; 100634 * let Y; 100635 * let Z; 100636 * let centerX; 100637 * let centerY; 100638 * let centerZ; 100639 * let h = 20; 100640 * let cam; 100641 * 100642 * function setup() { 100643 * createCanvas(100, 100, WEBGL); 100644 * // create a camera 100645 * cam = createCamera(); 100646 * // create sliders 100647 * for (var i = 0; i < 6; i++) { 100648 * if (i === 2) { 100649 * sliderGroup[i] = createSlider(10, 400, 200); 100650 * } else { 100651 * sliderGroup[i] = createSlider(-400, 400, 0); 100652 * } 100653 * h = map(i, 0, 6, 5, 85); 100654 * sliderGroup[i].position(10, height + h); 100655 * sliderGroup[i].style('width', '80px'); 100656 * } 100657 * } 100658 * 100659 * function draw() { 100660 * background(60); 100661 * // assigning sliders' value to each parameters 100662 * X = sliderGroup[0].value(); 100663 * Y = sliderGroup[1].value(); 100664 * Z = sliderGroup[2].value(); 100665 * centerX = sliderGroup[3].value(); 100666 * centerY = sliderGroup[4].value(); 100667 * centerZ = sliderGroup[5].value(); 100668 * cam.camera(X, Y, Z, centerX, centerY, centerZ, 0, 1, 0); 100669 * stroke(255); 100670 * fill(255, 102, 94); 100671 * box(85); 100672 * } 100673 * </code> 100674 * </div> 100675 * @alt 100676 * An interactive example of a red cube with 3 sliders for moving it across x, y, 100677 * z axis and 3 sliders for shifting its center. 100678 */ 100679 _main.default.Camera.prototype.camera = function (eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ) { 100680 if (typeof eyeX === 'undefined') { 100681 eyeX = this.defaultEyeX; 100682 eyeY = this.defaultEyeY; 100683 eyeZ = this.defaultEyeZ; 100684 centerX = eyeX; 100685 centerY = eyeY; 100686 centerZ = 0; 100687 upX = 0; 100688 upY = 1; 100689 upZ = 0; 100690 } 100691 this.eyeX = eyeX; 100692 this.eyeY = eyeY; 100693 this.eyeZ = eyeZ; 100694 if (typeof centerX !== 'undefined') { 100695 this.centerX = centerX; 100696 this.centerY = centerY; 100697 this.centerZ = centerZ; 100698 } 100699 if (typeof upX !== 'undefined') { 100700 this.upX = upX; 100701 this.upY = upY; 100702 this.upZ = upZ; 100703 } 100704 var local = this._getLocalAxes(); // the camera affects the model view matrix, insofar as it 100705 // inverse translates the world to the eye position of the camera 100706 // and rotates it. 100707 /* eslint-disable indent */ 100708 this.cameraMatrix.set(local.x[0], local.y[0], local.z[0], 0, local.x[1], local.y[1], local.z[1], 0, local.x[2], local.y[2], local.z[2], 0, 0, 0, 0, 1); 100709 /* eslint-enable indent */ 100710 var tx = - eyeX; 100711 var ty = - eyeY; 100712 var tz = - eyeZ; 100713 this.cameraMatrix.translate([tx, 100714 ty, 100715 tz]); 100716 if (this._isActive()) { 100717 this._renderer.uMVMatrix.set(this.cameraMatrix.mat4[0], this.cameraMatrix.mat4[1], this.cameraMatrix.mat4[2], this.cameraMatrix.mat4[3], this.cameraMatrix.mat4[4], this.cameraMatrix.mat4[5], this.cameraMatrix.mat4[6], this.cameraMatrix.mat4[7], this.cameraMatrix.mat4[8], this.cameraMatrix.mat4[9], this.cameraMatrix.mat4[10], this.cameraMatrix.mat4[11], this.cameraMatrix.mat4[12], this.cameraMatrix.mat4[13], this.cameraMatrix.mat4[14], this.cameraMatrix.mat4[15]); 100718 } 100719 return this; 100720 }; 100721 /** 100722 * Move camera along its local axes while maintaining current camera orientation. 100723 * @method move 100724 * @param {Number} x amount to move along camera's left-right axis 100725 * @param {Number} y amount to move along camera's up-down axis 100726 * @param {Number} z amount to move along camera's forward-backward axis 100727 * @example 100728 * <div> 100729 * <code> 100730 * // see the camera move along its own axes while maintaining its orientation 100731 * let cam; 100732 * let delta = 0.5; 100733 * 100734 * function setup() { 100735 * createCanvas(100, 100, WEBGL); 100736 * normalMaterial(); 100737 * cam = createCamera(); 100738 * } 100739 * 100740 * function draw() { 100741 * background(200); 100742 * 100743 * // move the camera along its local axes 100744 * cam.move(delta, delta, 0); 100745 * 100746 * // every 100 frames, switch direction 100747 * if (frameCount % 150 === 0) { 100748 * delta *= -1; 100749 * } 100750 * 100751 * translate(-10, -10, 0); 100752 * box(50, 8, 50); 100753 * translate(15, 15, 0); 100754 * box(50, 8, 50); 100755 * translate(15, 15, 0); 100756 * box(50, 8, 50); 100757 * translate(15, 15, 0); 100758 * box(50, 8, 50); 100759 * translate(15, 15, 0); 100760 * box(50, 8, 50); 100761 * translate(15, 15, 0); 100762 * box(50, 8, 50); 100763 * } 100764 * </code> 100765 * </div> 100766 * 100767 * @alt 100768 * camera view moves along a series of 3D boxes, maintaining the same 100769 * orientation throughout the move 100770 */ 100771 _main.default.Camera.prototype.move = function (x, y, z) { 100772 var local = this._getLocalAxes(); // scale local axes by movement amounts 100773 // based on http://learnwebgl.brown37.net/07_cameras/camera_linear_motion.html 100774 var dx = [ 100775 local.x[0] * x, 100776 local.x[1] * x, 100777 local.x[2] * x 100778 ]; 100779 var dy = [ 100780 local.y[0] * y, 100781 local.y[1] * y, 100782 local.y[2] * y 100783 ]; 100784 var dz = [ 100785 local.z[0] * z, 100786 local.z[1] * z, 100787 local.z[2] * z 100788 ]; 100789 this.camera(this.eyeX + dx[0] + dy[0] + dz[0], this.eyeY + dx[1] + dy[1] + dz[1], this.eyeZ + dx[2] + dy[2] + dz[2], this.centerX + dx[0] + dy[0] + dz[0], this.centerY + dx[1] + dy[1] + dz[1], this.centerZ + dx[2] + dy[2] + dz[2], this.upX, this.upY, this.upZ); 100790 }; 100791 /** 100792 * Set camera position in world-space while maintaining current camera 100793 * orientation. 100794 * @method setPosition 100795 * @param {Number} x x position of a point in world space 100796 * @param {Number} y y position of a point in world space 100797 * @param {Number} z z position of a point in world space 100798 * @example 100799 * <div> 100800 * <code> 100801 * // press '1' '2' or '3' keys to set camera position 100802 * 100803 * let cam; 100804 * 100805 * function setup() { 100806 * createCanvas(100, 100, WEBGL); 100807 * normalMaterial(); 100808 * cam = createCamera(); 100809 * } 100810 * 100811 * function draw() { 100812 * background(200); 100813 * 100814 * // '1' key 100815 * if (keyIsDown(49)) { 100816 * cam.setPosition(30, 0, 80); 100817 * } 100818 * // '2' key 100819 * if (keyIsDown(50)) { 100820 * cam.setPosition(0, 0, 80); 100821 * } 100822 * // '3' key 100823 * if (keyIsDown(51)) { 100824 * cam.setPosition(-30, 0, 80); 100825 * } 100826 * 100827 * box(20); 100828 * } 100829 * </code> 100830 * </div> 100831 * 100832 * @alt 100833 * camera position changes as the user presses keys, altering view of a 3D box 100834 */ 100835 _main.default.Camera.prototype.setPosition = function (x, y, z) { 100836 var diffX = x - this.eyeX; 100837 var diffY = y - this.eyeY; 100838 var diffZ = z - this.eyeZ; 100839 this.camera(x, y, z, this.centerX + diffX, this.centerY + diffY, this.centerZ + diffZ, this.upX, this.upY, this.upZ); 100840 }; //////////////////////////////////////////////////////////////////////////////// 100841 // Camera Helper Methods
100842 //////////////////////////////////////////////////////////////////////////////// 100843 // @TODO: combine this function with _setDefaultCamera to compute these values 100844 // as-needed 100845 _main.default.Camera.prototype._computeCameraDefaultSettings = function () { 100846 this.defaultCameraFOV = 60 / 180 * Math.PI; 100847 this.defaultAspectRatio = this._renderer.width / this._renderer.height; 100848 this.defaultEyeX = 0; 100849 this.defaultEyeY = 0; 100850 this.defaultEyeZ = this._renderer.height / 2 / Math.tan(this.defaultCameraFOV / 2); 100851 this.defaultCenterX = 0; 100852 this.defaultCenterY = 0; 100853 this.defaultCenterZ = 0; 100854 this.defaultCameraNear = this.defaultEyeZ * 0.1; 100855 this.defaultCameraFar = this.defaultEyeZ * 10; 100856 }; //detect if user didn't set the camera 100857 //then call this function below 100858 _main.default.Camera.prototype._setDefaultCamera = function () { 100859 this.cameraFOV = this.defaultCameraFOV; 100860 this.aspectRatio = this.defaultAspectRatio; 100861 this.eyeX = this.defaultEyeX; 100862 this.eyeY = this.defaultEyeY; 100863 this.eyeZ = this.defaultEyeZ; 100864 this.centerX = this.defaultCenterX; 100865 this.centerY = this.defaultCenterY; 100866 this.centerZ = this.defaultCenterZ; 100867 this.upX = 0; 100868 this.upY = 1; 100869 this.upZ = 0; 100870 this.cameraNear = this.defaultCameraNear; 100871 this.cameraFar = this.defaultCameraFar; 100872 this.perspective(); 100873 this.camera(); 100874 this.cameraType = 'default'; 100875 }; 100876 _main.default.Camera.prototype._resize = function () { 100877 // If we're using the default camera, update the aspect ratio 100878 if (this.cameraType === 'default') { 100879 this._computeCameraDefaultSettings(); 100880 this._setDefaultCamera(); 100881 } else { 100882 this.perspective(this.cameraFOV, this._renderer.width / this._renderer.height); 100883 } 100884 }; 100885 /** 100886 * Returns a copy of a camera. 100887 * @method copy 100888 * @private 100889 */ 100890 _main.default.Camera.prototype.copy = function () { 100891 var _cam = new _main.default.Camera(this._renderer); 100892 _cam.cameraFOV = this.cameraFOV; 100893 _cam.aspectRatio = this.aspectRatio; 100894 _cam.eyeX = this.eyeX; 100895 _cam.eyeY = this.eyeY; 100896 _cam.eyeZ = this.eyeZ; 100897 _cam.centerX = this.centerX; 100898 _cam.centerY = this.centerY; 100899 _cam.centerZ = this.centerZ; 100900 _cam.cameraNear = this.cameraNear; 100901 _cam.cameraFar = this.cameraFar; 100902 _cam.cameraType = this.cameraType; 100903 _cam.cameraMatrix = this.cameraMatrix.copy(); 100904 _cam.projMatrix = this.projMatrix.copy(); 100905 return _cam; 100906 }; 100907 /** 100908 * Returns a camera's local axes: left-right, up-down, and forward-backward, 100909 * as defined by vectors in world-space. 100910 * @method _getLocalAxes 100911 * @private 100912 */ 100913 _main.default.Camera.prototype._getLocalAxes = function () { 100914 // calculate camera local Z vector 100915 var z0 = this.eyeX - this.centerX; 100916 var z1 = this.eyeY - this.centerY; 100917 var z2 = this.eyeZ - this.centerZ; // normalize camera local Z vector 100918 var eyeDist = Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); 100919 if (eyeDist !== 0) { 100920 z0 /= eyeDist; 100921 z1 /= eyeDist; 100922 z2 /= eyeDist; 100923 } // calculate camera Y vector 100924 100925 var y0 = this.upX; 100926 var y1 = this.upY; 100927 var y2 = this.upZ; // compute camera local X vector as up vector (local Y) cross local Z 100928 var x0 = y1 * z2 - y2 * z1; 100929 var x1 = - y0 * z2 + y2 * z0; 100930 var x2 = y0 * z1 - y1 * z0; // recompute y = z cross x 100931 y0 = z1 * x2 - z2 * x1; 100932 y1 = - z0 * x2 + z2 * x0; 100933 y2 = z0 * x1 - z1 * x0; // cross product gives area of parallelogram, which is < 1.0 for 100934 // non-perpendicular unit-length vectors; so normalize x, y here: 100935 var xmag = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); 100936 if (xmag !== 0) { 100937 x0 /= xmag; 100938 x1 /= xmag; 100939 x2 /= xmag; 100940 } 100941 var ymag = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); 100942 if (ymag !== 0) { 100943 y0 /= ymag; 100944 y1 /= ymag; 100945 y2 /= ymag; 100946 } 100947 return { 100948 x: [ 100949 x0, 100950 x1, 100951 x2 100952 ], 100953 y: [ 100954 y0, 100955 y1, 100956 y2 100957 ], 100958 z: [ 100959 z0, 100960 z1, 100961 z2 100962 ] 100963 }; 100964 }; 100965 /** 100966 * Orbits the camera about center point. For use with orbitControl(). 100967 * @method _orbit 100968 * @private 100969 * @param {Number} dTheta change in spherical coordinate theta 100970 * @param {Number} dPhi change in spherical coordinate phi 100971 * @param {Number} dRadius change in radius 100972 */ 100973 _main.default.Camera.prototype._orbit = function (dTheta, dPhi, dRadius) { 100974 var diffX = this.eyeX - this.centerX; 100975 var diffY = this.eyeY - this.centerY; 100976 var diffZ = this.eyeZ - this.centerZ; // get spherical coorinates for current camera position about origin 100977 var camRadius = Math.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ); // from https://github.com/mrdoob/three.js/blob/dev/src/math/Spherical.js#L72-L73 100978 var camTheta = Math.atan2(diffX, diffZ); // equatorial angle 100979 var camPhi = Math.acos(Math.max( - 1, Math.min(1, diffY / camRadius))); // polar angle 100980 var newUpY = this.upY > 0 ? 1 : - 1; // add change according to the direction of newupY 100981 camTheta += newUpY * dTheta; 100982 camPhi += newUpY * dPhi; // if camPhi becomes >= PI or <= 0, 100983 // upY of camera need to be flipped to the other side 100984 if (camPhi <= 0 || camPhi >= Math.PI) { 100985 newUpY *= - 1; 100986 } 100987 camRadius += dRadius; // prevent zooming through the center: 100988 if (camRadius < 0) { 100989 camRadius = 0.1; 100990 } // from https://github.com/mrdoob/three.js/blob/dev/src/math/Vector3.js#L628-L632 100991 100992 var _x = Math.sin(camPhi) * camRadius * Math.sin(camTheta); 100993 var _y = Math.cos(camPhi) * camRadius; 100994 var _z = Math.sin(camPhi) * camRadius * Math.cos(camTheta); 100995 this.camera(_x + this.centerX, _y + this.centerY, _z + this.centerZ, this.centerX, this.centerY, this.centerZ, 0, newUpY, 0); 100996 }; 100997 /** 100998 * Returns true if camera is currently attached to renderer. 100999 * @method _isActive 101000 * @private 101001 */ 101002 _main.default.Camera.prototype._isActive = function () { 101003 return this === this._renderer._curCamera; 101004 }; 101005 /** 101006 * Sets the current (active) camera of a 3D sketch. 101007 * Allows for switching between multiple cameras. 101008 * @method setCamera 101009 * @param {p5.Camera} cam p5.Camera object 101010 * @for p5 101011 * @example 101012 * <div> 101013 * <code> 101014 * let cam1, cam2; 101015 * let currentCamera; 101016 * 101017 * function setup() { 101018 * createCanvas(100, 100, WEBGL); 101019 * normalMaterial(); 101020 * 101021 * cam1 = createCamera(); 101022 * cam2 = createCamera(); 101023 * cam2.setPosition(30, 0, 50); 101024 * cam2.lookAt(0, 0, 0); 101025 * cam2.ortho(); 101026 * 101027 * // set variable for previously active camera: 101028 * currentCamera = 1; 101029 * 101030 * describe( 101031 * 'Canvas switches between two camera views, each showing a series of spinning 3D boxes.' 101032 * ); 101033 * } 101034 * 101035 * function draw() { 101036 * background(200); 101037 * 101038 * // camera 1: 101039 * cam1.lookAt(0, 0, 0); 101040 * cam1.setPosition(sin(frameCount / 60) * 200, 0, 100); 101041 * 101042 * // every 100 frames, switch between the two cameras 101043 * if (frameCount % 100 === 0) { 101044 * if (currentCamera === 1) { 101045 * setCamera(cam1); 101046 * currentCamera = 0; 101047 * } else { 101048 * setCamera(cam2); 101049 * currentCamera = 1; 101050 * } 101051 * } 101052 * 101053 * drawBoxes(); 101054 * } 101055 * 101056 * function drawBoxes() { 101057 * rotateX(frameCount * 0.01); 101058 * translate(-100, 0, 0); 101059 * box(20); 101060 * translate(35, 0, 0); 101061 * box(20); 101062 * translate(35, 0, 0); 101063 * box(20); 101064 * translate(35, 0, 0); 101065 * box(20); 101066 * translate(35, 0, 0); 101067 * box(20); 101068 * translate(35, 0, 0); 101069 * box(20); 101070 * translate(35, 0, 0); 101071 * box(20); 101072 * } 101073 * </code> 101074 * </div> 101075 * 101076 * @alt 101077 * Canvas switches between two camera views, each showing a series of spinning 101078 * 3D boxes. 101079 */ 101080 _main.default.prototype.setCamera = function (cam) { 101081 this._renderer._curCamera = cam; // set the projection matrix (which is not normally updated each frame)
101082 this._renderer.uPMatrix.set(cam.projMatrix.mat4[0], cam.projMatrix.mat4[1], cam.projMatrix.mat4[2], cam.projMatrix.mat4[3], cam.projMatrix.mat4[4], cam.projMatrix.mat4[5], cam.projMatrix.mat4[6], cam.projMatrix.mat4[7], cam.projMatrix.mat4[8], cam.projMatrix.mat4[9], cam.projMatrix.mat4[10], cam.projMatrix.mat4[11], cam.projMatrix.mat4[12], cam.projMatrix.mat4[13], cam.projMatrix.mat4[14], cam.projMatrix.mat4[15]); 101083 }; 101084 var _default = _main.default.Camera; 101085 exports.default = _default; 101086 }, 101087 { 101088 '../core/main': 290 101089 } 101090 ], 101091 339: [ 101092 function (_dereq_, module, exports) { 101093 'use strict'; 101094 _dereq_('core-js/modules/es.array.slice'); 101095 _dereq_('core-js/modules/es.string.sub'); 101096 _dereq_('core-js/modules/es.array.slice'); 101097 _dereq_('core-js/modules/es.string.sub'); 101098 Object.defineProperty(exports, '__esModule', { 101099 value: true 101100 }); 101101 exports.default = void 0; 101102 var _main = _interopRequireDefault(_dereq_('../core/main')); 101103 function _interopRequireDefault(obj) { 101104 return obj && obj.__esModule ? obj : { 101105 default: 101106 obj 101107 }; 101108 } /** 101109 * @module Shape 101110 * @submodule 3D Primitives 101111 * @for p5 101112 * @requires core 101113 * @requires p5.Geometry 101114 */ 101115 //some of the functions are adjusted from Three.js(http://threejs.org) 101116 /** 101117 * p5 Geometry class 101118 * @class p5.Geometry 101119 * @constructor 101120 * @param {Integer} [detailX] number of vertices along the x-axis. 101121 * @param {Integer} [detailY] number of vertices along the y-axis. 101122 * @param {function} [callback] function to call upon object instantiation. 101123 */ 101124 101125 _main.default.Geometry = function (detailX, detailY, callback) { 101126 //an array containing every vertex 101127 //@type [p5.Vector] 101128 this.vertices = [ 101129 ]; //an array containing every vertex for stroke drawing 101130 this.lineVertices = [ 101131 ]; // The tangents going into or out of a vertex on a line. Along a straight 101132 // line segment, both should be equal. At an endpoint, one or the other 101133 // will not exist and will be all 0. In joins between line segments, they 101134 // may be different, as they will be the tangents on either side of the join. 101135 this.lineTangentsIn = [ 101136 ]; 101137 this.lineTangentsOut = [ 101138 ]; // When drawing lines with thickness, entries in this buffer represent which 101139 // side of the centerline the vertex will be placed. The sign of the number 101140 // will represent the side of the centerline, and the absolute value will be 101141 // used as an enum to determine which part of the cap or join each vertex 101142 // represents. See the doc comments for _addCap and _addJoin for diagrams. 101143 this.lineSides = [ 101144 ]; //an array containing 1 normal per vertex 101145 //@type [p5.Vector] 101146 //[p5.Vector, p5.Vector, p5.Vector,p5.Vector, p5.Vector, p5.Vector,...] 101147 this.vertexNormals = [ 101148 ]; //an array containing each three vertex indices that form a face 101149 //[[0, 1, 2], [2, 1, 3], ...] 101150 this.faces = [ 101151 ]; //a 2D array containing uvs for every vertex 101152 //[[0.0,0.0],[1.0,0.0], ...] 101153 this.uvs = [ 101154 ]; // a 2D array containing edge connectivity pattern for create line vertices 101155 //based on faces for most objects; 101156 this.edges = [ 101157 ]; 101158 this.vertexColors = [ 101159 ]; // One color per vertex representing the stroke color at that vertex 101160 this.vertexStrokeColors = [ 101161 ]; // One color per line vertex, generated automatically based on 101162 // vertexStrokeColors in _edgesToVertices() 101163 this.lineVertexColors = [ 101164 ]; 101165 this.detailX = detailX !== undefined ? detailX : 1; 101166 this.detailY = detailY !== undefined ? detailY : 1; 101167 this.dirtyFlags = { 101168 }; 101169 if (callback instanceof Function) { 101170 callback.call(this); 101171 } 101172 return this; // TODO: is this a constructor? 101173 }; 101174 _main.default.Geometry.prototype.reset = function () { 101175 this.lineVertices.length = 0; 101176 this.lineTangentsIn.length = 0; 101177 this.lineTangentsOut.length = 0; 101178 this.lineSides.length = 0; 101179 this.vertices.length = 0; 101180 this.edges.length = 0; 101181 this.vertexColors.length = 0; 101182 this.vertexStrokeColors.length = 0; 101183 this.lineVertexColors.length = 0; 101184 this.vertexNormals.length = 0; 101185 this.uvs.length = 0; 101186 this.dirtyFlags = { 101187 }; 101188 }; 101189 /** 101190 * computes faces for geometry objects based on the vertices. 101191 * @method computeFaces 101192 * @chainable 101193 */ 101194 _main.default.Geometry.prototype.computeFaces = function () { 101195 this.faces.length = 0; 101196 var sliceCount = this.detailX + 1; 101197 var a, 101198 b, 101199 c, 101200 d; 101201 for (var i = 0; i < this.detailY; i++) { 101202 for (var j = 0; j < this.detailX; j++) { 101203 a = i * sliceCount + j; // + offset; 101204 b = i * sliceCount + j + 1; // + offset; 101205 c = (i + 1) * sliceCount + j + 1; // + offset; 101206 d = (i + 1) * sliceCount + j; // + offset; 101207 this.faces.push([a, 101208 b, 101209 d]); 101210 this.faces.push([d, 101211 b, 101212 c]); 101213 } 101214 } 101215 return this; 101216 };
101217 _main.default.Geometry.prototype._getFaceNormal = function (faceId) { 101218 //This assumes that vA->vB->vC is a counter-clockwise ordering 101219 var face = this.faces[faceId]; 101220 var vA = this.vertices[face[0]]; 101221 var vB = this.vertices[face[1]]; 101222 var vC = this.vertices[face[2]]; 101223 var ab = _main.default.Vector.sub(vB, vA); 101224 var ac = _main.default.Vector.sub(vC, vA); 101225 var n = _main.default.Vector.cross(ab, ac); 101226 var ln = _main.default.Vector.mag(n); 101227 var sinAlpha = ln / (_main.default.Vector.mag(ab) * _main.default.Vector.mag(ac)); 101228 if (sinAlpha === 0 || isNaN(sinAlpha)) { 101229 console.warn('p5.Geometry.prototype._getFaceNormal:', 'face has colinear sides or a repeated vertex'); 101230 return n; 101231 } 101232 if (sinAlpha > 1) sinAlpha = 1; // handle float rounding error 101233 return n.mult(Math.asin(sinAlpha) / ln); 101234 }; 101235 /** 101236 * computes smooth normals per vertex as an average of each 101237 * face. 101238 * @method computeNormals 101239 * @chainable 101240 */ 101241 _main.default.Geometry.prototype.computeNormals = function () { 101242 var vertexNormals = this.vertexNormals; 101243 var vertices = this.vertices; 101244 var faces = this.faces; 101245 var iv; // initialize the vertexNormals array with empty vectors 101246 vertexNormals.length = 0; 101247 for (iv = 0; iv < vertices.length; ++iv) { 101248 vertexNormals.push(new _main.default.Vector()); 101249 } // loop through all the faces adding its normal to the normal 101250 // of each of its vertices 101251 101252 for (var f = 0; f < faces.length; ++f) { 101253 var face = faces[f]; 101254 var faceNormal = this._getFaceNormal(f); // all three vertices get the normal added 101255 for (var fv = 0; fv < 3; ++fv) { 101256 var vertexIndex = face[fv]; 101257 vertexNormals[vertexIndex].add(faceNormal); 101258 } 101259 } // normalize the normals 101260 101261 for (iv = 0; iv < vertices.length; ++iv) { 101262 vertexNormals[iv].normalize(); 101263 } 101264 return this; 101265 }; 101266 /** 101267 * Averages the vertex normals. Used in curved 101268 * surfaces 101269 * @method averageNormals 101270 * @chainable 101271 */ 101272 _main.default.Geometry.prototype.averageNormals = function () { 101273 for (var i = 0; i <= this.detailY; i++) { 101274 var offset = this.detailX + 1; 101275 var temp = _main.default.Vector.add(this.vertexNormals[i * offset], this.vertexNormals[i * offset + this.detailX]); 101276 temp = _main.default.Vector.div(temp, 2); 101277 this.vertexNormals[i * offset] = temp; 101278 this.vertexNormals[i * offset + this.detailX] = temp; 101279 } 101280 return this; 101281 }; 101282 /** 101283 * Averages pole normals. Used in spherical primitives 101284 * @method averagePoleNormals 101285 * @chainable 101286 */ 101287 _main.default.Geometry.prototype.averagePoleNormals = function () { 101288 //average the north pole 101289 var sum = new _main.default.Vector(0, 0, 0); 101290 for (var i = 0; i < this.detailX; i++) { 101291 sum.add(this.vertexNormals[i]); 101292 } 101293 sum = _main.default.Vector.div(sum, this.detailX); 101294 for (var _i = 0; _i < this.detailX; _i++) { 101295 this.vertexNormals[_i] = sum; 101296 } //average the south pole 101297 101298 sum = new _main.default.Vector(0, 0, 0); 101299 for (var _i2 = this.vertices.length - 1; _i2 > this.vertices.length - 1 - this.detailX; _i2--) { 101300 sum.add(this.vertexNormals[_i2]); 101301 } 101302 sum = _main.default.Vector.div(sum, this.detailX); 101303 for (var _i3 = this.vertices.length - 1; _i3 > this.vertices.length - 1 - this.detailX; _i3--) { 101304 this.vertexNormals[_i3] = sum; 101305 } 101306 return this; 101307 }; 101308 /** 101309 * Create a 2D array for establishing stroke connections 101310 * @private 101311 * @chainable 101312 */ 101313 _main.default.Geometry.prototype._makeTriangleEdges = function () { 101314 this.edges.length = 0; 101315 if (Array.isArray(this.strokeIndices)) { 101316 for (var i = 0, max = this.strokeIndices.length; i < max; i++) { 101317 this.edges.push(this.strokeIndices[i]); 101318 } 101319 } else { 101320 for (var j = 0; j < this.faces.length; j++) { 101321 this.edges.push([this.faces[j][0], 101322 this.faces[j][1]]); 101323 this.edges.push([this.faces[j][1], 101324 this.faces[j][2]]); 101325 this.edges.push([this.faces[j][2], 101326 this.faces[j][0]]); 101327 } 101328 } 101329 return this; 101330 }; 101331 /** 101332 * Converts each line segment into the vertices and vertex attributes needed 101333 * to turn the line into a polygon on screen. This will include: 101334 * - Two triangles line segment to create a rectangle 101335 * - Two triangles per endpoint to create a stroke cap rectangle. A fragment 101336 * shader is responsible for displaying the appropriate cap style within 101337 * that rectangle. 101338 * - Four triangles per join between adjacent line segments, creating a quad on 101339 * either side of the join, perpendicular to the lines. A vertex shader will 101340 * discard the quad in the "elbow" of the join, and a fragment shader will 101341 * display the appropriate join style within the remaining quad. 101342 * 101343 * @private 101344 * @chainable 101345 */ 101346 _main.default.Geometry.prototype._edgesToVertices = function () { 101347 this.lineVertices.length = 0; 101348 this.lineTangentsIn.length = 0; 101349 this.lineTangentsOut.length = 0; 101350 this.lineSides.length = 0; 101351 var closed = this.edges.length > 1 && this.edges[0][0] === this.edges[this.edges.length - 1][1]; 101352 var addedStartingCap = false;
101353 var lastValidDir; 101354 for (var i = 0; i < this.edges.length; i++) { 101355 var prevEdge = this.edges[i - 1]; 101356 var currEdge = this.edges[i]; 101357 var begin = this.vertices[currEdge[0]]; 101358 var end = this.vertices[currEdge[1]]; 101359 var fromColor = this.vertexStrokeColors.length > 0 ? this.vertexStrokeColors.slice(currEdge[0] * 4, (currEdge[0] + 1) * 4) : [ 101360 0, 101361 0, 101362 0, 101363 0 101364 ]; 101365 var toColor = this.vertexStrokeColors.length > 0 ? this.vertexStrokeColors.slice(currEdge[1] * 4, (currEdge[1] + 1) * 4) : [ 101366 0, 101367 0, 101368 0, 101369 0 101370 ]; 101371 var dir = end.copy().sub(begin).normalize(); 101372 var dirOK = dir.magSq() > 0; 101373 if (dirOK) { 101374 this._addSegment(begin, end, fromColor, toColor, dir); 101375 } 101376 if (i > 0 && prevEdge[1] === currEdge[0]) { 101377 // Add a join if this segment shares a vertex with the previous. Skip 101378 // actually adding join vertices if either the previous segment or this 101379 // one has a length of 0. 101380 // 101381 // Don't add a join if the tangents point in the same direction, which 101382 // would mean the edges line up exactly, and there is no need for a join. 101383 if (lastValidDir && dirOK && dir.dot(lastValidDir) < 1 - 1e-8) { 101384 this._addJoin(begin, lastValidDir, dir, fromColor); 101385 } 101386 if (dirOK && !addedStartingCap && !closed) { 101387 this._addCap(begin, dir.copy().mult( - 1), fromColor); 101388 addedStartingCap = true; 101389 } 101390 } else { 101391 addedStartingCap = false; // Start a new line 101392 if (dirOK && (!closed || i > 0)) { 101393 this._addCap(begin, dir.copy().mult( - 1), fromColor); 101394 addedStartingCap = true; 101395 } 101396 if (lastValidDir && (!closed || i < this.edges.length - 1)) { 101397 // Close off the last segment with a cap 101398 this._addCap(this.vertices[prevEdge[1]], lastValidDir, fromColor); 101399 lastValidDir = undefined; 101400 } 101401 } 101402 if (i === this.edges.length - 1) { 101403 if (closed) { 101404 this._addJoin(end, dir, this.vertices[this.edges[0][1]].copy().sub(end).normalize(), toColor); 101405 } else { 101406 this._addCap(end, dir, toColor); 101407 } 101408 } 101409 if (dirOK) { 101410 lastValidDir = dir; 101411 } 101412 } 101413 return this; 101414 }; 101415 /** 101416 * Adds the vertices and vertex attributes for two triangles making a rectangle 101417 * for a straight line segment. A vertex shader is responsible for picking 101418 * proper coordinates on the screen given the centerline positions, the tangent, 101419 * and the side of the centerline each vertex belongs to. Sides follow the 101420 * following scheme: 101421 * 101422 * -1 -1 101423 * o-------------o 101424 * | | 101425 * o-------------o 101426 * 1 1 101427 * 101428 * @private 101429 * @chainable 101430 */ 101431 _main.default.Geometry.prototype._addSegment = function (begin, end, fromColor, toColor, dir) { 101432 var a = begin.array(); 101433 var b = end.array(); 101434 var dirArr = dir.array(); 101435 this.lineSides.push(1, - 1, 1, 1, - 1, - 1); 101436 for (var _i4 = 0, _arr = [ 101437 this.lineTangentsIn, 101438 this.lineTangentsOut 101439 ]; _i4 < _arr.length; _i4++) { 101440 var tangents = _arr[_i4]; 101441 tangents.push(dirArr, dirArr, dirArr, dirArr, dirArr, dirArr); 101442 } 101443 this.lineVertices.push(a, a, b, b, a, b); 101444 this.lineVertexColors.push(fromColor, fromColor, toColor, toColor, fromColor, toColor); 101445 return this; 101446 }; 101447 /** 101448 * Adds the vertices and vertex attributes for two triangles representing the 101449 * stroke cap of a line. A fragment shader is responsible for displaying the 101450 * appropriate cap style within the rectangle they make. 101451 * 101452 * The lineSides buffer will include the following values for the points on 101453 * the cap rectangle: 101454 * 101455 * -1 -2 101456 * -----------o---o 101457 * | | 101458 * -----------o---o 101459 * 1 2 101460 * @private 101461 * @chainable 101462 */ 101463 _main.default.Geometry.prototype._addCap = function (point, tangent, color) { 101464 var ptArray = point.array(); 101465 var tanInArray = tangent.array(); 101466 var tanOutArray = [ 101467 0, 101468 0, 101469 0 101470 ]; 101471 for (var i = 0; i < 6; i++) { 101472 this.lineVertices.push(ptArray); 101473 this.lineTangentsIn.push(tanInArray); 101474 this.lineTangentsOut.push(tanOutArray); 101475 this.lineVertexColors.push(color); 101476 } 101477 this.lineSides.push( - 1, - 2, 2, 2, 1, - 1); 101478 return this; 101479 }; 101480 /** 101481 * Adds the vertices and vertex attributes for four triangles representing a 101482 * join between two adjacent line segments. This creates a quad on either side 101483 * of the shared vertex of the two line segments, with each quad perpendicular 101484 * to the lines. A vertex shader will discard all but the quad in the "elbow" of 101485 * the join, and a fragment shader will display the appropriate join style 101486 * within the remaining quad. 101487 * 101488 * The lineSides buffer will include the following values for the points on 101489 * the join rectangles: 101490 * 101491 * -1 -2 101492 * -------------o----o 101493 * | | 101494 * 1 o----o----o -3 101495 * | | 0 | 101496 * --------o----o | 101497 * 2| 3 | 101498 * | | 101499 * | | 101500 * @private 101501 * @chainable 101502 */ 101503 _main.default.Geometry.prototype._addJoin = function (point, fromTangent, toTangent, color) { 101504 var ptArray = point.array(); 101505 var tanInArray = fromTangent.array(); 101506 var tanOutArray = toTangent.array(); 101507 for (var i = 0; i < 12; i++) { 101508 this.lineVertices.push(ptArray); 101509 this.lineTangentsIn.push(tanInArray); 101510 this.lineTangentsOut.push(tanOutArray); 101511 this.lineVertexColors.push(color); 101512 } 101513 for (var _i5 = 0, _arr2 = [ 101514 - 1, 101515 1 101516 ]; _i5 < _arr2.length; _i5++) { 101517 var side = _arr2[_i5]; 101518 this.lineSides.push(side, 2 * side, 3 * side, side, 3 * side, 0); 101519 } 101520 return this; 101521 }; 101522 /** 101523 * Modifies all vertices to be centered within the range -100 to 100. 101524 * @method normalize 101525 * @chainable 101526 */ 101527 _main.default.Geometry.prototype.normalize = function () { 101528 if (this.vertices.length > 0) { 101529 // Find the corners of our bounding box 101530 var maxPosition = this.vertices[0].copy(); 101531 var minPosition = this.vertices[0].copy(); 101532 for (var i = 0; i < this.vertices.length; i++) { 101533 maxPosition.x = Math.max(maxPosition.x, this.vertices[i].x); 101534 minPosition.x = Math.min(minPosition.x, this.vertices[i].x); 101535 maxPosition.y = Math.max(maxPosition.y, this.vertices[i].y); 101536 minPosition.y = Math.min(minPosition.y, this.vertices[i].y); 101537 maxPosition.z = Math.max(maxPosition.z, this.vertices[i].z); 101538 minPosition.z = Math.min(minPosition.z, this.vertices[i].z); 101539 } 101540 var center = _main.default.Vector.lerp(maxPosition, minPosition, 0.5); 101541 var dist = _main.default.Vector.sub(maxPosition, minPosition); 101542 var longestDist = Math.max(Math.max(dist.x, dist.y), dist.z); 101543 var scale = 200 / longestDist; 101544 for (var _i6 = 0; _i6 < this.vertices.length; _i6++) { 101545 this.vertices[_i6].sub(center); 101546 this.vertices[_i6].mult(scale); 101547 } 101548 } 101549 return this; 101550 }; 101551 var _default = _main.default.Geometry; 101552 exports.default = _default; 101553 }, 101554 { 101555 '../core/main': 290, 101556 'core-js/modules/es.array.slice': 180, 101557 'core-js/modules/es.string.sub': 210 101558 } 101559 ], 101560 340: [
101561 function (_dereq_, module, exports) { 101562 'use strict'; 101563 _dereq_('core-js/modules/es.array.iterator'); 101564 _dereq_('core-js/modules/es.object.to-string'); 101565 _dereq_('core-js/modules/es.typed-array.float32-array'); 101566 _dereq_('core-js/modules/es.typed-array.copy-within'); 101567 _dereq_('core-js/modules/es.typed-array.every'); 101568 _dereq_('core-js/modules/es.typed-array.fill'); 101569 _dereq_('core-js/modules/es.typed-array.filter'); 101570 _dereq_('core-js/modules/es.typed-array.find'); 101571 _dereq_('core-js/modules/es.typed-array.find-index'); 101572 _dereq_('core-js/modules/es.typed-array.for-each'); 101573 _dereq_('core-js/modules/es.typed-array.includes'); 101574 _dereq_('core-js/modules/es.typed-array.index-of'); 101575 _dereq_('core-js/modules/es.typed-array.iterator'); 101576 _dereq_('core-js/modules/es.typed-array.join'); 101577 _dereq_('core-js/modules/es.typed-array.last-index-of'); 101578 _dereq_('core-js/modules/es.typed-array.map'); 101579 _dereq_('core-js/modules/es.typed-array.reduce'); 101580 _dereq_('core-js/modules/es.typed-array.reduce-right'); 101581 _dereq_('core-js/modules/es.typed-array.reverse'); 101582 _dereq_('core-js/modules/es.typed-array.set'); 101583 _dereq_('core-js/modules/es.typed-array.slice'); 101584 _dereq_('core-js/modules/es.typed-array.some'); 101585 _dereq_('core-js/modules/es.typed-array.sort'); 101586 _dereq_('core-js/modules/es.typed-array.subarray'); 101587 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 101588 _dereq_('core-js/modules/es.typed-array.to-string'); 101589 _dereq_('core-js/modules/es.array.iterator'); 101590 _dereq_('core-js/modules/es.object.to-string'); 101591 _dereq_('core-js/modules/es.typed-array.float32-array'); 101592 _dereq_('core-js/modules/es.typed-array.copy-within'); 101593 _dereq_('core-js/modules/es.typed-array.every'); 101594 _dereq_('core-js/modules/es.typed-array.fill'); 101595 _dereq_('core-js/modules/es.typed-array.filter'); 101596 _dereq_('core-js/modules/es.typed-array.find'); 101597 _dereq_('core-js/modules/es.typed-array.find-index'); 101598 _dereq_('core-js/modules/es.typed-array.for-each'); 101599 _dereq_('core-js/modules/es.typed-array.includes'); 101600 _dereq_('core-js/modules/es.typed-array.index-of'); 101601 _dereq_('core-js/modules/es.typed-array.iterator'); 101602 _dereq_('core-js/modules/es.typed-array.join'); 101603 _dereq_('core-js/modules/es.typed-array.last-index-of'); 101604 _dereq_('core-js/modules/es.typed-array.map'); 101605 _dereq_('core-js/modules/es.typed-array.reduce'); 101606 _dereq_('core-js/modules/es.typed-array.reduce-right'); 101607 _dereq_('core-js/modules/es.typed-array.reverse'); 101608 _dereq_('core-js/modules/es.typed-array.set'); 101609 _dereq_('core-js/modules/es.typed-array.slice'); 101610 _dereq_('core-js/modules/es.typed-array.some'); 101611 _dereq_('core-js/modules/es.typed-array.sort'); 101612 _dereq_('core-js/modules/es.typed-array.subarray'); 101613 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 101614 _dereq_('core-js/modules/es.typed-array.to-string'); 101615 Object.defineProperty(exports, '__esModule', { 101616 value: true 101617 }); 101618 exports.default = void 0; 101619 var _main = _interopRequireDefault(_dereq_('../core/main')); 101620 function _interopRequireDefault(obj) { 101621 return obj && obj.__esModule ? obj : { 101622 default: 101623 obj 101624 }; 101625 } /** 101626 * @requires constants 101627 * @todo see methods below needing further implementation. 101628 * future consideration: implement SIMD optimizations 101629 * when browser compatibility becomes available 101630 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/ 101631 * Reference/Global_Objects/SIMD 101632 */ 101633 101634 var GLMAT_ARRAY_TYPE = Array; 101635 var isMatrixArray = function isMatrixArray(x) { 101636 return x instanceof Array; 101637 }; 101638 if (typeof Float32Array !== 'undefined') { 101639 GLMAT_ARRAY_TYPE = Float32Array; 101640 isMatrixArray = function isMatrixArray(x) { 101641 return x instanceof Array || x instanceof Float32Array; 101642 }; 101643 } /** 101644 * A class to describe a 4Ã4 matrix 101645 * for model and view matrix manipulation in the p5js webgl renderer. 101646 * @class p5.Matrix 101647 * @private 101648 * @constructor 101649 * @param {Array} [mat4] array literal of our 4Ã4 matrix 101650 */ 101651 101652 _main.default.Matrix = function () { 101653 var args = new Array(arguments.length); 101654 for (var i = 0; i < args.length; ++i) { 101655 args[i] = arguments[i]; 101656 } // This is default behavior when object 101657 // instantiated using createMatrix() 101658 // @todo implement createMatrix() in core/math.js 101659 101660 if (args.length && args[args.length - 1] instanceof _main.default) { 101661 this.p5 = args[args.length - 1]; 101662 } 101663 if (args[0] === 'mat3') { 101664 this.mat3 = Array.isArray(args[1]) ? args[1] : new GLMAT_ARRAY_TYPE([1, 101665 0, 101666 0, 101667 0, 101668 1, 101669 0, 101670 0, 101671 0, 101672 1]); 101673 } else { 101674 this.mat4 = Array.isArray(args[0]) ? args[0] : new GLMAT_ARRAY_TYPE([1, 101675 0, 101676 0, 101677 0, 101678 0, 101679 1, 101680 0, 101681 0, 101682 0, 101683 0, 101684 1, 101685 0, 101686 0, 101687 0, 101688 0, 101689 1]); 101690 } 101691 return this; 101692 }; 101693 /** 101694 * Sets the x, y, and z component of the vector using two or three separate 101695 * variables, the data from a p5.Matrix, or the values from a float array. 101696 * 101697 * @method set 101698 * @param {p5.Matrix|Float32Array|Number[]} [inMatrix] the input p5.Matrix or 101699 * an Array of length 16 101700 * @chainable 101701 */ 101702 /** 101703 * @method set 101704 * @param {Number[]} elements 16 numbers passed by value to avoid 101705 * array copying. 101706 * @chainable 101707 */ 101708 _main.default.Matrix.prototype.set = function (inMatrix) { 101709 if (inMatrix instanceof _main.default.Matrix) { 101710 this.mat4 = inMatrix.mat4; 101711 return this; 101712 } else if (isMatrixArray(inMatrix)) { 101713 this.mat4 = inMatrix; 101714 return this; 101715 } else if (arguments.length === 16) { 101716 this.mat4[0] = arguments[0]; 101717 this.mat4[1] = arguments[1]; 101718 this.mat4[2] = arguments[2]; 101719 this.mat4[3] = arguments[3]; 101720 this.mat4[4] = arguments[4]; 101721 this.mat4[5] = arguments[5]; 101722 this.mat4[6] = arguments[6]; 101723 this.mat4[7] = arguments[7]; 101724 this.mat4[8] = arguments[8]; 101725 this.mat4[9] = arguments[9]; 101726 this.mat4[10] = arguments[10]; 101727 this.mat4[11] = arguments[11]; 101728 this.mat4[12] = arguments[12]; 101729 this.mat4[13] = arguments[13]; 101730 this.mat4[14] = arguments[14]; 101731 this.mat4[15] = arguments[15]; 101732 } 101733 return this; 101734 }; 101735 /** 101736 * Gets a copy of the vector, returns a p5.Matrix object. 101737 * 101738 * @method get 101739 * @return {p5.Matrix} the copy of the p5.Matrix object 101740 */ 101741 _main.default.Matrix.prototype.get = function () { 101742 return new _main.default.Matrix(this.mat4, this.p5); 101743 }; 101744 /** 101745 * return a copy of a matrix 101746 * @method copy 101747 * @return {p5.Matrix} the result matrix 101748 */ 101749 _main.default.Matrix.prototype.copy = function () { 101750 var copied = new _main.default.Matrix(this.p5); 101751 copied.mat4[0] = this.mat4[0]; 101752 copied.mat4[1] = this.mat4[1]; 101753 copied.mat4[2] = this.mat4[2]; 101754 copied.mat4[3] = this.mat4[3]; 101755 copied.mat4[4] = this.mat4[4]; 101756 copied.mat4[5] = this.mat4[5]; 101757 copied.mat4[6] = this.mat4[6]; 101758 copied.mat4[7] = this.mat4[7]; 101759 copied.mat4[8] = this.mat4[8]; 101760 copied.mat4[9] = this.mat4[9]; 101761 copied.mat4[10] = this.mat4[10]; 101762 copied.mat4[11] = this.mat4[11]; 101763 copied.mat4[12] = this.mat4[12]; 101764 copied.mat4[13] = this.mat4[13]; 101765 copied.mat4[14] = this.mat4[14]; 101766 copied.mat4[15] = this.mat4[15]; 101767 return copied; 101768 }; 101769 /** 101770 * return an identity matrix 101771 * @method identity 101772 * @return {p5.Matrix} the result matrix 101773 */ 101774 _main.default.Matrix.identity = function (pInst) { 101775 return new _main.default.Matrix(pInst); 101776 }; 101777 /** 101778 * transpose according to a given matrix 101779 * @method transpose 101780 * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be 101781 * based on to transpose 101782 * @chainable 101783 */ 101784 _main.default.Matrix.prototype.transpose = function (a) { 101785 var a01, 101786 a02, 101787 a03, 101788 a12, 101789 a13, 101790 a23; 101791 if (a instanceof _main.default.Matrix) { 101792 a01 = a.mat4[1]; 101793 a02 = a.mat4[2]; 101794 a03 = a.mat4[3]; 101795 a12 = a.mat4[6]; 101796 a13 = a.mat4[7]; 101797 a23 = a.mat4[11]; 101798 this.mat4[0] = a.mat4[0]; 101799 this.mat4[1] = a.mat4[4]; 101800 this.mat4[2] = a.mat4[8]; 101801 this.mat4[3] = a.mat4[12]; 101802 this.mat4[4] = a01; 101803 this.mat4[5] = a.mat4[5]; 101804 this.mat4[6] = a.mat4[9]; 101805 this.mat4[7] = a.mat4[13]; 101806 this.mat4[8] = a02; 101807 this.mat4[9] = a12; 101808 this.mat4[10] = a.mat4[10]; 101809 this.mat4[11] = a.mat4[14]; 101810 this.mat4[12] = a03; 101811 this.mat4[13] = a13; 101812 this.mat4[14] = a23; 101813 this.mat4[15] = a.mat4[15]; 101814 } else if (isMatrixArray(a)) { 101815 a01 = a[1]; 101816 a02 = a[2]; 101817 a03 = a[3]; 101818 a12 = a[6]; 101819 a13 = a[7]; 101820 a23 = a[11]; 101821 this.mat4[0] = a[0]; 101822 this.mat4[1] = a[4]; 101823 this.mat4[2] = a[8]; 101824 this.mat4[3] = a[12]; 101825 this.mat4[4] = a01; 101826 this.mat4[5] = a[5]; 101827 this.mat4[6] = a[9]; 101828 this.mat4[7] = a[13]; 101829 this.mat4[8] = a02; 101830 this.mat4[9] = a12; 101831 this.mat4[10] = a[10]; 101832 this.mat4[11] = a[14]; 101833 this.mat4[12] = a03; 101834 this.mat4[13] = a13; 101835 this.mat4[14] = a23; 101836 this.mat4[15] = a[15]; 101837 } 101838 return this; 101839 }; 101840 /** 101841 * invert matrix according to a give matrix 101842 * @method invert 101843 * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be 101844 * based on to invert 101845 * @chainable 101846 */ 101847 _main.default.Matrix.prototype.invert = function (a) { 101848 var a00, 101849 a01, 101850 a02, 101851 a03, 101852 a10, 101853 a11, 101854 a12, 101855 a13; 101856 var a20, 101857 a21, 101858 a22, 101859 a23, 101860 a30, 101861 a31, 101862 a32, 101863 a33; 101864 if (a instanceof _main.default.Matrix) { 101865 a00 = a.mat4[0]; 101866 a01 = a.mat4[1]; 101867 a02 = a.mat4[2]; 101868 a03 = a.mat4[3]; 101869 a10 = a.mat4[4]; 101870 a11 = a.mat4[5]; 101871 a12 = a.mat4[6]; 101872 a13 = a.mat4[7]; 101873 a20 = a.mat4[8]; 101874 a21 = a.mat4[9]; 101875 a22 = a.mat4[10]; 101876 a23 = a.mat4[11]; 101877 a30 = a.mat4[12]; 101878 a31 = a.mat4[13]; 101879 a32 = a.mat4[14]; 101880 a33 = a.mat4[15]; 101881 } else if (isMatrixArray(a)) { 101882 a00 = a[0]; 101883 a01 = a[1]; 101884 a02 = a[2]; 101885 a03 = a[3]; 101886 a10 = a[4]; 101887 a11 = a[5]; 101888 a12 = a[6]; 101889 a13 = a[7]; 101890 a20 = a[8]; 101891 a21 = a[9]; 101892 a22 = a[10]; 101893 a23 = a[11]; 101894 a30 = a[12]; 101895 a31 = a[13]; 101896 a32 = a[14]; 101897 a33 = a[15]; 101898 } 101899 var b00 = a00 * a11 - a01 * a10; 101900 var b01 = a00 * a12 - a02 * a10; 101901 var b02 = a00 * a13 - a03 * a10; 101902 var b03 = a01 * a12 - a02 * a11; 101903 var b04 = a01 * a13 - a03 * a11; 101904 var b05 = a02 * a13 - a03 * a12; 101905 var b06 = a20 * a31 - a21 * a30; 101906 var b07 = a20 * a32 - a22 * a30; 101907 var b08 = a20 * a33 - a23 * a30; 101908 var b09 = a21 * a32 - a22 * a31; 101909 var b10 = a21 * a33 - a23 * a31; 101910 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant 101911 var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; 101912 if (!det) { 101913 return null; 101914 } 101915 det = 1 / det; 101916 this.mat4[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; 101917 this.mat4[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; 101918 this.mat4[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; 101919 this.mat4[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; 101920 this.mat4[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; 101921 this.mat4[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; 101922 this.mat4[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; 101923 this.mat4[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; 101924 this.mat4[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; 101925 this.mat4[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; 101926 this.mat4[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; 101927 this.mat4[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; 101928 this.mat4[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; 101929 this.mat4[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; 101930 this.mat4[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; 101931 this.mat4[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; 101932 return this; 101933 }; 101934 /** 101935 * Inverts a 3Ã3 matrix 101936 * @method invert3x3 101937 * @chainable 101938 */ 101939 _main.default.Matrix.prototype.invert3x3 = function () { 101940 var a00 = this.mat3[0]; 101941 var a01 = this.mat3[1]; 101942 var a02 = this.mat3[2]; 101943 var a10 = this.mat3[3]; 101944 var a11 = this.mat3[4]; 101945 var a12 = this.mat3[5]; 101946 var a20 = this.mat3[6]; 101947 var a21 = this.mat3[7]; 101948 var a22 = this.mat3[8]; 101949 var b01 = a22 * a11 - a12 * a21; 101950 var b11 = - a22 * a10 + a12 * a20; 101951 var b21 = a21 * a10 - a11 * a20; // Calculate the determinant 101952 var det = a00 * b01 + a01 * b11 + a02 * b21; 101953 if (!det) { 101954 return null; 101955 } 101956 det = 1 / det; 101957 this.mat3[0] = b01 * det; 101958 this.mat3[1] = ( - a22 * a01 + a02 * a21) * det; 101959 this.mat3[2] = (a12 * a01 - a02 * a11) * det; 101960 this.mat3[3] = b11 * det; 101961 this.mat3[4] = (a22 * a00 - a02 * a20) * det; 101962 this.mat3[5] = ( - a12 * a00 + a02 * a10) * det; 101963 this.mat3[6] = b21 * det; 101964 this.mat3[7] = ( - a21 * a00 + a01 * a20) * det; 101965 this.mat3[8] = (a11 * a00 - a01 * a10) * det; 101966 return this; 101967 }; 101968 /** 101969 * transposes a 3Ã3 p5.Matrix by a mat3 101970 * @method transpose3x3 101971 * @param {Number[]} mat3 1-dimensional array 101972 * @chainable 101973 */ 101974 _main.default.Matrix.prototype.transpose3x3 = function (mat3) { 101975 var a01 = mat3[1], 101976 a02 = mat3[2], 101977 a12 = mat3[5]; 101978 this.mat3[1] = mat3[3]; 101979 this.mat3[2] = mat3[6]; 101980 this.mat3[3] = a01; 101981 this.mat3[5] = mat3[7]; 101982 this.mat3[6] = a02; 101983 this.mat3[7] = a12; 101984 return this; 101985 }; 101986 /** 101987 * converts a 4Ã4 matrix to its 3Ã3 inverse transform 101988 * commonly used in MVMatrix to NMatrix conversions. 101989 * @method invertTranspose 101990 * @param {p5.Matrix} mat4 the matrix to be based on to invert 101991 * @chainable 101992 * @todo finish implementation 101993 */ 101994 _main.default.Matrix.prototype.inverseTranspose = function (matrix) { 101995 if (this.mat3 === undefined) { 101996 console.error('sorry, this function only works with mat3'); 101997 } else { 101998 //convert mat4 -> mat3 101999 this.mat3[0] = matrix.mat4[0]; 102000 this.mat3[1] = matrix.mat4[1]; 102001 this.mat3[2] = matrix.mat4[2]; 102002 this.mat3[3] = matrix.mat4[4]; 102003 this.mat3[4] = matrix.mat4[5]; 102004 this.mat3[5] = matrix.mat4[6]; 102005 this.mat3[6] = matrix.mat4[8]; 102006 this.mat3[7] = ma
102006trix.mat4[9]; 102007 this.mat3[8] = matrix.mat4[10]; 102008 } 102009 var inverse = this.invert3x3(); // check inverse succeeded 102010 if (inverse) { 102011 inverse.transpose3x3(this.mat3); 102012 } else { 102013 // in case of singularity, just zero the matrix 102014 for (var i = 0; i < 9; i++) { 102015 this.mat3[i] = 0; 102016 } 102017 } 102018 return this; 102019 }; 102020 /** 102021 * inspired by Toji's mat4 determinant 102022 * @method determinant 102023 * @return {Number} Determinant of our 4Ã4 matrix 102024 */ 102025 _main.default.Matrix.prototype.determinant = function () { 102026 var d00 = this.mat4[0] * this.mat4[5] - this.mat4[1] * this.mat4[4], 102027 d01 = this.mat4[0] * this.mat4[6] - this.mat4[2] * this.mat4[4], 102028 d02 = this.mat4[0] * this.mat4[7] - this.mat4[3] * this.mat4[4], 102029 d03 = this.mat4[1] * this.mat4[6] - this.mat4[2] * this.mat4[5], 102030 d04 = this.mat4[1] * this.mat4[7] - this.mat4[3] * this.mat4[5], 102031 d05 = this.mat4[2] * this.mat4[7] - this.mat4[3] * this.mat4[6], 102032 d06 = this.mat4[8] * this.mat4[13] - this.mat4[9] * this.mat4[12], 102033 d07 = this.mat4[8] * this.mat4[14] - this.mat4[10] * this.mat4[12], 102034 d08 = this.mat4[8] * this.mat4[15] - this.mat4[11] * this.mat4[12], 102035 d09 = this.mat4[9] * this.mat4[14] - this.mat4[10] * this.mat4[13], 102036 d10 = this.mat4[9] * this.mat4[15] - this.mat4[11] * this.mat4[13], 102037 d11 = this.mat4[10] * this.mat4[15] - this.mat4[11] * this.mat4[14]; // Calculate the determinant 102038 return d00 * d11 - d01 * d10 + d02 * d09 + d03 * d08 - d04 * d07 + d05 * d06; 102039 }; 102040 /** 102041 * multiply two mat4s 102042 * @method mult 102043 * @param {p5.Matrix|Float32Array|Number[]} multMatrix The matrix 102044 * we want to multiply by 102045 * @chainable 102046 */ 102047 _main.default.Matrix.prototype.mult = function (multMatrix) { 102048 var _src; 102049 if (multMatrix === this || multMatrix === this.mat4) { 102050 _src = this.copy().mat4; // only need to allocate in this rare case 102051 } else if (multMatrix instanceof _main.default.Matrix) { 102052 _src = multMatrix.mat4; 102053 } else if (isMatrixArray(multMatrix)) { 102054 _src = multMatrix; 102055 } else if (arguments.length === 16) { 102056 _src = arguments; 102057 } else { 102058 return; // nothing to do. 102059 } // each row is used for the multiplier 102060 102061 var b0 = this.mat4[0], 102062 b1 = this.mat4[1], 102063 b2 = this.mat4[2], 102064 b3 = this.mat4[3]; 102065 this.mat4[0] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; 102066 this.mat4[1] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; 102067 this.mat4[2] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; 102068 this.mat4[3] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; 102069 b0 = this.mat4[4]; 102070 b1 = this.mat4[5]; 102071 b2 = this.mat4[6]; 102072 b3 = this.mat4[7]; 102073 this.mat4[4] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; 102074 this.mat4[5] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; 102075 this.mat4[6] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; 102076 this.mat4[7] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; 102077 b0 = this.mat4[8]; 102078 b1 = this.mat4[9]; 102079 b2 = this.mat4[10]; 102080 b3 = this.mat4[11]; 102081 this.mat4[8] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; 102082 this.mat4[9] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; 102083 this.mat4[10] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; 102084 this.mat4[11] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; 102085 b0 = this.mat4[12]; 102086 b1 = this.mat4[13]; 102087 b2 = this.mat4[14]; 102088 b3 = this.mat4[15]; 102089 this.mat4[12] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; 102090 this.mat4[13] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; 102091 this.mat4[14] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; 102092 this.mat4[15] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; 102093 return this; 102094 }; 102095 _main.default.Matrix.prototype.apply = function (multMatrix) { 102096 var _src; 102097 if (multMatrix === this || multMatrix === this.mat4) { 102098 _src = this.copy().mat4; // only need to allocate in this rare case 102099 } else if (multMatrix instanceof _main.default.Matrix) { 102100 _src = multMatrix.mat4; 102101 } else if (isMatrixArray(multMatrix)) { 102102 _src = multMatrix; 102103 } else if (arguments.length === 16) { 102104 _src = arguments; 102105 } else { 102106 return; // nothing to do. 102107 } 102108 var mat4 = this.mat4; // each row is used for the multiplier 102109 var m0 = mat4[0]; 102110 var m4 = mat4[4]; 102111 var m8 = mat4[8]; 102112 var m12 = mat4[12];
102113 mat4[0] = _src[0] * m0 + _src[1] * m4 + _src[2] * m8 + _src[3] * m12; 102114 mat4[4] = _src[4] * m0 + _src[5] * m4 + _src[6] * m8 + _src[7] * m12; 102115 mat4[8] = _src[8] * m0 + _src[9] * m4 + _src[10] * m8 + _src[11] * m12; 102116 mat4[12] = _src[12] * m0 + _src[13] * m4 + _src[14] * m8 + _src[15] * m12; 102117 var m1 = mat4[1]; 102118 var m5 = mat4[5]; 102119 var m9 = mat4[9]; 102120 var m13 = mat4[13]; 102121 mat4[1] = _src[0] * m1 + _src[1] * m5 + _src[2] * m9 + _src[3] * m13; 102122 mat4[5] = _src[4] * m1 + _src[5] * m5 + _src[6] * m9 + _src[7] * m13; 102123 mat4[9] = _src[8] * m1 + _src[9] * m5 + _src[10] * m9 + _src[11] * m13; 102124 mat4[13] = _src[12] * m1 + _src[13] * m5 + _src[14] * m9 + _src[15] * m13; 102125 var m2 = mat4[2]; 102126 var m6 = mat4[6]; 102127 var m10 = mat4[10]; 102128 var m14 = mat4[14]; 102129 mat4[2] = _src[0] * m2 + _src[1] * m6 + _src[2] * m10 + _src[3] * m14; 102130 mat4[6] = _src[4] * m2 + _src[5] * m6 + _src[6] * m10 + _src[7] * m14; 102131 mat4[10] = _src[8] * m2 + _src[9] * m6 + _src[10] * m10 + _src[11] * m14; 102132 mat4[14] = _src[12] * m2 + _src[13] * m6 + _src[14] * m10 + _src[15] * m14; 102133 var m3 = mat4[3]; 102134 var m7 = mat4[7]; 102135 var m11 = mat4[11]; 102136 var m15 = mat4[15]; 102137 mat4[3] = _src[0] * m3 + _src[1] * m7 + _src[2] * m11 + _src[3] * m15; 102138 mat4[7] = _src[4] * m3 + _src[5] * m7 + _src[6] * m11 + _src[7] * m15; 102139 mat4[11] = _src[8] * m3 + _src[9] * m7 + _src[10] * m11 + _src[11] * m15; 102140 mat4[15] = _src[12] * m3 + _src[13] * m7 + _src[14] * m11 + _src[15] * m15; 102141 return this; 102142 }; 102143 /** 102144 * scales a p5.Matrix by scalars or a vector 102145 * @method scale 102146 * @param {p5.Vector|Float32Array|Number[]} s vector to scale by 102147 * @chainable 102148 */ 102149 _main.default.Matrix.prototype.scale = function (x, y, z) { 102150 if (x instanceof _main.default.Vector) { 102151 // x is a vector, extract the components from it. 102152 y = x.y; 102153 z = x.z; 102154 x = x.x; // must be last 102155 } else if (x instanceof Array) { 102156 // x is an array, extract the components from it. 102157 y = x[1]; 102158 z = x[2]; 102159 x = x[0]; // must be last 102160 } 102161 this.mat4[0] *= x; 102162 this.mat4[1] *= x; 102163 this.mat4[2] *= x; 102164 this.mat4[3] *= x; 102165 this.mat4[4] *= y; 102166 this.mat4[5] *= y; 102167 this.mat4[6] *= y; 102168 this.mat4[7] *= y; 102169 this.mat4[8] *= z; 102170 this.mat4[9] *= z; 102171 this.mat4[10] *= z; 102172 this.mat4[11] *= z; 102173 return this; 102174 }; 102175 /** 102176 * rotate our Matrix around an axis by the given angle. 102177 * @method rotate 102178 * @param {Number} a The angle of rotation in radians 102179 * @param {p5.Vector|Number[]} axis the axis(es) to rotate around 102180 * @chainable 102181 * inspired by Toji's gl-matrix lib, mat4 rotation 102182 */ 102183 _main.default.Matrix.prototype.rotate = function (a, x, y, z) { 102184 if (x instanceof _main.default.Vector) { 102185 // x is a vector, extract the components from it. 102186 y = x.y; 102187 z = x.z; 102188 x = x.x; //must be last 102189 } else if (x instanceof Array) { 102190 // x is an array, extract the components from it. 102191 y = x[1]; 102192 z = x[2]; 102193 x = x[0]; //must be last 102194 } 102195 var len = Math.sqrt(x * x + y * y + z * z); 102196 x *= 1 / len; 102197 y *= 1 / len; 102198 z *= 1 / len; 102199 var a00 = this.mat4[0]; 102200 var a01 = this.mat4[1]; 102201 var a02 = this.mat4[2]; 102202 var a03 = this.mat4[3]; 102203 var a10 = this.mat4[4]; 102204 var a11 = this.mat4[5]; 102205 var a12 = this.mat4[6]; 102206 var a13 = this.mat4[7]; 102207 var a20 = this.mat4[8]; 102208 var a21 = this.mat4[9]; 102209 var a22 = this.mat4[10]; 102210 var a23 = this.mat4[11]; //sin,cos, and tan of respective angle 102211 var sA = Math.sin(a); 102212 var cA = Math.cos(a); 102213 var tA = 1 - cA; // Construct the elements of the rotation matrix 102214 var b00 = x * x * tA + cA; 102215 var b01 = y * x * tA + z * sA; 102216 var b02 = z * x * tA - y * sA; 102217 var b10 = x * y * tA - z * sA; 102218 var b11 = y * y * tA + cA; 102219 var b12 = z * y * tA + x * sA; 102220 var b20 = x * z * tA + y * sA; 102221 var b21 = y * z * tA - x * sA; 102222 var b22 = z * z * tA + cA; // rotation-specific matrix multiplication 102223 this.mat4[0] = a00 * b00 + a10 * b01 + a20 * b02; 102224 this.mat4[1] = a01 * b00 + a11 * b01 + a21 * b02; 102225 this.mat4[2] = a02 * b00 + a12 * b01 + a22 * b02; 102226 this.mat4[3] = a03 * b00 + a13 * b01 + a23 * b02; 102227 this.mat4[4] = a00 * b10 + a10 * b11 + a20 * b12; 102228 this.mat4[5] = a01 * b10 + a11 * b11 + a21 * b12; 102229 this.mat4[6] = a02 * b10 + a12 * b11 + a22 * b12; 102230 this.mat4[7] = a03 * b10 + a13 * b11 + a23 * b12; 102231 this.mat4[8] = a00 * b20 + a10 * b21 + a20 * b22; 102232 this.mat4[9] = a01 * b20 + a11 * b21 + a21 * b22; 102233 this.mat4[10] = a02 * b20 + a12 * b21 + a22 * b22; 102234 this.mat4[11] = a03 * b20 + a13 * b21 + a23 * b22; 102235 return this; 102236 }; 102237 /** 102238 * @todo finish implementing this method! 102239 * translates 102240 * @method translate 102241 * @param {Number[]} v vector to translate by 102242 * @chainable 102243 */ 102244 _main.default.Matrix.prototype.translate = function (v) { 102245 var x = v[0], 102246 y = v[1], 102247 z = v[2] || 0; 102248 this.mat4[12] += this.mat4[0] * x + this.mat4[4] * y + this.mat4[8] * z; 102249 this.mat4[13] += this.mat4[1] * x + this.mat4[5] * y + this.mat4[9] * z; 102250 this.mat4[14] += this.mat4[2] * x + this.mat4[6] * y + this.mat4[10] * z; 102251 this.mat4[15] += this.mat4[3] * x + this.mat4[7] * y + this.mat4[11] * z; 102252 }; 102253 _main.default.Matrix.prototype.rotateX = function (a) { 102254 this.rotate(a, 1, 0, 0); 102255 }; 102256 _main.default.Matrix.prototype.rotateY = function (a) { 102257 this.rotate(a, 0, 1, 0); 102258 }; 102259 _main.default.Matrix.prototype.rotateZ = function (a) { 102260 this.rotate(a, 0, 0, 1); 102261 }; 102262 /** 102263 * sets the perspective matrix 102264 * @method perspective 102265 * @param {Number} fovy [description] 102266 * @param {Number} aspect [description] 102267 * @param {Number} near near clipping plane 102268 * @param {Number} far far clipping plane 102269 * @chainable 102270 */ 102271 _main.default.Matrix.prototype.perspective = function (fovy, aspect, near, far) { 102272 var f = 1 / Math.tan(fovy / 2), 102273 nf = 1 / (near - far); 102274 this.mat4[0] = f / aspect; 102275 this.mat4[1] = 0; 102276 this.mat4[2] = 0; 102277 this.mat4[3] = 0; 102278 this.mat4[4] = 0; 102279 this.mat4[5] = f; 102280 this.mat4[6] = 0; 102281 this.mat4[7] = 0; 102282 this.mat4[8] = 0; 102283 this.mat4[9] = 0; 102284 this.mat4[10] = (far + near) * nf; 102285 this.mat4[11] = - 1; 102286 this.mat4[12] = 0; 102287 this.mat4[13] = 0; 102288 this.mat4[14] = 2 * far * near * nf; 102289 this.mat4[15] = 0; 102290 return this; 102291 }; 102292 /** 102293 * sets the ortho matrix 102294 * @method ortho 102295 * @param {Number} left [description] 102296 * @param {Number} right [description] 102297 * @param {Number} bottom [description] 102298 * @param {Number} top [description] 102299 * @param {Number} near near clipping plane 102300 * @param {Number} far far clipping plane 102301 * @chainable 102302 */ 102303 _main.default.Matrix.prototype.ortho = function (left, right, bottom, top, near, far) { 102304 var lr = 1 / (left - right),
102305 bt = 1 / (bottom - top), 102306 nf = 1 / (near - far); 102307 this.mat4[0] = - 2 * lr; 102308 this.mat4[1] = 0; 102309 this.mat4[2] = 0; 102310 this.mat4[3] = 0; 102311 this.mat4[4] = 0; 102312 this.mat4[5] = - 2 * bt; 102313 this.mat4[6] = 0; 102314 this.mat4[7] = 0; 102315 this.mat4[8] = 0; 102316 this.mat4[9] = 0; 102317 this.mat4[10] = 2 * nf; 102318 this.mat4[11] = 0; 102319 this.mat4[12] = (left + right) * lr; 102320 this.mat4[13] = (top + bottom) * bt; 102321 this.mat4[14] = (far + near) * nf; 102322 this.mat4[15] = 1; 102323 return this; 102324 }; 102325 /** 102326 * PRIVATE 102327 */ 102328 // matrix methods adapted from: 102329 // https://developer.mozilla.org/en-US/docs/Web/WebGL/ 102330 // gluPerspective 102331 // 102332 // function _makePerspective(fovy, aspect, znear, zfar){ 102333 // const ymax = znear * Math.tan(fovy * Math.PI / 360.0); 102334 // const ymin = -ymax; 102335 // const xmin = ymin * aspect; 102336 // const xmax = ymax * aspect; 102337 // return _makeFrustum(xmin, xmax, ymin, ymax, znear, zfar); 102338 // } 102339 //// 102340 //// glFrustum 102341 //// 102342 //function _makeFrustum(left, right, bottom, top, znear, zfar){ 102343 // const X = 2*znear/(right-left); 102344 // const Y = 2*znear/(top-bottom); 102345 // const A = (right+left)/(right-left); 102346 // const B = (top+bottom)/(top-bottom); 102347 // const C = -(zfar+znear)/(zfar-znear); 102348 // const D = -2*zfar*znear/(zfar-znear); 102349 // const frustrumMatrix =[ 102350 // X, 0, A, 0, 102351 // 0, Y, B, 0, 102352 // 0, 0, C, D, 102353 // 0, 0, -1, 0 102354 //]; 102355 //return frustrumMatrix; 102356 // } 102357 // function _setMVPMatrices(){ 102358 ////an identity matrix 102359 ////@TODO use the p5.Matrix class to abstract away our MV matrices and 102360 ///other math 102361 //const _mvMatrix = 102362 //[ 102363 // 1.0,0.0,0.0,0.0, 102364 // 0.0,1.0,0.0,0.0, 102365 // 0.0,0.0,1.0,0.0, 102366 // 0.0,0.0,0.0,1.0 102367 //]; 102368 var _default = _main.default.Matrix; 102369 exports.default = _default; 102370 }, 102371 { 102372 '../core/main': 290, 102373 'core-js/modules/es.array.iterator': 176, 102374 'core-js/modules/es.object.to-string': 195, 102375 'core-js/modules/es.typed-array.copy-within': 215, 102376 'core-js/modules/es.typed-array.every': 216, 102377 'core-js/modules/es.typed-array.fill': 217, 102378 'core-js/modules/es.typed-array.filter': 218, 102379 'core-js/modules/es.typed-array.find': 220, 102380 'core-js/modules/es.typed-array.find-index': 219, 102381 'core-js/modules/es.typed-array.float32-array': 221, 102382 'core-js/modules/es.typed-array.for-each': 223, 102383 'core-js/modules/es.typed-array.includes': 224, 102384 'core-js/modules/es.typed-array.index-of': 225, 102385 'core-js/modules/es.typed-array.iterator': 228, 102386 'core-js/modules/es.typed-array.join': 229, 102387 'core-js/modules/es.typed-array.last-index-of': 230, 102388 'core-js/modules/es.typed-array.map': 231, 102389 'core-js/modules/es.typed-array.reduce': 233, 102390 'core-js/modules/es.typed-array.reduce-right': 232, 102391 'core-js/modules/es.typed-array.reverse': 234, 102392 'core-js/modules/es.typed-array.set': 235, 102393 'core-js/modules/es.typed-array.slice': 236, 102394 'core-js/modules/es.typed-array.some': 237, 102395 'core-js/modules/es.typed-array.sort': 238, 102396 'core-js/modules/es.typed-array.subarray': 239, 102397 'core-js/modules/es.typed-array.to-locale-string': 240, 102398 'core-js/modules/es.typed-array.to-string': 241 102399 } 102400 ], 102401 341: [ 102402 function (_dereq_, module, exports) { 102403 'use strict'; 102404 _dereq_('core-js/modules/es.array.map'); 102405 _dereq_('core-js/modules/es.array.map'); 102406 Object.defineProperty(exports, '__esModule', { 102407 value: true 102408 }); 102409 exports.default = void 0; 102410 var _main = _interopRequireDefault(_dereq_('../core/main')); 102411 function _interopRequireDefault(obj) { 102412 return obj && obj.__esModule ? obj : { 102413 default: 102414 obj 102415 }; 102416 } 102417 _main.default.RenderBuffer = function (size, src, dst, attr, renderer, map) { 102418 this.size = size; // the number of FLOATs in each vertex 102419 this.src = src; // the name of the model's source array 102420 this.dst = dst; // the name of the geometry's buffer 102421 this.attr = attr; // the name of the vertex attribute 102422 this._renderer = renderer; 102423 this.map = map; // optional, a transformation function to apply to src 102424 }; 102425 /** 102426 * Enables and binds the buffers used by shader when the appropriate data exists in geometry. 102427 * Must always be done prior to drawing geometry in WebGL. 102428 * @param {p5.Geometry} geometry Geometry that is going to be drawn 102429 * @param {p5.Shader} shader Active shader 102430 * @private 102431 */ 102432 _main.default.RenderBuffer.prototype._prepareBuffer = function (geometry, shader) { 102433 var attributes = shader.attributes; 102434 var gl = this._renderer.GL; 102435 var model; 102436 if (geometry.model) { 102437 model = geometry.model; 102438 } else { 102439 model = geometry; 102440 } // loop through each of the buffer definitions 102441 102442 var attr = attributes[this.attr]; 102443 if (!attr) { 102444 return; 102445 } // check if the model has the appropriate source array 102446 102447 var buffer = geometry[this.dst]; 102448 var src = model[this.src]; 102449 if (src.length > 0) { 102450 // check if we need to create the GL buffer 102451 var createBuffer = !buffer; 102452 if (createBuffer) { 102453 // create and remember the buffer 102454 geometry[this.dst] = buffer = gl.createBuffer(); 102455 } // bind the buffer 102456 102457 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // check if we need to fill the buffer with data 102458 if (createBuffer || model.dirtyFlags[this.src] !== false) { 102459 var map = this.map; // get the values from the model, possibly transformed 102460 var values = map ? map(src) : src;
102460 // fill the buffer with the values 102461 this._renderer._bindBuffer(buffer, gl.ARRAY_BUFFER, values); // mark the model's source array as clean 102462 model.dirtyFlags[this.src] = false; 102463 } // enable the attribute 102464 102465 shader.enableAttrib(attr, this.size); 102466 } else { 102467 var loc = attr.location; 102468 if (loc === - 1 || !this._renderer.registerEnabled[loc]) { 102469 return; 102470 } // Disable register corresponding to unused attribute 102471 102472 gl.disableVertexAttribArray(loc); // Record register availability 102473 this._renderer.registerEnabled[loc] = false; 102474 } 102475 }; 102476 var _default = _main.default.RenderBuffer; 102477 exports.default = _default; 102478 }, 102479 { 102480 '../core/main': 290, 102481 'core-js/modules/es.array.map': 179 102482 } 102483 ], 102484 342: [ 102485 function (_dereq_, module, exports) { 102486 'use strict'; 102487 _dereq_('core-js/modules/es.symbol'); 102488 _dereq_('core-js/modules/es.symbol.description'); 102489 _dereq_('core-js/modules/es.symbol.iterator'); 102490 _dereq_('core-js/modules/es.array.concat'); 102491 _dereq_('core-js/modules/es.array.fill'); 102492 _dereq_('core-js/modules/es.array.from'); 102493 _dereq_('core-js/modules/es.array.iterator'); 102494 _dereq_('core-js/modules/es.array.map'); 102495 _dereq_('core-js/modules/es.array.slice'); 102496 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 102497 _dereq_('core-js/modules/es.object.to-string'); 102498 _dereq_('core-js/modules/es.regexp.to-string'); 102499 _dereq_('core-js/modules/es.string.iterator'); 102500 _dereq_('core-js/modules/es.weak-map'); 102501 _dereq_('core-js/modules/web.dom-collections.iterator'); 102502 function _typeof2(obj) { 102503 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 102504 _typeof2 = function _typeof2(obj) { 102505 return typeof obj; 102506 }; 102507 } else { 102508 _typeof2 = function _typeof2(obj) { 102509 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 102510 }; 102511 } 102512 return _typeof2(obj); 102513 } 102514 function _typeof(obj) { 102515 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 102516 _typeof = function _typeof(obj) { 102517 return _typeof2(obj); 102518 }; 102519 } else { 102520 _typeof = function _typeof(obj) { 102521 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 102522 }; 102523 } 102524 return _typeof(obj); 102525 } 102526 _dereq_('core-js/modules/es.symbol'); 102527 _dereq_('core-js/modules/es.symbol.description'); 102528 _dereq_('core-js/modules/es.symbol.iterator'); 102529 _dereq_('core-js/modules/es.array.concat'); 102530 _dereq_('core-js/modules/es.array.fill'); 102531 _dereq_('core-js/modules/es.array.from'); 102532 _dereq_('core-js/modules/es.array.iterator'); 102533 _dereq_('core-js/modules/es.array.map'); 102534 _dereq_('core-js/modules/es.array.slice'); 102535 _dereq_('core-js/modules/es.object.to-string'); 102536 _dereq_('core-js/modules/es.regexp.to-string'); 102537 _dereq_('core-js/modules/es.string.iterator'); 102538 _dereq_('core-js/modules/web.dom-collections.iterator'); 102539 Object.defineProperty(exports, '__esModule', { 102540 value: true 102541 }); 102542 exports.default = void 0; 102543 var _main = _interopRequireDefault(_dereq_('../core/main')); 102544 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 102545 _dereq_('./p5.RenderBuffer'); 102546 function _getRequireWildcardCache() { 102547 if (typeof WeakMap !== 'function') return null; 102548 var cache = new WeakMap(); 102549 _getRequireWildcardCache = function _getRequireWildcardCache() { 102550 return cache; 102551 }; 102552 return cache; 102553 } 102554 function _interopRequireWildcard(obj) { 102555 if (obj && obj.__esModule) { 102556 return obj; 102557 } 102558 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 102559 return { 102560 default: 102561 obj 102562 }; 102563 } 102564 var cache = _getRequireWildcardCache(); 102565 if (cache && cache.has(obj)) { 102566 return cache.get(obj); 102567 } 102568 var newObj = { 102569 }; 102570 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 102571 for (var key in obj) { 102572 if (Object.prototype.hasOwnProperty.call(obj, key)) { 102573 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 102574 if (desc && (desc.get || desc.set)) { 102575 Object.defineProperty(newObj, key, desc); 102576 } else { 102577 newObj[key] = obj[key]; 102578 } 102579 } 102580 } 102581 newObj.default = obj; 102582 if (cache) { 102583 cache.set(obj, newObj); 102584 } 102585 return newObj; 102586 } 102587 function _interopRequireDefault(obj) { 102588 return obj && obj.__esModule ? obj : { 102589 default: 102590 obj 102591 }; 102592 } 102593 function _toConsumableArray(arr) { 102594 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); 102595 } 102596 function _nonIterableSpread() { 102597 throw new TypeError('Invalid attempt to spread non-iterable instance'); 102598 } 102599 function _iterableToArray(iter) { 102600 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') return Array.from(iter); 102601 } 102602 function _arrayWithoutHoles(arr) { 102603 if (Array.isArray(arr)) { 102604 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 102605 arr2[i] = arr[i]; 102606 } 102607 return arr2; 102608 } 102609 } /** 102610 * Begin shape drawing. This is a helpful way of generating 102611 * custom shapes quickly. However in WEBGL mode, application 102612 * performance will likely drop as a result of too many calls to 102613 * <a href="#/p5/beginShape">beginShape()</a> / <a href="#/p5/endShape">endShape()</a>. As a high performance alternative, 102614 * please use p5.js geometry primitives. 102615 * @private 102616 * @method beginShape 102617 * @param {Number} mode webgl primitives mode. beginShape supports the 102618 * following modes: 102619 * POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES, 102620 * TRIANGLE_STRIP, TRIANGLE_FAN, QUADS, QUAD_STRIP, 102621 * and TESS(WEBGL only) 102622 * @chainable 102623 */ 102624 102625 _main.default.RendererGL.prototype.beginShape = function (mode) { 102626 this.immediateMode.shapeMode = mode !== undefined ? mode : constants.TESS; 102627 this.immediateMode.geometry.reset(); 102628 return this; 102629 }; 102630 var immediateBufferStrides = { 102631 vertices: 1, 102632 vertexNormals: 1, 102633 vertexColors: 4, 102634 vertexStrokeColors: 4, 102635 uvs: 2 102636 }; 102637 /** 102638 * adds a vertex to be drawn in a custom Shape. 102639 * @private 102640 * @method vertex 102641 * @param {Number} x x-coordinate of vertex 102642 * @param {Number} y y-coordinate of vertex 102643 * @param {Number} z z-coordinate of vertex 102644 * @chainable 102645 * @TODO implement handling of <a href="#/p5.Vector">p5.Vector</a> args 102646 */ 102647 _main.default.RendererGL.prototype.vertex = function (x, y) { 102648 // WebGL 1 doesn't support QUADS or QUAD_STRIP, so we duplicate data to turn 102649 // QUADS into TRIANGLES and QUAD_STRIP into TRIANGLE_STRIP. (There is no extra 102650 // work to convert QUAD_STRIP here, since the only difference is in how edges 102651 // are rendered.) 102652 if (this.immediateMode.shapeMode === constants.QUADS) { 102653 // A finished quad turned into triangles should leave 6 vertices in the 102654 // buffer: 102655 // 0--3 0 3--5 102656 // | | --> | \ \ | 102657 // 1--2 1--2 4 102658 // When vertex index 3 is being added, add the necessary duplicates. 102659 if (this.immediateMode.geometry.vertices.length % 6 === 3) { 102660 for (var key in immediateBufferStrides) { 102661 var stride = immediateBufferStrides[key]; 102662 var buffer = this.immediateMode.geometry[key]; 102663 buffer.push.apply(buffer, _toConsumableArray(buffer.slice(buffer.length - 3 * stride, buffer.length - 2 * stride)).concat(_toConsumableArray(buffer.slice(buffer.length - stride, buffer.length)))); 102664 } 102665 } 102666 } 102667 var z, 102668 u, 102669 v; // default to (x, y) mode: all other arguments assumed to be 0. 102670 z = u = v = 0; 102671 if (arguments.length === 3) { 102672 // (x, y, z) mode: (u, v) assumed to be 0. 102673 z = arguments[2]; 102674 } else if (arguments.length === 4) { 102675 // (x, y, u, v) mode: z assumed to be 0. 102676 u = arguments[2]; 102677 v = arguments[3]; 102678 } else if (arguments.length === 5) { 102679 // (x, y, z, u, v) mode 102680 z = arguments[2]; 102681 u = arguments[3]; 102682 v = arguments[4]; 102683 } 102684 var vert = new _main.default.Vector(x, y, z); 102685 this.immediateMode.geometry.vertices.push(vert); 102686 this.immediateMode.geometry.vertexNormals.push(this._currentNormal); 102687 var vertexColor = this.curFillColor || [ 102688 0.5, 102689 0.5, 102690 0.5, 102691 1 102692 ]; 102693 this.immediateMode.geometry.vertexColors.push(vertexColor[0], vertexColor[1], vertexColor[2], vertexColor[3]); 102694 var lineVertexColor = this.curStrokeColor || [ 102695 0.5, 102696 0.5, 102697 0.5, 102698 1 102699 ]; 102700 this.immediateMode.geometry.vertexStrokeColors.push(lineVertexColor[0], lineVertexColor[1], lineVertexColor[2], lineVertexColor[3]); 102701 if (this.textureMode === constants.IMAGE) { 102702 if (this._tex !== null) { 102703 if (this._tex.width > 0 && this._tex.height > 0) { 102704 u /= this._tex.width; 102705 v /= this._tex.height; 102706 } 102707 } else if (!this.isProcessingVertices && this._tex === null && arguments.length >= 4) { 102708 // Only throw this warning if custom uv's have been provided 102709 console.warn('You must first call texture() before using' + ' vertex() with image based u and v coordinates'); 102710 } 102711 } 102712 this.immediateMode.geometry.uvs.push(u, v); 102713 this.immediateMode._bezierVertex[0] = x; 102714 this.immediateMode._bezierVertex[1] = y; 102715 this.immediateMode._bezierVertex[2] = z; 102716 this.immediateMode._quadraticVertex[0] = x; 102717 this.immediateMode._quadraticVertex[1] = y; 102718 this.immediateMode._quadraticVertex[2] = z; 102719 return this; 102720 }; 102721 /** 102722 * Sets the normal to use for subsequent vertices. 102723 * @method vertexNormal 102724 * @param {Number} x 102725 * @param {Number} y 102726 * @param {Number} z 102727 * @chainable 102728 * 102729 * @method vertexNormal 102730 * @param {Vector} v 102731 * @chainable 102732 */ 102733 _main.default.RendererGL.prototype.normal = function (xorv, y, z) { 102734 if (xorv instanceof _main.default.Vector) { 102735 this._currentNormal = xorv; 102736 } else { 102737 this._currentNormal = new _main.default.Vector(xorv, y, z); 102738 } 102739 return this; 102740 }; 102741 /** 102742 * End shape drawing and render vertices to screen. 102743 * @chainable 102744 */ 102745 _main.default.RendererGL.prototype.endShape = function (mode, isCurve, isBezier, isQuadratic, isContour, shapeKind) { 102746 if (this.immediateMode.shapeMode === constants.POINTS) { 102747 this._drawPoints(this.immediateMode.geometry.vertices, this.immediateMode.buffers.point); 102748 return this; 102749 } 102750 this.isProcessingVertices = true; 102751 this._processVertices.apply(this, arguments); 102752 this.isProcessingVertices = false;
102753 if (this._doFill) { 102754 if (this.immediateMode.geometry.vertices.length > 1) { 102755 this._drawImmediateFill(); 102756 } 102757 } 102758 if (this._doStroke) { 102759 if (this.immediateMode.geometry.lineVertices.length > 1) { 102760 this._drawImmediateStroke(); 102761 } 102762 } 102763 this.isBezier = false; 102764 this.isQuadratic = false; 102765 this.isCurve = false; 102766 this.immediateMode._bezierVertex.length = 0; 102767 this.immediateMode._quadraticVertex.length = 0; 102768 this.immediateMode._curveVertex.length = 0; 102769 return this; 102770 }; 102771 /** 102772 * Called from endShape(). This function calculates the stroke vertices for custom shapes and 102773 * tesselates shapes when applicable. 102774 * @private 102775 * @param {Number} mode webgl primitives mode. beginShape supports the 102776 * following modes: 102777 * POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES, 102778 * TRIANGLE_STRIP, TRIANGLE_FAN and TESS(WEBGL only) 102779 */ 102780 _main.default.RendererGL.prototype._processVertices = function (mode) { 102781 if (this.immediateMode.geometry.vertices.length === 0) return; 102782 var calculateStroke = this._doStroke; 102783 var shouldClose = mode === constants.CLOSE; 102784 if (calculateStroke) { 102785 this.immediateMode.geometry.edges = this._calculateEdges(this.immediateMode.shapeMode, this.immediateMode.geometry.vertices, shouldClose); 102786 this.immediateMode.geometry._edgesToVertices(); 102787 } // For hollow shapes, user must set mode to TESS 102788 102789 var convexShape = this.immediateMode.shapeMode === constants.TESS; // We tesselate when drawing curves or convex shapes 102790 var shouldTess = this._doFill && (this.isBezier || this.isQuadratic || this.isCurve || convexShape) && this.immediateMode.shapeMode !== constants.LINES; 102791 if (shouldTess) { 102792 this._tesselateShape(); 102793 } 102794 }; 102795 /** 102796 * Called from _processVertices(). This function calculates the stroke vertices for custom shapes and 102797 * tesselates shapes when applicable. 102798 * @private 102799 * @returns {Array[Number]} indices for custom shape vertices indicating edges. 102800 */ 102801 _main.default.RendererGL.prototype._calculateEdges = function (shapeMode, verts, shouldClose) { 102802 var res = [ 102803 ]; 102804 var i = 0; 102805 switch (shapeMode) { 102806 case constants.TRIANGLE_STRIP: 102807 for (i = 0; i < verts.length - 2; i++) { 102808 res.push([i, 102809 i + 1]); 102810 res.push([i, 102811 i + 2]); 102812 } 102813 res.push([i, 102814 i + 1]); 102815 break; 102816 case constants.TRIANGLE_FAN: 102817 for (i = 1; i < verts.length - 1; i++) { 102818 res.push([0, 102819 i]); 102820 res.push([i, 102821 i + 1]); 102822 } 102823 res.push([0, 102824 verts.length - 1]); 102825 break; 102826 case constants.TRIANGLES: 102827 for (i = 0; i < verts.length - 2; i = i + 3) { 102828 res.push([i, 102829 i + 1]); 102830 res.push([i + 1, 102831 i + 2]); 102832 res.push([i + 2, 102833 i]); 102834 } 102835 break; 102836 case constants.LINES: 102837 for (i = 0; i < verts.length - 1; i = i + 2) { 102838 res.push([i, 102839 i + 1]); 102840 } 102841 break; 102842 case constants.QUADS: 102843 // Quads have been broken up into two triangles by `vertex()`: 102844 // 0 3--5 102845 // | \ \ | 102846 // 1--2 4 102847 for (i = 0; i < verts.length - 5; i += 6) { 102848 res.push([i, 102849 i + 1]); 102850 res.push([i + 1, 102851 i + 2]); 102852 res.push([i + 3, 102853 i + 5]); 102854 res.push([i + 4, 102855 i + 5]); 102856 } 102857 break; 102858 case constants.QUAD_STRIP: 102859 // 0---2---4 102860 // | | | 102861 // 1---3---5 102862 for (i = 0; i < verts.length - 2; i += 2) { 102863 res.push([i, 102864 i + 1]); 102865 res.push([i, 102866 i + 2]); 102867 res.push([i + 1, 102868 i + 3]); 102869 } 102870 res.push([i, 102871 i + 1]); 102872 break; 102873 default: 102874 for (i = 0; i < verts.length - 1; i++) { 102875 res.push([i, 102876 i + 1]); 102877 } 102878 break; 102879 } 102880 if (shouldClose) { 102881 res.push([verts.length - 1, 102882 0]); 102883 } 102884 return res; 102885 }; 102886 /** 102887 * Called from _processVertices() when applicable. This function tesselates immediateMode.geometry. 102888 * @private 102889 */ 102890 _main.default.RendererGL.prototype._tesselateShape = function () { 102891 var _this = this; 102892 this.immediateMode.shapeMode = constants.TRIANGLES; 102893 var contours = [ 102894 this._flatten(this.immediateMode.geometry.vertices.map(function (vert, i) { 102895 return [vert.x, 102896 vert.y, 102897 vert.z, 102898 _this.immediateMode.geometry.uvs[i * 2], 102899 _this.immediateMode.geometry.uvs[i * 2 + 1], 102900 _this.immediateMode.geometry.vertexColors[i * 4], 102901 _this.immediateMode.geometry.vertexColors[i * 4 + 1], 102902 _this.immediateMode.geometry.vertexColors[i * 4 + 2], 102903 _this.immediateMode.geometry.vertexColors[i * 4 + 3], 102904 _this.immediateMode.geometry.vertexNormals[i].x, 102905 _this.immediateMode.geometry.vertexNormals[i].y, 102906 _this.immediateMode.geometry.vertexNormals[i].z]; 102907 })) 102908 ]; 102909 var polyTriangles = this._triangulate(contours); 102910 this.immediateMode.geometry.vertices = [ 102911 ]; 102912 this.immediateMode.geometry.vertexNormals = [ 102913 ]; 102914 this.immediateMode.geometry.uvs = [ 102915 ]; 102916 var colors = [ 102917 ]; 102918 for (var j = 0, polyTriLength = polyTriangles.length; j < polyTriLength; j = j + _main.default.RendererGL.prototype.tessyVertexSize) { 102919 colors.push.apply(colors, _toConsumableArray(polyTriangles.slice(j + 5, j + 9))); 102920 this.normal.apply(this, _toConsumableArray(polyTriangles.slice(j + 9, j + 12))); 102921 this.vertex.apply(this, _toConsumableArray(polyTriangles.slice(j, j + 5))); 102922 } 102923 this.immediateMode.geometry.vertexColors = colors; 102924 }; 102925 /** 102926 * Called from endShape(). Responsible for calculating normals, setting shader uniforms, 102927 * enabling all appropriate buffers, applying color blend, and drawing the fill geometry. 102928 * @private 102929 */ 102930 _main.default.RendererGL.prototype._drawImmediateFill = function () { 102931 var gl = this.GL; 102932 this._useVertexColor = this.immediateMode.geometry.vertexColors.length > 0; 102933 var shader = this._getImmediateFillShader(); 102934 this._setFillUniforms(shader); 102935 var _iteratorNormalCompletion = true; 102936 var _didIteratorError = false;
102937 var _iteratorError = undefined; 102938 try { 102939 for (var _iterator = this.immediateMode.buffers.fill[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 102940 var buff = _step.value; 102941 buff._prepareBuffer(this.immediateMode.geometry, shader); 102942 } // LINE_STRIP and LINES are not used for rendering, instead 102943 // they only indicate a way to modify vertices during the _processVertices() step 102944 102945 } catch (err) { 102946 _didIteratorError = true; 102947 _iteratorError = err; 102948 } finally { 102949 try { 102950 if (!_iteratorNormalCompletion && _iterator.return != null) { 102951 _iterator.return(); 102952 } 102953 } finally { 102954 if (_didIteratorError) { 102955 throw _iteratorError; 102956 } 102957 } 102958 } 102959 if (this.immediateMode.shapeMode === constants.LINE_STRIP || this.immediateMode.shapeMode === constants.LINES) { 102960 this.immediateMode.shapeMode = constants.TRIANGLE_FAN; 102961 } // WebGL 1 doesn't support the QUADS and QUAD_STRIP modes, so we 102962 // need to convert them to a supported format. In `vertex()`, we reformat 102963 // the input data into the formats specified below. 102964 102965 if (this.immediateMode.shapeMode === constants.QUADS) { 102966 this.immediateMode.shapeMode = constants.TRIANGLES; 102967 } else if (this.immediateMode.shapeMode === constants.QUAD_STRIP) { 102968 this.immediateMode.shapeMode = constants.TRIANGLE_STRIP; 102969 } 102970 this._applyColorBlend(this.curFillColor); 102971 gl.drawArrays(this.immediateMode.shapeMode, 0, this.immediateMode.geometry.vertices.length); 102972 shader.unbindShader(); 102973 }; 102974 /** 102975 * Called from endShape(). Responsible for calculating normals, setting shader uniforms, 102976 * enabling all appropriate buffers, applying color blend, and drawing the stroke geometry. 102977 * @private 102978 */ 102979 _main.default.RendererGL.prototype._drawImmediateStroke = function () { 102980 var gl = this.GL; 102981 var faceCullingEnabled = gl.isEnabled(gl.CULL_FACE); // Prevent strokes from getting removed by culling 102982 gl.disable(gl.CULL_FACE); 102983 var shader = this._getImmediateStrokeShader(); 102984 this._useLineColor = this.immediateMode.geometry.vertexStrokeColors.length > 0; 102985 this._setStrokeUniforms(shader); 102986 var _iteratorNormalCompletion2 = true; 102987 var _didIteratorError2 = false;
102988 var _iteratorError2 = undefined; 102989 try { 102990 for (var _iterator2 = this.immediateMode.buffers.stroke[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 102991 var buff = _step2.value; 102992 buff._prepareBuffer(this.immediateMode.geometry, shader); 102993 } 102994 } catch (err) { 102995 _didIteratorError2 = true; 102996 _iteratorError2 = err; 102997 } finally { 102998 try { 102999 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 103000 _iterator2.return(); 103001 } 103002 } finally { 103003 if (_didIteratorError2) { 103004 throw _iteratorError2; 103005 } 103006 } 103007 } 103008 this._applyColorBlend(this.curStrokeColor); 103009 gl.drawArrays(gl.TRIANGLES, 0, this.immediateMode.geometry.lineVertices.length); 103010 if (faceCullingEnabled) { 103011 gl.enable(gl.CULL_FACE); 103012 } 103013 shader.unbindShader(); 103014 }; 103015 var _default = _main.default.RendererGL; 103016 exports.default = _default; 103017 }, 103018 { 103019 '../core/constants': 278, 103020 '../core/main': 290, 103021 './p5.RenderBuffer': 341, 103022 'core-js/modules/es.array.concat': 167, 103023 'core-js/modules/es.array.fill': 170, 103024 'core-js/modules/es.array.from': 173, 103025 'core-js/modules/es.array.iterator': 176, 103026 'core-js/modules/es.array.map': 179, 103027 'core-js/modules/es.array.slice': 180, 103028 'core-js/modules/es.object.get-own-property-descriptor': 191, 103029 'core-js/modules/es.object.to-string': 195, 103030 'core-js/modules/es.regexp.to-string': 200, 103031 'core-js/modules/es.string.iterator': 204, 103032 'core-js/modules/es.symbol': 214, 103033 'core-js/modules/es.symbol.description': 212, 103034 'core-js/modules/es.symbol.iterator': 213, 103035 'core-js/modules/es.weak-map': 246, 103036 'core-js/modules/web.dom-collections.iterator': 248 103037 } 103038 ], 103039 343: [ 103040 function (_dereq_, module, exports) { 103041 'use strict'; 103042 _dereq_('core-js/modules/es.symbol'); 103043 _dereq_('core-js/modules/es.symbol.description'); 103044 _dereq_('core-js/modules/es.symbol.iterator'); 103045 _dereq_('core-js/modules/es.array.fill'); 103046 _dereq_('core-js/modules/es.array.iterator'); 103047 _dereq_('core-js/modules/es.array.some'); 103048 _dereq_('core-js/modules/es.object.keys'); 103049 _dereq_('core-js/modules/es.object.to-string'); 103050 _dereq_('core-js/modules/es.string.iterator'); 103051 _dereq_('core-js/modules/es.typed-array.float32-array'); 103052 _dereq_('core-js/modules/es.typed-array.uint16-array'); 103053 _dereq_('core-js/modules/es.typed-array.uint32-array'); 103054 _dereq_('core-js/modules/es.typed-array.copy-within'); 103055 _dereq_('core-js/modules/es.typed-array.every'); 103056 _dereq_('core-js/modules/es.typed-array.fill'); 103057 _dereq_('core-js/modules/es.typed-array.filter'); 103058 _dereq_('core-js/modules/es.typed-array.find'); 103059 _dereq_('core-js/modules/es.typed-array.find-index'); 103060 _dereq_('core-js/modules/es.typed-array.for-each'); 103061 _dereq_('core-js/modules/es.typed-array.includes'); 103062 _dereq_('core-js/modules/es.typed-array.index-of'); 103063 _dereq_('core-js/modules/es.typed-array.iterator'); 103064 _dereq_('core-js/modules/es.typed-array.join'); 103065 _dereq_('core-js/modules/es.typed-array.last-index-of'); 103066 _dereq_('core-js/modules/es.typed-array.map'); 103067 _dereq_('core-js/modules/es.typed-array.reduce'); 103068 _dereq_('core-js/modules/es.typed-array.reduce-right'); 103069 _dereq_('core-js/modules/es.typed-array.reverse'); 103070 _dereq_('core-js/modules/es.typed-array.set'); 103071 _dereq_('core-js/modules/es.typed-array.slice'); 103072 _dereq_('core-js/modules/es.typed-array.some'); 103073 _dereq_('core-js/modules/es.typed-array.sort'); 103074 _dereq_('core-js/modules/es.typed-array.subarray'); 103075 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 103076 _dereq_('core-js/modules/es.typed-array.to-string'); 103077 _dereq_('core-js/modules/web.dom-collections.iterator'); 103078 _dereq_('core-js/modules/es.symbol'); 103079 _dereq_('core-js/modules/es.symbol.description'); 103080 _dereq_('core-js/modules/es.symbol.iterator'); 103081 _dereq_('core-js/modules/es.array.fill'); 103082 _dereq_('core-js/modules/es.array.iterator'); 103083 _dereq_('core-js/modules/es.array.some'); 103084 _dereq_('core-js/modules/es.object.keys'); 103085 _dereq_('core-js/modules/es.object.to-string'); 103086 _dereq_('core-js/modules/es.string.iterator'); 103087 _dereq_('core-js/modules/es.typed-array.float32-array'); 103088 _dereq_('core-js/modules/es.typed-array.uint16-array'); 103089 _dereq_('core-js/modules/es.typed-array.uint32-array'); 103090 _dereq_('core-js/modules/es.typed-array.copy-within'); 103091 _dereq_('core-js/modules/es.typed-array.every'); 103092 _dereq_('core-js/modules/es.typed-array.fill'); 103093 _dereq_('core-js/modules/es.typed-array.filter'); 103094 _dereq_('core-js/modules/es.typed-array.find'); 103095 _dereq_('core-js/modules/es.typed-array.find-index'); 103096 _dereq_('core-js/modules/es.typed-array.for-each'); 103097 _dereq_('core-js/modules/es.typed-array.includes'); 103098 _dereq_('core-js/modules/es.typed-array.index-of'); 103099 _dereq_('core-js/modules/es.typed-array.iterator'); 103100 _dereq_('core-js/modules/es.typed-array.join'); 103101 _dereq_('core-js/modules/es.typed-array.last-index-of'); 103102 _dereq_('core-js/modules/es.typed-array.map'); 103103 _dereq_('core-js/modules/es.typed-array.reduce'); 103104 _dereq_('core-js/modules/es.typed-array.reduce-right'); 103105 _dereq_('core-js/modules/es.typed-array.reverse'); 103106 _dereq_('core-js/modules/es.typed-array.set'); 103107 _dereq_('core-js/modules/es.typed-array.slice'); 103108 _dereq_('core-js/modules/es.typed-array.some'); 103109 _dereq_('core-js/modules/es.typed-array.sort'); 103110 _dereq_('core-js/modules/es.typed-array.subarray'); 103111 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 103112 _dereq_('core-js/modules/es.typed-array.to-string'); 103113 _dereq_('core-js/modules/web.dom-collections.iterator'); 103114 Object.defineProperty(exports, '__esModule', { 103115 value: true 103116 }); 103117 exports.default = void 0; 103118 var _main = _interopRequireDefault(_dereq_('../core/main')); 103119 _dereq_('./p5.RendererGL'); 103120 _dereq_('./p5.RenderBuffer'); 103121 function _interopRequireDefault(obj) { 103122 return obj && obj.__esModule ? obj : { 103123 default: 103124 obj 103125 }; 103126 } //Retained Mode. The default mode for rendering 3D primitives 103127 //in WEBGL. 103128 103129 var hashCount = 0; 103130 /** 103131 * _initBufferDefaults 103132 * @private 103133 * @description initializes buffer defaults. runs each time a new geometry is 103134 * registered 103135 * @param {String} gId key of the geometry object 103136 * @returns {Object} a new buffer object 103137 */ 103138 _main.default.RendererGL.prototype._initBufferDefaults = function (gId) { 103139 this._freeBuffers(gId); //@TODO remove this limit on hashes in retainedMode.geometry 103140 hashCount++; 103141 if (hashCount > 1000) { 103142 var key = Object.keys(this.retainedMode.geometry) [0]; 103143 delete this.retainedMode.geometry[key]; 103144 hashCount--; 103145 } //create a new entry in our retainedMode.geometry 103146 103147 return this.retainedMode.geometry[gId] = { 103148 }; 103149 }; 103150 _main.default.RendererGL.prototype._freeBuffers = function (gId) { 103151 var buffers = this.retainedMode.geometry[gId]; 103152 if (!buffers) { 103153 return; 103154 } 103155 delete this.retainedMode.geometry[gId]; 103156 hashCount--; 103157 var gl = this.GL; 103158 if (buffers.indexBuffer) { 103159 gl.deleteBuffer(buffers.indexBuffer); 103160 } 103161 function freeBuffers(defs) { 103162 var _iteratorNormalCompletion = true; 103163 var _didIteratorError = false;
103164 var _iteratorError = undefined; 103165 try { 103166 for (var _iterator = defs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 103167 var def = _step.value; 103168 if (buffers[def.dst]) { 103169 gl.deleteBuffer(buffers[def.dst]); 103170 buffers[def.dst] = null; 103171 } 103172 } 103173 } catch (err) { 103174 _didIteratorError = true; 103175 _iteratorError = err; 103176 } finally { 103177 try { 103178 if (!_iteratorNormalCompletion && _iterator.return != null) { 103179 _iterator.return(); 103180 } 103181 } finally { 103182 if (_didIteratorError) { 103183 throw _iteratorError; 103184 } 103185 } 103186 } 103187 } // free all the buffers 103188 103189 freeBuffers(this.retainedMode.buffers.stroke); 103190 freeBuffers(this.retainedMode.buffers.fill); 103191 }; 103192 /** 103193 * creates a buffers object that holds the WebGL render buffers 103194 * for a geometry. 103195 * @private 103196 * @param {String} gId key of the geometry object 103197 * @param {p5.Geometry} model contains geometry data 103198 */ 103199 _main.default.RendererGL.prototype.createBuffers = function (gId, model) { 103200 var gl = this.GL; //initialize the gl buffers for our geom groups 103201 var buffers = this._initBufferDefaults(gId); 103202 buffers.model = model; 103203 var indexBuffer = buffers.indexBuffer; 103204 if (model.faces.length) { 103205 // allocate space for faces 103206 if (!indexBuffer) indexBuffer = buffers.indexBuffer = gl.createBuffer(); 103207 var vals = _main.default.RendererGL.prototype._flatten(model.faces); // If any face references a vertex with an index greater than the maximum 103208 // un-singed 16 bit integer, then we need to use a Uint32Array instead of a 103209 // Uint16Array 103210 var hasVertexIndicesOverMaxUInt16 = vals.some(function (v) { 103211 return v > 65535; 103212 }); 103213 var type = hasVertexIndicesOverMaxUInt16 ? Uint32Array : Uint16Array; 103214 this._bindBuffer(indexBuffer, gl.ELEMENT_ARRAY_BUFFER, vals, type); // If we're using a Uint32Array for our indexBuffer we will need to pass a 103215 // different enum value to WebGL draw triangles. This happens in 103216 // the _drawElements function. 103217 buffers.indexBufferType = hasVertexIndicesOverMaxUInt16 ? gl.UNSIGNED_INT : gl.UNSIGNED_SHORT; // the vertex count is based on the number of faces 103218 buffers.vertexCount = model.faces.length * 3; 103219 } else { 103220 // the index buffer is unused, remove it 103221 if (indexBuffer) { 103222 gl.deleteBuffer(indexBuffer); 103223 buffers.indexBuffer = null; 103224 } // the vertex count comes directly from the model 103225 103226 buffers.vertexCount = model.vertices ? model.vertices.length : 0; 103227 } 103228 buffers.lineVertexCount = model.lineVertices ? model.lineVertices.length : 0; 103229 return buffers; 103230 }; 103231 /** 103232 * Draws buffers given a geometry key ID 103233 * @private 103234 * @param {String} gId ID in our geom hash 103235 * @chainable 103236 */ 103237 _main.default.RendererGL.prototype.drawBuffers = function (gId) { 103238 var gl = this.GL; 103239 var geometry = this.retainedMode.geometry[gId]; 103240 if (this._doStroke && geometry.lineVertexCount > 0) { 103241 var faceCullingEnabled = gl.isEnabled(gl.CULL_FACE); // Prevent strokes from getting removed by culling 103242 gl.disable(gl.CULL_FACE); 103243 var strokeShader = this._getRetainedStrokeShader(); 103244 this._useLineColor = geometry.model.vertexStrokeColors.length > 0; 103245 this._setStrokeUniforms(strokeShader); 103246 var _iteratorNormalCompletion2 = true; 103247 var _didIteratorError2 = false;
103248 var _iteratorError2 = undefined; 103249 try { 103250 for (var _iterator2 = this.retainedMode.buffers.stroke[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 103251 var buff = _step2.value; 103252 buff._prepareBuffer(geometry, strokeShader); 103253 } 103254 } catch (err) { 103255 _didIteratorError2 = true; 103256 _iteratorError2 = err; 103257 } finally { 103258 try { 103259 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 103260 _iterator2.return(); 103261 } 103262 } finally { 103263 if (_didIteratorError2) { 103264 throw _iteratorError2; 103265 } 103266 } 103267 } 103268 this._applyColorBlend(this.curStrokeColor); 103269 this._drawArrays(gl.TRIANGLES, gId); 103270 if (faceCullingEnabled) { 103271 gl.enable(gl.CULL_FACE); 103272 } 103273 strokeShader.unbindShader(); 103274 } 103275 if (this._doFill) { 103276 this._useVertexColor = geometry.model.vertexColors.length > 0; 103277 var fillShader = this._getRetainedFillShader(); 103278 this._setFillUniforms(fillShader); 103279 var _iteratorNormalCompletion3 = true; 103280 var _didIteratorError3 = false; 103281 var _iteratorError3 = undefined; 103282 try { 103283 for (var _iterator3 = this.retainedMode.buffers.fill[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 103284 var _buff = _step3.value; 103285 _buff._prepareBuffer(geometry, fillShader); 103286 } 103287 } catch (err) { 103288 _didIteratorError3 = true; 103289 _iteratorError3 = err; 103290 } finally { 103291 try { 103292 if (!_iteratorNormalCompletion3 && _iterator3.return != null) { 103293 _iterator3.return(); 103294 } 103295 } finally { 103296 if (_didIteratorError3) { 103297 throw _iteratorError3; 103298 } 103299 } 103300 } 103301 if (geometry.indexBuffer) { 103302 //vertex index buffer 103303 this._bindBuffer(geometry.indexBuffer, gl.ELEMENT_ARRAY_BUFFER); 103304 } 103305 this._applyColorBlend(this.curFillColor); 103306 this._drawElements(gl.TRIANGLES, gId); 103307 fillShader.unbindShader(); 103308 } 103309 return this; 103310 }; 103311 /** 103312 * Calls drawBuffers() with a scaled model/view matrix. 103313 * 103314 * This is used by various 3d primitive methods (in primitives.js, eg. plane, 103315 * box, torus, etc...) to allow caching of un-scaled geometries. Those 103316 * geometries are generally created with unit-length dimensions, cached as 103317 * such, and then scaled appropriately in this method prior to rendering. 103318 * 103319 * @private 103320 * @method drawBuffersScaled 103321 * @param {String} gId ID in our geom hash 103322 * @param {Number} scaleX the amount to scale in the X direction 103323 * @param {Number} scaleY the amount to scale in the Y direction 103324 * @param {Number} scaleZ the amount to scale in the Z direction 103325 */ 103326 _main.default.RendererGL.prototype.drawBuffersScaled = function (gId, scaleX, scaleY, scaleZ) { 103327 var uMVMatrix = this.uMVMatrix.copy(); 103328 try { 103329 this.uMVMatrix.scale(scaleX, scaleY, scaleZ); 103330 this.drawBuffers(gId); 103331 } finally { 103332 this.uMVMatrix = uMVMatrix; 103333 } 103334 }; 103335 _main.default.RendererGL.prototype._drawArrays = function (drawMode, gId) { 103336 this.GL.drawArrays(drawMode, 0, this.retainedMode.geometry[gId].lineVertexCount); 103337 return this; 103338 }; 103339 _main.default.RendererGL.prototype._drawElements = function (drawMode, gId) { 103340 var buffers = this.retainedMode.geometry[gId]; 103341 var gl = this.GL; // render the fill 103342 if (buffers.indexBuffer) { 103343 // If this model is using a Uint32Array we need to ensure the 103344 // OES_element_index_uint WebGL extension is enabled. 103345 if (buffers.indexBufferType === gl.UNSIGNED_INT) { 103346 if (!gl.getExtension('OES_element_index_uint')) { 103347 throw new Error('Unable to render a 3d model with > 65535 triangles. Your web browser does not support the WebGL Extension OES_element_index_uint.'); 103348 } 103349 } // we're drawing faces 103350 103351 gl.drawElements(gl.TRIANGLES, buffers.vertexCount, buffers.indexBufferType, 0); 103352 } else { 103353 // drawing vertices 103354 gl.drawArrays(drawMode || gl.TRIANGLES, 0, buffers.vertexCount); 103355 } 103356 }; 103357 _main.default.RendererGL.prototype._drawPoints = function (vertices, vertexBuffer) { 103358 var gl = this.GL; 103359 var pointShader = this._getImmediatePointShader(); 103360 this._setPointUniforms(pointShader); 103361 this._bindBuffer(vertexBuffer, gl.ARRAY_BUFFER, this._vToNArray(vertices), Float32Array, gl.STATIC_DRAW); 103362 pointShader.enableAttrib(pointShader.attributes.aPosition, 3); 103363 gl.drawArrays(gl.Points, 0, vertices.length); 103364 pointShader.unbindShader(); 103365 }; 103366 var _default = _main.default.RendererGL; 103367 exports.default = _default; 103368 }, 103369 { 103370 '../core/main': 290, 103371 './p5.RenderBuffer': 341, 103372 './p5.RendererGL': 344, 103373 'core-js/modules/es.array.fill': 170, 103374 'core-js/modules/es.array.iterator': 176, 103375 'core-js/modules/es.array.some': 181, 103376 'core-js/modules/es.object.keys': 194, 103377 'core-js/modules/es.object.to-string': 195, 103378 'core-js/modules/es.string.iterator': 204, 103379 'core-js/modules/es.symbol': 214, 103380 'core-js/modules/es.symbol.description': 212, 103381 'core-js/modules/es.symbol.iterator': 213, 103382 'core-js/modules/es.typed-array.copy-within': 215, 103383 'core-js/modules/es.typed-array.every': 216, 103384 'core-js/modules/es.typed-array.fill': 217, 103385 'core-js/modules/es.typed-array.filter': 218, 103386 'core-js/modules/es.typed-array.find': 220, 103387 'core-js/modules/es.typed-array.find-index': 219, 103388 'core-js/modules/es.typed-array.float32-array': 221, 103389 'core-js/modules/es.typed-array.for-each': 223, 103390 'core-js/modules/es.typed-array.includes': 224, 103391 'core-js/modules/es.typed-array.index-of': 225, 103392 'core-js/modules/es.typed-array.iterator': 228, 103393 'core-js/modules/es.typed-array.join': 229, 103394 'core-js/modules/es.typed-array.last-index-of': 230, 103395 'core-js/modules/es.typed-array.map': 231, 103396 'core-js/modules/es.typed-array.reduce': 233, 103397 'core-js/modules/es.typed-array.reduce-right': 232, 103398 'core-js/modules/es.typed-array.reverse': 234, 103399 'core-js/modules/es.typed-array.set': 235, 103400 'core-js/modules/es.typed-array.slice': 236, 103401 'core-js/modules/es.typed-array.some': 237, 103402 'core-js/modules/es.typed-array.sort': 238, 103403 'core-js/modules/es.typed-array.subarray': 239, 103404 'core-js/modules/es.typed-array.to-locale-string': 240, 103405 'core-js/modules/es.typed-array.to-string': 241, 103406 'core-js/modules/es.typed-array.uint16-array': 242, 103407 'core-js/modules/es.typed-array.uint32-array': 243, 103408 'core-js/modules/web.dom-collections.iterator': 248 103409 } 103410 ], 103411 344: [
103412 function (_dereq_, module, exports) { 103413 'use strict'; 103414 _dereq_('core-js/modules/es.symbol'); 103415 _dereq_('core-js/modules/es.symbol.description'); 103416 _dereq_('core-js/modules/es.symbol.iterator'); 103417 _dereq_('core-js/modules/es.array.concat'); 103418 _dereq_('core-js/modules/es.array.fill'); 103419 _dereq_('core-js/modules/es.array.filter'); 103420 _dereq_('core-js/modules/es.array.from'); 103421 _dereq_('core-js/modules/es.array.includes'); 103422 _dereq_('core-js/modules/es.array.iterator'); 103423 _dereq_('core-js/modules/es.array.slice'); 103424 _dereq_('core-js/modules/es.object.assign'); 103425 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 103426 _dereq_('core-js/modules/es.object.to-string'); 103427 _dereq_('core-js/modules/es.regexp.to-string'); 103428 _dereq_('core-js/modules/es.string.includes'); 103429 _dereq_('core-js/modules/es.string.iterator'); 103430 _dereq_('core-js/modules/es.typed-array.float32-array'); 103431 _dereq_('core-js/modules/es.typed-array.float64-array'); 103432 _dereq_('core-js/modules/es.typed-array.int16-array'); 103433 _dereq_('core-js/modules/es.typed-array.uint8-array'); 103434 _dereq_('core-js/modules/es.typed-array.uint16-array'); 103435 _dereq_('core-js/modules/es.typed-array.uint32-array'); 103436 _dereq_('core-js/modules/es.typed-array.copy-within'); 103437 _dereq_('core-js/modules/es.typed-array.every'); 103438 _dereq_('core-js/modules/es.typed-array.fill'); 103439 _dereq_('core-js/modules/es.typed-array.filter'); 103440 _dereq_('core-js/modules/es.typed-array.find'); 103441 _dereq_('core-js/modules/es.typed-array.find-index'); 103442 _dereq_('core-js/modules/es.typed-array.for-each'); 103443 _dereq_('core-js/modules/es.typed-array.includes'); 103444 _dereq_('core-js/modules/es.typed-array.index-of'); 103445 _dereq_('core-js/modules/es.typed-array.iterator'); 103446 _dereq_('core-js/modules/es.typed-array.join'); 103447 _dereq_('core-js/modules/es.typed-array.last-index-of'); 103448 _dereq_('core-js/modules/es.typed-array.map'); 103449 _dereq_('core-js/modules/es.typed-array.reduce'); 103450 _dereq_('core-js/modules/es.typed-array.reduce-right'); 103451 _dereq_('core-js/modules/es.typed-array.reverse'); 103452 _dereq_('core-js/modules/es.typed-array.set'); 103453 _dereq_('core-js/modules/es.typed-array.slice'); 103454 _dereq_('core-js/modules/es.typed-array.some'); 103455 _dereq_('core-js/modules/es.typed-array.sort'); 103456 _dereq_('core-js/modules/es.typed-array.subarray'); 103457 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 103458 _dereq_('core-js/modules/es.typed-array.to-string'); 103459 _dereq_('core-js/modules/es.weak-map'); 103460 _dereq_('core-js/modules/web.dom-collections.iterator'); 103461 function _typeof2(obj) { 103462 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 103463 _typeof2 = function _typeof2(obj) { 103464 return typeof obj; 103465 }; 103466 } else { 103467 _typeof2 = function _typeof2(obj) { 103468 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 103469 }; 103470 } 103471 return _typeof2(obj); 103472 } 103473 function _typeof(obj) { 103474 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 103475 _typeof = function _typeof(obj) { 103476 return _typeof2(obj); 103477 }; 103478 } else { 103479 _typeof = function _typeof(obj) { 103480 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 103481 }; 103482 } 103483 return _typeof(obj); 103484 } 103485 _dereq_('core-js/modules/es.symbol'); 103486 _dereq_('core-js/modules/es.symbol.description'); 103487 _dereq_('core-js/modules/es.symbol.iterator'); 103488 _dereq_('core-js/modules/es.array.concat'); 103489 _dereq_('core-js/modules/es.array.fill'); 103490 _dereq_('core-js/modules/es.array.filter'); 103491 _dereq_('core-js/modules/es.array.from'); 103492 _dereq_('core-js/modules/es.array.includes'); 103493 _dereq_('core-js/modules/es.array.iterator'); 103494 _dereq_('core-js/modules/es.array.slice'); 103495 _dereq_('core-js/modules/es.object.assign'); 103496 _dereq_('core-js/modules/es.object.to-string'); 103497 _dereq_('core-js/modules/es.regexp.to-string'); 103498 _dereq_('core-js/modules/es.string.includes'); 103499 _dereq_('core-js/modules/es.string.iterator'); 103500 _dereq_('core-js/modules/es.typed-array.float32-array'); 103501 _dereq_('core-js/modules/es.typed-array.float64-array'); 103502 _dereq_('core-js/modules/es.typed-array.int16-array'); 103503 _dereq_('core-js/modules/es.typed-array.uint8-array'); 103504 _dereq_('core-js/modules/es.typed-array.uint16-array'); 103505 _dereq_('core-js/modules/es.typed-array.uint32-array'); 103506 _dereq_('core-js/modules/es.typed-array.copy-within'); 103507 _dereq_('core-js/modules/es.typed-array.every'); 103508 _dereq_('core-js/modules/es.typed-array.fill'); 103509 _dereq_('core-js/modules/es.typed-array.filter'); 103510 _dereq_('core-js/modules/es.typed-array.find'); 103511 _dereq_('core-js/modules/es.typed-array.find-index'); 103512 _dereq_('core-js/modules/es.typed-array.for-each'); 103513 _dereq_('core-js/modules/es.typed-array.includes'); 103514 _dereq_('core-js/modules/es.typed-array.index-of'); 103515 _dereq_('core-js/modules/es.typed-array.iterator'); 103516 _dereq_('core-js/modules/es.typed-array.join'); 103517 _dereq_('core-js/modules/es.typed-array.last-index-of'); 103518 _dereq_('core-js/modules/es.typed-array.map'); 103519 _dereq_('core-js/modules/es.typed-array.reduce'); 103520 _dereq_('core-js/modules/es.typed-array.reduce-right'); 103521 _dereq_('core-js/modules/es.typed-array.reverse'); 103522 _dereq_('core-js/modules/es.typed-array.set'); 103523 _dereq_('core-js/modules/es.typed-array.slice'); 103524 _dereq_('core-js/modules/es.typed-array.some'); 103525 _dereq_('core-js/modules/es.typed-array.sort'); 103526 _dereq_('core-js/modules/es.typed-array.subarray'); 103527 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 103528 _dereq_('core-js/modules/es.typed-array.to-string'); 103529 _dereq_('core-js/modules/web.dom-collections.iterator'); 103530 Object.defineProperty(exports, '__esModule', { 103531 value: true 103532 }); 103533 exports.default = void 0; 103534 var _main = _interopRequireDefault(_dereq_('../core/main')); 103535 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 103536 var _libtess = _interopRequireDefault(_dereq_('libtess')); 103537 _dereq_('./p5.Shader'); 103538 _dereq_('./p5.Camera'); 103539 _dereq_('../core/p5.Renderer'); 103540 _dereq_('./p5.Matrix'); 103541 var _path = _dereq_('path'); 103542 function _getRequireWildcardCache() { 103543 if (typeof WeakMap !== 'function') return null; 103544 var cache = new WeakMap(); 103545 _getRequireWildcardCache = function _getRequireWildcardCache() { 103546 return cache; 103547 }; 103548 return cache; 103549 } 103550 function _interopRequireWildcard(obj) { 103551 if (obj && obj.__esModule) { 103552 return obj; 103553 } 103554 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 103555 return { 103556 default: 103557 obj 103558 }; 103559 } 103560 var cache = _getRequireWildcardCache(); 103561 if (cache && cache.has(obj)) { 103562 return cache.get(obj); 103563 } 103564 var newObj = { 103565 }; 103566 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 103567 for (var key in obj) { 103568 if (Object.prototype.hasOwnProperty.call(obj, key)) { 103569 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 103570 if (desc && (desc.get || desc.set)) { 103571 Object.defineProperty(newObj, key, desc); 103572 } else { 103573 newObj[key] = obj[key]; 103574 } 103575 } 103576 } 103577 newObj.default = obj; 103578 if (cache) { 103579 cache.set(obj, newObj); 103580 } 103581 return newObj; 103582 } 103583 function _interopRequireDefault(obj) { 103584 return obj && obj.__esModule ? obj : { 103585 default: 103586 obj 103587 }; 103588 } 103589 function _toConsumableArray(arr) { 103590 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); 103591 } 103592 function _nonIterableSpread() { 103593 throw new TypeError('Invalid attempt to spread non-iterable instance'); 103594 } 103595 function _iterableToArray(iter) { 103596 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') return Array.from(iter); 103597 } 103598 function _arrayWithoutHoles(arr) { 103599 if (Array.isArray(arr)) { 103600 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 103601 arr2[i] = arr[i]; 103602 } 103603 return arr2; 103604 } 103605 } 103606 var STROKE_CAP_ENUM = { 103607 }; 103608 var STROKE_JOIN_ENUM = { 103609 }; 103610 var lineDefs = ''; 103611 var defineStrokeCapEnum = function defineStrokeCapEnum(key, val) {
103612 lineDefs += '#define STROKE_CAP_'.concat(key, ' ').concat(val, '\n'); 103613 STROKE_CAP_ENUM[constants[key]] = val; 103614 }; 103615 var defineStrokeJoinEnum = function defineStrokeJoinEnum(key, val) { 103616 lineDefs += '#define STROKE_JOIN_'.concat(key, ' ').concat(val, '\n'); 103617 STROKE_JOIN_ENUM[constants[key]] = val; 103618 }; // Define constants in line shaders for each type of cap/join, and also record 103619 // the values in JS objects 103620 defineStrokeCapEnum('ROUND', 0); 103621 defineStrokeCapEnum('PROJECT', 1); 103622 defineStrokeCapEnum('SQUARE', 2); 103623 defineStrokeJoinEnum('ROUND', 0); 103624 defineStrokeJoinEnum('MITER', 1); 103625 defineStrokeJoinEnum('BEVEL', 2); 103626 var lightingShader = 'precision highp float;\nprecision highp int;\n\nuniform mat4 uViewMatrix;\n\nuniform bool uUseLighting;\n\nuniform int uAmbientLightCount;\nuniform vec3 uAmbientColor[5];\n\nuniform int uDirectionalLightCount;\nuniform vec3 uLightingDirection[5];\nuniform vec3 uDirectionalDiffuseColors[5];\nuniform vec3 uDirectionalSpecularColors[5];\n\nuniform int uPointLightCount;\nuniform vec3 uPointLightLocation[5];\nuniform vec3 uPointLightDiffuseColors[5];\t\nuniform vec3 uPointLightSpecularColors[5];\n\nuniform int uSpotLightCount;\nuniform float uSpotLightAngle[5];\nuniform float uSpotLightConc[5];\nuniform vec3 uSpotLightDiffuseColors[5];\nuniform vec3 uSpotLightSpecularColors[5];\nuniform vec3 uSpotLightLocation[5];\nuniform vec3 uSpotLightDirection[5];\n\nuniform bool uSpecular;\nuniform float uShininess;\n\nuniform float uConstantAttenuation;\nuniform float uLinearAttenuation;\nuniform float uQuadraticAttenuation;\n\nconst float specularFactor = 2.0;\nconst float diffuseFactor = 0.73;\n\nstruct LightResult {\n float specular;\n float diffuse;\n};\n\nfloat _phongSpecular(\n vec3 lightDirection,\n vec3 viewDirection,\n vec3 surfaceNormal,\n float shininess) {\n\n vec3 R = reflect(lightDirection, surfaceNormal);\n return pow(max(0.0, dot(R, viewDirection)), shininess);\n}\n\nfloat _lambertDiffuse(vec3 lightDirection, vec3 surfaceNormal) {\n return max(0.0, dot(-lightDirection, surfaceNormal));\n}\n\nLightResult _light(vec3 viewDirection, vec3 normal, vec3 lightVector) {\n\n vec3 lightDir = normalize(lightVector);\n\n //compute our diffuse & specular terms\n LightResult lr;\n if (uSpecular)\n lr.specular = _phongSpecular(lightDir, viewDirection, normal, uShininess);\n lr.diffuse = _lambertDiffuse(lightDir, normal);\n return lr;\n}\n\nvoid totalLight(\n vec3 modelPosition,\n vec3 normal,\n out vec3 totalDiffuse,\n out vec3 totalSpecular\n) {\n\n totalSpecular = vec3(0.0);\n\n if (!uUseLighting) {\n totalDiffuse = vec3(1.0);\n return;\n }\n\n totalDiffuse = vec3(0.0);\n\n vec3 viewDirection = normalize(-modelPosition);\n\n for (int j = 0; j < 5; j++) {\n if (j < uDirectionalLightCount) {\n vec3 lightVector = (uViewMatrix * vec4(uLightingDirection[j], 0.0)).xyz;\n vec3 lightColor = uDirectionalDiffuseColors[j];\n vec3 specularColor = uDirectionalSpecularColors[j];\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if (j < uPointLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uPointLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n //calculate attenuation\n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n vec3 lightColor = lightFalloff * uPointLightDiffuseColors[j];\n vec3 specularColor = lightFalloff * uPointLightSpecularColors[j];\n\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if(j < uSpotLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uSpotLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n\n vec3 lightDirection = (uViewMatrix * vec4(uSpotLightDirection[j], 0.0)).xyz;\n float spotDot = dot(normalize(lightVector), normalize(lightDirection));\n float spotFalloff;\n if(spotDot < uSpotLightAngle[j]) {\n spotFalloff = 0.0;\n }\n else {\n spotFalloff = pow(spotDot, uSpotLightConc[j]);\n }\n lightFalloff *= spotFalloff;\n\n vec3 lightColor = uSpotLightDiffuseColors[j];\n vec3 specularColor = uSpotLightSpecularColors[j];\n \n LightResult result = _light(viewDirection, normal, lightVector);\n \n totalDiffuse += result.diffuse * lightColor * lightFalloff;\n totalSpecular += result.specular * lightColor * specularColor * lightFalloff;\n }\n }\n\n totalDiffuse *= diffuseFactor;
103626\n totalSpecular *= specularFactor;\n}\n'; 103627 var defaultShaders = { 103628 immediateVert: 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uResolution;\nuniform float uPointSize;\n\nvarying vec4 vColor;\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n gl_PointSize = uPointSize;\n}\n', 103629 vertexColorVert: 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nvarying vec4 vColor;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n}\n', 103630 vertexColorFrag: 'precision mediump float;\nvarying vec4 vColor;\nvoid main(void) {\n gl_FragColor = vec4(vColor.rgb, 1.) * vColor.a;\n}\n', 103631 normalVert: 'attribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nuniform vec4 uMaterialColor;\nuniform bool uUseVertexColor;\n\nvarying vec3 vVertexNormal;\nvarying highp vec2 vVertTexCoord;\nvarying vec4 vColor;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0
103631);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vVertexNormal = normalize(vec3( uNormalMatrix * aNormal ));\n vVertTexCoord = aTexCoord;\n vColor = (uUseVertexColor ? aVertexColor : uMaterialColor);\n}\n', 103632 normalFrag: 'precision mediump float;\nvarying vec3 vVertexNormal;\nvoid main(void) {\n gl_FragColor = vec4(vVertexNormal, 1.0);\n}', 103633 basicFrag: 'precision mediump float;\nvarying vec4 vColor;\nvoid main(void) {\n gl_FragColor = vec4(vColor.rgb, 1.) * vColor.a;\n}\n', 103634 lightVert: lightingShader + '// include lighting.glgl\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nuniform bool uUseVertexColor;\nuniform vec4 uMaterialColor;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\nvarying vec4 vColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0
103634);\n gl_Position = uProjectionMatrix * viewModelPosition;\n\n vec3 vertexNormal = normalize(uNormalMatrix * aNormal);\n vVertTexCoord = aTexCoord;\n\n totalLight(viewModelPosition.xyz, vertexNormal, vDiffuseColor, vSpecularColor);\n\n for (int i = 0; i < 8; i++) {\n if (i < uAmbientLightCount) {\n vDiffuseColor += uAmbientColor[i];\n }\n }\n \n vColor = (uUseVertexColor ? aVertexColor : uMaterialColor);\n}\n', 103635 lightTextureFrag: 'precision highp float;\n\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\nuniform bool uEmissive;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\nvarying vec4 vColor;\n\nvoid main(void) {\n if(uEmissive && !isTexture) {\n gl_FragColor = vColor;\n }\n else {\n vec4 baseColor = isTexture ? texture2D(uSampler, vVertTexCoord) * (uTint / vec4(255, 255, 255, 255)) : vColor;\n gl_FragColor = vec4(gl_FragColor.rgb * vDiffuseColor + vSpecularColor, 1.) * baseColor.a;\n }\n}\n', 103636 phongVert: 'precision highp float;\nprecision highp int;\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\nattribute vec4 aVertexColor;\n\nuniform vec3 uAmbientColor[5];\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\nuniform int uAmbientLightCount;\n\nuniform bool uUseVertexColor;\nuniform vec4 uMaterialColor;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\nvarying vec4 vColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0
103636);\n\n // Pass varyings to fragment shader\n vViewPosition = viewModelPosition.xyz;\n gl_Position = uProjectionMatrix * viewModelPosition; \n\n vNormal = uNormalMatrix * aNormal;\n vTexCoord = aTexCoord;\n\n // TODO: this should be a uniform\n vAmbientColor = vec3(0.0);\n for (int i = 0; i < 5; i++) {\n if (i < uAmbientLightCount) {\n vAmbientColor += uAmbientColor[i];\n }\n }\n \n vColor = (uUseVertexColor ? aVertexColor : uMaterialColor);\n}\n', 103637 phongFrag: lightingShader + '// include lighting.glsl\nprecision highp float;\nprecision highp int;\n\nuniform vec4 uSpecularMatColor;\nuniform vec4 uAmbientMatColor;\nuniform vec4 uEmissiveMatColor;\n\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\nvarying vec4 vColor;\n\nvoid main(void) {\n\n vec3 diffuse;\n vec3 specular;\n totalLight(vViewPosition, normalize(vNormal), diffuse, specular);\n\n // Calculating final color as result of all lights (plus emissive term).\n\n vec4 baseColor = isTexture ? texture2D(uSampler, vTexCoord) * (uTint / vec4(255, 255, 255, 255)) : vColor;\n gl_FragColor = vec4(diffuse * baseColor.rgb + \n vAmbientColor * uAmbientMatColor.rgb + \n specular * uSpecularMatColor.rgb + \n uEmissiveMatColor.rgb, 1.) * baseColor.a;\n}\n', 103638 fontVert: 'precision mediump float;\n\nattribute vec3 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uGlyphRect;\nuniform float uGlyphOffset;\n\nvarying vec2 vTexCoord;\nvarying float w;
103638\n\nvoid main() {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n\n // scale by the size of the glyph\'s rectangle\n positionVec4.xy *= uGlyphRect.zw - uGlyphRect.xy;\n\n // Expand glyph bounding boxes by 1px on each side to give a bit of room\n // for antialiasing\n vec2 pixelScale = vec2(\n 1. / uModelViewMatrix[0][0],\n 1. / uModelViewMatrix[1][1]\n );\n vec2 offset = pixelScale * normalize(aTexCoord - vec2(0.5, 0.5)) * vec2(1., -1.);\n vec2 textureOffset = offset * (1. / vec2(\n uGlyphRect.z - uGlyphRect.x,\n uGlyphRect.w - uGlyphRect.y\n ));\n\n // move to the corner of the glyph\n positionVec4.xy += uGlyphRect.xy;\n\n // move to the letter\'s line offset\n positionVec4.x += uGlyphOffset;\n\n positionVec4.xy += offset;\n \n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vTexCoord = aTexCoord + textureOffset;\n w = gl_Position.w;\n}\n', 103639 fontFrag: '#extension GL_OES_standard_derivatives : enable\nprecision mediump float;\n\n#if 0\n // simulate integer math using floats\n\t#define int float\n\t#define ivec2 vec2\n\t#define INT(x) float(x)\n\n\tint ifloor(float v) { return floor(v); }\n\tivec2 ifloor(vec2 v) { return floor(v); }\n\n#else\n // use native integer math\n\tprecision highp int;\n\t#define INT(x) x\n\n\tint ifloor(float v) { return int(v); }\n\tint ifloor(int v) { return v; }\n\tivec2 ifloor(vec2 v) { return ivec2(v); }\n\n#endif\n\nuniform sampler2D uSamplerStrokes;\nuniform sampler2D uSamplerRowStrokes;\nuniform sampler2D uSamplerRows;\nuniform sampler2D uSamplerColStrokes;\nuniform sampler2D uSamplerCols;\n\nuniform ivec2 uStrokeImageSize;\nuniform ivec2 uCellsImageSize;\nuniform ivec2 uGridImageSize;\n\nuniform ivec2 uGridOffset;\nuniform ivec2 uGridSize;\nuniform vec4 uMaterialColor;\n\nvarying vec2 vTexCoord;\n\n// some helper functions\nint round(float v) { return ifloor(v + 0.5); }\nivec2 round(vec2 v) { return ifloor(v + 0.5); }\nfloat saturate(float v) { return clamp(v, 0.0, 1.0); }\nvec2 saturate(vec2 v) { return clamp(v, 0.0, 1.0); }\n\nint mul(float v1, int v2) {\n return ifloor(v1 * float(v2));\n}\n\nivec2 mul(vec2 v1, ivec2 v2) {\n return ifloor(v1 * vec2(v2) + 0.5);\n}\n\n// unpack a 16-bit integer from a float vec2\nint getInt16(vec2 v) {\n ivec2 iv = round(v * 255.0);\n return iv.x * INT(128) + iv.y;\n}\n\nvec2 pixelScale;\nvec2 coverage = vec2(0.0);\nvec2 weight = vec2(0.5);\nconst float minDistance = 1.0/8192.0;\nconst float hardness = 1.05; // amount of antialias\n\n// the maximum number of curves in a glyph\nconst int N = INT(250);\n\n// retrieves an indexed pixel from a sampler\nvec4 getTexel(sampler2D sampler, int pos, ivec2 size) {\n int width = size.x;\n int y = ifloor(pos / width);\n int x = pos - y * width; // pos % width\n\n return texture2D(sampler, (vec2(x, y) + 0.5) / vec2(size));\n}\n\nvoid calulateCrossings(vec2 p0, vec2 p1, vec2 p2, out vec2 C1, out vec2 C2) {\n\n // get the coefficients of the quadratic in t\n vec2 a = p0 - p1 * 2.0 + p2;\n vec2 b = p0 - p1;\n vec2 c = p0 - vTexCoord;\n\n // found out which values of \'t\' it crosses the axes\n vec2 surd = sqrt(max(vec2(0.0), b * b - a * c));\n vec2 t1 = ((b - surd) / a).yx;\n vec2 t2 = ((b + surd) / a).yx;\n\n // approximate straight lines to avoid rounding errors\n if (abs(a.y) < 0.001)\n t1.x = t2.x = c.y / (2.0 * b.y);\n\n if (abs(a.x) < 0.001)\n t1.y = t2.y = c.x / (2.0 * b.x);\n\n // plug into quadratic formula to find the corrdinates of the crossings\n C1 = ((a * t1 - b * 2.0) * t1 + c) * pixelScale;\n C2 = ((a * t2 - b * 2.0) * t2 + c) * pixelScale;\n}\n\nvoid coverageX(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n // determine on which side of the x-axis the points lie\n bool y0 = p0.y > vTexCoord.y;\n bool y1 = p1.y > vTexCoord.y;\n bool y2 = p2.y > vTexCoord.y;\n\n // could web be under the curve (after t1)?\n if (y1 ? !y2 : y0) {\n // add the coverage for t1\n coverage.x += saturate(C1.x + 0.5);\n // calculate the anti-aliasing for t1\n weight.x = min(weight.x, abs(C1.x));\n }\n\n // are we outside the curve (after t2)?\n if (y1 ? !y0 : y2) {\n // subtract the coverage for t2\n coverage.x -= saturate(C2.x + 0.5);
103639\n // calculate the anti-aliasing for t2\n weight.x = min(weight.x, abs(C2.x));\n }\n}\n\n// this is essentially the same as coverageX, but with the axes swapped\nvoid coverageY(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n bool x0 = p0.x > vTexCoord.x;\n bool x1 = p1.x > vTexCoord.x;\n bool x2 = p2.x > vTexCoord.x;\n\n if (x1 ? !x2 : x0) {\n coverage.y -= saturate(C1.y + 0.5);\n weight.y = min(weight.y, abs(C1.y));\n }\n\n if (x1 ? !x0 : x2) {\n coverage.y += saturate(C2.y + 0.5);\n weight.y = min(weight.y, abs(C2.y));\n }\n}\n\nvoid main() {\n\n // calculate the pixel scale based on screen-coordinates\n pixelScale = hardness / fwidth(vTexCoord);\n\n // which grid cell is this pixel in?\n ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));\n\n // intersect curves in this row\n {\n // the index into the row info bitmap\n int rowIndex = gridCoord.y + uGridOffset.y;\n // fetch the info texel\n vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);\n // unpack the rowInfo\n int rowStrokeIndex = getInt16(rowInfo.xy);\n int rowStrokeCount = getInt16(rowInfo.zw);\n\n for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {\n if (iRowStroke >= rowStrokeCount)\n break;\n\n // each stroke is made up of 3 points: the start and control point\n // and the start of the next curve.\n // fetch the indices of this pair of strokes:\n vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);\n\n // unpack the stroke index\n int strokePos = getInt16(strokeIndices.xy);\n\n // fetch the two strokes\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n\n // calculate the coverage\n coverageX(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n // intersect curves in this column\n {\n int colIndex = gridCoord.x + uGridOffset.x;\n vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);\n int colStrokeIndex = getInt16(colInfo.xy);\n int colStrokeCount = getInt16(colInfo.zw);\n \n for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {\n if (iColStroke >= colStrokeCount)\n break;\n\n vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);\n\n int strokePos = getInt16(strokeIndices.xy);\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n coverageY(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n weight = saturate(1.0 - weight * 2.0);\n float distance = max(weight.x + weight.y, minDistance); // manhattan approx.\n float antialias = abs(dot(coverage, weight) / distance);\n float cover = min(abs(coverage.x), abs(coverage.y));\n gl_FragColor = vec4(uMaterialColor.rgb, 1.) * uMaterialColor.a;\n gl_FragColor *= saturate(max(antialias, cover));\n}\n', 103640 lineVert: lineDefs + '/*\n Part of the Processing project - http://processing.org\n Copyright (c) 2012-15 The Processing Foundation\n Copyright (c) 2004-12 Ben Fry and Casey Reas\n Copyright (c) 2001-04 Massachusetts Institute of Technology\n This library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation, version 2.1.\n This library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n You should have received a copy of the GNU Lesser General\n Public License along with this library; if not, write to the\n Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA\n*/\n\n#define PROCESSING_LINE_SHADER\n\nprecision mediump float;\nprecision mediump int;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uStrokeWeight;\n\nuniform bool uUseLineColor;\nuniform vec4 uMaterialColor;\n\nuniform vec4 uViewport;\nuniform int uPerspective;\nuniform int uStrokeJoin;\n\nattribute vec4 aPosition;\nattribute vec3 aTangentIn;\nattribute vec3 aTangentOut;\nattribute float aSide;\nattribute vec4 aVertexColor;\n\nvarying vec4 vColor;\nvarying vec2 vTangent;\nvarying vec2 vCenter;\nvarying vec2 vPosition;\nvarying float vMaxDist;\nvarying float vCap;\nvarying float vJoin;\n\nvec2 lineIntersection(vec2 aPoint, vec2 aDir, vec2 bPoint, vec2 bDir) {\n // Rotate and translate so a starts at the origin and goes out to the right\n bPoint -= aPoint;\n vec2 rotatedBFrom = vec2(\n bPoint.x*aDir.x + bPoint.y*aDir.y,\n bPoint.y*aDir.x - bPoint.x*aDir.y\n );\n vec2 bTo = bPoint + bDir;\n vec2 rotatedBTo = vec2(\n bTo.x*aDir.x + bTo.y*aDir.y,\n bTo.y*aDir.x - bTo.x*aDir.y\n );\n float intersectionDistance =\n rotatedBTo.x + (rotatedBFrom.x - rotatedBTo.x) * rotatedBTo.y /\n (rotatedBTo.y - rotatedBFrom.y);\n return aPoint + aDir * intersectionDistance;\n}\n\nvoid main() {\n // using a scale <1 moves the lines towards the camera\n // in order to prevent popping effects due to half of\n // the line disappearing behind the geometry faces.\n vec3 scale = vec3(0.9995);\n\n // Caps have one of either the in or out tangent set to 0\n vCap = (aTangentIn == vec3(0.)) != (aTangentOut == (vec3(0.)))\n ? 1. : 0.;
103640\n\n // Joins have two unique, defined tangents\n vJoin = (\n aTangentIn != vec3(0.) &&\n aTangentOut != vec3(0.) &&\n aTangentIn != aTangentOut\n ) ? 1. : 0.;\n\n vec4 posp = uModelViewMatrix * aPosition;\n vec4 posqIn = uModelViewMatrix * (aPosition + vec4(aTangentIn, 0));\n vec4 posqOut = uModelViewMatrix * (aPosition + vec4(aTangentOut, 0));\n\n // Moving vertices slightly toward the camera\n // to avoid depth-fighting with the fill triangles.\n // Discussed here:\n // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 \n posp.xyz = posp.xyz * scale;\n posqIn.xyz = posqIn.xyz * scale;\n posqOut.xyz = posqOut.xyz * scale;\n\n vec4 p = uProjectionMatrix * posp;\n vec4 qIn = uProjectionMatrix * posqIn;\n vec4 qOut = uProjectionMatrix * posqOut;\n vCenter = p.xy;\n\n // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])\n // screen_p = (p.xy/p.w + <1,1>) * 0.5 * uViewport.zw\n\n // prevent division by W by transforming the tangent formula (div by 0 causes\n // the line to disappear, see https://github.com/processing/processing/issues/5183)\n // t = screen_q - screen_p\n //\n // tangent is normalized and we don\'t care which aDirection it points to (+-)\n // t = +- normalize( screen_q - screen_p )\n // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*uViewport.zw - (p.xy/p.w+<1,1>)*0.5*uViewport.zw )\n //\n // extract common factor, <1,1> - <1,1> cancels out\n // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * uViewport.zw )\n //\n // convert to common divisor\n // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * uViewport.zw )\n //\n // remove the common scalar divisor/factor, not needed due to normalize and +-\n // (keep uViewport - can\'t remove because it has different components for x and y\n // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)\n // t = +- normalize( (q.xy*p.w - p.xy*q.w) * uViewport.zw )\n\n vec2 tangentIn = normalize((qIn.xy*p.w - p.xy*qIn.w) * uViewport.zw);\n vec2 tangentOut = normalize((qOut.xy*p.w - p.xy*qOut.w) * uViewport.zw);\n\n vec2 curPerspScale;\n if(uPerspective == 1) {\n // Perspective ---\n // convert from world to clip by multiplying with projection scaling factor\n // to get the right thickness (see https://github.com/processing/processing/issues/5182)\n // invert Y, projections in Processing invert Y\n curPerspScale = (uProjectionMatrix * vec4(1, -1, 0, 0)).xy;\n } else {\n // No Perspective ---\n // multiply by W (to cancel out division by W later in the pipeline) and\n // convert from screen to clip (derived from clip to screen above)\n curPerspScale = p.w / (0.5 * uViewport.zw);\n }\n\n vec2 offset;\n if (vJoin == 1.) {\n vTangent = normalize(tangentIn + tangentOut);\n vec2 normalIn = vec2(-tangentIn.y, tangentIn.x);\n vec2 normalOut = vec2(-tangentOut.y, tangentOut.x);\n float side = sign(aSide);\n float sideEnum = abs(aSide);\n\n // We generate vertices for joins on either side of the centerline, but\n // the "elbow" side is the only one needing a join. By not setting the\n // offset for the other side, all its vertices will end up in the same\n // spot and not render, effectively discarding it.\n if (sign(dot(tangentOut, vec2(-tangentIn.y, tangentIn.x))) != side) {\n // Side enums:\n // 1: the side going into the join\n // 2: the middle of the join\n // 3: the side going out of the join\n if (sideEnum == 2.) {\n // Calculate the position + tangent on either side of the join, and\n // find where the lines intersect to find the elbow of the join\n vec2 c = (posp.xy/posp.w + vec2(1.,1.)) * 0.5 * uViewport.zw;\n vec2 intersection = lineIntersection(\n c + (side * normalIn * uStrokeWeight / 2.) * curPerspScale,\n tangentIn,\n c + (side * normalOut * uStrokeWeight / 2.) * curPerspScale,\n tangentOut\n );\n offset = (intersection - c);\n\n // When lines are thick and the angle of the join approaches 180, the\n // elbow might be really far from the center. We\'ll apply a limit to\n // the magnitude to avoid lines going across the whole screen when this\n // happens.\n float mag = length(offset);\n float maxMag = 3. * uStrokeWeight;\n if (mag >
103640 maxMag) {\n offset *= maxMag / mag;\n }\n } else if (sideEnum == 1.) {\n offset = side * normalIn * curPerspScale * uStrokeWeight / 2.;\n } else if (sideEnum == 3.) {\n offset = side * normalOut * curPerspScale * uStrokeWeight / 2.;\n }\n }\n if (uStrokeJoin == STROKE_JOIN_BEVEL) {\n vec2 avgNormal = vec2(-vTangent.y, vTangent.x);\n vMaxDist = abs(dot(avgNormal, normalIn * uStrokeWeight / 2.));\n } else {\n vMaxDist = uStrokeWeight / 2.;\n }\n } else {\n vec2 tangent = aTangentIn == vec3(0.) ? tangentOut : tangentIn;\n vTangent = tangent;\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n float normalOffset = sign(aSide);\n // Caps will have side values of -2 or 2 on the edge of the cap that\n // extends out from the line\n float tangentOffset = abs(aSide) - 1.;\n offset = (normal * normalOffset + tangent * tangentOffset) *\n uStrokeWeight * 0.5 * curPerspScale;\n vMaxDist = uStrokeWeight / 2.;\n }\n vPosition = vCenter + offset / curPerspScale;\n\n gl_Position.xy = p.xy + offset.xy;\n gl_Position.zw = p.zw;\n \n vColor = (uUseLineColor ? aVertexColor : uMaterialColor);\n}\n', 103641 lineFrag: lineDefs + 'precision mediump float;\nprecision mediump int;\n\nuniform vec4 uMaterialColor;\nuniform int uStrokeCap;\nuniform int uStrokeJoin;\nuniform float uStrokeWeight;\n\nvarying vec4 vColor;\nvarying vec2 vTangent;\nvarying vec2 vCenter;\nvarying vec2 vPosition;\nvarying float vMaxDist;\nvarying float vCap;\nvarying float vJoin;\n\nfloat distSquared(vec2 a, vec2 b) {\n vec2 aToB = b - a;\n return dot(aToB, aToB);\n}\n\nvoid main() {\n if (vCap > 0.) {\n if (\n uStrokeCap == STROKE_CAP_ROUND &&\n distSquared(vPosition, vCenter) > uStrokeWeight * uStrokeWeight * 0.25\n ) {\n discard;\n } else if (\n uStrokeCap == STROKE_CAP_SQUARE &&\n dot(vPosition - vCenter, vTangent) > 0.\n ) {\n discard;\n }\n // Use full area for PROJECT\n } else if (vJoin > 0.) {\n if (\n uStrokeJoin == STROKE_JOIN_ROUND &&\n distSquared(vPosition, vCenter) > uStrokeWeight * uStrokeWeight * 0.25\n ) {\n discard;\n } else if (uStrokeJoin == STROKE_JOIN_BEVEL) {\n vec2 normal = vec2(-vTangent.y, vTangent.x);\n if (abs(dot(vPosition - vCenter, normal)) > vMaxDist) {\n discard;\n }\n }\n // Use full area for MITER\n }\n gl_FragColor = vec4(vColor.rgb, 1.) * vColor.a;\n}\n', 103642 pointVert: 'attribute vec3 aPosition;\nuniform float uPointSize;\nvarying float vStrokeWeight;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;
103642\nvoid main() {\n\tvec4 positionVec4 = vec4(aPosition, 1.0);\n\tgl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n\tgl_PointSize = uPointSize;\n\tvStrokeWeight = uPointSize;\n}', 103643 pointFrag: 'precision mediump float;\nprecision mediump int;\nuniform vec4 uMaterialColor;\nvarying float vStrokeWeight;\n\nvoid main(){\n float mask = 0.0;\n\n // make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n mask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n // if strokeWeight is 1 or less lets just draw a square\n // this prevents weird artifacting from carving circles when our points are really small\n // if strokeWeight is larger than 1, we just use it as is\n\n mask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n // throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n if(mask > 0.98){\n discard;\n }\n\n gl_FragColor = vec4(uMaterialColor.rgb, 1.) * uMaterialColor.a;\n}\n' 103644 }; 103645 /** 103646 * 3D graphics class 103647 * @private 103648 * @class p5.RendererGL 103649 * @constructor 103650 * @extends p5.Renderer 103651 * @todo extend class to include public method for offscreen 103652 * rendering (FBO). 103653 */ 103654 _main.default.RendererGL = function (elt, pInst, isMainCanvas, attr) { 103655 _main.default.Renderer.call(this, elt, pInst, isMainCanvas); 103656 this._setAttributeDefaults(pInst); 103657 this._initContext(); 103658 this.isP3D = true; //lets us know we're in 3d mode 103659 // This redundant property is useful in reminding you that you are 103660 // interacting with WebGLRenderingContext, still worth considering future removal 103661 this.GL = this.drawingContext; 103662 this._pInst._setProperty('drawingContext', this.drawingContext); // erasing 103663 this._isErasing = false; // lights 103664 this._enableLighting = false; 103665 this.ambientLightColors = [ 103666 ]; 103667 this.specularColors = [ 103668 1, 103669 1, 103670 1 103671 ]; 103672 this.directionalLightDirections = [ 103673 ]; 103674 this.directionalLightDiffuseColors = [ 103675 ]; 103676 this.directionalLightSpecularColors = [ 103677 ]; 103678 this.pointLightPositions = [ 103679 ]; 103680 this.pointLightDiffuseColors = [ 103681 ]; 103682 this.pointLightSpecularColors = [ 103683 ]; 103684 this.spotLightPositions = [ 103685 ]; 103686 this.spotLightDirections = [ 103687 ]; 103688 this.spotLightDiffuseColors = [ 103689 ]; 103690 this.spotLightSpecularColors = [ 103691 ]; 103692 this.spotLightAngle = [ 103693 ]; 103694 this.spotLightConc = [ 103695 ]; 103696 this.drawMode = constants.FILL; 103697 this.curFillColor = this._cachedFillStyle = [ 103698 1, 103699 1, 103700 1, 103701 1 103702 ]; 103703 this.curAmbientColor = this._cachedFillStyle = [ 103704 1, 103705 1, 103706 1, 103707 1 103708 ]; 103709 this.curSpecularColor = this._cachedFillStyle = [ 103710 0, 103711 0, 103712 0, 103713 0 103714 ]; 103715 this.curEmissiveColor = this._cachedFillStyle = [ 103716 0, 103717 0, 103718 0, 103719 0 103720 ]; 103721 this.curStrokeColor = this._cachedStrokeStyle = [ 103722 0, 103723 0, 103724 0, 103725 1 103726 ]; 103727 this.curBlendMode = constants.BLEND; 103728 this._cachedBlendMode = undefined; 103729 this.blendExt = this.GL.getExtension('EXT_blend_minmax'); 103730 this._isBlending = false; 103731 this._useSpecularMaterial = false; 103732 this._useEmissiveMaterial = false; 103733 this._useNormalMaterial = false; 103734 this._useShininess = 1; 103735 this._useLineColor = false; 103736 this._useVertexColor = false; 103737 this.registerEnabled = [ 103738 ]; 103739 this._tint = [ 103740 255, 103741 255, 103742 255, 103743 255 103744 ]; // lightFalloff variables 103745 this.constantAttenuation = 1; 103746 this.linearAttenuation = 0; 103747 this.quadraticAttenuation = 0; 103748 /** 103749 * model view, projection, & normal 103750 * matrices 103751 */ 103752 this.uMVMatrix = new _main.default.Matrix(); 103753 this.uPMatrix = new _main.default.Matrix(); 103754 this.uNMatrix = new _main.default.Matrix('mat3'); // Current vertex normal 103755 this._currentNormal = new _main.default.Vector(0, 0, 1); // Camera 103756 this._curCamera = new _main.default.Camera(this); 103757 this._curCamera._computeCameraDefaultSettings(); 103758 this._curCamera._setDefaultCamera(); 103759 this._defaultLightShader = undefined; 103760 this._defaultImmediateModeShader = undefined; 103761 this._defaultNormalShader = undefined; 103762 this._defaultColorShader = undefined; 103763 this._defaultPointShader = undefined; 103764 this.userFillShader = undefined; 103765 this.userStrokeShader = undefined; 103766 this.userPointShader = undefined; // Default drawing is done in Retained Mode 103767 // Geometry and Material hashes stored here 103768 this.retainedMode = { 103769 geometry: { 103770 }, 103771 buffers: { 103772 stroke: [ 103773 new _main.default.RenderBuffer(4, 'lineVertexColors', 'lineColorBuffer', 'aVertexColor', this, this._flatten), 103774 new _main.default.RenderBuffer(3, 'lineVertices', 'lineVerticesBuffer', 'aPosition', this, this._flatten), 103775 new _main.default.RenderBuffer(3, 'lineTangentsIn', 'lineTangentsInBuffer', 'aTangentIn', this, this._flatten), 103776 new _main.default.RenderBuffer(3, 'lineTangentsOut', 'lineTangentsOutBuffer', 'aTangentOut', this, this._flatten), 103777 new _main.default.RenderBuffer(1, 'lineSides', 'lineSidesBuffer', 'aSide', this) 103778 ], 103779 fill: [ 103780 new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray), 103781 new _main.default.RenderBuffer(3, 'vertexNormals', 'normalBuffer', 'aNormal', this, this._vToNArray), 103782 new _main.default.RenderBuffer(4, 'vertexColors', 'colorBuffer', 'aVertexColor', this), 103783 new _main.default.RenderBuffer(3, 'vertexAmbients', 'ambientBuffer', 'aAmbientColor', this), //new BufferDef(3, 'vertexSpeculars', 'specularBuffer', 'aSpecularColor'), 103784 new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten) 103785 ], 103786 text: [ 103787 new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray), 103788 new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten) 103789 ] 103790 } 103791 }; // Immediate Mode 103792 // Geometry and Material hashes stored here 103793 this.immediateMode = { 103794 geometry: new _main.default.Geometry(), 103795 shapeMode: constants.TRIANGLE_FAN, 103796 _bezierVertex: [ 103797 ], 103798 _quadraticVertex: [ 103799 ], 103800 _curveVertex: [ 103801 ], 103802 buffers: { 103803 fill: [ 103804 new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray), 103805 new _main.default.RenderBuffer(3, 'vertexNormals', 'normalBuffer', 'aNormal', this, this._vToNArray), 103806 new _main.default.RenderBuffer(4, 'vertexColors', 'colorBuffer', 'aVertexColor', this), 103807 new _main.default.RenderBuffer(3, 'vertexAmbients', 'ambientBuffer', 'aAmbientColor', this), 103808 new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten) 103809 ], 103810 stroke: [ 103811 new _main.default.RenderBuffer(4, 'lineVertexColors', 'lineColorBuffer', 'aVertexColor', this, this._flatten), 103812 new _main.default.RenderBuffer(3, 'lineVertices', 'lineVerticesBuffer', 'aPosition', this, this._flatten), 103813 new _main.default.RenderBuffer(3, 'lineTangentsIn', 'lineTangentsInBuffer', 'aTangentIn', this, this._flatten), 103814 new _main.default.RenderBuffer(3, 'lineTangentsOut', 'lineTangentsOutBuffer', 'aTangentOut', this, this._flatten), 103815 new _main.default.RenderBuffer(1, 'lineSides', 'lineSidesBuffer', 'aSide', this) 103816 ], 103817 point: this.GL.createBuffer() 103818 } 103819 }; 103820 this.pointSize = 5; //default point size 103821 this.curStrokeWeight = 1; 103822 this.curStrokeCap = constants.ROUND; 103823 this.curStrokeJoin = constants.ROUND; // array of textures created in this gl context via this.getTexture(src) 103824 this.textures = [ 103825 ]; 103826 this.textureMode = constants.IMAGE; // default wrap settings 103827 this.textureWrapX = constants.CLAMP; 103828 this.textureWrapY = constants.CLAMP; 103829 this._tex = null; 103830 this._curveTightness = 6; // lookUpTable for coefficients needed to be calculated for bezierVertex, same are used for curveVertex 103831 this._lookUpTableBezier = [ 103832 ]; // lookUpTable for coefficients needed to be calculated for quadraticVertex 103833 this._lookUpTableQuadratic = [ 103834 ]; // current curveDetail in the Bezier lookUpTable 103835 this._lutBezierDetail = 0; // current curveDetail in the Quadratic lookUpTable 103836 this._lutQuadraticDetail = 0; // Used to distinguish between user calls to vertex() and internal
103836calls 103837 this.isProcessingVertices = false; 103838 this._tessy = this._initTessy(); 103839 this.fontInfos = { 103840 }; 103841 this._curShader = undefined; 103842 return this; 103843 }; 103844 _main.default.RendererGL.prototype = Object.create(_main.default.Renderer.prototype); ////////////////////////////////////////////// 103845 // Setting 103846 ////////////////////////////////////////////// 103847 _main.default.RendererGL.prototype._setAttributeDefaults = function (pInst) { 103848 // See issue #3850, safer to enable AA in Safari 103849 var applyAA = navigator.userAgent.toLowerCase().includes('safari'); 103850 var defaults = { 103851 alpha: true, 103852 depth: true, 103853 stencil: true, 103854 antialias: applyAA, 103855 premultipliedAlpha: true, 103856 preserveDrawingBuffer: true, 103857 perPixelLighting: true 103858 }; 103859 if (pInst._glAttributes === null) { 103860 pInst._glAttributes = defaults; 103861 } else { 103862 pInst._glAttributes = Object.assign(defaults, pInst._glAttributes); 103863 } 103864 return; 103865 }; 103866 _main.default.RendererGL.prototype._initContext = function () { 103867 this.drawingContext = this.canvas.getContext('webgl', this._pInst._glAttributes) || this.canvas.getContext('experimental-webgl', this._pInst._glAttributes); 103868 if (this.drawingContext === null) { 103869 throw new Error('Error creating webgl context'); 103870 } else { 103871 var gl = this.drawingContext; 103872 gl.enable(gl.DEPTH_TEST); 103873 gl.depthFunc(gl.LEQUAL); 103874 gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); 103875 this._viewport = this.drawingContext.getParameter(this.drawingContext.VIEWPORT); 103876 } 103877 }; //This is helper function to reset the context anytime the attributes 103878 //are changed with setAttributes() 103879 _main.default.RendererGL.prototype._resetContext = function (options, callback) { 103880 var w = this.width; 103881 var h = this.height; 103882 var defaultId = this.canvas.id; 103883 var isPGraphics = this._pInst instanceof _main.default.Graphics; 103884 if (isPGraphics) { 103885 var pg = this._pInst; 103886 pg.canvas.parentNode.removeChild(pg.canvas); 103887 pg.canvas = document.createElement('canvas'); 103888 var node = pg._pInst._userNode || document.body; 103889 node.appendChild(pg.canvas); 103890 _main.default.Element.call(pg, pg.canvas, pg._pInst); 103891 pg.width = w; 103892 pg.height = h; 103893 } else { 103894 var c = this.canvas; 103895 if (c) { 103896 c.parentNode.removeChild(c); 103897 } 103898 c = document.createElement('canvas'); 103899 c.id = defaultId; 103900 if (this._pInst._userNode) { 103901 this._pInst._userNode.appendChild(c); 103902 } else { 103903 document.body.appendChild(c); 103904 } 103905 this._pInst.canvas = c; 103906 this.canvas = c; 103907 } 103908 var renderer = new _main.default.RendererGL(this._pInst.canvas, this._pInst, !isPGraphics); 103909 this._pInst._setProperty('_renderer', renderer); 103910 renderer.resize(w, h); 103911 renderer._applyDefaults(); 103912 if (!isPGraphics) { 103913 this._pInst._elements.push(renderer); 103914 } 103915 if (typeof callback === 'function') { 103916 //setTimeout with 0 forces the task to the back of the queue, this ensures that 103917 //we finish switching out the renderer 103918 setTimeout(function () { 103919 callback.apply(window._renderer, options); 103920 }, 0); 103921 } 103922 }; 103923 /** 103924 * @module Rendering 103925 * @submodule Rendering 103926 * @for p5 103927 */ 103928 /** 103929 * Set attributes for the WebGL Drawing context. 103930 * This is a way of adjusting how the WebGL 103931 * renderer works to fine-tune the display and performance. 103932 * 103933 * Note that this will reinitialize the drawing context 103934 * if called after the WebGL canvas is made. 103935 * 103936 * If an object is passed as the parameter, all attributes 103937 * not declared in the object will be set to defaults. 103938 * 103939 * The available attributes are: 103940 * <br> 103941 * alpha - indicates if the canvas contains an alpha buffer 103942 * default is true 103943 * 103944 * depth - indicates whether the drawing buffer has a depth buffer 103945 * of at least 16 bits - default is true 103946 * 103947 * stencil - indicates whether the drawing buffer has a stencil buffer 103948 * of at least 8 bits 103949 *
103950 * antialias - indicates whether or not to perform anti-aliasing 103951 * default is false (true in Safari) 103952 * 103953 * premultipliedAlpha - indicates that the page compositor will assume 103954 * the drawing buffer contains colors with pre-multiplied alpha 103955 * default is true 103956 * 103957 * preserveDrawingBuffer - if true the buffers will not be cleared and 103958 * and will preserve their values until cleared or overwritten by author 103959 * (note that p5 clears automatically on draw loop) 103960 * default is true 103961 * 103962 * perPixelLighting - if true, per-pixel lighting will be used in the 103963 * lighting shader otherwise per-vertex lighting is used. 103964 * default is true. 103965 * 103966 * @method setAttributes 103967 * @for p5 103968 * @param {String} key Name of attribute 103969 * @param {Boolean} value New value of named attribute 103970 * @example 103971 * <div> 103972 * <code> 103973 * function setup() { 103974 * createCanvas(100, 100, WEBGL); 103975 * } 103976 * 103977 * function draw() { 103978 * background(255); 103979 * push(); 103980 * rotateZ(frameCount * 0.02); 103981 * rotateX(frameCount * 0.02); 103982 * rotateY(frameCount * 0.02); 103983 * fill(0, 0, 0); 103984 * box(50); 103985 * pop(); 103986 * } 103987 * </code> 103988 * </div> 103989 * <br> 103990 * Now with the antialias attribute set to true. 103991 * <br> 103992 * <div> 103993 * <code> 103994 * function setup() { 103995 * setAttributes('antialias', true); 103996 * createCanvas(100, 100, WEBGL); 103997 * } 103998 * 103999 * function draw() { 104000 * background(255); 104001 * push(); 104002 * rotateZ(frameCount * 0.02); 104003 * rotateX(frameCount * 0.02); 104004 * rotateY(frameCount * 0.02); 104005 * fill(0, 0, 0); 104006 * box(50); 104007 * pop(); 104008 * } 104009 * </code> 104010 * </div> 104011 * 104012 * <div> 104013 * <code> 104014 * // press the mouse button to disable perPixelLighting 104015 * function setup() { 104016 * createCanvas(100, 100, WEBGL); 104017 * noStroke(); 104018 * fill(255); 104019 * } 104020 * 104021 * let lights = [ 104022 * { c: '#f00', t: 1.12, p: 1.91, r: 0.2 }, 104023 * { c: '#0f0', t: 1.21, p: 1.31, r: 0.2 }, 104024 * { c: '#00f', t: 1.37, p: 1.57, r: 0.2 }, 104025 * { c: '#ff0', t: 1.12, p: 1.91, r: 0.7 }, 104026 * { c: '#0ff', t: 1.21, p: 1.31, r: 0.7 }, 104027 * { c: '#f0f', t: 1.37, p: 1.57, r: 0.7 } 104028 * ]; 104029 * 104030 * function draw() { 104031 * let t = millis() / 1000 + 1000; 104032 * background(0); 104033 * directionalLight(color('#222'), 1, 1, 1); 104034 * 104035 * for (let i = 0; i < lights.length; i++) { 104036 * let light = lights[i]; 104037 * pointLight( 104038 * color(light.c), 104039 * p5.Vector.fromAngles(t * light.t, t * light.p, width * light.r) 104040 * ); 104041 * } 104042 * 104043 * specularMaterial(255); 104044 * sphere(width * 0.1); 104045 * 104046 * rotateX(t * 0.77); 104047 * rotateY(t * 0.83); 104048 * rotateZ(t * 0.91); 104049 * torus(width * 0.3, width * 0.07, 24, 10); 104050 * } 104051 * 104052 * function mousePressed() { 104053 * setAttributes('perPixelLighting', false); 104054 * noStroke(); 104055 * fill(255); 104056 * } 104057 * function mouseReleased() { 104058 * setAttributes('perPixelLighting', true); 104059 * noStroke(); 104060 * fill(255); 104061 * } 104062 * </code> 104063 * </div> 104064 * 104065 * @alt a rotating cube with smoother edges 104066 */ 104067 /** 104068 * @method setAttributes 104069 * @for p5 104070 * @param {Object} obj object with key-value pairs 104071 */ 104072 _main.default.prototype.setAttributes = function (key, value) { 104073 if (typeof this._glAttributes === 'undefined') { 104074 console.log('You are trying to use setAttributes on a p5.Graphics object ' + 'that does not use a WEBGL renderer.'); 104075 return; 104076 } 104077 var unchanged = true; 104078 if (typeof value !== 'undefined') { 104079 //first time modifying the attributes 104080 if (this._glAttributes === null) { 104081 this._glAttributes = { 104082 }; 104083 } 104084 if (this._glAttributes[key] !== value) { 104085 //changing value of previously altered attribute 104086 this._glAttributes[key] = value; 104087 unchanged = false; 104088 } //setting all attributes with some change 104089 104090 } else if (key instanceof Object) { 104091 if (this._glAttributes !== key) { 104092 this._glAttributes = key; 104093 unchanged = false; 104094 } 104095 } //@todo_FES 104096 104097 if (!this._renderer.isP3D || unchanged) { 104098 return; 104099 } 104100 if (!this._setupDone) { 104101 for (var x in this._renderer.retainedMode.geometry) { 104102 if (this._renderer.retainedMode.geometry.hasOwnProperty(x)) { 104103 console.error('Sorry, Could not set the attributes, you need to call setAttributes() ' + 'before calling the other drawing methods in setup()'); 104104 return; 104105 } 104106 } 104107 } 104108 this.push(); 104109 this._renderer._resetContext(); 104110 this.pop(); 104111 if (this._renderer._curCamera) { 104112 this._renderer._curCamera._renderer = this._renderer; 104113 } 104114 }; 104115 /** 104116 * @class p5.RendererGL 104117 */ 104118 _main.default.RendererGL.prototype._update = function () { 104119 // reset model view and apply initial camera transform 104120 // (containing only look at info; no projection). 104121 this.uMVMatrix.set(this._curCamera.cameraMatrix.mat4[0], this._curCamera.cameraMatrix.mat4[1], this._curCamera.cameraMatrix.mat4[2], this._curCamera.cameraMatrix.mat4[3], this._curCamera.cameraMatrix.mat4[4], this._curCamera.cameraMatrix.mat4[5], this._curCamera.cameraMatrix.mat4[6], this._curCamera.cameraMatrix.mat4[7], this._curCamera.cameraMatrix.mat4[8], this._curCamera.cameraMatrix.mat4[9], this._curCamera.cameraMatrix.mat4[10], this._curCamera.cameraMatrix.mat4[11], this._curCamera.cameraMatrix.mat4[12], this._curCamera.cameraMatrix.mat4[13], this._curCamera.cameraMatrix.mat4[14], this._curCamera.cameraMatrix.mat4[15]); // reset light data for new frame. 104122 this.ambientLightColors.length = 0; 104123 this.specularColors = [ 104124 1, 104125 1, 104126 1 104127 ]; 104128 this.directionalLightDirections.length = 0; 104129 this.directionalLightDiffuseColors.length = 0; 104130 this.directionalLightSpecularColors.length = 0; 104131 this.pointLightPositions.length = 0; 104132 this.pointLightDiffuseColors.length = 0; 104133 this.pointLightSpecularColors.length = 0; 104134 this.spotLightPositions.length = 0; 104135 this.spotLightDirections.length = 0; 104136 this.spotLightDiffuseColors.length = 0; 104137 this.spotLightSpecularColors.length = 0; 104138 this.spotLightAngle.length = 0; 104139 this.spotLightConc.length = 0; 104140 this._enableLighting = false; //reset tint value for new frame 104141 this._tint = [ 104142 255, 104143 255, 104144 255, 104145 255 104146 ]; //Clear depth every frame 104147 this.GL.clear(this.GL.DEPTH_BUFFER_BIT); 104148 }; 104149 /** 104150 * [background description] 104151 */ 104152 _main.default.RendererGL.prototype.background = function () { 104153 var _this$_pInst; 104154 var _col = (_this$_pInst = this._pInst).color.apply(_this$_pInst, arguments); 104155 var _r = _col.levels[0] / 255; 104156 var _g = _col.levels[1] / 255; 104157 var _b = _col.levels[2] / 255; 104158 var _a = _col.levels[3] / 255; 104159 this.clear(_r, _g, _b, _a); 104160 }; ////////////////////////////////////////////// 104161 // COLOR
104162 ////////////////////////////////////////////// 104163 /** 104164 * Basic fill material for geometry with a given color 104165 * @method fill 104166 * @class p5.RendererGL 104167 * @param {Number|Number[]|String|p5.Color} v1 gray value, 104168 * red or hue value (depending on the current color mode), 104169 * or color Array, or CSS color string 104170 * @param {Number} [v2] green or saturation value 104171 * @param {Number} [v3] blue or brightness value 104172 * @param {Number} [a] opacity 104173 * @chainable 104174 * @example 104175 * <div> 104176 * <code> 104177 * function setup() { 104178 * createCanvas(200, 200, WEBGL); 104179 * } 104180 * 104181 * function draw() { 104182 * background(0); 104183 * noStroke(); 104184 * fill(100, 100, 240); 104185 * rotateX(frameCount * 0.01); 104186 * rotateY(frameCount * 0.01); 104187 * box(75, 75, 75); 104188 * } 104189 * </code> 104190 * </div> 104191 * 104192 * @alt 104193 * black canvas with purple cube spinning 104194 */ 104195 _main.default.RendererGL.prototype.fill = function (v1, v2, v3, a) { 104196 //see material.js for more info on color blending in webgl 104197 var color = _main.default.prototype.color.apply(this._pInst, arguments); 104198 this.curFillColor = color._array; 104199 this.drawMode = constants.FILL; 104200 this._useNormalMaterial = false; 104201 this._tex = null; 104202 }; 104203 /** 104204 * Basic stroke material for geometry with a given color 104205 * @method stroke 104206 * @param {Number|Number[]|String|p5.Color} v1 gray value, 104207 * red or hue value (depending on the current color mode), 104208 * or color Array, or CSS color string 104209 * @param {Number} [v2] green or saturation value 104210 * @param {Number} [v3] blue or brightness value 104211 * @param {Number} [a] opacity 104212 * @example 104213 * <div> 104214 * <code> 104215 * function setup() { 104216 * createCanvas(200, 200, WEBGL); 104217 * } 104218 * 104219 * function draw() { 104220 * background(0); 104221 * stroke(240, 150, 150); 104222 * fill(100, 100, 240); 104223 * rotateX(frameCount * 0.01); 104224 * rotateY(frameCount * 0.01); 104225 * box(75, 75, 75); 104226 * } 104227 * </code> 104228 * </div> 104229 * 104230 * @alt 104231 * black canvas with purple cube with pink outline spinning 104232 */ 104233 _main.default.RendererGL.prototype.stroke = function (r, g, b, a) { 104234 var color = _main.default.prototype.color.apply(this._pInst, arguments); 104235 this.curStrokeColor = color._array; 104236 }; 104237 _main.default.RendererGL.prototype.strokeCap = function (cap) { 104238 this.curStrokeCap = cap; 104239 }; 104240 _main.default.RendererGL.prototype.strokeJoin = function (join) { 104241 this.curStrokeJoin = join; 104242 }; 104243 _main.default.RendererGL.prototype.filter = function (filterType) { 104244 // filter can be achieved using custom shaders. 104245 // https://github.com/aferriss/p5jsShaderExamples 104246 // https://itp-xstory.github.io/p5js-shaders/#/ 104247 console.error('filter() does not work in WEBGL mode'); 104248 }; 104249 _main.default.RendererGL.prototype.blendMode = function (mode) { 104250 if (mode === constants.DARKEST || mode === constants.LIGHTEST || mode === constants.ADD || mode === constants.BLEND || mode === constants.SUBTRACT || mode === constants.SCREEN || mode === constants.EXCLUSION || mode === constants.REPLACE || mode === constants.MULTIPLY || mode === constants.REMOVE) this.curBlendMode = mode; 104251 else if (mode === constants.BURN || mode === constants.OVERLAY || mode === constants.HARD_LIGHT || mode === constants.SOFT_LIGHT || mode === constants.DODGE) { 104252 console.warn('BURN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, and DODGE only w
104252ork for blendMode in 2D mode.'); 104253 } 104254 }; 104255 _main.default.RendererGL.prototype.erase = function (opacityFill, opacityStroke) { 104256 if (!this._isErasing) { 104257 this._applyBlendMode(constants.REMOVE); 104258 this._isErasing = true; 104259 this._cachedFillStyle = this.curFillColor.slice(); 104260 this.curFillColor = [ 104261 1, 104262 1, 104263 1, 104264 opacityFill / 255 104265 ]; 104266 this._cachedStrokeStyle = this.curStrokeColor.slice(); 104267 this.curStrokeColor = [ 104268 1, 104269 1, 104270 1, 104271 opacityStroke / 255 104272 ]; 104273 } 104274 }; 104275 _main.default.RendererGL.prototype.noErase = function () { 104276 if (this._isErasing) { 104277 this._isErasing = false; 104278 this.curFillColor = this._cachedFillStyle.slice(); 104279 this.curStrokeColor = this._cachedStrokeStyle.slice(); 104280 this.blendMode(this._cachedBlendMode); 104281 } 104282 }; 104283 /** 104284 * Change weight of stroke 104285 * @method strokeWeight 104286 * @param {Number} stroke weight to be used for drawing 104287 * @example 104288 * <div> 104289 * <code> 104290 * function setup() { 104291 * createCanvas(200, 400, WEBGL); 104292 * setAttributes('antialias', true); 104293 * } 104294 * 104295 * function draw() { 104296 * background(0); 104297 * noStroke(); 104298 * translate(0, -100, 0); 104299 * stroke(240, 150, 150); 104300 * fill(100, 100, 240); 104301 * push(); 104302 * strokeWeight(8); 104303 * rotateX(frameCount * 0.01); 104304 * rotateY(frameCount * 0.01); 104305 * sphere(75); 104306 * pop(); 104307 * push(); 104308 * translate(0, 200, 0); 104309 * strokeWeight(1); 104310 * rotateX(frameCount * 0.01); 104311 * rotateY(frameCount * 0.01); 104312 * sphere(75); 104313 * pop(); 104314 * } 104315 * </code> 104316 * </div> 104317 * 104318 * @alt 104319 * black canvas with two purple rotating spheres with pink 104320 * outlines the sphere on top has much heavier outlines, 104321 */ 104322 _main.default.RendererGL.prototype.strokeWeight = function (w) { 104323 if (this.curStrokeWeight !== w) { 104324 this.pointSize = w; 104325 this.curStrokeWeight = w; 104326 } 104327 }; // x,y are canvas-relative (pre-scaled by _pixelDensity) 104328 _main.default.RendererGL.prototype._getPixel = function (x, y) { 104329 var imageData, 104330 index; 104331 imageData = new Uint8Array(4); 104332 this.drawingContext.readPixels(x, y, 1, 1, this.drawingContext.RGBA, this.drawingContext.UNSIGNED_BYTE, imageData); 104333 index = 0; 104334 return [imageData[index + 0], 104335 imageData[index + 1], 104336 imageData[index + 2], 104337 imageData[index + 3]]; 104338 }; 104339 /** 104340 * Loads the pixels data for this canvas into the pixels[] attribute. 104341 * Note that updatePixels() and set() do not work. 104342 * Any pixel manipulation must be done directly to the pixels[] array. 104343 * 104344 * @private 104345 * @method loadPixels 104346 */ 104347 _main.default.RendererGL.prototype.loadPixels = function () { 104348 var pixelsState = this._pixelsState; //@todo_FES 104349 if (this._pInst._glAttributes.preserveDrawingBuffer !== true) { 104350 console.log('loadPixels only works in WebGL when preserveDrawingBuffer ' + 'is true.'); 104351 return; 104352 } //if there isn't a renderer-level temporary pixels buffer 104353 //make a new one 104354 104355 var pixels = pixelsState.pixels; 104356 var len = this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4; 104357 if (!(pixels instanceof Uint8Array) || pixels.length !== len) { 104358 pixels = new Uint8Array(len); 104359 this._pixelsState._setProperty('pixels', pixels); 104360 } 104361 var pd = this._pInst._pixelDensity; 104362 this.GL.readPixels(0, 0, this.width * pd, this.height * pd, this.GL.RGBA, this.GL.UNSIGNED_BYTE, pixels); 104363 }; ////////////////////////////////////////////// 104364 // HASH | for geometry
104365 ////////////////////////////////////////////// 104366 _main.default.RendererGL.prototype.geometryInHash = function (gId) { 104367 return this.retainedMode.geometry[gId] !== undefined; 104368 }; 104369 /** 104370 * [resize description] 104371 * @private 104372 * @param {Number} w [description] 104373 * @param {Number} h [description] 104374 */ 104375 _main.default.RendererGL.prototype.resize = function (w, h) { 104376 _main.default.Renderer.prototype.resize.call(this, w, h); 104377 this.GL.viewport(0, 0, this.GL.drawingBufferWidth, this.GL.drawingBufferHeight); 104378 this._viewport = this.GL.getParameter(this.GL.VIEWPORT); 104379 this._curCamera._resize(); //resize pixels buffer 104380 var pixelsState = this._pixelsState; 104381 if (typeof pixelsState.pixels !== 'undefined') { 104382 pixelsState._setProperty('pixels', new Uint8Array(this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4)); 104383 } 104384 }; 104385 /** 104386 * clears color and depth buffers 104387 * with r,g,b,a 104388 * @private 104389 * @param {Number} r normalized red val. 104390 * @param {Number} g normalized green val. 104391 * @param {Number} b normalized blue val. 104392 * @param {Number} a normalized alpha val. 104393 */ 104394 _main.default.RendererGL.prototype.clear = function () { 104395 var _r = (arguments.length <= 0 ? undefined : arguments[0]) || 0; 104396 var _g = (arguments.length <= 1 ? undefined : arguments[1]) || 0; 104397 var _b = (arguments.length <= 2 ? undefined : arguments[2]) || 0; 104398 var _a = (arguments.length <= 3 ? undefined : arguments[3]) || 0; 104399 this.GL.clearColor(_r * _a, _g * _a, _b * _a, _a); 104400 this.GL.clearDepth(1); 104401 this.GL.clear(this.GL.COLOR_BUFFER_BIT | this.GL.DEPTH_BUFFER_BIT); 104402 }; 104403 _main.default.RendererGL.prototype.applyMatrix = function (a, b, c, d, e, f) { 104404 if (arguments.length === 16) { 104405 _main.default.Matrix.prototype.apply.apply(this.uMVMatrix, arguments); 104406 } else { 104407 this.uMVMatrix.apply([a, 104408 b, 104409 0, 104410 0, 104411 c, 104412 d, 104413 0, 104414 0, 104415 0, 104416 0, 104417 1, 104418 0, 104419 e, 104420 f, 104421 0, 104422 1]); 104423 } 104424 }; 104425 /** 104426 * [translate description] 104427 * @private 104428 * @param {Number} x [description] 104429 * @param {Number} y [description] 104430 * @param {Number} z [description] 104431 * @chainable 104432 * @todo implement handle for components or vector as args 104433 */ 104434 _main.default.RendererGL.prototype.translate = function (x, y, z) { 104435 if (x instanceof _main.default.Vector) { 104436 z = x.z; 104437 y = x.y; 104438 x = x.x; 104439 } 104440 this.uMVMatrix.translate([x, 104441 y, 104442 z]); 104443 return this; 104444 }; 104445 /** 104446 * Scales the Model View Matrix by a vector 104447 * @private 104448 * @param {Number | p5.Vector | Array} x [description] 104449 * @param {Number} [y] y-axis scalar 104450 * @param {Number} [z] z-axis scalar 104451 * @chainable 104452 */ 104453 _main.default.RendererGL.prototype.scale = function (x, y, z) { 104454 this.uMVMatrix.scale(x, y, z); 104455 return this; 104456 }; 104457 _main.default.RendererGL.prototype.rotate = function (rad, axis) { 104458 if (typeof axis === 'undefined') { 104459 return this.rotateZ(rad); 104460 } 104461 _main.default.Matrix.prototype.rotate.apply(this.uMVMatrix, arguments); 104462 return this; 104463 }; 104464 _main.default.RendererGL.prototype.rotateX = function (rad) { 104465 this.rotate(rad, 1, 0, 0); 104466 return this; 104467 }; 104468 _main.default.RendererGL.prototype.rotateY = function (rad) { 104469 this.rotate(rad, 0, 1, 0); 104470 return this; 104471 }; 104472 _main.default.RendererGL.prototype.rotateZ = function (rad) { 104473 this.rotate(rad, 0, 0, 1); 104474 return this; 104475 }; 104476 _main.default.RendererGL.prototype.push = function () { 104477 // get the base renderer style 104478 var style = _main.default.Renderer.prototype.push.apply(this); // add webgl-specific style properties 104479 var properties = style.properties; 104480 properties.uMVMatrix = this.uMVMatrix.copy(); 104481 properties.uPMatrix = this.uPMatrix.copy(); 104482 properties._curCamera = this._curCamera; // make a copy of the current camera for the push state 104483 // this preserves any references stored using 'createCamera' 104484 this._curCamera = this._curCamera.copy(); 104485 properties.ambientLightColors = this.ambientLightColors.slice(); 104486 properties.specularColors = this.specularColors.slice(); 104487 properties.directionalLightDirections = this.directionalLightDirections.slice(); 104488 properties.directionalLightDiffuseColors = this.directionalLightDiffuseColors.slice(); 104489 properties.directionalLightSpecularColors = this.directionalLightSpecularColors.slice(); 104490 properties.pointLightPositions = this.pointLightPositions.slice(); 104491 properties.pointLightDiffuseColors = this.pointLightDiffuseColors.slice(); 104492 properties.pointLightSpecularColors = this.pointLightSpecularColors.slice(); 104493 properties.spotLightPositions = this.spotLightPositions.slice(); 104494 properties.spotLightDirections = this.spotLightDirections.slice(); 104495 properties.spotLightDiffuseColors = this.spotLightDiffuseColors.slice(); 104496 properties.spotLightSpecularColors = this.spotLightSpecularColors.slice(); 104497 properties.spotLightAngle = this.spotLightAngle.slice(); 104498 properties.spotLightConc = this.spotLightConc.slice(); 104499 properties.userFillShader = this.userFillShader; 104500 properties.userStrokeShader = this.userStrokeShader; 104501 properties.userPointShader = this.userPointShader; 104502 properties.pointSize = this.pointSize; 104503 properties.curStrokeWeight = this.curStrokeWeight; 104504 properties.curStrokeColor = this.curStrokeColor; 104505 properties.curFillColor = this.curFillColor; 104506 properties.curAmbientColor = this.curAmbientColor; 104507 properties.curSpecularColor = this.curSpecularColor; 104508 properties.curEmissiveColor = this.curEmissiveColor; 104509 properties._useSpecularMaterial = this._useSpecularMaterial; 104510 properties._useEmissiveMaterial = this._useEmissiveMaterial; 104511 properties._useShininess = this._useShininess; 104512 properties.constantAttenuation = this.constantAttenuation; 104513 properties.linearAttenuation = this.linearAttenuation; 104514 properties.quadraticAttenuation = this.quadraticAttenuation; 104515 properties._enableLighting = this._enableLighting; 104516 properties._useNormalMaterial = this._useNormalMaterial; 104517 properties._tex = this._tex; 104518 properties.drawMode = this.drawMode; 104519 properties._currentNormal = this._currentNormal;
104520 properties.curBlendMode = this.curBlendMode; 104521 return style; 104522 }; 104523 _main.default.RendererGL.prototype.resetMatrix = function () { 104524 this.uMVMatrix.set(this._curCamera.cameraMatrix.mat4[0], this._curCamera.cameraMatrix.mat4[1], this._curCamera.cameraMatrix.mat4[2], this._curCamera.cameraMatrix.mat4[3], this._curCamera.cameraMatrix.mat4[4], this._curCamera.cameraMatrix.mat4[5], this._curCamera.cameraMatrix.mat4[6], this._curCamera.cameraMatrix.mat4[7], this._curCamera.cameraMatrix.mat4[8], this._curCamera.cameraMatrix.mat4[9], this._curCamera.cameraMatrix.mat4[10], this._curCamera.cameraMatrix.mat4[11], this._curCamera.cameraMatrix.mat4[12], this._curCamera.cameraMatrix.mat4[13], this._curCamera.cameraMatrix.mat4[14], this._curCamera.cameraMatrix.mat4[15]); 104525 return this; 104526 }; ////////////////////////////////////////////// 104527 // SHADER 104528 ////////////////////////////////////////////// 104529 /* 104530 * shaders are created and cached on a per-renderer basis, 104531 * on the grounds that each renderer will have its own gl context 104532 * and the shader must be valid in that context. 104533 */ 104534 _main.default.RendererGL.prototype._getImmediateStrokeShader = function () { 104535 // select the stroke shader to use 104536 var stroke = this.userStrokeShader; 104537 if (!stroke || !stroke.isStrokeShader()) { 104538 return this._getLineShader(); 104539 } 104540 return stroke; 104541 }; 104542 _main.default.RendererGL.prototype._getRetainedStrokeShader = _main.default.RendererGL.prototype._getImmediateStrokeShader; 104543 /* 104544 * selects which fill shader should be used based on renderer state, 104545 * for use with begin/endShape and immediate vertex mode. 104546 */ 104547 _main.default.RendererGL.prototype._getImmediateFillShader = function () { 104548 var fill = this.userFillShader; 104549 if (this._useNormalMaterial) { 104550 if (!fill || !fill.isNormalShader()) { 104551 return this._getNormalShader(); 104552 } 104553 } 104554 if (this._enableLighting) { 104555 if (!fill || !fill.isLightShader()) { 104556 return this._getLightShader(); 104557 } 104558 } else if (this._tex) { 104559 if (!fill || !fill.isTextureShader()) { 104560 return this._getLightShader(); 104561 } 104562 } else if (!fill /*|| !fill.isColorShader()*/ 104563 ) { 104564 return this._getImmediateModeShader(); 104565 } 104566 return fill; 104567 }; 104568 /* 104569 * selects which fill shader should be used based on renderer state 104570 * for retained mode. 104571 */ 104572 _main.default.RendererGL.prototype._getRetainedFillShader = function () { 104573 if (this._useNormalMaterial) { 104574 return this._getNormalShader(); 104575 } 104576 var fill = this.userFillShader; 104577 if (this._enableLighting) { 104578 if (!fill || !fill.isLightShader()) { 104579 return this._getLightShader(); 104580 } 104581 } else if (this._tex) { 104582 if (!fill || !fill.isTextureShader()) { 104583 return this._getLightShader(); 104584 } 104585 } else if (!fill /* || !fill.isColorShader()*/ 104586 ) { 104587 return this._getColorShader(); 104588 } 104589 return fill; 104590 }; 104591 _main.default.RendererGL.prototype._getImmediatePointShader = function () { 104592 // select the point shader to use 104593 var point = this.userPointShader; 104594 if (!point || !point.isPointShader()) { 104595 return this._getPointShader(); 104596 } 104597 return point; 104598 }; 104599 _main.default.RendererGL.prototype._getRetainedLineShader = _main.default.RendererGL.prototype._getImmediateLineShader; 104600 _main.default.RendererGL.prototype._getLightShader = function () { 104601 if (!this._defaultLightShader) { 104602 if (this._pInst._glAttributes.perPixelLighting) { 104603 this._defaultLightShader = new _main.default.Shader(this, defaultShaders.phongVert, defaultShaders.phongFrag); 104604 } else { 104605 this._defaultLightShader = new _main.default.Shader(this, defaultShaders.lightVert, defaultShaders.lightTextureFrag); 104606 } 104607 } 104608 return this._defaultLightShader; 104609 }; 104610 _main.default.RendererGL.prototype._getImmediateModeShader = function () { 104611 if (!this._defaultImmediateModeShader) { 104612 this._defaultImmediateModeShader = new _main.default.Shader(this, defaultShaders.immediateVert, defaultShaders.vertexColorFrag); 104613 } 104614 return this._defaultImmediateModeShader; 104615 }; 104616 _main.default.RendererGL.prototype._getNormalShader = function () { 104617 if (!this._defaultNormalShader) { 104618 this._defaultNormalShader = new _main.default.Shader(this, defaultShaders.normalVert, defaultShaders.normalFrag); 104619 } 104620 return this._defaultNormalShader; 104621 }; 104622 _main.default.RendererGL.prototype._getColorShader = function () { 104623 if (!this._defaultColorShader) { 104624 this._defaultColorShader = new _main.default.Shader(this, defaultShaders.normalVert, defaultShaders.basicFrag); 104625 } 104626 return this._defaultColorShader; 104627 }; 104628 _main.default.RendererGL.prototype._getPointShader = function () { 104629 if (!this._defaultPointShader) { 104630 this._defaultPointShader = new _main.default.Shader(this, defaultShaders.pointVert, defaultShaders.pointFrag); 104631 } 104632 return this._defaultPointShader; 104633 }; 104634 _main.default.RendererGL.prototype._getLineShader = function () { 104635 if (!this._defaultLineShader) { 104636 this._defaultLineShader = new _main.default.Shader(this, defaultShaders.lineVert, defaultShaders.lineFrag); 104637 } 104638 return this._defaultLineShader; 104639 }; 104640 _main.default.RendererGL.prototype._getFontShader = function () { 104641 if (!this._defaultFontShader) { 104642 this.GL.getExtension('OES_standard_derivatives'); 104643 this._defaultFontShader = new _main.default.Shader(this, defaultShaders.fontVert, defaultShaders.fontFrag); 104644 } 104645 return this._defaultFontShader; 104646 }; 104647 _main.default.RendererGL.prototype._getEmptyTexture = function () { 104648 if (!this._emptyTexture) { 104649 // a plain white texture RGBA, full alpha, single pixel. 104650 var im = new _main.default.Image(1, 1); 104651 im.set(0, 0, 255); 104652 this._emptyTexture = new _main.default.Texture(this, im); 104653 } 104654 return this._emptyTexture; 104655 }; 104656 _main.default.RendererGL.prototype.getTexture = function (img) { 104657 var textures = this.textures; 104658 var _iteratorNormalCompletion = true; 104659 var _didIteratorError = false;
104660 var _iteratorError = undefined; 104661 try { 104662 for (var _iterator = textures[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 104663 var texture = _step.value; 104664 if (texture.src === img) return texture; 104665 } 104666 } catch (err) { 104667 _didIteratorError = true; 104668 _iteratorError = err; 104669 } finally { 104670 try { 104671 if (!_iteratorNormalCompletion && _iterator.return != null) { 104672 _iterator.return(); 104673 } 104674 } finally { 104675 if (_didIteratorError) { 104676 throw _iteratorError; 104677 } 104678 } 104679 } 104680 var tex = new _main.default.Texture(this, img); 104681 textures.push(tex); 104682 return tex; 104683 }; 104684 _main.default.RendererGL.prototype._setStrokeUniforms = function (strokeShader) { 104685 strokeShader.bindShader(); // set the uniform values 104686 strokeShader.setUniform('uUseLineColor', this._useLineColor); 104687 strokeShader.setUniform('uMaterialColor', this.curStrokeColor); 104688 strokeShader.setUniform('uStrokeWeight', this.curStrokeWeight); 104689 strokeShader.setUniform('uStrokeCap', STROKE_CAP_ENUM[this.curStrokeCap]); 104690 strokeShader.setUniform('uStrokeJoin', STROKE_JOIN_ENUM[this.curStrokeJoin]); 104691 }; 104692 _main.default.RendererGL.prototype._setFillUniforms = function (fillShader) { 104693 fillShader.bindShader(); // TODO: optimize 104694 fillShader.setUniform('uUseVertexColor', this._useVertexColor); 104695 fillShader.setUniform('uMaterialColor', this.curFillColor); 104696 fillShader.setUniform('isTexture', !!this._tex); 104697 if (this._tex) { 104698 fillShader.setUniform('uSampler', this._tex); 104699 } 104700 fillShader.setUniform('uTint', this._tint); 104701 fillShader.setUniform('uAmbientMatColor', this.curAmbientColor); 104702 fillShader.setUniform('uSpecularMatColor', this.curSpecularColor); 104703 fillShader.setUniform('uEmissiveMatColor', this.curEmissiveColor); 104704 fillShader.setUniform('uSpecular', this._useSpecularMaterial); 104705 fillShader.setUniform('uEmissive', this._useEmissiveMaterial); 104706 fillShader.setUniform('uShininess', this._useShininess); 104707 fillShader.setUniform('uUseLighting', this._enableLighting); 104708 var pointLightCount = this.pointLightDiffuseColors.length / 3; 104709 fillShader.setUniform('uPointLightCount', pointLightCount); 104710 fillShader.setUniform('uPointLightLocation', this.pointLightPositions); 104711 fillShader.setUniform('uPointLightDiffuseColors', this.pointLightDiffuseColors); 104712 fillShader.setUniform('uPointLightSpecularColors', this.pointLightSpecularColors); 104713 var directionalLightCount = this.directionalLightDiffuseColors.length / 3; 104714 fillShader.setUniform('uDirectionalLightCount', directionalLightCount); 104715 fillShader.setUniform('uLightingDirection', this.directionalLightDirections); 104716 fillShader.setUniform('uDirectionalDiffuseColors', this.directionalLightDiffuseColors); 104717 fillShader.setUniform('uDirectionalSpecularColors', this.directionalLightSpecularColors); // TODO: sum these here... 104718 var ambientLightCount = this.ambientLightColors.length / 3; 104719 fillShader.setUniform('uAmbientLightCount', ambientLightCount); 104720 fillShader.setUniform('uAmbientColor', this.ambientLightColors); 104721 var spotLightCount = this.spotLightDiffuseColors.length / 3; 104722 fillShader.setUniform('uSpotLightCount', spotLightCount); 104723 fillShader.setUniform('uSpotLightAngle', this.spotLightAngle); 104724 fillShader.setUniform('uSpotLightConc', this.spotLightConc); 104725 fillShader.setUniform('uSpotLightDiffuseColors', this.spotLightDiffuseColors); 104726 fillShader.setUniform('uSpotLightSpecularColors', this.spotLightSpecularColors); 104727 fillShader.setUniform('uSpotLightLocation', this.spotLightPositions); 104728 fillShader.setUniform('uSpotLightDirection', this.spotLightDirections); 104729 fillShader.setUniform('uConstantAttenuation', this.constantAttenuation); 104730 fillShader.setUniform('uLinearAttenuation', this.linearAttenuation); 104731 fillShader.setUniform('uQuadraticAttenuation', this.quadraticAttenuation); 104732 fillShader.bindTextures(); 104733 }; 104734 _main.default.RendererGL.prototype._setPointUniforms = function (pointShader) { 104735 pointShader.bindShader(); // set the uniform values 104736 pointShader.setUniform('uMaterialColor', this.curStrokeColor); // @todo is there an instance where this isn't stroke weight? 104737 // should be they be same var? 104738 pointShader.setUniform('uPointSize', this.pointSize * this._pInst._pixelDensity); 104739 }; 104740 /* Binds a buffer to the drawing context 104741 * when passed more than two arguments it also updates or initializes 104742 * the data associated with the buffer 104743 */ 104744 _main.default.RendererGL.prototype._bindBuffer = function (buffer, target, values, type, usage) { 104745 if (!target) target = this.GL.ARRAY_BUFFER; 104746 this.GL.bindBuffer(target, buffer); 104747 if (values !== undefined) { 104748 var data = new (type || Float32Array) (values); 104749 this.GL.bufferData(target, data, usage || this.GL.STATIC_DRAW); 104750 } 104751 }; /////////////////////////////// 104752 //// UTILITY FUNCTIONS
104753 ////////////////////////////// 104754 _main.default.RendererGL.prototype._arraysEqual = function (a, b) { 104755 var aLength = a.length; 104756 if (aLength !== b.length) return false; 104757 for (var i = 0; i < aLength; i++) { 104758 if (a[i] !== b[i]) return false; 104759 } 104760 return true; 104761 }; 104762 _main.default.RendererGL.prototype._isTypedArray = function (arr) { 104763 var res = false; 104764 res = arr instanceof Float32Array; 104765 res = arr instanceof Float64Array; 104766 res = arr instanceof Int16Array; 104767 res = arr instanceof Uint16Array; 104768 res = arr instanceof Uint32Array; 104769 return res; 104770 }; 104771 /** 104772 * turn a two dimensional array into one dimensional array 104773 * @private 104774 * @param {Array} arr 2-dimensional array 104775 * @return {Array} 1-dimensional array 104776 * [[1, 2, 3],[4, 5, 6]] -> [1, 2, 3, 4, 5, 6] 104777 */ 104778 _main.default.RendererGL.prototype._flatten = function (arr) { 104779 //when empty, return empty 104780 if (arr.length === 0) { 104781 return []; 104782 } else if (arr.length > 20000) { 104783 //big models , load slower to avoid stack overflow 104784 //faster non-recursive flatten via axelduch 104785 //stackoverflow.com/questions/27266550/how-to-flatten-nested-array-in-javascript 104786 var _toString = Object.prototype.toString; 104787 var arrayTypeStr = '[object Array]'; 104788 var result = [ 104789 ]; 104790 var nodes = arr.slice(); 104791 var node; 104792 node = nodes.pop(); 104793 do { 104794 if (_toString.call(node) === arrayTypeStr) { 104795 nodes.push.apply(nodes, _toConsumableArray(node)); 104796 } else { 104797 result.push(node); 104798 } 104799 } while (nodes.length && (node = nodes.pop()) !== undefined); 104800 result.reverse(); // we reverse result to restore the original order 104801 return result; 104802 } else { 104803 var _ref; //otherwise if model within limits for browser 104804 //use faster recursive loading 104805 return (_ref = [ 104806 ]).concat.apply(_ref, _toConsumableArray(arr)); 104807 } 104808 }; 104809 /** 104810 * turn a p5.Vector Array into a one dimensional number array 104811 * @private 104812 * @param {p5.Vector[]} arr an array of p5.Vector 104813 * @return {Number[]} a one dimensional array of numbers 104814 * [p5.Vector(1, 2, 3), p5.Vector(4, 5, 6)] -> 104815 * [1, 2, 3, 4, 5, 6] 104816 */ 104817 _main.default.RendererGL.prototype._vToNArray = function (arr) { 104818 var ret = [ 104819 ]; 104820 var _iteratorNormalCompletion2 = true; 104821 var _didIteratorError2 = false;
104822 var _iteratorError2 = undefined; 104823 try { 104824 for (var _iterator2 = arr[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 104825 var item = _step2.value; 104826 ret.push(item.x, item.y, item.z); 104827 } 104828 } catch (err) { 104829 _didIteratorError2 = true; 104830 _iteratorError2 = err; 104831 } finally { 104832 try { 104833 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 104834 _iterator2.return(); 104835 } 104836 } finally { 104837 if (_didIteratorError2) { 104838 throw _iteratorError2; 104839 } 104840 } 104841 } 104842 return ret; 104843 }; 104844 /** 104845 * ensures that p5 is using a 3d renderer. throws an error if not. 104846 */ 104847 _main.default.prototype._assert3d = function (name) { 104848 if (!this._renderer.isP3D) throw new Error(''.concat(name, '() is only supported in WEBGL mode. If you\'d like to use 3D graphics and WebGL, see https://p5js.org/examples/form-3d-primitives.html for more information.')); 104849 }; // function to initialize GLU Tesselator 104850 _main.default.RendererGL.prototype.tessyVertexSize = 12; 104851 _main.default.RendererGL.prototype._initTessy = function initTesselator() { 104852 // function called for each vertex of tesselator output 104853 function vertexCallback(data, polyVertArray) { 104854 for (var i = 0; i < data.length; i++) { 104855 polyVertArray[polyVertArray.length] = data[i]; 104856 } 104857 } 104858 function begincallback(type) { 104859 if (type !== _libtess.default.primitiveType.GL_TRIANGLES) { 104860 console.log('expected TRIANGLES but got type: '.concat(type)); 104861 } 104862 } 104863 function errorcallback(errno) { 104864 console.log('error callback'); 104865 console.log('error number: '.concat(errno)); 104866 } // callback for when segments intersect and must be split 104867 104868 function combinecallback(coords, data, weight) { 104869 var result = new Array(_main.default.RendererGL.prototype.tessyVertexSize).fill(0); 104870 for (var i = 0; i < weight.length; i++) { 104871 for (var j = 0; j < result.length; j++) { 104872 if (weight[i] === 0 || !data[i]) continue; 104873 result[j] += data[i][j] * weight[i]; 104874 } 104875 } 104876 return result; 104877 } 104878 function edgeCallback(flag) { // don't really care about the flag, but need no-strip/no-fan behavior 104879 } 104880 var tessy = new _libtess.default.GluTesselator(); 104881 tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_VERTEX_DATA, vertexCallback); 104882 tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_BEGIN, begincallback); 104883 tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_ERROR, errorcallback); 104884 tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_COMBINE, combinecallback); 104885 tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_EDGE_FLAG, edgeCallback); 104886 return tessy; 104887 }; 104888 _main.default.RendererGL.prototype._triangulate = function (contours) { 104889 // libtess will take 3d verts and flatten to a plane for tesselation. 104890 // libtess is capable of calculating a plane to tesselate on, but 104891 // if all of the vertices have the same z values, we'll just 104892 // assume the face is facing the camera, letting us skip any performance 104893 // issues or bugs in libtess's automatic calculation. 104894 var z = contours[0] ? contours[0][2] : undefined; 104895 var allSameZ = true; 104896 var _iteratorNormalCompletion3 = true; 104897 var _didIteratorError3 = false; 104898 var _iteratorError3 = undefined; 104899 try { 104900 for (var _iterator3 = contours[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 104901 var _contour = _step3.value; 104902 for (var _j = 0; _j < _contour.length; _j += _main.default.RendererGL.prototype.tessyVertexSize) { 104903 if (_contour[_j + 2] !== z) { 104904 allSameZ = false;
104905 break; 104906 } 104907 } 104908 } 104909 } catch (err) { 104910 _didIteratorError3 = true; 104911 _iteratorError3 = err; 104912 } finally { 104913 try { 104914 if (!_iteratorNormalCompletion3 && _iterator3.return != null) { 104915 _iterator3.return(); 104916 } 104917 } finally { 104918 if (_didIteratorError3) { 104919 throw _iteratorError3; 104920 } 104921 } 104922 } 104923 if (allSameZ) { 104924 this._tessy.gluTessNormal(0, 0, 1); 104925 } else { 104926 // Let libtess pick a plane for us 104927 this._tessy.gluTessNormal(0, 0, 0); 104928 } 104929 var triangleVerts = [ 104930 ]; 104931 this._tessy.gluTessBeginPolygon(triangleVerts); 104932 for (var i = 0; i < contours.length; i++) { 104933 this._tessy.gluTessBeginContour(); 104934 var contour = contours[i]; 104935 for (var j = 0; j < contour.length; j += _main.default.RendererGL.prototype.tessyVertexSize) { 104936 var coords = contour.slice(j, j + _main.default.RendererGL.prototype.tessyVertexSize); 104937 this._tessy.gluTessVertex(coords, coords); 104938 } 104939 this._tessy.gluTessEndContour(); 104940 } // finish polygon 104941 104942 this._tessy.gluTessEndPolygon(); 104943 return triangleVerts; 104944 }; // function to calculate BezierVertex Coefficients 104945 _main.default.RendererGL.prototype._bezierCoefficients = function (t) { 104946 var t2 = t * t; 104947 var t3 = t2 * t; 104948 var mt = 1 - t; 104949 var mt2 = mt * mt; 104950 var mt3 = mt2 * mt; 104951 return [mt3, 104952 3 * mt2 * t, 104953 3 * mt * t2, 104954 t3]; 104955 }; // function to calculate QuadraticVertex Coefficients 104956 _main.default.RendererGL.prototype._quadraticCoefficients = function (t) { 104957 var t2 = t * t; 104958 var mt = 1 - t; 104959 var mt2 = mt * mt; 104960 return [mt2, 104961 2 * mt * t, 104962 t2]; 104963 }; // function to convert Bezier coordinates to Catmull Rom Splines 104964 _main.default.RendererGL.prototype._bezierToCatmull = function (w) { 104965 var p1 = w[1]; 104966 var p2 = w[1] + (w[2] - w[0]) / this._curveTightness; 104967 var p3 = w[2] - (w[3] - w[1]) / this._curveTightness; 104968 var p4 = w[2]; 104969 var p = [ 104970 p1, 104971 p2, 104972 p3, 104973 p4 104974 ]; 104975 return p; 104976 }; 104977 var _default = _main.default.RendererGL; 104978 exports.default = _default; 104979 }, 104980 { 104981 '../core/constants': 278, 104982 '../core/main': 290, 104983 '../core/p5.Renderer': 293, 104984 './p5.Camera': 338, 104985 './p5.Matrix': 340, 104986 './p5.Shader': 345, 104987 'core-js/modules/es.array.concat': 167, 104988 'core-js/modules/es.array.fill': 170, 104989 'core-js/modules/es.array.filter': 171, 104990 'core-js/modules/es.array.from': 173, 104991 'core-js/modules/es.array.includes': 174, 104992 'core-js/modules/es.array.iterator': 176, 104993 'core-js/modules/es.array.slice': 180, 104994 'core-js/modules/es.object.assign': 190, 104995 'core-js/modules/es.object.get-own-property-descriptor': 191, 104996 'core-js/modules/es.object.to-string': 195, 104997 'core-js/modules/es.regexp.to-string': 200, 104998 'core-js/modules/es.string.includes': 203, 104999 'core-js/modules/es.string.iterator': 204, 105000 'core-js/modules/es.symbol': 214, 105001 'core-js/modules/es.symbol.description': 212, 105002 'core-js/modules/es.symbol.iterator': 213, 105003 'core-js/modules/es.typed-array.copy-within': 215, 105004 'core-js/modules/es.typed-array.every': 216, 105005 'core-js/modules/es.typed-array.fill': 217, 105006 'core-js/modules/es.typed-array.filter': 218, 105007 'core-js/modules/es.typed-array.find': 220, 105008 'core-js/modules/es.typed-array.find-index': 219, 105009 'core-js/modules/es.typed-array.float32-array': 221, 105010 'core-js/modules/es.typed-array.float64-array': 222, 105011 'core-js/modules/es.typed-array.for-each': 223, 105012 'core-js/modules/es.typed-array.includes': 224, 105013 'core-js/modules/es.typed-array.index-of': 225, 105014 'core-js/modules/es.typed-array.int16-array': 226, 105015 'core-js/modules/es.typed-array.iterator': 228, 105016 'core-js/modules/es.typed-array.join': 229, 105017 'core-js/modules/es.typed-array.last-index-of': 230, 105018 'core-js/modules/es.typed-array.map': 231, 105019 'core-js/modules/es.typed-array.reduce': 233, 105020 'core-js/modules/es.typed-array.reduce-right': 232, 105021 'core-js/modules/es.typed-array.reverse': 234, 105022 'core-js/modules/es.typed-array.set': 235, 105023 'core-js/modules/es.typed-array.slice': 236, 105024 'core-js/modules/es.typed-array.some': 237, 105025 'core-js/modules/es.typed-array.sort': 238, 105026 'core-js/modules/es.typed-array.subarray': 239, 105027 'core-js/modules/es.typed-array.to-locale-string': 240, 105028 'core-js/modules/es.typed-array.to-string': 241, 105029 'core-js/modules/es.typed-array.uint16-array': 242, 105030 'core-js/modules/es.typed-array.uint32-array': 243, 105031 'core-js/modules/es.typed-array.uint8-array': 244, 105032 'core-js/modules/es.weak-map': 246, 105033 'core-js/modules/web.dom-collections.iterator': 248, 105034 'libtess': 261, 105035 'path': 264 105036 } 105037 ], 105038 345: [
105039 function (_dereq_, module, exports) { 105040 'use strict'; 105041 _dereq_('core-js/modules/es.symbol'); 105042 _dereq_('core-js/modules/es.symbol.description'); 105043 _dereq_('core-js/modules/es.symbol.iterator'); 105044 _dereq_('core-js/modules/es.array.index-of'); 105045 _dereq_('core-js/modules/es.array.iterator'); 105046 _dereq_('core-js/modules/es.array.slice'); 105047 _dereq_('core-js/modules/es.function.name'); 105048 _dereq_('core-js/modules/es.object.to-string'); 105049 _dereq_('core-js/modules/es.string.iterator'); 105050 _dereq_('core-js/modules/web.dom-collections.iterator'); 105051 _dereq_('core-js/modules/es.symbol'); 105052 _dereq_('core-js/modules/es.symbol.description'); 105053 _dereq_('core-js/modules/es.symbol.iterator'); 105054 _dereq_('core-js/modules/es.array.index-of'); 105055 _dereq_('core-js/modules/es.array.iterator'); 105056 _dereq_('core-js/modules/es.array.slice'); 105057 _dereq_('core-js/modules/es.function.name'); 105058 _dereq_('core-js/modules/es.object.to-string'); 105059 _dereq_('core-js/modules/es.string.iterator'); 105060 _dereq_('core-js/modules/web.dom-collections.iterator'); 105061 Object.defineProperty(exports, '__esModule', { 105062 value: true 105063 }); 105064 exports.default = void 0; 105065 var _main = _interopRequireDefault(_dereq_('../core/main')); 105066 function _interopRequireDefault(obj) { 105067 return obj && obj.__esModule ? obj : { 105068 default: 105069 obj 105070 }; 105071 } /** 105072 * This module defines the p5.Shader class 105073 * @module 3D 105074 * @submodule Material 105075 * @for p5 105076 * @requires core 105077 */ 105078 /** 105079 * Shader class for WEBGL Mode 105080 * @class p5.Shader 105081 * @constructor 105082 * @param {p5.RendererGL} renderer an instance of p5.RendererGL that 105083 * will provide the GL context for this new p5.Shader 105084 * @param {String} vertSrc source code for the vertex shader (as a string) 105085 * @param {String} fragSrc source code for the fragment shader (as a string) 105086 */ 105087 105088 _main.default.Shader = function (renderer, vertSrc, fragSrc) { 105089 // TODO: adapt this to not take ids, but rather, 105090 // to take the source for a vertex and fragment shader 105091 // to enable custom shaders at some later date 105092 this._renderer = renderer; 105093 this._vertSrc = vertSrc; 105094 this._fragSrc = fragSrc; 105095 this._vertShader = - 1; 105096 this._fragShader = - 1; 105097 this._glProgram = 0; 105098 this._loadedAttributes = false; 105099 this.attributes = { 105100 }; 105101 this._loadedUniforms = false; 105102 this.uniforms = { 105103 }; 105104 this._bound = false; 105105 this.samplers = [ 105106 ]; 105107 }; 105108 /** 105109 * Creates, compiles, and links the shader based on its 105110 * sources for the vertex and fragment shaders (provided 105111 * to the constructor). Populates known attributes and 105112 * uniforms from the shader. 105113 * @method init 105114 * @chainable 105115 * @private 105116 */ 105117 _main.default.Shader.prototype.init = function () { 105118 if (this._glProgram === 0 /* or context is stale? */ 105119 ) { 105120 var gl = this._renderer.GL; // @todo: once custom shading is allowed, 105121 // friendly error messages should be used here to share 105122 // compiler and linker errors. 105123 //set up the shader by 105124 // 1. creating and getting a gl id for the shader program, 105125 // 2. compliling its vertex & fragment sources, 105126 // 3. linking the vertex and fragment shaders 105127 this._vertShader = gl.createShader(gl.VERTEX_SHADER); //load in our default vertex shader 105128 gl.shaderSource(this._vertShader, this._vertSrc); 105129 gl.compileShader(this._vertShader); // if our vertex shader failed compilation? 105130 if (!gl.getShaderParameter(this._vertShader, gl.COMPILE_STATUS)) { 105131 console.error('Yikes! An error occurred compiling the vertex shader:'.concat(gl.getShaderInfoLog(this._vertShader))); 105132 return null; 105133 } 105134 this._fragShader = gl.createShader(gl.FRAGMENT_SHADER); //load in our material frag shader 105135 gl.shaderSource(this._fragShader, this._fragSrc); 105136 gl.compileShader(this._fragShader); // if our frag shader failed compilation? 105137 if (!gl.getShaderParameter(this._fragShader, gl.COMPILE_STATUS)) { 105138 console.error('Darn! An error occurred compiling the fragment shader:'.concat(gl.getShaderInfoLog(this._fragShader))); 105139 return null; 105140 } 105141 this._glProgram = gl.createProgram(); 105142 gl.attachShader(this._glProgram, this._vertShader); 105143 gl.attachShader(this._glProgram, this._fragShader); 105144 gl.linkProgram(this._glProgram); 105145 if (!gl.getProgramParameter(this._glProgram, gl.LINK_STATUS)) { 105146 console.error('Snap! Error linking shader program: '.concat(gl.getProgramInfoLog(this._glProgram))); 105147 } 105148 this._loadAttributes(); 105149 this._loadUniforms(); 105150 } 105151 return this; 105152 }; 105153 /** 105154 * Queries the active attributes for this shader and loads 105155 * their names and locations into the attributes array. 105156 * @method _loadAttributes 105157 * @private 105158 */ 105159 _main.default.Shader.prototype._loadAttributes = function () { 105160 if (this._loadedAttributes) { 105161 return; 105162 } 105163 this.attributes = { 105164 }; 105165 var gl = this._renderer.GL; 105166 var numAttributes = gl.getProgramParameter(this._glProgram, gl.ACTIVE_ATTRIBUTES); 105167 for (var i = 0; i < numAttributes; ++i) { 105168 var attributeInfo = gl.getActiveAttrib(this._glProgram, i); 105169 var name = attributeInfo.name; 105170 var location = gl.getAttribLocation(this._glProgram, name); 105171 var attribute = { 105172 }; 105173 attribute.name = name; 105174 attribute.location = location; 105175 attribute.index = i; 105176 attribute.type = attributeInfo.type; 105177 attribute.size = attributeInfo.size; 105178 this.attributes[name] = attribute; 105179 } 105180 this._loadedAttributes = true; 105181 }; 105182 /** 105183 * Queries the active uniforms for this shader and loads 105184 * their names and locations into the uniforms array. 105185 * @method _loadUniforms 105186 * @private 105187 */ 105188 _main.default.Shader.prototype._loadUniforms = function () { 105189 if (this._loadedUniforms) { 105190 return; 105191 } 105192 var gl = this._renderer.GL; // Inspect shader and cache uniform info 105193 var numUniforms = gl.getProgramParameter(this._glProgram, gl.ACTIVE_UNIFORMS); 105194 var samplerIndex = 0; 105195 for (var i = 0; i < numUniforms; ++i) { 105196 var uniformInfo = gl.getActiveUniform(this._glProgram, i); 105197 var uniform = { 105198 }; 105199 uniform.location = gl.getUniformLocation(this._glProgram, uniformInfo.name); 105200 uniform.size = uniformInfo.size; 105201 var uniformName = uniformInfo.name; //uniforms thats are arrays have their name returned as 105202 //someUniform[0] which is a bit silly so we trim it 105203 //off here. The size property tells us that its an array 105204 //so we dont lose any information by doing this 105205 if (uniformInfo.size > 1) { 105206 uniformName = uniformName.substring(0, uniformName.indexOf('[0]')); 105207 } 105208 uniform.name = uniformName; 105209 uniform.type = uniformInfo.type; 105210 uniform._cachedData = undefined; 105211 if (uniform.type === gl.SAMPLER_2D) { 105212 uniform.samplerIndex = samplerIndex; 105213 samplerIndex++; 105214 this.samplers.push(uniform); 105215 } 105216 uniform.isArray = uniformInfo.size > 1 || uniform.type === gl.FLOAT_MAT3 || uniform.type === gl.FLOAT_MAT4 || uniform.type === gl.FLOAT_VEC2 || uniform.type === gl.FLOAT_VEC3 || uniform.type === gl.FLOAT_VEC4 || uniform.type === gl.INT_VEC2 || uniform.type === gl.INT_VEC4 || uniform.type === gl.INT_VEC3; 105217 this.uniforms[uniformName] = uniform; 105218 } 105219 this._loadedUniforms = true; 105220 }; 105221 _main.default.Shader.prototype.compile = function () { // TODO 105222 }; 105223 /** 105224 * initializes (if needed) and binds the shader program. 105225 * @method bindShader 105226 * @private 105227 */ 105228 _main.default.Shader.prototype.bindShader = function () { 105229 this.init(); 105230 if (!this._bound) { 105231 this.useProgram(); 105232 this._bound = true; 105233 this._setMatrixUniforms(); 105234 this.setUniform('uViewport', this._renderer._viewport); 105235 } 105236 }; 105237 /** 105238 * @method unbindShader 105239 * @chainable 105240 * @private 105241 */ 105242 _main.default.Shader.prototype.unbindShader = function () { 105243 if (this._bound) { 105244 this.unbindTextures(); //this._renderer.GL.useProgram(0); ?? 105245 this._bound = false;
105246 } 105247 return this; 105248 }; 105249 _main.default.Shader.prototype.bindTextures = function () { 105250 var gl = this._renderer.GL; 105251 var _iteratorNormalCompletion = true; 105252 var _didIteratorError = false; 105253 var _iteratorError = undefined; 105254 try { 105255 for (var _iterator = this.samplers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 105256 var uniform = _step.value; 105257 var tex = uniform.texture; 105258 if (tex === undefined) { 105259 // user hasn't yet supplied a texture for this slot. 105260 // (or there may not be one--maybe just lighting), 105261 // so we supply a default texture instead. 105262 tex = this._renderer._getEmptyTexture(); 105263 } 105264 gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex); 105265 tex.bindTexture(); 105266 tex.update(); 105267 gl.uniform1i(uniform.location, uniform.samplerIndex); 105268 } 105269 } catch (err) { 105270 _didIteratorError = true; 105271 _iteratorError = err; 105272 } finally { 105273 try { 105274 if (!_iteratorNormalCompletion && _iterator.return != null) { 105275 _iterator.return(); 105276 } 105277 } finally { 105278 if (_didIteratorError) { 105279 throw _iteratorError; 105280 } 105281 } 105282 } 105283 }; 105284 _main.default.Shader.prototype.updateTextures = function () { 105285 var _iteratorNormalCompletion2 = true; 105286 var _didIteratorError2 = false;
105287 var _iteratorError2 = undefined; 105288 try { 105289 for (var _iterator2 = this.samplers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 105290 var uniform = _step2.value; 105291 var tex = uniform.texture; 105292 if (tex) { 105293 tex.update(); 105294 } 105295 } 105296 } catch (err) { 105297 _didIteratorError2 = true; 105298 _iteratorError2 = err; 105299 } finally { 105300 try { 105301 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 105302 _iterator2.return(); 105303 } 105304 } finally { 105305 if (_didIteratorError2) { 105306 throw _iteratorError2; 105307 } 105308 } 105309 } 105310 }; 105311 _main.default.Shader.prototype.unbindTextures = function () { 105312 var _iteratorNormalCompletion3 = true; 105313 var _didIteratorError3 = false; 105314 var _iteratorError3 = undefined; 105315 try { 105316 for (var _iterator3 = this.samplers[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 105317 var uniform = _step3.value; 105318 this.setUniform(uniform.name, this._renderer._getEmptyTexture()); 105319 } 105320 } catch (err) { 105321 _didIteratorError3 = true; 105322 _iteratorError3 = err; 105323 } finally { 105324 try { 105325 if (!_iteratorNormalCompletion3 && _iterator3.return != null) { 105326 _iterator3.return(); 105327 } 105328 } finally { 105329 if (_didIteratorError3) { 105330 throw _iteratorError3; 105331 } 105332 } 105333 } 105334 }; 105335 _main.default.Shader.prototype._setMatrixUniforms = function () { 105336 var viewMatrix = this._renderer._curCamera.cameraMatrix; 105337 var projectionMatrix = this._renderer.uPMatrix; 105338 var modelViewMatrix = this._renderer.uMVMatrix; 105339 var modelViewProjectionMatrix = modelViewMatrix.copy(); 105340 modelViewProjectionMatrix.mult(projectionMatrix); 105341 if (this.isStrokeShader()) { 105342 if (this._renderer._curCamera.cameraType === 'default') { 105343 // strokes scale up as they approach camera, default 105344 this.setUniform('uPerspective', 1); 105345 } else { 105346 // strokes have uniform scale regardless of distance from camera 105347 this.setUniform('uPerspective', 0); 105348 } 105349 } 105350 this.setUniform('uViewMatrix', viewMatrix.mat4); 105351 this.setUniform('uProjectionMatrix', projectionMatrix.mat4); 105352 this.setUniform('uModelViewMatrix', modelViewMatrix.mat4); 105353 this.setUniform('uModelViewProjectionMatrix', modelViewProjectionMatrix.mat4); 105354 if (this.uniforms.uNormalMatrix) { 105355 this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix); 105356 this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3); 105357 } 105358 }; 105359 /** 105360 * @method useProgram 105361 * @chainable 105362 * @private 105363 */ 105364 _main.default.Shader.prototype.useProgram = function () { 105365 var gl = this._renderer.GL; 105366 if (this._renderer._curShader !== this) { 105367 gl.useProgram(this._glProgram); 105368 this._renderer._curShader = this; 105369 } 105370 return this; 105371 }; 105372 /** 105373 * Used to set the uniforms of a 105374 * <a href="#/p5.Shader">p5.Shader</a> object. 105375 * 105376 * Uniforms are used as a way to provide shader programs 105377 * (which run on the GPU) with values from a sketch 105378 * (which runs on the CPU). 105379 * 105380 * @method setUniform 105381 * @chainable 105382 * @param {String} uniformName the name of the uniform. 105383 * Must correspond to the name used in the vertex and fragment shaders 105384 * @param {Boolean|Number|Number[]|p5.Image|p5.Graphics|p5.MediaElement|p5.Texture} 105385 * data the data to associate with the uniform. The type can be 105386 * a boolean (true/false), a number, an array of numbers, or 105387 * an image (p5.Image, p5.Graphics, p5.MediaElement, p5.Texture) 105388 * 105389 * @example 105390 * <div modernizr='webgl'> 105391 * <code> 105392 * // Click within the image to toggle the value of uniforms 105393 * // Note: for an alternative approach to the same example, 105394 * // involving toggling between shaders please refer to: 105395 * // https://p5js.org/reference/#/p5/shader 105396 * 105397 * let grad; 105398 * let showRedGreen = false;
105399 * 105400 * function preload() { 105401 * // note that we are using two instances 105402 * // of the same vertex and fragment shaders 105403 * grad = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); 105404 * } 105405 * 105406 * function setup() { 105407 * createCanvas(100, 100, WEBGL); 105408 * shader(grad); 105409 * noStroke(); 105410 * 105411 * describe( 105412 * 'canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.' 105413 * ); 105414 * } 105415 * 105416 * function draw() { 105417 * // update the offset values for each scenario, 105418 * // moving the "grad" shader in either vertical or 105419 * // horizontal direction each with differing colors 105420 * 105421 * if (showRedGreen === true) { 105422 * grad.setUniform('colorCenter', [1, 0, 0]); 105423 * grad.setUniform('colorBackground', [0, 1, 0]); 105424 * grad.setUniform('offset', [sin(millis() / 2000), 1]); 105425 * } else { 105426 * grad.setUniform('colorCenter', [1, 0.5, 0]); 105427 * grad.setUniform('colorBackground', [0.226, 0, 0.615]); 105428 * grad.setUniform('offset', [0, sin(millis() / 2000) + 1]); 105429 * } 105430 * quad(-1, -1, 1, -1, 1, 1, -1, 1); 105431 * } 105432 * 105433 * function mouseClicked() { 105434 * showRedGreen = !showRedGreen; 105435 * } 105436 * </code> 105437 * </div> 105438 * 105439 * @alt 105440 * canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed. 105441 */ 105442 _main.default.Shader.prototype.setUniform = function (uniformName, data) { 105443 var uniform = this.uniforms[uniformName]; 105444 if (!uniform) { 105445 return; 105446 } 105447 var gl = this._renderer.GL; 105448 if (uniform.isArray) { 105449 if (uniform._cachedData && this._renderer._arraysEqual(uniform._cachedData, data)) { 105450 return; 105451 } else { 105452 uniform._cachedData = data.slice(0); 105453 } 105454 } else if (uniform._cachedData && uniform._cachedData === data) { 105455 return; 105456 } else { 105457 if (Array.isArray(data)) { 105458 uniform._cachedData = data.slice(0); 105459 } else { 105460 uniform._cachedData = data; 105461 } 105462 } 105463 var location = uniform.location; 105464 this.useProgram(); 105465 switch (uniform.type) { 105466 case gl.BOOL: 105467 if (data === true) { 105468 gl.uniform1i(location, 1); 105469 } else { 105470 gl.uniform1i(location, 0); 105471 } 105472 break; 105473 case gl.INT: 105474 if (uniform.size > 1) { 105475 data.length && gl.uniform1iv(location, data); 105476 } else { 105477 gl.uniform1i(location, data); 105478 } 105479 break; 105480 case gl.FLOAT: 105481 if (uniform.size > 1) { 105482 data.length && gl.uniform1fv(location, data); 105483 } else { 105484 gl.uniform1f(location, data); 105485 } 105486 break; 105487 case gl.FLOAT_MAT3: 105488 gl.uniformMatrix3fv(location, false, data); 105489 break; 105490 case gl.FLOAT_MAT4: 105491 gl.uniformMatrix4fv(location, false, data); 105492 break; 105493 case gl.FLOAT_VEC2: 105494 if (uniform.size > 1) { 105495 data.length && gl.uniform2fv(location, data); 105496 } else { 105497 gl.uniform2f(location, data[0], data[1]); 105498 } 105499 break; 105500 case gl.FLOAT_VEC3: 105501 if (uniform.size > 1) { 105502 data.length && gl.uniform3fv(location, data); 105503 } else { 105504 gl.uniform3f(location, data[0], data[1], data[2]); 105505 } 105506 break; 105507 case gl.FLOAT_VEC4: 105508 if (uniform.size > 1) { 105509 data.length && gl.uniform4fv(location, data); 105510 } else { 105511 gl.uniform4f(location, data[0], data[1], data[2], data[3]); 105512 } 105513 break; 105514 case gl.INT_VEC2: 105515 if (uniform.size > 1) { 105516 data.length && gl.uniform2iv(location, data); 105517 } else { 105518 gl.uniform2i(location, data[0], data[1]); 105519 } 105520 break; 105521 case gl.INT_VEC3: 105522 if (uniform.size > 1) { 105523 data.length && gl.uniform3iv(location, data); 105524 } else { 105525 gl.uniform3i(location, data[0], data[1], data[2]); 105526 } 105527 break; 105528 case gl.INT_VEC4: 105529 if (uniform.size > 1) { 105530 data.length && gl.uniform4iv(location, data); 105531 } else { 105532 gl.uniform4i(location, data[0], data[1], data[2], data[3]); 105533 } 105534 break; 105535 case gl.SAMPLER_2D: 105536 gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex); 105537 uniform.texture = data instanceof _main.default.Texture ? data : this._renderer.getTexture(data); 105538 gl.uniform1i(location, uniform.samplerIndex); 105539 if (uniform.texture.src.gifProperties) { 105540 uniform.texture.src._animateGif(this._renderer._pInst); 105541 } 105542 break; 105543 //@todo complete all types 105544 } 105545 return this; 105546 }; 105547 /* NONE OF THIS IS FAST OR EFFICIENT BUT BEAR WITH ME 105548 * 105549 * these shader "type" query methods are used by various 105550 * facilities of the renderer to determine if changing
105551 * the shader type for the required action (for example, 105552 * do we need to load the default lighting shader if the 105553 * current shader cannot handle lighting?) 105554 * 105555 **/ 105556 _main.default.Shader.prototype.isLightShader = function () { 105557 return this.attributes.aNormal !== undefined || this.uniforms.uUseLighting !== undefined || this.uniforms.uAmbientLightCount !== undefined || this.uniforms.uDirectionalLightCount !== undefined || this.uniforms.uPointLightCount !== undefined || this.uniforms.uAmbientColor !== undefined || this.uniforms.uDirectionalDiffuseColors !== undefined || this.uniforms.uDirectionalSpecularColors !== undefined || this.uniforms.uPointLightLocation !== undefined || this.uniforms.uPointLightDiffuseColors !== undefined || this.uniforms.uPointLightSpecularColors !== undefined || this.uniforms.uLightingDirection !== undefined || this.uniforms.uSpecular !== undefined; 105558 }; 105559 _main.default.Shader.prototype.isNormalShader = function () { 105560 return this.attributes.aNormal !== undefined; 105561 }; 105562 _main.default.Shader.prototype.isTextureShader = function () { 105563 return this.samplers.length > 0; 105564 }; 105565 _main.default.Shader.prototype.isColorShader = function () { 105566 return this.attributes.aVertexColor !== undefined || this.uniforms.uMaterialColor !== undefined; 105567 }; 105568 _main.default.Shader.prototype.isTexLightShader = function () { 105569 return this.isLightShader() && this.isTextureShader(); 105570 }; 105571 _main.default.Shader.prototype.isStrokeShader = function () { 105572 return this.uniforms.uStrokeWeight !== undefined; 105573 }; 105574 /** 105575 * @method enableAttrib 105576 * @chainable 105577 * @private 105578 */ 105579 _main.default.Shader.prototype.enableAttrib = function (attr, size, type, normalized, stride, offset) { 105580 if (attr) { 105581 if (typeof IS_MINIFIED === 'undefined' && this.attributes[attr.name] !== attr) { 105582 console.warn('The attribute "'.concat(attr.name, '"passed to enableAttrib does not belong to this shader.')); 105583 } 105584 var loc = attr.location; 105585 if (loc !== - 1) { 105586 var gl = this._renderer.GL; // Enable register even if it is disabled 105587 if (!this._renderer.registerEnabled[loc]) { 105588 gl.enableVertexAttribArray(loc); // Record register availability 105589 this._renderer.registerEnabled[loc] = true; 105590 } 105591 this._renderer.GL.vertexAttribPointer(loc, size, type || gl.FLOAT, normalized || false, stride || 0, offset || 0); 105592 } 105593 } 105594 return this; 105595 }; 105596 var _default = _main.default.Shader; 105597 exports.default = _default; 105598 }, 105599 { 105600 '../core/main': 290, 105601 'core-js/modules/es.array.index-of': 175, 105602 'core-js/modules/es.array.iterator': 176, 105603 'core-js/modules/es.array.slice': 180, 105604 'core-js/modules/es.function.name': 183, 105605 'core-js/modules/es.object.to-string': 195, 105606 'core-js/modules/es.string.iterator': 204, 105607 'core-js/modules/es.symbol': 214, 105608 'core-js/modules/es.symbol.description': 212, 105609 'core-js/modules/es.symbol.iterator': 213, 105610 'core-js/modules/web.dom-collections.iterator': 248 105611 } 105612 ], 105613 346: [ 105614 function (_dereq_, module, exports) { 105615 'use strict'; 105616 _dereq_('core-js/modules/es.symbol'); 105617 _dereq_('core-js/modules/es.symbol.description'); 105618 _dereq_('core-js/modules/es.symbol.iterator'); 105619 _dereq_('core-js/modules/es.array.iterator'); 105620 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 105621 _dereq_('core-js/modules/es.object.to-string'); 105622 _dereq_('core-js/modules/es.string.iterator'); 105623 _dereq_('core-js/modules/es.typed-array.uint8-array'); 105624 _dereq_('core-js/modules/es.typed-array.copy-within'); 105625 _dereq_('core-js/modules/es.typed-array.every'); 105626 _dereq_('core-js/modules/es.typed-array.fill'); 105627 _dereq_('core-js/modules/es.typed-array.filter'); 105628 _dereq_('core-js/modules/es.typed-array.find'); 105629 _dereq_('core-js/modules/es.typed-array.find-index'); 105630 _dereq_('core-js/modules/es.typed-array.for-each'); 105631 _dereq_('core-js/modules/es.typed-array.includes'); 105632 _dereq_('core-js/modules/es.typed-array.index-of'); 105633 _dereq_('core-js/modules/es.typed-array.iterator'); 105634 _dereq_('core-js/modules/es.typed-array.join'); 105635 _dereq_('core-js/modules/es.typed-array.last-index-of'); 105636 _dereq_('core-js/modules/es.typed-array.map'); 105637 _dereq_('core-js/modules/es.typed-array.reduce'); 105638 _dereq_('core-js/modules/es.typed-array.reduce-right'); 105639 _dereq_('core-js/modules/es.typed-array.reverse'); 105640 _dereq_('core-js/modules/es.typed-array.set'); 105641 _dereq_('core-js/modules/es.typed-array.slice'); 105642 _dereq_('core-js/modules/es.typed-array.some'); 105643 _dereq_('core-js/modules/es.typed-array.sort'); 105644 _dereq_('core-js/modules/es.typed-array.subarray'); 105645 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 105646 _dereq_('core-js/modules/es.typed-array.to-string'); 105647 _dereq_('core-js/modules/es.weak-map'); 105648 _dereq_('core-js/modules/web.dom-collections.iterator'); 105649 function _typeof2(obj) { 105650 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 105651 _typeof2 = function _typeof2(obj) { 105652 return typeof obj; 105653 }; 105654 } else { 105655 _typeof2 = function _typeof2(obj) { 105656 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 105657 }; 105658 } 105659 return _typeof2(obj); 105660 } 105661 function _typeof(obj) { 105662 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 105663 _typeof = function _typeof(obj) { 105664 return _typeof2(obj); 105665 }; 105666 } else { 105667 _typeof = function _typeof(obj) { 105668 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _t
105668ypeof2(obj); 105669 }; 105670 } 105671 return _typeof(obj); 105672 } 105673 _dereq_('core-js/modules/es.array.iterator'); 105674 _dereq_('core-js/modules/es.object.to-string'); 105675 _dereq_('core-js/modules/es.typed-array.uint8-array'); 105676 _dereq_('core-js/modules/es.typed-array.copy-within'); 105677 _dereq_('core-js/modules/es.typed-array.every'); 105678 _dereq_('core-js/modules/es.typed-array.fill'); 105679 _dereq_('core-js/modules/es.typed-array.filter'); 105680 _dereq_('core-js/modules/es.typed-array.find'); 105681 _dereq_('core-js/modules/es.typed-array.find-index'); 105682 _dereq_('core-js/modules/es.typed-array.for-each'); 105683 _dereq_('core-js/modules/es.typed-array.includes'); 105684 _dereq_('core-js/modules/es.typed-array.index-of'); 105685 _dereq_('core-js/modules/es.typed-array.iterator'); 105686 _dereq_('core-js/modules/es.typed-array.join'); 105687 _dereq_('core-js/modules/es.typed-array.last-index-of'); 105688 _dereq_('core-js/modules/es.typed-array.map'); 105689 _dereq_('core-js/modules/es.typed-array.reduce'); 105690 _dereq_('core-js/modules/es.typed-array.reduce-right'); 105691 _dereq_('core-js/modules/es.typed-array.reverse'); 105692 _dereq_('core-js/modules/es.typed-array.set'); 105693 _dereq_('core-js/modules/es.typed-array.slice'); 105694 _dereq_('core-js/modules/es.typed-array.some'); 105695 _dereq_('core-js/modules/es.typed-array.sort'); 105696 _dereq_('core-js/modules/es.typed-array.subarray'); 105697 _dereq_('core-js/modules/es.typed-array.to-locale-string'); 105698 _dereq_('core-js/modules/es.typed-array.to-string'); 105699 Object.defineProperty(exports, '__esModule', { 105700 value: true 105701 }); 105702 exports.default = void 0; 105703 var _main = _interopRequireDefault(_dereq_('../core/main')); 105704 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 105705 function _getRequireWildcardCache() { 105706 if (typeof WeakMap !== 'function') return null; 105707 var cache = new WeakMap(); 105708 _getRequireWildcardCache = function _getRequireWildcardCache() { 105709 return cache; 105710 }; 105711 return cache; 105712 } 105713 function _interopRequireWildcard(obj) { 105714 if (obj && obj.__esModule) { 105715 return obj; 105716 } 105717 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 105718 return { 105719 default: 105720 obj 105721 }; 105722 } 105723 var cache = _getRequireWildcardCache(); 105724 if (cache && cache.has(obj)) { 105725 return cache.get(obj); 105726 } 105727 var newObj = { 105728 }; 105729 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 105730 for (var key in obj) { 105731 if (Object.prototype.hasOwnProperty.call(obj, key)) { 105732 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 105733 if (desc && (desc.get || desc.set)) { 105734 Object.defineProperty(newObj, key, desc); 105735 } else { 105736 newObj[key] = obj[key]; 105737 } 105738 } 105739 } 105740 newObj.default = obj; 105741 if (cache) { 105742 cache.set(obj, newObj); 105743 } 105744 return newObj; 105745 } 105746 function _interopRequireDefault(obj) { 105747 return obj && obj.__esModule ? obj : { 105748 default: 105749 obj 105750 }; 105751 } /** 105752 * This module defines the p5.Texture class 105753 * @module 3D 105754 * @submodule Material 105755 * @for p5 105756 * @requires core 105757 */ 105758 /** 105759 * Texture class for WEBGL Mode 105760 * @private 105761 * @class p5.Texture 105762 * @param {p5.RendererGL} renderer an instance of p5.RendererGL that 105763 * will provide the GL context for this new p5.Texture 105764 * @param {p5.Image|p5.Graphics|p5.Element|p5.MediaElement|ImageData} [obj] the
105765 * object containing the image data to store in the texture. 105766 * @param {Object} [settings] optional A javascript object containing texture 105767 * settings. 105768 * @param {Number} [settings.format] optional The internal color component 105769 * format for the texture. Possible values for format include gl.RGBA, 105770 * gl.RGB, gl.ALPHA, gl.LUMINANCE, gl.LUMINANCE_ALPHA. Defaults to gl.RBGA 105771 * @param {Number} [settings.minFilter] optional The texture minification 105772 * filter setting. Possible values are gl.NEAREST or gl.LINEAR. Defaults 105773 * to gl.LINEAR. Note, Mipmaps are not implemented in p5. 105774 * @param {Number} [settings.magFilter] optional The texture magnification 105775 * filter setting. Possible values are gl.NEAREST or gl.LINEAR. Defaults 105776 * to gl.LINEAR. Note, Mipmaps are not implemented in p5. 105777 * @param {Number} [settings.wrapS] optional The texture wrap settings for 105778 * the s coordinate, or x axis. Possible values are gl.CLAMP_TO_EDGE, 105779 * gl.REPEAT, and gl.MIRRORED_REPEAT. The mirror settings are only available 105780 * when using a power of two sized texture. Defaults to gl.CLAMP_TO_EDGE 105781 * @param {Number} [settings.wrapT] optional The texture wrap settings for 105782 * the t coordinate, or y axis. Possible values are gl.CLAMP_TO_EDGE, 105783 * gl.REPEAT, and gl.MIRRORED_REPEAT. The mirror settings are only available 105784 * when using a power of two sized texture. Defaults to gl.CLAMP_TO_EDGE 105785 * @param {Number} [settings.dataType] optional The data type of the texel 105786 * data. Possible values are gl.UNSIGNED_BYTE or gl.FLOAT. There are more 105787 * formats that are not implemented in p5. Defaults to gl.UNSIGNED_BYTE. 105788 */ 105789 105790 _main.default.Texture = function (renderer, obj, settings) { 105791 this._renderer = renderer; 105792 var gl = this._renderer.GL; 105793 settings = settings || { 105794 }; 105795 if (settings.dataType === gl.FLOAT) { 105796 var ext = gl.getExtension('OES_texture_float'); 105797 if (!ext) { 105798 console.log('Oh no, your device doesn\'t support floating point textures!'); 105799 } 105800 var linear = gl.getExtension('OES_texture_float_linear'); 105801 if (!linear) { 105802 console.log('Ack! Your device doesn\'t support linear filtering for floating point textures'); 105803 } 105804 } 105805 this.src = obj; 105806 this.glTex = undefined; 105807 this.glTarget = gl.TEXTURE_2D; 105808 this.glFormat = settings.format || gl.RGBA; 105809 this.mipmaps = false; 105810 this.glMinFilter = settings.minFilter || gl.LINEAR; 105811 this.glMagFilter = settings.magFilter || gl.LINEAR; 105812 this.glWrapS = settings.wrapS || gl.CLAMP_TO_EDGE; 105813 this.glWrapT = settings.wrapT || gl.CLAMP_TO_EDGE; 105814 this.glDataType = settings.dataType || gl.UNSIGNED_BYTE; // used to determine if this texture might need constant updating 105815 // because it is a video or gif. 105816 this.isSrcMediaElement = typeof _main.default.MediaElement !== 'undefined' && obj instanceof _main.default.MediaElement; 105817 this._videoPrevUpdateTime = 0; 105818 this.isSrcHTMLElement = typeof _main.default.Element !== 'undefined' && obj instanceof _main.default.Element && !(obj instanceof _main.default.Graphics) && !(obj instanceof _main.default.Renderer); 105819 this.isSrcP5Image = obj instanceof _main.default.Image; 105820 this.isSrcP5Graphics = obj instanceof _main.default.Graphics; 105821 this.isSrcP5Renderer = obj instanceof _main.default.Renderer; 105822 this.isImageData = typeof ImageData !== 'undefined' && obj instanceof ImageData; 105823 var textureData = this._getTextureDataFromSource(); 105824 this.width = textureData.width; 105825 this.height = textureData.height; 105826 this.init(textureData); 105827 return this; 105828 }; 105829 _main.default.Texture.prototype._getTextureDataFromSource = function () { 105830 var textureData; 105831 if (this.isSrcP5Image) { 105832 // param is a p5.Image 105833 textureData = this.src.canvas; 105834 } else if (this.isSrcMediaElement || this.isSrcP5Graphics || this.isSrcP5Renderer || this.isSrcHTMLElement) { 105835 // if param is a video HTML element 105836 textureData = this.src.elt; 105837 } else if (this.isImageData) { 105838 textureData = this.src; 105839 } 105840 return textureData; 105841 }; 105842 /** 105843 * Initializes common texture parameters, creates a gl texture, 105844 * tries to upload the texture for the first time if data is 105845 * already available. 105846 * @private 105847 * @method init 105848 */ 105849 _main.default.Texture.prototype.init = function (data) { 105850 var gl = this._renderer.GL; 105851 this.glTex = gl.createTexture(); 105852 this.glWrapS = this._renderer.textureWrapX; 105853 this.glWrapT = this._renderer.textureWrapY; 105854 this.setWrapMode(this.glWrapS, this.glWrapT); 105855 this.bindTexture(); //gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); 105856 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter); 105857 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter); 105858 if (this.width === 0 || this.height === 0 || this.isSrcMediaElement && !this.src.loadedmetadata) { 105859 // assign a 1Ã1 empty texture initially, because data is not yet ready, 105860 // so that no errors occur in gl console! 105861 var tmpdata = new Uint8Array([1, 105862 1, 105863 1, 105864 1]); 105865 gl.texImage2D(this.glTarget, 0, gl.RGBA, 1, 1, 0, this.glFormat, this.glDataType, tmpdata); 105866 } else { 105867 // data is ready: just push the texture! 105868 gl.texImage2D(this.glTarget, 0, this.glFormat, this.glFormat, this.glDataType, data); 105869 } 105870 }; 105871 /** 105872 * Checks if the source data for this texture has changed (if it's 105873 * easy to do so) and reuploads the texture if necessary. If it's not 105874 * possible or to expensive to do a calculation to determine wheter or 105875 * not the data has occurred, this method simply re-uploads the texture. 105876 * @method update 105877 */ 105878 _main.default.Texture.prototype.update = function () { 105879 var data = this.src; 105880 if (data.width === 0 || data.height === 0) { 105881 return false; // nothing to do! 105882 } 105883 var textureData = this._getTextureDataFromSource(); 105884 var updated = false;
105885 var gl = this._renderer.GL; // pull texture from data, make sure width & height are appropriate 105886 if (textureData.width !== this.width || textureData.height !== this.height) { 105887 updated = true; // make sure that if the width and height of this.src have changed 105888 // for some reason, we update our metadata and upload the texture again 105889 this.width = textureData.width; 105890 this.height = textureData.height; 105891 if (this.isSrcP5Image) { 105892 data.setModified(false); 105893 } else if (this.isSrcMediaElement || this.isSrcHTMLElement) { 105894 // on the first frame the metadata comes in, the size will be changed 105895 // from 0 to actual size, but pixels may not be available. 105896 // flag for update in a future frame. 105897 // if we don't do this, a paused video, for example, may not 105898 // send the first frame to texture memory. 105899 data.setModified(true); 105900 } 105901 } else if (this.isSrcP5Image) { 105902 // for an image, we only update if the modified field has been set, 105903 // for example, by a call to p5.Image.set 105904 if (data.isModified()) { 105905 updated = true; 105906 data.setModified(false); 105907 } 105908 } else if (this.isSrcMediaElement) { 105909 // for a media element (video), we'll check if the current time in 105910 // the video frame matches the last time. if it doesn't match, the 105911 // video has advanced or otherwise been taken to a new frame, 105912 // and we need to upload it. 105913 if (data.isModified()) { 105914 // p5.MediaElement may have also had set/updatePixels, etc. called 105915 // on it and should be updated, or may have been set for the first 105916 // time! 105917 updated = true; 105918 data.setModified(false); 105919 } else if (data.loadedmetadata) { 105920 // if the meta data has been loaded, we can ask the video 105921 // what it's current position (in time) is. 105922 if (this._videoPrevUpdateTime !== data.time()) { 105923 // update the texture in gpu mem only if the current 105924 // video timestamp does not match the timestamp of the last 105925 // time we uploaded this texture (and update the time we 105926 // last uploaded, too) 105927 this._videoPrevUpdateTime = data.time(); 105928 updated = true; 105929 } 105930 } 105931 } else if (this.isImageData) { 105932 if (data._dirty) { 105933 data._dirty = false; 105934 updated = true; 105935 } 105936 } else { 105937 /* data instanceof p5.Graphics, probably */ 105938 // there is not enough information to tell if the texture can be 105939 // conditionally updated; so to be safe, we just go ahead and upload it. 105940 updated = true; 105941 } 105942 if (updated) { 105943 this.bindTexture(); 105944 gl.texImage2D(this.glTarget, 0, this.glFormat, this.glFormat, this.glDataType, textureData); 105945 } 105946 return updated; 105947 }; 105948 /** 105949 * Binds the texture to the appropriate GL target. 105950 * @method bindTexture 105951 */ 105952 _main.default.Texture.prototype.bindTexture = function () { 105953 // bind texture using gl context + glTarget and 105954 // generated gl texture object 105955 var gl = this._renderer.GL; 105956 gl.bindTexture(this.glTarget, this.glTex); 105957 return this; 105958 }; 105959 /** 105960 * Unbinds the texture from the appropriate GL target. 105961 * @method unbindTexture 105962 */ 105963 _main.default.Texture.prototype.unbindTexture = function () { 105964 // unbind per above, disable texturing on glTarget 105965 var gl = this._renderer.GL; 105966 gl.bindTexture(this.glTarget, null); 105967 }; 105968 /**
105969 * Sets how a texture is be interpolated when upscaled or downscaled. 105970 * Nearest filtering uses nearest neighbor scaling when interpolating 105971 * Linear filtering uses WebGL's linear scaling when interpolating 105972 * @method setInterpolation 105973 * @param {String} downScale Specifies the texture filtering when 105974 * textures are shrunk. Options are LINEAR or NEAREST 105975 * @param {String} upScale Specifies the texture filtering when 105976 * textures are magnified. Options are LINEAR or NEAREST 105977 * @todo implement mipmapping filters 105978 */ 105979 _main.default.Texture.prototype.setInterpolation = function (downScale, upScale) { 105980 var gl = this._renderer.GL; 105981 if (downScale === constants.NEAREST) { 105982 this.glMinFilter = gl.NEAREST; 105983 } else { 105984 this.glMinFilter = gl.LINEAR; 105985 } 105986 if (upScale === constants.NEAREST) { 105987 this.glMagFilter = gl.NEAREST; 105988 } else { 105989 this.glMagFilter = gl.LINEAR; 105990 } 105991 this.bindTexture(); 105992 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter); 105993 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter); 105994 this.unbindTexture(); 105995 }; 105996 /** 105997 * Sets the texture wrapping mode. This controls how textures behave 105998 * when their uv's go outside of the 0 - 1 range. There are three options: 105999 * CLAMP, REPEAT, and MIRROR. REPEAT & MIRROR are only available if the texture 106000 * is a power of two size (128, 256, 512, 1024, etc.). 106001 * @method setWrapMode 106002 * @param {String} wrapX Controls the horizontal texture wrapping behavior 106003 * @param {String} wrapY Controls the vertical texture wrapping behavior 106004 */ 106005 _main.default.Texture.prototype.setWrapMode = function (wrapX, wrapY) { 106006 var gl = this._renderer.GL; // for webgl 1 we need to check if the texture is power of two 106007 // if it isn't we will set the wrap mode to CLAMP 106008 // webgl2 will support npot REPEAT and MIRROR but we don't check for it yet 106009 var isPowerOfTwo = function isPowerOfTwo(x) { 106010 return (x & x - 1) === 0; 106011 }; 106012 var textureData = this._getTextureDataFromSource(); 106013 var wrapWidth; 106014 var wrapHeight; 106015 if (textureData.naturalWidth && textureData.naturalHeight) { 106016 wrapWidth = textureData.naturalWidth; 106017 wrapHeight = textureData.naturalHeight; 106018 } else { 106019 wrapWidth = this.width; 106020 wrapHeight = this.height; 106021 } 106022 var widthPowerOfTwo = isPowerOfTwo(wrapWidth); 106023 var heightPowerOfTwo = isPowerOfTwo(wrapHeight); 106024 if (wrapX === constants.REPEAT) { 106025 if (widthPowerOfTwo && heightPowerOfTwo) { 106026 this.glWrapS = gl.REPEAT; 106027 } else { 106028 console.warn('You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'); 106029 this.glWrapS = gl.CLAMP_TO_EDGE; 106030 } 106031 } else if (wrapX === constants.MIRROR) { 106032 if (widthPowerOfTwo && heightPowerOfTwo) { 106033 this.glWrapS = gl.MIRRORED_REPEAT; 106034 } else { 106035 console.warn('You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'); 106036 this.glWrapS = gl.CLAMP_TO_EDGE; 106037 } 106038 } else { 106039 // falling back to default if didn't get a proper mode 106040 this.glWrapS = gl.CLAMP_TO_EDGE; 106041 } 106042 if (wrapY === constants.REPEAT) { 106043 if (widthPowerOfTwo && heightPowerOfTwo) { 106044 this.glWrapT = gl.REPEAT; 106045 } else { 106046 console.warn('You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'); 106047 this.glWrapT = gl.CLAMP_TO_EDGE; 106048 } 106049 } else if (wrapY === constants.MIRROR) { 106050 if (widthPowerOfTwo && heightPowerOfTwo) { 106051 this.glWrapT = gl.MIRRORED_REPEAT; 106052 } else { 106053 console.warn('You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'); 106054 this.glWrapT = gl.CLAMP_TO_EDGE; 106055 } 106056 } else { 106057 // falling back to default if didn't get a proper mode 106058 this.glWrapT = gl.CLAMP_TO_EDGE; 106059 } 106060 this.bindTexture(); 106061 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.glWrapS); 106062 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.glWrapT); 106063 this.unbindTexture(); 106064 }; 106065 var _default = _main.default.Texture; 106066 exports.default = _default; 106067 }, 106068 { 106069 '../core/constants': 278, 106070 '../core/main': 290, 106071 'core-js/modules/es.array.iterator': 176, 106072 'core-js/modules/es.object.get-own-property-descriptor': 191, 106073 'core-js/modules/es.object.to-string': 195, 106074 'core-js/modules/es.string.iterator': 204, 106075 'core-js/modules/es.symbol': 214, 106076 'core-js/modules/es.symbol.description': 212, 106077 'core-js/modules/es.symbol.iterator': 213, 106078 'core-js/modules/es.typed-array.copy-within': 215, 106079 'core-js/modules/es.typed-array.every': 216, 106080 'core-js/modules/es.typed-array.fill': 217, 106081 'core-js/modules/es.typed-array.filter': 218, 106082 'core-js/modules/es.typed-array.find': 220, 106083 'core-js/modules/es.typed-array.find-index': 219, 106084 'core-js/modules/es.typed-array.for-each': 223, 106085 'core-js/modules/es.typed-array.includes': 224, 106086 'core-js/modules/es.typed-array.index-of': 225, 106087 'core-js/modules/es.typed-array.iterator': 228, 106088 'core-js/modules/es.typed-array.join': 229, 106089 'core-js/modules/es.typed-array.last-index-of': 230, 106090 'core-js/modules/es.typed-array.map': 231, 106091 'core-js/modules/es.typed-array.reduce': 233, 106092 'core-js/modules/es.typed-array.reduce-right': 232, 106093 'core-js/modules/es.typed-array.reverse': 234, 106094 'core-js/modules/es.typed-array.set': 235, 106095 'core-js/modules/es.typed-array.slice': 236, 106096 'core-js/modules/es.typed-array.some': 237, 106097 'core-js/modules/es.typed-array.sort': 238, 106098 'core-js/modules/es.typed-array.subarray': 239, 106099 'core-js/modules/es.typed-array.to-locale-string': 240, 106100 'core-js/modules/es.typed-array.to-string': 241, 106101 'core-js/modules/es.typed-array.uint8-array': 244, 106102 'core-js/modules/es.weak-map': 246, 106103 'core-js/modules/web.dom-collections.iterator': 248 106104 } 106105 ], 106106 347: [
106107 function (_dereq_, module, exports) { 106108 'use strict'; 106109 _dereq_('core-js/modules/es.symbol'); 106110 _dereq_('core-js/modules/es.symbol.description'); 106111 _dereq_('core-js/modules/es.symbol.iterator'); 106112 _dereq_('core-js/modules/es.array.iterator'); 106113 _dereq_('core-js/modules/es.object.get-own-property-descriptor'); 106114 _dereq_('core-js/modules/es.object.to-string'); 106115 _dereq_('core-js/modules/es.regexp.exec'); 106116 _dereq_('core-js/modules/es.string.iterator'); 106117 _dereq_('core-js/modules/es.string.split'); 106118 _dereq_('core-js/modules/es.string.sub'); 106119 _dereq_('core-js/modules/es.weak-map'); 106120 _dereq_('core-js/modules/web.dom-collections.iterator'); 106121 function _typeof2(obj) { 106122 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { 106123 _typeof2 = function _typeof2(obj) { 106124 return typeof obj; 106125 }; 106126 } else { 106127 _typeof2 = function _typeof2(obj) { 106128 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; 106129 }; 106130 } 106131 return _typeof2(obj); 106132 } 106133 function _typeof(obj) { 106134 if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { 106135 _typeof = function _typeof(obj) { 106136 return _typeof2(obj); 106137 }; 106138 } else { 106139 _typeof = function _typeof(obj) { 106140 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : _typeof2(obj); 106141 }; 106142 } 106143 return _typeof(obj); 106144 } 106145 _dereq_('core-js/modules/es.symbol'); 106146 _dereq_('core-js/modules/es.symbol.description'); 106147 _dereq_('core-js/modules/es.symbol.iterator'); 106148 _dereq_('core-js/modules/es.array.iterator'); 106149 _dereq_('core-js/modules/es.object.to-string'); 106150 _dereq_('core-js/modules/es.regexp.exec'); 106151 _dereq_('core-js/modules/es.string.iterator'); 106152 _dereq_('core-js/modules/es.string.split'); 106153 _dereq_('core-js/modules/es.string.sub'); 106154 _dereq_('core-js/modules/web.dom-collections.iterator'); 106155 var _main = _interopRequireDefault(_dereq_('../core/main')); 106156 var constants = _interopRequireWildcard(_dereq_('../core/constants')); 106157 _dereq_('./p5.Shader'); 106158 _dereq_('./p5.RendererGL.Retained'); 106159 function _getRequireWildcardCache() { 106160 if (typeof WeakMap !== 'function') return null; 106161 var cache = new WeakMap(); 106162 _getRequireWildcardCache = function _getRequireWildcardCache() { 106163 return cache; 106164 }; 106165 return cache; 106166 } 106167 function _interopRequireWildcard(obj) { 106168 if (obj && obj.__esModule) { 106169 return obj; 106170 } 106171 if (obj === null || _typeof(obj) !== 'object' && typeof obj !== 'function') { 106172 return { 106173 default: 106174 obj 106175 }; 106176 } 106177 var cache = _getRequireWildcardCache(); 106178 if (cache && cache.has(obj)) { 106179 return cache.get(obj); 106180 } 106181 var newObj = { 106182 }; 106183 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 106184 for (var key in obj) { 106185 if (Object.prototype.hasOwnProperty.call(obj, key)) { 106186 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 106187 if (desc && (desc.get || desc.set)) { 106188 Object.defineProperty(newObj, key, desc); 106189 } else { 106190 newObj[key] = obj[key]; 106191 } 106192 } 106193 } 106194 newObj.default = obj; 106195 if (cache) { 106196 cache.set(obj, newObj); 106197 } 106198 return newObj; 106199 } 106200 function _interopRequireDefault(obj) { 106201 return obj && obj.__esModule ? obj : { 106202 default: 106203 obj 106204 }; 106205 } // Text/Typography 106206 // @TODO: 106207 106208 _main.default.RendererGL.prototype._applyTextProperties = function () { //@TODO finish implementation 106209 //console.error('text commands not yet implemented in webgl'); 106210 }; 106211 _main.default.RendererGL.prototype.textWidth = function (s) { 106212 if (this._isOpenType()) { 106213 return this._textFont._textWidth(s, this._textSize); 106214 } 106215 return 0; // TODO: error 106216 }; // rendering constants 106217 // the number of rows/columns dividing each glyph 106218 var charGridWidth = 9; 106219 var charGridHeight = charGridWidth; // size of the image holding the bezier stroke info 106220 var strokeImageWidth = 64; 106221 var strokeImageHeight = 64; // size of the image holding the stroke indices for each row/col 106222 var gridImageWidth = 64; 106223 var gridImageHeight = 64; // size of the image holding the offset/length of each row/col stripe 106224 var cellImageWidth = 64; 106225 var cellImageHeight = 64; 106226 /** 106227 * @private 106228 * @class ImageInfos 106229 * @param {Integer} width 106230 * @param {Integer} height 106231 * 106232 * the ImageInfos class holds a list of ImageDatas of a given size. 106233 */ 106234 function ImageInfos(width, height) { 106235 this.width = width; 106236 this.height = height; 106237 this.infos = [ 106238 ]; // the list of images 106239 /** 106240 * 106241 * @method findImage 106242 * @param {Integer} space 106243 * @return {Object} contains the ImageData, and pixel index into that 106244 * ImageData where the free space was allocated. 106245 * 106246 * finds free space of a given size in the ImageData list 106247 */ 106248 this.findImage = function (space) { 106249 var imageSize = this.width * this.height; 106250 if (space > imageSize) throw new Error('font is too complex to render in 3D'); // search through the list of images, looking for one with 106251 // anough unused space. 106252 var imageInfo, 106253 imageData; 106254 for (var ii = this.infos.length - 1; ii >= 0; --ii) { 106255 var imageInfoTest = this.infos[ii]; 106256 if (imageInfoTest.index + space < imageSize) { 106257 // found one 106258 imageInfo = imageInfoTest; 106259 imageData = imageInfoTest.imageData; 106260 break; 106261 } 106262 } 106263 if (!imageInfo) { 106264 try { 106265 // create a new image 106266 imageData = new ImageData(this.width, this.height); 106267 } catch (err) { 106268 // for browsers that don't support ImageData constructors (ie IE11) 106269 // create an ImageData using the old method 106270 var canvas = document.getElementsByTagName('canvas') [0]; 106271 var created = !canvas; 106272 if (!canvas) { 106273 // create a temporary canvas 106274 canvas = document.createElement('canvas'); 106275 canvas.style.display = 'none'; 106276 document.body.appendChild(canvas); 106277 } 106278 var ctx = canvas.getContext('2d'); 106279 if (ctx) { 106280 imageData = ctx.createImageData(this.width, this.height); 106281 } 106282 if (created) { 106283 // distroy the temporary canvas, if necessary 106284 document.body.removeChild(canvas); 106285 } 106286 } // construct & dd the new image info 106287 106288 imageInfo = { 106289 index: 0, 106290 imageData: imageData 106291 }; 106292 this.infos.push(imageInfo); 106293 } 106294 var index = imageInfo.index; 106295 imageInfo.index += space; // move to the start of the next image 106296 imageData._dirty = true; 106297 return { 106298 imageData: imageData, 106299 index: index 106300 }; 106301 }; 106302 } /** 106303 * @function setPixel 106304 * @param {Object} imageInfo 106305 * @param {Number} r 106306 * @param {Number} g 106307 * @param {Number} b 106308 * @param {Number} a 106309 * 106310 * writes the next pixel into an indexed ImageData 106311 */ 106312 106313 function setPixel(imageInfo, r, g, b, a) { 106314 var imageData = imageInfo.imageData; 106315 var pixels = imageData.data; 106316 var index = imageInfo.index++ * 4; 106317 pixels[index++] = r; 106318 pixels[index++] = g; 106319 pixels[index++] = b; 106320 pixels[index++] = a; 106321 } 106322 var SQRT3 = Math.sqrt(3); 106323 /** 106324 * @private 106325 * @class FontInfo 106326 * @param {Object} font an opentype.js font object 106327 * 106328 * contains cached images and glyph information for an opentype font 106329 */ 106330 var FontInfo = function FontInfo(font) { 106331 this.font = font; // the bezier curve coordinates 106332 this.strokeImageInfos = new ImageInfos(strokeImageWidth, strokeImageHeight); // lists of curve indices for each row/column slice 106333 this.colDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight); 106334 this.rowDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight); // the offset & length of each row/col slice in the glyph 106335 this.colCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight); 106336 this.rowCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight); // the cached information for each glyph 106337 this.glyphInfos = { 106338 }; 106339 /** 106340 * @method getGlyphInfo 106341 * @param {Glyph} glyph the x positions of points in the curve 106342 * @returns {Object} the glyphInfo for that glyph 106343 * 106344 * calculates rendering info for a glyph, including the curve information, 106345 * row & column stripes compiled into textures. 106346 */ 106347 this.getGlyphInfo = function (glyph) { 106348 // check the cache 106349 var gi = this.glyphInfos[glyph.index]; 106350 if (gi) return gi; // get the bounding box of the glyph from opentype.js 106351 var bb = glyph.getBoundingBox(); 106352 var xMin = bb.x1; 106353 var yMin = bb.y1; 106354 var gWidth = bb.x2 - xMin; 106355 var gHeight = bb.y2 - yMin; 106356 var cmds = glyph.path.commands; // don't bother rendering invisible glyphs 106357 if (gWidth === 0 || gHeight === 0 || !cmds.length) { 106358 return this.glyphInfos[glyph.index] = { 106359 }; 106360 } 106361 var i; 106362 var strokes = [ 106363 ]; // the strokes in this glyph 106364 var rows = [ 106365 ]; // the indices of strokes in each row 106366 var cols = [ 106367 ]; // the indices of strokes in each column 106368 for (i = charGridWidth - 1; i >= 0; --i) { 106369 cols.push([]); 106370 } 106371 for (i = charGridHeight - 1; i >= 0; --i) { 106372 rows.push([]); 106373 } /** 106374 * @function push 106375 * @param {Number[]} xs the x positions of points in the curve 106376 * @param {Number[]} ys the y positions of points in the curve 106377 * @param {Object} v the curve information 106378 * 106379 * adds a curve to the rows & columns that it intersects with 106380 */ 106381 106382 function push(xs, ys, v) { 106383 var index = strokes.length; // the index of this stroke 106384 strokes.push(v);
106384 // add this stroke to the list 106385 /** 106386 * @function minMax 106387 * @param {Number[]} rg the list of values to compare 106388 * @param {Number} min the initial minimum value 106389 * @param {Number} max the initial maximum value 106390 * 106391 * find the minimum & maximum value in a list of values 106392 */ 106393 function minMax(rg, min, max) { 106394 for (var _i = rg.length; _i-- > 0; ) { 106395 var _v = rg[_i]; 106396 if (min > _v) min = _v; 106397 if (max < _v) max = _v; 106398 } 106399 return { 106400 min: min, 106401 max: max 106402 }; 106403 } // Expand the bounding box of the glyph by the number of cells below 106404 // before rounding. Curves only partially through a cell won't be added 106405 // to adjacent cells, but ones that are close will be. This helps fix 106406 // small visual glitches that occur when curves are close to grid cell 106407 // boundaries. 106408 106409 var cellOffset = 0.5; // loop through the rows & columns that the curve intersects 106410 // adding the curve to those slices 106411 var mmX = minMax(xs, 1, 0); 106412 var ixMin = Math.max(Math.floor(mmX.min * charGridWidth - cellOffset), 0); 106413 var ixMax = Math.min(Math.ceil(mmX.max * charGridWidth + cellOffset), charGridWidth); 106414 for (var iCol = ixMin; iCol < ixMax; ++iCol) { 106415 cols[iCol].push(index); 106416 } 106417 var mmY = minMax(ys, 1, 0); 106418 var iyMin = Math.max(Math.floor(mmY.min * charGridHeight - cellOffset), 0); 106419 var iyMax = Math.min(Math.ceil(mmY.max * charGridHeight + cellOffset), charGridHeight); 106420 for (var iRow = iyMin; iRow < iyMax; ++iRow) { 106421 rows[iRow].push(index); 106422 } 106423 } /** 106424 * @function clamp 106425 * @param {Number} v the value to clamp 106426 * @param {Number} min the minimum value 106427 * @param {Number} max the maxmimum value 106428 * 106429 * clamps a value between a minimum & maximum value 106430 */ 106431 106432 function clamp(v, min, max) { 106433 if (v < min) return min; 106434 if (v > max) return max; 106435 return v; 106436 } /** 106437 * @function byte 106438 * @param {Number} v the value to scale 106439 * 106440 * converts a floating-point number in the range 0-1 to a byte 0-255 106441 */ 106442 106443 function byte(v) { 106444 return clamp(255 * v, 0, 255); 106445 } /** 106446 * @private 106447 * @class Cubic 106448 * @param {Number} p0 the start point of the curve 106449 * @param {Number} c0 the first control point 106450 * @param {Number} c1 the second control point 106451 * @param {Number} p1 the end point 106452 * 106453 * a cubic curve 106454 */ 106455 106456 function Cubic(p0, c0, c1, p1) { 106457 this.p0 = p0; 106458 this.c0 = c0; 106459 this.c1 = c1; 106460 this.p1 = p1; 106461 /** 106462 * @method toQuadratic 106463 * @return {Object} the quadratic approximation 106464 * 106465 * converts the cubic to a quadtratic approximation by 106466 * picking an appropriate quadratic control point 106467 */ 106468 this.toQuadratic = function () { 106469 return { 106470 x: this.p0.x, 106471 y: this.p0.y, 106472 x1: this.p1.x, 106473 y1: this.p1.y, 106474 cx: ((this.c0.x + this.c1.x) * 3 - (this.p0.x + this.p1.x)) / 4, 106475 cy: ((this.c0.y + this.c1.y) * 3 - (this.p0.y + this.p1.y)) / 4 106476 }; 106477 }; 106478 /** 106479 * @method quadError 106480 * @return {Number} the error 106481 * 106482 * calculates the magnitude of error of this curve's 106483 * quadratic approximation. 106484 */ 106485 this.quadError = function () { 106486 return _main.default.Vector.sub(_main.default.Vector.sub(this.p1, this.p0), _main.default.Vector.mult(_main.default.Vector.sub(this.c1, this.c0), 3)).mag() / 2; 106487 }; 106488 /** 106489 * @method split 106490 * @param {Number} t the value (0-1) at which to split 106491 * @return {Cubic} the second part of the curve 106492 * 106493 * splits the cubic into two parts at a point 't' along the curve. 106494 * this cubic keeps its start point and its end point becomes the 106495 * point at 't'. the 'end half is returned. 106496 */ 106497 this.split = function (t) { 106498 var m1 = _main.default.Vector.lerp(this.p0, this.c0, t); 106499 var m2 = _main.default.Vector.lerp(this.c0, this.c1, t); 106500 var mm1 = _main.default.Vector.lerp(m1, m2, t);
106501 this.c1 = _main.default.Vector.lerp(this.c1, this.p1, t); 106502 this.c0 = _main.default.Vector.lerp(m2, this.c1, t); 106503 var pt = _main.default.Vector.lerp(mm1, this.c0, t); 106504 var part1 = new Cubic(this.p0, m1, mm1, pt); 106505 this.p0 = pt; 106506 return part1; 106507 }; 106508 /** 106509 * @method splitInflections 106510 * @return {Cubic[]} the non-inflecting pieces of this cubic 106511 * 106512 * returns an array containing 0, 1 or 2 cubics split resulting 106513 * from splitting this cubic at its inflection points. 106514 * this cubic is (potentially) altered and returned in the list. 106515 */ 106516 this.splitInflections = function () { 106517 var a = _main.default.Vector.sub(this.c0, this.p0); 106518 var b = _main.default.Vector.sub(_main.default.Vector.sub(this.c1, this.c0), a); 106519 var c = _main.default.Vector.sub(_main.default.Vector.sub(_main.default.Vector.sub(this.p1, this.c1), a), _main.default.Vector.mult(b, 2)); 106520 var cubics = [ 106521 ]; // find the derivative coefficients 106522 var A = b.x * c.y - b.y * c.x; 106523 if (A !== 0) { 106524 var B = a.x * c.y - a.y * c.x; 106525 var C = a.x * b.y - a.y * b.x; 106526 var disc = B * B - 4 * A * C; 106527 if (disc >= 0) { 106528 if (A < 0) { 106529 A = - A; 106530 B = - B; 106531 C = - C; 106532 } 106533 var Q = Math.sqrt(disc); 106534 var t0 = ( - B - Q) / (2 * A); // the first inflection point 106535 var t1 = ( - B + Q) / (2 * A); // the second inflection point 106536 // test if the first inflection point lies on the curve 106537 if (t0 > 0 && t0 < 1) { 106538 // split at the first inflection point 106539 cubics.push(this.split(t0)); // scale t2 into the second part 106540 t1 = 1 - (1 - t1) / (1 - t0); 106541 } // test if the second inflection point lies on the curve 106542 106543 if (t1 > 0 && t1 < 1) { 106544 // split at the second inflection point 106545 cubics.push(this.split(t1)); 106546 } 106547 } 106548 } 106549 cubics.push(this); 106550 return cubics; 106551 }; 106552 } /** 106553 * @function cubicToQuadratics 106554 * @param {Number} x0 106555 * @param {Number} y0 106556 * @param {Number} cx0 106557 * @param {Number} cy0 106558 * @param {Number} cx1 106559 * @param {Number} cy1 106560 * @param {Number} x1 106561 * @param {Number} y1 106562 * @returns {Cubic[]} an array of cubics whose quadratic approximations 106563 * closely match the civen cubic. 106564 * 106565 * converts a cubic curve to a list of quadratics. 106566 */ 106567 106568 function cubicToQuadratics(x0, y0, cx0, cy0, cx1, cy1, x1, y1) { 106569 // create the Cubic object and split it at its inflections 106570 var cubics = new Cubic(new _main.default.Vector(x0, y0), new _main.default.Vector(cx0, cy0), new _main.default.Vector(cx1, cy1), new _main.default.Vector(x1, y1)).splitInflections(); 106571 var qs = [ 106572 ]; // the final list of quadratics 106573 var precision = 30 / SQRT3; // for each of the non-inflected pieces of the original cubic 106574 var _iteratorNormalCompletion = true; 106575 var _didIteratorError = false; 106576 var _iteratorError = undefined; 106577 try { 106578 for (var _iterator = cubics[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 106579 var cubic = _step.value; // the cubic is iteratively split in 3 pieces: 106580 // the first piece is accumulated in 'qs', the result. 106581 // the last piece is accumulated in 'tail', temporarily. 106582 // the middle piece is repeatedly split again, while necessary. 106583 var tail = [ 106584 ]; 106585 var t3 = void 0; 106586 for (; ; ) { 106587 // calculate this cubic's precision 106588 t3 = precision / cubic.quadError(); 106589 if (t3 >= 0.5 * 0.5 * 0.5) { 106590 break; // not too bad, we're done 106591 } // find a split point based on the error 106592 106593 var t = Math.pow(t3, 1 / 3);
106593 // split the cubic in 3 106594 var start = cubic.split(t); 106595 var middle = cubic.split(1 - t / (1 - t)); 106596 qs.push(start); // the first part 106597 tail.push(cubic); // the last part 106598 cubic = middle; // iterate on the middle piece 106599 } 106600 if (t3 < 1) { 106601 // a little excess error, split the middle in two 106602 qs.push(cubic.split(0.5)); 106603 } // add the middle piece to the result 106604 106605 qs.push(cubic); // finally add the tail, reversed, onto the result 106606 Array.prototype.push.apply(qs, tail.reverse()); 106607 } 106608 } catch (err) { 106609 _didIteratorError = true; 106610 _iteratorError = err; 106611 } finally { 106612 try { 106613 if (!_iteratorNormalCompletion && _iterator.return != null) { 106614 _iterator.return(); 106615 } 106616 } finally { 106617 if (_didIteratorError) { 106618 throw _iteratorError; 106619 } 106620 } 106621 } 106622 return qs; 106623 } /** 106624 * @function pushLine 106625 * @param {Number} x0 106626 * @param {Number} y0 106627 * @param {Number} x1 106628 * @param {Number} y1 106629 * 106630 * add a straight line to the row/col grid of a glyph 106631 */ 106632 106633 function pushLine(x0, y0, x1, y1) { 106634 var mx = (x0 + x1) / 2; 106635 var my = (y0 + y1) / 2; 106636 push([x0, 106637 x1], [ 106638 y0, 106639 y1 106640 ], { 106641 x: x0, 106642 y: y0, 106643 cx: mx, 106644 cy: my 106645 }); 106646 } /** 106647 * @function samePoint 106648 * @param {Number} x0 106649 * @param {Number} y0 106650 * @param {Number} x1 106651 * @param {Number} y1 106652 * @return {Boolean} true if the two points are sufficiently close 106653 * 106654 * tests if two points are close enough to be considered the same 106655 */ 106656 106657 function samePoint(x0, y0, x1, y1) { 106658 return Math.abs(x1 - x0) < 0.00001 && Math.abs(y1 - y0) < 0.00001; 106659 } 106660 var x0, 106661 y0, 106662 xs, 106663 ys; 106664 var _iteratorNormalCompletion2 = true; 106665 var _didIteratorError2 = false;
106666 var _iteratorError2 = undefined; 106667 try { 106668 for (var _iterator2 = cmds[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 106669 var cmd = _step2.value; // scale the coordinates to the range 0-1 106670 var x1 = (cmd.x - xMin) / gWidth; 106671 var y1 = (cmd.y - yMin) / gHeight; // don't bother if this point is the same as the last 106672 if (samePoint(x0, y0, x1, y1)) continue; 106673 switch (cmd.type) { 106674 case 'M': 106675 { 106676 // move 106677 xs = x1; 106678 ys = y1; 106679 break; 106680 } 106681 case 'L': 106682 { 106683 // line 106684 pushLine(x0, y0, x1, y1); 106685 break; 106686 } 106687 case 'Q': 106688 { 106689 // quadratic 106690 var cx = (cmd.x1 - xMin) / gWidth; 106691 var cy = (cmd.y1 - yMin) / gHeight; 106692 push([x0, 106693 x1, 106694 cx], [ 106695 y0, 106696 y1, 106697 cy 106698 ], { 106699 x: x0, 106700 y: y0, 106701 cx: cx, 106702 cy: cy 106703 }); 106704 break; 106705 } 106706 case 'Z': 106707 { 106708 // end 106709 if (!samePoint(x0, y0, xs, ys)) { 106710 // add an extra line closing the loop, if necessary 106711 pushLine(x0, y0, xs, ys); 106712 strokes.push({ 106713 x: xs, 106714 y: ys 106715 }); 106716 } else { 106717 strokes.push({ 106718 x: x0, 106719 y: y0 106720 }); 106721 } 106722 break; 106723 } 106724 case 'C': 106725 { 106726 // cubic 106727 var cx1 = (cmd.x1 - xMin) / gWidth; 106728 var cy1 = (cmd.y1 - yMin) / gHeight; 106729 var cx2 = (cmd.x2 - xMin) / gWidth; 106730 var cy2 = (cmd.y2 - yMin) / gHeight; 106731 var qs = cubicToQuadratics(x0, y0, cx1, cy1, cx2, cy2, x1, y1); 106732 for (var iq = 0; iq < qs.length; iq++) { 106733 var q = qs[iq].toQuadratic(); 106734 push([q.x, 106735 q.x1, 106736 q.cx], [ 106737 q.y, 106738 q.y1, 106739 q.cy 106740 ], q); 106741 } 106742 break; 106743 } 106744 default: 106745 throw new Error('unknown command type: '.concat(cmd.type)); 106746 } 106747 x0 = x1; 106748 y0 = y1; 106749 } // allocate space for the strokes 106750 106751 } catch (err) { 106752 _didIteratorError2 = true; 106753 _iteratorError2 = err; 106754 } finally { 106755 try { 106756 if (!_iteratorNormalCompletion2 && _iterator2.return != null) { 106757 _iterator2.return(); 106758 } 106759 } finally { 106760 if (_didIteratorError2) { 106761 throw _iteratorError2; 106762 } 106763 } 106764 } 106765 var strokeCount = strokes.length; 106766 var strokeImageInfo = this.strokeImageInfos.findImage(strokeCount); 106767 var strokeOffset = strokeImageInfo.index; // fill the stroke image 106768 for (var il = 0; il < strokeCount; ++il) { 106769 var s = strokes[il]; 106770 setPixel(strokeImageInfo, byte(s.x), byte(s.y), byte(s.cx), byte(s.cy)); 106771 } /** 106772 * @function layout 106773 * @param {Number[][]} dim 106774 * @param {ImageInfo[]} dimImageInfos 106775 * @param {ImageInfo[]} cellImageInfos 106776 * @return {Object} 106777 * 106778 * lays out the curves in a dimension (row or col) into two 106779 * images, one for the indices of the curves themselves, and 106780 * one containing the offset and length of those index spans. 106781 */ 106782 106783 function layout(dim, dimImageInfos, cellImageInfos) { 106784 var dimLength = dim.length; // the number of slices in this dimension 106785 var dimImageInfo = dimImageInfos.findImage(dimLength); 106786 var dimOffset = dimImageInfo.index; // calculate the total number of stroke indices in this dimension 106787 var totalStrokes = 0; 106788 for (var id = 0; id < dimLength; ++id) { 106789 totalStrokes += dim[id].length; 106790 } // allocate space for the stroke indices 106791 106792 var cellImageInfo = cellImageInfos.findImage(totalStrokes); // for each slice in the glyph 106793 for (var _i2 = 0; _i2 < dimLength; ++_i2) { 106794 var strokeIndices = dim[_i2]; 106795 var _strokeCount = strokeIndices.length; 106796 var cellLineIndex = cellImageInfo.index; // write the offset and count into the glyph slice image 106797 setPixel(dimImageInfo, cellLineIndex >> 7, cellLineIndex & 127, _strokeCount >> 7, _strokeCount & 127); // for each stroke index in that slice 106798 for (var iil = 0; iil < _strokeCount; ++iil) { 106799 // write the stroke index into the slice's image 106800 var strokeIndex = strokeIndices[iil] + strokeOffset; 106801 setPixel(cellImageInfo, strokeIndex >> 7, strokeIndex & 127, 0, 0); 106802 } 106803 } 106804 return { 106805 cellImageInfo: cellImageInfo, 106806 dimOffset: dimOffset, 106807 dimImageInfo: dimImageInfo 106808 }; 106809 } // initialize the info for this glyph 106810 106811 gi = this.glyphInfos[glyph.index] = { 106812 glyph: glyph, 106813 uGlyphRect: [ 106814 bb.x1, 106815 - bb.y1, 106816 bb.x2, 106817 - bb.y2 106818 ], 106819 strokeImageInfo: strokeImageInfo, 106820 strokes: strokes, 106821 colInfo: layout(cols, this.colDimImageInfos, this.colCellImageInfos), 106822 rowInfo: layout(rows, this.rowDimImageInfos, this.rowCellImageInfos) 106823 }; 106824 gi.uGridOffset = [ 106825 gi.colInfo.dimOffset, 106826 gi.rowInfo.dimOffset 106827 ]; 106828 return gi; 106829 }; 106830 }; 106831 _main.default.RendererGL.prototype._renderText = function (p, line, x, y, maxY) { 106832 if (!this._textFont || typeof this._textFont === 'string') { 106833 console.log('WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.'); 106834 return; 106835 } 106836 if (y >= maxY || !this._doFill) { 106837 return; // don't render lines beyond our maxY position 106838 } 106839 if (!this._isOpenType()) { 106840 console.log('WEBGL: only Opentype (.otf) and Truetype (.ttf) fonts are supported'); 106841 return p; 106842 } 106843 p.push(); // fix to #803 106844 // remember this state, so it can be restored later 106845 var doStroke = this._doStroke; 106846 var drawMode = this.drawMode; 106847 this._doStroke = false;
106848 this.drawMode = constants.TEXTURE; // get the cached FontInfo object 106849 var font = this._textFont.font; 106850 var fontInfo = this._textFont._fontInfo; 106851 if (!fontInfo) { 106852 fontInfo = this._textFont._fontInfo = new FontInfo(font); 106853 } // calculate the alignment and move/scale the view accordingly 106854 106855 var pos = this._textFont._handleAlignment(this, line, x, y); 106856 var fontSize = this._textSize; 106857 var scale = fontSize / font.unitsPerEm; 106858 this.translate(pos.x, pos.y, 0); 106859 this.scale(scale, scale, 1); // initialize the font shader 106860 var gl = this.GL; 106861 var initializeShader = !this._defaultFontShader; 106862 var sh = this._getFontShader(); 106863 sh.init(); 106864 sh.bindShader(); // first time around, bind the shader fully 106865 if (initializeShader) { 106866 // these are constants, really. just initialize them one-time. 106867 sh.setUniform('uGridImageSize', [ 106868 gridImageWidth, 106869 gridImageHeight 106870 ]); 106871 sh.setUniform('uCellsImageSize', [ 106872 cellImageWidth, 106873 cellImageHeight 106874 ]); 106875 sh.setUniform('uStrokeImageSize', [ 106876 strokeImageWidth, 106877 strokeImageHeight 106878 ]); 106879 sh.setUniform('uGridSize', [ 106880 charGridWidth, 106881 charGridHeight 106882 ]); 106883 } 106884 this._applyColorBlend(this.curFillColor); 106885 var g = this.retainedMode.geometry['glyph']; 106886 if (!g) { 106887 // create the geometry for rendering a quad 106888 var geom = this._textGeom = new _main.default.Geometry(1, 1, function () { 106889 for (var i = 0; i <= 1; i++) { 106890 for (var j = 0; j <= 1; j++) { 106891 this.vertices.push(new _main.default.Vector(j, i, 0)); 106892 this.uvs.push(j, i); 106893 } 106894 } 106895 }); 106896 geom.computeFaces().computeNormals(); 106897 g = this.createBuffers('glyph', geom); 106898 } // bind the shader buffers 106899 106900 var _iteratorNormalCompletion3 = true; 106901 var _didIteratorError3 = false; 106902 var _iteratorError3 = undefined; 106903 try { 106904 for (var _iterator3 = this.retainedMode.buffers.text[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 106905 var buff = _step3.value; 106906 buff._prepareBuffer(g, sh); 106907 } 106908 } catch (err) { 106909 _didIteratorError3 = true; 106910 _iteratorError3 = err; 106911 } finally { 106912 try { 106913 if (!_iteratorNormalCompletion3 && _iterator3.return != null) { 106914 _iterator3.return(); 106915 } 106916 } finally { 106917 if (_didIteratorError3) { 106918 throw _iteratorError3; 106919 } 106920 } 106921 } 106922 this._bindBuffer(g.indexBuffer, gl.ELEMENT_ARRAY_BUFFER); // this will have to do for now... 106923 sh.setUniform('uMaterialColor', this.curFillColor); 106924 try { 106925 var dx = 0; // the x position in the line 106926 var glyphPrev = null; // the previous glyph, used for kerning 106927 // fetch the glyphs in the line of text 106928 var glyphs = font.stringToGlyphs(line); 106929 var _iteratorNormalCompletion4 = true; 106930 var _didIteratorError4 = false; 106931 var _iteratorError4 = undefined; 106932 try { 106933 for (var _iterator4 = glyphs[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { 106934 var glyph = _step4.value; // kern 106935 if (glyphPrev) dx += font.getKerningValue(glyphPrev, glyph); 106936 var gi = fontInfo.getGlyphInfo(glyph); 106937 if (gi.uGlyphRect) { 106938 var rowInfo = gi.rowInfo; 106939 var colInfo = gi.colInfo; 106940 sh.setUniform('uSamplerStrokes', gi.strokeImageInfo.imageData); 106941 sh.setUniform('uSamplerRowStrokes', rowInfo.cellImageInfo.imageData); 106942 sh.setUniform('uSamplerRows', rowInfo.dimImageInfo.imageData); 106943 sh.setUniform('uSamplerColStrokes', colInfo.cellImageInfo.imageData); 106944 sh.setUniform('uSamplerCols', colInfo.dimImageInfo.imageData); 106945 sh.setUniform('uGridOffset', gi.uGridOffset); 106946 sh.setUniform('uGlyphRect', gi.uGlyphRect); 106947 sh.setUniform('uGlyphOffset', dx); 106948 sh.bindTextures(); // afterwards, only textures need updating 106949 // draw it 106950 gl.drawElements(gl.TRIANGLES, 6, this.GL.UNSIGNED_SHORT, 0); 106951 } 106952 dx += glyph.advanceWidth; 106953 glyphPrev = glyph; 106954 } 106955 } catch (err) {
106956 _didIteratorError4 = true; 106957 _iteratorError4 = err; 106958 } finally { 106959 try { 106960 if (!_iteratorNormalCompletion4 && _iterator4.return != null) { 106961 _iterator4.return(); 106962 } 106963 } finally { 106964 if (_didIteratorError4) { 106965 throw _iteratorError4; 106966 } 106967 } 106968 } 106969 } finally { 106970 // clean up 106971 sh.unbindShader(); 106972 this._doStroke = doStroke; 106973 this.drawMode = drawMode; 106974 p.pop(); 106975 } 106976 return p; 106977 }; 106978 }, 106979 { 106980 '../core/constants': 278, 106981 '../core/main': 290, 106982 './p5.RendererGL.Retained': 343, 106983 './p5.Shader': 345, 106984 'core-js/modules/es.array.iterator': 176, 106985 'core-js/modules/es.object.get-own-property-descriptor': 191, 106986 'core-js/modules/es.object.to-string': 195, 106987 'core-js/modules/es.regexp.exec': 199, 106988 'core-js/modules/es.string.iterator': 204, 106989 'core-js/modules/es.string.split': 209, 106990 'core-js/modules/es.string.sub': 210, 106991 'core-js/modules/es.symbol': 214, 106992 'core-js/modules/es.symbol.description': 212, 106993 'core-js/modules/es.symbol.iterator': 213, 106994 'core-js/modules/es.weak-map': 246, 106995 'core-js/modules/web.dom-collections.iterator': 248 106996 } 106997 ], 106998 348: [ 106999 function (_dereq_, module, exports) { 107000 module.exports = { 107001 'fes': { 107002 'autoplay': 'The media that tried to play (with \'{{src}}\') wasn\'t allowed to by this browser, most likely due to the browser\'s autoplay policy.\n\n+ More info: {{url}}', 107003 'checkUserDefinedFns': 'It seems that you may have accidentally written {{name}} instead of {{actualName}}. Please correct it if it\'s not intentional.', 107004 'fileLoadError': { 107005 'bytes': 'It looks like there was a problem loading your file. {{suggestion}}', 107006 'font': 'It looks like there was a problem loading your font. {{suggestion}}', 107007 'gif': 'There was some trouble loading your GIF. Make sure that your GIF is using 87a or 89a encoding.', 107008 'image': 'It looks like there was a problem loading your image. {{suggestion}}', 107009 'json': 'It looks like there was a problem loading your JSON file. {{suggestion}}', 107010 'large': 'If your large file isn\'t fetched successfully, we recommend splitting the file into smaller segments and fetching those.', 107011 'strings': 'It looks like there was a problem loading your text file. {{suggestion}}', 107012 'suggestion': 'Try checking if the file path ({{filePath}}) is correct, hosting the file online, or running a local server.\n\n+ More info: {{url}}', 107013 'table': 'It looks like there was a problem loading your table file. {{suggestion}}', 107014 'xml': 'It looks like there was a problem loading your XML file. {{suggestion}}' 107015 }, 107016 'friendlyParamError': { 107017 'type_EMPTY_VAR': '{{location}} {{func}}() was expecting {{formatType}} for the {{position}} parameter, received an empty variable instead. If not intentional, this is often a problem with scope.\n\n+ More info: {{url}}', 107018 'type_TOO_FEW_ARGUMENTS': '{{location}} {{func}}() was expecting at least {{minParams}} arguments, but received only {{argCount}}.', 107019 'type_TOO_MANY_ARGUMENTS': '{{location}} {{func}}() was expecting no more than {{maxParams}} arguments, but received {{argCount}}.', 107020 'type_WRONG_TYPE': '{{location}} {{func}}() was expecting {{formatType}} for the {{position}} parameter, received {{argType}} instead.' 107021 }, 107022 'globalErrors': { 107023 'reference': { 107024 'cannotAccess': '\n{{location}} "{{symbol}}" is used before declaration. Make sure you have declared the variable before using it.\n\n+ More info: {{url}}', 107025 'notDefined': '\n{{location}} "{{symbol}}" is not defined in the current scope. If you have defined it in your code, you should check its scope, spelling, and letter-casing (JavaScript is case-sensitive).\n\n+ More info: {{url}}' 107026 }, 107027 'stackSubseq': 'â[{{location}}] \n\t Called from line {{line}} in {{func}}()\n', 107028 'stackTop': 'â[{{location}}] \n\t Error at line {{line}} in {{func}}()\n', 107029 'syntax': { 107030 'badReturnOrYield': '\nSyntax Error - return lies outside of a function. Make sure youâre not missing any brackets, so that return lies inside a function.\n\n+ More info: {{url}}', 107031 'invalidToken': '\nSyntax Error - Found a symbol that JavaScript doesn\'t recognize or didn\'t expect at it\'s place.\n\n+ More info: {{url}}', 107032 'missingInitializer': '\nSyntax Error - A const variable is declared but not initialized. In JavaScript, an initializer for a const is required. A value must be specified in the same statement in which the variable is declared. Check the line number in the error and assign the const variable a value.\n\n+ More info: {{url}}', 107033 'redeclaredVariable': '\nSyntax Error - "{{symbol}}" is being redeclared. JavaScript doesn\'t allow declaring a variable more than once. Check the line number in error for redeclaration of the variable.\n\n+ More info: {{url}}', 107034 'unexpectedToken': '\nSyntax Error - Symbol present at a place that wasn\'t expected.\nUsually this is due to a typo. Check the line number in the error for anything missing/extra.\n\n+ More info: {{url}}' 107035 }, 107036 'type': { 107037 'constAssign': '\n{{location}} A const variable is being re-assigned. In javascript, re-assigning a value to a constant is not allowed. If you want to re-assign new values to a variable, make sure it is declared as var or let.\n\n+ More info: {{url}}', 107038 'notfunc': '\n{{location}} "{{symbol}}" could not be called as a function.\nCheck the spelling, letter-casing (JavaScript is case-sensitive) and its type.\n\n+ More info: {{url}}', 107039 'notfuncObj': '\n{{location}} "{{symbol}}" could not be called as a function.\nVerify whether "{{obj}}" has "{{symbol}}" in it and check the spelling, letter-casing (JavaScript is case-sensitive) and its type.\n\n+ More info: {{url}}', 107040 'readFromNull': '\n{{location}} The property of null can\'t be read. In javascript the value null indicates that an object has no value.\n\n+ More info: {{url}}', 107041 'readFromUndefined': '\n{{location}}
107041 Cannot read property of undefined. Check the line number in error and make sure the variable which is being operated is not undefined.\n\n + More info: {{url}}' 107042 } 107043 }, 107044 'libraryError': '{{location}} An error with message "{{error}}" occurred inside the p5js library when {{func}} was called. If not stated otherwise, it might be an issue with the arguments passed to {{func}}.', 107045 'location': '[{{file}}, line {{line}}]', 107046 'misspelling': '{{location}} It seems that you may have accidentally written "{{name}}" instead of "{{actualName}}". Please correct it to {{actualName}} if you wish to use the {{type}} from p5.js.', 107047 'misspelling_plural': '{{location}} It seems that you may have accidentally written "{{name}}".\nYou may have meant one of the following: \n{{suggestions}}', 107048 'misusedTopLevel': 'Did you just try to use p5.js\'s {{symbolName}} {{symbolType}}? If so, you may want to move it into your sketch\'s setup() function.\n\n+ More info: {{url}}', 107049 'positions': { 107050 'p_1': 'first', 107051 'p_10': 'tenth', 107052 'p_11': 'eleventh', 107053 'p_12': 'twelfth', 107054 'p_2': 'second', 107055 'p_3': 'third', 107056 'p_4': 'fourth', 107057 'p_5': 'fifth', 107058 'p_6': 'sixth', 107059 'p_7': 'seventh', 107060 'p_8': 'eighth', 107061 'p_9': 'ninth' 107062 }, 107063 'pre': '\nð¸ p5.js says: {{message}}', 107064 'sketchReaderErrors': { 107065 'reservedConst': 'you have used a p5.js reserved variable "{{symbol}}" make sure you change the variable name to something else.\n\n+ More info: {{url}}', 107066 'reservedFunc': 'you have used a p5.js reserved function "{{symbol}}" make sure you change the function name to something else.\n\n+ More info: {{url}}' 107067 }, 107068 'welcome': 'Welcome! This is your friendly debugger. To turn me off, switch to using p5.min.js.', 107069 'wrongPreload': '{{location}} An error with message "{{error}}" occurred inside the p5js library when "{{func}}" was called. If not stated otherwise, it might be due to "{{func}}" being called from preload. Nothing besides load calls (loadImage, loadJSON, loadFont, loadStrings, etc.) should be inside the preload function.' 107070 } 107071 } 107072 }, 107073 { 107074 } 107075 ], 107076 349: [ 107077 function (_dereq_, module, exports) { 107078 'use strict'; 107079 Object.defineProperty(exports, '__esModule', { 107080 value: true 107081 }); 107082 exports.languages = exports.default = void 0; 107083 var _translation = _interopRequireDefault(_dereq_('./en/translation')); 107084 function _interopRequireDefault(obj) { 107085 return obj && obj.__esModule ? obj : { 107086 default: 107087 obj 107088 }; 107089 } // Only one language is imported above. This is intentional as other languages 107090 // will be hosted online and then downloaded whenever needed 107091 /** 107092 * Here, we define a default/fallback language which we can use without internet. 107093 * You won't have to change this when adding a new language. 107094 * 107095 * `translation` is the namespace we are using for our initial set of strings 107096 */ 107097 107098 var _default = { 107099 en: { 107100 translation: _translation.default 107101 } 107102 }; 107103 /** 107104 * This is a list of languages that we have added so far. 107105 * If you have just added a new language (yay!), add its key to the list below 107106 * (`en` is english, `es` es español). Also add its export to 107107 * dev.js, which is another file in this folder. 107108 */ 107109 exports.default = _default; 107110 var languages = [ 107111 'en', 107112 'es', 107113 'ko' 107114 ]; 107115 exports.languages = languages; 107116 }, 107117 { 107118 './en/translation': 348 107119 } 107120 ] 107121 }, { 107122 }, [ 107123 273 107124 ]) (273) 107125});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.