@rnacanvas/utilities 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Installation
2
+
3
+ With `npm`:
4
+
5
+ ```
6
+ npm install @rnacanvas/utilities
7
+ ```
8
+
9
+ # Usage
10
+
11
+ All exports of this package can be accessed as named imports.
12
+
13
+ ```javascript
14
+ // some example imports
15
+ import { detectMacOS } from '@rnacanvas/utilities';
16
+ import { DownloadableFile } from '@rnacanvas/utilities';
17
+ import { KeyBinding } from '@rnacanvas/utilities';
18
+ ```
19
+
20
+ ## `function hasFocus()`
21
+
22
+ The `hasFocus()` function returns `true` if and only if
23
+ the passed in node is the active element of the document.
24
+
25
+ ```javascript
26
+ hasFocus(document.activeElement); // true
27
+
28
+ hasFocus(document.createElement('div')); // false
29
+ ```
30
+
package/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-minimal
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns true if and only if the passed in node
3
+ * contains the active element of the document
4
+ * (or is the active element of the document).
5
+ */
6
+ export declare function containsFocus(node: Node): boolean;
7
+ //# sourceMappingURL=containsFocus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containsFocus.d.ts","sourceRoot":"","sources":["../src/containsFocus.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAMjD"}
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ import { isBeingInteractedWith } from './isBeingInteractedWith';
6
6
  export { isBeingInteractedWith };
7
7
  import { hasFocus } from './hasFocus';
8
8
  export { hasFocus };
9
+ import { containsFocus } from './containsFocus';
10
+ export { containsFocus };
9
11
  import { KeyBinding } from './KeyBinding';
10
12
  export { KeyBinding };
11
13
  import { detectMacOS } from './detectMacOS';
