framer-plugin
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -1010,3 +1010,3 @@ import React, { RefObject } from 'react'; | ||
constructor(data: ImageAssetData, api: FramerAPI); | ||
cloneWithAttributes({ altText }: Prettify<Partial<Pick<ImageAssetData, "altText">>>): Promise<ImageAsset>; | ||
cloneWithAttributes({ altText }: Prettify<Partial<Pick<ImageAssetData, "altText">>>): ImageAsset; | ||
measure(): Promise<Size>; | ||
@@ -1013,0 +1013,0 @@ /** |
var bt=Object.defineProperty;var Pt=(n,e,t)=>e in n?bt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>(Pt(n,typeof e!="symbol"?e+"":e,t),t),Oe=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var r=(n,e,t)=>(Oe(n,e,"read from private field"),t?t.call(n):e.get(n)),c=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},m=(n,e,t,i)=>(Oe(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t);var xe=(n,e,t,i)=>({set _(s){m(n,e,s,t)},get _(){return r(n,e,i)}});import H from"react";import{useCallback as Et,useEffect as Mt,useRef as Bt}from"react";function P(n){return n===null}function Te(n){return n===!0||n===!1}function d(n){return typeof n=="string"}function le(n){return typeof n=="number"&&Number.isFinite(n)}function de(n){return typeof n=="function"}function h(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function Ne(n){return Array.isArray(n)}function S(n,e){throw e||new Error(n?`Unexpected value: ${n}`:"Application entered invalid state")}function l(n,...e){if(n)return;let t=Error("Assertion Error"+(e.length>0?": "+e.join(" "):""));if(t.stack)try{let i=t.stack.split(` | ||
`);i[1]?.includes("assert")?(i.splice(1,1),t.stack=i.join(` | ||
`)):i[0]?.includes("assert")&&(i.splice(0,1),t.stack=i.join(` | ||
`))}catch{}throw t}var Ue="__class",Ie="LinearGradient",Ce="RadialGradient",ve="ConicGradient";function ue(n){if(!h(n))return!1;switch(n[Ue]){case Ie:case Ce:case ve:return!0;default:return!1}}function X(n){return n instanceof V||n instanceof G||n instanceof E}function _e(n){if(n instanceof V)return{__class:Ie,angle:n.angle,stops:n.stops};if(n instanceof G)return{__class:Ce,width:n.width,height:n.height,x:n.x,y:n.y,stops:n.stops};if(n instanceof E)return{__class:ve,angle:n.angle,x:n.x,y:n.y,stops:n.stops};S(n)}function ce(n){switch(n[Ue]){case Ie:return new V(n);case Ce:return new G(n);case ve:return new E(n);default:S(n)}}var V=class n{constructor(e){o(this,"angle");o(this,"stops");this.angle=e.angle,this.stops=e.stops,Object.freeze(this)}cloneWithAttributes(e){return new n({angle:e.angle??this.angle,stops:e.stops??this.stops})}toCSS(){let e=this.stops.map(t=>`${t.color} ${t.position*100}%`).join(", ");return`linear-gradient(${this.angle}deg, ${e})`}},G=class n{constructor(e){o(this,"width");o(this,"height");o(this,"x");o(this,"y");o(this,"stops");this.width=e.width,this.height=e.height,this.x=e.x,this.y=e.y,this.stops=e.stops,Object.freeze(this)}cloneWithAttributes(e){return new n({width:e.width??this.width,height:e.height??this.height,x:e.x??this.x,y:e.y??this.y,stops:e.stops??this.stops})}toCSS(){let e=this.stops.map((t,i)=>{let s=this.stops[i+1],a=t.position===1&&s?.position===1?t.position-1e-4:t.position;return`${t.color} ${a*100}%`}).join(", ");return`radial-gradient(${this.width} ${this.height} at ${this.x} ${this.y}, ${e})`}},E=class n{constructor(e){o(this,"angle");o(this,"x");o(this,"y");o(this,"stops");this.angle=e.angle,this.x=e.x,this.y=e.y,this.stops=e.stops,Object.freeze(this)}cloneWithAttributes(e){return new n({angle:e.angle??this.angle,x:e.x??this.x,y:e.y??this.y,stops:e.stops??this.stops})}toCSS(){let e=this.stops.map(t=>`${t.color} ${t.position*360}deg`).join(", ");return`conic-gradient(from ${this.angle}deg at ${this.x} ${this.y}, ${e})`}};var xt="invoke";function x(n){return xt in n}var Tt="ImageAsset",Nt="__class";function me(n){return h(n)?n[Nt]===Tt:!1}var k,M,ke=class ke{constructor(e,t){o(this,"id");o(this,"url");o(this,"thumbnailUrl");o(this,"altText");c(this,k,void 0);c(this,M,void 0);l(x(t)),this.url=e.url,m(this,M,t),this.id=e.id,this.thumbnailUrl=e.thumbnailUrl,this.altText=e.altText}async cloneWithAttributes({altText:e}){return new ke({__class:"ImageAsset",id:this.id,url:this.url,thumbnailUrl:this.thumbnailUrl,altText:e!==void 0?e:this.altText},r(this,M))}async measure(){return St(this.url)}async getData(){if(r(this,k)&&r(this,k).bytes.length>0)return r(this,k);let e=await r(this,M).invoke("getImageData",{id:this.id});if(!e)throw new Error("Failed to load image data");return m(this,k,e),e}async loadBitmap(){let{mimeType:e,bytes:t}=await this.getData(),i=new Blob([t],{type:e});return createImageBitmap(i)}async loadImage(){let e=await this.getData(),t=URL.createObjectURL(new Blob([e.bytes]));return new Promise((i,s)=>{let a=new Image;a.onload=()=>i(a),a.onerror=()=>s(),a.src=t})}};k=new WeakMap,M=new WeakMap;var y=ke;function It(n){return n instanceof y}function B(n){return n.type==="bytes"?[n.bytes.buffer]:[]}function Ct(n){if(!h(n))return!1;let e="bytes",t="mimeType";return!(!(e in n)||!(t in n)||!(n[e]instanceof Uint8Array)||!d(n[t]))}async function Y(n){return n instanceof File?ze(n):n.image instanceof File?ze(n.image):Ct(n.image)?{name:n.name,altText:n.altText,type:"bytes",mimeType:n.image.mimeType,bytes:n.image.bytes}:{name:n.name,altText:n.altText,type:"url",url:n.image}}function Se(n){return Promise.all(n.map(Y))}function vt(n){if(!n.startsWith("image/"))throw new Error(`Unsupported mime type: ${n}`)}async function ze(n){return new Promise((e,t)=>{let i=new FileReader;i.onload=s=>{let a=n.type;vt(n.type);let u=s.target?.result;if(!u||!(u instanceof ArrayBuffer)){t(new Error("Failed to read file, arrayBuffer is null"));return}let C=new Uint8Array(u);e({bytes:C,mimeType:a,type:"bytes"})},i.onerror=s=>{t(s)},i.readAsArrayBuffer(n)})}async function St(n){let e=n instanceof File,t=e?URL.createObjectURL(n):n,i=new Image;return i.crossOrigin="anonymous",i.src=t,await i.decode().finally(()=>{e&&URL.revokeObjectURL(t)}),{height:i.height,width:i.width}}function A(n){if(At(n))return Dt(n);if(Ne(n))return n.map(A);if(h(n)){let e={};for(let t in n)e[t]=A(n[t]);return e}return n}function He(n,e){let t={};for(let i in n)t[i]=Ae(n[i],e);return t}function Ae(n,e){if(kt(n))switch(n.__class){case"ImageAsset":return new y(n,e);case"LinearGradient":case"RadialGradient":case"ConicGradient":return ce(n);default:S(n)}if(h(n)){let t={};for(let i in n)t[i]=Ae(n[i],e);return t}return Ne(n)?n.map(t=>Ae(t,e)):n}function kt(n){return!!(me(n)||ue(n))}function At(n){return!!(n instanceof y||X(n))}function Dt(n){if(n instanceof y)return{__class:"ImageAsset",id:n.id,thumbnailUrl:n.thumbnailUrl,url:n.url,altText:n.altText};if(X(n))return _e(n);S(n)}var b,ge=class{constructor(e,t){o(this,"id");o(this,"name");c(this,b,void 0);l(d(e.id),"Node must have an id"),l(d(e.name),"Node must have a name"),this.id=e.id,this.name=e.name,l(x(t)),m(this,b,t),Object.freeze(this)}async getItemIds(){return r(this,b).invoke("getCollectionItemIds",this.id)}async setItemOrder(e){return r(this,b).invoke("setCollectionItemOrder",this.id,e)}async getFields(){return r(this,b).invoke("getCollectionFields",this.id)}async setFields(e){return r(this,b).invoke("setCollectionFields",this.id,e)}async addItems(e){return r(this,b).invoke("addCollectionItems",this.id,e)}async removeItems(e){return r(this,b).invoke("removeCollectionItems",this.id,e)}async setPluginData(e,t){return r(this,b).invoke("setPluginDataForNode",this.id,e,t)}async getPluginData(e){return r(this,b).invoke("getPluginDataForNode",this.id,e)}async getPluginDataKeys(){return r(this,b).invoke("getPluginDataKeysForNode",this.id)}};b=new WeakMap;var Wt=(()=>{let n=null;return{disableUntilMouseUp:()=>{if(n)return;n=document.createElement("style"),n.textContent="* { pointer-events: none !important; user-select: none !important; -webkit-user-select: none !important; }",document.head.appendChild(n);let e=()=>{n&&(document.head.removeChild(n),n=null,s())},t=a=>{a.buttons>0&&a.buttons&1||e()},i=()=>{e()};window.addEventListener("pointerup",t,!0),window.addEventListener("pointermove",t,!0),window.addEventListener("blur",i);function s(){window.removeEventListener("pointerup",t,!0),window.removeEventListener("pointermove",t,!0),window.removeEventListener("blur",i)}}}})(),Ke=5,wt=(()=>{let n=1;return{next:()=>`drag-${n++}`}})();function Rt(){}function je(n,e,t){if(n.mode!=="default")return Rt;l(x(n));let i=wt.next(),s=document.body.style.cursor,a={type:"idle"},u=document.body,C=p=>{a.type!=="idle"&&(a.type==="dragging"&&n.invoke("onDragEnd",{...p,dragSessionId:i}),a={type:"idle"},ft())},oe=p=>{if(a.type==="idle")return;if(!(p.buttons>0&&!!(p.buttons&1))){C({cancelled:!1});return}let{clientX:re,clientY:j}=p;if(a.type==="pointerDown"){let $=re-a.dragStart.mouse.x,Be=j-a.dragStart.mouse.y;if(Math.abs($)<Ke&&Math.abs(Be)<Ke)return;a={type:"dragging",dragStart:a.dragStart},n.invoke("onDragStart",a.dragStart),document.getSelection()?.empty(),Wt.disableUntilMouseUp()}u.setPointerCapture(p.pointerId);let se={x:re,y:j};n.invoke("onDrag",{dragSessionId:i,mouse:se}).then($=>{a.type==="dragging"&&(document.body.style.cursor=$??"")})},Ve=p=>{p.key==="Escape"&&C({cancelled:!0})},Ge=()=>{C({cancelled:!0})},Ee=p=>{C({cancelled:!0});let K=e.getBoundingClientRect(),re={x:K.x,y:K.y,width:K.width,height:K.height},j,se=e.querySelectorAll("svg");if(se.length===1){let ae=se.item(0).getBoundingClientRect();j={x:ae.x,y:ae.y,width:ae.width,height:ae.height}}let $={x:p.clientX,y:p.clientY};a={type:"pointerDown",dragStart:{dragSessionId:i,elementRect:re,svgRect:j,mouse:$}},n.invoke("setDragData",i,t()),u.addEventListener("pointermove",oe,!0),u.addEventListener("pointerup",oe,!0),window.addEventListener("keydown",Ve,!0),window.addEventListener("blur",Ge)},Me=()=>{let p=t();p.type==="detachedComponentLayers"&&n.invoke("preloadDetachedComponentLayers",p.url),p.type==="image"&&n.invoke("preloadImageUrlForInsertion",p.image),p.previewImage&&n.invoke("preloadDragPreviewImage",p.previewImage)};e.addEventListener("pointerdown",Ee),e.addEventListener("mouseenter",Me);function ft(){document.body.style.cursor=s,u.removeEventListener("pointermove",oe,!0),u.removeEventListener("pointerup",oe,!0),window.removeEventListener("keydown",Ve,!0),window.removeEventListener("blur",Ge)}return()=>{e.removeEventListener("pointerdown",Ee),e.removeEventListener("mouseenter",Me),C({cancelled:!0})}}var q=class extends Error{};var Ft={default:!0,image:!0,editImage:!0,configureCollection:!0,syncCollection:!0};function $e(n){return d(n)&&n in Ft}var Lt={methodResponse:!0,pluginReadyResponse:!0,subscriptionMessage:!0};function Vt(n){return d(n)&&n in Lt}function Xe(n){return h(n)&&Vt(n["type"])}var ie,f,T,v=class{constructor(e,t){o(this,"id");c(this,ie,void 0);c(this,f,void 0);c(this,T,void 0);l(d(e.id),"Node must have an id"),this.id=e.id,m(this,f,t),m(this,ie,e.originalId??null),l(x(t)),m(this,T,t)}get isReplica(){return r(this,ie)!==null}remove(){return r(this,f).removeNode(this.id)}select(){return r(this,f).setSelection([this.id])}clone(){return r(this,f).cloneNode(this.id)}setAttributes(e){return r(this,f).setAttributes(this.id,e)}getRect(){return r(this,f).getRect(this.id)}zoomIntoView(e){return r(this,f).zoomIntoView([this.id],e)}getParent(){return r(this,f).getParent(this.id)}getChildren(){return D(this)?Promise.resolve([]):r(this,f).getChildren(this.id)}async getNodesWithType(e){return D(this)?Promise.resolve([]):(await r(this,T).invoke("getNodesWithType",this.id,e)).map(i=>g(i,r(this,f)))}async getNodesWithAttribute(e){return D(this)?Promise.resolve([]):(await r(this,T).invoke("getNodesWithAttribute",this.id,e)).map(i=>g(i,r(this,f)))}async getNodesWithAttributeSet(e){return D(this)?Promise.resolve([]):(await r(this,T).invoke("getNodesWithAttributeSet",this.id,e)).map(i=>g(i,r(this,f)))}async*walk(){if(yield this,!D(this))for(let e of await this.getChildren())yield*e.walk()}async getPluginData(e){return r(this,T).invoke("getPluginDataForNode",this.id,e)}async setPluginData(e,t){return r(this,T).invoke("setPluginDataForNode",this.id,e,t)}async getPluginDataKeys(){return r(this,T).invoke("getPluginDataKeysForNode",this.id)}};ie=new WeakMap,f=new WeakMap,T=new WeakMap;var W=class extends v{constructor(t,i){super(t,i);o(this,"__class","FrameNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"backgroundColor");o(this,"backgroundImage");o(this,"backgroundGradient");o(this,"rotation");o(this,"opacity");o(this,"borderRadius");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");o(this,"maxWidth");o(this,"minWidth");o(this,"maxHeight");o(this,"minHeight");o(this,"aspectRatio");l(t.__class==="FrameNode","FrameNode must have a __class property"),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.backgroundColor=t.backgroundColor??null,this.backgroundImage=t.backgroundImage?new y(t.backgroundImage,i):null,this.rotation=t.rotation??0,this.opacity=t.opacity??1,this.borderRadius=t.borderRadius??null,this.backgroundGradient=ue(t.backgroundGradient)?ce(t.backgroundGradient):null,l(t.position,"Must have a position"),this.position=t.position,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,this.maxWidth=t.maxWidth??null,this.minWidth=t.minWidth??null,this.maxHeight=t.maxHeight??null,this.minHeight=t.minHeight??null,this.aspectRatio=t.aspectRatio??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},O,Z=class extends v{constructor(t,i){super(t,i);o(this,"__class","TextNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"rotation");o(this,"opacity");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");o(this,"maxWidth");o(this,"minWidth");o(this,"maxHeight");o(this,"minHeight");c(this,O,void 0);l(x(i)),m(this,O,i),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.rotation=t.rotation??0,this.opacity=t.opacity??1,l(t.position,"Must have a position"),this.position=t.position,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,this.maxWidth=t.maxWidth??null,this.minWidth=t.minWidth??null,this.maxHeight=t.maxHeight??null,this.minHeight=t.minHeight??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}async setText(t){await r(this,O).invoke("setTextForNode",this.id,t)}async getText(){return r(this,O).invoke("getTextForNode",this.id)}};O=new WeakMap;var Q=class extends v{constructor(t,i){super(t,i);o(this,"__class","SVGNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"svg");o(this,"rotation");o(this,"opacity");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");l(t.svg,"SVG node must have a non-empty SVG string"),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.svg=t.svg,this.rotation=t.rotation??0,this.opacity=t.opacity??1,l(t.position,"Must have a position"),this.position=t.position??null,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},J=class extends v{constructor(t,i){super(t,i);o(this,"__class","ComponentInstanceNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"componentIdentifier");o(this,"controls");o(this,"rotation");o(this,"opacity");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");o(this,"maxWidth");o(this,"minWidth");o(this,"maxHeight");o(this,"minHeight");o(this,"aspectRatio");l(t.componentIdentifier,"ComponentInstance node must have a component identifier"),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.componentIdentifier=t.componentIdentifier,this.controls=He(t.controls??{},i),this.rotation=t.rotation??0,this.opacity=t.opacity??1,l(t.position,"Must have a position"),this.position=t.position,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,this.maxWidth=t.maxWidth??null,this.minWidth=t.minWidth??null,this.maxHeight=t.maxHeight??null,this.minHeight=t.minHeight??null,this.aspectRatio=t.aspectRatio??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},ee=class extends v{constructor(t,i){super(t,i);o(this,"_class","WebPageNode");Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},te=class extends v{constructor(t,i){super(t,i);o(this,"__class","ComponentNode");o(this,"name");this.name=t.name??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},ne=class extends v{constructor(t,i){super(t,i);o(this,"__class","UnknownNode");Object.freeze(this)}clone(){throw Error("Can not clone unknown node")}setAttributes(t){throw Error("Can not set attributes on unknown node")}};function g(n,e){switch(n.__class){case"WebPageNode":return new ee(n,e);case"ComponentNode":return new te(n,e);case"ComponentInstanceNode":return new J(n,e);case"FrameNode":return new W(n,e);case"SVGNode":return new Q(n,e);case"TextNode":return new Z(n,e);case"UnknownNode":return new ne(n,e);default:return new ne(n,e)}}function De(n){return A(n)}function pe(n){return n instanceof W}function Ye(n){return n instanceof Z}function qe(n){return n instanceof Q}function he(n){return n instanceof J}function Ze(n){return n instanceof ee}function Qe(n){return n instanceof te}function D(n){return n instanceof ne}function ye(n){return!!(pe(n)||Ye(n)||he(n)||qe(n)||D(n))}function We(n){return!!(Ze(n)||Qe(n)||D(n))}var N,we=class we{constructor(e,t){o(this,"id");o(this,"name");o(this,"light");o(this,"dark");c(this,N,void 0);l(d(e.id),"Node must have an id"),this.id=e.id,this.name=e.name,this.light=e.light,this.dark=e.dark,l(x(t)),m(this,N,t)}async setAttributes(e){let t=await r(this,N).invoke("setColorStyleAttributes",this.id,e);return t?new we(t,r(this,N)):null}async getPluginData(e){return r(this,N).invoke("getPluginDataForNode",this.id,e)}async setPluginData(e,t){return r(this,N).invoke("setPluginDataForNode",this.id,e,t)}async getPluginDataKeys(){return r(this,N).invoke("getPluginDataKeysForNode",this.id)}async remove(){return r(this,N).invoke("removeColorStyle",this.id)}};N=new WeakMap;var w=we,I,Re=class Re{constructor(e,t){o(this,"id");o(this,"name");o(this,"tag");o(this,"color");o(this,"transform");o(this,"alignment");o(this,"decoration");o(this,"balance");o(this,"breakpoints");o(this,"minWidth");o(this,"fontSize");o(this,"letterSpacing");o(this,"lineHeight");o(this,"paragraphSpacing");c(this,I,void 0);l(d(e.id),"Node must have an id"),this.id=e.id,this.name=e.name,this.tag=e.tag,this.color=e.color,this.transform=e.transform,this.alignment=e.alignment,this.decoration=e.decoration,this.balance=e.balance,this.breakpoints=e.breakpoints,this.minWidth=e.minWidth,this.fontSize=e.fontSize,this.letterSpacing=e.letterSpacing,this.lineHeight=e.lineHeight,this.paragraphSpacing=e.paragraphSpacing,l(x(t)),m(this,I,t)}async setAttributes(e){let t=await r(this,I).invoke("setTextStyleAttributes",this.id,e);return new Re(t,r(this,I))}async getPluginData(e){return r(this,I).invoke("getPluginDataForNode",this.id,e)}async setPluginData(e,t){return r(this,I).invoke("setPluginDataForNode",this.id,e,t)}async getPluginDataKeys(){return r(this,I).invoke("getPluginDataKeysForNode",this.id)}async remove(){return r(this,I).invoke("removeTextStyle",this.id)}};I=new WeakMap;var R=Re;var U=null;function Je(n){if(!U){let t=document.createElement("style");document.head.appendChild(t),U=t.sheet}if(!U){n();return}let e=U.insertRule("* { transition: none !important; animation: none !important; }");n(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{U&&U.deleteRule(e)})})}var Gt=1,be,Pe,_,F,z,L,fe=class{constructor({isTestEnv:e}={}){c(this,be,0);c(this,Pe,0);c(this,_,[]);c(this,F,void 0);c(this,z,new Map);c(this,L,void 0);o(this,"subscriptions",new Map);o(this,"onMessage",e=>{let t=e.data;if(Xe(t))switch(t.type){case"pluginReadyResponse":{if(!e.source)throw new Error("No 'source' on incoming message: "+t.type);l(r(this,L)===t.mode,"Mode must match"),this.applyPluginTheme(t.theme),m(this,F,(s,a)=>window.parent.postMessage(s,e.origin,a));for(let s of r(this,_))r(this,F).call(this,...s);m(this,_,[]);break}case"methodResponse":{let i=r(this,z).get(t.id);if(!i)throw new Error(`No handler for response with id ${t.id}`);r(this,z).delete(t.id),t.error?i.reject(new q(t.error)):i.resolve(t.result);break}case"subscriptionMessage":{let{topic:i,payload:s}=t,a=this.subscriptions.get(i);if(!a)throw new Error("Received a subscription message but no handler present");for(let u of a)u(s);break}default:S(t)}});o(this,"applyPluginTheme",e=>{Je(()=>{document.body.setAttribute("data-framer-theme",e.mode);for(let t in e.tokens)document.body.style.setProperty(t,e.tokens[t])})});if(e){m(this,L,"default");return}let i=new URL(window.location.href).searchParams.get("mode");l($e(i),`Invalid mode: ${i}`),m(this,L,i),window.addEventListener("message",this.onMessage);let s={type:"pluginReadySignal",breakingChangesVersion:Gt};window.parent.postMessage(s,"*"),this.subscribe("theme",this.applyPluginTheme),window.addEventListener("pointerdown",()=>{this.invoke("onPointerDown")})}get mode(){return r(this,L)}invoke(e,...t){return this.invokeTransferable(e,void 0,...t)}invokeTransferable(e,t,...i){return new Promise((s,a)=>{let u={args:i,methodName:e,id:xe(this,be)._++,type:"methodInvocation"},C=s;r(this,z).set(u.id,{resolve:C,reject:a}),this.queueMessage(u,t)})}subscribe(e,t){this.queueMessage({type:"subscribe",topic:e});let i=this.subscriptions.get(e)??new Set;return i.add(t),this.subscriptions.set(e,i),()=>{let s=this.subscriptions.get(e)??new Set;s.delete(t),s.size===0&&this.queueMessage({type:"unsubscribe",topic:e}),this.subscriptions.set(e,s)}}queueMessage(e,t){if(!r(this,F)){r(this,_).push([e,t]);return}r(this,F).call(this,e,t)}async showUI(e){return this.invoke("showUI",e)}async hideUI(){return this.invoke("hideUI")}async closePlugin(e,t){return this.invoke("closePlugin",e,t)}async getCurrentUser(){return this.invoke("getCurrentUser")}async getSelection(){return(await this.invoke("getSelection")).map(t=>{let i=g(t,this);return l(ye(i)),i})}async setSelection(e){let t=d(e)?[e]:Array.from(e);return this.invoke("setSelection",t)}subscribeToSelection(e){return this.subscribe("selection",t=>{let i=t.map(s=>{let a=g(s,this);return l(ye(a)),a});e(i)})}async getCanvasRoot(){let e=await this.invoke("getCanvasRoot"),t=g(e,this);return l(We(t)),t}subscribeToCanvasRoot(e){return this.subscribe("canvasRoot",t=>{let i=g(t,this);l(We(i)),e(i)})}async getPublishInfo(){return this.invoke("getPublishInfo")}subscribeToPublishInfo(e){return this.subscribe("publishInfo",e)}async createFrameNode(e,t){let i=De(e),s=await this.invoke("createNode","FrameNode",t??null,i);if(!s)return null;let a=g(s,this);return l(a instanceof W),a}async removeNode(e){return this.invoke("removeNode",e)}async cloneNode(e){let t=await this.invoke("cloneNode",e);return t?g(t,this):null}async getNode(e){let t=await this.invoke("getNode",e);return t?g(t,this):null}async getParent(e){let t=await this.invoke("getParent",e);return t?g(t,this):null}async getChildren(e){return(await this.invoke("getChildren",e)).map(i=>{let s=g(i,this);return l(ye(s)),s})}async getRect(e){return this.invoke("getRect",e)}async zoomIntoView(e,t){let i=d(e)?[e]:Array.from(e);return this.invoke("zoomIntoView",i,t)}async setAttributes(e,t){let i=De(t),s=await this.invoke("setAttributes",e,i);return s?g(s,this):null}async setParent(e,t,i){return this.invoke("setParent",e,t,i)}async getNodesWithType(e){return(await this.invoke("getNodesWithType",null,e)).map(i=>g(i,this))}async getNodesWithAttribute(e){return(await this.invoke("getNodesWithAttribute",null,e)).map(i=>g(i,this))}async getNodesWithAttributeSet(e){return(await this.invoke("getNodesWithAttributeSet",null,e)).map(i=>g(i,this))}async getImage(){let e=await this.invoke("getImage");return e?new y(e,this):null}subscribeToImage(e){return this.subscribe("image",t=>{if(!t){e(null);return}e(new y(t,this))})}async addImage(e){let t=await Y(e),i=B(t);return this.invokeTransferable("addImage",i,t)}async setImage(e){let t=await Y(e),i=B(t);return this.invokeTransferable("setImage",i,t)}async uploadImage(e){let t=await Y(e),i=B(t),s=await this.invokeTransferable("uploadImage",i,t);return new y(s,this)}async addImages(e){let t=await Se(e),i=t.flatMap(B);await this.invokeTransferable("addImages",i,t)}async uploadImages(e){let t=await Se(e),i=t.flatMap(B),s=await this.invokeTransferable("uploadImages",i,t),a=[];for(let u of s)a.push(new y(u,this));return a}async addSVG(e){return this.invoke("addSVG",e)}async addComponentInstance({url:e,attributes:t}){let i=A(t),s=await this.invoke("addComponentInstance",{url:e,attributes:h(i)?i:void 0}),a=g(s,this);return l(he(a)),a}async addDetachedComponentLayers({url:e,layout:t,attributes:i}){let s=A(i),a=await this.invoke("addDetachedComponentLayers",{url:e,layout:t,attributes:h(s)?s:void 0}),u=g(a,this);return l(pe(u)),u}async preloadDetachedComponentLayers(e){await this.invoke("preloadDetachedComponentLayers",e)}async preloadImageUrlForInsertion(e){await this.invoke("preloadImageUrlForInsertion",e)}async preloadDragPreviewImage(e){await this.invoke("preloadDragPreviewImage",e)}async getText(){return this.invoke("getText")}async setText(e){return this.invoke("setText",e)}async addText(e,t){return this.invoke("addText",e,t)}async setCustomCode(e){return this.invoke("setCustomCode",e)}async getCustomCode(){return this.invoke("getCustomCode")}subscribeToCustomCode(e){return this.subscribe("customCode",e)}subscribeToText(e){return this.subscribe("text",e)}makeDraggable(e,t){return je(this,e,t)}async getCollection(){let e=await this.invoke("getCollection");return l(e,"Collection data must be defined"),new ge(e,this)}notify(e,t){let i=`notification-${xe(this,Pe)._++}`;return this.invoke("notify",e,{notificationId:i,variant:t?.variant??"info",buttonText:t?.button?.text,durationMs:t?.durationMs}).then(s=>{s==="actionButtonClicked"&&t?.button?.onClick&&t.button.onClick(),t?.onDisappear&&t.onDisappear()}),{close:()=>this.invoke("closeNotification",i)}}async getPluginData(e){return this.invoke("getPluginData",e)}async setPluginData(e,t){return this.invoke("setPluginData",e,t)}async getPluginDataKeys(){return this.invoke("getPluginDataKeys")}async getColorStyles(){return(await this.invoke("getColorStyles")).map(t=>new w(t,this))}async getColorStyle(e){let t=await this.invoke("getColorStyle",e);return t?new w(t,this):null}async createColorStyle(e){let t=await this.invoke("createColorStyle",e);return new w(t,this)}subscribeToColorStyles(e){return this.subscribe("colorStyles",t=>{let i=t.map(s=>new w(s,this));return e(i)})}async getTextStyles(){return(await this.invoke("getTextStyles")).map(t=>new R(t,this))}async getTextStyle(e){let t=await this.invoke("getTextStyle",e);return t?new R(t,this):null}async createTextStyle(e){let t=await this.invoke("createTextStyle",e);return new R(t,this)}subscribeToTextStyles(e){return this.subscribe("textStyles",t=>{let i=t.map(s=>new R(s,this));return e(i)})}};be=new WeakMap,Pe=new WeakMap,_=new WeakMap,F=new WeakMap,z=new WeakMap,L=new WeakMap;var Fe=new fe;function Le(n,e){let t=Ot(()=>de(e)?e():e);Mt(()=>{let i=n.current;if(i instanceof HTMLElement)return Fe.makeDraggable(i,t)},[t])}function Ot(n){let e=Bt(n);return e.current=n,Et((...t)=>e.current(...t),[])}var Ut=H.forwardRef(function({data:e,children:t,...i},s){let a=H.useRef(null);if(Le(a,e),H.isValidElement(t)){let u=Object.assign({},i);return h(t.props)&&Object.assign(u,t.props),u.ref=Ht(a,s,t.ref),H.cloneElement(t,u)}return H.Children.count(t)>1&&H.Children.only(t),null}),_t="current";function zt(n){return h(n)&&_t in n}function Ht(...n){return e=>{for(let t of n)de(t)?t(e):zt(t)&&(t.current=e)}}var Kt={fixed:!0,sticky:!0,absolute:!0,relative:!0},et="position";function ni(n){if(!(et in n))return!1;let e=n[et];return d(e)&&Kt[e]===!0}var tt="top";function ii(n){if(!(tt in n))return!1;let e=n[tt];return d(e)||P(e)}var nt="width";function oi(n){if(!(nt in n))return!1;let e=n[nt];return d(e)||P(e)}var it="maxWidth";function ri(n){if(!(it in n))return!1;let e=n[it];return d(e)||P(e)}var ot="aspectRatio";function si(n){if(!(ot in n))return!1;let e=n[ot];return le(e)||P(e)}var rt="name";function ai(n){if(!(rt in n))return!1;let e=n[rt];return d(e)||P(e)}var st="visible";function li(n){if(!(st in n))return!1;let e=n[st];return Te(e)}var at="locked";function di(n){if(!(at in n))return!1;let e=n[at];return Te(e)}var lt="backgroundColor";function ui(n){if(!(lt in n))return!1;let e=n[lt];return d(e)||P(e)}var dt="backgroundImage";function ci(n){if(!(dt in n))return!1;let e=n[dt];return e instanceof y||P(e)}var ut="backgroundImage";function mi(n){if(!(ut in n))return!1;let e=n[ut];return e instanceof y?!1:me(e)||P(e)}var ct="backgroundGradient";function gi(n){if(!(ct in n))return!1;let e=n[ct];return X(e)||P(e)}var mt="backgroundGradient";function pi(n){if(!(mt in n))return!1;let e=n[mt];return h(e)||P(e)}var gt="rotation";function hi(n){if(!(gt in n))return!1;let e=n[gt];return le(e)}var pt="opacity";function yi(n){if(!(pt in n))return!1;let e=n[pt];return le(e)}var ht="borderRadius";function fi(n){if(!(ht in n))return!1;let e=n[ht];return d(e)||P(e)}var yt="svg";function bi(n){if(!(yt in n))return!1;let e=n[yt];return d(e)}export{J as ComponentInstanceNode,te as ComponentNode,E as ConicGradient,Ut as Draggable,W as FrameNode,q as FramerPluginError,V as LinearGradient,G as RadialGradient,Q as SVGNode,Z as TextNode,ee as WebPageNode,Fe as framer,he as isComponentInstanceNode,Qe as isComponentNode,pe as isFrameNode,It as isImageAsset,qe as isSVGNode,Ye as isTextNode,Ze as isWebPageNode,si as supportsAspectRatio,ui as supportsBackgroundColor,gi as supportsBackgroundGradient,pi as supportsBackgroundGradientData,ci as supportsBackgroundImage,mi as supportsBackgroundImageData,fi as supportsBorderRadius,di as supportsLocked,ai as supportsName,yi as supportsOpacity,ii as supportsPins,ni as supportsPosition,hi as supportsRotation,bi as supportsSVG,oi as supportsSize,ri as supportsSizeConstraints,li as supportsVisible,Le as useMakeDraggable}; | ||
`))}catch{}throw t}var Ue="__class",Ie="LinearGradient",Ce="RadialGradient",ve="ConicGradient";function ue(n){if(!h(n))return!1;switch(n[Ue]){case Ie:case Ce:case ve:return!0;default:return!1}}function X(n){return n instanceof V||n instanceof G||n instanceof E}function _e(n){if(n instanceof V)return{__class:Ie,angle:n.angle,stops:n.stops};if(n instanceof G)return{__class:Ce,width:n.width,height:n.height,x:n.x,y:n.y,stops:n.stops};if(n instanceof E)return{__class:ve,angle:n.angle,x:n.x,y:n.y,stops:n.stops};S(n)}function ce(n){switch(n[Ue]){case Ie:return new V(n);case Ce:return new G(n);case ve:return new E(n);default:S(n)}}var V=class n{constructor(e){o(this,"angle");o(this,"stops");this.angle=e.angle,this.stops=e.stops,Object.freeze(this)}cloneWithAttributes(e){return new n({angle:e.angle??this.angle,stops:e.stops??this.stops})}toCSS(){let e=this.stops.map(t=>`${t.color} ${t.position*100}%`).join(", ");return`linear-gradient(${this.angle}deg, ${e})`}},G=class n{constructor(e){o(this,"width");o(this,"height");o(this,"x");o(this,"y");o(this,"stops");this.width=e.width,this.height=e.height,this.x=e.x,this.y=e.y,this.stops=e.stops,Object.freeze(this)}cloneWithAttributes(e){return new n({width:e.width??this.width,height:e.height??this.height,x:e.x??this.x,y:e.y??this.y,stops:e.stops??this.stops})}toCSS(){let e=this.stops.map((t,i)=>{let s=this.stops[i+1],a=t.position===1&&s?.position===1?t.position-1e-4:t.position;return`${t.color} ${a*100}%`}).join(", ");return`radial-gradient(${this.width} ${this.height} at ${this.x} ${this.y}, ${e})`}},E=class n{constructor(e){o(this,"angle");o(this,"x");o(this,"y");o(this,"stops");this.angle=e.angle,this.x=e.x,this.y=e.y,this.stops=e.stops,Object.freeze(this)}cloneWithAttributes(e){return new n({angle:e.angle??this.angle,x:e.x??this.x,y:e.y??this.y,stops:e.stops??this.stops})}toCSS(){let e=this.stops.map(t=>`${t.color} ${t.position*360}deg`).join(", ");return`conic-gradient(from ${this.angle}deg at ${this.x} ${this.y}, ${e})`}};var xt="invoke";function x(n){return xt in n}var Tt="ImageAsset",Nt="__class";function me(n){return h(n)?n[Nt]===Tt:!1}var k,M,ke=class ke{constructor(e,t){o(this,"id");o(this,"url");o(this,"thumbnailUrl");o(this,"altText");c(this,k,void 0);c(this,M,void 0);l(x(t)),this.url=e.url,m(this,M,t),this.id=e.id,this.thumbnailUrl=e.thumbnailUrl,this.altText=e.altText}cloneWithAttributes({altText:e}){return new ke({__class:"ImageAsset",id:this.id,url:this.url,thumbnailUrl:this.thumbnailUrl,altText:e!==void 0?e:this.altText},r(this,M))}async measure(){return St(this.url)}async getData(){if(r(this,k)&&r(this,k).bytes.length>0)return r(this,k);let e=await r(this,M).invoke("getImageData",{id:this.id});if(!e)throw new Error("Failed to load image data");return m(this,k,e),e}async loadBitmap(){let{mimeType:e,bytes:t}=await this.getData(),i=new Blob([t],{type:e});return createImageBitmap(i)}async loadImage(){let e=await this.getData(),t=URL.createObjectURL(new Blob([e.bytes]));return new Promise((i,s)=>{let a=new Image;a.onload=()=>i(a),a.onerror=()=>s(),a.src=t})}};k=new WeakMap,M=new WeakMap;var y=ke;function It(n){return n instanceof y}function B(n){return n.type==="bytes"?[n.bytes.buffer]:[]}function Ct(n){if(!h(n))return!1;let e="bytes",t="mimeType";return!(!(e in n)||!(t in n)||!(n[e]instanceof Uint8Array)||!d(n[t]))}async function Y(n){return n instanceof File?ze(n):n.image instanceof File?ze(n.image):Ct(n.image)?{name:n.name,altText:n.altText,type:"bytes",mimeType:n.image.mimeType,bytes:n.image.bytes}:{name:n.name,altText:n.altText,type:"url",url:n.image}}function Se(n){return Promise.all(n.map(Y))}function vt(n){if(!n.startsWith("image/"))throw new Error(`Unsupported mime type: ${n}`)}async function ze(n){return new Promise((e,t)=>{let i=new FileReader;i.onload=s=>{let a=n.type;vt(n.type);let u=s.target?.result;if(!u||!(u instanceof ArrayBuffer)){t(new Error("Failed to read file, arrayBuffer is null"));return}let C=new Uint8Array(u);e({bytes:C,mimeType:a,type:"bytes"})},i.onerror=s=>{t(s)},i.readAsArrayBuffer(n)})}async function St(n){let e=n instanceof File,t=e?URL.createObjectURL(n):n,i=new Image;return i.crossOrigin="anonymous",i.src=t,await i.decode().finally(()=>{e&&URL.revokeObjectURL(t)}),{height:i.height,width:i.width}}function A(n){if(At(n))return Dt(n);if(Ne(n))return n.map(A);if(h(n)){let e={};for(let t in n)e[t]=A(n[t]);return e}return n}function He(n,e){let t={};for(let i in n)t[i]=Ae(n[i],e);return t}function Ae(n,e){if(kt(n))switch(n.__class){case"ImageAsset":return new y(n,e);case"LinearGradient":case"RadialGradient":case"ConicGradient":return ce(n);default:S(n)}if(h(n)){let t={};for(let i in n)t[i]=Ae(n[i],e);return t}return Ne(n)?n.map(t=>Ae(t,e)):n}function kt(n){return!!(me(n)||ue(n))}function At(n){return!!(n instanceof y||X(n))}function Dt(n){if(n instanceof y)return{__class:"ImageAsset",id:n.id,thumbnailUrl:n.thumbnailUrl,url:n.url,altText:n.altText};if(X(n))return _e(n);S(n)}var b,ge=class{constructor(e,t){o(this,"id");o(this,"name");c(this,b,void 0);l(d(e.id),"Node must have an id"),l(d(e.name),"Node must have a name"),this.id=e.id,this.name=e.name,l(x(t)),m(this,b,t),Object.freeze(this)}async getItemIds(){return r(this,b).invoke("getCollectionItemIds",this.id)}async setItemOrder(e){return r(this,b).invoke("setCollectionItemOrder",this.id,e)}async getFields(){return r(this,b).invoke("getCollectionFields",this.id)}async setFields(e){return r(this,b).invoke("setCollectionFields",this.id,e)}async addItems(e){return r(this,b).invoke("addCollectionItems",this.id,e)}async removeItems(e){return r(this,b).invoke("removeCollectionItems",this.id,e)}async setPluginData(e,t){return r(this,b).invoke("setPluginDataForNode",this.id,e,t)}async getPluginData(e){return r(this,b).invoke("getPluginDataForNode",this.id,e)}async getPluginDataKeys(){return r(this,b).invoke("getPluginDataKeysForNode",this.id)}};b=new WeakMap;var Wt=(()=>{let n=null;return{disableUntilMouseUp:()=>{if(n)return;n=document.createElement("style"),n.textContent="* { pointer-events: none !important; user-select: none !important; -webkit-user-select: none !important; }",document.head.appendChild(n);let e=()=>{n&&(document.head.removeChild(n),n=null,s())},t=a=>{a.buttons>0&&a.buttons&1||e()},i=()=>{e()};window.addEventListener("pointerup",t,!0),window.addEventListener("pointermove",t,!0),window.addEventListener("blur",i);function s(){window.removeEventListener("pointerup",t,!0),window.removeEventListener("pointermove",t,!0),window.removeEventListener("blur",i)}}}})(),Ke=5,wt=(()=>{let n=1;return{next:()=>`drag-${n++}`}})();function Rt(){}function je(n,e,t){if(n.mode!=="default")return Rt;l(x(n));let i=wt.next(),s=document.body.style.cursor,a={type:"idle"},u=document.body,C=p=>{a.type!=="idle"&&(a.type==="dragging"&&n.invoke("onDragEnd",{...p,dragSessionId:i}),a={type:"idle"},ft())},oe=p=>{if(a.type==="idle")return;if(!(p.buttons>0&&!!(p.buttons&1))){C({cancelled:!1});return}let{clientX:re,clientY:j}=p;if(a.type==="pointerDown"){let $=re-a.dragStart.mouse.x,Be=j-a.dragStart.mouse.y;if(Math.abs($)<Ke&&Math.abs(Be)<Ke)return;a={type:"dragging",dragStart:a.dragStart},n.invoke("onDragStart",a.dragStart),document.getSelection()?.empty(),Wt.disableUntilMouseUp()}u.setPointerCapture(p.pointerId);let se={x:re,y:j};n.invoke("onDrag",{dragSessionId:i,mouse:se}).then($=>{a.type==="dragging"&&(document.body.style.cursor=$??"")})},Ve=p=>{p.key==="Escape"&&C({cancelled:!0})},Ge=()=>{C({cancelled:!0})},Ee=p=>{C({cancelled:!0});let K=e.getBoundingClientRect(),re={x:K.x,y:K.y,width:K.width,height:K.height},j,se=e.querySelectorAll("svg");if(se.length===1){let ae=se.item(0).getBoundingClientRect();j={x:ae.x,y:ae.y,width:ae.width,height:ae.height}}let $={x:p.clientX,y:p.clientY};a={type:"pointerDown",dragStart:{dragSessionId:i,elementRect:re,svgRect:j,mouse:$}},n.invoke("setDragData",i,t()),u.addEventListener("pointermove",oe,!0),u.addEventListener("pointerup",oe,!0),window.addEventListener("keydown",Ve,!0),window.addEventListener("blur",Ge)},Me=()=>{let p=t();p.type==="detachedComponentLayers"&&n.invoke("preloadDetachedComponentLayers",p.url),p.type==="image"&&n.invoke("preloadImageUrlForInsertion",p.image),p.previewImage&&n.invoke("preloadDragPreviewImage",p.previewImage)};e.addEventListener("pointerdown",Ee),e.addEventListener("mouseenter",Me);function ft(){document.body.style.cursor=s,u.removeEventListener("pointermove",oe,!0),u.removeEventListener("pointerup",oe,!0),window.removeEventListener("keydown",Ve,!0),window.removeEventListener("blur",Ge)}return()=>{e.removeEventListener("pointerdown",Ee),e.removeEventListener("mouseenter",Me),C({cancelled:!0})}}var q=class extends Error{};var Ft={default:!0,image:!0,editImage:!0,configureCollection:!0,syncCollection:!0};function $e(n){return d(n)&&n in Ft}var Lt={methodResponse:!0,pluginReadyResponse:!0,subscriptionMessage:!0};function Vt(n){return d(n)&&n in Lt}function Xe(n){return h(n)&&Vt(n["type"])}var ie,f,T,v=class{constructor(e,t){o(this,"id");c(this,ie,void 0);c(this,f,void 0);c(this,T,void 0);l(d(e.id),"Node must have an id"),this.id=e.id,m(this,f,t),m(this,ie,e.originalId??null),l(x(t)),m(this,T,t)}get isReplica(){return r(this,ie)!==null}remove(){return r(this,f).removeNode(this.id)}select(){return r(this,f).setSelection([this.id])}clone(){return r(this,f).cloneNode(this.id)}setAttributes(e){return r(this,f).setAttributes(this.id,e)}getRect(){return r(this,f).getRect(this.id)}zoomIntoView(e){return r(this,f).zoomIntoView([this.id],e)}getParent(){return r(this,f).getParent(this.id)}getChildren(){return D(this)?Promise.resolve([]):r(this,f).getChildren(this.id)}async getNodesWithType(e){return D(this)?Promise.resolve([]):(await r(this,T).invoke("getNodesWithType",this.id,e)).map(i=>g(i,r(this,f)))}async getNodesWithAttribute(e){return D(this)?Promise.resolve([]):(await r(this,T).invoke("getNodesWithAttribute",this.id,e)).map(i=>g(i,r(this,f)))}async getNodesWithAttributeSet(e){return D(this)?Promise.resolve([]):(await r(this,T).invoke("getNodesWithAttributeSet",this.id,e)).map(i=>g(i,r(this,f)))}async*walk(){if(yield this,!D(this))for(let e of await this.getChildren())yield*e.walk()}async getPluginData(e){return r(this,T).invoke("getPluginDataForNode",this.id,e)}async setPluginData(e,t){return r(this,T).invoke("setPluginDataForNode",this.id,e,t)}async getPluginDataKeys(){return r(this,T).invoke("getPluginDataKeysForNode",this.id)}};ie=new WeakMap,f=new WeakMap,T=new WeakMap;var W=class extends v{constructor(t,i){super(t,i);o(this,"__class","FrameNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"backgroundColor");o(this,"backgroundImage");o(this,"backgroundGradient");o(this,"rotation");o(this,"opacity");o(this,"borderRadius");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");o(this,"maxWidth");o(this,"minWidth");o(this,"maxHeight");o(this,"minHeight");o(this,"aspectRatio");l(t.__class==="FrameNode","FrameNode must have a __class property"),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.backgroundColor=t.backgroundColor??null,this.backgroundImage=t.backgroundImage?new y(t.backgroundImage,i):null,this.rotation=t.rotation??0,this.opacity=t.opacity??1,this.borderRadius=t.borderRadius??null,this.backgroundGradient=ue(t.backgroundGradient)?ce(t.backgroundGradient):null,l(t.position,"Must have a position"),this.position=t.position,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,this.maxWidth=t.maxWidth??null,this.minWidth=t.minWidth??null,this.maxHeight=t.maxHeight??null,this.minHeight=t.minHeight??null,this.aspectRatio=t.aspectRatio??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},O,Z=class extends v{constructor(t,i){super(t,i);o(this,"__class","TextNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"rotation");o(this,"opacity");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");o(this,"maxWidth");o(this,"minWidth");o(this,"maxHeight");o(this,"minHeight");c(this,O,void 0);l(x(i)),m(this,O,i),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.rotation=t.rotation??0,this.opacity=t.opacity??1,l(t.position,"Must have a position"),this.position=t.position,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,this.maxWidth=t.maxWidth??null,this.minWidth=t.minWidth??null,this.maxHeight=t.maxHeight??null,this.minHeight=t.minHeight??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}async setText(t){await r(this,O).invoke("setTextForNode",this.id,t)}async getText(){return r(this,O).invoke("getTextForNode",this.id)}};O=new WeakMap;var Q=class extends v{constructor(t,i){super(t,i);o(this,"__class","SVGNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"svg");o(this,"rotation");o(this,"opacity");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");l(t.svg,"SVG node must have a non-empty SVG string"),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.svg=t.svg,this.rotation=t.rotation??0,this.opacity=t.opacity??1,l(t.position,"Must have a position"),this.position=t.position??null,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},J=class extends v{constructor(t,i){super(t,i);o(this,"__class","ComponentInstanceNode");o(this,"name");o(this,"visible");o(this,"locked");o(this,"componentIdentifier");o(this,"controls");o(this,"rotation");o(this,"opacity");o(this,"position");o(this,"top");o(this,"right");o(this,"bottom");o(this,"left");o(this,"centerX");o(this,"centerY");o(this,"width");o(this,"height");o(this,"maxWidth");o(this,"minWidth");o(this,"maxHeight");o(this,"minHeight");o(this,"aspectRatio");l(t.componentIdentifier,"ComponentInstance node must have a component identifier"),this.name=t.name??null,this.visible=t.visible??!0,this.locked=t.locked??!1,this.componentIdentifier=t.componentIdentifier,this.controls=He(t.controls??{},i),this.rotation=t.rotation??0,this.opacity=t.opacity??1,l(t.position,"Must have a position"),this.position=t.position,this.left=t.left??null,this.right=t.right??null,this.top=t.top??null,this.bottom=t.bottom??null,this.centerX=t.centerX??null,this.centerY=t.centerY??null,this.width=t.width??null,this.height=t.height??null,this.maxWidth=t.maxWidth??null,this.minWidth=t.minWidth??null,this.maxHeight=t.maxHeight??null,this.minHeight=t.minHeight??null,this.aspectRatio=t.aspectRatio??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},ee=class extends v{constructor(t,i){super(t,i);o(this,"_class","WebPageNode");Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},te=class extends v{constructor(t,i){super(t,i);o(this,"__class","ComponentNode");o(this,"name");this.name=t.name??null,Object.freeze(this)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},ne=class extends v{constructor(t,i){super(t,i);o(this,"__class","UnknownNode");Object.freeze(this)}clone(){throw Error("Can not clone unknown node")}setAttributes(t){throw Error("Can not set attributes on unknown node")}};function g(n,e){switch(n.__class){case"WebPageNode":return new ee(n,e);case"ComponentNode":return new te(n,e);case"ComponentInstanceNode":return new J(n,e);case"FrameNode":return new W(n,e);case"SVGNode":return new Q(n,e);case"TextNode":return new Z(n,e);case"UnknownNode":return new ne(n,e);default:return new ne(n,e)}}function De(n){return A(n)}function pe(n){return n instanceof W}function Ye(n){return n instanceof Z}function qe(n){return n instanceof Q}function he(n){return n instanceof J}function Ze(n){return n instanceof ee}function Qe(n){return n instanceof te}function D(n){return n instanceof ne}function ye(n){return!!(pe(n)||Ye(n)||he(n)||qe(n)||D(n))}function We(n){return!!(Ze(n)||Qe(n)||D(n))}var N,we=class we{constructor(e,t){o(this,"id");o(this,"name");o(this,"light");o(this,"dark");c(this,N,void 0);l(d(e.id),"Node must have an id"),this.id=e.id,this.name=e.name,this.light=e.light,this.dark=e.dark,l(x(t)),m(this,N,t)}async setAttributes(e){let t=await r(this,N).invoke("setColorStyleAttributes",this.id,e);return t?new we(t,r(this,N)):null}async getPluginData(e){return r(this,N).invoke("getPluginDataForNode",this.id,e)}async setPluginData(e,t){return r(this,N).invoke("setPluginDataForNode",this.id,e,t)}async getPluginDataKeys(){return r(this,N).invoke("getPluginDataKeysForNode",this.id)}async remove(){return r(this,N).invoke("removeColorStyle",this.id)}};N=new WeakMap;var w=we,I,Re=class Re{constructor(e,t){o(this,"id");o(this,"name");o(this,"tag");o(this,"color");o(this,"transform");o(this,"alignment");o(this,"decoration");o(this,"balance");o(this,"breakpoints");o(this,"minWidth");o(this,"fontSize");o(this,"letterSpacing");o(this,"lineHeight");o(this,"paragraphSpacing");c(this,I,void 0);l(d(e.id),"Node must have an id"),this.id=e.id,this.name=e.name,this.tag=e.tag,this.color=e.color,this.transform=e.transform,this.alignment=e.alignment,this.decoration=e.decoration,this.balance=e.balance,this.breakpoints=e.breakpoints,this.minWidth=e.minWidth,this.fontSize=e.fontSize,this.letterSpacing=e.letterSpacing,this.lineHeight=e.lineHeight,this.paragraphSpacing=e.paragraphSpacing,l(x(t)),m(this,I,t)}async setAttributes(e){let t=await r(this,I).invoke("setTextStyleAttributes",this.id,e);return new Re(t,r(this,I))}async getPluginData(e){return r(this,I).invoke("getPluginDataForNode",this.id,e)}async setPluginData(e,t){return r(this,I).invoke("setPluginDataForNode",this.id,e,t)}async getPluginDataKeys(){return r(this,I).invoke("getPluginDataKeysForNode",this.id)}async remove(){return r(this,I).invoke("removeTextStyle",this.id)}};I=new WeakMap;var R=Re;var U=null;function Je(n){if(!U){let t=document.createElement("style");document.head.appendChild(t),U=t.sheet}if(!U){n();return}let e=U.insertRule("* { transition: none !important; animation: none !important; }");n(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{U&&U.deleteRule(e)})})}var Gt=1,be,Pe,_,F,z,L,fe=class{constructor({isTestEnv:e}={}){c(this,be,0);c(this,Pe,0);c(this,_,[]);c(this,F,void 0);c(this,z,new Map);c(this,L,void 0);o(this,"subscriptions",new Map);o(this,"onMessage",e=>{let t=e.data;if(Xe(t))switch(t.type){case"pluginReadyResponse":{if(!e.source)throw new Error("No 'source' on incoming message: "+t.type);l(r(this,L)===t.mode,"Mode must match"),this.applyPluginTheme(t.theme),m(this,F,(s,a)=>window.parent.postMessage(s,e.origin,a));for(let s of r(this,_))r(this,F).call(this,...s);m(this,_,[]);break}case"methodResponse":{let i=r(this,z).get(t.id);if(!i)throw new Error(`No handler for response with id ${t.id}`);r(this,z).delete(t.id),t.error?i.reject(new q(t.error)):i.resolve(t.result);break}case"subscriptionMessage":{let{topic:i,payload:s}=t,a=this.subscriptions.get(i);if(!a)throw new Error("Received a subscription message but no handler present");for(let u of a)u(s);break}default:S(t)}});o(this,"applyPluginTheme",e=>{Je(()=>{document.body.setAttribute("data-framer-theme",e.mode);for(let t in e.tokens)document.body.style.setProperty(t,e.tokens[t])})});if(e){m(this,L,"default");return}let i=new URL(window.location.href).searchParams.get("mode");l($e(i),`Invalid mode: ${i}`),m(this,L,i),window.addEventListener("message",this.onMessage);let s={type:"pluginReadySignal",breakingChangesVersion:Gt};window.parent.postMessage(s,"*"),this.subscribe("theme",this.applyPluginTheme),window.addEventListener("pointerdown",()=>{this.invoke("onPointerDown")})}get mode(){return r(this,L)}invoke(e,...t){return this.invokeTransferable(e,void 0,...t)}invokeTransferable(e,t,...i){return new Promise((s,a)=>{let u={args:i,methodName:e,id:xe(this,be)._++,type:"methodInvocation"},C=s;r(this,z).set(u.id,{resolve:C,reject:a}),this.queueMessage(u,t)})}subscribe(e,t){this.queueMessage({type:"subscribe",topic:e});let i=this.subscriptions.get(e)??new Set;return i.add(t),this.subscriptions.set(e,i),()=>{let s=this.subscriptions.get(e)??new Set;s.delete(t),s.size===0&&this.queueMessage({type:"unsubscribe",topic:e}),this.subscriptions.set(e,s)}}queueMessage(e,t){if(!r(this,F)){r(this,_).push([e,t]);return}r(this,F).call(this,e,t)}async showUI(e){return this.invoke("showUI",e)}async hideUI(){return this.invoke("hideUI")}async closePlugin(e,t){return this.invoke("closePlugin",e,t)}async getCurrentUser(){return this.invoke("getCurrentUser")}async getSelection(){return(await this.invoke("getSelection")).map(t=>{let i=g(t,this);return l(ye(i)),i})}async setSelection(e){let t=d(e)?[e]:Array.from(e);return this.invoke("setSelection",t)}subscribeToSelection(e){return this.subscribe("selection",t=>{let i=t.map(s=>{let a=g(s,this);return l(ye(a)),a});e(i)})}async getCanvasRoot(){let e=await this.invoke("getCanvasRoot"),t=g(e,this);return l(We(t)),t}subscribeToCanvasRoot(e){return this.subscribe("canvasRoot",t=>{let i=g(t,this);l(We(i)),e(i)})}async getPublishInfo(){return this.invoke("getPublishInfo")}subscribeToPublishInfo(e){return this.subscribe("publishInfo",e)}async createFrameNode(e,t){let i=De(e),s=await this.invoke("createNode","FrameNode",t??null,i);if(!s)return null;let a=g(s,this);return l(a instanceof W),a}async removeNode(e){return this.invoke("removeNode",e)}async cloneNode(e){let t=await this.invoke("cloneNode",e);return t?g(t,this):null}async getNode(e){let t=await this.invoke("getNode",e);return t?g(t,this):null}async getParent(e){let t=await this.invoke("getParent",e);return t?g(t,this):null}async getChildren(e){return(await this.invoke("getChildren",e)).map(i=>{let s=g(i,this);return l(ye(s)),s})}async getRect(e){return this.invoke("getRect",e)}async zoomIntoView(e,t){let i=d(e)?[e]:Array.from(e);return this.invoke("zoomIntoView",i,t)}async setAttributes(e,t){let i=De(t),s=await this.invoke("setAttributes",e,i);return s?g(s,this):null}async setParent(e,t,i){return this.invoke("setParent",e,t,i)}async getNodesWithType(e){return(await this.invoke("getNodesWithType",null,e)).map(i=>g(i,this))}async getNodesWithAttribute(e){return(await this.invoke("getNodesWithAttribute",null,e)).map(i=>g(i,this))}async getNodesWithAttributeSet(e){return(await this.invoke("getNodesWithAttributeSet",null,e)).map(i=>g(i,this))}async getImage(){let e=await this.invoke("getImage");return e?new y(e,this):null}subscribeToImage(e){return this.subscribe("image",t=>{if(!t){e(null);return}e(new y(t,this))})}async addImage(e){let t=await Y(e),i=B(t);return this.invokeTransferable("addImage",i,t)}async setImage(e){let t=await Y(e),i=B(t);return this.invokeTransferable("setImage",i,t)}async uploadImage(e){let t=await Y(e),i=B(t),s=await this.invokeTransferable("uploadImage",i,t);return new y(s,this)}async addImages(e){let t=await Se(e),i=t.flatMap(B);await this.invokeTransferable("addImages",i,t)}async uploadImages(e){let t=await Se(e),i=t.flatMap(B),s=await this.invokeTransferable("uploadImages",i,t),a=[];for(let u of s)a.push(new y(u,this));return a}async addSVG(e){return this.invoke("addSVG",e)}async addComponentInstance({url:e,attributes:t}){let i=A(t),s=await this.invoke("addComponentInstance",{url:e,attributes:h(i)?i:void 0}),a=g(s,this);return l(he(a)),a}async addDetachedComponentLayers({url:e,layout:t,attributes:i}){let s=A(i),a=await this.invoke("addDetachedComponentLayers",{url:e,layout:t,attributes:h(s)?s:void 0}),u=g(a,this);return l(pe(u)),u}async preloadDetachedComponentLayers(e){await this.invoke("preloadDetachedComponentLayers",e)}async preloadImageUrlForInsertion(e){await this.invoke("preloadImageUrlForInsertion",e)}async preloadDragPreviewImage(e){await this.invoke("preloadDragPreviewImage",e)}async getText(){return this.invoke("getText")}async setText(e){return this.invoke("setText",e)}async addText(e,t){return this.invoke("addText",e,t)}async setCustomCode(e){return this.invoke("setCustomCode",e)}async getCustomCode(){return this.invoke("getCustomCode")}subscribeToCustomCode(e){return this.subscribe("customCode",e)}subscribeToText(e){return this.subscribe("text",e)}makeDraggable(e,t){return je(this,e,t)}async getCollection(){let e=await this.invoke("getCollection");return l(e,"Collection data must be defined"),new ge(e,this)}notify(e,t){let i=`notification-${xe(this,Pe)._++}`;return this.invoke("notify",e,{notificationId:i,variant:t?.variant??"info",buttonText:t?.button?.text,durationMs:t?.durationMs}).then(s=>{s==="actionButtonClicked"&&t?.button?.onClick&&t.button.onClick(),t?.onDisappear&&t.onDisappear()}),{close:()=>this.invoke("closeNotification",i)}}async getPluginData(e){return this.invoke("getPluginData",e)}async setPluginData(e,t){return this.invoke("setPluginData",e,t)}async getPluginDataKeys(){return this.invoke("getPluginDataKeys")}async getColorStyles(){return(await this.invoke("getColorStyles")).map(t=>new w(t,this))}async getColorStyle(e){let t=await this.invoke("getColorStyle",e);return t?new w(t,this):null}async createColorStyle(e){let t=await this.invoke("createColorStyle",e);return new w(t,this)}subscribeToColorStyles(e){return this.subscribe("colorStyles",t=>{let i=t.map(s=>new w(s,this));return e(i)})}async getTextStyles(){return(await this.invoke("getTextStyles")).map(t=>new R(t,this))}async getTextStyle(e){let t=await this.invoke("getTextStyle",e);return t?new R(t,this):null}async createTextStyle(e){let t=await this.invoke("createTextStyle",e);return new R(t,this)}subscribeToTextStyles(e){return this.subscribe("textStyles",t=>{let i=t.map(s=>new R(s,this));return e(i)})}};be=new WeakMap,Pe=new WeakMap,_=new WeakMap,F=new WeakMap,z=new WeakMap,L=new WeakMap;var Fe=new fe;function Le(n,e){let t=Ot(()=>de(e)?e():e);Mt(()=>{let i=n.current;if(i instanceof HTMLElement)return Fe.makeDraggable(i,t)},[t])}function Ot(n){let e=Bt(n);return e.current=n,Et((...t)=>e.current(...t),[])}var Ut=H.forwardRef(function({data:e,children:t,...i},s){let a=H.useRef(null);if(Le(a,e),H.isValidElement(t)){let u=Object.assign({},i);return h(t.props)&&Object.assign(u,t.props),u.ref=Ht(a,s,t.ref),H.cloneElement(t,u)}return H.Children.count(t)>1&&H.Children.only(t),null}),_t="current";function zt(n){return h(n)&&_t in n}function Ht(...n){return e=>{for(let t of n)de(t)?t(e):zt(t)&&(t.current=e)}}var Kt={fixed:!0,sticky:!0,absolute:!0,relative:!0},et="position";function ni(n){if(!(et in n))return!1;let e=n[et];return d(e)&&Kt[e]===!0}var tt="top";function ii(n){if(!(tt in n))return!1;let e=n[tt];return d(e)||P(e)}var nt="width";function oi(n){if(!(nt in n))return!1;let e=n[nt];return d(e)||P(e)}var it="maxWidth";function ri(n){if(!(it in n))return!1;let e=n[it];return d(e)||P(e)}var ot="aspectRatio";function si(n){if(!(ot in n))return!1;let e=n[ot];return le(e)||P(e)}var rt="name";function ai(n){if(!(rt in n))return!1;let e=n[rt];return d(e)||P(e)}var st="visible";function li(n){if(!(st in n))return!1;let e=n[st];return Te(e)}var at="locked";function di(n){if(!(at in n))return!1;let e=n[at];return Te(e)}var lt="backgroundColor";function ui(n){if(!(lt in n))return!1;let e=n[lt];return d(e)||P(e)}var dt="backgroundImage";function ci(n){if(!(dt in n))return!1;let e=n[dt];return e instanceof y||P(e)}var ut="backgroundImage";function mi(n){if(!(ut in n))return!1;let e=n[ut];return e instanceof y?!1:me(e)||P(e)}var ct="backgroundGradient";function gi(n){if(!(ct in n))return!1;let e=n[ct];return X(e)||P(e)}var mt="backgroundGradient";function pi(n){if(!(mt in n))return!1;let e=n[mt];return h(e)||P(e)}var gt="rotation";function hi(n){if(!(gt in n))return!1;let e=n[gt];return le(e)}var pt="opacity";function yi(n){if(!(pt in n))return!1;let e=n[pt];return le(e)}var ht="borderRadius";function fi(n){if(!(ht in n))return!1;let e=n[ht];return d(e)||P(e)}var yt="svg";function bi(n){if(!(yt in n))return!1;let e=n[yt];return d(e)}export{J as ComponentInstanceNode,te as ComponentNode,E as ConicGradient,Ut as Draggable,W as FrameNode,q as FramerPluginError,V as LinearGradient,G as RadialGradient,Q as SVGNode,Z as TextNode,ee as WebPageNode,Fe as framer,he as isComponentInstanceNode,Qe as isComponentNode,pe as isFrameNode,It as isImageAsset,qe as isSVGNode,Ye as isTextNode,Ze as isWebPageNode,si as supportsAspectRatio,ui as supportsBackgroundColor,gi as supportsBackgroundGradient,pi as supportsBackgroundGradientData,ci as supportsBackgroundImage,mi as supportsBackgroundImageData,fi as supportsBorderRadius,di as supportsLocked,ai as supportsName,yi as supportsOpacity,ii as supportsPins,ni as supportsPosition,hi as supportsRotation,bi as supportsSVG,oi as supportsSize,ri as supportsSizeConstraints,li as supportsVisible,Le as useMakeDraggable}; |
{ | ||
"name": "framer-plugin", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "src/index.ts", |
Sorry, the diff of this file is not supported yet
8
1656
251954