@uibot/page-annotation 0.18.1 → 0.19.0
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/dist/core/inject.d.ts +1 -1
- package/dist/core/runtime/styles.d.ts +1 -1
- package/dist/guest.js +1 -1
- package/dist/host.js +1 -1
- package/dist/runtime.js +51 -19
- package/dist/uibot/inject.d.ts +1 -1
- package/package.json +2 -2
package/dist/host.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var V="uibot.annotation.host.v1",B="uibot.annotation.page.v1",Ee=1048576,U=20,j=262144,q=2;function v(e){if(!e||typeof e!=="object"||Array.isArray(e))return!1;try{return new TextEncoder().encode(JSON.stringify(e)).length<=1048576}catch{return!1}}var z=["--pa-accent","--pa-accent-soft","--pa-outline","--pa-accent-contrast","--pa-surface","--pa-surface-contrast","--pa-shadow","--pa-muted","--pa-hover","--pa-border","--pa-popover-contrast","--pa-popover","--pa-focus","--pa-selected","--pa-accent-halo","--pa-field","--pa-checker","--pa-success","--pa-success-contrast","--pa-danger","--pa-danger-contrast","--pa-color-default"],De=8192;function w(e){if(typeof e!=="string"||e.length>256||!e.trim())return!1;if(/[;{}\\<>!@'"]/.test(e)||[...e].some((o)=>o.charCodeAt(0)<32)||/url\s*\(|var\s*\(|\/\*|\*\//i.test(e))return!1;let t=e.trim();if(/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.test(t))return!0;if(new Set("aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato transparent turquoise violet wheat white whitesmoke yellow yellowgreen".split(" ")).has(t.toLowerCase()))return!0;let r=t.match(/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch)\(([^()]+)\)$/i);if(r){let o=(r[1]??"").toLowerCase(),s=(r[2]??"").trim(),l=s.includes(",");if(l&&(!/^(rgb|rgba|hsl|hsla)$/.test(o)||s.includes("/")))return!1;let u=s.split("/");if(u.length>2)return!1;let g=l?s.split(",").map((y)=>y.trim()):(u[0]??"").trim().split(/\s+/),f=l?g[3]:u[1]?.trim();if(g.length!==3&&!(l&&g.length===4))return!1;let c=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?%?$/i;if(f!==void 0&&!c.test(f)&&!(f==="none"&&!l))return!1;return g.slice(0,3).every((y,S)=>{if(y==="none")return!l;let p=/^(hsl|hsla|hwb)$/.test(o)?S===0:/^(lch|oklch)$/.test(o)&&S===2;return c.test(y)||p&&/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(deg|rad|grad|turn)$/i.test(y)})}let i=t.match(/^color\((srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65) ([^()]+)\)$/i);if(i)return w(`rgb(${i[2]})`);let a=t.match(/^color-mix\(in srgb, (.+) (\d+(?:\.\d+)?)%, (.+)\)$/i);return!!a&&Number(a[2])<=100&&w(a[1])&&w(a[3])}function R(e){if(!e||typeof e!=="object"||Array.isArray(e))return{};try{if(new TextEncoder().encode(JSON.stringify(e)).length>8192)return{}}catch{return{}}let t={};for(let n of z){let r=Object.hasOwn(e,n)?e[n]:void 0;if(w(r))t[n]=r.trim()}return t}function Oe(e,t){let n=R(t);for(let r of z){let i=n[r];if(i===void 0)e.style.removeProperty(r);else e.style.setProperty(r,i)}}var ae={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},St=Array.from(new Set(Object.values(ae).flat()));var Et=Object.freeze([Object.freeze({name:"manifest",summary:"Describe query operations and list the derived resource index.",positionals:Object.freeze([]),options:Object.freeze([])}),Object.freeze({name:"search",summary:"Search resources with deterministic bilingual ranking and reasons.",positionals:Object.freeze([Object.freeze({name:"text",property:"text",type:"string",required:!1})]),options:Object.freeze([Object.freeze({name:"kind",property:"kinds",type:"resource-kind",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"tag",property:"tags",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"category",property:"categories",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"capability",property:"capabilities",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"maturity",property:"maturities",type:"resource-maturity",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"limit",property:"limit",type:"positive-integer"})])}),Object.freeze({name:"get",summary:"Resolve one canonical resource id or unambiguous alias.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])}),Object.freeze({name:"build",summary:"Plan dependency closure and gaps without writing or installing.",positionals:Object.freeze([Object.freeze({name:"root",property:"roots",type:"string",required:!0,variadic:!0})]),options:Object.freeze([])}),Object.freeze({name:"docs",summary:"Read curated public documentation for one resource.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"locale",property:"locale",type:"string"},{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"examples",summary:"Read one bounded page of examples and exact dependencies. Follow nextPage for complete source.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"install-plan",summary:"Describe distribution channels without installing or writing.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])})]);var se=["background","foreground","card","card-foreground","popover","popover-foreground","primary","primary-foreground","secondary","secondary-foreground","muted","muted-foreground","accent","accent-foreground","border","input","ring","destructive","destructive-foreground","success","success-foreground","warning","warning-foreground"],Ot=[...se,"radius","font-display","font-body","font-mono"];var P={count:20,messageBytes:1048576,screenshotBytes:262144,screenshots:2,comment:4000,selector:2000,edits:20};function E(e){if(!e||typeof e!=="object"||Array.isArray(e))throw Error("Invalid annotation object");return e}function I(e,t){if(Object.keys(e).some((n)=>!t.includes(n)))throw Error("Unknown annotation field")}function b(e,t,n=!1){if(typeof e!=="string"||!n&&!e.trim()||e.length>t||Array.from(e).some((r)=>{let i=r.charCodeAt(0);return i===127||i<32&&i!==9&&i!==10&&i!==13}))throw Error("Invalid annotation text");return e}function H(e){let t=E(e);I(t,["x","y","width","height"]);for(let n of["x","y","width","height"])if(typeof t[n]!=="number"||!Number.isFinite(t[n])||Math.abs(t[n])>1e7)throw Error("Invalid annotation coordinates");if(t.width<0||t.height<0)throw Error("Invalid annotation dimensions");return{x:t.x,y:t.y,width:t.width,height:t.height}}function W(e){if(!Array.isArray(e)||!e.length||e.length>P.count)throw Error("Expected 1 to 20 annotations");if(new TextEncoder().encode(JSON.stringify(e)).length>P.messageBytes)throw Error("Annotations exceed the message budget");let t=0,n=new Set;return e.map((r)=>{let i=E(r);I(i,["id","comment","target","type","priority","edits","screenshot"]);let a=b(i.id,100);if(!/^[a-zA-Z0-9_-]+$/.test(a)||n.has(a))throw Error("Invalid or duplicate annotation ID");n.add(a);let o=b(i.comment,P.comment).trim();if(!["bug","style","copywriting","feature","interaction","data","other"].includes(i.type)||!["low","medium","high","blocker"].includes(i.priority))throw Error("Invalid annotation classification");let s=E(i.target),l;if(s.kind==="element"){I(s,["kind","cssSelector","xpath","tagName","textContent","boundingBox","uibotId"]);let f=b(s.tagName,80);if(!/^[a-zA-Z][a-zA-Z0-9:_-]*$/.test(f))throw Error("Invalid annotation tag");let c=s.uibotId===void 0?void 0:b(s.uibotId,200);if(c!==void 0&&!/^[\w:.-]+$/.test(c))throw Error("Invalid annotation element ID");l={kind:"element",cssSelector:b(s.cssSelector,P.selector),xpath:b(s.xpath,P.selector,!0),tagName:f,boundingBox:H(s.boundingBox),...s.textContent===void 0?{}:{textContent:b(s.textContent,1000,!0)},...c===void 0?{}:{uibotId:c}}}else if(s.kind==="region")I(s,["kind","rect"]),l={kind:"region",rect:H(s.rect)};else throw Error("Invalid annotation target");let u;if(i.edits!==void 0){if(!Array.isArray(i.edits)||i.edits.length>P.edits)throw Error("Invalid annotation edits");u=i.edits.map((f)=>{let c=E(f);if(I(c,["kind","label","property","before","after"]),c.kind!=="style"&&c.kind!=="text")throw Error("Invalid annotation edit kind");let y=c.property===void 0?void 0:b(c.property,100);if(y!==void 0&&!/^[-a-zA-Z][\w-]*$/.test(y))throw Error("Invalid annotation style property");return{kind:c.kind,label:b(c.label,200),before:b(c.before,4000,!0),after:b(c.after,4000,!0),...y===void 0?{}:{property:y}}})}let g;if(i.screenshot!==void 0){if(g=b(i.screenshot,P.screenshotBytes),!/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(g)||++t>P.screenshots)throw Error("Invalid annotation screenshot")}return{id:a,comment:o,type:i.type,priority:i.priority,target:l,...u?{edits:u}:{},...g?{screenshot:g}:{}}})}function Mn(e){let t={blocker:0,high:1,medium:2,low:3};return[...e].sort((n,r)=>t[n.priority]-t[r.priority]||n.createdAt.localeCompare(r.createdAt))}function Fn(e,t){if(e.target.kind==="region")return`${t==="zh"?"\u533A\u57DF":"Region"} ${Math.round(e.target.rect.width)}\xD7${Math.round(e.target.rect.height)}`;return`${e.target.tagName}\u300C${(e.target.textContent??e.target.cssSelector).slice(0,48)}\u300D`}function K(e){let t=e.target;return{id:e.id,comment:e.comment.trim(),type:e.type,priority:e.priority,target:t.kind==="region"?{kind:"region",rect:t.rect}:{kind:"element",cssSelector:t.cssSelector,xpath:t.xpath,tagName:t.tagName,...t.textContent?{textContent:t.textContent}:{},boundingBox:t.boundingBox,...t.attributes["data-uibot-id"]?{uibotId:t.attributes["data-uibot-id"]}:{}},...e.edits?.length?{edits:e.edits.map((n)=>({kind:n.kind,label:n.label,before:n.before,after:n.after,...n.property?{property:n.property}:{}}))}:{},...e.screenshot?{screenshot:e.screenshot}:{}}}var Y=[{id:"red",value:"#ef4444",label:"\u7EA2"},{id:"orange",value:"#f97316",label:"\u6A59"},{id:"yellow",value:"#eab308",label:"\u9EC4"},{id:"green",value:"#22c55e",label:"\u7EFF"},{id:"blue",value:"#3b82f6",label:"\u84DD"},{id:"white",value:"#f8fafc",label:"\u767D"}],Vn=12,Bn=48,Un=4,jn=16;function G(e){let t=Math.round(e/4)*4;return Math.min(48,Math.max(12,t))}function le(e,t){let n=G(t),r=Math.max(1,[...e].length);return{width:Math.max(n,r*n),height:Math.ceil(n*1.35)}}var ce=new Set(Y.map((e)=>e.value));function de(e){return ce.has(e)}function qn(){return Y[0].value}function C(e){return typeof e==="number"&&Number.isFinite(e)}function ue(e){if(!e||typeof e!=="object"||Array.isArray(e))return null;let t=e;if(typeof t.color!=="string"||!de(t.color))return null;if(t.kind==="rect"){if(!C(t.x)||!C(t.y)||!C(t.width)||!C(t.height))return null;if(t.width<8||t.height<8)return null;return{kind:"rect",color:t.color,x:t.x,y:t.y,width:t.width,height:t.height}}if(t.kind==="arrow"){if(!C(t.x1)||!C(t.y1)||!C(t.x2)||!C(t.y2))return null;return{kind:"arrow",color:t.color,x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2}}if(t.kind==="text"){if(!C(t.x)||!C(t.y)||typeof t.text!=="string")return null;let n=t.text.trim();if(!n)return null;let r=t.fontSize===void 0?16:C(t.fontSize)?G(t.fontSize):null;if(r==null)return null;return{kind:"text",color:t.color,x:t.x,y:t.y,text:n,fontSize:r}}return null}function J(e){if(e===void 0)return;if(!Array.isArray(e))return;let t=[];for(let n of e){let r=ue(n);if(!r)return;t.push(r)}return t}function zn(e){if(e.length===0)return"\u533A\u57DF\u6807\u6CE8";let t=e.filter((a)=>a.kind==="rect").length,n=e.filter((a)=>a.kind==="arrow").length,r=e.filter((a)=>a.kind==="text"),i=[];if(t)i.push(`${t} \u4E2A\u6846`);if(n)i.push(`${n} \u4E2A\u7BAD\u5934`);if(r.length){let a=r.map((o)=>o.text.trim()).filter(Boolean).slice(0,3).map((o)=>`\u300C${o.length>16?`${o.slice(0,16)}\u2026`:o}\u300D`);i.push(a.length?`\u6587\u672C ${a.join(" ")}`:`${r.length} \u5904\u6587\u672C`)}return`\u533A\u57DF\u6807\u6CE8\uFF08${i.join("\uFF0C")}\uFF09`}function Hn(e,t=16){if(e.length===0)return null;let{POSITIVE_INFINITY:n,POSITIVE_INFINITY:r,NEGATIVE_INFINITY:i,NEGATIVE_INFINITY:a}=Number;for(let o of e)if(o.kind==="rect")n=Math.min(n,o.x),r=Math.min(r,o.y),i=Math.max(i,o.x+o.width),a=Math.max(a,o.y+o.height);else if(o.kind==="arrow")n=Math.min(n,o.x1,o.x2),r=Math.min(r,o.y1,o.y2),i=Math.max(i,o.x1,o.x2),a=Math.max(a,o.y1,o.y2);else{let s=le(o.text,o.fontSize);n=Math.min(n,o.x),r=Math.min(r,o.y),i=Math.max(i,o.x+s.width),a=Math.max(a,o.y+s.height)}return{x:n-t,y:r-t,width:Math.max(8,i-n+t*2),height:Math.max(8,a-r+t*2)}}function Wn(e,t,n){return e.map((r)=>{if(r.kind==="rect")return{...r,x:r.x+t,y:r.y+n};if(r.kind==="arrow")return{...r,x1:r.x1+t,y1:r.y1+n,x2:r.x2+t,y2:r.y2+n};return{...r,x:r.x+t,y:r.y+n,fontSize:r.fontSize}})}function $n(e,t){let n=Math.max(0,Math.min(e.x,t.width)),r=Math.max(0,Math.min(e.y,t.height)),i=Math.min(e.width,t.width-n),a=Math.min(e.height,t.height-r);if(i<8||a<8)return null;return{x:n,y:r,width:i,height:a}}var Z={blocker:0,high:1,medium:2,low:3};function T(e){return e.status==="open"||e.status==="processing"}function D(e){return[...e].sort((t,n)=>Z[t.priority]-Z[n.priority]||t.createdAt.localeCompare(n.createdAt))}function Yn(e){return D(e.filter(T))}var pe=["open","processing","done","verified","ignored"],ge=["bug","style","copywriting","feature","interaction","data","other"],X=["low","medium","high","blocker"],me=["testid","id","aria","class","text","path"],fe=["light","dark","unknown"],ye=["react","vue","angular","svelte","nextjs","nuxt","unknown"],be=["target-location","screenshot","context-bundle","dom-snapshot","style-snapshot"],Ce=["inline","exported-file","url","none"];function m(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function x(e,t){return typeof e==="string"&&t.includes(e)}function h(e){return typeof e==="number"&&Number.isFinite(e)}function A(e){return h(e)&&e>0}function _(e){return Array.isArray(e)&&e.every((t)=>typeof t==="string")}function ee(e){return m(e)&&Object.values(e).every((t)=>typeof t==="string")}function d(e){return e===void 0||typeof e==="string"}function te(e){if(!m(e)||!h(e.x)||!h(e.y)||!A(e.width)||!A(e.height))return;return{x:e.x,y:e.y,width:e.width,height:e.height}}function N(e){if(!m(e)||!A(e.width)||!A(e.height))return;return{width:e.width,height:e.height}}function M(e){if(!m(e)||!h(e.x)||!h(e.y))return;return{x:e.x,y:e.y}}function Q(e){if(!m(e)||typeof e.fileName!=="string"||!A(e.lineNumber))return;if(e.columnNumber!==void 0&&(!h(e.columnNumber)||e.columnNumber<0))return;if(!d(e.componentName))return;return{fileName:e.fileName,lineNumber:e.lineNumber,...e.columnNumber===void 0?{}:{columnNumber:e.columnNumber},...e.componentName===void 0?{}:{componentName:e.componentName}}}function xe(e){let t=te(e.boundingBox);if(typeof e.tagName!=="string"||!e.tagName||typeof e.cssSelector!=="string"||!e.cssSelector||typeof e.xpath!=="string"||!e.xpath||!ee(e.attributes)||!t||!_(e.domPath))return;if(!d(e.textContent)||e.breadcrumb!==void 0&&!_(e.breadcrumb))return;if(e.selectorStrategy!==void 0&&!x(e.selectorStrategy,me))return;if(!d(e.region))return;let n;if(e.accessibility!==void 0){if(!m(e.accessibility)||!d(e.accessibility.role)||!d(e.accessibility.name)||!d(e.accessibility.ariaLabel))return;n={...e.accessibility.role===void 0?{}:{role:e.accessibility.role},...e.accessibility.name===void 0?{}:{name:e.accessibility.name},...e.accessibility.ariaLabel===void 0?{}:{ariaLabel:e.accessibility.ariaLabel}}}let r=e.sourceLocation===void 0?void 0:Q(e.sourceLocation);if(e.sourceLocation!==void 0&&!r)return;let i;if(e.sourceStack!==void 0){if(!Array.isArray(e.sourceStack))return;let a=e.sourceStack.map(Q);if(a.some((o)=>!o))return;i=a.filter((o)=>Boolean(o))}return{kind:"element",tagName:e.tagName,cssSelector:e.cssSelector,xpath:e.xpath,...e.textContent===void 0?{}:{textContent:e.textContent},attributes:{...e.attributes},boundingBox:t,domPath:[...e.domPath],...n?{accessibility:n}:{},...e.selectorStrategy===void 0?{}:{selectorStrategy:e.selectorStrategy},...e.region===void 0?{}:{region:e.region},...e.breadcrumb===void 0?{}:{breadcrumb:[...e.breadcrumb]},...r?{sourceLocation:r}:{},...i?{sourceStack:i}:{}}}function he(e){let t=te(e.rect),n=N(e.viewport),r=M(e.scroll);if(!t||t.width<8||t.height<8||!n||!r||!A(e.devicePixelRatio))return;if(e.breadcrumb!==void 0&&!_(e.breadcrumb))return;let i;if(e.topLevelElements!==void 0){if(!Array.isArray(e.topLevelElements))return;i=[];for(let o of e.topLevelElements){if(!m(o)||typeof o.tagName!=="string"||!o.tagName||!d(o.text)||!d(o.role))return;i.push({tagName:o.tagName,...o.text===void 0?{}:{text:o.text},...o.role===void 0?{}:{role:o.role}})}}let a=e.marks===void 0?void 0:J(e.marks);if(e.marks!==void 0&&!a)return;return{kind:"region",rect:t,viewport:n,scroll:r,devicePixelRatio:e.devicePixelRatio,...e.breadcrumb===void 0?{}:{breadcrumb:[...e.breadcrumb]},...i?{topLevelElements:i}:{},...a?.length?{marks:a}:{}}}function ke(e){if(!m(e))return{ok:!1,reason:"target is not an object",raw:e};if(e.kind==="region"){let t=he(e);return t?{ok:!0,value:t}:{ok:!1,reason:"invalid region target",raw:e}}if(e.kind==="element"||e.kind===void 0){let t=xe(e);return t?{ok:!0,value:t}:{ok:!1,reason:"invalid element target",raw:e}}return{ok:!1,reason:`unknown target kind: ${String(e.kind)}`,raw:e}}function Pe(e){if(!m(e))return;let t=N(e.viewport),n=M(e.scroll);if(!t||!n||!A(e.devicePixelRatio)||!m(e.center)||!h(e.center.x)||!h(e.center.y)||typeof e.visible!=="boolean"||!d(e.positioning))return;return{viewport:t,scroll:n,devicePixelRatio:e.devicePixelRatio,center:{x:e.center.x,y:e.center.y},visible:e.visible,...e.positioning===void 0?{}:{positioning:e.positioning}}}function ne(e){if(!m(e))return;let{url:t,origin:n,path:r,title:i,capturedAt:a,query:o,hash:s,referrer:l,language:u,userAgent:g,uiState:f}=e,c=N(e.viewport),y=M(e.scroll);if(!c||!m(e.viewport)||!A(e.viewport.devicePixelRatio)||!y)return;if(typeof t!=="string"||!t||typeof n!=="string"||!n||typeof r!=="string"||!r||typeof i!=="string"||typeof a!=="string"||!a)return;if(!d(o)||!d(s)||!d(l)||!d(u)||!d(g)||!d(f))return;if(e.theme!==void 0&&!x(e.theme,fe))return;if(e.framework!==void 0&&!x(e.framework,ye))return;return{url:t,origin:n,path:r,title:i,viewport:{...c,devicePixelRatio:e.viewport.devicePixelRatio},scroll:y,capturedAt:a,...o===void 0?{}:{query:o},...s===void 0?{}:{hash:s},...l===void 0?{}:{referrer:l},...e.theme===void 0?{}:{theme:e.theme},...e.framework===void 0?{}:{framework:e.framework},...u===void 0?{}:{language:u},...g===void 0?{}:{userAgent:g},...f===void 0?{}:{uiState:f}}}function Ae(e){if(e===void 0)return[];if(!Array.isArray(e))return;let t=[];for(let n of e){if(!m(n)||!x(n.kind,["style","text"])||typeof n.label!=="string"||!d(n.property)||typeof n.before!=="string"||typeof n.after!=="string")return;t.push({kind:n.kind,label:n.label,before:n.before,after:n.after,...n.property===void 0?{}:{property:n.property}})}return t}function Re(e){if(!Array.isArray(e))return;let t=[];for(let n of e){if(!m(n)||!x(n.kind,be)||!x(n.availability,Ce)||typeof n.label!=="string"||!n.label||!d(n.annotationId)||!d(n.reference))return;if(n.availability!=="none"&&!n.reference?.trim())return;t.push({kind:n.kind,availability:n.availability,label:n.label,...n.annotationId===void 0?{}:{annotationId:n.annotationId},...n.reference===void 0?{}:{reference:n.reference}})}return t}function F(e){if(!m(e))return{ok:!1,reason:"annotation is not an object",raw:e};let{id:t,pageUrl:n,comment:r,createdAt:i,updatedAt:a}=e;if(!x(e.status,pe))return{ok:!1,reason:"invalid status",raw:e};if(!x(e.type,ge))return{ok:!1,reason:"invalid type",raw:e};if(!x(e.priority,X))return{ok:!1,reason:"invalid priority",raw:e};if(typeof t!=="string"||!t)return{ok:!1,reason:"invalid id",raw:e};if(typeof n!=="string"||!n)return{ok:!1,reason:"invalid pageUrl",raw:e};if(typeof r!=="string"||!r)return{ok:!1,reason:"invalid comment",raw:e};if(typeof i!=="string"||!i)return{ok:!1,reason:"invalid createdAt",raw:e};if(typeof a!=="string"||!a)return{ok:!1,reason:"invalid updatedAt",raw:e};if(!d(e.expectedResult)||!d(e.preserve)||!d(e.screenshot))return{ok:!1,reason:"invalid optional annotation text",raw:e};if(!ee(e.styleSummary))return{ok:!1,reason:"invalid styleSummary",raw:e};let o=Pe(e.geometry);if(!o)return{ok:!1,reason:"invalid geometry",raw:e};let s=ne(e.pageContext);if(!s)return{ok:!1,reason:"invalid pageContext",raw:e};let l=Ae(e.edits);if(!l)return{ok:!1,reason:"invalid edits",raw:e};let u=ke(e.target);if(!u.ok)return u;return{ok:!0,value:{id:t,pageUrl:n,status:e.status,type:e.type,priority:e.priority,comment:r,target:u.value,styleSummary:{...e.styleSummary},geometry:o,pageContext:s,createdAt:i,updatedAt:a,...e.expectedResult===void 0?{}:{expectedResult:e.expectedResult},...e.preserve===void 0?{}:{preserve:e.preserve},...e.screenshot===void 0?{}:{screenshot:e.screenshot},...l.length?{edits:l}:{}}}}function Ie(e){let t=[],n=[];return e.forEach((r,i)=>{let a=F(r);if(a.ok)t.push(a.value);else n.push({index:i,reason:a.reason,raw:a.raw})}),{annotations:D(t),failures:n}}function Qn(e){if(!m(e)||!Array.isArray(e.annotations))return{ok:!1,reason:"context annotations are missing",raw:e};if(e.version!=="1.0"&&e.version!=="2.0")return{ok:!1,reason:`unsupported context version: ${String(e.version)}`,raw:e};let t=Ie(e.annotations),[n]=t.failures;if(n)return{ok:!1,reason:`invalid annotation at index ${n.index}`,raw:e};let r=e.version==="2.0";if(r){if(e.schema!=="uibot/web-annotation-context"||typeof e.contextId!=="string"||!e.contextId||typeof e.createdAt!=="string"||!e.createdAt||!x(e.scope,["active","all"])||!m(e.summary)||!h(e.summary.totalAnnotations)||e.summary.totalAnnotations<0||!h(e.summary.activeAnnotations)||e.summary.activeAnnotations<0||!h(e.summary.includedAnnotations)||e.summary.includedAnnotations<0||e.summary.topPriority!==void 0&&!x(e.summary.topPriority,X))return{ok:!1,reason:"invalid v2 context metadata",raw:e}}let i=r?Re(e.evidence):[];if(!i)return{ok:!1,reason:"invalid context evidence",raw:e};let a=r?e.scope:"all",o=t.annotations,s=a==="active"?o.filter(T):o,l=e.page===void 0?void 0:ne(e.page);if(e.page!==void 0&&!l)return{ok:!1,reason:"invalid context page",raw:e};return{ok:!0,value:{schema:"uibot/web-annotation-context",version:"2.0",contextId:typeof e.contextId==="string"?e.contextId:`ctx_${Date.now()}`,createdAt:typeof e.createdAt==="string"?e.createdAt:new Date().toISOString(),scope:a,...l?{page:l}:{},summary:{totalAnnotations:o.length,activeAnnotations:o.filter(T).length,includedAnnotations:s.length,topPriority:D(s)[0]?.priority},evidence:i,annotations:s}}}function Se(e){return typeof e==="string"&&e.length<=j&&/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(e)}function re(e){if(!Array.isArray(e)||e.length>U||!v({items:e}))return null;let t=[],n=0,r=new Set;for(let i of e){let a=F(i);if(!a.ok)return null;let o=a.value;if(!/^[a-zA-Z0-9_-]{1,100}$/.test(o.id)||r.has(o.id)||!o.comment.trim()||o.comment.length>4000)return null;if(r.add(o.id),o.target.kind==="element"&&(o.target.cssSelector.length>2000||o.target.xpath.length>2000||(o.target.textContent?.length??0)>1000))return null;if(o.screenshot!==void 0&&(!Se(o.screenshot)||++n>q))return null;if((o.edits?.length??0)>20||o.edits?.some((s)=>s.before.length>4000||s.after.length>4000))return null;t.push(o)}try{if(t.length)W(t.map(K))}catch{return null}return t}function lr(e){let t=e.ownerWindow??window,n=e.nonce??crypto.randomUUID(),r={enabled:!1,locked:!1,locale:"zh",items:[],theme:R(e.theme)},i=!1,a=!1,o=!1,s,l=(p)=>{if(o===!p)return;o=!p,e.onResponsiveChange?.(p)},u=()=>{if(s!==void 0)t.clearTimeout(s);if(s=void 0,!r.enabled||a||i){if(!r.enabled||a)l(!0);return}s=t.setTimeout(()=>{if(s=void 0,!a&&r.enabled&&!i)l(!1)},e.handshakeTimeoutMs??2500)},g=(p)=>{if(!i)e.iframe.contentWindow?.postMessage({...p,source:V,nonce:n},"*")},f=()=>g({action:"sync",...r}),c=(p)=>{if(i||p.source!==e.iframe.contentWindow||!v(p.data))return;let k=p.data;if(k.source!==B||k.nonce!==n)return;if(k.action==="ready"){a=!0,u();return}if(k.action==="closed"){e.onClose();return}if(k.action!=="snapshot"||r.locked||!r.enabled)return;let L=re(k.items);if(L)e.onChange(L)};t.addEventListener("message",c);let y=()=>{if(a=!1,r.enabled||r.items.length)f();u()};e.iframe.addEventListener("load",y);let S=t.setInterval(()=>{if(!a&&r.enabled)f()},400);return{update(p){let k=r.enabled;if(r={...r,...p,theme:Object.hasOwn(p,"theme")?R(p.theme):r.theme??{}},f(),k!==r.enabled)u()},reveal(p){if(r.items.some((k)=>k.id===p))g({action:"reveal",id:p})},dispose(){if(i)return;if(g({action:"sync",enabled:!1,locked:!0,items:[],locale:r.locale}),i=!0,t.clearInterval(S),s!==void 0)t.clearTimeout(s);t.removeEventListener("message",c),e.iframe.removeEventListener("load",y)}}}var ve={primaryContrast:["--primary-foreground","#fafafa"],surface:["--card","#ffffff"],foreground:["--card-foreground","#18181b"],popover:["--popover","#ffffff"],popoverContrast:["--popover-foreground","#18181b"],border:["--border","#e4e4e7"],muted:["--muted-foreground","#71717a"],field:["--muted","#f4f4f5"],hover:["--accent","#f4f4f5"],focus:["--ring","#a1a1aa"],danger:["--destructive","#dc2626"]},O={accent:"#18181b",contrast:"#fafafa",selected:"#3f3f46",outline:"rgba(255, 255, 255, 0.6)"};function we(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(i)=>{let[a,o]=ve[i],s=t?.getPropertyValue(a).trim()??"";return R({"--pa-accent":s})["--pa-accent"]??o},r=O.accent;return R({"--pa-accent":r,"--pa-accent-contrast":O.contrast,"--pa-accent-soft":`color-mix(in srgb, ${r} 10%, transparent)`,"--pa-accent-halo":`color-mix(in srgb, ${r} 45%, transparent)`,"--pa-surface":n("surface"),"--pa-surface-contrast":n("foreground"),"--pa-popover":n("popover"),"--pa-popover-contrast":n("popoverContrast"),"--pa-border":n("border"),"--pa-muted":n("muted"),"--pa-field":n("field"),"--pa-hover":n("hover"),"--pa-selected":O.selected,"--pa-focus":n("focus"),"--pa-outline":O.outline,"--pa-shadow":"#00000033","--pa-checker":n("muted"),"--pa-danger":n("danger"),"--pa-danger-contrast":n("primaryContrast"),"--pa-success":"#15803d","--pa-success-contrast":"#ffffff","--pa-color-default":n("foreground")})}function ur(e,t){let n=e.ownerDocument.defaultView;if(!n)return()=>{};let r=()=>t(we(e)),i=new n.MutationObserver(r);i.observe(e,{attributes:!0,attributeFilter:["class","style"]});let a=n.matchMedia("(prefers-color-scheme: dark)");return a.addEventListener("change",r),()=>{i.disconnect(),a.removeEventListener("change",r)}}export{V as ANNOTATION_HOST_SOURCE,U as ANNOTATION_MAX_ITEMS,Ee as ANNOTATION_MAX_MESSAGE_BYTES,q as ANNOTATION_MAX_SCREENSHOTS,B as ANNOTATION_PAGE_SOURCE,j as ANNOTATION_SCREENSHOT_MAX_BYTES,De as ANNOTATION_THEME_MAX_BYTES,z as ANNOTATION_THEME_TOKENS,Oe as applyAnnotationTheme,v as boundedMessage,lr as createAnnotationController,w as isAnnotationThemeColor,ur as observeStudioAnnotationTheme,re as parseAnnotationItems,we as resolveStudioAnnotationTheme,Se as validScreenshot,R as validateAnnotationTheme};
|
|
2
|
+
var B="uibot.annotation.host.v1",V="uibot.annotation.page.v1",Ee=1048576,j=20,q=262144,U=2;function v(e){if(!e||typeof e!=="object"||Array.isArray(e))return!1;try{return new TextEncoder().encode(JSON.stringify(e)).length<=1048576}catch{return!1}}var z=["--pa-accent","--pa-accent-soft","--pa-outline","--pa-accent-contrast","--pa-surface","--pa-surface-contrast","--pa-shadow","--pa-muted","--pa-hover","--pa-border","--pa-popover-contrast","--pa-popover","--pa-focus","--pa-selected","--pa-accent-halo","--pa-field","--pa-checker","--pa-success","--pa-success-contrast","--pa-danger","--pa-danger-contrast","--pa-color-default"],De=8192;function w(e){if(typeof e!=="string"||e.length>256||!e.trim())return!1;if(/[;{}\\<>!@'"]/.test(e)||[...e].some((o)=>o.charCodeAt(0)<32)||/url\s*\(|var\s*\(|\/\*|\*\//i.test(e))return!1;let t=e.trim();if(/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.test(t))return!0;if(new Set("aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato transparent turquoise violet wheat white whitesmoke yellow yellowgreen".split(" ")).has(t.toLowerCase()))return!0;let r=t.match(/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch)\(([^()]+)\)$/i);if(r){let o=(r[1]??"").toLowerCase(),a=(r[2]??"").trim(),l=a.includes(",");if(l&&(!/^(rgb|rgba|hsl|hsla)$/.test(o)||a.includes("/")))return!1;let u=a.split("/");if(u.length>2)return!1;let g=l?a.split(",").map((y)=>y.trim()):(u[0]??"").trim().split(/\s+/),f=l?g[3]:u[1]?.trim();if(g.length!==3&&!(l&&g.length===4))return!1;let c=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?%?$/i;if(f!==void 0&&!c.test(f)&&!(f==="none"&&!l))return!1;return g.slice(0,3).every((y,S)=>{if(y==="none")return!l;let p=/^(hsl|hsla|hwb)$/.test(o)?S===0:/^(lch|oklch)$/.test(o)&&S===2;return c.test(y)||p&&/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(deg|rad|grad|turn)$/i.test(y)})}let i=t.match(/^color\((srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65) ([^()]+)\)$/i);if(i)return w(`rgb(${i[2]})`);let s=t.match(/^color-mix\(in srgb, (.+) (\d+(?:\.\d+)?)%, (.+)\)$/i);return!!s&&Number(s[2])<=100&&w(s[1])&&w(s[3])}function I(e){if(!e||typeof e!=="object"||Array.isArray(e))return{};try{if(new TextEncoder().encode(JSON.stringify(e)).length>8192)return{}}catch{return{}}let t={};for(let n of z){let r=Object.hasOwn(e,n)?e[n]:void 0;if(w(r))t[n]=r.trim()}return t}function Ne(e,t){let n=I(t);for(let r of z){let i=n[r];if(i===void 0)e.style.removeProperty(r);else e.style.setProperty(r,i)}}var se={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},St=Array.from(new Set(Object.values(se).flat()));var Et=Object.freeze([Object.freeze({name:"manifest",summary:"Describe query operations and list the derived resource index.",positionals:Object.freeze([]),options:Object.freeze([])}),Object.freeze({name:"search",summary:"Search resources with deterministic bilingual ranking and reasons.",positionals:Object.freeze([Object.freeze({name:"text",property:"text",type:"string",required:!1})]),options:Object.freeze([...[["function","functions"],["scenario","scenarios"],["unit","units"],["industry","industries"]].map(([e,t])=>Object.freeze({name:e,property:t,type:"string",multiple:!0,cliEncoding:"comma-separated"})),Object.freeze({name:"kind",property:"kinds",type:"resource-kind",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"tag",property:"tags",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"category",property:"categories",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"capability",property:"capabilities",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"maturity",property:"maturities",type:"resource-maturity",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"limit",property:"limit",type:"positive-integer"})])}),Object.freeze({name:"get",summary:"Resolve one canonical resource id or unambiguous alias.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])}),Object.freeze({name:"build",summary:"Plan dependency closure and gaps without writing or installing.",positionals:Object.freeze([Object.freeze({name:"root",property:"roots",type:"string",required:!0,variadic:!0})]),options:Object.freeze([])}),Object.freeze({name:"docs",summary:"Read curated public documentation for one resource.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"locale",property:"locale",type:"string"},{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"examples",summary:"Read one bounded page of examples and exact dependencies. Follow nextPage for complete source.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"install-plan",summary:"Describe distribution channels and fixed snapshot identity/closure without installing or writing.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])})]);var ae=["background","foreground","card","card-foreground","popover","popover-foreground","primary","primary-foreground","secondary","secondary-foreground","muted","muted-foreground","accent","accent-foreground","border","input","ring","destructive","destructive-foreground","success","success-foreground","warning","warning-foreground"],Nt=[...ae,"radius","font-display","font-body","font-mono"];var R={count:20,messageBytes:1048576,screenshotBytes:262144,screenshots:2,comment:4000,selector:2000,edits:20};function E(e){if(!e||typeof e!=="object"||Array.isArray(e))throw Error("Invalid annotation object");return e}function P(e,t){if(Object.keys(e).some((n)=>!t.includes(n)))throw Error("Unknown annotation field")}function b(e,t,n=!1){if(typeof e!=="string"||!n&&!e.trim()||e.length>t||Array.from(e).some((r)=>{let i=r.charCodeAt(0);return i===127||i<32&&i!==9&&i!==10&&i!==13}))throw Error("Invalid annotation text");return e}function H(e){let t=E(e);P(t,["x","y","width","height"]);for(let n of["x","y","width","height"])if(typeof t[n]!=="number"||!Number.isFinite(t[n])||Math.abs(t[n])>1e7)throw Error("Invalid annotation coordinates");if(t.width<0||t.height<0)throw Error("Invalid annotation dimensions");return{x:t.x,y:t.y,width:t.width,height:t.height}}function W(e){if(!Array.isArray(e)||!e.length||e.length>R.count)throw Error("Expected 1 to 20 annotations");if(new TextEncoder().encode(JSON.stringify(e)).length>R.messageBytes)throw Error("Annotations exceed the message budget");let t=0,n=new Set;return e.map((r)=>{let i=E(r);P(i,["id","comment","target","type","priority","edits","screenshot"]);let s=b(i.id,100);if(!/^[a-zA-Z0-9_-]+$/.test(s)||n.has(s))throw Error("Invalid or duplicate annotation ID");n.add(s);let o=b(i.comment,R.comment).trim();if(!["bug","style","copywriting","feature","interaction","data","other"].includes(i.type)||!["low","medium","high","blocker"].includes(i.priority))throw Error("Invalid annotation classification");let a=E(i.target),l;if(a.kind==="element"){P(a,["kind","cssSelector","xpath","tagName","textContent","boundingBox","uibotId"]);let f=b(a.tagName,80);if(!/^[a-zA-Z][a-zA-Z0-9:_-]*$/.test(f))throw Error("Invalid annotation tag");let c=a.uibotId===void 0?void 0:b(a.uibotId,200);if(c!==void 0&&!/^[\w:.-]+$/.test(c))throw Error("Invalid annotation element ID");l={kind:"element",cssSelector:b(a.cssSelector,R.selector),xpath:b(a.xpath,R.selector,!0),tagName:f,boundingBox:H(a.boundingBox),...a.textContent===void 0?{}:{textContent:b(a.textContent,1000,!0)},...c===void 0?{}:{uibotId:c}}}else if(a.kind==="region")P(a,["kind","rect"]),l={kind:"region",rect:H(a.rect)};else throw Error("Invalid annotation target");let u;if(i.edits!==void 0){if(!Array.isArray(i.edits)||i.edits.length>R.edits)throw Error("Invalid annotation edits");u=i.edits.map((f)=>{let c=E(f);if(P(c,["kind","label","property","before","after"]),c.kind!=="style"&&c.kind!=="text")throw Error("Invalid annotation edit kind");let y=c.property===void 0?void 0:b(c.property,100);if(y!==void 0&&!/^[-a-zA-Z][\w-]*$/.test(y))throw Error("Invalid annotation style property");return{kind:c.kind,label:b(c.label,200),before:b(c.before,4000,!0),after:b(c.after,4000,!0),...y===void 0?{}:{property:y}}})}let g;if(i.screenshot!==void 0){if(g=b(i.screenshot,R.screenshotBytes),!/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(g)||++t>R.screenshots)throw Error("Invalid annotation screenshot")}return{id:s,comment:o,type:i.type,priority:i.priority,target:l,...u?{edits:u}:{},...g?{screenshot:g}:{}}})}function ir(e){let t={blocker:0,high:1,medium:2,low:3};return[...e].sort((n,r)=>t[n.priority]-t[r.priority]||n.createdAt.localeCompare(r.createdAt))}function sr(e,t){if(e.target.kind==="region")return`${t==="zh"?"\u533A\u57DF":"Region"} ${Math.round(e.target.rect.width)}\xD7${Math.round(e.target.rect.height)}`;return`${e.target.tagName}\u300C${(e.target.textContent??e.target.cssSelector).slice(0,48)}\u300D`}function K(e){let t=e.target;return{id:e.id,comment:e.comment.trim(),type:e.type,priority:e.priority,target:t.kind==="region"?{kind:"region",rect:t.rect}:{kind:"element",cssSelector:t.cssSelector,xpath:t.xpath,tagName:t.tagName,...t.textContent?{textContent:t.textContent}:{},boundingBox:t.boundingBox,...t.attributes["data-uibot-id"]?{uibotId:t.attributes["data-uibot-id"]}:{}},...e.edits?.length?{edits:e.edits.map((n)=>({kind:n.kind,label:n.label,before:n.before,after:n.after,...n.property?{property:n.property}:{}}))}:{},...e.screenshot?{screenshot:e.screenshot}:{}}}var Y=[{id:"red",value:"#ef4444",label:"\u7EA2"},{id:"orange",value:"#f97316",label:"\u6A59"},{id:"yellow",value:"#eab308",label:"\u9EC4"},{id:"green",value:"#22c55e",label:"\u7EFF"},{id:"blue",value:"#3b82f6",label:"\u84DD"},{id:"white",value:"#f8fafc",label:"\u767D"}],lr=12,cr=48,dr=4,ur=16;function G(e){let t=Math.round(e/4)*4;return Math.min(48,Math.max(12,t))}function le(e,t){let n=G(t),r=Math.max(1,[...e].length);return{width:Math.max(n,r*n),height:Math.ceil(n*1.35)}}var ce=new Set(Y.map((e)=>e.value));function de(e){return ce.has(e)}function pr(){return Y[0].value}function h(e){return typeof e==="number"&&Number.isFinite(e)}function ue(e){if(!e||typeof e!=="object"||Array.isArray(e))return null;let t=e;if(typeof t.color!=="string"||!de(t.color))return null;if(t.kind==="rect"){if(!h(t.x)||!h(t.y)||!h(t.width)||!h(t.height))return null;if(t.width<8||t.height<8)return null;return{kind:"rect",color:t.color,x:t.x,y:t.y,width:t.width,height:t.height}}if(t.kind==="arrow"){if(!h(t.x1)||!h(t.y1)||!h(t.x2)||!h(t.y2))return null;return{kind:"arrow",color:t.color,x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2}}if(t.kind==="text"){if(!h(t.x)||!h(t.y)||typeof t.text!=="string")return null;let n=t.text.trim();if(!n)return null;let r=t.fontSize===void 0?16:h(t.fontSize)?G(t.fontSize):null;if(r==null)return null;return{kind:"text",color:t.color,x:t.x,y:t.y,text:n,fontSize:r}}return null}function J(e){if(e===void 0)return;if(!Array.isArray(e))return;let t=[];for(let n of e){let r=ue(n);if(!r)return;t.push(r)}return t}function gr(e){if(e.length===0)return"\u533A\u57DF\u6807\u6CE8";let t=e.filter((s)=>s.kind==="rect").length,n=e.filter((s)=>s.kind==="arrow").length,r=e.filter((s)=>s.kind==="text"),i=[];if(t)i.push(`${t} \u4E2A\u6846`);if(n)i.push(`${n} \u4E2A\u7BAD\u5934`);if(r.length){let s=r.map((o)=>o.text.trim()).filter(Boolean).slice(0,3).map((o)=>`\u300C${o.length>16?`${o.slice(0,16)}\u2026`:o}\u300D`);i.push(s.length?`\u6587\u672C ${s.join(" ")}`:`${r.length} \u5904\u6587\u672C`)}return`\u533A\u57DF\u6807\u6CE8\uFF08${i.join("\uFF0C")}\uFF09`}function mr(e,t=16){if(e.length===0)return null;let{POSITIVE_INFINITY:n,POSITIVE_INFINITY:r,NEGATIVE_INFINITY:i,NEGATIVE_INFINITY:s}=Number;for(let o of e)if(o.kind==="rect")n=Math.min(n,o.x),r=Math.min(r,o.y),i=Math.max(i,o.x+o.width),s=Math.max(s,o.y+o.height);else if(o.kind==="arrow")n=Math.min(n,o.x1,o.x2),r=Math.min(r,o.y1,o.y2),i=Math.max(i,o.x1,o.x2),s=Math.max(s,o.y1,o.y2);else{let a=le(o.text,o.fontSize);n=Math.min(n,o.x),r=Math.min(r,o.y),i=Math.max(i,o.x+a.width),s=Math.max(s,o.y+a.height)}return{x:n-t,y:r-t,width:Math.max(8,i-n+t*2),height:Math.max(8,s-r+t*2)}}function fr(e,t,n){return e.map((r)=>{if(r.kind==="rect")return{...r,x:r.x+t,y:r.y+n};if(r.kind==="arrow")return{...r,x1:r.x1+t,y1:r.y1+n,x2:r.x2+t,y2:r.y2+n};return{...r,x:r.x+t,y:r.y+n,fontSize:r.fontSize}})}function yr(e,t){let n=Math.max(0,Math.min(e.x,t.width)),r=Math.max(0,Math.min(e.y,t.height)),i=Math.min(e.width,t.width-n),s=Math.min(e.height,t.height-r);if(i<8||s<8)return null;return{x:n,y:r,width:i,height:s}}var Z={blocker:0,high:1,medium:2,low:3};function T(e){return e.status==="open"||e.status==="processing"}function D(e){return[...e].sort((t,n)=>Z[t.priority]-Z[n.priority]||t.createdAt.localeCompare(n.createdAt))}function hr(e){return D(e.filter(T))}var pe=["open","processing","done","verified","ignored"],ge=["bug","style","copywriting","feature","interaction","data","other"],X=["low","medium","high","blocker"],me=["testid","id","aria","class","text","path"],fe=["light","dark","unknown"],ye=["react","vue","angular","svelte","nextjs","nuxt","unknown"],be=["target-location","screenshot","context-bundle","dom-snapshot","style-snapshot"],he=["inline","exported-file","url","none"];function m(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function C(e,t){return typeof e==="string"&&t.includes(e)}function x(e){return typeof e==="number"&&Number.isFinite(e)}function A(e){return x(e)&&e>0}function O(e){return Array.isArray(e)&&e.every((t)=>typeof t==="string")}function ee(e){return m(e)&&Object.values(e).every((t)=>typeof t==="string")}function d(e){return e===void 0||typeof e==="string"}function te(e){if(!m(e)||!x(e.x)||!x(e.y)||!A(e.width)||!A(e.height))return;return{x:e.x,y:e.y,width:e.width,height:e.height}}function _(e){if(!m(e)||!A(e.width)||!A(e.height))return;return{width:e.width,height:e.height}}function M(e){if(!m(e)||!x(e.x)||!x(e.y))return;return{x:e.x,y:e.y}}function Q(e){if(!m(e)||typeof e.fileName!=="string"||!A(e.lineNumber))return;if(e.columnNumber!==void 0&&(!x(e.columnNumber)||e.columnNumber<0))return;if(!d(e.componentName))return;return{fileName:e.fileName,lineNumber:e.lineNumber,...e.columnNumber===void 0?{}:{columnNumber:e.columnNumber},...e.componentName===void 0?{}:{componentName:e.componentName}}}function Ce(e){let t=te(e.boundingBox);if(typeof e.tagName!=="string"||!e.tagName||typeof e.cssSelector!=="string"||!e.cssSelector||typeof e.xpath!=="string"||!e.xpath||!ee(e.attributes)||!t||!O(e.domPath))return;if(!d(e.textContent)||e.breadcrumb!==void 0&&!O(e.breadcrumb))return;if(e.selectorStrategy!==void 0&&!C(e.selectorStrategy,me))return;if(!d(e.region))return;let n;if(e.accessibility!==void 0){if(!m(e.accessibility)||!d(e.accessibility.role)||!d(e.accessibility.name)||!d(e.accessibility.ariaLabel))return;n={...e.accessibility.role===void 0?{}:{role:e.accessibility.role},...e.accessibility.name===void 0?{}:{name:e.accessibility.name},...e.accessibility.ariaLabel===void 0?{}:{ariaLabel:e.accessibility.ariaLabel}}}let r=e.sourceLocation===void 0?void 0:Q(e.sourceLocation);if(e.sourceLocation!==void 0&&!r)return;let i;if(e.sourceStack!==void 0){if(!Array.isArray(e.sourceStack))return;let s=e.sourceStack.map(Q);if(s.some((o)=>!o))return;i=s.filter((o)=>Boolean(o))}return{kind:"element",tagName:e.tagName,cssSelector:e.cssSelector,xpath:e.xpath,...e.textContent===void 0?{}:{textContent:e.textContent},attributes:{...e.attributes},boundingBox:t,domPath:[...e.domPath],...n?{accessibility:n}:{},...e.selectorStrategy===void 0?{}:{selectorStrategy:e.selectorStrategy},...e.region===void 0?{}:{region:e.region},...e.breadcrumb===void 0?{}:{breadcrumb:[...e.breadcrumb]},...r?{sourceLocation:r}:{},...i?{sourceStack:i}:{}}}function xe(e){let t=te(e.rect),n=_(e.viewport),r=M(e.scroll);if(!t||t.width<8||t.height<8||!n||!r||!A(e.devicePixelRatio))return;if(e.breadcrumb!==void 0&&!O(e.breadcrumb))return;let i;if(e.topLevelElements!==void 0){if(!Array.isArray(e.topLevelElements))return;i=[];for(let o of e.topLevelElements){if(!m(o)||typeof o.tagName!=="string"||!o.tagName||!d(o.text)||!d(o.role))return;i.push({tagName:o.tagName,...o.text===void 0?{}:{text:o.text},...o.role===void 0?{}:{role:o.role}})}}let s=e.marks===void 0?void 0:J(e.marks);if(e.marks!==void 0&&!s)return;return{kind:"region",rect:t,viewport:n,scroll:r,devicePixelRatio:e.devicePixelRatio,...e.breadcrumb===void 0?{}:{breadcrumb:[...e.breadcrumb]},...i?{topLevelElements:i}:{},...s?.length?{marks:s}:{}}}function ke(e){if(!m(e))return{ok:!1,reason:"target is not an object",raw:e};if(e.kind==="region"){let t=xe(e);return t?{ok:!0,value:t}:{ok:!1,reason:"invalid region target",raw:e}}if(e.kind==="element"||e.kind===void 0){let t=Ce(e);return t?{ok:!0,value:t}:{ok:!1,reason:"invalid element target",raw:e}}return{ok:!1,reason:`unknown target kind: ${String(e.kind)}`,raw:e}}function Re(e){if(!m(e))return;let t=_(e.viewport),n=M(e.scroll);if(!t||!n||!A(e.devicePixelRatio)||!m(e.center)||!x(e.center.x)||!x(e.center.y)||typeof e.visible!=="boolean"||!d(e.positioning))return;return{viewport:t,scroll:n,devicePixelRatio:e.devicePixelRatio,center:{x:e.center.x,y:e.center.y},visible:e.visible,...e.positioning===void 0?{}:{positioning:e.positioning}}}function ne(e){if(!m(e))return;let{url:t,origin:n,path:r,title:i,capturedAt:s,query:o,hash:a,referrer:l,language:u,userAgent:g,uiState:f}=e,c=_(e.viewport),y=M(e.scroll);if(!c||!m(e.viewport)||!A(e.viewport.devicePixelRatio)||!y)return;if(typeof t!=="string"||!t||typeof n!=="string"||!n||typeof r!=="string"||!r||typeof i!=="string"||typeof s!=="string"||!s)return;if(!d(o)||!d(a)||!d(l)||!d(u)||!d(g)||!d(f))return;if(e.theme!==void 0&&!C(e.theme,fe))return;if(e.framework!==void 0&&!C(e.framework,ye))return;return{url:t,origin:n,path:r,title:i,viewport:{...c,devicePixelRatio:e.viewport.devicePixelRatio},scroll:y,capturedAt:s,...o===void 0?{}:{query:o},...a===void 0?{}:{hash:a},...l===void 0?{}:{referrer:l},...e.theme===void 0?{}:{theme:e.theme},...e.framework===void 0?{}:{framework:e.framework},...u===void 0?{}:{language:u},...g===void 0?{}:{userAgent:g},...f===void 0?{}:{uiState:f}}}function Ae(e){if(e===void 0)return[];if(!Array.isArray(e))return;let t=[];for(let n of e){if(!m(n)||!C(n.kind,["style","text"])||typeof n.label!=="string"||!d(n.property)||typeof n.before!=="string"||typeof n.after!=="string")return;t.push({kind:n.kind,label:n.label,before:n.before,after:n.after,...n.property===void 0?{}:{property:n.property}})}return t}function Ie(e){if(!Array.isArray(e))return;let t=[];for(let n of e){if(!m(n)||!C(n.kind,be)||!C(n.availability,he)||typeof n.label!=="string"||!n.label||!d(n.annotationId)||!d(n.reference))return;if(n.availability!=="none"&&!n.reference?.trim())return;t.push({kind:n.kind,availability:n.availability,label:n.label,...n.annotationId===void 0?{}:{annotationId:n.annotationId},...n.reference===void 0?{}:{reference:n.reference}})}return t}function F(e){if(!m(e))return{ok:!1,reason:"annotation is not an object",raw:e};let{id:t,pageUrl:n,comment:r,createdAt:i,updatedAt:s}=e;if(!C(e.status,pe))return{ok:!1,reason:"invalid status",raw:e};if(!C(e.type,ge))return{ok:!1,reason:"invalid type",raw:e};if(!C(e.priority,X))return{ok:!1,reason:"invalid priority",raw:e};if(typeof t!=="string"||!t)return{ok:!1,reason:"invalid id",raw:e};if(typeof n!=="string"||!n)return{ok:!1,reason:"invalid pageUrl",raw:e};if(typeof r!=="string"||!r)return{ok:!1,reason:"invalid comment",raw:e};if(typeof i!=="string"||!i)return{ok:!1,reason:"invalid createdAt",raw:e};if(typeof s!=="string"||!s)return{ok:!1,reason:"invalid updatedAt",raw:e};if(!d(e.expectedResult)||!d(e.preserve)||!d(e.screenshot))return{ok:!1,reason:"invalid optional annotation text",raw:e};if(!ee(e.styleSummary))return{ok:!1,reason:"invalid styleSummary",raw:e};let o=Re(e.geometry);if(!o)return{ok:!1,reason:"invalid geometry",raw:e};let a=ne(e.pageContext);if(!a)return{ok:!1,reason:"invalid pageContext",raw:e};let l=Ae(e.edits);if(!l)return{ok:!1,reason:"invalid edits",raw:e};let u=ke(e.target);if(!u.ok)return u;return{ok:!0,value:{id:t,pageUrl:n,status:e.status,type:e.type,priority:e.priority,comment:r,target:u.value,styleSummary:{...e.styleSummary},geometry:o,pageContext:a,createdAt:i,updatedAt:s,...e.expectedResult===void 0?{}:{expectedResult:e.expectedResult},...e.preserve===void 0?{}:{preserve:e.preserve},...e.screenshot===void 0?{}:{screenshot:e.screenshot},...l.length?{edits:l}:{}}}}function Pe(e){let t=[],n=[];return e.forEach((r,i)=>{let s=F(r);if(s.ok)t.push(s.value);else n.push({index:i,reason:s.reason,raw:s.raw})}),{annotations:D(t),failures:n}}function Rr(e){if(!m(e)||!Array.isArray(e.annotations))return{ok:!1,reason:"context annotations are missing",raw:e};if(e.version!=="1.0"&&e.version!=="2.0")return{ok:!1,reason:`unsupported context version: ${String(e.version)}`,raw:e};let t=Pe(e.annotations),[n]=t.failures;if(n)return{ok:!1,reason:`invalid annotation at index ${n.index}`,raw:e};let r=e.version==="2.0";if(r){if(e.schema!=="uibot/web-annotation-context"||typeof e.contextId!=="string"||!e.contextId||typeof e.createdAt!=="string"||!e.createdAt||!C(e.scope,["active","all"])||!m(e.summary)||!x(e.summary.totalAnnotations)||e.summary.totalAnnotations<0||!x(e.summary.activeAnnotations)||e.summary.activeAnnotations<0||!x(e.summary.includedAnnotations)||e.summary.includedAnnotations<0||e.summary.topPriority!==void 0&&!C(e.summary.topPriority,X))return{ok:!1,reason:"invalid v2 context metadata",raw:e}}let i=r?Ie(e.evidence):[];if(!i)return{ok:!1,reason:"invalid context evidence",raw:e};let s=r?e.scope:"all",o=t.annotations,a=s==="active"?o.filter(T):o,l=e.page===void 0?void 0:ne(e.page);if(e.page!==void 0&&!l)return{ok:!1,reason:"invalid context page",raw:e};return{ok:!0,value:{schema:"uibot/web-annotation-context",version:"2.0",contextId:typeof e.contextId==="string"?e.contextId:`ctx_${Date.now()}`,createdAt:typeof e.createdAt==="string"?e.createdAt:new Date().toISOString(),scope:s,...l?{page:l}:{},summary:{totalAnnotations:o.length,activeAnnotations:o.filter(T).length,includedAnnotations:a.length,topPriority:D(a)[0]?.priority},evidence:i,annotations:a}}}function Se(e){return typeof e==="string"&&e.length<=q&&/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(e)}function re(e){if(!Array.isArray(e)||e.length>j||!v({items:e}))return null;let t=[],n=0,r=new Set;for(let i of e){let s=F(i);if(!s.ok)return null;let o=s.value;if(!/^[a-zA-Z0-9_-]{1,100}$/.test(o.id)||r.has(o.id)||!o.comment.trim()||o.comment.length>4000)return null;if(r.add(o.id),o.target.kind==="element"&&(o.target.cssSelector.length>2000||o.target.xpath.length>2000||(o.target.textContent?.length??0)>1000))return null;if(o.screenshot!==void 0&&(!Se(o.screenshot)||++n>U))return null;if((o.edits?.length??0)>20||o.edits?.some((a)=>a.before.length>4000||a.after.length>4000))return null;t.push(o)}try{if(t.length)W(t.map(K))}catch{return null}return t}function Nr(e){let t=e.ownerWindow??window,n=e.nonce??crypto.randomUUID(),r={enabled:!1,locked:!1,locale:"zh",items:[],theme:I(e.theme)},i=!1,s=!1,o=!1,a,l=(p)=>{if(o===!p)return;o=!p,e.onResponsiveChange?.(p)},u=()=>{if(a!==void 0)t.clearTimeout(a);if(a=void 0,!r.enabled||s||i){if(!r.enabled||s)l(!0);return}a=t.setTimeout(()=>{if(a=void 0,!s&&r.enabled&&!i)l(!1)},e.handshakeTimeoutMs??2500)},g=(p)=>{if(!i)e.iframe.contentWindow?.postMessage({...p,source:B,nonce:n},"*")},f=()=>g({action:"sync",...r}),c=(p)=>{if(i||p.source!==e.iframe.contentWindow||!v(p.data))return;let k=p.data;if(k.source!==V||k.nonce!==n)return;if(k.action==="ready"){s=!0,u();return}if(k.action==="closed"){e.onClose();return}if(k.action!=="snapshot"||r.locked||!r.enabled)return;let L=re(k.items);if(L)e.onChange(L)};t.addEventListener("message",c);let y=()=>{if(s=!1,r.enabled||r.items.length)f();u()};e.iframe.addEventListener("load",y);let S=t.setInterval(()=>{if(!s&&r.enabled)f()},400);return{update(p){let k=r.enabled;if(r={...r,...p,theme:Object.hasOwn(p,"theme")?I(p.theme):r.theme??{}},f(),k!==r.enabled)u()},reveal(p){if(r.items.some((k)=>k.id===p))g({action:"reveal",id:p})},dispose(){if(i)return;if(g({action:"sync",enabled:!1,locked:!0,items:[],locale:r.locale}),i=!0,t.clearInterval(S),a!==void 0)t.clearTimeout(a);t.removeEventListener("message",c),e.iframe.removeEventListener("load",y)}}}var ve={primaryContrast:["--primary-foreground","#fafafa"],surface:["--card","#ffffff"],foreground:["--card-foreground","#18181b"],popover:["--popover","#ffffff"],popoverContrast:["--popover-foreground","#18181b"],border:["--border","#e4e4e7"],muted:["--muted-foreground","#71717a"],field:["--muted","#f4f4f5"],hover:["--accent","#f4f4f5"],focus:["--ring","#a1a1aa"],danger:["--destructive","#dc2626"]},N={accent:"#18181b",contrast:"#fafafa",selected:"#3f3f46",outline:"rgba(255, 255, 255, 0.6)"};function we(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(i)=>{let[s,o]=ve[i],a=t?.getPropertyValue(s).trim()??"";return I({"--pa-accent":a})["--pa-accent"]??o},r=N.accent;return I({"--pa-accent":r,"--pa-accent-contrast":N.contrast,"--pa-accent-soft":`color-mix(in srgb, ${r} 10%, transparent)`,"--pa-accent-halo":`color-mix(in srgb, ${r} 45%, transparent)`,"--pa-surface":n("surface"),"--pa-surface-contrast":n("foreground"),"--pa-popover":n("popover"),"--pa-popover-contrast":n("popoverContrast"),"--pa-border":n("border"),"--pa-muted":n("muted"),"--pa-field":n("field"),"--pa-hover":n("hover"),"--pa-selected":N.selected,"--pa-focus":n("focus"),"--pa-outline":N.outline,"--pa-shadow":"#00000033","--pa-checker":n("muted"),"--pa-danger":n("danger"),"--pa-danger-contrast":n("primaryContrast"),"--pa-success":"#15803d","--pa-success-contrast":"#ffffff","--pa-color-default":n("foreground")})}function Mr(e,t){let n=e.ownerDocument.defaultView;if(!n)return()=>{};let r=()=>t(we(e)),i=new n.MutationObserver(r);i.observe(e,{attributes:!0,attributeFilter:["class","style"]});let s=n.matchMedia("(prefers-color-scheme: dark)");return s.addEventListener("change",r),()=>{i.disconnect(),s.removeEventListener("change",r)}}export{B as ANNOTATION_HOST_SOURCE,j as ANNOTATION_MAX_ITEMS,Ee as ANNOTATION_MAX_MESSAGE_BYTES,U as ANNOTATION_MAX_SCREENSHOTS,V as ANNOTATION_PAGE_SOURCE,q as ANNOTATION_SCREENSHOT_MAX_BYTES,De as ANNOTATION_THEME_MAX_BYTES,z as ANNOTATION_THEME_TOKENS,Ne as applyAnnotationTheme,v as boundedMessage,Nr as createAnnotationController,w as isAnnotationThemeColor,Mr as observeStudioAnnotationTheme,re as parseAnnotationItems,we as resolveStudioAnnotationTheme,Se as validScreenshot,I as validateAnnotationTheme};
|