@01.works/visual-review 0.8.2 → 0.8.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@01.works/visual-review",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "Invitation-only visual feedback for staging websites, hosted by 01.works.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- const e=`https://visual-review.01.works`;function t(e){let t=new URL(e),n=t.hostname===`localhost`||t.hostname===`127.0.0.1`||t.hostname.endsWith(`.test`)||t.hostname.endsWith(`.local`);if(t.protocol!==`https:`&&!(n&&t.protocol===`http:`))throw Error(`Visual Review serviceUrl must use HTTPS outside local development`);if(t.username||t.password||t.search||t.hash)throw Error(`Visual Review serviceUrl must be a plain origin or base path`);return t.toString().replace(/\/+$/,``)}const n=()=>{let e=Promise.resolve(null);return{ready:e,refresh:()=>e,dispose(){}}},r=new Map,i=6e4,a=1e4;function o(e={}){if(e.enabled!==!0||typeof window>`u`||typeof document>`u`)return n();let r=!1,i=0,a=null,o=null,p=null,h=null,g=!1,_=null,S=null,E=document.baseURI,A=new WeakMap,M=new Map,N=W(window),P=Z(e.styleNonce,document),F=e.activationParam??`visual-review`,I=v(window.location,F),L=m(window,e=>{let t=v(e,F);if(t===I)return;let n=O(F,e.href);n&&M.set(e.origin,n),I=t,z(e)}),R=e=>{r||!h||e.target!==h||(I=v(window.location,F),U())};return window.addEventListener(`visual-review:reauthenticate-required`,R),{ready:U(),refresh(){return r?Promise.resolve(null):(I=v(window.location,F),z(y(window.location),!0))},dispose(){r||(r=!0,i+=1,V(),h?.remove(),h=null,S=null,_?.remove(),_=null,M.clear(),L.unsubscribe(),window.removeEventListener(`visual-review:reauthenticate-required`,R))}};function z(e,t=!1){return!h||!S||S.origin!==e.origin||O(F,e.href)?U():B(h,S,e,t)}function B(t,n,r,c){let l=++i;a!==o&&a?.abort();let u=new AbortController;a=u;let d=s(e.build,r),f=(async()=>{try{let i=await k(n.resolvePage({location:r,signal:u.signal,collaboration:{cursors:e.collaboration?.cursors===!0,chat:e.collaboration?.chat===!0,scopeId:d}}),u.signal);return Q(l,u)?(i.commit?.(),t.setPage({pageId:i.pageId,collaboration:{roomId:i.collaborationRoomId,scopeId:d}},{reload:c}),t.isConnected||document.body?.append(t),t):$(l)}catch{return Q(l,u)?U():$(l)}})();return p=f,f}function V(){a?.abort(),o?.abort(),a=null,o=null}function U(){let t=++i;V(),h?.remove(),h=null,S=null,_?.remove();let n=new AbortController,r=document.createElement(`div`);r.dataset.agencyReviewRoot=``,a=n,o=n,_=r;let s=K(t,n,r);return p=s,s.then(r=>{r&&Q(t,n)&&h===r&&e.onReady?.(r)}),s}async function K(t,n,i){try{let e=document.body??await j(document,n.signal);if(!Q(t,n))return $(t);e.append(i);let r=await q(t,n,i);return Q(t,n)?r:(i.remove(),$(t))}catch(a){if(!Q(t,n))return i.remove(),$(t);if(d(a,`AUTH_CANCELLED`))return i.remove(),_===i&&(_=null),null;let o=A.get(i)?.[3];X(a,i);let s=Y(a,A.get(i)?.[2]);return o!==`storage`||g||!f(a)?J(i,s.message,P,()=>{r||_!==i||(I=v(window.location,F),U())}):(i.remove(),_===i&&(_=null)),e.onError?.(s),window.dispatchEvent(new CustomEvent(`visual-review:error`,{detail:s})),null}}async function q(n,r,i){let a=t(e.serviceUrl??`https://visual-review.01.works`),o=y(window.location),d=D(a,F,o,N),f=b(M.get(o.origin)),p=x(C(a,o.origin)),m=d?.source===`url`?d:f??p??d;if(!m)return A.delete(i),i.remove(),_===i&&(_=null),null;let O=m.invitationId;A.set(i,[a,o.origin,O,m.source]),m.source===`url`?(G(a,o.origin,N),M.set(o.origin,O),w(a,o.origin,O),L.suppress(()=>ee(F))):m.source===`handoff`&&M.set(o.origin,O),I=v(window.location,F);let j=await k((e.runtime??await c(a)).resolve({invitationId:O,location:o,signal:r.signal,authHost:i,styleNonce:P,collaboration:{cursors:e.collaboration?.cursors===!0,chat:e.collaboration?.chat===!0,scopeId:s(e.build,o)}}),r.signal);if(!Q(n,r))return null;T(a,o.origin,O),H(a,O,o,N),M.set(o.origin,O);let R=e.sourceContextResolver??await u(e.build,E,r.signal,P);if(!Q(n,r))return null;let{mountReviewWidget:z}=await l(r.signal);return Q(n,r)?(h=z({...j,collaboration:{cursors:e.collaboration?.cursors===!0&&!!(j.collaborationRepository&&j.collaborationRoomId),chat:e.collaboration?.chat===!0&&!!j.collaborationRepository,repository:j.collaborationRepository,roomId:j.collaborationRoomId,scopeId:s(e.build,o)},developerTools:e.developerTools,onNavigateToFeedback:async t=>{let n=new URL(t,window.location.href);if(n.origin!==window.location.origin)throw Error(`Visual Review route navigation must stay on the staging origin`);if(e.navigateToFeedback){await e.navigateToFeedback(n.href);return}window.location.assign(n.href)},sourceContextResolver:R,styleNonce:P}),S=j.resolvePage?{origin:o.origin,resolvePage:e=>j.resolvePage(e)}:null,i.remove(),_===i&&(_=null),g=!0,window.dispatchEvent(new CustomEvent(`visual-review:ready`,{detail:h})),h):null}function X(e,t){if(!f(e))return;let n=A.get(t);if(!n)return;let[r,i,a]=n;T(r,i,a),M.get(i)===a&&M.delete(i),G(r,i,N,a)}function Q(e,t){return!r&&i===e&&a===t&&!t.signal.aborted}function $(e){return!r&&i!==e?p:null}}function s(e,t){return JSON.stringify([M(e).buildId,t.pathname,t.search])}async function c(e){let{createHostedReviewRuntime:t}=await import(`./hosted-runtime-CbQolIXk.js`);return t({serviceUrl:e})}async function l(e){return A(import(`./src-F4lT3iYm.js`),e,a,`리뷰 위젯을 불러오는 시간이 초과되었습니다. 다시 시도해 주세요.`)}async function u(e,t,n,r){let i=M(e),{createGeneratedSourceContextResolver:o}=await A(import(`./generated-source-context-R_klctZM.js`),n,a,`리뷰 소스 정보를 불러오는 시간이 초과되었습니다. 다시 시도해 주세요.`),s=o({build:i}),c=s.resolve.bind(s),l=null;return s.resolve=async(e,t)=>{let n=await c(e,t);if(n.source)return n;try{if(!l){let{createReactSourceContextResolver:e}=await import(`./source-context-leuy5fdX.js`).then(e=>e.t);l=e({build:i,styleNonce:r})}let a=await l.resolve(e,t);return a.source?a:n}catch{return n}},s}function d(e,t){return e instanceof Error&&`code`in e&&e.code===t}function f(e){let t=e instanceof Error&&`code`in e?e.code:void 0;return typeof t==`string`&&/^INVITATION_(?:EXPIRED|NOT_FOUND|REVOKED)$/.test(t)}const p=new WeakMap;function m(e,t){let n=p.get(e);if(!n){let t=e.history,r=t.pushState,i=t.replaceState,a=new Set;n={history:t,originalPushStateDescriptor:Object.getOwnPropertyDescriptor(t,`pushState`),originalReplaceStateDescriptor:Object.getOwnPropertyDescriptor(t,`replaceState`),patchedPushState:function(t,n,i){r.call(this,t,n,i),h(e)},patchedReplaceState:function(t,n,r){i.call(this,t,n,r),h(e)},popstateListener:()=>h(e),subscribers:a,suppressionDepth:0},p.set(e,n),g(t,`pushState`,n.patchedPushState),g(t,`replaceState`,n.patchedReplaceState),e.addEventListener(`popstate`,n.popstateListener)}n.subscribers.add(t);let r=!0;return{suppress(e){n.suppressionDepth+=1;try{return e()}finally{--n.suppressionDepth}},unsubscribe(){r&&(r=!1,n.subscribers.delete(t),!(n.subscribers.size>0)&&(e.removeEventListener(`popstate`,n.popstateListener),_(n.history,`pushState`,n.patchedPushState,n.originalPushStateDescriptor),_(n.history,`replaceState`,n.patchedReplaceState,n.originalReplaceStateDescriptor),p.delete(e)))}}}function h(e){let t=p.get(e);if(!t||t.suppressionDepth>0)return;let n=y(e.location);[...t.subscribers].forEach(e=>e(n))}function g(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,writable:!0,value:n})}function _(e,t,n,r){if(Object.getOwnPropertyDescriptor(e,t)?.value===n){if(r){Object.defineProperty(e,t,r);return}delete e[t]}}function v(e,t){return`${e.origin}\n${e.pathname}\n${O(t,e.href)??``}`}function y(e){return new URL(e.href)}function b(e){return e?{invitationId:e,source:`memory`}:null}function x(e){return e?{invitationId:e,source:`handoff`}:null}function S(e,t){return JSON.stringify([e,t])}function C(e,t,n=Date.now()){let i=S(e,t),a=r.get(i);if(a){if(a.expiresAt>n)return a.invitationId;clearTimeout(a.timeout),r.delete(i)}}function w(e,t,n,a=Date.now()){E(a);let o=S(e,t),s=r.get(o);for(s&&(clearTimeout(s.timeout),r.delete(o));r.size>=32;){let e=r.keys().next().value;if(!e)break;let t=r.get(e);t&&clearTimeout(t.timeout),r.delete(e)}let c=a+i,l=setTimeout(()=>{r.get(o)?.expiresAt===c&&r.delete(o)},i);r.set(o,{invitationId:n,expiresAt:c,timeout:l})}function T(e,t,n){let i=S(e,t),a=r.get(i);a?.invitationId===n&&(clearTimeout(a.timeout),r.delete(i))}function E(e){for(let[t,n]of r)n.expiresAt>e||(clearTimeout(n.timeout),r.delete(t))}function D(e,t,n,r){let i=O(t,n.href);if(i)return{invitationId:i,source:`url`};let a=U(r,K(e,n.origin));return a?{invitationId:a,source:`storage`}:q(n.hostname)?{invitationId:`local-preview`,source:`local-preview`}:null}function O(e,t){let n=new URL(t);return(n.searchParams.get(e)??n.searchParams.get(`agency-review`)??n.searchParams.get(`agency-review-invite`))?.trim()||null}function ee(e){let t=new URL(window.location.href),n=new Set([e,`visual-review`,`agency-review`,`agency-review-invite`]),r=!1;n.forEach(e=>{t.searchParams.has(e)&&(t.searchParams.delete(e),r=!0)}),r&&window.history.replaceState(window.history.state,``,`${t.pathname}${t.search}${t.hash}`)}function k(e,t){return new Promise((n,r)=>{let i=()=>r(new DOMException(`Aborted`,`AbortError`));if(t.aborted){i();return}t.addEventListener(`abort`,i,{once:!0}),e.then(e=>{t.removeEventListener(`abort`,i),n(e)},e=>{t.removeEventListener(`abort`,i),r(e)})})}function A(e,t,n,r){return new Promise((i,a)=>{let o=!1,s=e=>{o||(o=!0,clearTimeout(l),t.removeEventListener(`abort`,c),e())},c=()=>{s(()=>a(new DOMException(`Aborted`,`AbortError`)))},l=setTimeout(()=>{s(()=>a(Error(r)))},n);if(t.aborted){c();return}t.addEventListener(`abort`,c,{once:!0}),e.then(e=>s(()=>i(e)),e=>s(()=>a(e)))})}function j(e,t){return e.body?Promise.resolve(e.body):t.aborted?Promise.reject(new DOMException(`Aborted`,`AbortError`)):new Promise((n,r)=>{let i=!1,a=new MutationObserver(()=>c()),o=()=>{e.removeEventListener(`DOMContentLoaded`,c),t.removeEventListener(`abort`,l),a.disconnect()},s=e=>{i||(i=!0,o(),e())},c=()=>{let t=e.body;t&&s(()=>n(t))},l=()=>{s(()=>r(new DOMException(`Aborted`,`AbortError`)))};e.addEventListener(`DOMContentLoaded`,c),t.addEventListener(`abort`,l,{once:!0}),a.observe(e,{childList:!0,subtree:!0}),c()})}function M(e){let t=document.querySelector(`meta[name="visual-review-build"]`),n=document.querySelector(`meta[name="visual-review-commit"]`),r=V(F()),i=V(I());return{buildId:B(e?.buildId)??z(t)??r??`unversioned`,gitCommit:L(e,n,i),generatedAt:e?.generatedAt,mode:e?.mode??P(N())??(q(window.location.hostname)?`development`:`production`)}}function N(){try{return process.env.VISUAL_REVIEW_PUBLIC_BUILD_MODE}catch{return}}function P(e){return e===`development`||e===`preview`||e===`production`?e:void 0}function F(){try{return process.env.VISUAL_REVIEW_PUBLIC_BUILD_ID}catch{return}}function I(){try{return process.env.VISUAL_REVIEW_PUBLIC_GIT_COMMIT}catch{return}}function L(e,t,n){return e?.gitCommit===null?null:typeof e?.gitCommit==`string`?R(e.gitCommit):R(t?.content)??R(n)}function R(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(t)?t:null}function z(e){return V(e?.content)}function B(e){let t=typeof e==`string`?e.trim():``;return t.length>0?t:null}function V(e){return typeof e==`string`&&e.length>0?e:null}function H(e,t,n,r){try{r?.setItem(K(e,n.origin),t)}catch{}}function U(e,t){try{return e?.getItem(t)??null}catch{return null}}function W(e){try{return e.localStorage}catch{return null}}function G(e,t,n,r){try{if(!n)return;let i=K(e,t),a=n.getItem(i);if(a===null||r!==void 0&&a!==r)return;n.removeItem(i)}catch{}}function K(e,t){return`visual-review:${e}:${t}:invitation`}function q(e){return e===`localhost`||e===`127.0.0.1`||e.endsWith(`.test`)||e.endsWith(`.local`)}function J(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=i.ownerDocument,o=a.createElement(`style`);n&&(o.nonce=n),o.textContent=te;let s=a.createElement(`strong`);s.textContent=`Visual Review를 시작할 수 없습니다`;let c=a.createElement(`span`);c.textContent=t;let l=a.createElement(`button`);l.type=`button`,l.textContent=`다시 시도`,l.addEventListener(`click`,()=>{l.disabled=!0,r?.()},{once:!0}),i.replaceChildren(o,s,c,l)}function Y(e,t){let n=e instanceof Error?e.message:String(e),r=Error(X(n,t));if(e&&typeof e==`object`){let n=`code`in e?e.code:void 0,i=`status`in e?e.status:void 0;typeof n==`string`&&Object.defineProperty(r,"code",{configurable:!0,enumerable:!0,value:X(n,t)}),typeof i==`number`&&Number.isFinite(i)&&Object.defineProperty(r,"status",{configurable:!0,enumerable:!0,value:i})}return r}function X(e,t){if(!t)return e;let n=new Set([t,encodeURIComponent(t)]),r=e;for(let e of n)e&&(r=r.split(e).join(`[redacted]`));return r}function Z(e,t){if(e!==void 0)return $(e);let n=t.currentScript,r=n?Q(n):void 0;if(r)return r;try{for(let e of t.querySelectorAll(`script[nonce],style[nonce]`)){let t=Q(e);if(t)return t}}catch{}}function Q(e){let t=`nonce`in e?e.nonce:void 0;return typeof t==`string`?$(t):void 0}function $(e){return e.trim()||void 0}const te=`:host{all:initial;position:fixed;right:18px;bottom:18px;z-index:2147483646;max-width:360px;padding:16px 18px;border:1px solid #efc4bd;border-radius:14px;background:#fff8f6;box-shadow:0 12px 40px rgba(0,0,0,.14);color:#7a271a;font:13px/1.5 Inter,ui-sans-serif,system-ui,sans-serif}strong{display:block;margin-bottom:4px;color:#53150d}span{display:block}button{margin-top:12px;padding:7px 10px;border:1px solid #d9a79f;border-radius:8px;background:#fff;color:#7a271a;font:650 12px/1 Inter,ui-sans-serif,system-ui,sans-serif;cursor:pointer}button:focus-visible{outline:2px solid #7a271a;outline-offset:2px}button:disabled{opacity:.55;cursor:wait}`;export{e as n,t as r,o as t};