@graview/guest 0.1.70 → 0.1.72

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.
Files changed (49) hide show
  1. package/README.md +21 -0
  2. package/client.js +1 -1
  3. package/dist/client.generated.d.ts.map +1 -1
  4. package/dist/client.generated.js +2 -2
  5. package/dist/client.generated.js.map +1 -1
  6. package/dist/guest.d.ts.map +1 -1
  7. package/dist/guest.js +39 -1
  8. package/dist/guest.js.map +1 -1
  9. package/dist/headless/runtime.generated.js +1 -1
  10. package/dist/host/fonts.d.ts +50 -3
  11. package/dist/host/fonts.d.ts.map +1 -1
  12. package/dist/host/fonts.js +306 -33
  13. package/dist/host/fonts.js.map +1 -1
  14. package/dist/host/frame.d.ts +24 -1
  15. package/dist/host/frame.d.ts.map +1 -1
  16. package/dist/host/frame.js +89 -1
  17. package/dist/host/frame.js.map +1 -1
  18. package/dist/host/index.d.ts +1 -1
  19. package/dist/host/index.d.ts.map +1 -1
  20. package/dist/host/manifest.d.ts.map +1 -1
  21. package/dist/host/manifest.js +22 -0
  22. package/dist/host/manifest.js.map +1 -1
  23. package/dist/host/pictures.d.ts +29 -1
  24. package/dist/host/pictures.d.ts.map +1 -1
  25. package/dist/host/pictures.js +66 -16
  26. package/dist/host/pictures.js.map +1 -1
  27. package/dist/host/react.d.ts +18 -0
  28. package/dist/host/react.d.ts.map +1 -1
  29. package/dist/host/react.js +21 -1
  30. package/dist/host/react.js.map +1 -1
  31. package/dist/host/session.d.ts +45 -1
  32. package/dist/host/session.d.ts.map +1 -1
  33. package/dist/host/session.js +133 -1
  34. package/dist/host/session.js.map +1 -1
  35. package/dist/host/view-runtime.generated.js +1 -1
  36. package/dist/host/view.d.ts +12 -0
  37. package/dist/host/view.d.ts.map +1 -1
  38. package/dist/host/view.js +3 -5
  39. package/dist/host/view.js.map +1 -1
  40. package/dist/host/worker-react.d.ts +4 -0
  41. package/dist/host/worker-react.d.ts.map +1 -1
  42. package/dist/host/worker-react.js +1 -0
  43. package/dist/host/worker-react.js.map +1 -1
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/protocol.d.ts +20 -0
  47. package/dist/protocol.d.ts.map +1 -1
  48. package/dist/protocol.js.map +1 -1
  49. package/package.json +3 -3
package/README.md CHANGED
@@ -60,6 +60,17 @@ guest.navigate(id);
60
60
  guest.autoSize();
61
61
  ```
62
62
 
63
+ The frame takes each height it asks for, up to `limits.maxHeight` (4,000px
64
+ by default). A page sized by its own frame (`height: 100vh`) asks for a
65
+ little more each time the frame grows. A height that tracks the frame's
66
+ own a few times running is refused for a moment: content that grows asks
67
+ another meanwhile and is taken; otherwise the height is given after all,
68
+ and a guest that then asks again by the same step is held, the frame wears
69
+ `data-guest-view-held`, and the host's `{ onProblem }` is told why. A gallery whose last
70
+ picture lands just there keeps its whole height. Size the
71
+ page by its content. `guestView({ onSize })` is told each height the frame
72
+ takes.
73
+
63
74
  In React, `useGuest()` from `@graview/guest/react` is the same connection:
64
75
  `{ props, act, navigate, size }`, re-rendering on every push. The guest
65
76
  entries import nothing of the framework, so a guest bundle carries none of it.
@@ -104,6 +115,16 @@ its policy needs `img-src data:` to show it. The scheme is the app's own
104
115
  again when the app's toggle or brand changes. `mountGuestView` takes
105
116
  `reads`, `theme`, `brand` and `places` too.
106
117
 
118
+ The faces the brand lends its views (`brand.views.fonts`) are lent to a
119
+ frame as well: the host reads each file — the app's own where `asset`
120
+ serves it, or one on an origin `fonts.origins` lists — at most 2 MB, the
121
+ last lent winning a shared name, and hands it as a `data:` font the client
122
+ puts in the frame's document. A guest names the family (`font-family:
123
+ "Rock Face", serif`) and loads nothing; its policy needs `font-src data:`.
124
+ Frames in one brand share one reading of its faces. The frame says it has
125
+ drawn once they are read, or after two seconds, saying which did not come.
126
+ What is not lent is said to the host's `{ onProblem }` (`guestView` says it in the console).
127
+
107
128
  `title` names the frame for assistive technology. Registered with the same
108
129
  title, the guest is a place on both faces: listed by `placesOf`, at
109
130
  `/places/the-price-sheet` on the routed face and `#view=the-price-sheet` in
