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 | 1x 1x 1x 1x 1x 1x 1x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 36x 36x 36x 36x 36x 36x 36x 37x 36x 36x 36x 36x 36x 36x 36x 36x 72x 72x 72x 72x 72x 72x 72x 72x 72x 36x 36x 36x 36x 37x 1x 1x 57x 57x 57x 1x 1x 1x 1x 535x 535x 535x 535x 1x 1x 1x 1x 1x 1x 1x 36x 72x 72x 1662x 1662x 72x 36x 36x 36x 36x 36x 36x 36x 1x 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 { __options } from '~/options'; /** * @name PaperScope * * @class The `PaperScope` class represents the scope associated with a Paper * context. When working with PaperScript, these scopes are automatically * created for us, and through clever scoping the properties and methods of * the active scope seem to become part of the global scope. * * When working with normal JavaScript code, `PaperScope` objects need to be * manually created and handled. * * Paper classes can only be accessed through `PaperScope` objects. Thus in * PaperScript they are global, while in JavaScript, they are available on the * global {@link paper} object. For JavaScript you can use {@link * PaperScope#install(scope) } to install the Paper classes and objects on the * global scope. Note that when working with more than one scope, this still * works for classes, but not for objects like {@link PaperScope#project}, since * they are not updated in the injected scope if scopes are switched. * * The global {@link paper} object is simply a reference to the currently active * `PaperScope`. */ export const PaperScope = Base.extend( /** @lends PaperScope# */ { _class: 'PaperScope', /** * Creates a PaperScope object. * * @name PaperScope#initialize * @function */ // DOCS: initialize() parameters initialize: function PaperScope() { // element is only used internally when creating scopes for PaperScript. // Whenever a PaperScope is created, it automatically becomes the active // one. ref.paper = this; // Default configurable settings. this.settings = new Base({ applyMatrix: true, insertItems: true, handleSize: 4, hitTolerance: 0, }); this.project = null; this.projects = []; this.tools = []; // Assign a unique id to each scope this._id = ref.PaperScope._id++; ref.PaperScope._scopes[this._id] = this; var proto = PaperScope.prototype; if (!this.support) { // Set up paper.support, as an object containing properties that // describe the support of various features. // @ts-expect-error TODO var ctx = ref.CanvasProvider.getContext(1, 1) || {}; proto.support = { nativeDash: 'setLineDash' in ctx || 'mozDash' in ctx, nativeBlendModes: ref.BlendMode.nativeModes, }; ref.CanvasProvider.release(ctx); } if (!this.agent) { // Use self.instead of window, to cover handle web-workers too. var user = globalThis.navigator?.userAgent.toLowerCase() || 'unknown-user-agent'; // Detect basic platforms, only mac internally required for now. var os = (/(darwin|win|mac|linux|freebsd|sunos)/.exec(user) || [])[0], platform = os === 'darwin' ? 'mac' : os, agent: any = (proto.agent = proto.browser = { platform: platform }); if (platform) agent[platform] = true; // Use replace() to get all matches, and deal with Chrome/Webkit // overlap: // TODO: Do we need Mozilla next to Firefox? Other than the // different treatment of the Chrome/Webkit overlap // here: { chrome: true, webkit: false }, Mozilla missing is the // only difference to jQuery.browser user.replace( /(opera|chrome|safari|webkit|firefox|msie|trident|atom|node|jsdom)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:v?([.\d]+))?/g, // @ts-expect-error = No overload matches this call. function (match, n, v1, v2, rv) { // Do not set additional browsers once chrome is detected. if (!agent.chrome) { var v = n === 'opera' ? v2 : /^(node|trident)$/.test(n) ? rv : v1; agent.version = v; agent.versionNumber = parseFloat(v); n = { trident: 'msie', jsdom: 'node' }[n] || n; agent.name = n; agent[n] = true; } } ); if (agent.chrome) delete agent.webkit; if (agent.atom) delete agent.chrome; } }, /** * The version of Paper.js, as a string. * * @type String * @readonly */ version: /*#=*/ __options.version, /** * Gives access to paper's configurable settings. * * @name PaperScope#settings * @type Object * * @option [settings.insertItems=true] {Boolean} controls whether newly * created items are automatically inserted into the scene graph, by * adding them to {@link Project#activeLayer} * @option [settings.applyMatrix=true] {Boolean} controls what value newly * created items have their {@link Item#applyMatrix} property set to * (Note that not all items can set this to `false`) * @option [settings.handleSize=4] {Number} the size of the curve handles * when drawing selections * @option [settings.hitTolerance=0] {Number} the default tolerance for hit- * tests, when no value is specified */ /** * The currently active project. * * @name PaperScope#project * @type Project */ /** * The list of all open projects within the current Paper.js context. * * @name PaperScope#projects * @type Project[] */ /** * The reference to the active project's view. * * @bean * @type View */ getView: function () { var project = this.project; return project && project._view; }, /** * The reference to the active tool. * * @name PaperScope#tool * @property * @type Tool */ /** * The list of available tools. * * @name PaperScope#tools * @property * @type Tool[] */ /** * A reference to the local scope. This is required, so `paper` will always * refer to the local scope, even when calling into it from another scope. * `paper.activate();` will have to be called in such a situation. * * @bean * @type PaperScript * @private */ getPaper: function () { return this; }, /** * Compiles the PaperScript code into a compiled function and executes it. * The compiled function receives all properties of this {@link PaperScope} * as arguments, to emulate a global scope with unaffected performance. It * also installs global view and tool handlers automatically on the * respective objects. * * @option options.url {String} the url of the source, for source-map * debugging * @option options.source {String} the source to be used for the source- * mapping, in case the code that's passed in has already been mingled. * * @param {String} code the PaperScript code * @param {Object} [options] the compilation options */ execute: function (code, options) { /*#*/ if (__options.paperScript) { var exports = ref.paper.PaperScript.execute(code, this, options); ref.View.updateFocus(); return exports; /*#*/ } }, /** * Injects the paper scope into any other given scope. Can be used for * example to inject the currently active PaperScope into the window's * global scope, to emulate PaperScript-style globally accessible Paper * classes and objects. * * <b>Please note:</b> Using this method may override native constructors * (e.g. Path). This may cause problems when using Paper.js in conjunction * with other libraries that rely on these constructors. Keep the library * scoped if you encounter issues caused by this. * * @example * paper.install(window); */ install: function (scope) { // Define project, view and tool as getters that redirect to these // values on the PaperScope, so they are kept up to date var that = this; Base.each(['project', 'view', 'tool'], function (key) { Base.define(scope, key, { configurable: true, get: function () { return that[key]; }, }); }); // Copy over all fields from this scope to the destination. // Do not use Base.each, since we also want to enumerate over // fields on PaperScope.prototype, e.g. all classes // Exclude all 'hidden' fields for (var key in this) if (!/^_/.test(key) && this[key]) scope[key] = this[key]; }, /** * Sets up an empty project for us. If a canvas is provided, it also creates * a {@link View} for it, both linked to this scope. * * @param {HTMLCanvasElement|String|Size} element the HTML canvas element * this scope should be associated with, or an ID string by which to find * the element, or the size of the canvas to be created for usage in a web * worker. */ setup: function (element) { // Make sure this is the active scope, so the created project and view // are automatically associated with it. ref.paper = this; // Create an empty project for the scope. this.project = new ref.Project(element); // This is needed in PaperScript.load(). return this; }, createCanvas: function (width, height) { // @ts-expect-error TODO return ref.CanvasProvider.getCanvas(width, height); }, /** * Activates this PaperScope, so all newly created items will be placed * in its active project. */ activate: function () { ref.paper = this; }, clear: function () { // Remove all projects, views and tools. // This also removes the installed event handlers. var projects = this.projects, tools = this.tools; for (var i = projects.length - 1; i >= 0; i--) projects[i].remove(); for (var i = tools.length - 1; i >= 0; i--) tools[i].remove(); }, remove: function () { this.clear(); delete PaperScope._scopes[this._id]; }, // @ts-expect-error = Only a void function can be called with the 'new' keyword statics: new (function () { // Produces helpers to e.g. check for both 'canvas' and // 'data-paper-canvas' attributes: function handleAttribute(name) { name += 'Attribute'; return function (el, attr) { return el[name](attr) || el[name]('data-paper-' + attr); }; } return /** @lends PaperScope */ { _scopes: {}, _id: 0, /** * Retrieves a PaperScope object with the given scope id. * * @param id * @return {PaperScope} */ get: function (id) { return this._scopes[id] || null; }, getAttribute: handleAttribute('get'), hasAttribute: handleAttribute('has'), }; })(), } ); ref.PaperScope = PaperScope; |