@hazem3500/komo 0.9.18 → 0.9.20
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/README.md +3 -1
- package/dist/{accent-picker-KV4WUTUN.js → accent-picker-JTX75MDO.js} +1 -1
- package/dist/anchors.d.ts +2 -0
- package/dist/{chunk-URGMAMH5.js → chunk-ILX63XAJ.js} +1 -1
- package/dist/chunk-J77KQ2WS.js +1 -0
- package/dist/{chunk-ANKCS6NI.js → chunk-PLSWBSSX.js} +1 -1
- package/dist/{design-export-G42ZDP5F.js → design-export-YFMZGYR3.js} +1 -1
- package/dist/design-mode.js +1 -1
- package/dist/dom.d.ts +2 -0
- package/dist/frame-portals.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/node.mjs +1 -1
- package/dist/{onboarding-BYM5KIZI.js → onboarding-DRNGWOJ6.js} +1 -1
- package/dist/react.js +1 -1
- package/dist/setup.js +1 -1
- package/dist/{toolbar-runtime-AQBTB2UG.js → toolbar-runtime-Y4YAL3P7.js} +1 -1
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
- package/server/setup-client.txt +42 -42
- package/src/types.ts +7 -0
- package/dist/chunk-57AHSROT.js +0 -1
package/README.md
CHANGED
|
@@ -435,6 +435,7 @@ Pass these to `initKomo(config)` from `@hazem3500/komo` or `useKomo(config)` fro
|
|
|
435
435
|
| `frame.include(element)` | `(element: HTMLElement) => boolean` | Fixed portals, including fixed descendants of static wrappers | Frame scales dialogs, overlays and toasts with the page. Script-positioned popovers keep their viewport placement while their content scales. Host transforms, animations and focus are preserved without moving portal DOM. Return `true` to map a whole body child through Frame or `false` to exclude its subtree; komo's own host is never framed. |
|
|
436
436
|
| `isolateEvents` | `boolean` | `true` | Keep komo's events out of the host page. See [Host events](#host-events). |
|
|
437
437
|
| `source(element)` | `(element: Element) => string \| undefined` | Anchor metadata | Return a repository-relative source path. |
|
|
438
|
+
| `anchorTarget(element)` | `(element: Element) => Element \| undefined` | Declared owners and stable semantic cards | Optional persistent ancestor for comment capture. Offsets stay relative to this owner when hover-only children disappear. Owners cannot cross a dialog/popover boundary. Design inspection continues to target the exact element. |
|
|
438
439
|
| `sourceUrl(source, branch)` | `(source: string, branch: string) => string` | GitHub viewer | Custom source or editor link. |
|
|
439
440
|
| `page()` | `() => string` | `location.pathname` | Canonical page identifier. |
|
|
440
441
|
| `navigate(url)` | `(url: URL) => void \| Promise<void>` | `location.assign` | Route to a comment on another page without reloading, e.g. `(url) => router.navigate({ href: url.pathname + url.search })`. komo opens the thread once its anchor renders; a rejection falls back to a page load. |
|
|
@@ -482,8 +483,9 @@ komo renders in a shadow root, so page listeners see its events as coming from k
|
|
|
482
483
|
- **Typing.** `keydown`, `keyup` and `keypress` from komo's inputs don't reach `document` or `window`, so app shortcuts (such as `react-hotkeys-hook` or a custom `keydown` listener) don't fire while someone writes a comment. Keys pressed on komo's buttons still reach the page.
|
|
483
484
|
- **Modals.** `pointerdown`, `mousedown`, `touchstart`, `touchmove`, `touchend`, `click`, `wheel`, `focusin` and `focusout` from komo's UI don't reach page listeners. An open Radix or similar dialog doesn't treat komo as an outside interaction, so it doesn't close, take focus back from the composer, or block the sidebar's scroll.
|
|
484
485
|
- **Focus traps.** When focus moves from the page into komo, komo stops that `focusout` for `document` listeners added after komo mounted, such as Radix's FocusScope.
|
|
486
|
+
- **Escape.** Escape from feedback fields and controls is marked handled in the host's own window before document capture listeners run. Feedback still receives it to close its composer or menu; Radix's document handler leaves the host dialog open. This also works when feedback runs inside an iframe.
|
|
485
487
|
|
|
486
|
-
|
|
488
|
+
Other capture-phase listeners still run. Set `isolateEvents: false` if your app needs to observe feedback events or handle Escape itself.
|
|
487
489
|
|
|
488
490
|
### CLI
|
|
489
491
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as e,i as t}from"./chunk-ANKCS6NI.js";import{useEffect as r,useLayoutEffect as n,useRef as o,useState as a}from"react";import{createRoot as c}from"react-dom/client";import l,{useRef as i,useMemo as u,useEffect as s,useState as f,useCallback as d,useLayoutEffect as h}from"react";function p(){return(p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function v(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(o[r]=e[r]);return o}function m(e){var t=i(e),r=i(function(e){t.current&&t.current(e)});return t.current=e,r.current}var g=function(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=1),e>r?r:e<t?t:e},b=function(e){return"touches"in e},_=function(e){return e&&e.ownerDocument.defaultView||self},w=function(e,t,r){var n=e.getBoundingClientRect(),o=b(t)?function(e,t){for(var r=0;r<e.length;r++)if(e[r].identifier===t)return e[r];return e[0]}(t.touches,r):t;return{left:g((o.pageX-(n.left+_(e).pageXOffset))/n.width),top:g((o.pageY-(n.top+_(e).pageYOffset))/n.height)}},x=function(e){!b(e)&&e.preventDefault()},C=l.memo(function(e){var t=e.onMove,r=e.onKey,n=e.onEnd,o=v(e,["onMove","onKey","onEnd"]),a=i(null),c=m(t),f=m(r),d=m(n),h=i(null),g=i(!1),C=u(function(){var e=function(e){x(e),(b(e)?e.touches.length>0:e.buttons>0)&&a.current?c(w(a.current,e,h.current)):(r(!1),d())},t=function(){r(!1),d()};function r(r){var n=g.current,o=_(a.current),c=r?o.addEventListener:o.removeEventListener;c(n?"touchmove":"mousemove",e),c(n?"touchend":"mouseup",t)}return[function(e){var t,n=e.nativeEvent,o=a.current;if(o&&(x(n),t=n,(!g.current||b(t))&&o)){if(b(n)){g.current=!0;var l=n.changedTouches||[];l.length&&(h.current=l[0].identifier)}o.focus(),c(w(o,n,h.current)),r(!0)}},function(e){var t=e.which||e.keyCode;t<37||t>40||(e.preventDefault(),f({left:39===t?.05:37===t?-.05:0,top:40===t?.05:38===t?-.05:0}))},function(e){var t=e.which||e.keyCode;t>=37&&t<=40&&d()},r]},[f,c,d]),E=C[0],y=C[1],k=C[2],N=C[3];return s(function(){return N},[N]),l.createElement("div",p({},o,{onTouchStart:E,onMouseDown:E,className:"react-colorful__interactive",ref:a,onKeyDown:y,onKeyUp:k,tabIndex:0,role:"slider"}))}),E=function(e){return e.filter(Boolean).join(" ")},y=function(e){var t=e.color,r=e.left,n=e.top,o=void 0===n?.5:n,a=E(["react-colorful__pointer",e.className]);return l.createElement("div",{className:a,style:{top:100*o+"%",left:100*r+"%"}},l.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:t}}))},k=function(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=Math.pow(10,t)),Math.round(r*e)/r},N=(Math.PI,function(e){return"#"===e[0]&&(e=e.substring(1)),e.length<6?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:4===e.length?k(parseInt(e[3]+e[3],16)/255,2):1}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16),a:8===e.length?k(parseInt(e.substring(6,8),16)/255,2):1}}),M=function(e){var t=function(e){var t=e.s,r=e.v,n=e.a,o=(200-t)*r/100;return{h:k(e.h),s:k(o>0&&o<200?t*r/100/(o<=100?o:200-o)*100:0),l:k(o/2),a:k(n,2)}}(e);return"hsl("+t.h+", "+t.s+"%, "+t.l+"%)"},L=function(e){var t=e.h,r=e.s,n=e.v,o=e.a;t=t/360*6,r/=100,n/=100;var a=Math.floor(t),c=n*(1-r),l=n*(1-(t-a)*r),i=n*(1-(1-t+a)*r),u=a%6;return{r:k(255*[n,l,c,c,i,n][u]),g:k(255*[i,n,n,l,c,c][u]),b:k(255*[c,c,i,n,n,l][u]),a:k(o,2)}},H=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},I=function(e){var t=e.r,r=e.g,n=e.b,o=e.a,a=o<1?H(k(255*o)):"";return"#"+H(t)+H(r)+H(n)+a},P=function(e){var t=e.r,r=e.g,n=e.b,o=e.a,a=Math.max(t,r,n),c=a-Math.min(t,r,n),l=c?a===t?(r-n)/c:a===r?2+(n-t)/c:4+(t-r)/c:0;return{h:60*(l<0?l+6:l),s:a?c/a*100:0,v:a/255*100,a:o}},j=l.memo(function(e){var t=e.hue,r=e.onChange,n=e.onChangeEnd,o=E(["react-colorful__hue",e.className]);return l.createElement("div",{className:o},l.createElement(C,{onMove:function(e){r({h:360*e.left})},onKey:function(e){r({h:g(t+360*e.left,0,360)})},onEnd:n,"aria-label":"Hue","aria-valuenow":k(t),"aria-valuemax":"360","aria-valuemin":"0"},l.createElement(y,{className:"react-colorful__hue-pointer",left:t/360,color:M({h:t,s:100,v:100,a:1})})))}),z=l.memo(function(e){var t=e.hsva,r=e.onChange,n=e.onChangeEnd,o={backgroundColor:M({h:t.h,s:100,v:100,a:1})};return l.createElement("div",{className:"react-colorful__saturation",style:o},l.createElement(C,{onMove:function(e){r({s:100*e.left,v:100-100*e.top})},onKey:function(e){r({s:g(t.s+100*e.left,0,100),v:g(t.v-100*e.top,0,100)})},onEnd:n,"aria-label":"Color","aria-valuetext":"Saturation "+k(t.s)+"%, Brightness "+k(t.v)+"%"},l.createElement(y,{className:"react-colorful__saturation-pointer",top:1-t.v/100,left:t.s/100,color:M(t)})))}),D=function(e,t){if(e===t)return!0;for(var r in e)if(e[r]!==t[r])return!1;return!0};var B=typeof window<"u"?h:s,K=new WeakMap,O=function(e){B(function(){var t=e.current;if(typeof document<"u"&&t){var r=t.getRootNode?t.getRootNode():t.ownerDocument,n=r&&("head"in r||"host"in r)?r:t.ownerDocument;if(!K.has(n)){var o="head"in n?n.head:n,a=(o.ownerDocument||document).createElement("style");a.innerHTML='.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url(\'data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>\')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}';var c=typeof __webpack_nonce__<"u"?__webpack_nonce__:void 0;c&&a.setAttribute("nonce",c),K.set(n,a),o.appendChild(a)}}},[])},S=function(e){var t=e.className,r=e.colorModel,n=e.color,o=void 0===n?r.defaultColor:n,a=e.onChange,c=e.onChangeEnd,u=v(e,["className","colorModel","color","onChange","onChangeEnd"]),h=i(null);O(h);var g=function(e,t,r,n){var o=m(r),a=m(n),c=f(function(){return e.toHsva(t)}),l=c[0],u=c[1],h=i({color:t,hsva:l}),p=i(!1);s(function(){if(!e.equal(t,h.current.color)){var r=e.toHsva(t);h.current={hsva:r,color:t},u(r),p.current=!1}},[t,e]),s(function(){var t;D(l,h.current.hsva)||e.equal(t=e.fromHsva(l),h.current.color)||(h.current={hsva:l,color:t},o(t),p.current=!0)},[l,e,o]);var v=d(function(e){u(function(t){return Object.assign({},t,e)})},[]),g=d(function(){p.current&&(p.current=!1,a(h.current.color))},[a]);return[l,v,g]}(r,o,a,c),b=g[0],_=g[1],w=g[2],x=E(["react-colorful",t]);return l.createElement("div",p({},u,{ref:h,className:x}),l.createElement(z,{hsva:b,onChange:_,onChangeEnd:w}),l.createElement(j,{hue:b.h,onChange:_,onChangeEnd:w,className:"react-colorful__last-control"}))},A={defaultColor:"000",toHsva:function(e){return P(N(e))},fromHsva:function(e){return function(e){return I(L(e))}({h:e.h,s:e.s,v:e.v,a:1})},equal:function(e,t){return e.toLowerCase()===t.toLowerCase()||D(N(e),N(t))}},R=function(e){return l.createElement(S,p({},e,{colorModel:A}))},T=/^#?([0-9A-F]{3,8})$/i,W=function(e){var t=e.color,r=void 0===t?"":t,n=e.onChange,o=e.onBlur,a=e.escape,c=e.validate,i=e.format,u=e.process,h=v(e,["color","onChange","onBlur","escape","validate","format","process"]),g=f(function(){return a(r)}),b=g[0],_=g[1],w=m(n),x=m(o),C=d(function(e){var t=a(e.target.value);_(t),c(t)&&w(u?u(t):t)},[a,u,c,w]),E=d(function(e){c(e.target.value)||_(a(r)),x(e)},[r,a,c,x]);return s(function(){_(a(r))},[r,a]),l.createElement("input",p({},h,{value:i?i(b):b,spellCheck:"false",onChange:C,onBlur:E}))},q=function(e){return"#"+e},$=function(e){var t=e.prefixed,r=e.alpha,n=v(e,["prefixed","alpha"]),o=d(function(e){return e.replace(/([^0-9A-F]+)/gi,"").substring(0,r?8:6)},[r]),a=d(function(e){return t=e,n=r,o=T.exec(t),3===(a=o?o[1].length:0)||6===a||!!n&&4===a||!!n&&8===a;var t,n,o,a},[r]);return l.createElement(W,p({},n,{escape:o,format:t?q:void 0,process:q,validate:a}))};import*as Y from"react";var F=({size:e=24,color:t="currentColor",...r})=>Y.createElement("svg",{viewBox:"0 0 24 24",width:e,height:e,stroke:t,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...r},Y.createElement("path",{d:"M12 5v14m-7-7h14"}));F.displayName="Plus";import{jsx as X,jsxs as U}from"react/jsx-runtime";var V=[["Lavender","#c8b5f4"],["Blue","#85b5ff"],["Mint","#84d9bb"],["Yellow","#f4d779"],["Peach","#f5af87"],["Pink","#efa5c6"]];function G({initial:t,onChange:c}){let[l,i]=a(t),[u,s]=a(!1),f=o(null),d=o(null),h=!V.some(([,e])=>e===l),p=e=>{if(!/^#[0-9a-f]{6}$/i.test(e))return;let t=e.toLowerCase();i(t),c(t)};return n(()=>{let e=f.current;if(!e)return;if(!u){let t=window.setTimeout(()=>e.hidePopover(),150);return()=>clearTimeout(t)}e.showPopover();let t=()=>{let t=d.current.getBoundingClientRect();e.style.left=`${Math.max(8,Math.min(t.right-e.offsetWidth,innerWidth-e.offsetWidth-8))}px`,e.style.top=`${Math.max(8,t.top-e.offsetHeight-8)}px`};return t(),e.querySelector('[role="slider"]')?.focus({preventScroll:!0}),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[u]),r(()=>{if(!u)return;let t=new AbortController;return e(d.current,"pointerdown",e=>{!e.composedPath().includes(f.current)&&!e.composedPath().includes(d.current)&&s(!1)},{signal:t.signal}),()=>t.abort()},[u]),U("div",{className:"account-accent",children:[X("span",{className:"account-accent-label",children:"Accent color"}),U("div",{className:"accent-swatches",role:"group","aria-label":"Accent color",children:[V.map(([e,t])=>X("button",{type:"button",className:"accent-swatch","aria-label":e,title:e,"aria-pressed":l===t,style:{"--swatch":t},onClick:()=>{p(t),s(!1)}},e)),X("button",{ref:d,type:"button",className:"accent-swatch accent-custom","aria-label":"Custom accent color","aria-haspopup":"dialog","aria-expanded":u,"aria-pressed":h,onClick:()=>s(!u),children:X(F,{"aria-hidden":"true"})})]}),U("div",{ref:f,popover:"manual",role:"dialog","aria-label":"Custom accent color",className:u?"accent-popover t-dropdown is-open":"accent-popover t-dropdown is-closing",onKeyDown:e=>{e.stopPropagation(),"Escape"===e.key&&(e.preventDefault(),s(!1),d.current?.focus())},children:[U("div",{className:"accent-popover-head",children:[X("span",{children:"Color"}),X("span",{children:l})]}),U("div",{className:"accent-picker-body",children:[X(R,{color:l,onChange:p}),X($,{"aria-label":"Hex accent color",className:"accent-hex",color:l,onChange:p,prefixed:!0})]})]})]})}function J(e,r){let n=t("div","account-accent-mount"),o=c(n);return o.render(X(G,{initial:e,onChange:r})),{element:n,destroy:()=>o.unmount()}}export{J as accentPicker};
|
|
1
|
+
import{i as e,j as t}from"./chunk-PLSWBSSX.js";import{useEffect as r,useLayoutEffect as n,useRef as o,useState as a}from"react";import{createRoot as c}from"react-dom/client";import l,{useRef as i,useMemo as u,useEffect as s,useState as f,useCallback as d,useLayoutEffect as h}from"react";function p(){return(p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function v(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(o[r]=e[r]);return o}function m(e){var t=i(e),r=i(function(e){t.current&&t.current(e)});return t.current=e,r.current}var g=function(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=1),e>r?r:e<t?t:e},b=function(e){return"touches"in e},_=function(e){return e&&e.ownerDocument.defaultView||self},w=function(e,t,r){var n=e.getBoundingClientRect(),o=b(t)?function(e,t){for(var r=0;r<e.length;r++)if(e[r].identifier===t)return e[r];return e[0]}(t.touches,r):t;return{left:g((o.pageX-(n.left+_(e).pageXOffset))/n.width),top:g((o.pageY-(n.top+_(e).pageYOffset))/n.height)}},x=function(e){!b(e)&&e.preventDefault()},C=l.memo(function(e){var t=e.onMove,r=e.onKey,n=e.onEnd,o=v(e,["onMove","onKey","onEnd"]),a=i(null),c=m(t),f=m(r),d=m(n),h=i(null),g=i(!1),C=u(function(){var e=function(e){x(e),(b(e)?e.touches.length>0:e.buttons>0)&&a.current?c(w(a.current,e,h.current)):(r(!1),d())},t=function(){r(!1),d()};function r(r){var n=g.current,o=_(a.current),c=r?o.addEventListener:o.removeEventListener;c(n?"touchmove":"mousemove",e),c(n?"touchend":"mouseup",t)}return[function(e){var t,n=e.nativeEvent,o=a.current;if(o&&(x(n),t=n,(!g.current||b(t))&&o)){if(b(n)){g.current=!0;var l=n.changedTouches||[];l.length&&(h.current=l[0].identifier)}o.focus(),c(w(o,n,h.current)),r(!0)}},function(e){var t=e.which||e.keyCode;t<37||t>40||(e.preventDefault(),f({left:39===t?.05:37===t?-.05:0,top:40===t?.05:38===t?-.05:0}))},function(e){var t=e.which||e.keyCode;t>=37&&t<=40&&d()},r]},[f,c,d]),E=C[0],y=C[1],k=C[2],N=C[3];return s(function(){return N},[N]),l.createElement("div",p({},o,{onTouchStart:E,onMouseDown:E,className:"react-colorful__interactive",ref:a,onKeyDown:y,onKeyUp:k,tabIndex:0,role:"slider"}))}),E=function(e){return e.filter(Boolean).join(" ")},y=function(e){var t=e.color,r=e.left,n=e.top,o=void 0===n?.5:n,a=E(["react-colorful__pointer",e.className]);return l.createElement("div",{className:a,style:{top:100*o+"%",left:100*r+"%"}},l.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:t}}))},k=function(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=Math.pow(10,t)),Math.round(r*e)/r},N=(Math.PI,function(e){return"#"===e[0]&&(e=e.substring(1)),e.length<6?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:4===e.length?k(parseInt(e[3]+e[3],16)/255,2):1}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16),a:8===e.length?k(parseInt(e.substring(6,8),16)/255,2):1}}),M=function(e){var t=function(e){var t=e.s,r=e.v,n=e.a,o=(200-t)*r/100;return{h:k(e.h),s:k(o>0&&o<200?t*r/100/(o<=100?o:200-o)*100:0),l:k(o/2),a:k(n,2)}}(e);return"hsl("+t.h+", "+t.s+"%, "+t.l+"%)"},L=function(e){var t=e.h,r=e.s,n=e.v,o=e.a;t=t/360*6,r/=100,n/=100;var a=Math.floor(t),c=n*(1-r),l=n*(1-(t-a)*r),i=n*(1-(1-t+a)*r),u=a%6;return{r:k(255*[n,l,c,c,i,n][u]),g:k(255*[i,n,n,l,c,c][u]),b:k(255*[c,c,i,n,n,l][u]),a:k(o,2)}},P=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},j=function(e){var t=e.r,r=e.g,n=e.b,o=e.a,a=o<1?P(k(255*o)):"";return"#"+P(t)+P(r)+P(n)+a},H=function(e){var t=e.r,r=e.g,n=e.b,o=e.a,a=Math.max(t,r,n),c=a-Math.min(t,r,n),l=c?a===t?(r-n)/c:a===r?2+(n-t)/c:4+(t-r)/c:0;return{h:60*(l<0?l+6:l),s:a?c/a*100:0,v:a/255*100,a:o}},z=l.memo(function(e){var t=e.hue,r=e.onChange,n=e.onChangeEnd,o=E(["react-colorful__hue",e.className]);return l.createElement("div",{className:o},l.createElement(C,{onMove:function(e){r({h:360*e.left})},onKey:function(e){r({h:g(t+360*e.left,0,360)})},onEnd:n,"aria-label":"Hue","aria-valuenow":k(t),"aria-valuemax":"360","aria-valuemin":"0"},l.createElement(y,{className:"react-colorful__hue-pointer",left:t/360,color:M({h:t,s:100,v:100,a:1})})))}),B=l.memo(function(e){var t=e.hsva,r=e.onChange,n=e.onChangeEnd,o={backgroundColor:M({h:t.h,s:100,v:100,a:1})};return l.createElement("div",{className:"react-colorful__saturation",style:o},l.createElement(C,{onMove:function(e){r({s:100*e.left,v:100-100*e.top})},onKey:function(e){r({s:g(t.s+100*e.left,0,100),v:g(t.v-100*e.top,0,100)})},onEnd:n,"aria-label":"Color","aria-valuetext":"Saturation "+k(t.s)+"%, Brightness "+k(t.v)+"%"},l.createElement(y,{className:"react-colorful__saturation-pointer",top:1-t.v/100,left:t.s/100,color:M(t)})))}),D=function(e,t){if(e===t)return!0;for(var r in e)if(e[r]!==t[r])return!1;return!0};var I=typeof window<"u"?h:s,S=new WeakMap,O=function(e){I(function(){var t=e.current;if(typeof document<"u"&&t){var r=t.getRootNode?t.getRootNode():t.ownerDocument,n=r&&("head"in r||"host"in r)?r:t.ownerDocument;if(!S.has(n)){var o="head"in n?n.head:n,a=(o.ownerDocument||document).createElement("style");a.innerHTML='.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url(\'data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>\')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}';var c=typeof __webpack_nonce__<"u"?__webpack_nonce__:void 0;c&&a.setAttribute("nonce",c),S.set(n,a),o.appendChild(a)}}},[])},K=function(e){var t=e.className,r=e.colorModel,n=e.color,o=void 0===n?r.defaultColor:n,a=e.onChange,c=e.onChangeEnd,u=v(e,["className","colorModel","color","onChange","onChangeEnd"]),h=i(null);O(h);var g=function(e,t,r,n){var o=m(r),a=m(n),c=f(function(){return e.toHsva(t)}),l=c[0],u=c[1],h=i({color:t,hsva:l}),p=i(!1);s(function(){if(!e.equal(t,h.current.color)){var r=e.toHsva(t);h.current={hsva:r,color:t},u(r),p.current=!1}},[t,e]),s(function(){var t;D(l,h.current.hsva)||e.equal(t=e.fromHsva(l),h.current.color)||(h.current={hsva:l,color:t},o(t),p.current=!0)},[l,e,o]);var v=d(function(e){u(function(t){return Object.assign({},t,e)})},[]),g=d(function(){p.current&&(p.current=!1,a(h.current.color))},[a]);return[l,v,g]}(r,o,a,c),b=g[0],_=g[1],w=g[2],x=E(["react-colorful",t]);return l.createElement("div",p({},u,{ref:h,className:x}),l.createElement(B,{hsva:b,onChange:_,onChangeEnd:w}),l.createElement(z,{hue:b.h,onChange:_,onChangeEnd:w,className:"react-colorful__last-control"}))},R={defaultColor:"000",toHsva:function(e){return H(N(e))},fromHsva:function(e){return function(e){return j(L(e))}({h:e.h,s:e.s,v:e.v,a:1})},equal:function(e,t){return e.toLowerCase()===t.toLowerCase()||D(N(e),N(t))}},A=function(e){return l.createElement(K,p({},e,{colorModel:R}))},W=/^#?([0-9A-F]{3,8})$/i,T=function(e){var t=e.color,r=void 0===t?"":t,n=e.onChange,o=e.onBlur,a=e.escape,c=e.validate,i=e.format,u=e.process,h=v(e,["color","onChange","onBlur","escape","validate","format","process"]),g=f(function(){return a(r)}),b=g[0],_=g[1],w=m(n),x=m(o),C=d(function(e){var t=a(e.target.value);_(t),c(t)&&w(u?u(t):t)},[a,u,c,w]),E=d(function(e){c(e.target.value)||_(a(r)),x(e)},[r,a,c,x]);return s(function(){_(a(r))},[r,a]),l.createElement("input",p({},h,{value:i?i(b):b,spellCheck:"false",onChange:C,onBlur:E}))},q=function(e){return"#"+e},$=function(e){var t=e.prefixed,r=e.alpha,n=v(e,["prefixed","alpha"]),o=d(function(e){return e.replace(/([^0-9A-F]+)/gi,"").substring(0,r?8:6)},[r]),a=d(function(e){return t=e,n=r,o=W.exec(t),3===(a=o?o[1].length:0)||6===a||!!n&&4===a||!!n&&8===a;var t,n,o,a},[r]);return l.createElement(T,p({},n,{escape:o,format:t?q:void 0,process:q,validate:a}))};import*as X from"react";var Y=({size:e=24,color:t="currentColor",...r})=>X.createElement("svg",{viewBox:"0 0 24 24",width:e,height:e,stroke:t,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...r},X.createElement("path",{d:"M12 5v14m-7-7h14"}));Y.displayName="Plus";import{jsx as F,jsxs as U}from"react/jsx-runtime";var V=[["Lavender","#c8b5f4"],["Blue","#85b5ff"],["Mint","#84d9bb"],["Yellow","#f4d779"],["Peach","#f5af87"],["Pink","#efa5c6"]];function G({initial:t,onChange:c}){let[l,i]=a(t),[u,s]=a(!1),f=o(null),d=o(null),h=!V.some(([,e])=>e===l),p=e=>{if(!/^#[0-9a-f]{6}$/i.test(e))return;let t=e.toLowerCase();i(t),c(t)};return n(()=>{let e=f.current;if(!e)return;if(!u){let t=window.setTimeout(()=>e.hidePopover(),150);return()=>clearTimeout(t)}e.showPopover();let t=()=>{let t=d.current.getBoundingClientRect();e.style.left=`${Math.max(8,Math.min(t.right-e.offsetWidth,innerWidth-e.offsetWidth-8))}px`,e.style.top=`${Math.max(8,t.top-e.offsetHeight-8)}px`};return t(),e.querySelector('[role="slider"]')?.focus({preventScroll:!0}),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[u]),r(()=>{if(!u)return;let t=new AbortController;return e(d.current,"pointerdown",e=>{!e.composedPath().includes(f.current)&&!e.composedPath().includes(d.current)&&s(!1)},{signal:t.signal}),()=>t.abort()},[u]),U("div",{className:"account-accent",children:[F("span",{className:"account-accent-label",children:"Accent color"}),U("div",{className:"accent-swatches",role:"group","aria-label":"Accent color",children:[V.map(([e,t])=>F("button",{type:"button",className:"accent-swatch","aria-label":e,title:e,"aria-pressed":l===t,style:{"--swatch":t},onClick:()=>{p(t),s(!1)}},e)),F("button",{ref:d,type:"button",className:"accent-swatch accent-custom","aria-label":"Custom accent color","aria-haspopup":"dialog","aria-expanded":u,"aria-pressed":h,onClick:()=>s(!u),children:F(Y,{"aria-hidden":"true"})})]}),U("div",{ref:f,popover:"manual",role:"dialog","aria-label":"Custom accent color",className:u?"accent-popover t-dropdown is-open":"accent-popover t-dropdown is-closing",onKeyDown:e=>{e.stopPropagation(),"Escape"===e.key&&(e.preventDefault(),s(!1),d.current?.focus())},children:[U("div",{className:"accent-popover-head",children:[F("span",{children:"Color"}),F("span",{children:l})]}),U("div",{className:"accent-picker-body",children:[F(A,{color:l,onChange:p}),F($,{"aria-label":"Hex accent color",className:"accent-hex",color:l,onChange:p,prefixed:!0})]})]})]})}function J(e,r){let n=t("div","account-accent-mount"),o=c(n);return o.render(F(G,{initial:e,onChange:r})),{element:n,destroy:()=>o.unmount()}}export{J as accentPicker};
|
package/dist/anchors.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Anchor } from "./types.js";
|
|
2
|
+
/** Prefer a persistent comment owner without changing precise DOM anchor capture. */
|
|
3
|
+
export declare function commentAnchorTarget(element: Element, root: Element, resolve?: (element: Element) => Element | undefined): Element;
|
|
2
4
|
export declare function captureAnchor(element: Element, start: {
|
|
3
5
|
x: number;
|
|
4
6
|
y: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{j as e,k as t,l as r}from"./chunk-PLSWBSSX.js";function o(o,s){let i=e("details","comment-menu"),n=e("summary","icon");n.setAttribute("aria-label",o),n.setAttribute("aria-haspopup","menu"),n.setAttribute("aria-expanded","false"),n.title=o,n.append(t("more"));let a=e("div","comment-menu-items");a.popover="manual",a.setAttribute("role","menu"),a.setAttribute("aria-label",o);let c=s.map(t=>{let o=r(t.label,()=>{i.open=!1,n.focus({preventScroll:!0}),t.onSelect()},"menu-action"+(t.destructive?" destructive":""),t.icon);return o.append(e("span","",t.label)),o.setAttribute("role","menuitem"),o.tabIndex=-1,a.append(o),o});return i.addEventListener("toggle",()=>{if(n.setAttribute("aria-expanded",String(i.open)),i.open){a.showPopover();let e=n.getBoundingClientRect();a.style.left=`${Math.max(8,Math.min(e.right-a.offsetWidth,innerWidth-a.offsetWidth-8))}px`,a.style.top=`${Math.max(8,Math.min(e.bottom+6,innerHeight-a.offsetHeight-8))}px`,(c.find(e=>"true"===e.getAttribute("aria-checked"))??c[0])?.focus({preventScroll:!0})}else a.hidePopover()}),i.addEventListener("keydown",e=>{if(!i.open)return;let t,r=c.indexOf(e.target);"ArrowDown"===e.key&&(t=(r+1)%c.length),"ArrowUp"===e.key&&(t=(r-1+c.length)%c.length),"Home"===e.key&&(t=0),"End"===e.key&&(t=c.length-1),void 0!==t&&(e.preventDefault(),c[t]?.focus()),"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),i.open=!1,n.focus({preventScroll:!0})),"Tab"===e.key&&(i.open=!1)}),i.append(n,a),i}function s(r,s,i,n){let a=o(r,s.map(([e,t])=>({label:t,icon:"check",onSelect:()=>n(e)})));a.classList.add("selection-menu");let c=a.querySelector("summary");return c.className="selection-trigger",c.replaceChildren(e("span","selection-label",s.find(([e])=>e===i)?.[1]),t("chevron")),a.querySelectorAll("[role=menuitem]").forEach((e,t)=>{e.setAttribute("role","menuitemradio"),e.setAttribute("aria-checked",String(s[t][0]===i))}),a}var i=class extends Error{constructor(e,t,r){super(t),this.status=e,this.code=r}status;code};function n(e){return!!e&&"string"==typeof e.id&&"string"==typeof e.name&&"boolean"==typeof e.verified&&[e.avatarUrl,e.accentColor].every(e=>void 0===e||"string"==typeof e)}function a(e){return Array.isArray(e)&&e.every(e=>e&&"string"==typeof e.id&&"string"==typeof e.page&&"boolean"==typeof e.resolved&&Number.isFinite(e.createdAt)&&Number.isFinite(e.updatedAt)&&(null===e.resolvedBy||n(e.resolvedBy))&&e.anchor&&(!("context"in e.anchor)||function(e){if(void 0===e)return!0;if(!e||"object"!=typeof e||Array.isArray(e))return!1;let t={tag:32,role:80,label:160,nearby:160,classes:200,selectedText:200,styles:500,scope:2e3};return Object.entries(e).every(([e,r])=>"number"==typeof t[e]&&"string"==typeof r&&r.length<=t[e])}(e.anchor.context))&&"string"==typeof e.anchor.selector&&"string"==typeof e.anchor.text&&[e.anchor.x,e.anchor.y,e.anchor.width,e.anchor.height,e.anchor.pageX,e.anchor.pageY,e.anchor.viewportWidth].every(Number.isFinite)&&Array.isArray(e.comments)&&e.comments.every(e=>e&&"string"==typeof e.id&&"string"==typeof e.body&&n(e.author)&&Number.isFinite(e.createdAt)&&(null===e.editedAt||Number.isFinite(e.editedAt))&&e.reactions&&"object"==typeof e.reactions&&!Array.isArray(e.reactions)&&Object.values(e.reactions).every(e=>Array.isArray(e)&&e.every(e=>"string"==typeof e))))}function c(e,t){if(!t||!Array.isArray(e))return e;let r=e=>"string"==typeof e?Object.hasOwn(t,e)?t[e]:void 0:e;return e.map(e=>e&&{...e,resolvedBy:r(e.resolvedBy),comments:Array.isArray(e.comments)&&e.comments.map(e=>e&&{...e,author:r(e.author)})})}function h(){return new i(0,"Could not read comments. Try again.","invalid_response")}var l=class{constructor(e){this.options=e;let t=new URL(e.sessionEndpoint??e.endpoint).href.replace(/\/$/,""),r=e.sessionDomain?.replace(/^\./,"")??"";this.cookieDomain=r&&(location.hostname===r||location.hostname.endsWith(`.${r}`))?r:"",this.cookieName=`${this.cookieDomain?"__Secure-":"__Host-"}bc-session-${encodeURIComponent(JSON.stringify([t,e.project]))}`,this.key=`branch-comments:${e.endpoint}:${e.project}`;let o=!1;try{let e=document.cookie.split("; ").find(e=>e.startsWith(`${this.cookieName}=`));o=void 0!==e,this.token=e?.slice(this.cookieName.length+1)||null}catch{}try{let e;try{e=JSON.parse(localStorage.getItem(this.userKey)??"null")}catch{}let t=localStorage.getItem(this.key)??(n(e?.user)&&"string"==typeof e.token?e.token:null);o?!this.token&&t&&this.clear():this.token=t,this.token&&e?.token===this.token&&n(e.user)&&(this.user=e.user)}catch{}try{let t=`bc-session-${encodeURIComponent(e.project)}`,r=location.hostname.match(/^[^.]+\.([^.]+\.(?:workers|pages)\.dev)$/)?.[1];for(let e of new Set(["",this.cookieDomain,r]))void 0!==e&&(document.cookie=`${t}=; Max-Age=0; Path=/${e?`; Domain=${e}`:""}`)}catch{}}options;token=null;user=null;transient=!1;revision;cachedThreads=[];reads=new AbortController;persistenceQueued=!1;persistenceBlocked=!1;key;cookieName;cookieDomain;get sessionKey(){return this.key}get userKey(){return`${this.key}:user`}rememberUser(){try{this.token&&this.user?localStorage.setItem(this.userKey,JSON.stringify({token:this.token,user:this.user})):localStorage.removeItem(this.userKey)}catch{}}cancelReads(){this.reads.abort(),this.reads=new AbortController}async request(e,t="GET",r){let o=new URL(e,this.options.endpoint.replace(/\/?$/,"/"));o.searchParams.set("project",this.options.project),o.searchParams.set("repo",this.options.repo),o.searchParams.set("branch",this.options.branch);let s={},n=this.token;n&&(s.Authorization=`Bearer ${n}`),void 0!==r&&(s["Content-Type"]="application/json");let a="GET"===t?this.reads.signal:void 0,c=AbortSignal.timeout(15e3),l=await fetch(o,{method:t,headers:s,body:void 0===r?void 0:JSON.stringify(r),credentials:"omit",cache:"no-store",signal:a?AbortSignal.any([a,c]):c}).catch(e=>{throw e instanceof TypeError?!1===navigator.onLine?new i(0,"You’re offline.","offline"):new i(0,"Can’t connect to comments.","unreachable"):e});a?.throwIfAborted();let u=await l.json().catch(()=>{if(a?.throwIfAborted(),l.ok)throw h();return{}});if(a?.throwIfAborted(),l.ok&&(!u||"object"!=typeof u||Array.isArray(u)))throw h();if(!l.ok)throw 401===l.status&&n&&this.token===n&&this.clear(),new i(l.status,"site_not_approved"===u?.code?"Comments aren’t turned on for this site yet.":u?.error??"Could not load comments.",u?.code);return u}get listKey(){return`${this.key}:${JSON.stringify([this.options.repo,this.options.branch])}:threads`}cached(){try{let e=JSON.parse(localStorage.getItem(this.listKey)??"null");return e&&(e.threads=c(e.threads,e.authors)),e?.token!==(this.token??"")||!a(e.threads)||void 0!==e.revision&&(!Number.isSafeInteger(e.revision)||e.revision<0)?null:(this.revision=e.revision,this.cachedThreads=e.threads,e.threads)}catch{return null}}persist(){this.persistenceQueued||this.persistenceBlocked||(this.persistenceQueued=!0,queueMicrotask(()=>{this.persistenceQueued=!1;try{let e=Object.create(null),t=[],r=0,o=!1,s=this.options.page?.()??location.pathname,i=[...this.cachedThreads].sort((e,t)=>+(t.page===s)-+(e.page===s));for(let s of i){let i=Object.create(null),n=t=>(t&&(i[t.id]={...e[t.id],...i[t.id],...t}),t?.id??null),a={...s,resolvedBy:n(s.resolvedBy),comments:s.comments.map(e=>({...e,author:n(e.author)}))},c=JSON.stringify(a).length+Object.entries(i).reduce((t,[r,o])=>t+JSON.stringify([r,o]).length-(e[r]?JSON.stringify([r,e[r]]).length:0),0)+2;r+c>25e4?o=!0:(r+=c,Object.assign(e,i),t.push(a))}if(o&&!t.length)return void localStorage.removeItem(this.listKey);localStorage.setItem(this.listKey,JSON.stringify({token:this.token??"",revision:o?void 0:this.revision,threads:t,authors:e}))}catch{this.persistenceBlocked=!0;try{localStorage.removeItem(this.listKey)}catch{}}}))}async list(){let e,t,r=this.token,o=this.reads.signal,s=[],n=0;for(;null!==n;){let l=await this.request(`threads?authors=1&offset=${n}${e?`&cursor=${encodeURIComponent(e)}`:""}${0===n&&void 0!==this.revision?`&revision=${this.revision}`:""}`).catch(e=>{throw e instanceof i&&403===e.status&&this.token===r&&(this.revision=void 0,this.cachedThreads=[],this.persist()),e});if(o.throwIfAborted(),l.threads=c(l.threads,l.authors),!0===l.notModified&&0===n&&void 0!==this.revision)return this.cachedThreads;if(!a(l.threads)||null!=l.nextCursor&&("string"!=typeof l.nextCursor||l.nextCursor.length>200||l.nextCursor===e)||void 0!==l.revision&&(!Number.isSafeInteger(l.revision)||l.revision<0)||null!=l.next&&(!Number.isSafeInteger(l.next)||l.next<=n))throw h();0===n&&(t=l.revision),s.push(...l.threads??[]),e=l.nextCursor??void 0,n=l.next??null}return this.revision=t,this.cachedThreads=s,this.persist(),s}save(e){e.token!==this.token&&(this.cancelReads(),this.revision=void 0,this.cachedThreads=[]),this.token=e.token,this.user=e.user,this.rememberUser();let t=!1;try{localStorage.setItem(this.key,e.token),t=!0}catch{}this.transient=!this.writeCookie(e.token,3456e4)&&!t}writeCookie(e,t){if("https:"!==location.protocol)return;let r="Path=/; SameSite=Lax; Secure";try{return this.cookieDomain&&(document.cookie=`${this.cookieName}=; Max-Age=0; ${r}`),document.cookie=`${this.cookieName}=${e}; Max-Age=${t}; ${r}${this.cookieDomain?`; Domain=${this.cookieDomain}`:""}`,document.cookie.split("; ").includes(`${this.cookieName}=${e}`)}catch{}}clear(){this.cancelReads();try{localStorage.removeItem(this.listKey);for(let e of Object.keys(localStorage))e.startsWith(`${this.key}:`)&&localStorage.removeItem(e)}catch{}this.revision=void 0,this.cachedThreads=[],this.token=null,this.user=null,this.transient=!1,this.rememberUser(),this.writeCookie("",3456e4);try{localStorage.removeItem(this.key)}catch{}}async restore(){if(!this.token)return;let e=this.token,t=await this.request("me");if(this.token===e){if(!n(t.user))throw h();this.save({token:e,user:t.user})}}async guest(e){this.save(await this.request("auth/guest","POST",{name:e}))}async logout(){let e=this.request("me","DELETE");this.clear(),await e}};export{o as a,s as b,i as c,l as d};
|