package/client.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! @graview/guest/client.js — a frame guest's client (GraviewGuest.connect). Generated from src/client-script.ts. Elastic License 2.0. */
2
- "use strict";var GraviewGuest=(()=>{var f=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var T=(n,r)=>{for(var t in r)f(n,t,{get:r[t],enumerable:!0})},S=(n,r,t,d)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of M(r))!O.call(n,s)&&s!==t&&f(n,s,{get:()=>r[s],enumerable:!(d=k(r,s))||d.enumerable});return n};var H=n=>S(f({},"__esModule",{value:!0}),n);var _={};T(_,{connect:()=>x,protocol:()=>y});var y=1;function v(n){if(typeof n=="string")return{type:"navigate",to:n};let{place:r,record:t,where:d,section:s}=n??{},u={...d===void 0?{}:{where:d},...s===void 0?{}:{section:String(s)}};return typeof r=="string"?{type:"navigate",place:r,...u}:typeof t=="string"?{type:"navigate",to:t,...u}:void 0}function h(n){let r=n;return typeof n=="object"&&n!==null&&r.graview==="host-hello"&&typeof r.nonce=="string"}function w(n,r={}){let t,d="",s,u=0,g=new Set,p=new Map,G=[],l=o=>{t?t.postMessage({...o,nonce:d}):G.push(o)},E=o=>{let e=o.data;if(!(!e||typeof e!="object")){if(e.type==="props"){s=e.props;for(let a of g)a(e.props)}else e.type==="answer"?(p.get(e.id)?.(e),p.delete(e.id)):e.type==="event"&&typeof e.listener=="number"?r.onEvent?.(e):e.type==="heartbeat"&&typeof e.beat=="number"&&l({type:"heartbeat",beat:e.beat});r.onMessage?.(e)}},c=()=>{},R=o=>{if(t||!n.fromHost(o)||!h(o.data)||o.data.protocol!==1)return;let e=o.ports[0];if(e){t=e,d=o.data.nonce,t.onmessage=E,t.start?.(),c();for(let a of G.splice(0))l(a)}};c=n.listen(R),n.ready({graview:"guest-ready",protocol:1});let m,b={get props(){return s},subscribe(o){return g.add(o),()=>g.delete(o)},act(o,e={}){let a=u+=1;return new Promise(i=>{p.set(a,i),l({type:"act",id:a,name:o,args:e})})},navigate(o){let e=v(o);e&&l(e)},size(o){l({type:"size",height:o})},autoSize(o){let e=o??globalThis.document?.documentElement,a=globalThis.ResizeObserver;if(!e||!a||typeof e.getBoundingClientRect!="function")return()=>{};m?.disconnect();let i=new a(()=>b.size(Math.ceil(e.getBoundingClientRect().height)));return i.observe(e),m=i,()=>i.disconnect()},close(){m?.disconnect(),c(),t?.close(),g.clear()}};return{guest:b,send:l}}function x(n={}){let r=n.window??globalThis;return w({listen(t){return r.addEventListener("message",t),()=>r.removeEventListener("message",t)},fromHost:t=>t.source===r.parent&&(n.hostOrigin===void 0||t.origin===n.hostOrigin),ready:t=>r.parent?.postMessage(t,"*")}).guest}return H(_);})();
2
+ "use strict";var GraviewGuest=(()=>{var G=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var T=(n,t)=>{for(var r in t)G(n,r,{get:t[r],enumerable:!0})},S=(n,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of M(t))!O.call(n,a)&&a!==r&&G(n,a,{get:()=>t[a],enumerable:!(i=k(t,a))||i.enumerable});return n};var H=n=>S(G({},"__esModule",{value:!0}),n);var N={};T(N,{connect:()=>x,protocol:()=>p});var p=1;function v(n){if(typeof n=="string")return{type:"navigate",to:n};let{place:t,record:r,where:i,section:a}=n??{},y={...i===void 0?{}:{where:i},...a===void 0?{}:{section:String(a)}};return typeof t=="string"?{type:"navigate",place:t,...y}:typeof r=="string"?{type:"navigate",to:r,...y}:void 0}function h(n){let t=n;return typeof n=="object"&&n!==null&&t.graview==="host-hello"&&typeof t.nonce=="string"}function w(n,t={}){let r,i="",a,y=0,s=new Set,u=new Map,g=[],d=o=>{r?r.postMessage({...o,nonce:i}):g.push(o)},E=o=>{let e=o.data;if(!(!e||typeof e!="object")){if(e.type==="props"){a=e.props;for(let l of s)l(e.props)}else e.type==="answer"?(u.get(e.id)?.(e),u.delete(e.id)):e.type==="event"&&typeof e.listener=="number"?t.onEvent?.(e):e.type==="heartbeat"&&typeof e.beat=="number"&&d({type:"heartbeat",beat:e.beat});t.onMessage?.(e)}},f=()=>{},R=o=>{if(r||!n.fromHost(o)||!h(o.data)||o.data.protocol!==1)return;let e=o.ports[0];if(e){r=e,i=o.data.nonce,r.onmessage=E,r.start?.(),f();for(let l of g.splice(0))d(l)}};f=n.listen(R),n.ready({graview:"guest-ready",protocol:1});let m,b={get props(){return a},subscribe(o){return s.add(o),()=>s.delete(o)},act(o,e={}){let l=y+=1;return new Promise(c=>{u.set(l,c),d({type:"act",id:l,name:o,args:e})})},navigate(o){let e=v(o);e&&d(e)},size(o){d({type:"size",height:o})},autoSize(o){let e=o??globalThis.document?.documentElement,l=globalThis.ResizeObserver;if(!e||!l||typeof e.getBoundingClientRect!="function")return()=>{};m?.disconnect();let c=new l(()=>b.size(Math.ceil(e.getBoundingClientRect().height)));return c.observe(e),m=c,()=>c.disconnect()},close(){m?.disconnect(),f(),r?.close(),s.clear()}};return{guest:b,send:d}}var _=/^data:font\/(?:woff2|woff|ttf|otf);base64,[A-Za-z0-9+/]+=*$/;function A(){let n=[];return t=>{if(t.type!=="fonts"||!Array.isArray(t.fonts))return;let r=globalThis,i=r.FontFace,a=r.document?.fonts;if(!i||!a)return;let y=n;n=[];for(let s of t.fonts.slice(0,8)){if(typeof s?.family!="string"||typeof s.src!="string"||!_.test(s.src))continue;let u=`url(${JSON.stringify(s.src)})`,g={display:"swap",...typeof s.weight=="string"?{weight:s.weight}:{},...typeof s.style=="string"?{style:s.style}:{}},d=new i(s.family,u,g);d.status==="error"&&(d=new i(JSON.stringify(s.family),u,g)),a.add(d),n.push(d),d.load().catch(()=>a.delete(d))}for(let s of y)a.delete(s)}}function x(n={}){let t=n.window??globalThis;return w({listen(r){return t.addEventListener("message",r),()=>t.removeEventListener("message",r)},fromHost:r=>r.source===t.parent&&(n.hostOrigin===void 0||r.origin===n.hostOrigin),ready:r=>t.parent?.postMessage(r,"*")},{onMessage:A()}).guest}return H(N);})();
@@ -1 +1 @@
1
- {"version":3,"file":"client.generated.d.ts","sourceRoot":"","sources":["../src/client.generated.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,EAAE,MAA2mF,CAAC;AACvoF,mCAAmC;AACnC,eAAO,MAAM,mBAAmB,EAAE,MAA8D,CAAC"}
1
+ {"version":3,"file":"client.generated.d.ts","sourceRoot":"","sources":["../src/client.generated.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,EAAE,MAA8xG,CAAC;AAC1zG,mCAAmC;AACnC,eAAO,MAAM,mBAAmB,EAAE,MAA8D,CAAC"}
@@ -3,7 +3,7 @@
3
3
  * The frame guest's client as one classic script (FR-88), as text a host
4
4
  * inlines, and its hash for a policy that names it.
5
5
  */
6
- export const GUEST_CLIENT = "/*! @graview/guest/client.js — a frame guest's client (GraviewGuest.connect). Generated from src/client-script.ts. Elastic License 2.0. */\n\"use strict\";var GraviewGuest=(()=>{var f=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var T=(n,r)=>{for(var t in r)f(n,t,{get:r[t],enumerable:!0})},S=(n,r,t,d)=>{if(r&&typeof r==\"object\"||typeof r==\"function\")for(let s of M(r))!O.call(n,s)&&s!==t&&f(n,s,{get:()=>r[s],enumerable:!(d=k(r,s))||d.enumerable});return n};var H=n=>S(f({},\"__esModule\",{value:!0}),n);var _={};T(_,{connect:()=>x,protocol:()=>y});var y=1;function v(n){if(typeof n==\"string\")return{type:\"navigate\",to:n};let{place:r,record:t,where:d,section:s}=n??{},u={...d===void 0?{}:{where:d},...s===void 0?{}:{section:String(s)}};return typeof r==\"string\"?{type:\"navigate\",place:r,...u}:typeof t==\"string\"?{type:\"navigate\",to:t,...u}:void 0}function h(n){let r=n;return typeof n==\"object\"&&n!==null&&r.graview===\"host-hello\"&&typeof r.nonce==\"string\"}function w(n,r={}){let t,d=\"\",s,u=0,g=new Set,p=new Map,G=[],l=o=>{t?t.postMessage({...o,nonce:d}):G.push(o)},E=o=>{let e=o.data;if(!(!e||typeof e!=\"object\")){if(e.type===\"props\"){s=e.props;for(let a of g)a(e.props)}else e.type===\"answer\"?(p.get(e.id)?.(e),p.delete(e.id)):e.type===\"event\"&&typeof e.listener==\"number\"?r.onEvent?.(e):e.type===\"heartbeat\"&&typeof e.beat==\"number\"&&l({type:\"heartbeat\",beat:e.beat});r.onMessage?.(e)}},c=()=>{},R=o=>{if(t||!n.fromHost(o)||!h(o.data)||o.data.protocol!==1)return;let e=o.ports[0];if(e){t=e,d=o.data.nonce,t.onmessage=E,t.start?.(),c();for(let a of G.splice(0))l(a)}};c=n.listen(R),n.ready({graview:\"guest-ready\",protocol:1});let m,b={get props(){return s},subscribe(o){return g.add(o),()=>g.delete(o)},act(o,e={}){let a=u+=1;return new Promise(i=>{p.set(a,i),l({type:\"act\",id:a,name:o,args:e})})},navigate(o){let e=v(o);e&&l(e)},size(o){l({type:\"size\",height:o})},autoSize(o){let e=o??globalThis.document?.documentElement,a=globalThis.ResizeObserver;if(!e||!a||typeof e.getBoundingClientRect!=\"function\")return()=>{};m?.disconnect();let i=new a(()=>b.size(Math.ceil(e.getBoundingClientRect().height)));return i.observe(e),m=i,()=>i.disconnect()},close(){m?.disconnect(),c(),t?.close(),g.clear()}};return{guest:b,send:l}}function x(n={}){let r=n.window??globalThis;return w({listen(t){return r.addEventListener(\"message\",t),()=>r.removeEventListener(\"message\",t)},fromHost:t=>t.source===r.parent&&(n.hostOrigin===void 0||t.origin===n.hostOrigin),ready:t=>r.parent?.postMessage(t,\"*\")}).guest}return H(_);})();\n";
6
+ export const GUEST_CLIENT = "/*! @graview/guest/client.js — a frame guest's client (GraviewGuest.connect). Generated from src/client-script.ts. Elastic License 2.0. */\n\"use strict\";var GraviewGuest=(()=>{var G=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var T=(n,t)=>{for(var r in t)G(n,r,{get:t[r],enumerable:!0})},S=(n,t,r,i)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let a of M(t))!O.call(n,a)&&a!==r&&G(n,a,{get:()=>t[a],enumerable:!(i=k(t,a))||i.enumerable});return n};var H=n=>S(G({},\"__esModule\",{value:!0}),n);var N={};T(N,{connect:()=>x,protocol:()=>p});var p=1;function v(n){if(typeof n==\"string\")return{type:\"navigate\",to:n};let{place:t,record:r,where:i,section:a}=n??{},y={...i===void 0?{}:{where:i},...a===void 0?{}:{section:String(a)}};return typeof t==\"string\"?{type:\"navigate\",place:t,...y}:typeof r==\"string\"?{type:\"navigate\",to:r,...y}:void 0}function h(n){let t=n;return typeof n==\"object\"&&n!==null&&t.graview===\"host-hello\"&&typeof t.nonce==\"string\"}function w(n,t={}){let r,i=\"\",a,y=0,s=new Set,u=new Map,g=[],d=o=>{r?r.postMessage({...o,nonce:i}):g.push(o)},E=o=>{let e=o.data;if(!(!e||typeof e!=\"object\")){if(e.type===\"props\"){a=e.props;for(let l of s)l(e.props)}else e.type===\"answer\"?(u.get(e.id)?.(e),u.delete(e.id)):e.type===\"event\"&&typeof e.listener==\"number\"?t.onEvent?.(e):e.type===\"heartbeat\"&&typeof e.beat==\"number\"&&d({type:\"heartbeat\",beat:e.beat});t.onMessage?.(e)}},f=()=>{},R=o=>{if(r||!n.fromHost(o)||!h(o.data)||o.data.protocol!==1)return;let e=o.ports[0];if(e){r=e,i=o.data.nonce,r.onmessage=E,r.start?.(),f();for(let l of g.splice(0))d(l)}};f=n.listen(R),n.ready({graview:\"guest-ready\",protocol:1});let m,b={get props(){return a},subscribe(o){return s.add(o),()=>s.delete(o)},act(o,e={}){let l=y+=1;return new Promise(c=>{u.set(l,c),d({type:\"act\",id:l,name:o,args:e})})},navigate(o){let e=v(o);e&&d(e)},size(o){d({type:\"size\",height:o})},autoSize(o){let e=o??globalThis.document?.documentElement,l=globalThis.ResizeObserver;if(!e||!l||typeof e.getBoundingClientRect!=\"function\")return()=>{};m?.disconnect();let c=new l(()=>b.size(Math.ceil(e.getBoundingClientRect().height)));return c.observe(e),m=c,()=>c.disconnect()},close(){m?.disconnect(),f(),r?.close(),s.clear()}};return{guest:b,send:d}}var _=/^data:font\\/(?:woff2|woff|ttf|otf);base64,[A-Za-z0-9+/]+=*$/;function A(){let n=[];return t=>{if(t.type!==\"fonts\"||!Array.isArray(t.fonts))return;let r=globalThis,i=r.FontFace,a=r.document?.fonts;if(!i||!a)return;let y=n;n=[];for(let s of t.fonts.slice(0,8)){if(typeof s?.family!=\"string\"||typeof s.src!=\"string\"||!_.test(s.src))continue;let u=`url(${JSON.stringify(s.src)})`,g={display:\"swap\",...typeof s.weight==\"string\"?{weight:s.weight}:{},...typeof s.style==\"string\"?{style:s.style}:{}},d=new i(s.family,u,g);d.status===\"error\"&&(d=new i(JSON.stringify(s.family),u,g)),a.add(d),n.push(d),d.load().catch(()=>a.delete(d))}for(let s of y)a.delete(s)}}function x(n={}){let t=n.window??globalThis;return w({listen(r){return t.addEventListener(\"message\",r),()=>t.removeEventListener(\"message\",r)},fromHost:r=>r.source===t.parent&&(n.hostOrigin===void 0||r.origin===n.hostOrigin),ready:r=>t.parent?.postMessage(r,\"*\")},{onMessage:A()}).guest}return H(N);})();\n";
7
7
  /** For `script-src 'sha256-…'`. */
8
- export const GUEST_CLIENT_SHA256 = "sha256-YrdP8mRqaOd0ZEbEYz+1p4bAzCbikmMCfQtrzLBJ3uo=";
8
+ export const GUEST_CLIENT_SHA256 = "sha256-2XAeZMdonBXb90qRuqWp/vsTv1iw+srlYoePfCaadUM=";
9
9
  //# sourceMappingURL=client.generated.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.generated.js","sourceRoot":"","sources":["../src/client.generated.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAW,kmFAAkmF,CAAC;AACvoF,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAW,qDAAqD,CAAC"}
1
+ {"version":3,"file":"client.generated.js","sourceRoot":"","sources":["../src/client.generated.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAW,qxGAAqxG,CAAC;AAC1zG,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAW,qDAAqD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"guest.d.ts","sourceRoot":"","sources":["../src/guest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAErD,8DAA8D;AAC9D,UAAU,WAAW;IACnB,QAAQ,CAAC,MAAM,EAAE;QAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IACtF,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACjF,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;CACrF;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,YAAY,EAAE,KAAK,EAAE,CAAC;AAEtB;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,KAAK,CAUrE"}
1
+ {"version":3,"file":"guest.d.ts","sourceRoot":"","sources":["../src/guest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAGrD,8DAA8D;AAC9D,UAAU,WAAW;IACnB,QAAQ,CAAC,MAAM,EAAE;QAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IACtF,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACjF,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;CACrF;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,YAAY,EAAE,KAAK,EAAE,CAAC;AAqCtB;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,KAAK,CAarE"}
package/dist/guest.js CHANGED
@@ -1,4 +1,42 @@
1
1
  import { openGuest } from "./channel.js";
2
+ /** A face as the client takes it: a `data:` font, never an address it would fetch. */
3
+ const DATA_FONT = /^data:font\/(?:woff2|woff|ttf|otf);base64,[A-Za-z0-9+/]+=*$/;
4
+ /**
5
+ * THE FACES THE APP LENDS A FRAME (Roadmap f-faces-lent-to-frames): each a
6
+ * `data:` font the host read, put in this document's fonts so the guest's
7
+ * `font-family` draws in it, and those lent before taken out once the new
8
+ * are in. Nothing is fetched: what is not a `data:` font is not taken. The
9
+ * frame's client alone: a worker view's faces are the page's (fonts.ts).
10
+ */
11
+ function frameFonts() {
12
+ let lent = [];
13
+ return (message) => {
14
+ if (message.type !== "fonts" || !Array.isArray(message.fonts))
15
+ return;
16
+ const here = globalThis;
17
+ const Face = here.FontFace;
18
+ const faces = here.document?.fonts;
19
+ if (!Face || !faces)
20
+ return;
21
+ const before = lent;
22
+ lent = [];
23
+ for (const font of message.fonts.slice(0, 8)) {
24
+ if (typeof font?.family !== "string" || typeof font.src !== "string" || !DATA_FONT.test(font.src))
25
+ continue;
26
+ const source = `url(${JSON.stringify(font.src)})`;
27
+ const descriptors = { display: "swap", ...(typeof font.weight === "string" ? { weight: font.weight } : {}), ...(typeof font.style === "string" ? { style: font.style } : {}) };
28
+ /* A family that is not one identifier ("Baloo 2") is an error at once in Firefox unless quoted, as the host's own loading finds (fonts.ts). */
29
+ let face = new Face(font.family, source, descriptors);
30
+ if (face.status === "error")
31
+ face = new Face(JSON.stringify(font.family), source, descriptors);
32
+ faces.add(face);
33
+ lent.push(face);
34
+ face.load().catch(() => faces.delete(face));
35
+ }
36
+ for (const face of before)
37
+ faces.delete(face);
38
+ };
39
+ }
2
40
  /**
3
41
  * Connect a guest view to its host: say it is ready, take the first hello
4
42
  * from the parent, and talk only over the port that came with it.
@@ -12,6 +50,6 @@ export function connectGuest(options = {}) {
12
50
  },
13
51
  fromHost: (event) => event.source === at.parent && (options.hostOrigin === undefined || event.origin === options.hostOrigin),
14
52
  ready: (message) => at.parent?.postMessage(message, "*"),
15
- }).guest;
53
+ }, { onMessage: frameFonts() }).guest;
16
54
  }
17
55
  //# sourceMappingURL=guest.js.map
package/dist/guest.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"guest.js","sourceRoot":"","sources":["../src/guest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,MAAM,cAAc,CAAC;AAsBrD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,UAA+B,EAAE;IAC5D,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,IAAK,UAAqC,CAAC;IACpE,OAAO,SAAS,CAAC;QACf,MAAM,CAAC,KAAK;YACV,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YACtC,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,mBAAmB,CAAC,SAA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