@uibot/page-annotation 0.20.0 → 0.22.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/host.js +1 -1
- package/dist/runtime.js +5 -5
- 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 B="uibot.annotation.host.v1",V="uibot.annotation.page.v1",Te=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"],Ne=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 Oe(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"]},vt=Array.from(new Set(Object.values(se).flat()));var Tt=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"],Ot=[...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 lr(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 cr(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"}],ur=12,pr=48,gr=4,mr=16;function G(e){let t=Math.round(e/4)*4;return Math.min(48,Math.max(12,t))}function ce(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 de=new Set(Y.map((e)=>e.value));function ue(e){return de.has(e)}function fr(){return Y[0].value}function h(e){return typeof e==="number"&&Number.isFinite(e)}function pe(e){if(!e||typeof e!=="object"||Array.isArray(e))return null;let t=e;if(typeof t.color!=="string"||!ue(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=pe(n);if(!r)return;t.push(r)}return t}function yr(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 br(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=ce(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 hr(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 Cr(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 kr(e){return D(e.filter(T))}var ge=["open","processing","done","verified","ignored"],me=["bug","style","copywriting","feature","interaction","data","other"],X=["low","medium","high","blocker"],fe=["testid","id","aria","class","text","path"],ye=["light","dark","unknown"],be=["react","vue","angular","svelte","nextjs","nuxt","unknown"],he=["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 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 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||!O(e.domPath))return;if(!d(e.textContent)||e.breadcrumb!==void 0&&!O(e.breadcrumb))return;if(e.selectorStrategy!==void 0&&!C(e.selectorStrategy,fe))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 ke(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 Re(e){if(!m(e))return{ok:!1,reason:"target is not an object",raw:e};if(e.kind==="region"){let t=ke(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 Ae(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,ye))return;if(e.framework!==void 0&&!C(e.framework,be))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 Ie(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 Pe(e){if(!Array.isArray(e))return;let t=[];for(let n of e){if(!m(n)||!C(n.kind,he)||!C(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:s}=e;if(!C(e.status,ge))return{ok:!1,reason:"invalid status",raw:e};if(!C(e.type,me))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=Ae(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=Ie(e.edits);if(!l)return{ok:!1,reason:"invalid edits",raw:e};let u=Re(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 Se(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 Pr(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=Se(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?Pe(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 ve(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&&(!ve(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 Mr(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 we={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 Ee(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(i)=>{let[s,o]=we[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 Br(e,t){let n=e.ownerDocument.defaultView;if(!n)return()=>{};let r=()=>t(Ee(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,Te as ANNOTATION_MAX_MESSAGE_BYTES,U as ANNOTATION_MAX_SCREENSHOTS,V as ANNOTATION_PAGE_SOURCE,q as ANNOTATION_SCREENSHOT_MAX_BYTES,Ne as ANNOTATION_THEME_MAX_BYTES,z as ANNOTATION_THEME_TOKENS,Oe as applyAnnotationTheme,v as boundedMessage,Mr as createAnnotationController,w as isAnnotationThemeColor,Br as observeStudioAnnotationTheme,re as parseAnnotationItems,Ee as resolveStudioAnnotationTheme,ve as validScreenshot,I as validateAnnotationTheme};
|
|
2
|
+
var L="uibot.annotation.host.v1",V="uibot.annotation.page.v1",De=1048576,j=20,U=262144,q=2;function w(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 H=["--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"],Ne=8192;function v(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(),c=a.includes(",");if(c&&(!/^(rgb|rgba|hsl|hsla)$/.test(o)||a.includes("/")))return!1;let u=a.split("/");if(u.length>2)return!1;let g=c?a.split(",").map((y)=>y.trim()):(u[0]??"").trim().split(/\s+/),m=c?g[3]:u[1]?.trim();if(g.length!==3&&!(c&&g.length===4))return!1;let l=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?%?$/i;if(m!==void 0&&!l.test(m)&&!(m==="none"&&!c))return!1;return g.slice(0,3).every((y,P)=>{if(y==="none")return!c;let p=/^(hsl|hsla|hwb)$/.test(o)?P===0:/^(lch|oklch)$/.test(o)&&P===2;return l.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 v(`rgb(${i[2]})`);let s=t.match(/^color-mix\(in srgb, (.+) (\d+(?:\.\d+)?)%, (.+)\)$/i);return!!s&&Number(s[2])<=100&&v(s[1])&&v(s[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 H){let r=Object.hasOwn(e,n)?e[n]:void 0;if(v(r))t[n]=r.trim()}return t}function _e(e,t){let n=R(t);for(let r of H){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"]},vt=Array.from(new Set(Object.values(ae).flat()));var Dt=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 ce=["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"],_t=[...ce,"radius","font-display","font-body","font-mono"];var A={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 S(e,t){if(Object.keys(e).some((n)=>!t.includes(n)))throw Error("Unknown annotation field")}function h(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 z(e){let t=E(e);S(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 K(e){if(!Array.isArray(e)||!e.length||e.length>A.count)throw Error("Expected 1 to 20 annotations");if(new TextEncoder().encode(JSON.stringify(e)).length>A.messageBytes)throw Error("Annotations exceed the message budget");let t=0,n=new Set;return e.map((r)=>{let i=E(r);S(i,["id","comment","target","type","priority","edits","screenshot"]);let s=h(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=h(i.comment,A.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),c;if(a.kind==="element"){S(a,["kind","cssSelector","xpath","tagName","textContent","boundingBox","uibotId"]);let m=h(a.tagName,80);if(!/^[a-zA-Z][a-zA-Z0-9:_-]*$/.test(m))throw Error("Invalid annotation tag");let l=a.uibotId===void 0?void 0:h(a.uibotId,200);if(l!==void 0&&!/^[\w:.-]+$/.test(l))throw Error("Invalid annotation element ID");c={kind:"element",cssSelector:h(a.cssSelector,A.selector),xpath:h(a.xpath,A.selector,!0),tagName:m,boundingBox:z(a.boundingBox),...a.textContent===void 0?{}:{textContent:h(a.textContent,1000,!0)},...l===void 0?{}:{uibotId:l}}}else if(a.kind==="region")S(a,["kind","rect"]),c={kind:"region",rect:z(a.rect)};else throw Error("Invalid annotation target");let u;if(i.edits!==void 0){if(!Array.isArray(i.edits)||i.edits.length>A.edits)throw Error("Invalid annotation edits");u=i.edits.map((m)=>{let l=E(m);if(S(l,["kind","label","property","before","after"]),l.kind!=="style"&&l.kind!=="text")throw Error("Invalid annotation edit kind");let y=l.property===void 0?void 0:h(l.property,100);if(y!==void 0&&!/^[-a-zA-Z][\w-]*$/.test(y))throw Error("Invalid annotation style property");return{kind:l.kind,label:h(l.label,200),before:h(l.before,4000,!0),after:h(l.after,4000,!0),...y===void 0?{}:{property:y}}})}let g;if(i.screenshot!==void 0){if(g=h(i.screenshot,A.screenshotBytes),!/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(g)||++t>A.screenshots)throw Error("Invalid annotation screenshot")}return{id:s,comment:o,type:i.type,priority:i.priority,target:c,...u?{edits:u}:{},...g?{screenshot:g}:{}}})}function Sr(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 Pr(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 Y(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 G=[{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"}],vr=12,Er=48,Tr=4,Dr=16;function Z(e){let t=Math.round(e/4)*4;return Math.min(48,Math.max(12,t))}function de(e,t){let n=Z(t),r=Math.max(1,[...e].length);return{width:Math.max(n,r*n),height:Math.ceil(n*1.35)}}var ue=new Set(G.map((e)=>e.value));function pe(e){return ue.has(e)}function Or(){return G[0].value}function b(e){return typeof e==="number"&&Number.isFinite(e)}function ge(e){if(!e||typeof e!=="object"||Array.isArray(e))return null;let t=e;if(typeof t.color!=="string"||!pe(t.color))return null;if(t.kind==="rect"){if(!b(t.x)||!b(t.y)||!b(t.width)||!b(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(!b(t.x1)||!b(t.y1)||!b(t.x2)||!b(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(!b(t.x)||!b(t.y)||typeof t.text!=="string")return null;let n=t.text.trim();if(!n)return null;let r=t.fontSize===void 0?16:b(t.fontSize)?Z(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=ge(n);if(!r)return;t.push(r)}return t}function Nr(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 _r(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=de(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 Mr(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 Fr(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 X={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)=>X[t.priority]-X[n.priority]||t.createdAt.localeCompare(n.createdAt))}function Lr(e){return D(e.filter(T))}var fe=["open","processing","done","verified","ignored"],me=["bug","style","copywriting","feature","interaction","data","other"],ee=["low","medium","high","blocker"],ye=["testid","id","aria","class","text","path"],he=["light","dark","unknown"],be=["react","vue","angular","svelte","nextjs","nuxt","unknown"],Ce=["target-location","screenshot","context-bundle","dom-snapshot","style-snapshot"],xe=["inline","exported-file","url","none"];function f(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 I(e){return x(e)&&e>0}function N(e){return Array.isArray(e)&&e.every((t)=>typeof t==="string")}function te(e){return f(e)&&Object.values(e).every((t)=>typeof t==="string")}function d(e){return e===void 0||typeof e==="string"}function ne(e){if(!f(e)||!x(e.x)||!x(e.y)||!I(e.width)||!I(e.height))return;return{x:e.x,y:e.y,width:e.width,height:e.height}}function _(e){if(!f(e)||!I(e.width)||!I(e.height))return;return{width:e.width,height:e.height}}function M(e){if(!f(e)||!x(e.x)||!x(e.y))return;return{x:e.x,y:e.y}}function Q(e){if(!f(e)||typeof e.fileName!=="string"||!I(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 ke(e){let t=ne(e.boundingBox);if(typeof e.tagName!=="string"||!e.tagName||typeof e.cssSelector!=="string"||!e.cssSelector||typeof e.xpath!=="string"||!e.xpath||!te(e.attributes)||!t||!N(e.domPath))return;if(!d(e.textContent)||e.breadcrumb!==void 0&&!N(e.breadcrumb))return;if(e.selectorStrategy!==void 0&&!C(e.selectorStrategy,ye))return;if(!d(e.region))return;let n;if(e.accessibility!==void 0){if(!f(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 Ae(e){let t=ne(e.rect),n=_(e.viewport),r=M(e.scroll);if(!t||t.width<8||t.height<8||!n||!r||!I(e.devicePixelRatio))return;if(e.breadcrumb!==void 0&&!N(e.breadcrumb))return;let i;if(e.topLevelElements!==void 0){if(!Array.isArray(e.topLevelElements))return;i=[];for(let o of e.topLevelElements){if(!f(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 Ie(e){if(!f(e))return{ok:!1,reason:"target is not an object",raw:e};if(e.kind==="region"){let t=Ae(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=ke(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(!f(e))return;let t=_(e.viewport),n=M(e.scroll);if(!t||!n||!I(e.devicePixelRatio)||!f(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 re(e){if(!f(e))return;let{url:t,origin:n,path:r,title:i,capturedAt:s,query:o,hash:a,referrer:c,language:u,userAgent:g,uiState:m}=e,l=_(e.viewport),y=M(e.scroll);if(!l||!f(e.viewport)||!I(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(c)||!d(u)||!d(g)||!d(m))return;if(e.theme!==void 0&&!C(e.theme,he))return;if(e.framework!==void 0&&!C(e.framework,be))return;return{url:t,origin:n,path:r,title:i,viewport:{...l,devicePixelRatio:e.viewport.devicePixelRatio},scroll:y,capturedAt:s,...o===void 0?{}:{query:o},...a===void 0?{}:{hash:a},...c===void 0?{}:{referrer:c},...e.theme===void 0?{}:{theme:e.theme},...e.framework===void 0?{}:{framework:e.framework},...u===void 0?{}:{language:u},...g===void 0?{}:{userAgent:g},...m===void 0?{}:{uiState:m}}}function Se(e){if(e===void 0)return[];if(!Array.isArray(e))return;let t=[];for(let n of e){if(!f(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 Pe(e){if(!Array.isArray(e))return;let t=[];for(let n of e){if(!f(n)||!C(n.kind,Ce)||!C(n.availability,xe)||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(!f(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,fe))return{ok:!1,reason:"invalid status",raw:e};if(!C(e.type,me))return{ok:!1,reason:"invalid type",raw:e};if(!C(e.priority,ee))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(!te(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=re(e.pageContext);if(!a)return{ok:!1,reason:"invalid pageContext",raw:e};let c=Se(e.edits);if(!c)return{ok:!1,reason:"invalid edits",raw:e};let u=Ie(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},...c.length?{edits:c}:{}}}}function we(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 qr(e){if(!f(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=we(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"])||!f(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,ee))return{ok:!1,reason:"invalid v2 context metadata",raw:e}}let i=r?Pe(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,c=e.page===void 0?void 0:re(e.page);if(e.page!==void 0&&!c)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,...c?{page:c}:{},summary:{totalAnnotations:o.length,activeAnnotations:o.filter(T).length,includedAnnotations:a.length,topPriority:D(a)[0]?.priority},evidence:i,annotations:a}}}function ve(e){return typeof e==="string"&&e.length<=U&&/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(e)}function oe(e){if(!Array.isArray(e)||e.length>j||!w({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&&(!ve(o.screenshot)||++n>q))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)K(t.map(Y))}catch{return null}return t}function Xr(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,s=!1,o=!1,a,c=(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)c(!0);return}a=t.setTimeout(()=>{if(a=void 0,!s&&r.enabled&&!i)c(!1)},e.handshakeTimeoutMs??2500)},g=(p)=>{if(!i)e.iframe.contentWindow?.postMessage({...p,source:L,nonce:n},"*")},m=()=>g({action:"sync",...r}),l=(p)=>{if(i||p.source!==e.iframe.contentWindow||!w(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 B=oe(k.items);if(B)e.onChange(B)};t.addEventListener("message",l);let y=()=>{if(s=!1,r.enabled||r.items.length)m();u()};e.iframe.addEventListener("load",y);let P=t.setInterval(()=>{if(!s&&r.enabled)m()},400);return{update(p){let k=r.enabled;if(r={...r,...p,theme:Object.hasOwn(p,"theme")?R(p.theme):r.theme??{}},m(),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(P),a!==void 0)t.clearTimeout(a);t.removeEventListener("message",l),e.iframe.removeEventListener("load",y)}}}var Ee={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 Te(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(i)=>{let[s,o]=Ee[i],a=t?.getPropertyValue(s).trim()??"";return R({"--pa-accent":a})["--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 to(e,t){let n=e.ownerDocument.defaultView;if(!n)return()=>{};let r=()=>t(Te(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{L as ANNOTATION_HOST_SOURCE,j as ANNOTATION_MAX_ITEMS,De as ANNOTATION_MAX_MESSAGE_BYTES,q as ANNOTATION_MAX_SCREENSHOTS,V as ANNOTATION_PAGE_SOURCE,U as ANNOTATION_SCREENSHOT_MAX_BYTES,Ne as ANNOTATION_THEME_MAX_BYTES,H as ANNOTATION_THEME_TOKENS,_e as applyAnnotationTheme,w as boundedMessage,Xr as createAnnotationController,v as isAnnotationThemeColor,to as observeStudioAnnotationTheme,oe as parseAnnotationItems,Te as resolveStudioAnnotationTheme,ve as validScreenshot,R as validateAnnotationTheme};
|