@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.cjs CHANGED
@@ -416,7 +416,9 @@ var CloudStorageAdapter = class {
416
416
  const payload = params.get("vizu_auth");
417
417
  if (!payload) return null;
418
418
  try {
419
- const json = JSON.parse(atob(payload));
419
+ const bytes = Uint8Array.from(atob(payload), (c) => c.charCodeAt(0));
420
+ const decoded = new TextDecoder("utf-8").decode(bytes);
421
+ const json = JSON.parse(decoded);
420
422
  if (!json.t || !json.e || !json.u || !json.w) return null;
421
423
  if (json.w !== this.workspace) return null;
422
424
  const stored = {
@@ -3216,7 +3218,16 @@ var Vizu = class {
3216
3218
  }
3217
3219
  if (matches(e, this.parsedShortcut)) {
3218
3220
  e.preventDefault();
3221
+ const wasEnabled = this.enabled;
3219
3222
  this.toggle();
3223
+ if (!wasEnabled && this.enabled && this.storage instanceof CloudStorageAdapter) {
3224
+ void this.storage.preflightAuth().catch((err) => {
3225
+ if (err?.code === "auth_canceled" || err?.code === "popup_blocked") return;
3226
+ if (typeof console !== "undefined") {
3227
+ console.warn("[vizu] preflight auth failed:", err);
3228
+ }
3229
+ });
3230
+ }
3220
3231
  }
3221
3232
  };
3222
3233
  /* ===== Reposition on scroll/resize ===== */
@@ -3246,6 +3257,7 @@ var Vizu = class {
3246
3257
  this.opts.namespace = options.namespace ?? DEFAULTS.namespace;
3247
3258
  this.opts.accent = options.accent ?? DEFAULTS.accent;
3248
3259
  this.parsedShortcut = parseShortcut(this.opts.shortcut);
3260
+ this.user = options.user ?? null;
3249
3261
  this.storage = resolveStorage(
3250
3262
  options.storage,
3251
3263
  options.cloud,
@@ -3254,7 +3266,6 @@ var Vizu = class {
3254
3266
  if (info.user) this.setUser(info.user);
3255
3267
  }
3256
3268
  );
3257
- this.user = options.user ?? null;
3258
3269
  if (options.actions) this.actions = [...options.actions];
3259
3270
  if (options.onCommentAdded) this.bus.on("comment:added", (p) => options.onCommentAdded(p.comment));
3260
3271
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
@@ -3305,14 +3316,6 @@ var Vizu = class {
3305
3316
  this.enabled = true;
3306
3317
  this.bus.emit("enabled", {});
3307
3318
  this.deferred(() => this.mount());
3308
- if (this.storage instanceof CloudStorageAdapter) {
3309
- void this.storage.preflightAuth().catch((err) => {
3310
- if (err?.code === "auth_canceled" || err?.code === "popup_blocked") return;
3311
- if (typeof console !== "undefined") {
3312
- console.warn("[vizu] preflight auth failed:", err);
3313
- }
3314
- });
3315
- }
3316
3319
  }
3317
3320
  disable() {
3318
3321
  if (!this.enabled) return;