@rnacanvas/utilities 6.0.0 → 6.1.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 +41 -0
- package/dist/detectWindows.d.ts +7 -0
- package/dist/detectWindows.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,6 +109,47 @@ containsFocus(ele1); // true
|
|
|
109
109
|
containsFocus(ele2); // true
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
+
## `class DownloadableFile`
|
|
113
|
+
|
|
114
|
+
Represents a file that can be downloaded by the user.
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
var file = new DownloadableFile('A file.txt', 'Some text.', { type: 'text/plain' });
|
|
118
|
+
|
|
119
|
+
file.name; // "A file.txt"
|
|
120
|
+
file.content; // "Some text."
|
|
121
|
+
file.type; // "text/plain"
|
|
122
|
+
|
|
123
|
+
// download the file for the user
|
|
124
|
+
file.download();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
A blob can be used in place of a string
|
|
128
|
+
for the content of a downloadable file.
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
var blob = new Blob(['<p>Hello</p>'], { type: 'text/html' });
|
|
132
|
+
|
|
133
|
+
var file1 = new DownloadableFile('hello.html', blob);
|
|
134
|
+
|
|
135
|
+
// specifying file type overrides blob type
|
|
136
|
+
var file2 = new DownloadableFile('hello.txt', blob, { type: 'text/plain' });
|
|
137
|
+
|
|
138
|
+
file2.type; // "text/plain"
|
|
139
|
+
file1.type; // "text/html"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
All constructor parameters are optional.
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
var file = new DownloadableFile();
|
|
146
|
+
|
|
147
|
+
// default values
|
|
148
|
+
file.name; // "Unnamed.txt"
|
|
149
|
+
file.content; // ""
|
|
150
|
+
file.type; // "text/plain"
|
|
151
|
+
```
|
|
152
|
+
|
|
112
153
|
## `class KeyBinding`
|
|
113
154
|
|
|
114
155
|
The `KeyBinding` class represents a key binding.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectWindows.d.ts","sourceRoot":"","sources":["../src/detectWindows.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { containsFocus } from './containsFocus';
|
|
|
10
10
|
export { containsFocus };
|
|
11
11
|
import { KeyBinding } from '@rnacanvas/key-bindings';
|
|
12
12
|
export { KeyBinding };
|
|
13
|
+
import { detectWindows } from './detectWindows';
|
|
14
|
+
export { detectWindows };
|
|
13
15
|
import { detectMacOS } from './detectMacOS';
|
|
14
16
|
export { detectMacOS };
|
|
15
17
|
import { DownloadableFile } from './DownloadableFile';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,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,yBAAyB,CAAC;AACrD,OAAO,EAAE,U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C;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,()=>(()=>{var e={992:function(e){var t;t=()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[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={};e.r(t),e.d(t,{KeyBinding:()=>p});var r,n,i,o,s,a,l,c,h,u,d=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r},f=function(e,t,r,n){if("a"===r&&!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"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};class p{constructor(e,t,a){r.add(this),this.key=e,n.set(this,void 0),i.set(this,void 0),o.set(this,void 0),s.set(this,void 0),d(this,n,t,"f"),d(this,i,e=>f(this,r,"m",u).call(this,e),"f"),d(this,o,a,"f")}get owner(){return f(this,s,"f")}set owner(e){var t;null===(t=f(this,s,"f"))||void 0===t||t.removeEventListener("keydown",f(this,i,"f")),null==e||e.addEventListener("keydown",f(this,i,"f"),{passive:!1}),d(this,s,e,"f")}}return n=new WeakMap,i=new WeakMap,o=new WeakMap,s=new WeakMap,r=new WeakSet,a=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.altKey)&&void 0!==t&&t},l=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.ctrlKey)&&void 0!==t&&t},c=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.metaKey)&&void 0!==t&&t},h=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.shiftKey)&&void 0!==t&&t},u=function(e){this.owner&&this.owner===document.activeElement&&e.key.toUpperCase()===this.key.toUpperCase()&&e.altKey===f(this,r,"a",a)&&e.ctrlKey===f(this,r,"a",l)&&e.metaKey===f(this,r,"a",c)&&e.shiftKey===f(this,r,"a",h)&&(e.preventDefault(),f(this,n,"f").call(this))},t})(),e.exports=t()}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";function e(e){return e.split(/\r\n|\r|\n/)}function t(e){try{return JSON.stringify(e),!0}catch(e){return!1}}function i(e){return e.map(e=>({v:e,priority:Math.random()})).sort((e,t)=>e.priority-t.priority).map(({v:e})=>e)}function o(e){return e===document.activeElement}function s(e){return!!document.activeElement&&e.contains(document.activeElement)}r.r(n),r.d(n,{DownloadableFile:()=>
|
|
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,()=>(()=>{var e={992:function(e){var t;t=()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[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={};e.r(t),e.d(t,{KeyBinding:()=>p});var r,n,i,o,s,a,l,c,h,u,d=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r},f=function(e,t,r,n){if("a"===r&&!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"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};class p{constructor(e,t,a){r.add(this),this.key=e,n.set(this,void 0),i.set(this,void 0),o.set(this,void 0),s.set(this,void 0),d(this,n,t,"f"),d(this,i,e=>f(this,r,"m",u).call(this,e),"f"),d(this,o,a,"f")}get owner(){return f(this,s,"f")}set owner(e){var t;null===(t=f(this,s,"f"))||void 0===t||t.removeEventListener("keydown",f(this,i,"f")),null==e||e.addEventListener("keydown",f(this,i,"f"),{passive:!1}),d(this,s,e,"f")}}return n=new WeakMap,i=new WeakMap,o=new WeakMap,s=new WeakMap,r=new WeakSet,a=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.altKey)&&void 0!==t&&t},l=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.ctrlKey)&&void 0!==t&&t},c=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.metaKey)&&void 0!==t&&t},h=function(){var e,t;return null!==(t=null===(e=f(this,o,"f"))||void 0===e?void 0:e.shiftKey)&&void 0!==t&&t},u=function(e){this.owner&&this.owner===document.activeElement&&e.key.toUpperCase()===this.key.toUpperCase()&&e.altKey===f(this,r,"a",a)&&e.ctrlKey===f(this,r,"a",l)&&e.metaKey===f(this,r,"a",c)&&e.shiftKey===f(this,r,"a",h)&&(e.preventDefault(),f(this,n,"f").call(this))},t})(),e.exports=t()}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";function e(e){return e.split(/\r\n|\r|\n/)}function t(e){try{return JSON.stringify(e),!0}catch(e){return!1}}function i(e){return e.map(e=>({v:e,priority:Math.random()})).sort((e,t)=>e.priority-t.priority).map(({v:e})=>e)}function o(e){return e===document.activeElement}function s(e){return!!document.activeElement&&e.contains(document.activeElement)}r.r(n),r.d(n,{DownloadableFile:()=>f,EventfulSet:()=>p,FiniteStack:()=>b,KeyBinding:()=>a.KeyBinding,containsFocus:()=>s,detectMacOS:()=>c,detectWindows:()=>l,hasFocus:()=>o,isJSONSerializable:()=>t,isURL:()=>E,shuffled:()=>i,splitLines:()=>e});var a=r(992);function l(){return-1!==navigator.userAgent.indexOf("Windows")}function c(){try{return window.navigator.platform.toLowerCase().includes("mac")}catch(e){return!1}}var h,u=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r},d=function(e,t,r,n){if("a"===r&&!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"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};class f{constructor(e,t,r){h.set(this,void 0),this.name=null!=e?e:"Unnamed.txt",this.content=null!=t?t:"",u(this,h,null==r?void 0:r.type,"f")}get type(){return null!=d(this,h,"f")?d(this,h,"f"):this.content instanceof Blob?this.content.type:"text/plain"}set type(e){u(this,h,e,"f")}download(){let e=new File([this.content],this.name,{type:this.type}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download=e.name,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(t)}}h=new WeakMap;class p{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 v,y,w,m,g=function(e,t,r,n){if("a"===r&&!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"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};class b{constructor(e){v.add(this),this.maxSize=e,y.set(this,[]),w.set(this,{change:[]})}get size(){return g(this,y,"f").length}isEmpty(){return 0==this.size}empty(){0!=this.size&&(function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?i.call(e,r):i?i.value=r:t.set(e,r)}(this,y,[],"f"),g(this,v,"m",m).call(this,"change"))}peek(){if(0==this.size)throw new Error("The stack is empty.");return g(this,y,"f")[g(this,y,"f").length-1]}push(e){g(this,y,"f").push(e),this.size>this.maxSize&&g(this,y,"f").shift(),g(this,v,"m",m).call(this,"change")}pop(){if(0==this.size)throw new Error("The stack is empty.");let e=g(this,y,"f").pop();return g(this,v,"m",m).call(this,"change"),e}addEventListener(e,t){g(this,w,"f")[e].push(t)}removeEventListener(e,t){g(this,w,"f")[e]=g(this,w,"f")[e].filter(e=>e!==t)}}function E(e){try{return new URL(e),!0}catch(e){return!1}}y=new WeakMap,w=new WeakMap,v=new WeakSet,m=function(e){g(this,w,"f")[e].forEach(e=>e())}})(),n})());
|