@format.dev/studio 0.2.0 → 0.3.0

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.
@@ -11524,7 +11524,7 @@ function Li({ children: e }) {
11524
11524
  };
11525
11525
  }, [p]), (0, v.useEffect)(() => {
11526
11526
  let e = () => {
11527
- d.current = null, c(!1), u(null), Lx();
11527
+ d.current = null, c(!1), u(null), Wx();
11528
11528
  }, t = (e) => e.detail?.attemptId === d.current, n = (e) => {
11529
11529
  t(e) && (d.current = null, c(!1), u(Ni));
11530
11530
  }, r = (e) => {
@@ -11540,7 +11540,7 @@ function Li({ children: e }) {
11540
11540
  body: { orgId: e }
11541
11541
  });
11542
11542
  if (t) throw new Ii(t, n);
11543
- Lx();
11543
+ Wx();
11544
11544
  }, h = async () => {
11545
11545
  let e = ++f.current;
11546
11546
  u(null), c(!0);
@@ -24864,21 +24864,28 @@ function Tb(e) {
24864
24864
  };
24865
24865
  }
24866
24866
  function Eb(e) {
24867
+ return Cb(e) ? {
24868
+ missingLang: e.missingLang === !0,
24869
+ invalidLang: Sb(e.invalidLang) ? e.invalidLang : null
24870
+ } : null;
24871
+ }
24872
+ function Db(e) {
24867
24873
  return Cb(e) ? {
24868
24874
  fonts: wb(e.fonts),
24869
- images: Tb(e.images)
24875
+ images: Tb(e.images),
24876
+ document: Eb(e.document)
24870
24877
  } : null;
24871
24878
  }
24872
- async function Db() {
24879
+ async function Ob() {
24873
24880
  let e = window.engine;
24874
24881
  if (!e?.summary) return null;
24875
24882
  try {
24876
- return Eb(await e.summary());
24883
+ return Db(await e.summary());
24877
24884
  } catch {
24878
24885
  return null;
24879
24886
  }
24880
24887
  }
24881
- function Ob(e) {
24888
+ function kb(e) {
24882
24889
  if (!Cb(e)) return null;
24883
24890
  let t = e.removedElements, n = e.removedTags, r = e.timestamp, i = e.documentName, a = e.variant;
24884
24891
  if (typeof t != "number" || !Number.isFinite(t) || !Cb(n) || typeof r != "number" || !Number.isFinite(r) || typeof i != "string" || typeof a != "string") return null;
@@ -24891,7 +24898,7 @@ function Ob(e) {
24891
24898
  timestamp: r
24892
24899
  } : null;
24893
24900
  }
24894
- function kb(e) {
24901
+ function Ab(e) {
24895
24902
  if (!Cb(e)) return null;
24896
24903
  let { documentName: t, variant: n, urls: r, timestamp: i } = e;
24897
24904
  return typeof t != "string" || typeof n != "string" || typeof i != "number" || !Number.isFinite(i) || !Array.isArray(r) || !r.every((e) => typeof e == "string") ? null : {
@@ -24901,7 +24908,7 @@ function kb(e) {
24901
24908
  timestamp: i
24902
24909
  };
24903
24910
  }
24904
- function Ab(e) {
24911
+ function jb(e) {
24905
24912
  if (!Cb(e)) return null;
24906
24913
  let { documentName: t, variant: n, assets: r, timestamp: i } = e;
24907
24914
  return typeof t != "string" || typeof n != "string" || typeof i != "number" || !Number.isFinite(i) || !Array.isArray(r) || !r.every((e) => typeof e == "string") ? null : {
@@ -24911,7 +24918,7 @@ function Ab(e) {
24911
24918
  timestamp: i
24912
24919
  };
24913
24920
  }
24914
- function jb(e) {
24921
+ function Mb(e) {
24915
24922
  if (!Cb(e)) return null;
24916
24923
  let { documentName: t, variant: n, tags: r, timestamp: i } = e;
24917
24924
  return typeof t != "string" || typeof n != "string" || typeof i != "number" || !Number.isFinite(i) || !Array.isArray(r) || !r.every((e) => typeof e == "string") ? null : {
@@ -24921,25 +24928,29 @@ function jb(e) {
24921
24928
  timestamp: i
24922
24929
  };
24923
24930
  }
24924
- function Mb(e) {
24931
+ function Nb(e) {
24925
24932
  return Cb(e) ? {
24926
- sanitization: e.sanitization == null ? null : Ob(e.sanitization),
24927
- remoteAssets: e.remoteAssets == null ? null : kb(e.remoteAssets),
24928
- imageFormats: e.imageFormats == null ? null : Ab(e.imageFormats),
24929
- unsupportedElements: e.unsupportedElements == null ? null : jb(e.unsupportedElements)
24933
+ sanitization: e.sanitization == null ? null : kb(e.sanitization),
24934
+ remoteAssets: e.remoteAssets == null ? null : Ab(e.remoteAssets),
24935
+ imageFormats: e.imageFormats == null ? null : jb(e.imageFormats),
24936
+ unsupportedElements: e.unsupportedElements == null ? null : Mb(e.unsupportedElements)
24930
24937
  } : null;
24931
24938
  }
24932
- async function Nb() {
24939
+ async function Pb() {
24933
24940
  let { data: e, error: t } = await _i("/api/diagnostics");
24934
- return t || e == null ? null : Mb(e);
24941
+ return t || e == null ? null : Nb(e);
24942
+ }
24943
+ function Fb(e) {
24944
+ let t = Math.max(0, ...(e.match(/`+/g) ?? []).map((e) => e.length)), n = "`".repeat(t + 1);
24945
+ return `${n} ${e} ${n}`;
24935
24946
  }
24936
- function Pb(e) {
24947
+ function Ib(e) {
24937
24948
  return e.map((e) => `- ${e}`).join("\n");
24938
24949
  }
24939
- function Fb(e, t) {
24950
+ function Lb(e, t) {
24940
24951
  return !t || e === t;
24941
24952
  }
24942
- function Ib(e) {
24953
+ function Rb(e) {
24943
24954
  let t = e.fonts;
24944
24955
  return !t || t.unresolved.length === 0 ? null : {
24945
24956
  kind: "system-fonts",
@@ -24952,9 +24963,9 @@ function Ib(e) {
24952
24963
  }
24953
24964
  };
24954
24965
  }
24955
- function Lb(e) {
24966
+ function zb(e) {
24956
24967
  let t = e.sanitization;
24957
- return !t || t.removedElements === 0 || !Fb(t.documentName, e.currentDocument) ? null : {
24968
+ return !t || t.removedElements === 0 || !Lb(t.documentName, e.currentDocument) ? null : {
24958
24969
  kind: "sanitization",
24959
24970
  title: "Unsupported elements removed",
24960
24971
  summary: "Some DOM elements have been removed from your document.",
@@ -24965,106 +24976,141 @@ function Lb(e) {
24965
24976
  }
24966
24977
  };
24967
24978
  }
24968
- function Rb(e) {
24979
+ function Bb(e) {
24969
24980
  let t = window.location.origin;
24970
24981
  return e.startsWith(t) ? e.slice(t.length).replace(/^\//, "") : e;
24971
24982
  }
24972
- function zb(e) {
24983
+ function Vb(e) {
24973
24984
  let t = e.brokenImages;
24974
24985
  return t.length === 0 ? null : {
24975
24986
  kind: "broken-assets",
24976
24987
  title: "Broken assets",
24977
24988
  summary: "Some images could not be loaded.",
24978
- detail: `These images failed to load and will be missing from your PDFs. Local assets must be placed in the document's \`assets\` directory or in your \`sharedAssetsDir\`. Remote assets are never fetched when generating PDFs.\n\n${Pb(t.map(Rb))}`,
24989
+ detail: `These images failed to load and will be missing from your PDFs. Local assets must be placed in the document's \`assets\` directory or in your \`sharedAssetsDir\`. Remote assets are never fetched when generating PDFs.\n\n${Ib(t.map(Bb))}`,
24979
24990
  link: {
24980
24991
  href: `${e.webUrl}/docs/studio/images`,
24981
24992
  label: "Read about assets"
24982
24993
  }
24983
24994
  };
24984
24995
  }
24985
- function Bb(e) {
24996
+ function Hb(e) {
24986
24997
  let t = e.remoteAssets;
24987
- return !t || t.urls.length === 0 || !Fb(t.documentName, e.currentDocument) ? null : {
24998
+ return !t || t.urls.length === 0 || !Lb(t.documentName, e.currentDocument) ? null : {
24988
24999
  kind: "remote-assets",
24989
25000
  title: "Remote assets detected",
24990
25001
  summary: "Loading assets from remote sources is not recommended.",
24991
- detail: `We recommend using local assets for more consistent and reliable PDFs. The following remote assets were found: \n\n${Pb(t.urls)}`,
25002
+ detail: `We recommend using local assets for more consistent and reliable PDFs. The following remote assets were found: \n\n${Ib(t.urls)}`,
24992
25003
  link: {
24993
25004
  href: `${e.webUrl}/authoring/assets#remote-assets`,
24994
25005
  label: "Read about assets"
24995
25006
  }
24996
25007
  };
24997
25008
  }
24998
- function Vb(e) {
25009
+ function Ub(e) {
24999
25010
  let t = e.imageFormats;
25000
- return !t || t.assets.length === 0 || !Fb(t.documentName, e.currentDocument) ? null : {
25011
+ return !t || t.assets.length === 0 || !Lb(t.documentName, e.currentDocument) ? null : {
25001
25012
  kind: "image-formats",
25002
25013
  title: "Suboptimal image formats detected",
25003
25014
  summary: "`WebP` and `AVIF` image formats are not recommended and will bloat file size.",
25004
- detail: `The following images should be converted to \`jpg\` or \`png\`:\n\n${Pb(t.assets)}`,
25015
+ detail: `The following images should be converted to \`jpg\` or \`png\`:\n\n${Ib(t.assets)}`,
25005
25016
  link: {
25006
25017
  href: `${e.webUrl}/docs/authoring/images#choosing-a-format`,
25007
25018
  label: "Choosing a format"
25008
25019
  }
25009
25020
  };
25010
25021
  }
25011
- function Hb(e) {
25022
+ function Wb(e) {
25012
25023
  let t = e.unsupportedElements;
25013
- return !t || t.tags.length === 0 || !Fb(t.documentName, e.currentDocument) ? null : {
25024
+ return !t || t.tags.length === 0 || !Lb(t.documentName, e.currentDocument) ? null : {
25014
25025
  kind: "unsupported-elements",
25015
25026
  title: "Unsupported elements detected",
25016
25027
  summary: "Some DOM elements are visible that will not render in your PDFs.",
25017
- detail: `Elements you should consider removing:\n\n${Pb(t.tags.map((e) => `\`<${e}>\``))}`,
25028
+ detail: `Elements you should consider removing:\n\n${Ib(t.tags.map((e) => `\`<${e}>\``))}`,
25018
25029
  link: {
25019
25030
  href: `${e.webUrl}/docs/miscellaneous/html-elements`,
25020
25031
  label: "Supported HTML elements"
25021
25032
  }
25022
25033
  };
25023
25034
  }
25024
- var Ub = [
25025
- Ib,
25026
- Lb,
25035
+ function Gb(e) {
25036
+ return {
25037
+ href: `${e}/docs/document-model/types/document#language`,
25038
+ label: "Read about document language"
25039
+ };
25040
+ }
25041
+ var Kb = {
25042
+ react: "Add `lang` to your `<Document>`:\n\n```tsx\n<Document title=\"Invoice\" lang=\"en\">\n```",
25043
+ vue: "Add `lang` to your `<Document>`:\n\n```vue\n<Document title=\"Invoice\" lang=\"en\">\n```",
25044
+ html: "Add `data-lang` to your document's `<template>`:\n\n```html\n<template\n data-type=\"document\"\n data-title=\"Invoice\"\n data-lang=\"en\">\n```"
25045
+ }, qb = `${Kb.react}\n\nIn HTML, use \`data-lang="en"\`.`;
25046
+ function Jb(e) {
25047
+ return e.missingLang ? {
25048
+ kind: "missing-lang",
25049
+ title: "Missing document language",
25050
+ summary: "Your document doesn't specify a language.",
25051
+ detail: `Screen readers use your document's language to choose the right voice and pronunciation, and PDF accessibility checks fail without one. ${(e.framework && Kb[e.framework]) ?? qb}`,
25052
+ link: Gb(e.webUrl)
25053
+ } : null;
25054
+ }
25055
+ function Yb(e) {
25056
+ return e.invalidLang === null ? null : {
25057
+ kind: "invalid-lang",
25058
+ title: "Invalid document language",
25059
+ summary: `Your language tag is not valid: ${Fb(e.invalidLang)}.`,
25060
+ detail: "Use a two or three-letter language code like `en` or `fr`, optionally followed by a hyphen and a region, like `en-US` or `pt-BR`. Until then, your PDF won't specify a language.",
25061
+ link: Gb(e.webUrl)
25062
+ };
25063
+ }
25064
+ var Xb = [
25065
+ Rb,
25027
25066
  zb,
25028
- Bb,
25029
25067
  Vb,
25030
- Hb
25068
+ Hb,
25069
+ Ub,
25070
+ Wb,
25071
+ Jb,
25072
+ Yb
25031
25073
  ];
25032
- async function Wb(e) {
25033
- let { webUrl: t, summary: n, currentDocument: r } = e, i = n === void 0 ? await Db() : Eb(n), a = await Nb();
25074
+ async function Zb(e) {
25075
+ let { webUrl: t, framework: n, summary: r, currentDocument: i } = e, a = r === void 0 ? await Ob() : Db(r), o = await Pb();
25034
25076
  return {
25035
25077
  webUrl: t,
25036
- fonts: i?.fonts ?? null,
25037
- brokenImages: i?.images?.broken ?? [],
25038
- sanitization: a?.sanitization ?? null,
25039
- remoteAssets: a?.remoteAssets ?? null,
25040
- imageFormats: a?.imageFormats ?? null,
25041
- unsupportedElements: a?.unsupportedElements ?? null,
25042
- currentDocument: r
25078
+ framework: n ?? null,
25079
+ fonts: a?.fonts ?? null,
25080
+ brokenImages: a?.images?.broken ?? [],
25081
+ missingLang: a?.document?.missingLang ?? !1,
25082
+ invalidLang: a?.document?.invalidLang ?? null,
25083
+ sanitization: o?.sanitization ?? null,
25084
+ remoteAssets: o?.remoteAssets ?? null,
25085
+ imageFormats: o?.imageFormats ?? null,
25086
+ unsupportedElements: o?.unsupportedElements ?? null,
25087
+ currentDocument: i
25043
25088
  };
25044
25089
  }
25045
- async function Gb(e) {
25046
- let t = await Wb(e);
25047
- return Ub.map((e) => e(t)).filter((e) => e !== null);
25090
+ async function Qb(e) {
25091
+ let t = await Zb(e);
25092
+ return Xb.map((e) => e(t)).filter((e) => e !== null);
25048
25093
  }
25049
25094
  //#endregion
25050
25095
  //#region src/app/hooks/useDiagnostics.ts
25051
- function Kb(e, t = "studio:engine-finish") {
25052
- let { setDiagnostics: n, clearDiagnostics: r } = q_(), { state: i } = bi(), a = i?.webUrl ?? "";
25096
+ function $b(e, t = "studio:engine-finish") {
25097
+ let { setDiagnostics: n, clearDiagnostics: r } = q_(), { state: i } = bi(), a = i?.webUrl ?? "", o = i?.framework;
25053
25098
  (0, v.useEffect)(() => {
25054
- let i = !0, o = 0;
25099
+ let i = !0, s = 0;
25055
25100
  r();
25056
- let s = async (t) => {
25057
- let r = ++o;
25101
+ let c = async (t) => {
25102
+ let r = ++s;
25058
25103
  try {
25059
- let s = await Gb({
25104
+ let c = await Qb({
25060
25105
  webUrl: a,
25106
+ framework: o,
25061
25107
  summary: t,
25062
25108
  currentDocument: e ?? void 0
25063
25109
  });
25064
- if (!i || r !== o) return;
25065
- n(s);
25110
+ if (!i || r !== s) return;
25111
+ n(c);
25066
25112
  } catch (e) {
25067
- if (!i || r !== o) return;
25113
+ if (!i || r !== s) return;
25068
25114
  let t = e instanceof Error ? e.message : String(e);
25069
25115
  n([{
25070
25116
  kind: "diagnostics-unavailable",
@@ -25073,97 +25119,98 @@ function Kb(e, t = "studio:engine-finish") {
25073
25119
  detail: `Failed to load diagnostics: ${t}`
25074
25120
  }]);
25075
25121
  }
25076
- }, c = (e) => {
25122
+ }, l = (e) => {
25077
25123
  let t = e.detail?.summary;
25078
- return s(t);
25124
+ return c(t);
25079
25125
  };
25080
- return window.addEventListener(t, c), () => {
25081
- i = !1, window.removeEventListener(t, c);
25126
+ return window.addEventListener(t, l), () => {
25127
+ i = !1, window.removeEventListener(t, l);
25082
25128
  };
25083
25129
  }, [
25084
25130
  n,
25085
25131
  r,
25086
25132
  t,
25087
25133
  e,
25088
- a
25134
+ a,
25135
+ o
25089
25136
  ]);
25090
25137
  }
25091
25138
  //#endregion
25092
25139
  //#region ../../packages/compile/dist/shared/env.mjs
25093
- function qb() {
25140
+ function ex() {
25094
25141
  return !0;
25095
25142
  }
25096
25143
  //#endregion
25097
25144
  //#region src/app/engine/client.ts
25098
25145
  window.engine = null;
25099
- var Jb = async (e, t) => {
25146
+ var tx = async (e, t) => {
25100
25147
  let { data: n, error: r } = await _i(`/api/render/${e}/${t}`, { responseType: "text" });
25101
25148
  if (r) throw r;
25102
25149
  if (!n) throw Error("No HTML returned");
25103
25150
  return n;
25104
- }, Yb = async (e) => {
25151
+ }, nx = async (e) => {
25105
25152
  let t = document.getElementById("user-root");
25106
25153
  t && (t.innerHTML = e);
25107
- }, Xb = () => {
25154
+ }, rx = () => {
25108
25155
  document.getElementById("format-pages")?.remove();
25109
25156
  let e = document.getElementById("user-root");
25110
25157
  e && (e.innerHTML = "");
25111
25158
  };
25112
- async function Zb() {
25159
+ async function ix() {
25113
25160
  let e = document.querySelector("#user-root [data-type=\"document\"]")?.getAttribute("data-fonts") ?? "", { data: t, error: n } = await _i(`/@studio/fonts.css?mode=${encodeURIComponent(e)}`, { responseType: "text" });
25114
25161
  if (n || !t) throw n ?? /* @__PURE__ */ Error("No font CSS returned");
25115
25162
  let r = document.getElementById("format-fonts"), i = r ?? document.createElement("style");
25116
25163
  r || (i.id = "format-fonts", document.head.appendChild(i)), i.textContent = t, await document.fonts.ready;
25117
25164
  }
25118
- async function Qb() {
25165
+ async function ax() {
25119
25166
  let { data: e, error: t } = await _i("/api/state");
25120
25167
  if (t) throw Error("Could not fetch engine path from dev server.");
25121
25168
  if (!e?.enginePath) throw Error("Engine path missing from state.");
25122
25169
  return e.enginePath;
25123
25170
  }
25124
- async function $b() {
25125
- let { default: e, FormatEngine: t } = await import(await Qb());
25171
+ async function ox() {
25172
+ let { default: e, FormatEngine: t } = await import(await ax());
25126
25173
  return {
25127
25174
  init: e,
25128
25175
  FormatEngine: t
25129
25176
  };
25130
25177
  }
25131
- async function ex() {
25178
+ async function sx() {
25132
25179
  let { data: e, error: t } = await _i("/api/engine-token");
25133
25180
  if (t) throw Error("Could not fetch engine token from dev server.");
25134
25181
  if (!e?.token) throw Error("Token missing from response");
25135
25182
  return e.token;
25136
25183
  }
25137
- var tx = /licen[cs]e|token has expired/i;
25138
- function nx(e) {
25184
+ var cx = /licen[cs]e|token has expired/i;
25185
+ function lx(e) {
25139
25186
  let t = e instanceof Error ? e.message : String(e);
25140
- return tx.test(t);
25187
+ return cx.test(t);
25141
25188
  }
25142
- async function rx() {
25189
+ async function ux() {
25143
25190
  let { data: e } = await _i("/api/auth/refresh", { method: "POST" });
25144
25191
  return !!e?.token;
25145
25192
  }
25146
- async function ix() {
25193
+ async function dx() {
25147
25194
  await _i("/api/auth/failed", {
25148
25195
  method: "POST",
25149
25196
  body: { reason: "licence_expired" }
25150
25197
  });
25151
25198
  }
25152
- function ax() {
25199
+ function fx() {
25153
25200
  window.dispatchEvent(new CustomEvent("studio:error", { detail: { data: B } }));
25154
25201
  }
25155
- var ox = Promise.resolve();
25156
- async function sx() {
25157
- let e = ox.then(() => cx());
25158
- return ox = e.catch(() => {}), e;
25202
+ var px = Promise.resolve();
25203
+ async function mx() {
25204
+ let e = px.then(() => hx());
25205
+ return px = e.catch(() => {}), e;
25159
25206
  }
25160
- async function cx(e = !1) {
25207
+ async function hx(e = !1) {
25161
25208
  try {
25162
25209
  let e = new CustomEvent("studio:engine-start");
25163
25210
  if (window.dispatchEvent(e), !window.engine) {
25164
- let { init: e, FormatEngine: t } = await $b();
25211
+ let { init: e, FormatEngine: t } = await ox();
25165
25212
  await e();
25166
- let n = await ex();
25213
+ let n = await sx();
25167
25214
  window.engine = new t({
25168
25215
  rootScopeSelector: "#user-root",
25169
25216
  cloneSource: !0,
@@ -25172,30 +25219,30 @@ async function cx(e = !1) {
25172
25219
  lazyPaint: !0
25173
25220
  });
25174
25221
  }
25175
- await Zb(), await window.engine.consume(), await window.engine.paginate();
25222
+ await ix(), await window.engine.consume(), await window.engine.paginate();
25176
25223
  let t = await window.engine.summary();
25177
- qb() && console.log("[studio] Engine diagnostics", t);
25224
+ ex() && console.log("[studio] Engine diagnostics", t);
25178
25225
  let n = new CustomEvent("studio:engine-finish", { detail: { summary: t } });
25179
25226
  window.dispatchEvent(n);
25180
25227
  } catch (t) {
25181
- if (nx(t)) {
25182
- await lx(t, e);
25228
+ if (lx(t)) {
25229
+ await gx(t, e);
25183
25230
  return;
25184
25231
  }
25185
25232
  throw console.error("Engine error", t), window.dispatchEvent(new CustomEvent("studio:error", { detail: { data: Pi } })), t;
25186
25233
  }
25187
25234
  }
25188
- async function lx(e, t) {
25189
- if (!t && await rx()) {
25190
- window.engine = null, await cx(!0);
25235
+ async function gx(e, t) {
25236
+ if (!t && await ux()) {
25237
+ window.engine = null, await hx(!0);
25191
25238
  return;
25192
25239
  }
25193
- console.error("Engine licence expired and could not be refreshed", e), await ix(), ax();
25240
+ console.error("Engine licence expired and could not be refreshed", e), await dx(), fx();
25194
25241
  }
25195
25242
  //#endregion
25196
25243
  //#region src/app/hooks/useDocumentRenderer.ts
25197
- var ux = 3;
25198
- function dx(e) {
25244
+ var _x = 3;
25245
+ function vx(e) {
25199
25246
  let { currentDocument: t, currentVariant: n } = e, { clearDocumentErrors: r } = ji(), i = (0, v.useRef)(null), a = (0, v.useRef)(!1), o = (0, v.useRef)(!1), s = (0, v.useRef)(!1), c = (0, v.useRef)(null), l = (0, v.useRef)(""), u = (0, v.useRef)(n);
25200
25247
  (0, v.useEffect)(() => {
25201
25248
  l.current = t || "";
@@ -25254,9 +25301,9 @@ function dx(e) {
25254
25301
  documentName: e,
25255
25302
  variant: t,
25256
25303
  isHmr: u
25257
- } })), Yb(await Jb(e, t)), await sx(), r(), n = !0, o = i.current, s = d !== null && d !== "" && d !== e, c.current = e;
25304
+ } })), nx(await tx(e, t)), await mx(), r(), n = !0, o = i.current, s = d !== null && d !== "" && d !== e, c.current = e;
25258
25305
  } catch (n) {
25259
- console.error("Failed to render document to html and start engine", n), d !== null && d !== e && (Xb(), c.current = null), window.dispatchEvent(new CustomEvent("studio:render-error", { detail: {
25306
+ console.error("Failed to render document to html and start engine", n), d !== null && d !== e && (rx(), c.current = null), window.dispatchEvent(new CustomEvent("studio:render-error", { detail: {
25260
25307
  documentName: e,
25261
25308
  variant: t
25262
25309
  } }));
@@ -25290,7 +25337,7 @@ function dx(e) {
25290
25337
  let n = 0;
25291
25338
  try {
25292
25339
  do
25293
- if (s.current = !1, a.current = !0, m(l.current, u.current), await y(l.current, u.current), n += 1, n >= ux && s.current) {
25340
+ if (s.current = !1, a.current = !0, m(l.current, u.current), await y(l.current, u.current), n += 1, n >= _x && s.current) {
25294
25341
  s.current = !1, queueMicrotask(() => {
25295
25342
  b();
25296
25343
  });
@@ -25317,52 +25364,52 @@ function dx(e) {
25317
25364
  }
25318
25365
  //#endregion
25319
25366
  //#region src/app/utils/router.ts
25320
- var fx = (e, t = "push") => {
25367
+ var yx = (e, t = "push") => {
25321
25368
  let n = `/${encodeURIComponent(e)}${window.location.search}`;
25322
25369
  if (n !== window.location.pathname + window.location.search) {
25323
25370
  let e = t === "push" ? "pushState" : "replaceState";
25324
25371
  window.history[e]({}, "", n);
25325
25372
  }
25326
- }, px = () => window.location.pathname.split("/")[1], mx = (e, t) => !!e && t.some((t) => t.name === e), hx = (e) => e[0]?.name, gx = () => {
25373
+ }, bx = () => window.location.pathname.split("/")[1], xx = (e, t) => !!e && t.some((t) => t.name === e), Sx = (e) => e[0]?.name, Cx = () => {
25327
25374
  try {
25328
25375
  return localStorage.getItem("mostRecentDocument") || void 0;
25329
25376
  } catch {
25330
25377
  return;
25331
25378
  }
25332
25379
  };
25333
- function _x() {
25334
- let { documents: e, setCurrentDocument: t } = va.getState(), n = px();
25335
- if (mx(n, e)) {
25380
+ function wx() {
25381
+ let { documents: e, setCurrentDocument: t } = va.getState(), n = bx();
25382
+ if (xx(n, e)) {
25336
25383
  t(n);
25337
25384
  return;
25338
25385
  }
25339
- let r = gx(), i = r && mx(r, e) ? r : hx(e);
25386
+ let r = Cx(), i = r && xx(r, e) ? r : Sx(e);
25340
25387
  if (i) {
25341
- t(i), fx(i, "replace");
25388
+ t(i), yx(i, "replace");
25342
25389
  return;
25343
25390
  }
25344
25391
  throw Error(Vv);
25345
25392
  }
25346
25393
  //#endregion
25347
25394
  //#region src/app/hooks/useDocumentNavigation.ts
25348
- function vx(e) {
25395
+ function Tx(e) {
25349
25396
  return e && typeof e == "object" && "message" in e ? String(e.message) : e ? String(e) : "Failed to resolve document";
25350
25397
  }
25351
- function yx(e) {
25398
+ function Ex(e) {
25352
25399
  let { currentVariant: t, setCurrentVariant: n, storeScrollPositionFor: r, storeCurrentScrollPosition: i, resetLastRenderedDocument: a } = e, { documents: o, currentDocument: s, setDocuments: c, setCurrentDocument: l, clearCurrentDocument: u, pendingNewDocument: d, clearPendingNewDocument: f } = va(), { addError: p } = ji(), [m, h] = (0, v.useState)(!1), g = (0, v.useRef)(!1), _ = (0, v.useCallback)(() => {
25353
25400
  try {
25354
- i(), _x();
25401
+ i(), wx();
25355
25402
  } catch (e) {
25356
25403
  R_(!1), p({
25357
- message: vx(e),
25404
+ message: Tx(e),
25358
25405
  title: "No Documents Found"
25359
25406
  });
25360
25407
  }
25361
25408
  }, [p, i]), y = (e) => {
25362
- n(zv), l(e), fx(e);
25409
+ n(zv), l(e), yx(e);
25363
25410
  }, b = (e, i = zv) => {
25364
25411
  if (e !== s) {
25365
- l(e), fx(e), n(i);
25412
+ l(e), yx(e), n(i);
25366
25413
  return;
25367
25414
  }
25368
25415
  i !== t && (r(e, t), n(i));
@@ -25382,7 +25429,7 @@ function yx(e) {
25382
25429
  return (0, v.useEffect)(() => {
25383
25430
  S();
25384
25431
  }, [S]), (0, v.useEffect)(() => {
25385
- d && (n(zv), l(d), fx(d), f());
25432
+ d && (n(zv), l(d), yx(d), f());
25386
25433
  }, [
25387
25434
  d,
25388
25435
  s,
@@ -25394,7 +25441,7 @@ function yx(e) {
25394
25441
  }, [o, _]), (0, v.useEffect)(() => (window.addEventListener("studio:documents-changed", S), window.addEventListener("popstate", _), () => {
25395
25442
  window.removeEventListener("studio:documents-changed", S), window.removeEventListener("popstate", _);
25396
25443
  }), [S, _]), (0, v.useEffect)(() => {
25397
- !m || o.length > 0 || (Xb(), R_(!1), s !== null && u(), window.location.pathname !== "/" && window.history.replaceState({}, "", "/"), a(), g.current = !1);
25444
+ !m || o.length > 0 || (rx(), R_(!1), s !== null && u(), window.location.pathname !== "/" && window.history.replaceState({}, "", "/"), a(), g.current = !1);
25398
25445
  }, [
25399
25446
  m,
25400
25447
  o.length,
@@ -25410,31 +25457,31 @@ function yx(e) {
25410
25457
  }
25411
25458
  //#endregion
25412
25459
  //#region src/app/engine/page-shadow-roots.ts
25413
- var bx = "studio:page-link-click", xx = [], Sx = null;
25414
- function Cx(e) {
25460
+ var Dx = "studio:page-link-click", Ox = [], kx = null;
25461
+ function Ax(e) {
25415
25462
  if (!e.currentTarget.host.closest("#format-pages")) return;
25416
25463
  let t = e.target?.closest?.("a[href]");
25417
25464
  if (!t) return;
25418
25465
  e.preventDefault();
25419
25466
  let { metaKey: n, ctrlKey: r } = e;
25420
- window.dispatchEvent(new CustomEvent(bx, { detail: {
25467
+ window.dispatchEvent(new CustomEvent(Dx, { detail: {
25421
25468
  element: t,
25422
25469
  href: t.getAttribute("href") || "",
25423
25470
  isModifierClick: !!(n || r)
25424
25471
  } }));
25425
25472
  }
25426
- function wx() {
25427
- Sx || (Sx = Element.prototype.attachShadow, Element.prototype.attachShadow = function(e) {
25428
- let t = Sx.call(this, e);
25429
- return xx.push(new WeakRef(t)), t.addEventListener("click", Cx, !0), t;
25473
+ function jx() {
25474
+ kx || (kx = Element.prototype.attachShadow, Element.prototype.attachShadow = function(e) {
25475
+ let t = kx.call(this, e);
25476
+ return Ox.push(new WeakRef(t)), t.addEventListener("click", Ax, !0), t;
25430
25477
  });
25431
25478
  }
25432
- function Tx() {
25479
+ function Mx() {
25433
25480
  let e = [];
25434
- for (let t = xx.length - 1; t >= 0; t--) {
25435
- let n = xx[t].deref();
25481
+ for (let t = Ox.length - 1; t >= 0; t--) {
25482
+ let n = Ox[t].deref();
25436
25483
  if (!n) {
25437
- xx.splice(t, 1);
25484
+ Ox.splice(t, 1);
25438
25485
  continue;
25439
25486
  }
25440
25487
  n.host.isConnected && n.host.closest("#format-pages") && e.push(n);
@@ -25443,24 +25490,24 @@ function Tx() {
25443
25490
  }
25444
25491
  //#endregion
25445
25492
  //#region src/app/hooks/useDocumentLinks.ts
25446
- function Ex(e) {
25493
+ function Nx(e) {
25447
25494
  try {
25448
25495
  return new URL(e, document.baseURI).toString();
25449
25496
  } catch {
25450
25497
  return e;
25451
25498
  }
25452
25499
  }
25453
- function Dx(e) {
25500
+ function Px(e) {
25454
25501
  if (!e) return;
25455
25502
  let t = `#${CSS.escape(e)}`, n = document.getElementById("format-pages")?.querySelector(t);
25456
25503
  if (n) {
25457
25504
  Mv(n);
25458
25505
  return;
25459
25506
  }
25460
- let r = Tx().map((e) => e.querySelector(t)).find(Boolean);
25507
+ let r = Mx().map((e) => e.querySelector(t)).find(Boolean);
25461
25508
  r && Mv(r);
25462
25509
  }
25463
- function Ox() {
25510
+ function Fx() {
25464
25511
  let [e, t] = (0, v.useState)(null), n = (0, v.useRef)(null);
25465
25512
  (0, v.useEffect)(() => {
25466
25513
  n.current = e;
@@ -25469,10 +25516,10 @@ function Ox() {
25469
25516
  t(null);
25470
25517
  }, []), i = (0, v.useCallback)(() => {
25471
25518
  let e = n.current;
25472
- e && (window.open(Ex(e.href), "_blank", "noopener,noreferrer"), t(null));
25519
+ e && (window.open(Nx(e.href), "_blank", "noopener,noreferrer"), t(null));
25473
25520
  }, []);
25474
25521
  return (0, v.useEffect)(() => {
25475
- wx();
25522
+ jx();
25476
25523
  let e = (e) => {
25477
25524
  let { anchor: r, href: i, isModifierClick: a } = e;
25478
25525
  if (!r) {
@@ -25480,11 +25527,11 @@ function Ox() {
25480
25527
  return;
25481
25528
  }
25482
25529
  if (i.startsWith("#")) {
25483
- Dx(i.slice(1)), t(null);
25530
+ Px(i.slice(1)), t(null);
25484
25531
  return;
25485
25532
  }
25486
25533
  if (n.current?.element === r || a) {
25487
- window.open(Ex(i), "_blank", "noopener,noreferrer"), t(null);
25534
+ window.open(Nx(i), "_blank", "noopener,noreferrer"), t(null);
25488
25535
  return;
25489
25536
  }
25490
25537
  t({
@@ -25510,8 +25557,8 @@ function Ox() {
25510
25557
  }, a = () => {
25511
25558
  t(null);
25512
25559
  };
25513
- return window.addEventListener(bx, r), document.addEventListener("click", i), window.addEventListener("studio:render-start", a), () => {
25514
- window.removeEventListener(bx, r), document.removeEventListener("click", i), window.removeEventListener("studio:render-start", a);
25560
+ return window.addEventListener(Dx, r), document.addEventListener("click", i), window.addEventListener("studio:render-start", a), () => {
25561
+ window.removeEventListener(Dx, r), document.removeEventListener("click", i), window.removeEventListener("studio:render-start", a);
25515
25562
  };
25516
25563
  }, []), {
25517
25564
  activeLink: e,
@@ -25519,7 +25566,7 @@ function Ox() {
25519
25566
  closeActiveLink: r
25520
25567
  };
25521
25568
  }
25522
- var kx = {
25569
+ var Ix = {
25523
25570
  studio: "fmt-_YTFwUb7",
25524
25571
  studioEmpty: "fmt-EFHZFlD9",
25525
25572
  hidden: "fmt-bIL9NMYn",
@@ -25528,8 +25575,8 @@ var kx = {
25528
25575
  };
25529
25576
  //#endregion
25530
25577
  //#region src/app/components/Studio/Studio.tsx
25531
- qb() && console.log("[studio] React version:", "19.2.8");
25532
- var Ax = [
25578
+ ex() && console.log("[studio] React version:", "19.2.8");
25579
+ var Lx = [
25533
25580
  "#sidebar-collapse-toggle",
25534
25581
  "#sidebar-new-document-button",
25535
25582
  "#sidebar-filter-toggle",
@@ -25545,7 +25592,7 @@ var Ax = [
25545
25592
  "#ppi-controls-trigger",
25546
25593
  "#pagenav-prev",
25547
25594
  "#pagenav-next"
25548
- ], jx = [
25595
+ ], Rx = [
25549
25596
  "#sidebar-org-selection[aria-expanded=\"true\"]",
25550
25597
  "#titlebar-document-button[aria-expanded=\"true\"]",
25551
25598
  "#titlebar-variant-button[aria-expanded=\"true\"]",
@@ -25554,19 +25601,19 @@ var Ax = [
25554
25601
  "#zoom-controls-trigger[aria-expanded=\"true\"]",
25555
25602
  "#ppi-controls-trigger[aria-expanded=\"true\"]"
25556
25603
  ];
25557
- function Mx() {
25604
+ function zx() {
25558
25605
  let { documents: e, currentDocument: t, openNewDocumentModal: n } = va();
25559
- Kb(t);
25560
- let [r, i] = Ae(Bv, Ce.withDefault(zv)), [a, o] = (0, v.useState)(!1), [s, c] = (0, v.useState)(!1), [l, u] = Uo("isSidebarCollapsed", !1), d = (0, v.useRef)(!1), { storeScrollPositionFor: f, storeCurrentScrollPosition: p, resetLastRenderedDocument: m } = dx({
25606
+ $b(t);
25607
+ let [r, i] = Ae(Bv, Ce.withDefault(zv)), [a, o] = (0, v.useState)(!1), [s, c] = (0, v.useState)(!1), [l, u] = Uo("isSidebarCollapsed", !1), d = (0, v.useRef)(!1), { storeScrollPositionFor: f, storeCurrentScrollPosition: p, resetLastRenderedDocument: m } = vx({
25561
25608
  currentDocument: t,
25562
25609
  currentVariant: r
25563
- }), { documentsLoaded: h, handleNavigate: g } = yx({
25610
+ }), { documentsLoaded: h, handleNavigate: g } = Ex({
25564
25611
  currentVariant: r,
25565
25612
  setCurrentVariant: i,
25566
25613
  storeScrollPositionFor: f,
25567
25614
  storeCurrentScrollPosition: p,
25568
25615
  resetLastRenderedDocument: m
25569
- }), { activeLink: _, openActiveLink: y, closeActiveLink: b } = Ox();
25616
+ }), { activeLink: _, openActiveLink: y, closeActiveLink: b } = Fx();
25570
25617
  ns([
25571
25618
  {
25572
25619
  key: "{",
@@ -25598,8 +25645,8 @@ function Mx() {
25598
25645
  document.documentElement.classList.toggle("is-ui-hidden", a);
25599
25646
  }, [a]), (0, v.useEffect)(() => {
25600
25647
  let e = (e) => {
25601
- if (e.key !== "Tab" || jx.some((e) => !!document.querySelector(e))) return;
25602
- let t = [...Ax];
25648
+ if (e.key !== "Tab" || Rx.some((e) => !!document.querySelector(e))) return;
25649
+ let t = [...Lx];
25603
25650
  if (!document.querySelector("#format-pages")) return;
25604
25651
  document.querySelector("#diagnostics-toggle") && t.push("#diagnostics-toggle");
25605
25652
  let n = t.map((e) => document.querySelector(e)).filter((e) => {
@@ -25618,7 +25665,7 @@ function Mx() {
25618
25665
  document.removeEventListener("keydown", e);
25619
25666
  };
25620
25667
  }, []), h && e.length === 0 ? /* @__PURE__ */ (0, R.jsxs)("div", {
25621
- className: `${kx.studio} ${kx.studioEmpty}`,
25668
+ className: `${Ix.studio} ${Ix.studioEmpty}`,
25622
25669
  children: [
25623
25670
  /* @__PURE__ */ (0, R.jsx)(W_, {}),
25624
25671
  /* @__PURE__ */ (0, R.jsx)(gy, {}),
@@ -25635,13 +25682,13 @@ function Mx() {
25635
25682
  /* @__PURE__ */ (0, R.jsx)(wy, {})
25636
25683
  ]
25637
25684
  }) : /* @__PURE__ */ (0, R.jsxs)("div", {
25638
- className: kx.studio,
25685
+ className: Ix.studio,
25639
25686
  children: [
25640
25687
  /* @__PURE__ */ (0, R.jsx)(W_, {}),
25641
25688
  /* @__PURE__ */ (0, R.jsx)(gy, {}),
25642
25689
  /* @__PURE__ */ (0, R.jsx)(ub, {}),
25643
25690
  !l && /* @__PURE__ */ (0, R.jsx)(Go, {
25644
- className: a ? kx.hidden : "",
25691
+ className: a ? Ix.hidden : "",
25645
25692
  collapsed: !1,
25646
25693
  onToggleCollapse: u,
25647
25694
  documents: e,
@@ -25651,7 +25698,7 @@ function Mx() {
25651
25698
  onOpenPalette: () => c(!0)
25652
25699
  }),
25653
25700
  /* @__PURE__ */ (0, R.jsxs)("div", {
25654
- className: `${kx.topBar} ${a ? kx.hidden : ""}`,
25701
+ className: `${Ix.topBar} ${a ? Ix.hidden : ""}`,
25655
25702
  children: [/* @__PURE__ */ (0, R.jsx)(wv, {
25656
25703
  documentName: t || "",
25657
25704
  variant: r,
@@ -25669,8 +25716,8 @@ function Mx() {
25669
25716
  } })]
25670
25717
  }),
25671
25718
  /* @__PURE__ */ (0, R.jsx)(Yu, {}),
25672
- /* @__PURE__ */ (0, R.jsx)(cy, { className: a ? kx.hidden : "" }),
25673
- /* @__PURE__ */ (0, R.jsx)(Iv, { className: a ? kx.hidden : "" }),
25719
+ /* @__PURE__ */ (0, R.jsx)(cy, { className: a ? Ix.hidden : "" }),
25720
+ /* @__PURE__ */ (0, R.jsx)(Iv, { className: a ? Ix.hidden : "" }),
25674
25721
  _ && /* @__PURE__ */ (0, R.jsx)(xy, {
25675
25722
  anchorElement: _.element,
25676
25723
  href: _.href,
@@ -25683,7 +25730,7 @@ function Mx() {
25683
25730
  onClose: () => c(!1)
25684
25731
  }),
25685
25732
  a && /* @__PURE__ */ (0, R.jsx)("button", {
25686
- className: kx.showUIButton,
25733
+ className: Ix.showUIButton,
25687
25734
  onClick: S,
25688
25735
  children: "Show UI"
25689
25736
  })
@@ -25692,18 +25739,18 @@ function Mx() {
25692
25739
  }
25693
25740
  //#endregion
25694
25741
  //#region src/app/components/ThemeInitializer/ThemeInitializer.tsx
25695
- function Nx() {
25742
+ function Bx() {
25696
25743
  return Si(), null;
25697
25744
  }
25698
25745
  //#endregion
25699
25746
  //#region src/app/index.tsx
25700
- var Px = document.getElementById("studio-ui"), Fx = _.createRoot(Px);
25701
- function Ix() {
25702
- Fx.render(/* @__PURE__ */ (0, R.jsx)(be, { children: /* @__PURE__ */ (0, R.jsx)(yi, { children: /* @__PURE__ */ (0, R.jsx)(Qo, { children: /* @__PURE__ */ (0, R.jsx)(Li, { children: /* @__PURE__ */ (0, R.jsx)(Ai, { children: /* @__PURE__ */ (0, R.jsxs)(K_, { children: [/* @__PURE__ */ (0, R.jsx)(Nx, {}), /* @__PURE__ */ (0, R.jsx)(Mx, {})] }) }) }) }) }) }));
25747
+ var Vx = document.getElementById("studio-ui"), Hx = _.createRoot(Vx);
25748
+ function Ux() {
25749
+ Hx.render(/* @__PURE__ */ (0, R.jsx)(be, { children: /* @__PURE__ */ (0, R.jsx)(yi, { children: /* @__PURE__ */ (0, R.jsx)(Qo, { children: /* @__PURE__ */ (0, R.jsx)(Li, { children: /* @__PURE__ */ (0, R.jsx)(Ai, { children: /* @__PURE__ */ (0, R.jsxs)(K_, { children: [/* @__PURE__ */ (0, R.jsx)(Bx, {}), /* @__PURE__ */ (0, R.jsx)(zx, {})] }) }) }) }) }) }));
25703
25750
  }
25704
- function Lx() {
25705
- Fx.unmount(), Fx = _.createRoot(Px), Ix();
25751
+ function Wx() {
25752
+ Hx.unmount(), Hx = _.createRoot(Vx), Ux();
25706
25753
  }
25707
- Ix();
25754
+ Ux();
25708
25755
  //#endregion
25709
- export { Lx as remountApp };
25756
+ export { Wx as remountApp };