fluxfiles 0.2.4 → 0.2.6

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/fluxfiles.js CHANGED
@@ -146,6 +146,27 @@
146
146
  iframe.setAttribute('allowfullscreen', 'true');
147
147
 
148
148
  if (!config.container) {
149
+ // Theme the modal chrome to match the embedded UI's theme, so dark
150
+ // mode darkens the window/header too (not just the iframe content).
151
+ // When the theme is auto/unset, mirror the embedded UI's anti-flash
152
+ // boot: prefer the last persisted theme (same localStorage key), then
153
+ // the OS preference — so the header doesn't flash light before a dark
154
+ // theme settles. Persist an explicit theme for the next open.
155
+ var THEME_KEY = 'fluxfiles_theme';
156
+ var storedTheme = null;
157
+ try { storedTheme = window.localStorage && localStorage.getItem(THEME_KEY); } catch (e) {}
158
+ try {
159
+ if (config.theme === 'dark' || config.theme === 'light') localStorage.setItem(THEME_KEY, config.theme);
160
+ } catch (e) {}
161
+ var chromeDark = config.theme === 'dark' ||
162
+ (config.theme !== 'light' && (
163
+ storedTheme === 'dark' ||
164
+ (storedTheme !== 'light' && window.matchMedia &&
165
+ window.matchMedia('(prefers-color-scheme: dark)').matches)
166
+ ));
167
+ var chromeBg = chromeDark ? '#2b2b2e' : '#f5f5f7';
168
+ var chromeBorder = chromeDark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.06)';
169
+
149
170
  // Modal overlay — UI scaled down 5% (icons, text, spacing)
150
171
  var overlay = document.createElement('div');
151
172
  overlay.id = 'fluxfiles-overlay';
@@ -153,11 +174,11 @@
153
174
 
154
175
  var modal = document.createElement('div');
155
176
  modal.id = 'fluxfiles-modal';
156
- modal.style.cssText = 'width:90vw;height:85vh;max-width:1200px;background:#f5f5f7;border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;';
177
+ modal.style.cssText = 'width:90vw;height:85vh;max-width:1200px;background:' + chromeBg + ';border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;';
157
178
 
158
179
  // Header — macOS-style red close button (left) with × icon
159
180
  var header = document.createElement('div');
160
- header.style.cssText = 'flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid rgba(0,0,0,0.06);background:#f5f5f7;';
181
+ header.style.cssText = 'flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid ' + chromeBorder + ';background:' + chromeBg + ';';
161
182
  var closeBtn = document.createElement('button');
162
183
  closeBtn.type = 'button';
163
184
  closeBtn.setAttribute('aria-label', 'Close');