@@ -1 +1 @@
1
- {"version":3,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E,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.utilities=t():e.utilities=t()}(this,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var r in i)e.o(i,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:i[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function i(e){return e.map((e=>({v:e,priority:Math.random()}))).sort(((e,t)=>e.priority-t.priority)).map((({v:e})=>e))}function r(){return!(!document.activeElement||"textarea"!==document.activeElement.tagName.toLowerCase()&&(e=document.activeElement,"input"!==e.tagName.toLowerCase()||"text"!==(null===(t=e.getAttribute("type"))||void 0===t?void 0:t.toLowerCase())));var e,t}e.r(t),e.d(t,{DownloadableFile:()=>d,EventfulSet:()=>u,FiniteStack:()=>m,KeyBinding:()=>c,detectMacOS:()=>l,hasFocus:()=>s,isBeingInteractedWith:()=>o,isURL:()=>g,shuffled:()=>i,userIsTyping:()=>r});let n=new Set;function o(e){return e===document.body||n.has(e)}function s(e){return e===document.activeElement}window.addEventListener("mousedown",(e=>{if(!(e.target instanceof Node))return void(n=new Set);n=new Set;let t=e.target;for(n.add(t);t.parentNode&&!n.has(t.parentNode);)n.add(t.parentNode),t=t.parentNode}));var a,h=function(e,t,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(e):r?r.value:t.get(e)};class c{constructor(e,t,i){this.key=e,this.scope=void 0,a.set(this,void 0),function(e,t,i,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===r?n.call(e,i):n?n.value=i:t.set(e,i)}(this,a,i,"f"),window.addEventListener("keydown",(i=>{var n,s,c,l;i.key.toUpperCase()===e.toUpperCase()&&(void 0===(null===(n=h(this,a,"f"))||void 0===n?void 0:n.altKey)||h(this,a,"f").altKey==i.altKey)&&(void 0===(null===(s=h(this,a,"f"))||void 0===s?void 0:s.shiftKey)||h(this,a,"f").shiftKey==i.shiftKey)&&(void 0===(null===(c=h(this,a,"f"))||void 0===c?void 0:c.ctrlKey)||h(this,a,"f").ctrlKey==i.ctrlKey)&&(void 0===(null===(l=h(this,a,"f"))||void 0===l?void 0:l.metaKey)||h(this,a,"f").metaKey==i.metaKey)&&!r()&&this.scope&&o(this.scope)&&(i.preventDefault(),t())}),{passive:!1})}}function l(){try{return window.navigator.platform.toLowerCase().includes("mac")}catch(e){return!1}}a=new WeakMap;class d{constructor(e){this.textContent=e}downloadAs(e,t){let i=new File([this.textContent],e,{type:t.type}),r=URL.createObjectURL(i),n=document.createElement("a");n.href=r,n.download=i.name,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(r)}}class u{constructor(){this.eventListeners={change:[]},this.underlyingSet=new Set}[Symbol.iterator](){return this.underlyingSet.values()}includes(e){return this.underlyingSet.has(e)}include(e){return this.includes(e)}addAll(e){let t=[...e];0!=t.length&&(t.every((e=>this.includes(e)))||(t.forEach((e=>this.underlyingSet.add(e))),this.callEventListeners("change")))}removeAll(e){let t=[...e];0!=t.length&&(t.every((e=>!this.includes(e)))||(t.forEach((e=>this.underlyingSet.delete(e))),this.callEventListeners("change")))}clear(){0!=this.underlyingSet.size&&(this.underlyingSet.clear(),this.callEventListeners("change"))}addEventListener(e,t){this.eventListeners[e].push(t)}callEventListeners(e){this.eventListeners[e].forEach((e=>e()))}removeEventListener(e,t){this.eventListeners[e]=this.eventListeners[e].filter((e=>e!==t))}}var f,p,v,y,w=function(e,t,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(e):r?r.value:t.get(e)};class m{constructor(e){f.add(this),this.maxSize=e,p.set(this,[]),v.set(this,{change:[]})}get size(){return w(this,p,"f").length}isEmpty(){return 0==this.size}empty(){0!=this.size&&(function(e,t,i,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===r?n.call(e,i):n?n.value=i:t.set(e,i)}(this,p,[],"f"),w(this,f,"m",y).call(this,"change"))}peek(){if(0==this.size)throw new Error("The stack is empty.");return w(this,p,"f")[w(this,p,"f").length-1]}push(e){w(this,p,"f").push(e),this.size>this.maxSize&&w(this,p,"f").shift(),w(this,f,"m",y).call(this,"change")}pop(){if(0==this.size)throw new Error("The stack is empty.");let e=w(this,p,"f").pop();return w(this,f,"m",y).call(this,"change"),e}addEventListener(e,t){w(this,v,"f")[e].push(t)}removeEventListener(e,t){w(this,v,"f")[e]=w(this,v,"f")[e].filter((e=>e!==t))}}function g(e){try{return new URL(e),!0}catch(e){return!1}}return p=new WeakMap,v=new WeakMap,f=new WeakSet,y=function(e){w(this,v,"f")[e].forEach((e=>e()))},t})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.utilities=t():e.utilities=t()}(this,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function i(e){return e.map((e=>({v:e,priority:Math.random()}))).sort(((e,t)=>e.priority-t.priority)).map((({v:e})=>e))}function n(){return!(!document.activeElement||"textarea"!==document.activeElement.tagName.toLowerCase()&&(e=document.activeElement,"input"!==e.tagName.toLowerCase()||"text"!==(null===(t=e.getAttribute("type"))||void 0===t?void 0:t.toLowerCase())));var e,t}e.r(t),e.d(t,{DownloadableFile:()=>u,EventfulSet:()=>f,FiniteStack:()=>g,KeyBinding:()=>l,containsFocus:()=>a,detectMacOS:()=>d,hasFocus:()=>s,isBeingInteractedWith:()=>o,isURL:()=>E,shuffled:()=>i,userIsTyping:()=>n});let r=new Set;function o(e){return e===document.body||r.has(e)}function s(e){return e===document.activeElement}function a(e){return!!document.activeElement&&e.contains(document.activeElement)}window.addEventListener("mousedown",(e=>{if(!(e.target instanceof Node))return void(r=new Set);r=new Set;let t=e.target;for(r.add(t);t.parentNode&&!r.has(t.parentNode);)r.add(t.parentNode),t=t.parentNode}));var c,h=function(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)};class l{constructor(e,t,i){this.key=e,this.scope=void 0,c.set(this,void 0),function(e,t,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?r.call(e,i):r?r.value=i:t.set(e,i)}(this,c,i,"f"),window.addEventListener("keydown",(i=>{var r,s,a,l;i.key.toUpperCase()===e.toUpperCase()&&(void 0===(null===(r=h(this,c,"f"))||void 0===r?void 0:r.altKey)||h(this,c,"f").altKey==i.altKey)&&(void 0===(null===(s=h(this,c,"f"))||void 0===s?void 0:s.shiftKey)||h(this,c,"f").shiftKey==i.shiftKey)&&(void 0===(null===(a=h(this,c,"f"))||void 0===a?void 0:a.ctrlKey)||h(this,c,"f").ctrlKey==i.ctrlKey)&&(void 0===(null===(l=h(this,c,"f"))||void 0===l?void 0:l.metaKey)||h(this,c,"f").metaKey==i.metaKey)&&!n()&&this.scope&&o(this.scope)&&(i.preventDefault(),t())}),{passive:!1})}}function d(){try{return window.navigator.platform.toLowerCase().includes("mac")}catch(e){return!1}}c=new WeakMap;class u{constructor(e){this.textContent=e}downloadAs(e,t){let i=new File([this.textContent],e,{type:t.type}),n=URL.createObjectURL(i),r=document.createElement("a");r.href=n,r.download=i.name,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}}class f{constructor(){this.eventListeners={change:[]},this.underlyingSet=new Set}[Symbol.iterator](){return this.underlyingSet.values()}includes(e){return this.underlyingSet.has(e)}include(e){return this.includes(e)}addAll(e){let t=[...e];0!=t.length&&(t.every((e=>this.includes(e)))||(t.forEach((e=>this.underlyingSet.add(e))),this.callEventListeners("change")))}removeAll(e){let t=[...e];0!=t.length&&(t.every((e=>!this.includes(e)))||(t.forEach((e=>this.underlyingSet.delete(e))),this.callEventListeners("change")))}clear(){0!=this.underlyingSet.size&&(this.underlyingSet.clear(),this.callEventListeners("change"))}addEventListener(e,t){this.eventListeners[e].push(t)}callEventListeners(e){this.eventListeners[e].forEach((e=>e()))}removeEventListener(e,t){this.eventListeners[e]=this.eventListeners[e].filter((e=>e!==t))}}var p,v,y,w,m=function(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)};class g{constructor(e){p.add(this),this.maxSize=e,v.set(this,[]),y.set(this,{change:[]})}get size(){return m(this,v,"f").length}isEmpty(){return 0==this.size}empty(){0!=this.size&&(function(e,t,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?r.call(e,i):r?r.value=i:t.set(e,i)}(this,v,[],"f"),m(this,p,"m",w).call(this,"change"))}peek(){if(0==this.size)throw new Error("The stack is empty.");return m(this,v,"f")[m(this,v,"f").length-1]}push(e){m(this,v,"f").push(e),this.size>this.maxSize&&m(this,v,"f").shift(),m(this,p,"m",w).call(this,"change")}pop(){if(0==this.size)throw new Error("The stack is empty.");let e=m(this,v,"f").pop();return m(this,p,"m",w).call(this,"change"),e}addEventListener(e,t){m(this,y,"f")[e].push(t)}removeEventListener(e,t){m(this,y,"f")[e]=m(this,y,"f")[e].filter((e=>e!==t))}}function E(e){try{return new URL(e),!0}catch(e){return!1}}return v=new WeakMap,y=new WeakMap,p=new WeakSet,w=function(e){m(this,y,"f")[e].forEach((e=>e()))},t})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnacanvas/utilities",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "General utilities",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {