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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 1x 2x 1x 2x 2x 1x 21x 21x 21x 21x 1x 10x 10x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 1x 1x 1x 21x 21x 1x 1x 1x 1x 2x 2x 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 { UID } from '~/util/UID'; import { ChangeFlag, Change } from './ChangeFlag'; import { Item } from './Item'; import { SymbolItem } from './SymbolItem'; /** * @name SymbolDefinition * * @class Symbols allow you to place multiple instances of an item in your * project. This can save memory, since all instances of a symbol simply refer * to the original item and it can speed up moving around complex objects, since * internal properties such as segment lists and gradient positions don't need * to be updated with every transformation. */ export const SymbolDefinition = Base.extend( /** @lends SymbolDefinition# */ { _class: 'SymbolDefinition', /** * Creates a Symbol definition. * * @param {Item} item the source item which is removed from the scene graph * and becomes the symbol's definition. * @param {Boolean} [dontCenter=false] * * @example {@paperscript split=true height=240} * // Placing 100 instances of a symbol: * var path = new Path.Star(new Point(0, 0), 6, 5, 13); * path.style = { * fillColor: 'white', * strokeColor: 'black' * }; * * // Create a symbol definition from the path: * var definition = new SymbolDefinition(path); * * // Place 100 instances of the symbol definition: * for (var i = 0; i < 100; i++) { * // Place an instance of the symbol definition in the project: * var instance = definition.place(); * * // Move the instance to a random position within the view: * instance.position = Point.random() * view.size; * * // Rotate the instance by a random amount between * // 0 and 360 degrees: * instance.rotate(Math.random() * 360); * * // Scale the instance between 0.25 and 1: * instance.scale(0.25 + Math.random() * 0.75); * } */ initialize: function SymbolDefinition(item, dontCenter) { // @ts-expect-error = Expected 1 arguments, but got 0 this._id = UID.get(); this.project = ref.paper.project; if (item) this.setItem(item, dontCenter); }, _serialize: function (options, dictionary) { return dictionary.add(this, function () { return Base.serialize([this._class, this._item], options, false, dictionary); }); }, /** * The project that this symbol belongs to. * * @type Project * @readonly * @name SymbolDefinition#project */ /** * Private notifier that is called whenever a change occurs in this symbol's * definition. * * @param {ChangeFlag} flags describes what exactly has changed */ _changed: function (flags) { if (flags & /*#=*/ ChangeFlag.GEOMETRY) // Clear cached bounds of all items that this symbol is linked to. Item._clearBoundsCache(this); if (flags & /*#=*/ ChangeFlag.APPEARANCE) this.project._changed(flags); }, /** * The item used as the symbol's definition. * * @bean * @type Item */ getItem: function () { return this._item; }, setItem: function (item, _dontCenter) { // Make sure we're not stealing another symbol's definition if (item._symbol) item = item.clone(); // Remove previous definition's reference to this symbol if (this._item) this._item._symbol = null; this._item = item; // Remove item from DOM, as it's embedded in Symbol now. item.remove(); item.setSelected(false); // Move position to 0, 0, so it's centered when placed. if (!_dontCenter) item.setPosition(new Point()); item._symbol = this; this._changed(/*#=*/ Change.GEOMETRY); }, /** * @bean * @deprecated use {@link #item} instead. */ getDefinition: '#getItem', setDefinition: '#setItem', /** * Places in instance of the symbol in the project. * * @param {Point} [position] the position of the placed symbol * @return {SymbolItem} */ place: function (position) { return new SymbolItem(this, position); }, /** * Returns a copy of the symbol. * * @return {SymbolDefinition} */ clone: function () { return new SymbolDefinition(this._item.clone(false)); }, /** * Checks whether the symbol's definition is equal to the supplied symbol. * * @param {SymbolDefinition} symbol * @return {Boolean} {@true if they are equal} */ equals: function (symbol) { return symbol === this || (symbol && this._item.equals(symbol._item)) || false; }, } ); |