package/fluxfiles.min.js CHANGED
@@ -1 +1 @@
1
- (function(F){"use strict";var k=1,b="fluxfiles",w="clipboard-write; fullscreen",r=null,s={},t={},h=!1,f="",c=!1;function M(){return"ff-"+Math.random().toString(36).substr(2,9)+Date.now().toString(36)}function l(e,n){!r||!r.contentWindow||r.contentWindow.postMessage({source:b,type:e,v:k,id:M(),payload:n||{}},f||"*")}function v(e){if(!(f&&e.origin!==f)){var n=e.data;if(!(!n||n.source!==b))switch(n.type){case"FM_READY":h=!0,l("FM_CONFIG",{disk:t.disk||"local",disks:t.disks||["local"],token:t.token||"",path:t.path||"",mode:t.mode||"picker",multiple:!!t.multiple,allowedTypes:t.allowedTypes||null,maxUploadMb:typeof t.maxUploadMb=="number"?t.maxUploadMb:typeof t.maxSize=="number"?Math.round(t.maxSize/(1024*1024)):null,maxFiles:typeof t.maxFiles=="number"?t.maxFiles:null,endpoint:t.endpoint||"",locale:t.locale||null,theme:t.theme||null}),u("FM_READY",n.payload);break;case"FM_SELECT":typeof t.onSelect=="function"&&t.onSelect(n.payload),u("FM_SELECT",n.payload),d.close();break;case"FM_TOKEN_REFRESH":if(c)break;c=!0,u("FM_TOKEN_REFRESH",n.payload),typeof t.onTokenRefresh=="function"?Promise.resolve().then(function(){return t.onTokenRefresh(n.payload)}).then(function(i){c=!1,i?(t.token=i,l("FM_TOKEN_UPDATED",{token:i})):l("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(i){c=!1,console.error("FluxFiles: onTokenRefresh failed",i),l("FM_TOKEN_FAILED",{reason:i.message||"refresh_error"})}):(c=!1,l("FM_TOKEN_FAILED",{reason:"no_handler"}));break;case"FM_EVENT":u("FM_EVENT",n.payload);break;case"FM_CLOSE":typeof t.onClose=="function"&&t.onClose(),u("FM_CLOSE",n.payload);break}}}function u(e,n){for(var i=s[e]||[],m=0;m<i.length;m++)try{i[m](n)}catch(a){console.error("FluxFiles listener error:",a)}}var d={open:function(e){t=e||{};var n=(t.endpoint||"").replace(/\/+$/,""),i=t.container?document.querySelector(t.container):document.body;try{var m=new URL(n+"/public/index.html");f=m.origin}catch{f=window.location.origin}if(this.close(),r=document.createElement("iframe"),r.id="fluxfiles-iframe",r.src=n+"/public/index.html",r.style.cssText="width:100%;height:100%;border:none;",r.setAttribute("allow",w),r.setAttribute("allowfullscreen","true"),t.container)i.appendChild(r);else{var a=document.createElement("div");a.id="fluxfiles-overlay",a.style.cssText="position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:99999;display:flex;align-items:center;justify-content:center;";var p=document.createElement("div");p.id="fluxfiles-modal",p.style.cssText="width:90vw;height:85vh;max-width:1200px;background:#f5f5f7;border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;";var x=document.createElement("div");x.style.cssText="flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid rgba(0,0,0,0.06);background:#f5f5f7;";var o=document.createElement("button");o.type="button",o.setAttribute("aria-label","Close"),o.style.cssText="width:13px;height:13px;padding:0;border:none;border-radius:50%;background:#ff5f57;box-shadow:inset 0 0 0 0.5px rgba(0,0,0,0.14);color:rgba(0,0,0,0);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:11px;line-height:1;font-weight:700;transition:filter .15s,color .15s;flex-shrink:0;",o.textContent="\xD7";var E=function(){o.style.color="rgba(0,0,0,0.55)",o.style.filter="brightness(0.93)"},y=function(){o.style.color="rgba(0,0,0,0)",o.style.filter="none"};o.addEventListener("mouseenter",E),o.addEventListener("mouseleave",y),o.addEventListener("focus",E),o.addEventListener("blur",y),o.addEventListener("click",function(){d.close()}),x.appendChild(o),p.appendChild(x);var g=document.createElement("div");g.style.cssText="flex:1;min-height:0;display:flex;flex-direction:column;",g.appendChild(r),p.appendChild(g),a.appendChild(p),document.body.appendChild(a),a.addEventListener("click",function(_){_.target===a&&d.close()})}window.addEventListener("message",v)},close:function(){h=!1,window.removeEventListener("message",v);var e=document.getElementById("fluxfiles-overlay");e&&e.remove();var n=document.getElementById("fluxfiles-iframe");n&&n.remove(),r=null},command:function(e,n){l("FM_COMMAND",Object.assign({action:e},n||{}))},navigate:function(e){this.command("navigate",{path:e})},setDisk:function(e){this.command("setDisk",{disk:e})},refresh:function(){this.command("refresh")},search:function(e){this.command("search",{q:e})},crossCopy:function(e,n){this.command("crossCopy",{dst_disk:e,dst_path:n||""})},crossMove:function(e,n){this.command("crossMove",{dst_disk:e,dst_path:n||""})},aiTag:function(){this.command("aiTag")},setLocale:function(e){this.command("setLocale",{locale:e})},imgUrl:function(e,n){if(!e||!e.img_base)return"";n=n||{};var i=[];return n.width&&i.push("width="+encodeURIComponent(n.width)),n.quality&&i.push("quality="+encodeURIComponent(n.quality)),n.format&&i.push("format="+encodeURIComponent(n.format)),e.img_base+(i.length?"&"+i.join("&"):"")},updateToken:function(e){t.token=e,h&&r&&l("FM_TOKEN_UPDATED",{token:e})},on:function(e,n){return s[e]||(s[e]=[]),s[e].push(n),function(){d.off(e,n)}},off:function(e,n){s[e]&&(s[e]=s[e].filter(function(i){return i!==n}))}};typeof module<"u"&&module.exports?module.exports=d:typeof define=="function"&&define.amd?define(function(){return d}):F.FluxFiles=d})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this);
1
+ (function(T){"use strict";var C=1,E="fluxfiles",L="clipboard-write; fullscreen",a=null,r={},n={},x=!1,f="",c=!1;function S(){return"ff-"+Math.random().toString(36).substr(2,9)+Date.now().toString(36)}function l(e,t){!a||!a.contentWindow||a.contentWindow.postMessage({source:E,type:e,v:C,id:S(),payload:t||{}},f||"*")}function _(e){if(!(f&&e.origin!==f)){var t=e.data;if(!(!t||t.source!==E))switch(t.type){case"FM_READY":x=!0,l("FM_CONFIG",{disk:n.disk||"local",disks:n.disks||["local"],token:n.token||"",path:n.path||"",mode:n.mode||"picker",multiple:!!n.multiple,allowedTypes:n.allowedTypes||null,maxUploadMb:typeof n.maxUploadMb=="number"?n.maxUploadMb:typeof n.maxSize=="number"?Math.round(n.maxSize/(1024*1024)):null,maxFiles:typeof n.maxFiles=="number"?n.maxFiles:null,endpoint:n.endpoint||"",locale:n.locale||null,theme:n.theme||null}),u("FM_READY",t.payload);break;case"FM_SELECT":typeof n.onSelect=="function"&&n.onSelect(t.payload),u("FM_SELECT",t.payload),s.close();break;case"FM_TOKEN_REFRESH":if(c)break;c=!0,u("FM_TOKEN_REFRESH",t.payload),typeof n.onTokenRefresh=="function"?Promise.resolve().then(function(){return n.onTokenRefresh(t.payload)}).then(function(i){c=!1,i?(n.token=i,l("FM_TOKEN_UPDATED",{token:i})):l("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(i){c=!1,console.error("FluxFiles: onTokenRefresh failed",i),l("FM_TOKEN_FAILED",{reason:i.message||"refresh_error"})}):(c=!1,l("FM_TOKEN_FAILED",{reason:"no_handler"}));break;case"FM_EVENT":u("FM_EVENT",t.payload);break;case"FM_CLOSE":typeof n.onClose=="function"&&n.onClose(),u("FM_CLOSE",t.payload);break}}}function u(e,t){for(var i=r[e]||[],m=0;m<i.length;m++)try{i[m](t)}catch(p){console.error("FluxFiles listener error:",p)}}var s={open:function(e){n=e||{};var t=(n.endpoint||"").replace(/\/+$/,""),i=n.container?document.querySelector(n.container):document.body;try{var m=new URL(t+"/public/index.html");f=m.origin}catch{f=window.location.origin}if(this.close(),a=document.createElement("iframe"),a.id="fluxfiles-iframe",a.src=t+"/public/index.html",a.style.cssText="width:100%;height:100%;border:none;",a.setAttribute("allow",L),a.setAttribute("allowfullscreen","true"),n.container)i.appendChild(a);else{var p="fluxfiles_theme",v=null;try{v=window.localStorage&&localStorage.getItem(p)}catch{}try{(n.theme==="dark"||n.theme==="light")&&localStorage.setItem(p,n.theme)}catch{}var k=n.theme==="dark"||n.theme!=="light"&&(v==="dark"||v!=="light"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches),w=k?"#2b2b2e":"#f5f5f7",O=k?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",d=document.createElement("div");d.id="fluxfiles-overlay",d.style.cssText="position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:99999;display:flex;align-items:center;justify-content:center;";var h=document.createElement("div");h.id="fluxfiles-modal",h.style.cssText="width:90vw;height:85vh;max-width:1200px;background:"+w+";border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;";var b=document.createElement("div");b.style.cssText="flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid "+O+";background:"+w+";";var o=document.createElement("button");o.type="button",o.setAttribute("aria-label","Close"),o.style.cssText="width:13px;height:13px;padding:0;border:none;border-radius:50%;background:#ff5f57;box-shadow:inset 0 0 0 0.5px rgba(0,0,0,0.14);color:rgba(0,0,0,0);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:11px;line-height:1;font-weight:700;transition:filter .15s,color .15s;flex-shrink:0;",o.textContent="\xD7";var F=function(){o.style.color="rgba(0,0,0,0.55)",o.style.filter="brightness(0.93)"},M=function(){o.style.color="rgba(0,0,0,0)",o.style.filter="none"};o.addEventListener("mouseenter",F),o.addEventListener("mouseleave",M),o.addEventListener("focus",F),o.addEventListener("blur",M),o.addEventListener("click",function(){s.close()}),b.appendChild(o),h.appendChild(b);var y=document.createElement("div");y.style.cssText="flex:1;min-height:0;display:flex;flex-direction:column;",y.appendChild(a),h.appendChild(y),d.appendChild(h),document.body.appendChild(d),d.addEventListener("click",function(g){g.target===d&&s.close()})}window.addEventListener("message",_)},close:function(){x=!1,window.removeEventListener("message",_);var e=document.getElementById("fluxfiles-overlay");e&&e.remove();var t=document.getElementById("fluxfiles-iframe");t&&t.remove(),a=null},command:function(e,t){l("FM_COMMAND",Object.assign({action:e},t||{}))},navigate:function(e){this.command("navigate",{path:e})},setDisk:function(e){this.command("setDisk",{disk:e})},refresh:function(){this.command("refresh")},search:function(e){this.command("search",{q:e})},crossCopy:function(e,t){this.command("crossCopy",{dst_disk:e,dst_path:t||""})},crossMove:function(e,t){this.command("crossMove",{dst_disk:e,dst_path:t||""})},aiTag:function(){this.command("aiTag")},setLocale:function(e){this.command("setLocale",{locale:e})},imgUrl:function(e,t){if(!e||!e.img_base)return"";t=t||{};var i=[];return t.width&&i.push("width="+encodeURIComponent(t.width)),t.quality&&i.push("quality="+encodeURIComponent(t.quality)),t.format&&i.push("format="+encodeURIComponent(t.format)),e.img_base+(i.length?"&"+i.join("&"):"")},updateToken:function(e){n.token=e,x&&a&&l("FM_TOKEN_UPDATED",{token:e})},on:function(e,t){return r[e]||(r[e]=[]),r[e].push(t),function(){s.off(e,t)}},off:function(e,t){r[e]&&(r[e]=r[e].filter(function(i){return i!==t}))}};typeof module<"u"&&module.exports?module.exports=s:typeof define=="function"&&define.amd?define(function(){return s}):T.FluxFiles=s})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluxfiles",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "FluxFiles JavaScript SDK — embed the file manager in any web app",
5
5
  "license": "MIT",
6
6
  "main": "fluxfiles.js",