mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
Two conflicts, both version pins. go.mod takes the branch's hanzo.ai/tygoja v0.0.3 — plugins/jsvm imports the vanity path, and the old github.com/hanzoai/tygoja line no longer resolved it — over main's newer github.com/hanzos3/go v1.0.2. ui-react/package.json takes the branch's exact pins at main's newer numbers, and the pnpm override moves with the dependency it overrides rather than holding @hanzo/ui two releases back. The branch tip did not compile on its own: it removed tools/auth but left core/collection_model_auth_options_test.go importing it to exercise the InitProvider it also removed. That test goes with the code it tested. @tanstack/react-router pins 1.170.33 because router-plugin 1.168.36 peers on ^1.170.33; exact pins do not float up to meet a peer the way the ranges they replace did. go vet ./... clean, ui-react builds and typechecks, dist rebuilt. Co-authored-by: Hanzo Dev <[email protected]>
1 line
8.9 KiB
JavaScript
1 line
8.9 KiB
JavaScript
var e={nav:`navigation`,main:`main`,header:`banner`,footer:`contentinfo`,aside:`complementary`,form:`form`,button:`button`,select:`combobox`,textarea:`textbox`,img:`img`,ul:`list`,ol:`list`,li:`listitem`,table:`table`,dialog:`dialog`,article:`article`,section:`region`,summary:`button`},t={checkbox:`checkbox`,radio:`radio`,range:`slider`,number:`spinbutton`,submit:`button`,button:`button`,reset:`button`,search:`searchbox`};function n(e,t){let n=e.getAttribute(t);return n==null||n===``?void 0:n}function r(e){return e.tagName.toLowerCase()}function i(i){let a=n(i,`role`);if(a)return a;let o=r(i);return o===`a`?n(i,`href`)==null?`generic`:`link`:o===`input`?t[(n(i,`type`)||`text`).toLowerCase()]??`textbox`:/^h[1-6]$/.test(o)?`heading`:e[o]??`generic`}function a(e){if(!e)return;let t=e.replace(/\s+/g,` `).trim();if(t)return t.length>80?t.slice(0,80)+`…`:t}function o(e){let t=n(e,`aria-label`);if(t)return a(t);let o=n(e,`aria-labelledby`);if(o&&typeof document<`u`){let e=a(o.split(/\s+/).map(e=>document.getElementById(e)?.textContent||``).join(` `));if(e)return e}let c=r(e);if(c===`img`)return a(n(e,`alt`));if(c===`input`||c===`textarea`||c===`select`){if(e.id&&typeof document<`u`){let t=a(document.querySelector(`label[for="${s(e.id)}"]`)?.textContent);if(t)return t}return a(n(e,`placeholder`)||n(e,`name`)||n(e,`title`))}let l=n(e,`title`);if(l)return a(l);let u=i(e);if(u===`button`||u===`link`||u===`heading`||u===`listitem`)return a(e.textContent)}function s(e){let t=typeof globalThis<`u`?globalThis:void 0;return t?.CSS?.escape?t.CSS.escape(e):e.replace(/["\\\]]/g,`\\$&`)}function c(e){let t=n(e,`data-hz-name`)||n(e,`data-component`);if(t)return a(t);let r=n(e,`data-observe`);if(r&&r!==`off`)return a(r);let i=n(e,`data-slot`);return i?a(i):l(e)}function l(e){try{let t=e,n=Object.keys(t).find(e=>e.startsWith(`__reactFiber$`)||e.startsWith(`__reactInternalInstance$`));if(!n)return;let r=t[n]?._debugOwner,i=0;for(;r&&i<20;){let e=r.type,t=e?.displayName||e?.name;if(t&&/^[A-Z]/.test(t))return t;r=r._debugOwner,i++}}catch{}}function u(e){let t=r(e),a=i(e),s={tag:t,role:a},l=n(e,`data-testid`)||n(e,`data-test-id`)||n(e,`data-test`);l&&(s.testid=l),e.id&&(s.id=e.id);let u=o(e);u&&(s.name=u);let f=d(e,t,a);f&&(s.kind=f);let p=c(e);return p&&(s.component=p),s}function d(e,t,r){if(t===`input`)return(n(e,`type`)||`text`).toLowerCase();if(t===`button`)return n(e,`type`)||void 0;if(t===`a`){let t=n(e,`href`);if(!t)return;try{return new URL(t,typeof location<`u`?location.href:`https://x`).pathname}catch{return t}}if(r===`heading`)return e.tagName.toLowerCase()}function f(e){return!!(e.component||e.testid||e.role&&e.role!==`generic`||e.name)}function p(e){let t=e.component??(e.role&&e.role!==`generic`?e.role:e.tag);return e.testid?`${t}[${e.testid}]`:e.name?`${t}[${e.name}]`:t}function m(e){let t=e.filter(f);return(t.length?t:e.length?[e[e.length-1]]:[]).map(p).join(`/`)}function h(e,t={}){let n=t.maxDepth??12,r=[],i=e,a=0,o=typeof document<`u`?document.documentElement:null;for(;i&&i.nodeType===1&&i!==o&&a<n;)r.unshift(u(i)),i=i.parentElement,a++;let s=r.length?r[r.length-1]:u(e);return{"@context":`https://schema.hanzo.ai/observe`,"@type":`Interaction`,path:r,target:s,label:m(r.length?r:[s])}}var g=64,_=new Set([`password`,`hidden`,`email`,`tel`]),v=/pass|pwd|secret|token|otp|cvv|cvc|csc|cc-|card|ccnum|credit|ssn|social|routing|account|pin|auth|api[-_ ]?key|security|dob|birth/i,y=`data-hz-private`;function b(e,t){return e.getAttribute(t)}function x(e,t={}){let n=t.privateAttribute??y,r=e;for(;r&&r.nodeType===1;){if(r.hasAttribute(n)||r.getAttribute(`data-observe`)===`off`||r.hasAttribute(`data-private`))return!0;r=r.parentElement}return!1}function S(e){return[b(e,`name`),e.id||null,b(e,`autocomplete`),b(e,`placeholder`),b(e,`aria-label`)].filter(Boolean).join(` `)}function C(e,t={}){return!!(v.test(e)||t.sensitive&&t.sensitive.test(e))}function w(e,t,n){return _.has(t)?!0:C(S(e),n)}function T(e){return e.length>g?e.slice(0,g)+`…`:e}function E(e,t={}){let n=e.tagName.toLowerCase();if(n!==`input`&&n!==`textarea`&&n!==`select`)return;if(n===`select`){let t=e,n=t.options[t.selectedIndex];return{redacted:!1,kind:`select`,value:n?T((n.text||``).trim()):void 0}}let r=(n===`textarea`?`textarea`:b(e,`type`)||`text`).toLowerCase();if(r===`checkbox`||r===`radio`)return{redacted:!1,kind:r,checked:e.checked};let i=e.value??``,a=w(e,r,t),o=t.maskInput!==!1;return a?{redacted:!0,kind:r}:o?{redacted:!0,kind:r,length:i.length}:{redacted:!1,kind:r,value:T(i)}}var D=class{constructor(e=500){this.capacity=e,this.subs=new Set,this.ring=[]}emit(e){this.ring.push(e),this.ring.length>this.capacity&&this.ring.splice(0,this.ring.length-this.capacity);for(let t of this.subs)try{t(e)}catch{}}subscribe(e){return this.subs.add(e),()=>{this.subs.delete(e)}}buffer(){return this.ring.slice()}clear(){this.ring=[]}},O=()=>typeof window<`u`&&typeof document<`u`,k=Symbol.for(`hanzo.observe.roots`);function A(){let e=globalThis,t=e[k];if(t)return t;let n=new Set;return e[k]=n,n}var j={click:`$click`,input:`$input`,change:`$change`,submit:`$submit`,nav:`$pageview`,view:`$view`},M=`hz:navigate`,N=0,P=null;function F(){if(!O()||(N++,P))return;let e=history.pushState,t=history.replaceState;P={push:e,replace:t};let n=()=>{try{window.dispatchEvent(new Event(M))}catch{}};history.pushState=function(...t){let r=e.apply(this,t);return n(),r},history.replaceState=function(...e){let r=t.apply(this,e);return n(),r}}function I(){N>0&&N--,N===0&&P&&(history.pushState=P.push,history.replaceState=P.replace,P=null)}function L(e){return e&&e.nodeType===1?e:e&&e.nodeType===3?e.parentElement:null}var R=12;function z(e){for(let t=e,n=0;t&&n<R;t=t.parentElement,n++){let e=getComputedStyle(t).position;if(e===`fixed`||e===`sticky`)return!0}return!1}function B(e,t){let n=e;if(typeof n.clientX==`number`&&typeof n.clientY==`number`)try{let e=z(t);return{$x:Math.round(n.clientX+(e?0:window.scrollX)),$y:Math.round(n.clientY+(e?0:window.scrollY)),$target_fixed:e,$viewport_width:window.innerWidth,$viewport_height:window.innerHeight}}catch{return}}var V=class{constructor(e){this.started=!1,this.pending=new Map,this.seen=new WeakSet,this.onClick=e=>{let t=L(e.target);this.fire(`click`,t,B(e,t))},this.onInput=e=>{let t=L(e.target);if(!t)return;let n=this.pending.get(t);n!==void 0&&clearTimeout(n),this.pending.set(t,setTimeout(()=>{this.pending.delete(t),this.fire(`input`,t)},this.cfg.inputDebounceMs))},this.onChange=e=>{let t=L(e.target);if(t){let e=this.pending.get(t);e!==void 0&&(clearTimeout(e),this.pending.delete(t))}this.fire(`change`,t)},this.onSubmit=e=>this.fire(`submit`,L(e.target)),this.onNav=()=>{O()&&this.fire(`nav`,document.body,{path:location.pathname+location.search})},this.cfg={enabled:!0,nav:!0,viewSelector:`[data-hz-view]`,inputDebounceMs:400,maxDepth:12,...e},this.root=e.root??(O()?document:{}),this.stream=new D(e.bufferSize??500)}get capturing(){return this.started}start(){if(this.started||!this.cfg.enabled||!O())return;let e=A();if(e.has(this.root))return;e.add(this.root),this.started=!0;let t=this.root;t.addEventListener(`click`,this.onClick,{capture:!0,passive:!0}),t.addEventListener(`input`,this.onInput,{capture:!0,passive:!0}),t.addEventListener(`change`,this.onChange,{capture:!0,passive:!0}),t.addEventListener(`submit`,this.onSubmit,{capture:!0,passive:!0}),this.cfg.nav&&(F(),window.addEventListener(`popstate`,this.onNav),window.addEventListener(M,this.onNav)),this.installView()}stop(){if(!this.started)return;this.started=!1,A().delete(this.root);let e=this.root;e.removeEventListener(`click`,this.onClick,{capture:!0}),e.removeEventListener(`input`,this.onInput,{capture:!0}),e.removeEventListener(`change`,this.onChange,{capture:!0}),e.removeEventListener(`submit`,this.onSubmit,{capture:!0}),this.cfg.nav&&(window.removeEventListener(`popstate`,this.onNav),window.removeEventListener(M,this.onNav),I());for(let e of this.pending.values())clearTimeout(e);this.pending.clear(),this.io?.disconnect(),this.io=void 0}watch(e){try{this.io?.observe(e)}catch{}}installView(){if(!(typeof IntersectionObserver>`u`))try{this.io=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=t.target;this.seen.has(e)||(this.seen.add(e),this.fire(`view`,e,{ratio:Math.round(t.intersectionRatio*100)/100}))}},{threshold:.5});let e=this.cfg.viewSelector;e&&this.root.querySelectorAll?.(e).forEach(e=>this.io.observe(e))}catch{}}fire(e,t,n){if(this.cfg.enabled)try{if(!t||x(t,this.cfg.redaction))return;let r=h(t,{maxDepth:this.cfg.maxDepth}),i=e===`input`||e===`change`?E(t,this.cfg.redaction):void 0,a={kind:e,name:j[e],at:Date.now(),semantic:r,value:i,props:n};this.stream.emit(a),this.cfg.sink(a)}catch{}}};function H(e){let t=e.semantic.target,n={$el:e.semantic.label,$role:t.role};return t.testid&&(n.$testid=t.testid),t.name&&(n.$name=t.name),t.component&&(n.$component=t.component),t.kind&&(n.$kind=t.kind),n.$path=e.semantic.path.map(e=>e.component||(e.testid?`${e.role}[${e.testid}]`:e.role)),e.value&&(n.$value=e.value),e.props&&Object.assign(n,e.props),n}function U(e,t){let n=new V({sink:e,...t});return n.start(),n}export{U as observe,H as wireProps}; |