Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 4674x 4674x 4674x 4674x 4674x 1393x 3281x 11x 3270x 4674x 4674x 36x 36x 684x 684x 684x 684x 684x 684x 684x 1612x 1612x 1612x 1612x 10x 10x 1612x 1603x 1603x 1602x 1377x 26x 26x 26x 1377x 94x 94x 94x 94x 94x 94x 1377x 1602x 1602x 1602x 1603x 1612x 684x 49702x 49702x 49702x 49702x 49702x 1569x 3574x 3574x 1569x 2890x 401x 401x 3574x 49702x 47881x 47881x 37326x 37326x 77x 77x 47881x 10555x 10555x 1338x 1338x 1338x 1338x 1338x 10555x 47881x 49702x 9221x 9221x 49301x 49702x 684x 5683x 5683x 684x 668x 668x 36x 36x 36x 36x 36x 36x 36x 72x 72x 72x 72x 72x 36x 36x 36x 1x 1x 1x 5341x 5341x 5341x 5341x 923x 923x 923x 923x 923x 5341x 5341x 1x 4x 8x 8x 8x 8x 5x 5x 5x 5x 5x 8x 8x 4x 4x 4x 4x 4x 4x 4x 1x 5242x 5242x 5242x 5242x 5242x 5242x 5242x 5242x 1x 2069x 2069x 2069x 1x 6703x 6703x 6703x 1x 712x 712x 712x 1x 1x 13x 13x 13x 13x 1x 1x 1x 15x 15x 15x 15x 15x 1x 1x 1x | /* * Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * http://paperjs.org/ * * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey * http://juerglehni.com/ & https://puckey.studio/ * * Distributed under the MIT license. See LICENSE file for details. * * All rights reserved. */ // TODO: remove eslint-disable comment and deal with errors over time /* eslint-disable */ import { ref } from '~/globals'; import { Base } from '~/straps'; import { Point } from '~/basic/Point'; import { Change } from '~/item/ChangeFlag'; import { Group } from '~/item/Group'; import { Item } from '~/item/Item'; import { CompoundPath } from '~/path/CompoundPath'; import { TextItem } from '~/text/TextItem'; import { Color } from './Color'; /** * @name Style * * @class Style is used for changing the visual styles of items * contained within a Paper.js project and is returned by * {@link Item#style} and {@link Project#currentStyle}. * * All properties of Style are also reflected directly in {@link Item}, * i.e.: {@link Item#fillColor}. * * To set multiple style properties in one go, you can pass an object to * {@link Item#style}. This is a convenient way to define a style once and * apply it to a series of items: * * @classexample {@paperscript} // Styling paths * * var path = new Path.Circle(new Point(80, 50), 30); * path.style = { * fillColor: new Color(1, 0, 0), * strokeColor: 'black', * strokeWidth: 5 * }; * * @classexample {@paperscript} // Styling text items * var text = new PointText(view.center); * text.content = 'Hello world.'; * text.style = { * fontFamily: 'Courier New', * fontWeight: 'bold', * fontSize: 20, * fillColor: 'red', * justification: 'center' * }; * * @classexample {@paperscript} // Styling groups * var path1 = new Path.Circle({ * center: [100, 50], * radius: 30 * }); * * var path2 = new Path.Rectangle({ * from: [170, 20], * to: [230, 80] * }); * * var group = new Group(path1, path2); * * // All styles set on a group are automatically * // set on the children of the group: * group.style = { * strokeColor: 'black', * dashArray: [4, 10], * strokeWidth: 4, * strokeCap: 'round' * }; * */ export const Style = Base.extend( // @ts-expect-error = 'new' expression, whose target lacks a construct signature new (function () { // Defaults for items without text-styles (PathItem, Shape, Raster, ...): var itemDefaults = { // Paths fillColor: null, fillRule: 'nonzero', strokeColor: null, strokeWidth: 1, strokeCap: 'butt', strokeJoin: 'miter', strokeScaling: true, miterLimit: 10, dashOffset: 0, dashArray: [], // Shadows shadowColor: null, shadowBlur: 0, shadowOffset: new Point(), // Selection selectedColor: null, }, // Defaults for Group, Layer and Project (anything item that allows nesting // needs to be able to pass down text styles as well): groupDefaults = Base.set({}, itemDefaults, { // Characters fontFamily: 'sans-serif', fontWeight: 'normal', fontSize: 12, leading: null, // Paragraphs justification: 'left', }), // Defaults for TextItem (override default fillColor to black): textDefaults = Base.set({}, groupDefaults, { fillColor: new Color(), // black }), flags = { strokeWidth: /*#=*/ Change.STROKE, strokeCap: /*#=*/ Change.STROKE, strokeJoin: /*#=*/ Change.STROKE, // strokeScaling can change the coordinates of cached path items strokeScaling: /*#=*/ Change.STROKE | Change.GEOMETRY, miterLimit: /*#=*/ Change.STROKE, fontFamily: /*#=*/ Change.GEOMETRY, fontWeight: /*#=*/ Change.GEOMETRY, fontSize: /*#=*/ Change.GEOMETRY, font: /*#=*/ Change.GEOMETRY, // deprecated, links to fontFamily leading: /*#=*/ Change.GEOMETRY, justification: /*#=*/ Change.GEOMETRY, }, item = { // Enforce creation of beans, as bean getters have hidden parameters, // see _dontMerge argument below. beans: true, }, fields = /** @lends Style# */ { _class: 'Style', beans: true, initialize: function Style(style, _owner, _project) { // We keep values in a separate object that we can iterate over. this._values = {}; this._owner = _owner; this._project = (_owner && _owner._project) || _project || ref.paper.project; // Use different defaults based on the owner this._defaults = !_owner || _owner instanceof Group ? groupDefaults : _owner instanceof TextItem ? textDefaults : itemDefaults; if (style) this.set(style); }, }; // Iterate over groupDefaults to inject getters / setters, to cover all // properties Base.each(groupDefaults, function (value, key) { var isColor = /Color$/.test(key), isPoint = key === 'shadowOffset', part = Base.capitalize(key), flag = flags[key], set = 'set' + part, get = 'get' + part; // Define getters and setters to be injected into this class. // This is how style values are handled: // - Style values are all stored in this._values // - The style object starts with an empty _values object, with fallback // on _defaults through code in the getter below. // - Only the styles that are explicitly set on the object get defined // in _values. // - Color values are not stored as converted colors immediately. The // raw value is stored, and conversion only happens in the getter. fields[set] = function (value) { var owner = this._owner, children = owner && owner._children, applyToChildren = children && children.length > 0 && !(owner instanceof CompoundPath); // Only unify styles on children of Groups, excluding CompoundPaths. if (applyToChildren) { for (var i = 0, l = children.length; i < l; i++) children[i]._style[set](value); } // Always store selectedColor in item _values to make sure that // group selected bounds and position color is coherent whether it // has children or not when the value is set. if ((key === 'selectedColor' || !applyToChildren) && key in this._defaults) { var old = this._values[key]; if (old !== value) { if (isColor) { // The old value may be a native string or other color // description that wasn't coerced to a color object yet if (old) { Color._setOwner(old, null); if (typeof old !== 'string') old._canvasStyle = null; } if (value && value.constructor === Color) { // NOTE: If value is not a Color, it is only // converted and cloned in the getter further down. value = Color._setOwner( value, owner, // Only provide a color-setter if the style // is to be applied to the children: applyToChildren && set ); } } // NOTE: We do not convert the values to Colors in the // setter. This only happens once the getter is called. this._values[key] = value; // Notify the owner of the style change STYLE is always set, // additional flags come from flags, as used for STROKE: if (owner) owner._changed(flag || /*#=*/ Change.STYLE); } } }; fields[get] = function (_dontMerge) { var owner = this._owner, children = owner && owner._children, applyToChildren = children && children.length > 0 && !(owner instanceof CompoundPath), value; // If the owner has children, walk through all of them and see if // they all have the same style. // If true is passed for _dontMerge, don't merge children styles. if (applyToChildren && !_dontMerge) { for (var i = 0, l = children.length; i < l; i++) { var childValue = children[i]._style[get](); if (!i) { value = childValue; } else if (!Base.equals(value, childValue)) { // If there is another child with a different // style, the style is not defined: return undefined; } } } else if (key in this._defaults) { var value = this._values[key]; if (value === undefined) { value = this._defaults[key]; // Clone defaults if available: if (value && value.clone) { value = value.clone(); } } else { var ctor = isColor ? Color : isPoint ? Point : null; if (ctor && !(value && value.constructor === ctor)) { // Convert to a Color / Point, and stored result of the // conversion. this._values[key] = value = ctor.read([value], 0, { readNull: true, clone: true, }); } } } if (value && isColor) { // Color._setOwner() may clone the color if it already has a // different owner (e.g. resulting from `childValue` above). // Only provide a color-setter if the style is to be applied to // the children: value = Color._setOwner(value, owner, applyToChildren && set); } return value; }; // Inject style getters and setters into the Item class, which redirect // calls to the linked style object. item[get] = function (_dontMerge) { return this._style[get](_dontMerge); }; item[set] = function (value) { this._style[set](value); }; }); // Create aliases for deprecated properties. The lookup table contains the // part after 'get' / 'set': // TODO: Remove once deprecated long enough, after December 2016. Base.each( { Font: 'FontFamily', WindingRule: 'FillRule', }, function (value, key) { var get = 'get' + key, set = 'set' + key; fields[get] = item[get] = '#get' + value; fields[set] = item[set] = '#set' + value; } ); Item.inject(item); return fields; })(), /** @lends Style# */ { set: function (style) { // If the passed style object is also a Style, clone its cloneable // fields rather than simply copying them. var isStyle = style instanceof Style, // Use the other stlyle's _values object for iteration values = isStyle ? style._values : style; if (values) { for (var key in values) { if (key in this._defaults) { var value = values[key]; // Delegate to setter, so Group styles work too. this[key] = value && isStyle && value.clone ? value.clone() : value; } } } }, equals: function (style) { // Since we're dealing with defaults, loop through style values in both // objects and compare with default fall-back. But in the secondary pass // only check against keys that weren't already in the first object: function compare(style1, style2, secondary) { var values1 = style1._values, values2 = style2._values, defaults2 = style2._defaults; for (var key in values1) { var value1 = values1[key], value2 = values2[key]; if (!(secondary && key in values2) && !Base.equals(value1, value2 === undefined ? defaults2[key] : value2)) return false; } return true; } return ( style === this || (style && this._class === style._class && // @ts-expect-error = Expected 3 arguments, but got 2 compare(this, style) && compare(style, this, true)) || false ); }, _dispose: function () { var color; color = this.getFillColor(); if (color) color._canvasStyle = null; color = this.getStrokeColor(); if (color) color._canvasStyle = null; color = this.getShadowColor(); if (color) color._canvasStyle = null; }, // DOCS: Style#hasFill() hasFill: function () { var color = this.getFillColor(); return !!color && color.alpha > 0; }, // DOCS: Style#hasStroke() hasStroke: function () { var color = this.getStrokeColor(); return !!color && color.alpha > 0 && this.getStrokeWidth() > 0; }, // DOCS: Style#hasShadow() hasShadow: function () { var color = this.getShadowColor(); // In order to draw a shadow, we need either a shadow blur or an // offset, or both. return !!color && color.alpha > 0 && (this.getShadowBlur() > 0 || !this.getShadowOffset().isZero()); }, /** * The view that this style belongs to. * * @bean * @type View */ getView: function () { return this._project._view; }, // Overrides getFontStyle: function () { var fontSize = this.getFontSize(); // To prevent an obscure iOS 7 crash, we have to convert the size to a // string first before passing it to the regular expression. // The following nonsensical statement would also prevent the bug, // proving that the issue is not the regular expression itself, but // something deeper down in the optimizer: // `if (size === 0) size = 0;` return ( this.getFontWeight() + ' ' + fontSize + (/[a-z]/i.test(fontSize + '') ? ' ' : 'px ') + this.getFontFamily() ); }, /** * @bean * @private * @deprecated use {@link #fontFamily} instead. */ getFont: '#getFontFamily', setFont: '#setFontFamily', getLeading: function getLeading() { // Override leading to return fontSize * 1.2 by default. var leading = (getLeading as any).base.call(this), fontSize = this.getFontSize(); if (/pt|em|%|px/.test(fontSize)) fontSize = this.getView().getPixelSize(fontSize); return leading != null ? leading : fontSize * 1.2; }, // DOCS: why isn't the example code showing up? /** * Style objects don't need to be created directly. Just pass an object to * {@link Item#style} or {@link Project#currentStyle}, it will be converted * to a Style object internally. * * @name Style#initialize * @param {Object} style */ /** * {@grouptitle Stroke Style} * * The color of the stroke. * * @name Style#strokeColor * @property * @type ?Color * * @example {@paperscript} * // Setting the stroke color of a path: * * // Create a circle shaped path at { x: 80, y: 50 } * // with a radius of 35: * var circle = new Path.Circle(new Point(80, 50), 35); * * // Set its stroke color to RGB red: * circle.strokeColor = new Color(1, 0, 0); */ /** * The width of the stroke. * * @name Style#strokeWidth * @property * @type Number * @default 1 * * @example {@paperscript} * // Setting an item's stroke width: * * // Create a circle shaped path at { x: 80, y: 50 } * // with a radius of 35: * var circle = new Path.Circle(new Point(80, 50), 35); * * // Set its stroke color to black: * circle.strokeColor = 'black'; * * // Set its stroke width to 10: * circle.strokeWidth = 10; */ /** * The shape to be used at the beginning and end of open {@link Path} items, * when they have a stroke. * * @name Style#strokeCap * @property * @type String * @values 'round', 'square', 'butt' * @default 'butt' * * @example {@paperscript height=200} * // A look at the different stroke caps: * * var line = new Path(new Point(80, 50), new Point(420, 50)); * line.strokeColor = 'black'; * line.strokeWidth = 20; * * // Select the path, so we can see where the stroke is formed: * line.selected = true; * * // Set the stroke cap of the line to be round: * line.strokeCap = 'round'; * * // Copy the path and set its stroke cap to be square: * var line2 = line.clone(); * line2.position.y += 50; * line2.strokeCap = 'square'; * * // Make another copy and set its stroke cap to be butt: * var line2 = line.clone(); * line2.position.y += 100; * line2.strokeCap = 'butt'; */ /** * The shape to be used at the segments and corners of {@link Path} items * when they have a stroke. * * @name Style#strokeJoin * @property * @type String * @values 'miter', 'round', 'bevel' * @default 'miter' * * @example {@paperscript height=120} * // A look at the different stroke joins: * var path = new Path(); * path.add(new Point(80, 100)); * path.add(new Point(120, 40)); * path.add(new Point(160, 100)); * path.strokeColor = 'black'; * path.strokeWidth = 20; * * // Select the path, so we can see where the stroke is formed: * path.selected = true; * * var path2 = path.clone(); * path2.position.x += path2.bounds.width * 1.5; * path2.strokeJoin = 'round'; * * var path3 = path2.clone(); * path3.position.x += path3.bounds.width * 1.5; * path3.strokeJoin = 'bevel'; */ /** * Specifies whether the stroke is to be drawn taking the current affine * transformation into account (the default behavior), or whether it should * appear as a non-scaling stroke. * * @name Style#strokeScaling * @property * @type Boolean * @default true */ /** * The dash offset of the stroke. * * @name Style#dashOffset * @property * @type Number * @default 0 */ /** * Specifies an array containing the dash and gap lengths of the stroke. * * @example {@paperscript} * var path = new Path.Circle(new Point(80, 50), 40); * path.strokeWidth = 2; * path.strokeColor = 'black'; * * // Set the dashed stroke to [10pt dash, 4pt gap]: * path.dashArray = [10, 4]; * * @name Style#dashArray * @property * @type Number[] * @default [] */ /** * The miter limit of the stroke. When two line segments meet at a sharp * angle and miter joins have been specified for {@link #strokeJoin}, it is * possible for the miter to extend far beyond the {@link #strokeWidth} of * the path. The miterLimit imposes a limit on the ratio of the miter length * to the {@link #strokeWidth}. * * @name Style#miterLimit * @property * @default 10 * @type Number */ /** * {@grouptitle Fill Style} * * The fill color. * * @name Style#fillColor * @property * @type ?Color * * @example {@paperscript} * // Setting the fill color of a path to red: * * // Create a circle shaped path at { x: 80, y: 50 } * // with a radius of 35: * var circle = new Path.Circle(new Point(80, 50), 35); * * // Set the fill color of the circle to RGB red: * circle.fillColor = new Color(1, 0, 0); */ /** * The fill-rule with which the shape gets filled. Please note that only * modern browsers support fill-rules other than `'nonzero'`. * * @name Style#fillRule * @property * @type String * @values 'nonzero', 'evenodd' * @default 'nonzero' */ /** * {@grouptitle Shadow Style} * * The shadow color. * * @property * @name Style#shadowColor * @type ?Color * * @example {@paperscript} * // Creating a circle with a black shadow: * * var circle = new Path.Circle({ * center: [80, 50], * radius: 35, * fillColor: 'white', * // Set the shadow color of the circle to RGB black: * shadowColor: new Color(0, 0, 0), * // Set the shadow blur radius to 12: * shadowBlur: 12, * // Offset the shadow by { x: 5, y: 5 } * shadowOffset: new Point(5, 5) * }); */ /** * The shadow's blur radius. * * @property * @name Style#shadowBlur * @type Number * @default 0 */ /** * The shadow's offset. * * @property * @name Style#shadowOffset * @type Point * @default 0 */ /** * {@grouptitle Selection Style} * * The color the item is highlighted with when selected. If the item does * not specify its own color, the color defined by its layer is used instead. * * @name Style#selectedColor * @property * @type ?Color */ /** * {@grouptitle Character Style} * * The font-family to be used in text content. * * @name Style#fontFamily * @type String * @default 'sans-serif' */ /** * * The font-weight to be used in text content. * * @name Style#fontWeight * @type String|Number * @default 'normal' */ /** * The font size of text content, as a number in pixels, or as a string with * optional units `'px'`, `'pt'` and `'em'`. * * @name Style#fontSize * @type Number|String * @default 10 */ /** * * The font-family to be used in text content, as one string. * * @name Style#font * @type String * @default 'sans-serif' * @deprecated use {@link #fontFamily} instead. */ /** * The text leading of text content. * * @name Style#leading * @type Number|String * @default fontSize * 1.2 */ /** * {@grouptitle Paragraph Style} * * The justification of text paragraphs. * * @name Style#justification * @type String * @values 'left', 'right', 'center' * @default 'left' */ } ); ref.Style = Style; |