fluxfiles 0.2.5 → 0.2.7

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
@@ -100,6 +100,14 @@
100
100
  emit('FM_EVENT', msg.payload);
101
101
  break;
102
102
 
103
+ case 'FM_THEME':
104
+ // Runtime theme sync: the embedded UI toggled/resolved its theme.
105
+ // Recolor the SDK-owned modal chrome to match (it can't read the
106
+ // cross-origin iframe's class), then notify subscribers.
107
+ applyChromeTheme(!!(msg.payload && msg.payload.theme === 'dark'));
108
+ emit('FM_THEME', msg.payload);
109
+ break;
110
+
103
111
  case 'FM_CLOSE':
104
112
  if (typeof config.onClose === 'function') {
105
113
  config.onClose();
@@ -116,6 +124,22 @@
116
124
  }
117
125
  }
118
126
 
127
+ // Recolor the SDK-owned modal chrome (window + header) at runtime to match the
128
+ // embedded UI's resolved theme. No-op when embedded in a host `container` (no chrome)
129
+ // or when closed. Colors mirror the boot values above.
130
+ function applyChromeTheme(dark) {
131
+ var modal = document.getElementById('fluxfiles-modal');
132
+ if (!modal) return;
133
+ var bg = dark ? '#2b2b2e' : '#f5f5f7';
134
+ var border = dark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.06)';
135
+ modal.style.background = bg;
136
+ var header = modal.firstElementChild; // header is appended before the body
137
+ if (header) {
138
+ header.style.background = bg;
139
+ header.style.borderBottom = '1px solid ' + border;
140
+ }
141
+ }
142
+
119
143
  var FluxFiles = {
120
144
  open: function(options) {
121
145
  config = options || {};
@@ -148,9 +172,22 @@
148
172
  if (!config.container) {
149
173
  // Theme the modal chrome to match the embedded UI's theme, so dark
150
174
  // mode darkens the window/header too (not just the iframe content).
175
+ // When the theme is auto/unset, mirror the embedded UI's anti-flash
176
+ // boot: prefer the last persisted theme (same localStorage key), then
177
+ // the OS preference — so the header doesn't flash light before a dark
178
+ // theme settles. Persist an explicit theme for the next open.
179
+ var THEME_KEY = 'fluxfiles_theme';
180
+ var storedTheme = null;
181
+ try { storedTheme = window.localStorage && localStorage.getItem(THEME_KEY); } catch (e) {}
182
+ try {
183
+ if (config.theme === 'dark' || config.theme === 'light') localStorage.setItem(THEME_KEY, config.theme);
184
+ } catch (e) {}
151
185
  var chromeDark = config.theme === 'dark' ||
152
- (config.theme !== 'light' && window.matchMedia &&
153
- window.matchMedia('(prefers-color-scheme: dark)').matches);
186
+ (config.theme !== 'light' && (
187
+ storedTheme === 'dark' ||
188
+ (storedTheme !== 'light' && window.matchMedia &&
189
+ window.matchMedia('(prefers-color-scheme: dark)').matches)
190
+ ));
154
191
  var chromeBg = chromeDark ? '#2b2b2e' : '#f5f5f7';
155
192
  var chromeBorder = chromeDark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.06)';
156
193
 
package/fluxfiles.min.js CHANGED
@@ -1 +1 @@
1
- (function(w){"use strict";var M=1,v="fluxfiles",T="clipboard-write; fullscreen",r=null,a={},t={},x=!1,f="",c=!1;function C(){return"ff-"+Math.random().toString(36).substr(2,9)+Date.now().toString(36)}function s(e,n){!r||!r.contentWindow||r.contentWindow.postMessage({source:v,type:e,v:M,id:C(),payload:n||{}},f||"*")}function E(e){if(!(f&&e.origin!==f)){var n=e.data;if(!(!n||n.source!==v))switch(n.type){case"FM_READY":x=!0,s("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),l.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,s("FM_TOKEN_UPDATED",{token:i})):s("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(i){c=!1,console.error("FluxFiles: onTokenRefresh failed",i),s("FM_TOKEN_FAILED",{reason:i.message||"refresh_error"})}):(c=!1,s("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=a[e]||[],m=0;m<i.length;m++)try{i[m](n)}catch(p){console.error("FluxFiles listener error:",p)}}var l={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",T),r.setAttribute("allowfullscreen","true"),t.container)i.appendChild(r);else{var p=t.theme==="dark"||t.theme!=="light"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches,y=p?"#2b2b2e":"#f5f5f7",L=p?"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:"+y+";border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;";var g=document.createElement("div");g.style.cssText="flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid "+L+";background:"+y+";";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 _=function(){o.style.color="rgba(0,0,0,0.55)",o.style.filter="brightness(0.93)"},F=function(){o.style.color="rgba(0,0,0,0)",o.style.filter="none"};o.addEventListener("mouseenter",_),o.addEventListener("mouseleave",F),o.addEventListener("focus",_),o.addEventListener("blur",F),o.addEventListener("click",function(){l.close()}),g.appendChild(o),h.appendChild(g);var b=document.createElement("div");b.style.cssText="flex:1;min-height:0;display:flex;flex-direction:column;",b.appendChild(r),h.appendChild(b),d.appendChild(h),document.body.appendChild(d),d.addEventListener("click",function(k){k.target===d&&l.close()})}window.addEventListener("message",E)},close:function(){x=!1,window.removeEventListener("message",E);var e=document.getElementById("fluxfiles-overlay");e&&e.remove();var n=document.getElementById("fluxfiles-iframe");n&&n.remove(),r=null},command:function(e,n){s("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,x&&r&&s("FM_TOKEN_UPDATED",{token:e})},on:function(e,n){return a[e]||(a[e]=[]),a[e].push(n),function(){l.off(e,n)}},off:function(e,n){a[e]&&(a[e]=a[e].filter(function(i){return i!==n}))}};typeof module<"u"&&module.exports?module.exports=l:typeof define=="function"&&define.amd?define(function(){return l}):w.FluxFiles=l})(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,l={},n={},b=!1,m="",h=!1;function S(){return"ff-"+Math.random().toString(36).substr(2,9)+Date.now().toString(36)}function s(t,e){!a||!a.contentWindow||a.contentWindow.postMessage({source:E,type:t,v:C,id:S(),payload:e||{}},m||"*")}function _(t){if(!(m&&t.origin!==m)){var e=t.data;if(!(!e||e.source!==E))switch(e.type){case"FM_READY":b=!0,s("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}),c("FM_READY",e.payload);break;case"FM_SELECT":typeof n.onSelect=="function"&&n.onSelect(e.payload),c("FM_SELECT",e.payload),d.close();break;case"FM_TOKEN_REFRESH":if(h)break;h=!0,c("FM_TOKEN_REFRESH",e.payload),typeof n.onTokenRefresh=="function"?Promise.resolve().then(function(){return n.onTokenRefresh(e.payload)}).then(function(i){h=!1,i?(n.token=i,s("FM_TOKEN_UPDATED",{token:i})):s("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(i){h=!1,console.error("FluxFiles: onTokenRefresh failed",i),s("FM_TOKEN_FAILED",{reason:i.message||"refresh_error"})}):(h=!1,s("FM_TOKEN_FAILED",{reason:"no_handler"}));break;case"FM_EVENT":c("FM_EVENT",e.payload);break;case"FM_THEME":O(!!(e.payload&&e.payload.theme==="dark")),c("FM_THEME",e.payload);break;case"FM_CLOSE":typeof n.onClose=="function"&&n.onClose(),c("FM_CLOSE",e.payload);break}}}function c(t,e){for(var i=l[t]||[],f=0;f<i.length;f++)try{i[f](e)}catch(r){console.error("FluxFiles listener error:",r)}}function O(t){var e=document.getElementById("fluxfiles-modal");if(e){var i=t?"#2b2b2e":"#f5f5f7",f=t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)";e.style.background=i;var r=e.firstElementChild;r&&(r.style.background=i,r.style.borderBottom="1px solid "+f)}}var d={open:function(t){n=t||{};var e=(n.endpoint||"").replace(/\/+$/,""),i=n.container?document.querySelector(n.container):document.body;try{var f=new URL(e+"/public/index.html");m=f.origin}catch{m=window.location.origin}if(this.close(),a=document.createElement("iframe"),a.id="fluxfiles-iframe",a.src=e+"/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 r="fluxfiles_theme",x=null;try{x=window.localStorage&&localStorage.getItem(r)}catch{}try{(n.theme==="dark"||n.theme==="light")&&localStorage.setItem(r,n.theme)}catch{}var k=n.theme==="dark"||n.theme!=="light"&&(x==="dark"||x!=="light"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches),F=k?"#2b2b2e":"#f5f5f7",R=k?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",u=document.createElement("div");u.id="fluxfiles-overlay",u.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:"+F+";border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;";var v=document.createElement("div");v.style.cssText="flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid "+R+";background:"+F+";";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 w=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",w),o.addEventListener("mouseleave",M),o.addEventListener("focus",w),o.addEventListener("blur",M),o.addEventListener("click",function(){d.close()}),v.appendChild(o),p.appendChild(v);var y=document.createElement("div");y.style.cssText="flex:1;min-height:0;display:flex;flex-direction:column;",y.appendChild(a),p.appendChild(y),u.appendChild(p),document.body.appendChild(u),u.addEventListener("click",function(g){g.target===u&&d.close()})}window.addEventListener("message",_)},close:function(){b=!1,window.removeEventListener("message",_);var t=document.getElementById("fluxfiles-overlay");t&&t.remove();var e=document.getElementById("fluxfiles-iframe");e&&e.remove(),a=null},command:function(t,e){s("FM_COMMAND",Object.assign({action:t},e||{}))},navigate:function(t){this.command("navigate",{path:t})},setDisk:function(t){this.command("setDisk",{disk:t})},refresh:function(){this.command("refresh")},search:function(t){this.command("search",{q:t})},crossCopy:function(t,e){this.command("crossCopy",{dst_disk:t,dst_path:e||""})},crossMove:function(t,e){this.command("crossMove",{dst_disk:t,dst_path:e||""})},aiTag:function(){this.command("aiTag")},setLocale:function(t){this.command("setLocale",{locale:t})},imgUrl:function(t,e){if(!t||!t.img_base)return"";e=e||{};var i=[];return e.width&&i.push("width="+encodeURIComponent(e.width)),e.quality&&i.push("quality="+encodeURIComponent(e.quality)),e.format&&i.push("format="+encodeURIComponent(e.format)),t.img_base+(i.length?"&"+i.join("&"):"")},updateToken:function(t){n.token=t,b&&a&&s("FM_TOKEN_UPDATED",{token:t})},on:function(t,e){return l[t]||(l[t]=[]),l[t].push(e),function(){d.off(t,e)}},off:function(t,e){l[t]&&(l[t]=l[t].filter(function(i){return i!==e}))}};typeof module<"u"&&module.exports?module.exports=d:typeof define=="function"&&define.amd?define(function(){return d}):T.FluxFiles=d})(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.5",
3
+ "version": "0.2.7",
4
4
  "description": "FluxFiles JavaScript SDK — embed the file manager in any web app",
5
5
  "license": "MIT",
6
6
  "main": "fluxfiles.js",