@unhingged/vizu-core 0.1.6 → 0.1.8

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.js CHANGED
@@ -380,7 +380,9 @@ var CloudStorageAdapter = class {
380
380
  const payload = params.get("vizu_auth");
381
381
  if (!payload) return null;
382
382
  try {
383
- const json = JSON.parse(atob(payload));
383
+ const bytes = Uint8Array.from(atob(payload), (c) => c.charCodeAt(0));
384
+ const decoded = new TextDecoder("utf-8").decode(bytes);
385
+ const json = JSON.parse(decoded);
384
386
  if (!json.t || !json.e || !json.u || !json.w) return null;
385
387
  if (json.w !== this.workspace) return null;
386
388
  const stored = {
@@ -3180,7 +3182,16 @@ var Vizu = class {
3180
3182
  }
3181
3183
  if (matches(e, this.parsedShortcut)) {
3182
3184
  e.preventDefault();
3185
+ const wasEnabled = this.enabled;
3183
3186
  this.toggle();
3187
+ if (!wasEnabled && this.enabled && this.storage instanceof CloudStorageAdapter) {
3188
+ void this.storage.preflightAuth().catch((err) => {
3189
+ if (err?.code === "auth_canceled" || err?.code === "popup_blocked") return;
3190
+ if (typeof console !== "undefined") {
3191
+ console.warn("[vizu] preflight auth failed:", err);
3192
+ }
3193
+ });
3194
+ }
3184
3195
  }
3185
3196
  };
3186
3197
  /* ===== Reposition on scroll/resize ===== */
@@ -3210,6 +3221,7 @@ var Vizu = class {
3210
3221
  this.opts.namespace = options.namespace ?? DEFAULTS.namespace;
3211
3222
  this.opts.accent = options.accent ?? DEFAULTS.accent;
3212
3223
  this.parsedShortcut = parseShortcut(this.opts.shortcut);
3224
+ this.user = options.user ?? null;
3213
3225
  this.storage = resolveStorage(
3214
3226
  options.storage,
3215
3227
  options.cloud,
@@ -3218,7 +3230,6 @@ var Vizu = class {
3218
3230
  if (info.user) this.setUser(info.user);
3219
3231
  }
3220
3232
  );
3221
- this.user = options.user ?? null;
3222
3233
  if (options.actions) this.actions = [...options.actions];
3223
3234
  if (options.onCommentAdded) this.bus.on("comment:added", (p) => options.onCommentAdded(p.comment));
3224
3235
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
@@ -3269,14 +3280,6 @@ var Vizu = class {
3269
3280
  this.enabled = true;
3270
3281
  this.bus.emit("enabled", {});
3271
3282
  this.deferred(() => this.mount());
3272
- if (this.storage instanceof CloudStorageAdapter) {
3273
- void this.storage.preflightAuth().catch((err) => {
3274
- if (err?.code === "auth_canceled" || err?.code === "popup_blocked") return;
3275
- if (typeof console !== "undefined") {
3276
- console.warn("[vizu] preflight auth failed:", err);
3277
- }
3278
- });
3279
- }
3280
3283
  }
3281
3284
  disable() {
3282
3285
  if (!this.enabled) return;