From eb68791ac504576930545edf6e35083012d6fde8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E9=98=BF=E6=B1=9F=28Relakkes?= =?UTF-8?q?=29?= Date: Mon, 1 Jun 2026 01:07:08 +0800 Subject: [PATCH] fix: send preview selections as annotated chat turns Element selection from the local preview should preserve the visual target the user picked and send the confirmed request directly to chat. The screenshot now captures the visible viewport before drawing the marker, and the selection event sends a model-facing prompt while the chat UI shows only the annotated image and compact element label. Constraint: No issue number was provided for this task. Constraint: Keep the preview-agent protocol shape unchanged. Rejected: Prefill the composer with the selection note | it keeps the old extra confirmation step and exposes implementation text in the input. Rejected: Full-document annotation coordinates | body-relative captures drift from the viewport selection users see. Confidence: high Scope-risk: moderate Directive: Do not route confirmed preview selections back through composer prefill without rechecking the Codex-style direct-send flow. Tested: cd desktop && bun run test --run src/preview-agent/screenshot.test.ts src/lib/previewEvents.test.ts src/lib/selectionComposer.test.ts src/components/chat/AttachmentGallery.test.tsx src/stores/chatStore.test.ts Tested: cd desktop && bun run lint Tested: cd desktop && bun run build:preview-agent Tested: bun run check:desktop Tested: git diff --check Not-tested: Real Tauri webview click-through smoke; in-app Browser automation timed out while local Vite HTTP smoke returned 200. --- desktop/src-tauri/resources/preview-agent.js | 2 +- .../src/components/browser/BrowserSurface.tsx | 13 +++- .../chat/AttachmentGallery.test.tsx | 21 +++++ .../src/components/chat/AttachmentGallery.tsx | 23 +++++- desktop/src/lib/previewEvents.test.ts | 42 ++++++++-- desktop/src/lib/previewEvents.ts | 22 ++++-- desktop/src/lib/selectionComposer.test.ts | 24 +++++- desktop/src/lib/selectionComposer.ts | 39 ++++++++++ desktop/src/preview-agent/screenshot.test.ts | 46 ++++++++++- desktop/src/preview-agent/screenshot.ts | 20 ++++- desktop/src/stores/chatStore.test.ts | 76 +++++++++++++++++++ desktop/src/stores/chatStore.ts | 13 ++-- 12 files changed, 310 insertions(+), 31 deletions(-) diff --git a/desktop/src-tauri/resources/preview-agent.js b/desktop/src-tauri/resources/preview-agent.js index 8fd07731..8ff56838 100644 --- a/desktop/src-tauri/resources/preview-agent.js +++ b/desktop/src-tauri/resources/preview-agent.js @@ -19,4 +19,4 @@ content: "" !important; display: none !important; }`,F5=function(M){z5(M,"."+Y6+K5+XQ+` - .`+X6+U5+XQ)},z5=function(M,Q){var q=M.ownerDocument;if(q){var Z=q.createElement("style");Z.textContent=Q,M.appendChild(Z)}},VQ=function(){function M(){}return M.getOrigin=function(Q){var q=M._link;if(!q)return"about:blank";return q.href=Q,q.href=q.href,q.protocol+q.hostname+q.port},M.isSameOrigin=function(Q){return M.getOrigin(Q)===M._origin},M.setContext=function(Q){M._link=Q.document.createElement("a"),M._origin=M.getOrigin(Q.location.href)},M._origin="about:blank",M}(),D5=function(){function M(Q,q){this.context=Q,this._options=q,this._cache={}}return M.prototype.addImage=function(Q){var q=Promise.resolve();if(this.has(Q))return q;if(G6(Q)||N5(Q))return(this._cache[Q]=this.loadImage(Q)).catch(function(){}),q;return q},M.prototype.match=function(Q){return this._cache[Q]},M.prototype.loadImage=function(Q){return W(this,void 0,void 0,function(){var q,Z,J,j,Y=this;return R(this,function(V){switch(V.label){case 0:if(q=VQ.isSameOrigin(Q),Z=!V6(Q)&&this._options.useCORS===!0&&n.SUPPORT_CORS_IMAGES&&!q,J=!V6(Q)&&!q&&!G6(Q)&&typeof this._options.proxy==="string"&&n.SUPPORT_CORS_XHR&&!Z,!q&&this._options.allowTaint===!1&&!V6(Q)&&!G6(Q)&&!J&&!Z)return[2];if(j=Q,!J)return[3,2];return[4,this.proxy(j)];case 1:j=V.sent(),V.label=2;case 2:return this.context.logger.debug("Added image "+Q.substring(0,256)),[4,new Promise(function(X,G){var $=new Image;if($.onload=function(){return X($)},$.onerror=G,A5(j)||Z)$.crossOrigin="anonymous";if($.src=j,$.complete===!0)setTimeout(function(){return X($)},500);if(Y._options.imageTimeout>0)setTimeout(function(){return G("Timed out ("+Y._options.imageTimeout+"ms) loading image")},Y._options.imageTimeout)})];case 3:return[2,V.sent()]}})})},M.prototype.has=function(Q){return typeof this._cache[Q]<"u"},M.prototype.keys=function(){return Promise.resolve(Object.keys(this._cache))},M.prototype.proxy=function(Q){var q=this,Z=this._options.proxy;if(!Z)throw Error("No proxy defined");var J=Q.substring(0,256);return new Promise(function(j,Y){var V=n.SUPPORT_RESPONSE_TYPE?"blob":"text",X=new XMLHttpRequest;X.onload=function(){if(X.status===200)if(V==="text")j(X.response);else{var H=new FileReader;H.addEventListener("load",function(){return j(H.result)},!1),H.addEventListener("error",function(F){return Y(F)},!1),H.readAsDataURL(X.response)}else Y("Failed to proxy resource "+J+" with status code "+X.status)},X.onerror=Y;var G=Z.indexOf("?")>-1?"&":"?";if(X.open("GET",""+Z+G+"url="+encodeURIComponent(Q)+"&responseType="+V),V!=="text"&&X instanceof XMLHttpRequest)X.responseType=V;if(q._options.imageTimeout){var $=q._options.imageTimeout;X.timeout=$,X.ontimeout=function(){return Y("Timed out ("+$+"ms) proxying "+J)}}X.send()})},M}(),W5=/^data:image\/svg\+xml/i,O5=/^data:image\/.*;base64,/i,B5=/^data:image\/.*/i,N5=function(M){return n.SUPPORT_SVG_DRAWING||!L5(M)},V6=function(M){return B5.test(M)},A5=function(M){return O5.test(M)},G6=function(M){return M.substr(0,4)==="blob"},L5=function(M){return M.substr(-3).toLowerCase()==="svg"||W5.test(M)},B=function(){function M(Q,q){this.type=0,this.x=Q,this.y=q}return M.prototype.add=function(Q,q){return new M(this.x+Q,this.y+q)},M}(),Z0=function(M,Q,q){return new B(M.x+(Q.x-M.x)*q,M.y+(Q.y-M.y)*q)},$8=function(){function M(Q,q,Z,J){this.type=1,this.start=Q,this.startControl=q,this.endControl=Z,this.end=J}return M.prototype.subdivide=function(Q,q){var Z=Z0(this.start,this.startControl,Q),J=Z0(this.startControl,this.endControl,Q),j=Z0(this.endControl,this.end,Q),Y=Z0(Z,J,Q),V=Z0(J,j,Q),X=Z0(Y,V,Q);return q?new M(this.start,Z,Y,X):new M(X,V,j,this.end)},M.prototype.add=function(Q,q){return new M(this.start.add(Q,q),this.startControl.add(Q,q),this.endControl.add(Q,q),this.end.add(Q,q))},M.prototype.reverse=function(){return new M(this.end,this.endControl,this.startControl,this.start)},M}(),V1=function(M){return M.type===1},I5=function(){function M(Q){var{styles:q,bounds:Z}=Q,J=N0(q.borderTopLeftRadius,Z.width,Z.height),j=J[0],Y=J[1],V=N0(q.borderTopRightRadius,Z.width,Z.height),X=V[0],G=V[1],$=N0(q.borderBottomRightRadius,Z.width,Z.height),H=$[0],F=$[1],A=N0(q.borderBottomLeftRadius,Z.width,Z.height),D=A[0],O=A[1],S=[];S.push((j+X)/Z.width),S.push((D+H)/Z.width),S.push((Y+O)/Z.height),S.push((G+F)/Z.height);var T=Math.max.apply(Math,S);if(T>1)j/=T,Y/=T,X/=T,G/=T,H/=T,F/=T,D/=T,O/=T;var I=Z.width-X,x=Z.height-F,y=Z.width-H,w=Z.height-O,N=q.borderTopWidth,v=q.borderRightWidth,b=q.borderBottomWidth,E=q.borderLeftWidth,a=h(q.paddingTop,Q.bounds.width),M1=h(q.paddingRight,Q.bounds.width),j1=h(q.paddingBottom,Q.bounds.width),_=h(q.paddingLeft,Q.bounds.width);this.topLeftBorderDoubleOuterBox=j>0||Y>0?u(Z.left+E/3,Z.top+N/3,j-E/3,Y-N/3,g.TOP_LEFT):new B(Z.left+E/3,Z.top+N/3),this.topRightBorderDoubleOuterBox=j>0||Y>0?u(Z.left+I,Z.top+N/3,X-v/3,G-N/3,g.TOP_RIGHT):new B(Z.left+Z.width-v/3,Z.top+N/3),this.bottomRightBorderDoubleOuterBox=H>0||F>0?u(Z.left+y,Z.top+x,H-v/3,F-b/3,g.BOTTOM_RIGHT):new B(Z.left+Z.width-v/3,Z.top+Z.height-b/3),this.bottomLeftBorderDoubleOuterBox=D>0||O>0?u(Z.left+E/3,Z.top+w,D-E/3,O-b/3,g.BOTTOM_LEFT):new B(Z.left+E/3,Z.top+Z.height-b/3),this.topLeftBorderDoubleInnerBox=j>0||Y>0?u(Z.left+E*2/3,Z.top+N*2/3,j-E*2/3,Y-N*2/3,g.TOP_LEFT):new B(Z.left+E*2/3,Z.top+N*2/3),this.topRightBorderDoubleInnerBox=j>0||Y>0?u(Z.left+I,Z.top+N*2/3,X-v*2/3,G-N*2/3,g.TOP_RIGHT):new B(Z.left+Z.width-v*2/3,Z.top+N*2/3),this.bottomRightBorderDoubleInnerBox=H>0||F>0?u(Z.left+y,Z.top+x,H-v*2/3,F-b*2/3,g.BOTTOM_RIGHT):new B(Z.left+Z.width-v*2/3,Z.top+Z.height-b*2/3),this.bottomLeftBorderDoubleInnerBox=D>0||O>0?u(Z.left+E*2/3,Z.top+w,D-E*2/3,O-b*2/3,g.BOTTOM_LEFT):new B(Z.left+E*2/3,Z.top+Z.height-b*2/3),this.topLeftBorderStroke=j>0||Y>0?u(Z.left+E/2,Z.top+N/2,j-E/2,Y-N/2,g.TOP_LEFT):new B(Z.left+E/2,Z.top+N/2),this.topRightBorderStroke=j>0||Y>0?u(Z.left+I,Z.top+N/2,X-v/2,G-N/2,g.TOP_RIGHT):new B(Z.left+Z.width-v/2,Z.top+N/2),this.bottomRightBorderStroke=H>0||F>0?u(Z.left+y,Z.top+x,H-v/2,F-b/2,g.BOTTOM_RIGHT):new B(Z.left+Z.width-v/2,Z.top+Z.height-b/2),this.bottomLeftBorderStroke=D>0||O>0?u(Z.left+E/2,Z.top+w,D-E/2,O-b/2,g.BOTTOM_LEFT):new B(Z.left+E/2,Z.top+Z.height-b/2),this.topLeftBorderBox=j>0||Y>0?u(Z.left,Z.top,j,Y,g.TOP_LEFT):new B(Z.left,Z.top),this.topRightBorderBox=X>0||G>0?u(Z.left+I,Z.top,X,G,g.TOP_RIGHT):new B(Z.left+Z.width,Z.top),this.bottomRightBorderBox=H>0||F>0?u(Z.left+y,Z.top+x,H,F,g.BOTTOM_RIGHT):new B(Z.left+Z.width,Z.top+Z.height),this.bottomLeftBorderBox=D>0||O>0?u(Z.left,Z.top+w,D,O,g.BOTTOM_LEFT):new B(Z.left,Z.top+Z.height),this.topLeftPaddingBox=j>0||Y>0?u(Z.left+E,Z.top+N,Math.max(0,j-E),Math.max(0,Y-N),g.TOP_LEFT):new B(Z.left+E,Z.top+N),this.topRightPaddingBox=X>0||G>0?u(Z.left+Math.min(I,Z.width-v),Z.top+N,I>Z.width+v?0:Math.max(0,X-v),Math.max(0,G-N),g.TOP_RIGHT):new B(Z.left+Z.width-v,Z.top+N),this.bottomRightPaddingBox=H>0||F>0?u(Z.left+Math.min(y,Z.width-E),Z.top+Math.min(x,Z.height-b),Math.max(0,H-v),Math.max(0,F-b),g.BOTTOM_RIGHT):new B(Z.left+Z.width-v,Z.top+Z.height-b),this.bottomLeftPaddingBox=D>0||O>0?u(Z.left+E,Z.top+Math.min(w,Z.height-b),Math.max(0,D-E),Math.max(0,O-b),g.BOTTOM_LEFT):new B(Z.left+E,Z.top+Z.height-b),this.topLeftContentBox=j>0||Y>0?u(Z.left+E+_,Z.top+N+a,Math.max(0,j-(E+_)),Math.max(0,Y-(N+a)),g.TOP_LEFT):new B(Z.left+E+_,Z.top+N+a),this.topRightContentBox=X>0||G>0?u(Z.left+Math.min(I,Z.width+E+_),Z.top+N+a,I>Z.width+E+_?0:X-E+_,G-(N+a),g.TOP_RIGHT):new B(Z.left+Z.width-(v+M1),Z.top+N+a),this.bottomRightContentBox=H>0||F>0?u(Z.left+Math.min(y,Z.width-(E+_)),Z.top+Math.min(x,Z.height+N+a),Math.max(0,H-(v+M1)),F-(b+j1),g.BOTTOM_RIGHT):new B(Z.left+Z.width-(v+M1),Z.top+Z.height-(b+j1)),this.bottomLeftContentBox=D>0||O>0?u(Z.left+E+_,Z.top+w,Math.max(0,D-(E+_)),O-(b+j1),g.BOTTOM_LEFT):new B(Z.left+E+_,Z.top+Z.height-(b+j1))}return M}(),g;(function(M){M[M.TOP_LEFT=0]="TOP_LEFT",M[M.TOP_RIGHT=1]="TOP_RIGHT",M[M.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",M[M.BOTTOM_LEFT=3]="BOTTOM_LEFT"})(g||(g={}));var u=function(M,Q,q,Z,J){var j=4*((Math.sqrt(2)-1)/3),Y=q*j,V=Z*j,X=M+q,G=Q+Z;switch(J){case g.TOP_LEFT:return new $8(new B(M,G),new B(M,G-V),new B(X-Y,Q),new B(X,Q));case g.TOP_RIGHT:return new $8(new B(M,Q),new B(M+Y,Q),new B(X,G-V),new B(X,G));case g.BOTTOM_RIGHT:return new $8(new B(X,Q),new B(X,Q+V),new B(M+Y,G),new B(M,G));case g.BOTTOM_LEFT:default:return new $8(new B(X,G),new B(X-Y,G),new B(M,Q+V),new B(M,Q))}},H8=function(M){return[M.topLeftBorderBox,M.topRightBorderBox,M.bottomRightBorderBox,M.bottomLeftBorderBox]},R5=function(M){return[M.topLeftContentBox,M.topRightContentBox,M.bottomRightContentBox,M.bottomLeftContentBox]},K8=function(M){return[M.topLeftPaddingBox,M.topRightPaddingBox,M.bottomRightPaddingBox,M.bottomLeftPaddingBox]},T5=function(){function M(Q,q,Z){this.offsetX=Q,this.offsetY=q,this.matrix=Z,this.type=0,this.target=6}return M}(),U8=function(){function M(Q,q){this.path=Q,this.target=q,this.type=1}return M}(),w5=function(){function M(Q){this.opacity=Q,this.type=2,this.target=6}return M}(),E5=function(M){return M.type===0},GQ=function(M){return M.type===1},C5=function(M){return M.type===2},$Q=function(M,Q){if(M.length===Q.length)return M.some(function(q,Z){return q===Q[Z]});return!1},S5=function(M,Q,q,Z,J){return M.map(function(j,Y){switch(Y){case 0:return j.add(Q,q);case 1:return j.add(Q+Z,q);case 2:return j.add(Q+Z,q+J);case 3:return j.add(Q,q+J)}return j})},HQ=function(){function M(Q){this.element=Q,this.inlineLevel=[],this.nonInlineLevel=[],this.negativeZIndex=[],this.zeroOrAutoZIndexOrTransformedOrOpacity=[],this.positiveZIndex=[],this.nonPositionedFloats=[],this.nonPositionedInlineLevel=[]}return M}(),KQ=function(){function M(Q,q){if(this.container=Q,this.parent=q,this.effects=[],this.curves=new I5(this.container),this.container.styles.opacity<1)this.effects.push(new w5(this.container.styles.opacity));if(this.container.styles.transform!==null){var Z=this.container.bounds.left+this.container.styles.transformOrigin[0].number,J=this.container.bounds.top+this.container.styles.transformOrigin[1].number,j=this.container.styles.transform;this.effects.push(new T5(Z,J,j))}if(this.container.styles.overflowX!==0){var Y=H8(this.curves),V=K8(this.curves);if($Q(Y,V))this.effects.push(new U8(Y,6));else this.effects.push(new U8(Y,2)),this.effects.push(new U8(V,4))}}return M.prototype.getEffects=function(Q){var q=[2,3].indexOf(this.container.styles.position)===-1,Z=this.parent,J=this.effects.slice(0);while(Z){var j=Z.effects.filter(function(X){return!GQ(X)});if(q||Z.container.styles.position!==0||!Z.parent){if(J.unshift.apply(J,j),q=[2,3].indexOf(Z.container.styles.position)===-1,Z.container.styles.overflowX!==0){var Y=H8(Z.curves),V=K8(Z.curves);if(!$Q(Y,V))J.unshift(new U8(V,6))}}else J.unshift.apply(J,j);Z=Z.parent}return J.filter(function(X){return r(X.target,Q)})},M}(),$6=function(M,Q,q,Z){M.container.elements.forEach(function(J){var j=r(J.flags,4),Y=r(J.flags,2),V=new KQ(J,M);if(r(J.styles.display,2048))Z.push(V);var X=r(J.flags,8)?[]:Z;if(j||Y){var G=j||J.styles.isPositioned()?q:Q,$=new HQ(V);if(J.styles.isPositioned()||J.styles.opacity<1||J.styles.isTransformed()){var H=J.styles.zIndex.order;if(H<0){var F=0;G.negativeZIndex.some(function(D,O){if(H>D.element.container.styles.zIndex.order)return F=O,!1;else if(F>0)return!0;return!1}),G.negativeZIndex.splice(F,0,$)}else if(H>0){var A=0;G.positiveZIndex.some(function(D,O){if(H>=D.element.container.styles.zIndex.order)return A=O+1,!1;else if(A>0)return!0;return!1}),G.positiveZIndex.splice(A,0,$)}else G.zeroOrAutoZIndexOrTransformedOrOpacity.push($)}else if(J.styles.isFloating())G.nonPositionedFloats.push($);else G.nonPositionedInlineLevel.push($);$6(V,$,j?$:q,X)}else{if(J.styles.isInlineLevel())Q.inlineLevel.push(V);else Q.nonInlineLevel.push(V);$6(V,Q,q,X)}if(r(J.flags,8))UQ(J,X)})},UQ=function(M,Q){var q=M instanceof e8?M.start:1,Z=M instanceof e8?M.reversed:!1;for(var J=0;J"u")return M[0];return q},x5=function(M,Q,q,Z,J){var j=Q[0],Y=Q[1],V=q[0],X=q[1];switch(M){case 2:return[new B(Math.round(Z.left),Math.round(Z.top+Y)),new B(Math.round(Z.left+Z.width),Math.round(Z.top+Y)),new B(Math.round(Z.left+Z.width),Math.round(X+Z.top+Y)),new B(Math.round(Z.left),Math.round(X+Z.top+Y))];case 3:return[new B(Math.round(Z.left+j),Math.round(Z.top)),new B(Math.round(Z.left+j+V),Math.round(Z.top)),new B(Math.round(Z.left+j+V),Math.round(Z.height+Z.top)),new B(Math.round(Z.left+j),Math.round(Z.height+Z.top))];case 1:return[new B(Math.round(Z.left+j),Math.round(Z.top+Y)),new B(Math.round(Z.left+j+V),Math.round(Z.top+Y)),new B(Math.round(Z.left+j+V),Math.round(Z.top+Y+X)),new B(Math.round(Z.left+j),Math.round(Z.top+Y+X))];default:return[new B(Math.round(J.left),Math.round(J.top)),new B(Math.round(J.left+J.width),Math.round(J.top)),new B(Math.round(J.left+J.width),Math.round(J.height+J.top)),new B(Math.round(J.left),Math.round(J.height+J.top))]}},g5="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",DQ="Hidden Text",p5=function(){function M(Q){this._data={},this._document=Q}return M.prototype.parseMetrics=function(Q,q){var Z=this._document.createElement("div"),J=this._document.createElement("img"),j=this._document.createElement("span"),Y=this._document.body;Z.style.visibility="hidden",Z.style.fontFamily=Q,Z.style.fontSize=q,Z.style.margin="0",Z.style.padding="0",Z.style.whiteSpace="nowrap",Y.appendChild(Z),J.src=g5,J.width=1,J.height=1,J.style.margin="0",J.style.padding="0",J.style.verticalAlign="baseline",j.style.fontFamily=Q,j.style.fontSize=q,j.style.margin="0",j.style.padding="0",j.appendChild(this._document.createTextNode(DQ)),Z.appendChild(j),Z.appendChild(J);var V=J.offsetTop-j.offsetTop+2;Z.removeChild(j),Z.appendChild(this._document.createTextNode(DQ)),Z.style.lineHeight="normal",J.style.verticalAlign="super";var X=J.offsetTop-Z.offsetTop+2;return Y.removeChild(Z),{baseline:V,middle:X}},M.prototype.getMetrics=function(Q,q){var Z=Q+" "+q;if(typeof this._data[Z]>"u")this._data[Z]=this.parseMetrics(Q,q);return this._data[Z]},M}(),WQ=function(){function M(Q,q){this.context=Q,this.options=q}return M}(),_5=1e4,h5=function(M){K(Q,M);function Q(q,Z){var J=M.call(this,q,Z)||this;if(J._activeEffects=[],J.canvas=Z.canvas?Z.canvas:document.createElement("canvas"),J.ctx=J.canvas.getContext("2d"),!Z.canvas)J.canvas.width=Math.floor(Z.width*Z.scale),J.canvas.height=Math.floor(Z.height*Z.scale),J.canvas.style.width=Z.width+"px",J.canvas.style.height=Z.height+"px";return J.fontMetrics=new p5(document),J.ctx.scale(J.options.scale,J.options.scale),J.ctx.translate(-Z.x,-Z.y),J.ctx.textBaseline="bottom",J._activeEffects=[],J.context.logger.debug("Canvas renderer initialized ("+Z.width+"x"+Z.height+") with scale "+Z.scale),J}return Q.prototype.applyEffects=function(q){var Z=this;while(this._activeEffects.length)this.popEffect();q.forEach(function(J){return Z.applyEffect(J)})},Q.prototype.applyEffect=function(q){if(this.ctx.save(),C5(q))this.ctx.globalAlpha=q.opacity;if(E5(q))this.ctx.translate(q.offsetX,q.offsetY),this.ctx.transform(q.matrix[0],q.matrix[1],q.matrix[2],q.matrix[3],q.matrix[4],q.matrix[5]),this.ctx.translate(-q.offsetX,-q.offsetY);if(GQ(q))this.path(q.path),this.ctx.clip();this._activeEffects.push(q)},Q.prototype.popEffect=function(){this._activeEffects.pop(),this.ctx.restore()},Q.prototype.renderStack=function(q){return W(this,void 0,void 0,function(){var Z;return R(this,function(J){switch(J.label){case 0:if(Z=q.element.container.styles,!Z.isVisible())return[3,2];return[4,this.renderStackContent(q)];case 1:J.sent(),J.label=2;case 2:return[2]}})})},Q.prototype.renderNode=function(q){return W(this,void 0,void 0,function(){return R(this,function(Z){switch(Z.label){case 0:if(r(q.container.flags,16))debugger;if(!q.container.styles.isVisible())return[3,3];return[4,this.renderNodeBackgroundAndBorders(q)];case 1:return Z.sent(),[4,this.renderNodeContent(q)];case 2:Z.sent(),Z.label=3;case 3:return[2]}})})},Q.prototype.renderTextWithLetterSpacing=function(q,Z,J){var j=this;if(Z===0)this.ctx.fillText(q.text,q.bounds.left,q.bounds.top+J);else{var Y=t8(q.text);Y.reduce(function(V,X){return j.ctx.fillText(X,V,q.bounds.top+J),V+j.ctx.measureText(X).width},q.bounds.left)}},Q.prototype.createFontStyle=function(q){var Z=q.fontVariant.filter(function(Y){return Y==="normal"||Y==="small-caps"}).join(""),J=s5(q.fontFamily).join(", "),j=B0(q.fontSize)?""+q.fontSize.number+q.fontSize.unit:q.fontSize.number+"px";return[[q.fontStyle,Z,q.fontWeight,j,J].join(" "),J,j]},Q.prototype.renderTextNode=function(q,Z){return W(this,void 0,void 0,function(){var J,j,Y,V,X,G,$,H,F=this;return R(this,function(A){return J=this.createFontStyle(Z),j=J[0],Y=J[1],V=J[2],this.ctx.font=j,this.ctx.direction=Z.direction===1?"rtl":"ltr",this.ctx.textAlign="left",this.ctx.textBaseline="alphabetic",X=this.fontMetrics.getMetrics(Y,V),G=X.baseline,$=X.middle,H=Z.paintOrder,q.textBounds.forEach(function(D){H.forEach(function(O){switch(O){case 0:F.ctx.fillStyle=i(Z.color),F.renderTextWithLetterSpacing(D,Z.letterSpacing,G);var S=Z.textShadow;if(S.length&&D.text.trim().length)S.slice(0).reverse().forEach(function(T){F.ctx.shadowColor=i(T.color),F.ctx.shadowOffsetX=T.offsetX.number*F.options.scale,F.ctx.shadowOffsetY=T.offsetY.number*F.options.scale,F.ctx.shadowBlur=T.blur.number,F.renderTextWithLetterSpacing(D,Z.letterSpacing,G)}),F.ctx.shadowColor="",F.ctx.shadowOffsetX=0,F.ctx.shadowOffsetY=0,F.ctx.shadowBlur=0;if(Z.textDecorationLine.length)F.ctx.fillStyle=i(Z.textDecorationColor||Z.color),Z.textDecorationLine.forEach(function(T){switch(T){case 1:F.ctx.fillRect(D.bounds.left,Math.round(D.bounds.top+G),D.bounds.width,1);break;case 2:F.ctx.fillRect(D.bounds.left,Math.round(D.bounds.top),D.bounds.width,1);break;case 3:F.ctx.fillRect(D.bounds.left,Math.ceil(D.bounds.top+$),D.bounds.width,1);break}});break;case 1:if(Z.webkitTextStrokeWidth&&D.text.trim().length)F.ctx.strokeStyle=i(Z.webkitTextStrokeColor),F.ctx.lineWidth=Z.webkitTextStrokeWidth,F.ctx.lineJoin=window.chrome?"miter":"round",F.ctx.strokeText(D.text,D.bounds.left,D.bounds.top+G);F.ctx.strokeStyle="",F.ctx.lineWidth=0,F.ctx.lineJoin="miter";break}})}),[2]})})},Q.prototype.renderReplacedElement=function(q,Z,J){if(J&&q.intrinsicWidth>0&&q.intrinsicHeight>0){var j=z8(q),Y=K8(Z);this.path(Y),this.ctx.save(),this.ctx.clip(),this.ctx.drawImage(J,0,0,q.intrinsicWidth,q.intrinsicHeight,j.left,j.top,j.width,j.height),this.ctx.restore()}},Q.prototype.renderNodeContent=function(q){return W(this,void 0,void 0,function(){var Z,J,j,Y,V,X,I,I,G,$,H,F,y,A,D,w,O,S,T,I,x,y,w;return R(this,function(N){switch(N.label){case 0:this.applyEffects(q.getEffects(4)),Z=q.container,J=q.curves,j=Z.styles,Y=0,V=Z.textNodes,N.label=1;case 1:if(!(Y0&&t>0)b=j.ctx.createPattern(w,"repeat"),j.renderRepeat(a,b,Z1,q1)}else if(CZ($)){if(E=H6(q,Z,[null,null,null]),a=E[0],M1=E[1],j1=E[2],_=E[3],t=E[4],b1=$.position.length===0?[x8]:$.position,Z1=h(b1[0],_),q1=h(b1[b1.length-1],t),u1=IZ($,Z1,q1,_,t),D1=u1[0],x1=u1[1],D1>0&&x1>0)if(l1=j.ctx.createRadialGradient(M1+Z1,j1+q1,0,M1+Z1,j1+q1,D1),j9($.stops,D1*2).forEach(function(C0){return l1.addColorStop(C0.stop,i(C0.color))}),j.path(a),j.ctx.fillStyle=l1,D1!==x1)d1=q.bounds.left+0.5*q.bounds.width,R1=q.bounds.top+0.5*q.bounds.height,c1=x1/D1,T1=1/c1,j.ctx.save(),j.ctx.translate(d1,R1),j.ctx.transform(1,0,0,c1,0,0),j.ctx.translate(-d1,-R1),j.ctx.fillRect(M1,T1*(j1-R1)+R1,_,t*T1),j.ctx.restore();else j.ctx.fill()}j0.label=6;case 6:return Z--,[2]}})},j=this,Y=0,V=q.styles.backgroundImage.slice(0).reverse(),G.label=1;case 1:if(!(Y0))return[3,11];if($.style!==2)return[3,5];return[4,this.renderDashedDottedBorder($.color,$.width,V,q.curves,2)];case 4:return F.sent(),[3,11];case 5:if($.style!==3)return[3,7];return[4,this.renderDashedDottedBorder($.color,$.width,V,q.curves,3)];case 6:return F.sent(),[3,11];case 7:if($.style!==4)return[3,9];return[4,this.renderDoubleBorder($.color,$.width,V,q.curves)];case 8:return F.sent(),[3,11];case 9:return[4,this.renderSolidBorder($.color,V,q.curves)];case 10:F.sent(),F.label=11;case 11:V++,F.label=12;case 12:return X++,[3,3];case 13:return[2]}})})},Q.prototype.renderDashedDottedBorder=function(q,Z,J,j,Y){return W(this,void 0,void 0,function(){var V,X,G,$,H,F,A,D,O,S,T,I,x,y,w,N,w,N;return R(this,function(v){if(this.ctx.save(),V=k5(j,J),X=FQ(j,J),Y===2)this.path(X),this.ctx.clip();if(V1(X[0]))G=X[0].start.x,$=X[0].start.y;else G=X[0].x,$=X[0].y;if(V1(X[1]))H=X[1].end.x,F=X[1].end.y;else H=X[1].x,F=X[1].y;if(J===0||J===2)A=Math.abs(G-H);else A=Math.abs($-F);if(this.ctx.beginPath(),Y===3)this.formatPath(V);else this.formatPath(X.slice(0,2));if(D=Z<3?Z*3:Z*2,O=Z<3?Z*2:Z,Y===3)D=Z,O=Z;if(S=!0,A<=D*2)S=!1;else if(A<=D*2+O)T=A/(2*D+O),D*=T,O*=T;else I=Math.floor((A+O)/(D+O)),x=(A-I*D)/(I-1),y=(A-(I+1)*D)/I,O=y<=0||Math.abs(O-x)U.postToHost(BQ(W));return{reportReady:()=>z({type:"ready"}),reportNavigated:()=>z({type:"navigated",url:U.location.href,title:U.title}),reportError:(W)=>z({type:"error",message:W}),send:z,on(W,R){let P=K.get(W)??[];P.push(R),K.set(W,P)},handleHostRaw(W){let R=NQ(W);if(!R)return;for(let P of K.get(R.type)??[])P(R)}}}var z6=X7(LQ(),1);function $7(U,K,z){let W=Math.max(U,K);if(W<=z)return{width:U,height:K};let R=z/W;return{width:Math.round(U*R),height:Math.round(K*R)}}async function F6(U,K=1600,z=0.85){let W=new Image;await new Promise((d,c)=>{W.onload=()=>d(),W.onerror=()=>c(Error("load")),W.src=U});let{width:R,height:P}=$7(W.naturalWidth,W.naturalHeight,K),C=document.createElement("canvas");return C.width=R,C.height=P,C.getContext("2d").drawImage(W,0,0,R,P),C.toDataURL("image/png",z)}function RQ(U,K,z=1){return{x:(U.left-K.left)*z,y:(U.top-K.top)*z,w:U.width*z,h:U.height*z}}var IQ="#2f7bff";function H7(U,K,z,W,R,P){let C=Math.max(0,Math.min(P,W/2,R/2));U.beginPath(),U.moveTo(K+C,z),U.arcTo(K+W,z,K+W,z+R,C),U.arcTo(K+W,z+R,K,z+R,C),U.arcTo(K,z+R,K,z,C),U.arcTo(K,z,K+W,z,C),U.closePath()}function TQ(U,K,z=1,W=1){U.save(),U.lineWidth=Math.max(2,Math.round(3*W)),U.strokeStyle=IQ,H7(U,K.x,K.y,K.w,K.h,6*W),U.stroke();let R=K.x+K.w/2,P=K.y,C=13*W;U.beginPath(),U.arc(R,P,C,0,Math.PI*2),U.fillStyle=IQ,U.fill(),U.fillStyle="#ffffff",U.font=`bold ${Math.round(14*W)}px sans-serif`,U.textAlign="center",U.textBaseline="middle",U.fillText(String(z),R,P),U.restore()}async function D6(U,K){let z=U==="element"&&K?K:document.body,W=await z6.default(z,{...U==="viewport"?{windowWidth:window.innerWidth,height:window.innerHeight}:{},useCORS:!0,logging:!1});return F6(W.toDataURL("image/png"))}async function wQ(U,K=1){let z=U.getBoundingClientRect(),W=document.body.getBoundingClientRect(),R=await z6.default(document.body,{useCORS:!0,logging:!1,scale:1}),P=R.getContext("2d");if(P)TQ(P,RQ(z,W,1),K);return F6(R.toDataURL("image/png"))}function EQ(U){let K=U.parentElement;if(!K||K.tagName.toLowerCase()==="body"||K.tagName.toLowerCase()==="html")return null;return K}function CQ(U){return U.firstElementChild}function SQ(U){let K=!1,z=null,W=null,R=document.createElement("div");R.style.cssText="position:fixed;inset:0;pointer-events:none;z-index:2147483647";let P=R.attachShadow({mode:"open"}),C=document.createElement("div");C.style.cssText="position:fixed;border:2px solid #2f7bff;background:rgba(47,123,255,.12);pointer-events:none",C.hidden=!0,P.appendChild(C);let d=(k)=>{if(!k){C.hidden=!0;return}let f=k.getBoundingClientRect();C.hidden=!1,C.style.left=`${f.left}px`,C.style.top=`${f.top}px`,C.style.width=`${f.width}px`,C.style.height=`${f.height}px`},c=(k)=>{z=k,d(k),U.onSelect(k)};return{enter(){if(K=!0,z=null,W=null,!R.isConnected)document.documentElement.appendChild(R)},hover(k){if(!K||z)return;W=k,d(k)},select(){if(W)c(W)},climb(){if(z){let k=EQ(z);if(k)z=k,d(k)}},descend(){if(z){let k=CQ(z);if(k)z=k,d(k)}},current(){return z},exit(){K=!1,z=null,W=null,C.hidden=!0,R.remove()}}}function K7(U){let K=U.tagName.toLowerCase(),z=U.parentElement;if(!z)return K;let W=Array.from(z.children).filter((R)=>R.tagName===U.tagName);if(W.length<=1)return K;return`${K}:nth-of-type(${W.indexOf(U)+1})`}function yQ(U){if(U.id)return`#${U.id}`;let K=[],z=U;while(z&&z.nodeType===1&&z.tagName.toLowerCase()!=="html"&&z.tagName.toLowerCase()!=="body"){if(z.id){K.unshift(`#${z.id}`);break}K.unshift(K7(z)),z=z.parentElement}return K.join(" > ")}function PQ(U){let K=[],z=U;while(z&&z.parentElement){let W=Array.from(z.parentElement.children).indexOf(z)+1;K.unshift(`${z.tagName.toLowerCase()}:nth-child(${W})`),z=z.parentElement}return K.join(" > ")}var U7=["color","backgroundColor","opacity","fontFamily","fontSize","fontWeight","textAlign","padding","margin"];function fQ(U){let K=window.getComputedStyle(U),z={};for(let P of U7)z[P]=K[P]??"";let W=U.getBoundingClientRect(),R=yQ(U);return{selector:R,nthPath:PQ(U),tag:U.tagName.toLowerCase(),id:U.id||void 0,classes:Array.from(U.classList),text:(U.textContent??"").trim().slice(0,200)||void 0,boundingBox:{x:W.x,y:W.y,w:W.width,h:W.height},computedStyles:z,outerHtmlSnippet:R.includes(":nth")?U.outerHTML.slice(0,300):void 0}}function W6(U,K){let z=window.getComputedStyle(U),W={};if(K.text!=null&&K.text!==U.textContent)W.text={from:U.textContent??"",to:K.text},U.textContent=K.text;if(K.color)W.color={from:z.color,to:K.color},U.style.color=K.color;if(K.background)W.background={from:z.backgroundColor,to:K.background},U.style.background=K.background;if(K.opacity)W.opacity={from:z.opacity,to:K.opacity},U.style.opacity=K.opacity;if(K.fontFamily)W.fontFamily={from:z.fontFamily,to:K.fontFamily},U.style.fontFamily=K.fontFamily;return W}var F7=[{key:"text",label:"文本"},{key:"color",label:"文字颜色"},{key:"background",label:"背景"},{key:"opacity",label:"Opacity"},{key:"fontFamily",label:"字体"}];function z7(U){let K=window.getComputedStyle(U);return{text:U.textContent??"",color:K.color,background:K.backgroundColor,opacity:K.opacity,fontFamily:K.fontFamily}}function D7(U,K){let z={};if(K.text!==U.text)z.text={from:U.text,to:K.text};if(K.color!==U.color)z.color={from:U.color,to:K.color};if(K.background!==U.background)z.background={from:U.background,to:K.background};if(K.opacity!==U.opacity)z.opacity={from:U.opacity,to:K.opacity};if(K.fontFamily!==U.fontFamily)z.fontFamily={from:U.fontFamily,to:K.fontFamily};return z}function W7(U,K){let z={};if(U==="text")z.text=K;else if(U==="color")z.color=K;else if(U==="background")z.background=K;else if(U==="opacity")z.opacity=K;else if(U==="fontFamily")z.fontFamily=K;return z}function kQ(U,K){let z=z7(U),W={...z},R="",P=document.createElement("div"),C=U.getBoundingClientRect(),d=Math.max(8,Math.min(C.bottom+8,window.innerHeight-380)),c=Math.max(8,Math.min(C.left,window.innerWidth-356));P.style.cssText=`position:fixed;top:${d}px;left:${c}px;z-index:2147483647`;let k=P.attachShadow({mode:"open"}),f=document.createElement("div");f.setAttribute("style","width:340px;box-sizing:border-box;background:#fff;border-radius:14px;box-shadow:0 10px 34px rgba(0,0,0,.2);padding:12px;font:13px/1.45 -apple-system,system-ui,sans-serif;color:#111");let W1=document.createElement("input");W1.setAttribute("data-field","description"),W1.placeholder="描述这些更改…",W1.setAttribute("style","width:100%;box-sizing:border-box;border:none;outline:none;font-size:14px;padding:6px 4px"),W1.addEventListener("input",()=>{R=W1.value}),f.appendChild(W1);let Y0=document.createElement("div");Y0.textContent=U.tagName.toLowerCase(),Y0.setAttribute("style","color:#8a8a8a;border-top:1px solid #eee;margin-top:6px;padding:8px 4px 4px;font-weight:600"),f.appendChild(Y0);for(let B1 of F7){let s1=document.createElement("label");s1.setAttribute("style","display:flex;align-items:center;gap:10px;padding:5px 4px");let X0=document.createElement("span");X0.textContent=B1.label,X0.setAttribute("style","width:74px;color:#555;flex:none");let N1=document.createElement("input");N1.setAttribute("data-field",B1.key),N1.value=z[B1.key],N1.setAttribute("style","flex:1;min-width:0;border:1px solid #e2e2e2;border-radius:8px;padding:5px 9px;font:inherit");let K1=B1.key;N1.addEventListener("input",()=>{W[K1]=N1.value,W6(U,W7(K1,N1.value))}),s1.appendChild(X0),s1.appendChild(N1),f.appendChild(s1)}let O1=document.createElement("div");O1.setAttribute("style","display:flex;justify-content:space-between;align-items:center;margin-top:12px");let w1=document.createElement("button");w1.setAttribute("data-action","cancel"),w1.textContent="取消",w1.setAttribute("style","border:none;background:#f1f1f1;border-radius:18px;padding:7px 16px;cursor:pointer;font:inherit");let $1=document.createElement("button");return $1.setAttribute("data-action","confirm"),$1.textContent="✓",$1.setAttribute("style","border:none;background:#2f7bff;color:#fff;border-radius:50%;width:34px;height:34px;cursor:pointer;font-size:16px"),w1.addEventListener("click",()=>{W6(U,z),K.onCancel()}),$1.addEventListener("click",()=>{K.onConfirm({...D7(z,W),description:R||void 0})}),O1.appendChild(w1),O1.appendChild($1),f.appendChild(O1),k.appendChild(f),document.documentElement.appendChild(P),{host:P,destroy:()=>{P.remove()}}}(()=>{window.__PREVIEW_AGENT__=!0;let K=AQ({postToHost:(c)=>{let k=window.__TAURI_INTERNALS__;if(k?.invoke)k.invoke("preview_message",{raw:c})},location:window.location,title:document.title});window.__PREVIEW_BRIDGE__=K,window.__PREVIEW_AGENT_CAPTURE__=D6,K.on("capture",async(c)=>{try{K.send({type:"screenshot",dataUrl:await D6(c.kind),kind:c.kind})}catch(k){K.reportError(String(k))}});let z=!1,W=null,R=SQ({onSelect:()=>{}}),P=()=>{W?.destroy(),W=null,z=!1,R.exit(),K.send({type:"picker-exited"})},C=async(c,k)=>{try{let f=await wQ(c);K.send({type:"selection",payload:{pageUrl:window.location.href,sourceHint:document.title||void 0,element:fQ(c),change:k,screenshot:{dataUrl:f,kind:"region"}}})}catch(f){K.reportError(String(f))}};K.on("enter-picker",()=>{z=!0,R.enter()}),K.on("exit-picker",()=>{P()}),document.addEventListener("mousemove",(c)=>{if(!z)return;let k=c.target;if(k instanceof Element)R.hover(k)},!0),document.addEventListener("click",(c)=>{if(!z||W)return;c.preventDefault(),c.stopPropagation(),R.select();let k=R.current();if(z=!1,!(k instanceof HTMLElement)){P();return}W=kQ(k,{onConfirm:(f)=>{P(),C(k,f)},onCancel:()=>{P()}})},!0);let d=()=>{K.reportReady(),K.reportNavigated()};if(document.readyState!=="loading")d();else document.addEventListener("DOMContentLoaded",d);window.addEventListener("popstate",()=>K.reportNavigated())})();})(); + .`+X6+U5+XQ)},z5=function(M,Q){var q=M.ownerDocument;if(q){var Z=q.createElement("style");Z.textContent=Q,M.appendChild(Z)}},VQ=function(){function M(){}return M.getOrigin=function(Q){var q=M._link;if(!q)return"about:blank";return q.href=Q,q.href=q.href,q.protocol+q.hostname+q.port},M.isSameOrigin=function(Q){return M.getOrigin(Q)===M._origin},M.setContext=function(Q){M._link=Q.document.createElement("a"),M._origin=M.getOrigin(Q.location.href)},M._origin="about:blank",M}(),D5=function(){function M(Q,q){this.context=Q,this._options=q,this._cache={}}return M.prototype.addImage=function(Q){var q=Promise.resolve();if(this.has(Q))return q;if(G6(Q)||N5(Q))return(this._cache[Q]=this.loadImage(Q)).catch(function(){}),q;return q},M.prototype.match=function(Q){return this._cache[Q]},M.prototype.loadImage=function(Q){return W(this,void 0,void 0,function(){var q,Z,J,j,Y=this;return R(this,function(V){switch(V.label){case 0:if(q=VQ.isSameOrigin(Q),Z=!V6(Q)&&this._options.useCORS===!0&&n.SUPPORT_CORS_IMAGES&&!q,J=!V6(Q)&&!q&&!G6(Q)&&typeof this._options.proxy==="string"&&n.SUPPORT_CORS_XHR&&!Z,!q&&this._options.allowTaint===!1&&!V6(Q)&&!G6(Q)&&!J&&!Z)return[2];if(j=Q,!J)return[3,2];return[4,this.proxy(j)];case 1:j=V.sent(),V.label=2;case 2:return this.context.logger.debug("Added image "+Q.substring(0,256)),[4,new Promise(function(X,G){var $=new Image;if($.onload=function(){return X($)},$.onerror=G,A5(j)||Z)$.crossOrigin="anonymous";if($.src=j,$.complete===!0)setTimeout(function(){return X($)},500);if(Y._options.imageTimeout>0)setTimeout(function(){return G("Timed out ("+Y._options.imageTimeout+"ms) loading image")},Y._options.imageTimeout)})];case 3:return[2,V.sent()]}})})},M.prototype.has=function(Q){return typeof this._cache[Q]<"u"},M.prototype.keys=function(){return Promise.resolve(Object.keys(this._cache))},M.prototype.proxy=function(Q){var q=this,Z=this._options.proxy;if(!Z)throw Error("No proxy defined");var J=Q.substring(0,256);return new Promise(function(j,Y){var V=n.SUPPORT_RESPONSE_TYPE?"blob":"text",X=new XMLHttpRequest;X.onload=function(){if(X.status===200)if(V==="text")j(X.response);else{var H=new FileReader;H.addEventListener("load",function(){return j(H.result)},!1),H.addEventListener("error",function(F){return Y(F)},!1),H.readAsDataURL(X.response)}else Y("Failed to proxy resource "+J+" with status code "+X.status)},X.onerror=Y;var G=Z.indexOf("?")>-1?"&":"?";if(X.open("GET",""+Z+G+"url="+encodeURIComponent(Q)+"&responseType="+V),V!=="text"&&X instanceof XMLHttpRequest)X.responseType=V;if(q._options.imageTimeout){var $=q._options.imageTimeout;X.timeout=$,X.ontimeout=function(){return Y("Timed out ("+$+"ms) proxying "+J)}}X.send()})},M}(),W5=/^data:image\/svg\+xml/i,O5=/^data:image\/.*;base64,/i,B5=/^data:image\/.*/i,N5=function(M){return n.SUPPORT_SVG_DRAWING||!L5(M)},V6=function(M){return B5.test(M)},A5=function(M){return O5.test(M)},G6=function(M){return M.substr(0,4)==="blob"},L5=function(M){return M.substr(-3).toLowerCase()==="svg"||W5.test(M)},B=function(){function M(Q,q){this.type=0,this.x=Q,this.y=q}return M.prototype.add=function(Q,q){return new M(this.x+Q,this.y+q)},M}(),Z0=function(M,Q,q){return new B(M.x+(Q.x-M.x)*q,M.y+(Q.y-M.y)*q)},$8=function(){function M(Q,q,Z,J){this.type=1,this.start=Q,this.startControl=q,this.endControl=Z,this.end=J}return M.prototype.subdivide=function(Q,q){var Z=Z0(this.start,this.startControl,Q),J=Z0(this.startControl,this.endControl,Q),j=Z0(this.endControl,this.end,Q),Y=Z0(Z,J,Q),V=Z0(J,j,Q),X=Z0(Y,V,Q);return q?new M(this.start,Z,Y,X):new M(X,V,j,this.end)},M.prototype.add=function(Q,q){return new M(this.start.add(Q,q),this.startControl.add(Q,q),this.endControl.add(Q,q),this.end.add(Q,q))},M.prototype.reverse=function(){return new M(this.end,this.endControl,this.startControl,this.start)},M}(),V1=function(M){return M.type===1},I5=function(){function M(Q){var{styles:q,bounds:Z}=Q,J=N0(q.borderTopLeftRadius,Z.width,Z.height),j=J[0],Y=J[1],V=N0(q.borderTopRightRadius,Z.width,Z.height),X=V[0],G=V[1],$=N0(q.borderBottomRightRadius,Z.width,Z.height),H=$[0],F=$[1],A=N0(q.borderBottomLeftRadius,Z.width,Z.height),D=A[0],O=A[1],S=[];S.push((j+X)/Z.width),S.push((D+H)/Z.width),S.push((Y+O)/Z.height),S.push((G+F)/Z.height);var T=Math.max.apply(Math,S);if(T>1)j/=T,Y/=T,X/=T,G/=T,H/=T,F/=T,D/=T,O/=T;var I=Z.width-X,x=Z.height-F,y=Z.width-H,w=Z.height-O,N=q.borderTopWidth,v=q.borderRightWidth,b=q.borderBottomWidth,E=q.borderLeftWidth,a=h(q.paddingTop,Q.bounds.width),M1=h(q.paddingRight,Q.bounds.width),j1=h(q.paddingBottom,Q.bounds.width),_=h(q.paddingLeft,Q.bounds.width);this.topLeftBorderDoubleOuterBox=j>0||Y>0?u(Z.left+E/3,Z.top+N/3,j-E/3,Y-N/3,g.TOP_LEFT):new B(Z.left+E/3,Z.top+N/3),this.topRightBorderDoubleOuterBox=j>0||Y>0?u(Z.left+I,Z.top+N/3,X-v/3,G-N/3,g.TOP_RIGHT):new B(Z.left+Z.width-v/3,Z.top+N/3),this.bottomRightBorderDoubleOuterBox=H>0||F>0?u(Z.left+y,Z.top+x,H-v/3,F-b/3,g.BOTTOM_RIGHT):new B(Z.left+Z.width-v/3,Z.top+Z.height-b/3),this.bottomLeftBorderDoubleOuterBox=D>0||O>0?u(Z.left+E/3,Z.top+w,D-E/3,O-b/3,g.BOTTOM_LEFT):new B(Z.left+E/3,Z.top+Z.height-b/3),this.topLeftBorderDoubleInnerBox=j>0||Y>0?u(Z.left+E*2/3,Z.top+N*2/3,j-E*2/3,Y-N*2/3,g.TOP_LEFT):new B(Z.left+E*2/3,Z.top+N*2/3),this.topRightBorderDoubleInnerBox=j>0||Y>0?u(Z.left+I,Z.top+N*2/3,X-v*2/3,G-N*2/3,g.TOP_RIGHT):new B(Z.left+Z.width-v*2/3,Z.top+N*2/3),this.bottomRightBorderDoubleInnerBox=H>0||F>0?u(Z.left+y,Z.top+x,H-v*2/3,F-b*2/3,g.BOTTOM_RIGHT):new B(Z.left+Z.width-v*2/3,Z.top+Z.height-b*2/3),this.bottomLeftBorderDoubleInnerBox=D>0||O>0?u(Z.left+E*2/3,Z.top+w,D-E*2/3,O-b*2/3,g.BOTTOM_LEFT):new B(Z.left+E*2/3,Z.top+Z.height-b*2/3),this.topLeftBorderStroke=j>0||Y>0?u(Z.left+E/2,Z.top+N/2,j-E/2,Y-N/2,g.TOP_LEFT):new B(Z.left+E/2,Z.top+N/2),this.topRightBorderStroke=j>0||Y>0?u(Z.left+I,Z.top+N/2,X-v/2,G-N/2,g.TOP_RIGHT):new B(Z.left+Z.width-v/2,Z.top+N/2),this.bottomRightBorderStroke=H>0||F>0?u(Z.left+y,Z.top+x,H-v/2,F-b/2,g.BOTTOM_RIGHT):new B(Z.left+Z.width-v/2,Z.top+Z.height-b/2),this.bottomLeftBorderStroke=D>0||O>0?u(Z.left+E/2,Z.top+w,D-E/2,O-b/2,g.BOTTOM_LEFT):new B(Z.left+E/2,Z.top+Z.height-b/2),this.topLeftBorderBox=j>0||Y>0?u(Z.left,Z.top,j,Y,g.TOP_LEFT):new B(Z.left,Z.top),this.topRightBorderBox=X>0||G>0?u(Z.left+I,Z.top,X,G,g.TOP_RIGHT):new B(Z.left+Z.width,Z.top),this.bottomRightBorderBox=H>0||F>0?u(Z.left+y,Z.top+x,H,F,g.BOTTOM_RIGHT):new B(Z.left+Z.width,Z.top+Z.height),this.bottomLeftBorderBox=D>0||O>0?u(Z.left,Z.top+w,D,O,g.BOTTOM_LEFT):new B(Z.left,Z.top+Z.height),this.topLeftPaddingBox=j>0||Y>0?u(Z.left+E,Z.top+N,Math.max(0,j-E),Math.max(0,Y-N),g.TOP_LEFT):new B(Z.left+E,Z.top+N),this.topRightPaddingBox=X>0||G>0?u(Z.left+Math.min(I,Z.width-v),Z.top+N,I>Z.width+v?0:Math.max(0,X-v),Math.max(0,G-N),g.TOP_RIGHT):new B(Z.left+Z.width-v,Z.top+N),this.bottomRightPaddingBox=H>0||F>0?u(Z.left+Math.min(y,Z.width-E),Z.top+Math.min(x,Z.height-b),Math.max(0,H-v),Math.max(0,F-b),g.BOTTOM_RIGHT):new B(Z.left+Z.width-v,Z.top+Z.height-b),this.bottomLeftPaddingBox=D>0||O>0?u(Z.left+E,Z.top+Math.min(w,Z.height-b),Math.max(0,D-E),Math.max(0,O-b),g.BOTTOM_LEFT):new B(Z.left+E,Z.top+Z.height-b),this.topLeftContentBox=j>0||Y>0?u(Z.left+E+_,Z.top+N+a,Math.max(0,j-(E+_)),Math.max(0,Y-(N+a)),g.TOP_LEFT):new B(Z.left+E+_,Z.top+N+a),this.topRightContentBox=X>0||G>0?u(Z.left+Math.min(I,Z.width+E+_),Z.top+N+a,I>Z.width+E+_?0:X-E+_,G-(N+a),g.TOP_RIGHT):new B(Z.left+Z.width-(v+M1),Z.top+N+a),this.bottomRightContentBox=H>0||F>0?u(Z.left+Math.min(y,Z.width-(E+_)),Z.top+Math.min(x,Z.height+N+a),Math.max(0,H-(v+M1)),F-(b+j1),g.BOTTOM_RIGHT):new B(Z.left+Z.width-(v+M1),Z.top+Z.height-(b+j1)),this.bottomLeftContentBox=D>0||O>0?u(Z.left+E+_,Z.top+w,Math.max(0,D-(E+_)),O-(b+j1),g.BOTTOM_LEFT):new B(Z.left+E+_,Z.top+Z.height-(b+j1))}return M}(),g;(function(M){M[M.TOP_LEFT=0]="TOP_LEFT",M[M.TOP_RIGHT=1]="TOP_RIGHT",M[M.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",M[M.BOTTOM_LEFT=3]="BOTTOM_LEFT"})(g||(g={}));var u=function(M,Q,q,Z,J){var j=4*((Math.sqrt(2)-1)/3),Y=q*j,V=Z*j,X=M+q,G=Q+Z;switch(J){case g.TOP_LEFT:return new $8(new B(M,G),new B(M,G-V),new B(X-Y,Q),new B(X,Q));case g.TOP_RIGHT:return new $8(new B(M,Q),new B(M+Y,Q),new B(X,G-V),new B(X,G));case g.BOTTOM_RIGHT:return new $8(new B(X,Q),new B(X,Q+V),new B(M+Y,G),new B(M,G));case g.BOTTOM_LEFT:default:return new $8(new B(X,G),new B(X-Y,G),new B(M,Q+V),new B(M,Q))}},H8=function(M){return[M.topLeftBorderBox,M.topRightBorderBox,M.bottomRightBorderBox,M.bottomLeftBorderBox]},R5=function(M){return[M.topLeftContentBox,M.topRightContentBox,M.bottomRightContentBox,M.bottomLeftContentBox]},K8=function(M){return[M.topLeftPaddingBox,M.topRightPaddingBox,M.bottomRightPaddingBox,M.bottomLeftPaddingBox]},T5=function(){function M(Q,q,Z){this.offsetX=Q,this.offsetY=q,this.matrix=Z,this.type=0,this.target=6}return M}(),U8=function(){function M(Q,q){this.path=Q,this.target=q,this.type=1}return M}(),w5=function(){function M(Q){this.opacity=Q,this.type=2,this.target=6}return M}(),E5=function(M){return M.type===0},GQ=function(M){return M.type===1},C5=function(M){return M.type===2},$Q=function(M,Q){if(M.length===Q.length)return M.some(function(q,Z){return q===Q[Z]});return!1},S5=function(M,Q,q,Z,J){return M.map(function(j,Y){switch(Y){case 0:return j.add(Q,q);case 1:return j.add(Q+Z,q);case 2:return j.add(Q+Z,q+J);case 3:return j.add(Q,q+J)}return j})},HQ=function(){function M(Q){this.element=Q,this.inlineLevel=[],this.nonInlineLevel=[],this.negativeZIndex=[],this.zeroOrAutoZIndexOrTransformedOrOpacity=[],this.positiveZIndex=[],this.nonPositionedFloats=[],this.nonPositionedInlineLevel=[]}return M}(),KQ=function(){function M(Q,q){if(this.container=Q,this.parent=q,this.effects=[],this.curves=new I5(this.container),this.container.styles.opacity<1)this.effects.push(new w5(this.container.styles.opacity));if(this.container.styles.transform!==null){var Z=this.container.bounds.left+this.container.styles.transformOrigin[0].number,J=this.container.bounds.top+this.container.styles.transformOrigin[1].number,j=this.container.styles.transform;this.effects.push(new T5(Z,J,j))}if(this.container.styles.overflowX!==0){var Y=H8(this.curves),V=K8(this.curves);if($Q(Y,V))this.effects.push(new U8(Y,6));else this.effects.push(new U8(Y,2)),this.effects.push(new U8(V,4))}}return M.prototype.getEffects=function(Q){var q=[2,3].indexOf(this.container.styles.position)===-1,Z=this.parent,J=this.effects.slice(0);while(Z){var j=Z.effects.filter(function(X){return!GQ(X)});if(q||Z.container.styles.position!==0||!Z.parent){if(J.unshift.apply(J,j),q=[2,3].indexOf(Z.container.styles.position)===-1,Z.container.styles.overflowX!==0){var Y=H8(Z.curves),V=K8(Z.curves);if(!$Q(Y,V))J.unshift(new U8(V,6))}}else J.unshift.apply(J,j);Z=Z.parent}return J.filter(function(X){return r(X.target,Q)})},M}(),$6=function(M,Q,q,Z){M.container.elements.forEach(function(J){var j=r(J.flags,4),Y=r(J.flags,2),V=new KQ(J,M);if(r(J.styles.display,2048))Z.push(V);var X=r(J.flags,8)?[]:Z;if(j||Y){var G=j||J.styles.isPositioned()?q:Q,$=new HQ(V);if(J.styles.isPositioned()||J.styles.opacity<1||J.styles.isTransformed()){var H=J.styles.zIndex.order;if(H<0){var F=0;G.negativeZIndex.some(function(D,O){if(H>D.element.container.styles.zIndex.order)return F=O,!1;else if(F>0)return!0;return!1}),G.negativeZIndex.splice(F,0,$)}else if(H>0){var A=0;G.positiveZIndex.some(function(D,O){if(H>=D.element.container.styles.zIndex.order)return A=O+1,!1;else if(A>0)return!0;return!1}),G.positiveZIndex.splice(A,0,$)}else G.zeroOrAutoZIndexOrTransformedOrOpacity.push($)}else if(J.styles.isFloating())G.nonPositionedFloats.push($);else G.nonPositionedInlineLevel.push($);$6(V,$,j?$:q,X)}else{if(J.styles.isInlineLevel())Q.inlineLevel.push(V);else Q.nonInlineLevel.push(V);$6(V,Q,q,X)}if(r(J.flags,8))UQ(J,X)})},UQ=function(M,Q){var q=M instanceof e8?M.start:1,Z=M instanceof e8?M.reversed:!1;for(var J=0;J"u")return M[0];return q},x5=function(M,Q,q,Z,J){var j=Q[0],Y=Q[1],V=q[0],X=q[1];switch(M){case 2:return[new B(Math.round(Z.left),Math.round(Z.top+Y)),new B(Math.round(Z.left+Z.width),Math.round(Z.top+Y)),new B(Math.round(Z.left+Z.width),Math.round(X+Z.top+Y)),new B(Math.round(Z.left),Math.round(X+Z.top+Y))];case 3:return[new B(Math.round(Z.left+j),Math.round(Z.top)),new B(Math.round(Z.left+j+V),Math.round(Z.top)),new B(Math.round(Z.left+j+V),Math.round(Z.height+Z.top)),new B(Math.round(Z.left+j),Math.round(Z.height+Z.top))];case 1:return[new B(Math.round(Z.left+j),Math.round(Z.top+Y)),new B(Math.round(Z.left+j+V),Math.round(Z.top+Y)),new B(Math.round(Z.left+j+V),Math.round(Z.top+Y+X)),new B(Math.round(Z.left+j),Math.round(Z.top+Y+X))];default:return[new B(Math.round(J.left),Math.round(J.top)),new B(Math.round(J.left+J.width),Math.round(J.top)),new B(Math.round(J.left+J.width),Math.round(J.height+J.top)),new B(Math.round(J.left),Math.round(J.height+J.top))]}},g5="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",DQ="Hidden Text",p5=function(){function M(Q){this._data={},this._document=Q}return M.prototype.parseMetrics=function(Q,q){var Z=this._document.createElement("div"),J=this._document.createElement("img"),j=this._document.createElement("span"),Y=this._document.body;Z.style.visibility="hidden",Z.style.fontFamily=Q,Z.style.fontSize=q,Z.style.margin="0",Z.style.padding="0",Z.style.whiteSpace="nowrap",Y.appendChild(Z),J.src=g5,J.width=1,J.height=1,J.style.margin="0",J.style.padding="0",J.style.verticalAlign="baseline",j.style.fontFamily=Q,j.style.fontSize=q,j.style.margin="0",j.style.padding="0",j.appendChild(this._document.createTextNode(DQ)),Z.appendChild(j),Z.appendChild(J);var V=J.offsetTop-j.offsetTop+2;Z.removeChild(j),Z.appendChild(this._document.createTextNode(DQ)),Z.style.lineHeight="normal",J.style.verticalAlign="super";var X=J.offsetTop-Z.offsetTop+2;return Y.removeChild(Z),{baseline:V,middle:X}},M.prototype.getMetrics=function(Q,q){var Z=Q+" "+q;if(typeof this._data[Z]>"u")this._data[Z]=this.parseMetrics(Q,q);return this._data[Z]},M}(),WQ=function(){function M(Q,q){this.context=Q,this.options=q}return M}(),_5=1e4,h5=function(M){K(Q,M);function Q(q,Z){var J=M.call(this,q,Z)||this;if(J._activeEffects=[],J.canvas=Z.canvas?Z.canvas:document.createElement("canvas"),J.ctx=J.canvas.getContext("2d"),!Z.canvas)J.canvas.width=Math.floor(Z.width*Z.scale),J.canvas.height=Math.floor(Z.height*Z.scale),J.canvas.style.width=Z.width+"px",J.canvas.style.height=Z.height+"px";return J.fontMetrics=new p5(document),J.ctx.scale(J.options.scale,J.options.scale),J.ctx.translate(-Z.x,-Z.y),J.ctx.textBaseline="bottom",J._activeEffects=[],J.context.logger.debug("Canvas renderer initialized ("+Z.width+"x"+Z.height+") with scale "+Z.scale),J}return Q.prototype.applyEffects=function(q){var Z=this;while(this._activeEffects.length)this.popEffect();q.forEach(function(J){return Z.applyEffect(J)})},Q.prototype.applyEffect=function(q){if(this.ctx.save(),C5(q))this.ctx.globalAlpha=q.opacity;if(E5(q))this.ctx.translate(q.offsetX,q.offsetY),this.ctx.transform(q.matrix[0],q.matrix[1],q.matrix[2],q.matrix[3],q.matrix[4],q.matrix[5]),this.ctx.translate(-q.offsetX,-q.offsetY);if(GQ(q))this.path(q.path),this.ctx.clip();this._activeEffects.push(q)},Q.prototype.popEffect=function(){this._activeEffects.pop(),this.ctx.restore()},Q.prototype.renderStack=function(q){return W(this,void 0,void 0,function(){var Z;return R(this,function(J){switch(J.label){case 0:if(Z=q.element.container.styles,!Z.isVisible())return[3,2];return[4,this.renderStackContent(q)];case 1:J.sent(),J.label=2;case 2:return[2]}})})},Q.prototype.renderNode=function(q){return W(this,void 0,void 0,function(){return R(this,function(Z){switch(Z.label){case 0:if(r(q.container.flags,16))debugger;if(!q.container.styles.isVisible())return[3,3];return[4,this.renderNodeBackgroundAndBorders(q)];case 1:return Z.sent(),[4,this.renderNodeContent(q)];case 2:Z.sent(),Z.label=3;case 3:return[2]}})})},Q.prototype.renderTextWithLetterSpacing=function(q,Z,J){var j=this;if(Z===0)this.ctx.fillText(q.text,q.bounds.left,q.bounds.top+J);else{var Y=t8(q.text);Y.reduce(function(V,X){return j.ctx.fillText(X,V,q.bounds.top+J),V+j.ctx.measureText(X).width},q.bounds.left)}},Q.prototype.createFontStyle=function(q){var Z=q.fontVariant.filter(function(Y){return Y==="normal"||Y==="small-caps"}).join(""),J=s5(q.fontFamily).join(", "),j=B0(q.fontSize)?""+q.fontSize.number+q.fontSize.unit:q.fontSize.number+"px";return[[q.fontStyle,Z,q.fontWeight,j,J].join(" "),J,j]},Q.prototype.renderTextNode=function(q,Z){return W(this,void 0,void 0,function(){var J,j,Y,V,X,G,$,H,F=this;return R(this,function(A){return J=this.createFontStyle(Z),j=J[0],Y=J[1],V=J[2],this.ctx.font=j,this.ctx.direction=Z.direction===1?"rtl":"ltr",this.ctx.textAlign="left",this.ctx.textBaseline="alphabetic",X=this.fontMetrics.getMetrics(Y,V),G=X.baseline,$=X.middle,H=Z.paintOrder,q.textBounds.forEach(function(D){H.forEach(function(O){switch(O){case 0:F.ctx.fillStyle=i(Z.color),F.renderTextWithLetterSpacing(D,Z.letterSpacing,G);var S=Z.textShadow;if(S.length&&D.text.trim().length)S.slice(0).reverse().forEach(function(T){F.ctx.shadowColor=i(T.color),F.ctx.shadowOffsetX=T.offsetX.number*F.options.scale,F.ctx.shadowOffsetY=T.offsetY.number*F.options.scale,F.ctx.shadowBlur=T.blur.number,F.renderTextWithLetterSpacing(D,Z.letterSpacing,G)}),F.ctx.shadowColor="",F.ctx.shadowOffsetX=0,F.ctx.shadowOffsetY=0,F.ctx.shadowBlur=0;if(Z.textDecorationLine.length)F.ctx.fillStyle=i(Z.textDecorationColor||Z.color),Z.textDecorationLine.forEach(function(T){switch(T){case 1:F.ctx.fillRect(D.bounds.left,Math.round(D.bounds.top+G),D.bounds.width,1);break;case 2:F.ctx.fillRect(D.bounds.left,Math.round(D.bounds.top),D.bounds.width,1);break;case 3:F.ctx.fillRect(D.bounds.left,Math.ceil(D.bounds.top+$),D.bounds.width,1);break}});break;case 1:if(Z.webkitTextStrokeWidth&&D.text.trim().length)F.ctx.strokeStyle=i(Z.webkitTextStrokeColor),F.ctx.lineWidth=Z.webkitTextStrokeWidth,F.ctx.lineJoin=window.chrome?"miter":"round",F.ctx.strokeText(D.text,D.bounds.left,D.bounds.top+G);F.ctx.strokeStyle="",F.ctx.lineWidth=0,F.ctx.lineJoin="miter";break}})}),[2]})})},Q.prototype.renderReplacedElement=function(q,Z,J){if(J&&q.intrinsicWidth>0&&q.intrinsicHeight>0){var j=z8(q),Y=K8(Z);this.path(Y),this.ctx.save(),this.ctx.clip(),this.ctx.drawImage(J,0,0,q.intrinsicWidth,q.intrinsicHeight,j.left,j.top,j.width,j.height),this.ctx.restore()}},Q.prototype.renderNodeContent=function(q){return W(this,void 0,void 0,function(){var Z,J,j,Y,V,X,I,I,G,$,H,F,y,A,D,w,O,S,T,I,x,y,w;return R(this,function(N){switch(N.label){case 0:this.applyEffects(q.getEffects(4)),Z=q.container,J=q.curves,j=Z.styles,Y=0,V=Z.textNodes,N.label=1;case 1:if(!(Y0&&t>0)b=j.ctx.createPattern(w,"repeat"),j.renderRepeat(a,b,Z1,q1)}else if(CZ($)){if(E=H6(q,Z,[null,null,null]),a=E[0],M1=E[1],j1=E[2],_=E[3],t=E[4],b1=$.position.length===0?[x8]:$.position,Z1=h(b1[0],_),q1=h(b1[b1.length-1],t),u1=IZ($,Z1,q1,_,t),D1=u1[0],x1=u1[1],D1>0&&x1>0)if(l1=j.ctx.createRadialGradient(M1+Z1,j1+q1,0,M1+Z1,j1+q1,D1),j9($.stops,D1*2).forEach(function(C0){return l1.addColorStop(C0.stop,i(C0.color))}),j.path(a),j.ctx.fillStyle=l1,D1!==x1)d1=q.bounds.left+0.5*q.bounds.width,R1=q.bounds.top+0.5*q.bounds.height,c1=x1/D1,T1=1/c1,j.ctx.save(),j.ctx.translate(d1,R1),j.ctx.transform(1,0,0,c1,0,0),j.ctx.translate(-d1,-R1),j.ctx.fillRect(M1,T1*(j1-R1)+R1,_,t*T1),j.ctx.restore();else j.ctx.fill()}j0.label=6;case 6:return Z--,[2]}})},j=this,Y=0,V=q.styles.backgroundImage.slice(0).reverse(),G.label=1;case 1:if(!(Y0))return[3,11];if($.style!==2)return[3,5];return[4,this.renderDashedDottedBorder($.color,$.width,V,q.curves,2)];case 4:return F.sent(),[3,11];case 5:if($.style!==3)return[3,7];return[4,this.renderDashedDottedBorder($.color,$.width,V,q.curves,3)];case 6:return F.sent(),[3,11];case 7:if($.style!==4)return[3,9];return[4,this.renderDoubleBorder($.color,$.width,V,q.curves)];case 8:return F.sent(),[3,11];case 9:return[4,this.renderSolidBorder($.color,V,q.curves)];case 10:F.sent(),F.label=11;case 11:V++,F.label=12;case 12:return X++,[3,3];case 13:return[2]}})})},Q.prototype.renderDashedDottedBorder=function(q,Z,J,j,Y){return W(this,void 0,void 0,function(){var V,X,G,$,H,F,A,D,O,S,T,I,x,y,w,N,w,N;return R(this,function(v){if(this.ctx.save(),V=k5(j,J),X=FQ(j,J),Y===2)this.path(X),this.ctx.clip();if(V1(X[0]))G=X[0].start.x,$=X[0].start.y;else G=X[0].x,$=X[0].y;if(V1(X[1]))H=X[1].end.x,F=X[1].end.y;else H=X[1].x,F=X[1].y;if(J===0||J===2)A=Math.abs(G-H);else A=Math.abs($-F);if(this.ctx.beginPath(),Y===3)this.formatPath(V);else this.formatPath(X.slice(0,2));if(D=Z<3?Z*3:Z*2,O=Z<3?Z*2:Z,Y===3)D=Z,O=Z;if(S=!0,A<=D*2)S=!1;else if(A<=D*2+O)T=A/(2*D+O),D*=T,O*=T;else I=Math.floor((A+O)/(D+O)),x=(A-I*D)/(I-1),y=(A-(I+1)*D)/I,O=y<=0||Math.abs(O-x)U.postToHost(BQ(W));return{reportReady:()=>z({type:"ready"}),reportNavigated:()=>z({type:"navigated",url:U.location.href,title:U.title}),reportError:(W)=>z({type:"error",message:W}),send:z,on(W,R){let P=K.get(W)??[];P.push(R),K.set(W,P)},handleHostRaw(W){let R=NQ(W);if(!R)return;for(let P of K.get(R.type)??[])P(R)}}}var z6=X7(LQ(),1);function $7(U,K,z){let W=Math.max(U,K);if(W<=z)return{width:U,height:K};let R=z/W;return{width:Math.round(U*R),height:Math.round(K*R)}}async function F6(U,K=1600,z=0.85){let W=new Image;await new Promise((d,c)=>{W.onload=()=>d(),W.onerror=()=>c(Error("load")),W.src=U});let{width:R,height:P}=$7(W.naturalWidth,W.naturalHeight,K),C=document.createElement("canvas");return C.width=R,C.height=P,C.getContext("2d").drawImage(W,0,0,R,P),C.toDataURL("image/png",z)}function RQ(U,K,z=1){return{x:(U.left-K.left)*z,y:(U.top-K.top)*z,w:U.width*z,h:U.height*z}}var IQ="#2f7bff";function H7(U,K,z,W,R,P){let C=Math.max(0,Math.min(P,W/2,R/2));U.beginPath(),U.moveTo(K+C,z),U.arcTo(K+W,z,K+W,z+R,C),U.arcTo(K+W,z+R,K,z+R,C),U.arcTo(K,z+R,K,z,C),U.arcTo(K,z,K+W,z,C),U.closePath()}function TQ(U,K,z=1,W=1){U.save(),U.lineWidth=Math.max(2,Math.round(3*W)),U.strokeStyle=IQ,H7(U,K.x,K.y,K.w,K.h,6*W),U.stroke();let R=K.x+K.w/2,P=K.y,C=13*W;U.beginPath(),U.arc(R,P,C,0,Math.PI*2),U.fillStyle=IQ,U.fill(),U.fillStyle="#ffffff",U.font=`bold ${Math.round(14*W)}px sans-serif`,U.textAlign="center",U.textBaseline="middle",U.fillText(String(z),R,P),U.restore()}async function D6(U,K){let z=U==="element"&&K?K:document.body,W=await z6.default(z,{...U==="viewport"?{windowWidth:window.innerWidth,height:window.innerHeight}:{},useCORS:!0,logging:!1});return F6(W.toDataURL("image/png"))}async function wQ(U,K=1){let z=U.getBoundingClientRect(),W={left:0,top:0,width:window.innerWidth,height:window.innerHeight},R=await z6.default(document.documentElement,{useCORS:!0,logging:!1,scale:1,x:window.scrollX,y:window.scrollY,width:window.innerWidth,height:window.innerHeight,windowWidth:window.innerWidth,windowHeight:window.innerHeight,scrollX:window.scrollX,scrollY:window.scrollY}),P=R.getContext("2d");if(P)TQ(P,RQ(z,W,1),K);return F6(R.toDataURL("image/png"))}function EQ(U){let K=U.parentElement;if(!K||K.tagName.toLowerCase()==="body"||K.tagName.toLowerCase()==="html")return null;return K}function CQ(U){return U.firstElementChild}function SQ(U){let K=!1,z=null,W=null,R=document.createElement("div");R.style.cssText="position:fixed;inset:0;pointer-events:none;z-index:2147483647";let P=R.attachShadow({mode:"open"}),C=document.createElement("div");C.style.cssText="position:fixed;border:2px solid #2f7bff;background:rgba(47,123,255,.12);pointer-events:none",C.hidden=!0,P.appendChild(C);let d=(k)=>{if(!k){C.hidden=!0;return}let f=k.getBoundingClientRect();C.hidden=!1,C.style.left=`${f.left}px`,C.style.top=`${f.top}px`,C.style.width=`${f.width}px`,C.style.height=`${f.height}px`},c=(k)=>{z=k,d(k),U.onSelect(k)};return{enter(){if(K=!0,z=null,W=null,!R.isConnected)document.documentElement.appendChild(R)},hover(k){if(!K||z)return;W=k,d(k)},select(){if(W)c(W)},climb(){if(z){let k=EQ(z);if(k)z=k,d(k)}},descend(){if(z){let k=CQ(z);if(k)z=k,d(k)}},current(){return z},exit(){K=!1,z=null,W=null,C.hidden=!0,R.remove()}}}function K7(U){let K=U.tagName.toLowerCase(),z=U.parentElement;if(!z)return K;let W=Array.from(z.children).filter((R)=>R.tagName===U.tagName);if(W.length<=1)return K;return`${K}:nth-of-type(${W.indexOf(U)+1})`}function yQ(U){if(U.id)return`#${U.id}`;let K=[],z=U;while(z&&z.nodeType===1&&z.tagName.toLowerCase()!=="html"&&z.tagName.toLowerCase()!=="body"){if(z.id){K.unshift(`#${z.id}`);break}K.unshift(K7(z)),z=z.parentElement}return K.join(" > ")}function PQ(U){let K=[],z=U;while(z&&z.parentElement){let W=Array.from(z.parentElement.children).indexOf(z)+1;K.unshift(`${z.tagName.toLowerCase()}:nth-child(${W})`),z=z.parentElement}return K.join(" > ")}var U7=["color","backgroundColor","opacity","fontFamily","fontSize","fontWeight","textAlign","padding","margin"];function fQ(U){let K=window.getComputedStyle(U),z={};for(let P of U7)z[P]=K[P]??"";let W=U.getBoundingClientRect(),R=yQ(U);return{selector:R,nthPath:PQ(U),tag:U.tagName.toLowerCase(),id:U.id||void 0,classes:Array.from(U.classList),text:(U.textContent??"").trim().slice(0,200)||void 0,boundingBox:{x:W.x,y:W.y,w:W.width,h:W.height},computedStyles:z,outerHtmlSnippet:R.includes(":nth")?U.outerHTML.slice(0,300):void 0}}function W6(U,K){let z=window.getComputedStyle(U),W={};if(K.text!=null&&K.text!==U.textContent)W.text={from:U.textContent??"",to:K.text},U.textContent=K.text;if(K.color)W.color={from:z.color,to:K.color},U.style.color=K.color;if(K.background)W.background={from:z.backgroundColor,to:K.background},U.style.background=K.background;if(K.opacity)W.opacity={from:z.opacity,to:K.opacity},U.style.opacity=K.opacity;if(K.fontFamily)W.fontFamily={from:z.fontFamily,to:K.fontFamily},U.style.fontFamily=K.fontFamily;return W}var F7=[{key:"text",label:"文本"},{key:"color",label:"文字颜色"},{key:"background",label:"背景"},{key:"opacity",label:"Opacity"},{key:"fontFamily",label:"字体"}];function z7(U){let K=window.getComputedStyle(U);return{text:U.textContent??"",color:K.color,background:K.backgroundColor,opacity:K.opacity,fontFamily:K.fontFamily}}function D7(U,K){let z={};if(K.text!==U.text)z.text={from:U.text,to:K.text};if(K.color!==U.color)z.color={from:U.color,to:K.color};if(K.background!==U.background)z.background={from:U.background,to:K.background};if(K.opacity!==U.opacity)z.opacity={from:U.opacity,to:K.opacity};if(K.fontFamily!==U.fontFamily)z.fontFamily={from:U.fontFamily,to:K.fontFamily};return z}function W7(U,K){let z={};if(U==="text")z.text=K;else if(U==="color")z.color=K;else if(U==="background")z.background=K;else if(U==="opacity")z.opacity=K;else if(U==="fontFamily")z.fontFamily=K;return z}function kQ(U,K){let z=z7(U),W={...z},R="",P=document.createElement("div"),C=U.getBoundingClientRect(),d=Math.max(8,Math.min(C.bottom+8,window.innerHeight-380)),c=Math.max(8,Math.min(C.left,window.innerWidth-356));P.style.cssText=`position:fixed;top:${d}px;left:${c}px;z-index:2147483647`;let k=P.attachShadow({mode:"open"}),f=document.createElement("div");f.setAttribute("style","width:340px;box-sizing:border-box;background:#fff;border-radius:14px;box-shadow:0 10px 34px rgba(0,0,0,.2);padding:12px;font:13px/1.45 -apple-system,system-ui,sans-serif;color:#111");let W1=document.createElement("input");W1.setAttribute("data-field","description"),W1.placeholder="描述这些更改…",W1.setAttribute("style","width:100%;box-sizing:border-box;border:none;outline:none;font-size:14px;padding:6px 4px"),W1.addEventListener("input",()=>{R=W1.value}),f.appendChild(W1);let Y0=document.createElement("div");Y0.textContent=U.tagName.toLowerCase(),Y0.setAttribute("style","color:#8a8a8a;border-top:1px solid #eee;margin-top:6px;padding:8px 4px 4px;font-weight:600"),f.appendChild(Y0);for(let B1 of F7){let s1=document.createElement("label");s1.setAttribute("style","display:flex;align-items:center;gap:10px;padding:5px 4px");let X0=document.createElement("span");X0.textContent=B1.label,X0.setAttribute("style","width:74px;color:#555;flex:none");let N1=document.createElement("input");N1.setAttribute("data-field",B1.key),N1.value=z[B1.key],N1.setAttribute("style","flex:1;min-width:0;border:1px solid #e2e2e2;border-radius:8px;padding:5px 9px;font:inherit");let K1=B1.key;N1.addEventListener("input",()=>{W[K1]=N1.value,W6(U,W7(K1,N1.value))}),s1.appendChild(X0),s1.appendChild(N1),f.appendChild(s1)}let O1=document.createElement("div");O1.setAttribute("style","display:flex;justify-content:space-between;align-items:center;margin-top:12px");let w1=document.createElement("button");w1.setAttribute("data-action","cancel"),w1.textContent="取消",w1.setAttribute("style","border:none;background:#f1f1f1;border-radius:18px;padding:7px 16px;cursor:pointer;font:inherit");let $1=document.createElement("button");return $1.setAttribute("data-action","confirm"),$1.textContent="✓",$1.setAttribute("style","border:none;background:#2f7bff;color:#fff;border-radius:50%;width:34px;height:34px;cursor:pointer;font-size:16px"),w1.addEventListener("click",()=>{W6(U,z),K.onCancel()}),$1.addEventListener("click",()=>{K.onConfirm({...D7(z,W),description:R||void 0})}),O1.appendChild(w1),O1.appendChild($1),f.appendChild(O1),k.appendChild(f),document.documentElement.appendChild(P),{host:P,destroy:()=>{P.remove()}}}(()=>{window.__PREVIEW_AGENT__=!0;let K=AQ({postToHost:(c)=>{let k=window.__TAURI_INTERNALS__;if(k?.invoke)k.invoke("preview_message",{raw:c})},location:window.location,title:document.title});window.__PREVIEW_BRIDGE__=K,window.__PREVIEW_AGENT_CAPTURE__=D6,K.on("capture",async(c)=>{try{K.send({type:"screenshot",dataUrl:await D6(c.kind),kind:c.kind})}catch(k){K.reportError(String(k))}});let z=!1,W=null,R=SQ({onSelect:()=>{}}),P=()=>{W?.destroy(),W=null,z=!1,R.exit(),K.send({type:"picker-exited"})},C=async(c,k)=>{try{let f=await wQ(c);K.send({type:"selection",payload:{pageUrl:window.location.href,sourceHint:document.title||void 0,element:fQ(c),change:k,screenshot:{dataUrl:f,kind:"region"}}})}catch(f){K.reportError(String(f))}};K.on("enter-picker",()=>{z=!0,R.enter()}),K.on("exit-picker",()=>{P()}),document.addEventListener("mousemove",(c)=>{if(!z)return;let k=c.target;if(k instanceof Element)R.hover(k)},!0),document.addEventListener("click",(c)=>{if(!z||W)return;c.preventDefault(),c.stopPropagation(),R.select();let k=R.current();if(z=!1,!(k instanceof HTMLElement)){P();return}W=kQ(k,{onConfirm:(f)=>{P(),C(k,f)},onCancel:()=>{P()}})},!0);let d=()=>{K.reportReady(),K.reportNavigated()};if(document.readyState!=="loading")d();else document.addEventListener("DOMContentLoaded",d);window.addEventListener("popstate",()=>K.reportNavigated())})();})(); diff --git a/desktop/src/components/browser/BrowserSurface.tsx b/desktop/src/components/browser/BrowserSurface.tsx index 73221b56..bd2e4c46 100644 --- a/desktop/src/components/browser/BrowserSurface.tsx +++ b/desktop/src/components/browser/BrowserSurface.tsx @@ -102,10 +102,11 @@ export function BrowserSurface({ sessionId }: { sessionId: string }) { previewBridge.navigate(session.url) }} /> -
+
+ {hasSelectionNote && ( + + + ads_click + + {attachment.name} + + )} {onRemove && attachment.id && (