@eduwork/dsh-remote-access 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.
@@ -1 +1,4 @@
1
- "use strict";(()=>{var a=parent.remoteTunnel,s=new URL(document.baseURI);function l(n){let{name:e,code:t,message:r,details:o}=n,d=e==="TunnelStreamError";return Object.assign(new Error(r??"remote stream failed"),{dshRemoteStreamFailure:d?{kind:"remote",code:t,details:structuredClone(o)}:{kind:"carrier"}})}function c(n){let e=n.target?.closest?.("a[download]");if(n.defaultPrevented||!(e instanceof HTMLAnchorElement))return;let t=new URL(e.href);t.origin!==s.origin||!t.pathname.startsWith(s.pathname)||(n.preventDefault(),u(t,e.download).catch(r=>console.error("remote download failed",r)))}var i=HTMLAnchorElement.prototype.click;async function u(n,e){let t=await fetch(n);if(!t.ok)throw new Error(`HTTP ${t.status} for ${n.pathname}`);let r=document.createElement("a");r.href=URL.createObjectURL(await t.blob()),r.download=e||m(t.headers.get("content-disposition")??"")||n.pathname.split("/").at(-1),i.call(r),setTimeout(()=>URL.revokeObjectURL(r.href),6e4)}function m(n){let e=/filename\*=UTF-8''([^;]+)/i.exec(n)?.[1];return e===void 0?/filename="?([^";]+)/i.exec(n)?.[1]:decodeURIComponent(e)}a!==void 0&&(document.documentElement.setAttribute("data-eduwork-remote",""),Object.assign(globalThis,{__DSH_TRANSPORT__:{async fetch(n,e){let t=new URL(n,s),r={method:e.method??"GET",url:`/${t.pathname.slice(s.pathname.length)}${t.search}`,headers:[...new Headers(e.headers)],...e.body!=null&&{body:await new Response(e.body).arrayBuffer()}},o=await a.fetch(r,e.signal);if("error"in o)throw new TypeError(o.error);return new Response(o.body.byteLength===0?null:o.body,{status:o.status,headers:o.headers})},async*openStream(n,e,t,r){try{for await(let o of a.openStream(n,e,t,r))yield structuredClone(o)}catch(o){throw t.aborted?t.reason:l(o)}}}}),addEventListener("click",c,!0),HTMLAnchorElement.prototype.click=function(){this.isConnected||this.addEventListener("click",c,{once:!0}),i.call(this)});})();
1
+ "use strict";(()=>{Promise.withResolvers??=()=>{let e,t;return{promise:new Promise((i,r)=>{e=i,t=r}),resolve:e,reject:t}};AbortSignal.any??=e=>{let t=[...e],o=new AbortController,i=t.find(a=>a.aborted);if(i!==void 0)return o.abort(i.reason),o.signal;let r=a=>{for(let d of t)d.removeEventListener("abort",r);o.abort(a.target.reason)};for(let a of t)a.addEventListener("abort",r);return o.signal};URL.canParse??=(e,t)=>{try{return new URL(e,t),!0}catch{return!1}};var v="--eduwork-anchor-name",A="--eduwork-position-anchor",E=new Map([["anchor-name",v],["position-anchor",A]]),w=12,S=4,y="data-eduwork-anchored",T="--eduwork-anchored-top",L="--eduwork-anchored-left",k="--eduwork-anchored-max-width",C="--eduwork-anchored-max-height",W=`[${y}]{top:var(${T})!important;left:var(${L})!important;right:auto!important;bottom:auto!important}
2
+ [${y}~=narrow]{max-width:var(${k})!important}
3
+ [${y}~=short]{max-height:var(${C})!important}`;function $(e,t){let o=t+1;for(;o<e.length&&e[o]!==e[t];)o+=e[o]==="\\"?2:1;return o}function _(e){let t=[],o=0,i=0;for(let r=0;r<e.length;r++){let a=e[r];a==="\\"?r++:a==='"'||a==="'"?r=$(e,r):a==="("||a==="["?o++:a===")"||a==="]"?o--:a===","&&o===0&&(t.push(e.slice(i,r).trim()),i=r+1)}return t.push(e.slice(i).trim()),t}function q(e){let t=[],o=[],i=[],r=[],a="";for(let d=0;d<e.length;d++){let u=e[d];if(u==="/"&&e[d+1]==="*"){let h=e.indexOf("*/",d+2);d=h<0?e.length:h+1}else if(u==='"'||u==="'"){let h=$(e,d);a+=e.slice(d,h+1),d=h}else if(u==="\\")a+=e.slice(d,d+2),d++;else if(u==="{")r.push(a.trim()),a="";else if(u===";"||u==="}"){let[,h,m]=/^\s*(anchor-name|position-anchor)\s*:([^]*)$/.exec(a)??[];if(h!==void 0&&m!==void 0&&r.length>0){let f=E.get(h);t.push(`${r.join("{")}{${f}:${m.trim()}${"}".repeat(r.length)}`),(f===v?o:i).push(..._(r.at(-1)))}u==="}"&&r.pop(),a=""}else a+=u}return{css:t.join(`
4
+ `),anchors:o,cards:i}}function N(e,t,o){let i=o.height-w-S-e.bottom,r=e.top-S-w,a=t.height<=i,d=a===t.height<=r?i>=r:a,u=Math.max(0,d?i:r),h=Math.min(t.height,u),m=o.width-2*w,f=Math.min(t.width,m),R=e.left+e.right>o.width,b=Math.max(w,Math.min(R?e.right-f:e.left,o.width-w-f));return{top:d?e.bottom+S:e.top-S-h,left:b,...t.width>m&&{maxWidth:m},...t.height>u&&{maxHeight:u}}}function B(){for(let n of E.values())CSS.registerProperty({name:n,syntax:"*",inherits:!1});let e={anchors:new Set([`[style*="${v}"]`]),cards:new Set([`[style*="${A}"]`])},t=CSSStyleDeclaration.prototype,{setProperty:o,getPropertyValue:i,getPropertyPriority:r,removeProperty:a}=t,d=n=>E.get(n)??n;Object.assign(t,{setProperty(n,c,s){o.call(this,d(n),c,s)},getPropertyValue(n){return i.call(this,d(n))},getPropertyPriority(n){return r.call(this,d(n))},removeProperty(n){return a.call(this,d(n))}});for(let[n,c]of E)Object.defineProperty(t,n.replace(/-(\w)/g,(s,l)=>l.toUpperCase()),{configurable:!0,enumerable:!0,get(){return i.call(this,c)},set(s){o.call(this,c,s??"")}});let u=new WeakSet,h=n=>{let c=document.createElement("style");return u.add(c),c.textContent=n,c},m=(n,c)=>{let s=q(c);for(let l of s.anchors)CSS.supports(`selector(${l})`)&&e.anchors.add(l);for(let l of s.cards)CSS.supports(`selector(${l})`)&&e.cards.add(l);s.css!==""&&(n.after(h(s.css)),x())},f=n=>{u.has(n)||(n instanceof HTMLStyleElement?(u.add(n),m(n,n.textContent??"")):n instanceof HTMLLinkElement&&n.relList.contains("stylesheet")&&n.href!==""&&(u.add(n),fetch(n.href).then(c=>{if(!c.ok)throw new Error(`HTTP ${c.status}`);return c.text()}).then(c=>m(n,c),c=>console.error("anchor positioning fallback cannot read",n.href,c))))},R,b=new Set,j=n=>{n.removeAttribute(y);for(let c of[T,L,k,C])n.style.removeProperty(c);b.delete(n)},O=(n,c)=>{R??=document.head.appendChild(h(W)),b.add(n);let{style:s}=n;n.setAttribute(y,""),s.setProperty(T,"0px"),s.setProperty(L,"0px");let l=n.getBoundingClientRect(),g=document.documentElement,p=N(c.getBoundingClientRect(),l,{width:g.clientWidth,height:g.clientHeight});s.setProperty(T,`${p.top-l.top}px`),s.setProperty(L,`${p.left-l.left}px`),p.maxWidth!==void 0&&s.setProperty(k,`${p.maxWidth}px`),p.maxHeight!==void 0&&s.setProperty(C,`${p.maxHeight}px`),n.setAttribute(y,`${p.maxWidth===void 0?"":"narrow"} ${p.maxHeight===void 0?"":"short"}`.trim())},M=0,x=()=>{M||=requestAnimationFrame(I)},I=()=>{M=0;let n=new Map;for(let s of document.querySelectorAll([...e.anchors].join()))if(s.getClientRects().length!==0)for(let l of getComputedStyle(s).getPropertyValue(v).split(","))l.trim()!==""&&n.set(l.trim(),s);let c=new Map;for(let s of document.querySelectorAll([...e.cards].join())){let l=getComputedStyle(s),g=n.get(l.getPropertyValue(A).trim());g===void 0||s.contains(g)||s.getClientRects().length===0||l.visibility==="hidden"||l.position!=="fixed"&&l.position!=="absolute"||c.set(s,g)}for(let s of b)c.has(s)||j(s);for(let[s,l]of c)O(s,l);c.size>0&&x()};new MutationObserver(n=>{for(let c of n)for(let s of c.addedNodes)if(s instanceof Element){f(s);for(let l of s.querySelectorAll("style, link"))f(l)}x()}).observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","hidden"]});for(let n of document.querySelectorAll("style, link"))f(n)}typeof CSS<"u"&&!CSS.supports("anchor-name","--a")&&typeof CSS.registerProperty=="function"&&B();var H=parent.remoteTunnel,P=new URL(document.baseURI);function F(e){let{name:t,code:o,message:i,details:r}=e,a=t==="TunnelStreamError";return Object.assign(new Error(i??"remote stream failed"),{dshRemoteStreamFailure:a?{kind:"remote",code:o,details:structuredClone(r)}:{kind:"carrier"}})}function U(e){let t=e.target?.closest?.("a[download]");if(e.defaultPrevented||!(t instanceof HTMLAnchorElement))return;let o=new URL(t.href);o.origin!==P.origin||!o.pathname.startsWith(P.pathname)||(e.preventDefault(),G(o,t.download).catch(i=>console.error("remote download failed",i)))}var D=HTMLAnchorElement.prototype.click;async function G(e,t){let o=await fetch(e);if(!o.ok)throw new Error(`HTTP ${o.status} for ${e.pathname}`);let i=document.createElement("a");i.href=URL.createObjectURL(await o.blob()),i.download=t||V(o.headers.get("content-disposition")??"")||e.pathname.split("/").at(-1),D.call(i),setTimeout(()=>URL.revokeObjectURL(i.href),6e4)}function V(e){let t=/filename\*=UTF-8''([^;]+)/i.exec(e)?.[1];return t===void 0?/filename="?([^";]+)/i.exec(e)?.[1]:decodeURIComponent(t)}H!==void 0&&(document.documentElement.setAttribute("data-eduwork-remote",""),Object.assign(globalThis,{__DSH_TRANSPORT__:{async fetch(e,t){let o=new URL(e,P),i={method:t.method??"GET",url:`/${o.pathname.slice(P.pathname.length)}${o.search}`,headers:[...new Headers(t.headers)],...t.body!=null&&{body:await new Response(t.body).arrayBuffer()}},r=await H.fetch(i,t.signal);if("error"in r)throw new TypeError(r.error);return new Response(r.body.byteLength===0?null:r.body,{status:r.status,headers:r.headers})},async*openStream(e,t,o,i){try{for await(let r of H.openStream(e,t,o,i))yield structuredClone(r)}catch(r){throw o.aborted?o.reason:F(r)}}}}),addEventListener("click",U,!0),HTMLAnchorElement.prototype.click=function(){this.isConnected||this.addEventListener("click",U,{once:!0}),D.call(this)});})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduwork/dsh-remote-access",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "End-to-end encrypted remote access to a DSH host through a self-hosted relay",
5
5
  "type": "module",
6
6
  "license": "MulanPSL-2.0 AND MIT",