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 | 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 36x 36x 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 { DomEvent } from '~/dom/DomEvent'; import { View } from '~/view/View'; /** * @name Key * @namespace */ // @ts-expect-error export const Key = new (function () { var keyLookup = { // Unify different key identifier naming schemes, e.g. on Gecko, IE: '\t': 'tab', ' ': 'space', '\b': 'backspace', '\x7f': 'delete', Spacebar: 'space', Del: 'delete', Win: 'meta', Esc: 'escape', }, // To find corresponding characters for special keys in keydown events: charLookup = { tab: '\t', space: ' ', enter: '\r', }, // Only keypress reliable gets char-codes that are actually representing // characters with all modifiers taken into account across all browsers. // So we need to perform a little trickery here to use these codes with // onKeyDown/Up: // - keydown is used to handle modifiers and special keys such as // arrows, space, control, etc, for which events are fired right away. // - keypress fires the actual onKeyDown event for all other keys. // - keyup handles the onKeyUp events for both. keyMap = {}, // Map for currently pressed keys charMap = {}, // key -> char mappings for pressed keys metaFixMap, // Keys that will not receive keyup events due to Mac bug downKey, // The key from the keydown event, if it wasn't handled already // Use new Base() to convert into a Base object, for #toString() modifiers = new Base({ shift: false, control: false, alt: false, // WAS: option meta: false, // WAS: command capsLock: false, space: false, }).inject({ // Short-cut to modifiers.alt for backward compatibility option: { get: function () { return this.alt; }, }, // Platform independent short-cut to modifiers.control / meta, // based on whichever key is used for commands. command: { get: function () { var agent = ref.paper && ref.paper.agent; return agent && agent.mac ? this.meta : this.control; }, }, }); function getKey(event) { var key = event.key || event.keyIdentifier; key = /^U\+/.test(key) ? // Expand keyIdentifier Unicode format. String.fromCharCode(parseInt(key.substr(2), 16)) : // Use short version for arrow keys: ArrowLeft -> Left /^Arrow[A-Z]/.test(key) ? key.substr(5) : // This is far from ideal, but what else can we do? key === 'Unidentified' || key === undefined ? String.fromCharCode(event.keyCode) : key; return ( keyLookup[key] || // Hyphenate camel-cased special keys, lower-case normal ones: (key.length > 1 ? Base.hyphenate(key) : key.toLowerCase()) ); } function handleKey(down, key, character, event) { var type = down ? 'keydown' : 'keyup', view = View._focused, name; keyMap[key] = down; // Link the key from keydown with the character form keypress, so keyup // can retrieve the character again. // Use delete instead of setting to null, so charMap only contains keys // that are currently pressed, allowing the use of `key in charMap` // checks and enumeration over pressed keys, e.g. in the blur event. if (down) { charMap[key] = character; } else { delete charMap[key]; } // Detect modifiers and mark them as pressed / released if (key.length > 1 && (name = Base.camelize(key)) in modifiers) { modifiers[name] = down; var agent = ref.paper && ref.paper.agent; if (name === 'meta' && agent && agent.mac) { // Fix a strange behavior on Mac where no keyup events are // received for any keys pressed while the meta key is down. // Keep track of the normal keys being pressed and trigger keyup // events for all these keys when meta is released: if (down) { metaFixMap = {}; } else { for (var k in metaFixMap) { // Make sure it wasn't released already in the meantime: if (k in charMap) handleKey(false, k, metaFixMap[k], event); } metaFixMap = null; } } } else if (down && metaFixMap) { // A normal key, add it to metaFixMap if that's defined. metaFixMap[key] = character; } if (view) { view._handleKeyEvent(down ? 'keydown' : 'keyup', event, key, character); } } DomEvent.add(globalThis.document, { keydown: function (event) { var key = getKey(event), agent = ref.paper && ref.paper.agent; // Directly handle any special keys (key.length > 1) in keydown, as // not all of them will receive keypress events. // Chrome doesn't fire keypress events for command and alt keys, // so we need to handle this in a way that works across all OSes. if ( key.length > 1 || (agent && agent.chrome && (event.altKey || (agent.mac && event.metaKey) || (!agent.mac && event.ctrlKey))) ) { handleKey(true, key, charLookup[key] || (key.length > 1 ? '' : key), event); } else { // If it wasn't handled yet, store the downKey so keypress can // compare and handle buggy edge cases, known to happen in // Chrome on Ubuntu. downKey = key; } }, keypress: function (event) { if (downKey) { var key = getKey(event), code = event.charCode, // Try event.charCode if its above 32 and fall back onto the // key value if it's a single character, empty otherwise. character = code >= 32 ? String.fromCharCode(code) : key.length > 1 ? '' : key; if (key !== downKey) { // This shouldn't happen, but it does in Chrome on Ubuntu. // In these cases, character is actually the key we want! // See #881 key = character.toLowerCase(); } handleKey(true, key, character, event); downKey = null; } }, keyup: function (event) { var key = getKey(event); if (key in charMap) handleKey(false, key, charMap[key], event); }, }); DomEvent.add(globalThis.window, { blur: function (event) { // Emit key-up events for all currently pressed keys. for (var key in charMap) handleKey(false, key, charMap[key], event); }, }); return /** @lends Key */ { /** * The current state of the keyboard modifiers. * * @property * @type Object * * @option modifiers.shift {Boolean} {@true if the shift key is * pressed}. * @option modifiers.control {Boolean} {@true if the control key is * pressed}. * @option modifiers.alt {Boolean} {@true if the alt/option key is * pressed}. * @option modifiers.meta {Boolean} {@true if the meta/windows/command * key is pressed}. * @option modifiers.capsLock {Boolean} {@true if the caps-lock key is * active}. * @option modifiers.space {Boolean} {@true if the space key is * pressed}. * @option modifiers.option {Boolean} {@true if the alt/option key is * pressed}. This is the same as `modifiers.alt` * @option modifiers.command {Boolean} {@true if the meta key is pressed * on Mac, or the control key is pressed on Windows and Linux}. */ modifiers: modifiers, /** * Checks whether the specified key is pressed. * * @param {String} key any character or special key descriptor: * {@values 'enter', 'space', 'shift', 'control', 'alt', 'meta', * 'caps-lock', 'left', 'up', 'right', 'down', 'escape', 'delete', * ...} * @return {Boolean} {@true if the key is pressed} * * @example * // Whenever the user clicks, create a circle shaped path. If the * // 'a' key is pressed, fill it with red, otherwise fill it with blue: * function onMouseDown(event) { * var path = new Path.Circle(event.point, 10); * if (Key.isDown('a')) { * path.fillColor = 'red'; * } else { * path.fillColor = 'blue'; * } * } */ isDown: function (key) { return !!keyMap[key]; }, }; })(); |