@bloklabs/presets 1.15.2 → 1.16.1
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/dist/index.cjs +1 -1
- package/dist/index.mjs +6 -6
- package/package.json +1 -1
- package/types/index.d.ts +5 -0
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return new Promise((t,n)=>{var r;let i=new XMLHttpRequest;i.open(e.method,e.url);for(let[t,n]of Object.entries((r=e.headers)==null?{}:r))i.setRequestHeader(t,n);e.onProgress&&(i.upload.onprogress=t=>{var n
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return new Promise((t,n)=>{var r;let i=new XMLHttpRequest;i.open(e.method,e.url);for(let[t,n]of Object.entries((r=e.headers)==null?{}:r))i.setRequestHeader(t,n);e.onProgress&&(i.upload.onprogress=t=>{var n;t.lengthComputable&&t.total!==0&&((n=e.onProgress)==null||n.call(e,Math.round(t.loaded/t.total*100)))}),i.onload=()=>t({status:i.status,text:i.responseText}),i.onerror=()=>n(Error(`Upload failed: network error`)),i.send(e.body)})}function t(e){"@babel/helpers - typeof";return t=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t(e)}function n(e,n){if(t(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n||`default`);if(t(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(e)}function r(e){var r=n(e,`string`);return t(r)==`symbol`?r:r+``}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?a(Object(n),!0).forEach(function(t){i(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function s(e){let t=Array.from(e).reduce((e,t)=>t===`/`?e+1:0,0);return e.slice(0,e.length-t)}function c(t){var n;let r=s(t.baseUrl),i=(n=t.field)==null?`file`:n,a=async()=>{var e;return typeof t.headers==`function`?t.headers():(e=t.headers)==null?{}:e};return{async uploadByFile(t,n){let o=new FormData;o.append(i,t);let{status:s,text:c}=await e({method:`POST`,url:`${r}/upload`,body:o,headers:await a(),onProgress:n.onProgress});if(s<200||s>299)throw Error(`Fetch endpoint upload failed with status ${s}`);return l(c,t.name)},async uploadByUrl(e,t){let n=await fetch(`${r}/upload-by-url`,{method:`POST`,headers:o(o({},await a()),{},{"Content-Type":`application/json`}),body:JSON.stringify({url:e})});if(!n.ok)throw Error(`Fetch endpoint upload failed with status ${n.status}`);return d(u(await n.text()))},async delete(e,t){let n=await fetch(`${r}/delete`,{method:`POST`,headers:o(o({},await a()),{},{"Content-Type":`application/json`}),body:JSON.stringify({url:e})});if(!n.ok)throw Error(`Fetch endpoint delete failed with status ${n.status}`)}}}function l(e,t){var n;let r=d(u(e));return{url:r.url,fileName:(n=r.fileName)==null?t:n}}function u(e){try{return JSON.parse(e)}catch(e){throw Error(`Upload failed: the endpoint returned a malformed response`)}}function d(e){if(typeof e!=`object`||!e||typeof e.url!=`string`)throw Error(`Upload failed: the endpoint returned no url`);let t=e;return{url:t.url,fileName:typeof t.fileName==`string`?t.fileName:void 0}}function f(e){return c(e)}function p(e,t={}){let n=e=>{var n;return typeof t.bucket==`function`?t.bucket(e):(n=t.bucket)==null?`blok`:n};return{async uploadByFile(r,i){var a,o;let s=(a=(o=t.path)==null?void 0:o.call(t,r,i))==null?m(r.name):a,{data:c,error:l}=await e.storage.from(n(i.kind)).upload(s,r,{contentType:r.type||void 0,upsert:!1});if(l!==null||c===null){var u;throw Error(`Supabase upload failed: ${(u=l==null?void 0:l.message)==null?`unknown error`:u}`)}let{data:d}=e.storage.from(n(i.kind)).getPublicUrl(c.path);return{url:d.publicUrl,fileName:r.name}}}}function m(e){let t=/\.[a-z0-9]+$/i.exec(e),n=t?t[0].toLowerCase():``;return`${crypto.randomUUID()}${n}`}function h(t){return{async uploadByFile(n,r){let i=await t.sign({fileName:n.name,mimeType:n.type,size:n.size,kind:r.kind}),{status:a}=await e({method:`PUT`,url:i.uploadUrl,body:n,headers:o(o({},i.headers),{},{"Content-Type":n.type||`application/octet-stream`}),onProgress:r.onProgress});if(a<200||a>299)throw Error(`Presigned upload failed with status ${a}`);return{url:i.publicUrl,fileName:n.name}}}}var g={image:`image`,video:`video`,audio:`video`,file:`raw`};function _(t){let n=e=>{var n;return`https://api.cloudinary.com/v1_1/${t.cloudName}/${(n=g[e])==null?`raw`:n}/upload`},r=async(r,i,a)=>{let o=new FormData;o.append(`file`,i),o.append(`upload_preset`,t.uploadPreset),t.folder!==void 0&&o.append(`folder`,t.folder);let{status:s,text:c}=await e({method:`POST`,url:n(r),body:o,onProgress:a});return v(c,s,typeof i==`string`?void 0:i.name)};return{uploadByFile:(e,t)=>r(t.kind,e,t.onProgress),uploadByUrl:(e,t)=>r(t.kind,e,t.onProgress)}}function v(e,t,n){let r=y(e,t);if(typeof r.secure_url!=`string`){var i;let e=r.error;throw Error(`Cloudinary upload failed: ${(i=e==null?void 0:e.message)==null?`status ${t}`:i}`)}return{url:r.secure_url,fileName:n}}function y(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Cloudinary upload failed with status ${t}`)}}var b=`blok-assets`,x=`assets`,S=`blok:asset/`;function C(e){return new Promise((t,n)=>{let r=indexedDB.open(e,1);r.onupgradeneeded=()=>{r.result.createObjectStore(x)},r.onsuccess=()=>t(r.result),r.onerror=()=>{var e;return n((e=r.error)==null?Error(`IndexedDB open failed`):e)}})}function w(e,t,n){return new Promise((r,i)=>{let a=n(e.transaction(x,t).objectStore(x));a.onsuccess=()=>r(a.result),a.onerror=()=>{var e;return i((e=a.error)==null?Error(`IndexedDB request failed`):e)}})}function T(e={}){var t;let n=(t=e.dbName)==null?b:t;return{async uploadByFile(e,t){let r=crypto.randomUUID(),i=await C(n);try{await w(i,`readwrite`,t=>t.put({blob:e,name:e.name,type:e.type},r))}finally{i.close()}return{url:`${S}${r}`,fileName:e.name}}}}async function E(e,t={}){var n;if(!e.startsWith(S))return e;let r=await D(await C((n=t.dbName)==null?b:n),e.slice(11));return r?URL.createObjectURL(r.blob):null}function D(e,t){return w(e,`readonly`,e=>e.get(t)).finally(()=>e.close())}exports.cloudinaryStorage=_,exports.fetchStorage=f,exports.indexedDBStorage=T,exports.presignedStorage=h,exports.resolveBlokObjectUrl=E,exports.supabaseStorage=p;
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ function e(e) {
|
|
|
7
7
|
for (let [t, n] of Object.entries((r = e.headers) == null ? {} : r)) i.setRequestHeader(t, n);
|
|
8
8
|
e.onProgress && (i.upload.onprogress = (t) => {
|
|
9
9
|
var n;
|
|
10
|
-
|
|
10
|
+
t.lengthComputable && t.total !== 0 && ((n = e.onProgress) == null || n.call(e, Math.round(t.loaded / t.total * 100)));
|
|
11
11
|
}), i.onload = () => t({
|
|
12
12
|
status: i.status,
|
|
13
13
|
text: i.responseText
|
|
@@ -15,7 +15,7 @@ function e(e) {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
|
-
//#region \0@oxc-project+runtime@0.
|
|
18
|
+
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/typeof.js
|
|
19
19
|
function t(e) {
|
|
20
20
|
"@babel/helpers - typeof";
|
|
21
21
|
return t = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
@@ -25,7 +25,7 @@ function t(e) {
|
|
|
25
25
|
}, t(e);
|
|
26
26
|
}
|
|
27
27
|
//#endregion
|
|
28
|
-
//#region \0@oxc-project+runtime@0.
|
|
28
|
+
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPrimitive.js
|
|
29
29
|
function n(e, n) {
|
|
30
30
|
if (t(e) != "object" || !e) return e;
|
|
31
31
|
var r = e[Symbol.toPrimitive];
|
|
@@ -37,13 +37,13 @@ function n(e, n) {
|
|
|
37
37
|
return (n === "string" ? String : Number)(e);
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
|
-
//#region \0@oxc-project+runtime@0.
|
|
40
|
+
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPropertyKey.js
|
|
41
41
|
function r(e) {
|
|
42
42
|
var r = n(e, "string");
|
|
43
43
|
return t(r) == "symbol" ? r : r + "";
|
|
44
44
|
}
|
|
45
45
|
//#endregion
|
|
46
|
-
//#region \0@oxc-project+runtime@0.
|
|
46
|
+
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/defineProperty.js
|
|
47
47
|
function i(e, t, n) {
|
|
48
48
|
return (t = r(t)) in e ? Object.defineProperty(e, t, {
|
|
49
49
|
value: n,
|
|
@@ -53,7 +53,7 @@ function i(e, t, n) {
|
|
|
53
53
|
}) : e[t] = n, e;
|
|
54
54
|
}
|
|
55
55
|
//#endregion
|
|
56
|
-
//#region \0@oxc-project+runtime@0.
|
|
56
|
+
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/objectSpread2.js
|
|
57
57
|
function a(e, t) {
|
|
58
58
|
var n = Object.keys(e);
|
|
59
59
|
if (Object.getOwnPropertySymbols) {
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -42,6 +42,11 @@ interface UploadContext {
|
|
|
42
42
|
tool?: string;
|
|
43
43
|
/** Upload progress in percent (0–100), when the host reports it. */
|
|
44
44
|
onProgress?(percent: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set when this upload is one of several renditions of the same asset.
|
|
47
|
+
* `role: 'original'` is the untouched file the user picked.
|
|
48
|
+
*/
|
|
49
|
+
variant?: { mimeType: string; role: 'original' | 'variant' };
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
/**
|