Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

framer-plugin

Package Overview
Dependencies
Maintainers
38
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

framer-plugin - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

dist/index.js.map

107

dist/index.d.ts
import * as valibot from 'valibot';
import React, { RefObject } from 'react';
type BaseSchema = valibot.BaseSchema;
type OptionalSchema<Wrapped extends BaseSchema> = valibot.OptionalSchema<Wrapped>;
type InferSchema<Schema extends BaseSchema> = valibot.Input<Schema>;
declare const optionalString: OptionalSchema<valibot.StringSchema<string>>;
type OptionalString = InferSchema<typeof optionalString>;
declare const customCodeLocationSchema: valibot.BaseSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd"> & {
type: "union";
options: valibot.LiteralSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd">[];
message: valibot.ErrorMessage | undefined;
pipe: valibot.Pipe<"headStart" | "headEnd" | "bodyStart" | "bodyEnd"> | undefined;
};
declare const setCustomCodeOptionsSchema: valibot.BaseSchema<{
code: string | null;
location: "headStart" | "headEnd" | "bodyStart" | "bodyEnd";
}, {
code: string | null;
location: "headStart" | "headEnd" | "bodyStart" | "bodyEnd";
}> & {
type: "object";
entries: {
code: valibot.NullableSchema<valibot.StringSchema<string>, undefined, string | null>;
location: valibot.BaseSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd"> & {
type: "union";
options: valibot.LiteralSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd">[];
message: valibot.ErrorMessage | undefined;
pipe: valibot.Pipe<"headStart" | "headEnd" | "bodyStart" | "bodyEnd"> | undefined;
};
};
rest: undefined;
message: valibot.ErrorMessage | undefined;
pipe: valibot.Pipe<{
code: string | null;
location: "headStart" | "headEnd" | "bodyStart" | "bodyEnd";
}> | undefined;
};
type SetCustomCodeOptions = InferSchema<typeof setCustomCodeOptionsSchema>;
type CustomCodeLocation = InferSchema<typeof customCodeLocationSchema>;
type CustomCode = Record<CustomCodeLocation, {
disabled: boolean;
code: string | null;
}>;
type NodeId = string;

@@ -89,5 +46,2 @@ interface WithId {

}
interface WithHTML {
readonly html: string;
}
interface WithSVG {

@@ -135,3 +89,3 @@ readonly svg: string;

type TraitVariant = TraitVariantData | TraitVariantNode;
interface AllTraits<T extends TraitVariant = TraitVariant> extends WithId, WithChildren, WithName, WithVisible, WithLocked, WithBackgroundColor, WithBackgroundImage<T>, WithBackgroundGradient, WithRotation, WithOpacity, WithBorderRadius, WithComponentIdentifier, WithControlAttributes, WithHTML, WithSVG, WithPosition, WithPins, WithSize, WithSizeConstraints, WithAspectRatio {
interface AllTraits<T extends TraitVariant = TraitVariant> extends WithId, WithChildren, WithName, WithVisible, WithLocked, WithBackgroundColor, WithBackgroundImage<T>, WithBackgroundGradient, WithRotation, WithOpacity, WithBorderRadius, WithComponentIdentifier, WithControlAttributes, WithSVG, WithPosition, WithPins, WithSize, WithSizeConstraints, WithAspectRatio {
}

@@ -154,5 +108,10 @@ type PartialNodeData = AnyNode | Partial<AnyNodeData>;

declare function withBorderRadius<T extends PartialNodeData>(node: T): node is T & WithBorderRadius;
declare function withHTML<T extends PartialNodeData>(node: T): node is T & WithHTML;
declare function withSVG<T extends PartialNodeData>(node: T): node is T & WithSVG;
type BaseSchema = valibot.BaseSchema;
type OptionalSchema<Wrapped extends BaseSchema> = valibot.OptionalSchema<Wrapped>;
type InferSchema<Schema extends BaseSchema> = valibot.Input<Schema>;
declare const optionalString: OptionalSchema<valibot.StringSchema<string>>;
type OptionalString = InferSchema<typeof optionalString>;
interface Rect {

@@ -222,5 +181,5 @@ x: number;

}
interface EditableTextNodeAttributes extends DrawableNode, WithPosition, WithPins, WithSize, WithSizeConstraints, WithHTML, WithRotation {
interface EditableTextNodeAttributes extends DrawableNode, WithPosition, WithPins, WithSize, WithSizeConstraints, WithRotation {
}
interface TextNodeData extends CommonNodeData, DrawableNode, WithPosition, WithPins, WithSize, WithSizeConstraints, WithHTML, WithRotation {
interface TextNodeData extends CommonNodeData, DrawableNode, WithPosition, WithPins, WithSize, WithSizeConstraints, WithRotation {
__class: "TextNode";

@@ -232,3 +191,2 @@ }

readonly locked: boolean;
readonly html: string;
readonly rotation: number;

@@ -357,2 +315,39 @@ readonly opacity: number;

declare const customCodeLocationSchema: valibot.BaseSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd"> & {
type: "union";
options: valibot.LiteralSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd">[];
message: valibot.ErrorMessage | undefined;
pipe: valibot.Pipe<"headStart" | "headEnd" | "bodyStart" | "bodyEnd"> | undefined;
};
declare const setCustomCodeOptionsSchema: valibot.BaseSchema<{
html: string | null;
location: "headStart" | "headEnd" | "bodyStart" | "bodyEnd";
}, {
html: string | null;
location: "headStart" | "headEnd" | "bodyStart" | "bodyEnd";
}> & {
type: "object";
entries: {
html: valibot.NullableSchema<valibot.StringSchema<string>, undefined, string | null>;
location: valibot.BaseSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd"> & {
type: "union";
options: valibot.LiteralSchema<"headStart" | "headEnd" | "bodyStart" | "bodyEnd", "headStart" | "headEnd" | "bodyStart" | "bodyEnd">[];
message: valibot.ErrorMessage | undefined;
pipe: valibot.Pipe<"headStart" | "headEnd" | "bodyStart" | "bodyEnd"> | undefined;
};
};
rest: undefined;
message: valibot.ErrorMessage | undefined;
pipe: valibot.Pipe<{
html: string | null;
location: "headStart" | "headEnd" | "bodyStart" | "bodyEnd";
}> | undefined;
};
type SetCustomCodeOptions = InferSchema<typeof setCustomCodeOptionsSchema>;
type CustomCodeLocation = InferSchema<typeof customCodeLocationSchema>;
type CustomCode = Record<CustomCodeLocation, {
disabled: boolean;
html: string | null;
}>;
declare const dragDataPayloadSchema: valibot.UnionSchema<(valibot.ObjectSchema<{

@@ -532,3 +527,3 @@ type: valibot.LiteralSchema<"svg", "svg">;

getCurrentUser(): Promise<User>;
getSelection(): Promise<CanvasNode[]>;
getSelection(): Promise<(FrameNode | TextNode | CodeComponentNode | SVGNode | UnknownNode)[]>;
setSelection(nodeIds: string | Iterable<string>): Promise<void>;

@@ -541,3 +536,2 @@ subscribeToSelection(callback: (result: CanvasNode[]) => void): VoidFunction;

createFrameNode(attributes: Partial<EditableFrameNodeAttributes>, parentId?: string): Promise<FrameNode | null>;
createSVGNode(attributes: Partial<EditableSVGNodeAttributes>, parentId?: string | undefined): Promise<SVGNode | null>;
removeNode(nodeId: string): Promise<void>;

@@ -565,3 +559,3 @@ cloneNode(nodeId: string): Promise<AnyNode | null>;

getCustomCode(): Promise<CustomCode>;
subscribeToCustomHTML(callback: (customHTML: CustomCode) => void): VoidFunction;
subscribeToCustomCode(callback: (customHTML: CustomCode) => void): VoidFunction;
subscribeToText(callback: (text: string | null) => void): Unsubscribe;

@@ -712,3 +706,2 @@ makeDraggable(element: HTMLElement, getDragData: () => DragData): Cleanup;

createFrameNode(attributes: Partial<EditableFrameNodeAttributes>, parentId?: NodeId): Promise<FrameNode | null>;
createSVGNode(attributes: Partial<EditableSVGNodeAttributes>, parentId?: NodeId): Promise<SVGNode | null>;
/** Remove a node from the canvas. */

@@ -775,3 +768,3 @@ removeNode: (nodeId: NodeId) => Promise<void>;

*/
subscribeToCustomHTML: (htmlUpdate: (customHTML: CustomCode) => void) => Unsubscribe;
subscribeToCustomCode: (callback: (customCode: CustomCode) => void) => Unsubscribe;
/** Add a code component by module URL. */

@@ -917,2 +910,2 @@ addComponent: (moduleUrl: string, attributes?: Partial<EditableCodeComponentNodeAttributes>, controlAttributes?: ControlAttributes) => Promise<CodeComponentNode | null>;

export { type AllTraits, type AnyNode, type BorderRadius, type CanvasNode, type CanvasRootNode, CodeComponentNode, type ControlAttributes, type CustomCode, type CustomCodeLocation, Draggable, type FitContent, type FractionalLength, FrameNode, type HeightConstraint, type HeightLength, ImageAsset, type Length, type NodeId, type PercentageLength, type PixelLength, type Position, SVGNode, SmartComponentNode, TextNode, type TraitVariant, type TraitVariantData, type TraitVariantNode, type UIOptions, type ViewportHeightLength, type ViewportWidthLength, WebPageNode, type WidthConstraint, type WidthLength, type WithAspectRatio, type WithBackgroundColor, type WithBackgroundGradient, type WithBackgroundImage, type WithBorderRadius, type WithChildren, type WithComponentIdentifier, type WithControlAttributes, type WithHTML, type WithId, type WithLocked, type WithName, type WithOpacity, type WithPins, type WithPosition, type WithRotation, type WithSVG, type WithSize, type WithSizeConstraints, type WithVisible, framer, isCodeComponentNode, isFrameNode, isSVGNode, isSmartComponentNode, isTextNode, isWebPageNode, useMakeDraggable, withAspectRatio, withBackgroundColor, withBackgroundGradient, withBackgroundImage, withBackgroundImageData, withBorderRadius, withHTML, withLocked, withName, withOpacity, withPins, withPosition, withRotation, withSVG, withSize, withSizeConstraints, withVisible };
export { type AllTraits, type AnyNode, type BorderRadius, type CanvasNode, type CanvasRootNode, CodeComponentNode, type ControlAttributes, type CustomCode, type CustomCodeLocation, Draggable, type FitContent, type FractionalLength, FrameNode, type HeightConstraint, type HeightLength, ImageAsset, type Length, type NodeId, type PercentageLength, type PixelLength, type Position, SVGNode, SmartComponentNode, TextNode, type TraitVariant, type TraitVariantData, type TraitVariantNode, type UIOptions, type ViewportHeightLength, type ViewportWidthLength, WebPageNode, type WidthConstraint, type WidthLength, type WithAspectRatio, type WithBackgroundColor, type WithBackgroundGradient, type WithBackgroundImage, type WithBorderRadius, type WithChildren, type WithComponentIdentifier, type WithControlAttributes, type WithId, type WithLocked, type WithName, type WithOpacity, type WithPins, type WithPosition, type WithRotation, type WithSVG, type WithSize, type WithSizeConstraints, type WithVisible, framer, isCodeComponentNode, isFrameNode, isSVGNode, isSmartComponentNode, isTextNode, isWebPageNode, useMakeDraggable, withAspectRatio, withBackgroundColor, withBackgroundGradient, withBackgroundImage, withBackgroundImageData, withBorderRadius, withLocked, withName, withOpacity, withPins, withPosition, withRotation, withSVG, withSize, withSizeConstraints, withVisible };

@@ -1,4 +0,4 @@

var yt=Object.defineProperty;var Pt=(n,t,e)=>t in n?yt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var i=(n,t,e)=>(Pt(n,typeof t!="symbol"?t+"":t,e),e),ke=(n,t,e)=>{if(!t.has(n))throw TypeError("Cannot "+e)};var d=(n,t,e)=>(ke(n,t,"read from private field"),e?e.call(n):t.get(n)),f=(n,t,e)=>{if(t.has(n))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(n):t.set(n,e)},v=(n,t,e,o)=>(ke(n,t,"write to private field"),o?o.call(n,e):t.set(n,e),e);var We=(n,t,e,o)=>({set _(r){v(n,t,r,e)},get _(){return d(n,t,o)}});import G from"react";import{useCallback as Xt,useEffect as Yt,useRef as $t}from"react";import{intersect as It}from"valibot";var xt="invoke";function Z(n){return xt in n}function x(n){return n===null}function he(n){return n===!0||n===!1}function c(n){return typeof n=="string"}function ee(n){return typeof n=="number"&&Number.isFinite(n)}function te(n){return typeof n=="function"}function g(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function fe(n){return Array.isArray(n)}function ne(n,t){throw t||new Error(n?`Unexpected value: ${n}`:"Application entered invalid state")}function u(n,...t){if(n)return;let e=Error("Assertion Error"+(t.length>0?": "+t.join(" "):""));if(e.stack)try{let o=e.stack.split(`
var ft=Object.defineProperty;var bt=(n,t,e)=>t in n?ft(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var i=(n,t,e)=>(bt(n,typeof t!="symbol"?t+"":t,e),e),Te=(n,t,e)=>{if(!t.has(n))throw TypeError("Cannot "+e)};var d=(n,t,e)=>(Te(n,t,"read from private field"),e?e.call(n):t.get(n)),h=(n,t,e)=>{if(t.has(n))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(n):t.set(n,e)},v=(n,t,e,o)=>(Te(n,t,"write to private field"),o?o.call(n,e):t.set(n,e),e);var We=(n,t,e,o)=>({set _(r){v(n,t,r,e)},get _(){return d(n,t,o)}});import z from"react";import{useCallback as _t,useEffect as Kt,useRef as Xt}from"react";import{intersect as Pt}from"valibot";var yt="invoke";function ee(n){return yt in n}function x(n){return n===null}function ge(n){return n===!0||n===!1}function c(n){return typeof n=="string"}function te(n){return typeof n=="number"&&Number.isFinite(n)}function ne(n){return typeof n=="function"}function g(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function he(n){return Array.isArray(n)}function oe(n,t){throw t||new Error(n?`Unexpected value: ${n}`:"Application entered invalid state")}function u(n,...t){if(n)return;let e=Error("Assertion Error"+(t.length>0?": "+t.join(" "):""));if(e.stack)try{let o=e.stack.split(`
`);o[1]?.includes("assert")?(o.splice(1,1),e.stack=o.join(`
`)):o[0]?.includes("assert")&&(o.splice(0,1),e.stack=o.join(`
`))}catch{}throw e}import*as a from"valibot";function I(n){return a.optional(n)}var Re=a.boolean(),F=a.number(),_=I(F),S=a.string(),C=I(S);function m(n){return a.object(n)}function De(n){return I(m(n))}function W(...n){return a.union(n.map(t=>a.literal(t)))}function we(...n){return I(a.union(n.map(t=>a.literal(t))))}var Ee=n=>a.instance(n),k=a.merge;var oe=a.record,ie=a.unknown();var re=a.union,b=a.literal,Le=a.special,Me=a.is;var cn=m({id:S}),Nt="ImageAsset",vt="__class";function se(n){return g(n)?n[vt]===Nt:!1}var R,K,p=class{constructor(t,e){i(this,"id");i(this,"url");i(this,"thumbnailUrl");f(this,R,void 0);f(this,K,void 0);u(Z(e)),this.url=t.url,v(this,K,e),this.id=t.id,this.thumbnailUrl=t.thumbnailUrl}async measure(){return Dt(this.url)}async getData(){if(d(this,R)&&d(this,R).bytes.length>0)return d(this,R);let t=await d(this,K).invoke("getImageData",{id:this.id});if(!t)throw new Error("Failed to load image data");return v(this,R,t),t}async loadBitmap(){let{mimeType:t,bytes:e}=await this.getData(),o=new Blob([e],{type:t});return createImageBitmap(o)}async loadImage(){let t=await this.getData(),e=URL.createObjectURL(new Blob([t.bytes]));return new Promise((o,r)=>{let s=new Image;s.onload=()=>o(s),s.onerror=()=>r(),s.src=e})}};R=new WeakMap,K=new WeakMap;var St=m({name:C}),Fe=m({bytes:Ee(Uint8Array),mimeType:S}),At=k([Fe,m({type:b("bytes")})]),Tt=m({type:b("url"),url:S}),Ct=re([At,Tt]),pn=It([St,Ct]),Oe=m({svg:S,name:C});function O(n){return n.type==="bytes"?[n.bytes.buffer]:[]}async function X(n){return Me(Fe,n)?{type:"bytes",...n}:n instanceof File?Rt(n):{type:"url",url:n}}function kt(n,t){return{...n,name:t}}function be(n){return Promise.all(n.map(async t=>{let e=await X(t.image);return kt(e,t.name)}))}function Wt(n){if(!n.startsWith("image/"))throw new Error(`Unsupported mime type: ${n}`)}async function Rt(n){return new Promise((t,e)=>{let o=new FileReader;o.onload=r=>{let s=n.type;Wt(n.type);let l=r.target?.result;if(!l||!(l instanceof ArrayBuffer)){e(new Error("Failed to read file, arrayBuffer is null"));return}let y=new Uint8Array(l);t({bytes:y,mimeType:s,type:"bytes"})},o.onerror=r=>{e(r)},o.readAsArrayBuffer(n)})}async function Dt(n){let t=n instanceof File,e=t?URL.createObjectURL(n):n,o=new Image;return o.crossOrigin="anonymous",o.src=e,await o.decode().finally(()=>{t&&URL.revokeObjectURL(e)}),{height:o.height,width:o.width}}function D(n){if(Et(n))return Lt(n);if(fe(n))return n.map(D);if(g(n)){let t={};for(let e in n)t[e]=D(n[e]);return t}return n}function Ve(n,t){let e={};for(let o in n)e[o]=ye(n[o],t);return e}function ye(n,t){if(wt(n)&&n.__class==="ImageAsset")return new p(n,t);if(g(n)){let e={};for(let o in n)e[o]=ye(n[o],t);return e}return fe(n)?n.map(e=>ye(e,t)):n}function wt(n){return!!se(n)}function Et(n){return n instanceof p}function Lt(n){if(n instanceof p)return{__class:"ImageAsset",id:n.id,thumbnailUrl:n.thumbnailUrl,url:n.url};ne(n)}import*as Be from"valibot";var Mt=(()=>{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 t=()=>{n&&(document.head.removeChild(n),n=null,r())},e=s=>{s.buttons>0&&s.buttons&1||t()},o=()=>{t()};window.addEventListener("pointerup",e,!0),window.addEventListener("pointermove",e,!0),window.addEventListener("blur",o);function r(){window.removeEventListener("pointerup",e,!0),window.removeEventListener("pointermove",e,!0),window.removeEventListener("blur",o)}}}})(),Ue=5,Pe=m({dragSessionId:S}),Ft=k([m({type:b("svg")}),Oe]),Ot=m({type:b("image"),image:S,name:C,previewImage:C}),Vt=m({type:b("component"),moduleUrl:S,attributes:I(Le(g)),controlAttributes:I(oe(ie))}),vn=Be.union([Ft,Ot,Vt]),He=m({x:F,y:F}),Ge=m({width:F,height:F}),Ut=k([He,Ge]),ze=m({mouse:He}),Bt=m({elementRect:Ut,svgSize:I(Ge)}),Sn=k([Pe,Bt,ze]),An=k([Pe,ze]),Tn=k([Pe,m({cancelled:Re})]),Ht=(()=>{let n=1;return{next:()=>`drag-${n++}`}})();function je(n,t,e){u(Z(n));let o=document.body.style.cursor,r={type:"idle"},s=document.body,l=P=>{if(r.type==="idle")return;let{dragSessionId:T}=r.dragStart;r.type==="dragging"&&n.invoke("onDragEnd",{...P,dragSessionId:T}),r={type:"idle"},bt()},y=P=>{if(r.type==="idle")return;let{dragSessionId:T}=r.dragStart;if(!(P.buttons>0&&!!(P.buttons&1))){l({cancelled:!1});return}let{clientX:z,clientY:j}=P;if(r.type==="pointerDown"){let M=z-r.dragStart.mouse.x,Te=j-r.dragStart.mouse.y;if(Math.abs(M)<Ue&&Math.abs(Te)<Ue)return;r={type:"dragging",dragStart:r.dragStart},n.invoke("onDragStart",r.dragStart),document.getSelection()?.empty(),Mt.disableUntilMouseUp()}s.setPointerCapture(P.pointerId);let ge={x:z,y:j};n.invoke("onDrag",{dragSessionId:T,mouse:ge}).then(M=>{r.type==="dragging"&&(document.body.style.cursor=M??"")})},Ne=P=>{P.key==="Escape"&&l({cancelled:!0})},ve=()=>{l({cancelled:!0})},Se=P=>{l({cancelled:!0});let T=t.getBoundingClientRect(),Ae={x:T.x,y:T.y,width:T.width,height:T.height},z,j=t.querySelectorAll("svg");if(j.length===1){let Ce=j.item(0).getBoundingClientRect();z={width:Ce.width,height:Ce.height}}let ge={x:P.clientX,y:P.clientY},M=Ht.next();r={type:"pointerDown",dragStart:{dragSessionId:M,elementRect:Ae,svgSize:z,mouse:ge}},n.invoke("setDragData",M,e()),s.addEventListener("pointermove",y,!0),s.addEventListener("pointerup",y,!0),window.addEventListener("keydown",Ne,!0),window.addEventListener("blur",ve)};t.addEventListener("pointerdown",Se);function bt(){document.body.style.cursor=o,s.removeEventListener("pointermove",y,!0),s.removeEventListener("pointerup",y,!0),window.removeEventListener("keydown",Ne,!0),window.removeEventListener("blur",ve)}return()=>{t.removeEventListener("pointerdown",Se),l({cancelled:!0})}}var Rn=W("default","image","editImage");var Gt={pluginReadySignal:!0,pluginReadyResponse:!0,methodInvocation:!0,methodResponse:!0,subscribe:!0,unsubscribe:!0,subscriptionMessage:!0};function zt(n){return c(n)&&n in Gt}function _e(n){return g(n)&&zt(n["type"])}var Ke=["FrameNode","SVGNode"],jt=["WebPageNode","SmartComponentNode","UnknownNode","CodeComponentNode","TextNode"],On=W(...Ke),Vn=W(...Ke,...jt),Un=oe(ie),N,A=class{constructor(t,e){i(this,"id");f(this,N,void 0);u(c(t.id),"Node must have an id"),this.id=t.id,v(this,N,e)}remove(){return d(this,N).removeNode(this.id)}select(){return d(this,N).setSelection([this.id])}clone(){return d(this,N).cloneNode(this.id)}setAttributes(t){return d(this,N).setAttributes(this.id,t)}getRect(){return d(this,N).getRect(this.id)}getParent(){return d(this,N).getParent(this.id)}getChildren(){return ae(this)?Promise.resolve([]):d(this,N).getChildren(this.id)}async*walk(){if(yield this,!ae(this))for(let t of await this.getChildren())yield*await t.walk()}};N=new WeakMap;var w=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"backgroundColor");i(this,"backgroundImage");i(this,"backgroundGradient");i(this,"rotation");i(this,"opacity");i(this,"borderRadius");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");i(this,"maxWidth");i(this,"minWidth");i(this,"maxHeight");i(this,"minHeight");i(this,"aspectRatio");u(e.__class==="FrameNode","FrameNode must have a __class property"),this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.backgroundColor=e.backgroundColor??null,this.backgroundImage=e.backgroundImage?new p(e.backgroundImage,o):null,this.backgroundGradient=e.backgroundGradient??null,this.rotation=e.rotation??0,this.opacity=e.opacity??1,this.borderRadius=e.borderRadius??null,u(e.position,"Must have a position"),this.position=e.position,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null,this.maxWidth=e.maxWidth??null,this.minWidth=e.minWidth??null,this.maxHeight=e.maxHeight??null,this.minHeight=e.minHeight??null,this.aspectRatio=e.aspectRatio??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},Y=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"html");i(this,"rotation");i(this,"opacity");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");i(this,"maxWidth");i(this,"minWidth");i(this,"maxHeight");i(this,"minHeight");u(e.html,"Text node must have a non-empty HTML string"),this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.html=e.html,this.rotation=e.rotation??0,this.opacity=e.opacity??1,u(e.position,"Must have a position"),this.position=e.position,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null,this.maxWidth=e.maxWidth??null,this.minWidth=e.minWidth??null,this.maxHeight=e.maxHeight??null,this.minHeight=e.minHeight??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},E=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"svg");i(this,"rotation");i(this,"opacity");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");u(e.svg,"SVG node must have a non-empty SVG string"),this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.svg=e.svg,this.rotation=e.rotation??0,this.opacity=e.opacity??1,u(e.position,"Must have a position"),this.position=e.position??null,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},$=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"componentIdentifier");i(this,"controlAttributes");i(this,"rotation");i(this,"opacity");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");i(this,"maxWidth");i(this,"minWidth");i(this,"maxHeight");i(this,"minHeight");i(this,"aspectRatio");u(e.componentIdentifier,"Code component node must have an identifier"),this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.componentIdentifier=e.componentIdentifier,this.controlAttributes=Ve(e.controlAttributes??{},o),this.rotation=e.rotation??0,this.opacity=e.opacity??1,u(e.position,"Must have a position"),this.position=e.position,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null,this.maxWidth=e.maxWidth??null,this.minWidth=e.minWidth??null,this.maxHeight=e.maxHeight??null,this.minHeight=e.minHeight??null,this.aspectRatio=e.aspectRatio??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}setControlAttributes(e){return this.setAttributes({controlAttributes:e})}},q=class extends A{constructor(t,e){super(t,e)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},Q=class extends A{constructor(e,o){super(e,o);i(this,"name");this.name=e.name??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},J=class extends A{constructor(t,e){super(t,e)}clone(){throw Error("Can not clone unknown node")}setAttributes(t){throw Error("Can not set attributes on unknown node")}};function h(n,t){switch(n.__class){case"WebPageNode":return new q(n,t);case"SmartComponentNode":return new Q(n,t);case"CodeComponentNode":return new $(n,t);case"FrameNode":return new w(n,t);case"SVGNode":return new E(n,t);case"TextNode":return new Y(n,t);case"UnknownNode":return new J(n,t);default:return new J(n,t)}}function de(n){return D(n)}function Xe(n){return n instanceof w}function Ye(n){return n instanceof Y}function $e(n){return n instanceof E}function le(n){return n instanceof $}function qe(n){return n instanceof q}function Qe(n){return n instanceof Q}function ae(n){return n instanceof J}function ue(n){return!!(Xe(n)||Ye(n)||le(n)||$e(n)||ae(n))}function Je(n){return!!(qe(n)||Qe(n)||ae(n))}var V=null;function Ze(n){if(!V){let e=document.createElement("style");document.head.appendChild(e),V=e.sheet}if(!V){n();return}let t=V.insertRule("* { transition: none !important; animation: none !important; }");n(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{V&&V.deleteRule(t)})})}var _t=0,ce,U,L,B,H,pe,me=class{constructor({isTestEnv:t}={}){f(this,ce,0);f(this,U,[]);f(this,L,void 0);f(this,B,new Map);f(this,H,void 0);f(this,pe,new Promise(t=>{v(this,H,t)}));i(this,"subscriptions",new Map);i(this,"onMessage",t=>{let e=t.data;if(_e(e))switch(e.type){case"pluginReadyResponse":{if(!t.source)throw new Error("No 'source' on incoming message: "+e.type);u(d(this,H)),d(this,H).call(this,e.mode),this.applyPluginTheme(e.theme),v(this,L,(r,s)=>window.parent.postMessage(r,t.origin,s));for(let r of d(this,U))d(this,L).call(this,...r);v(this,U,[]);break}case"methodInvocation":throw new Error("Method invocation cannot be handled by plugin.");case"methodResponse":{let o=d(this,B).get(e.id);if(!o)throw new Error(`No handler for response with id ${e.id}`);d(this,B).delete(e.id),e.error?o.reject(e.error):o.resolve(e.result);break}case"subscriptionMessage":{let{topic:o,payload:r}=e,s=this.subscriptions.get(o);if(!s)throw new Error("Received a subscription message but no handler present");for(let l of s)l(r);break}case"unsubscribe":case"subscribe":case"pluginReadySignal":throw new Error("Plugin received invalid event: "+t.type);default:ne(e)}});i(this,"applyPluginTheme",t=>{Ze(()=>{document.body.setAttribute("data-framer-theme",t.mode);for(let e in t.tokens)document.body.style.setProperty(e,t.tokens[e])})});if(t)return;window.addEventListener("message",this.onMessage);let e={type:"pluginReadySignal",breakingChangesVersion:_t};window.parent.postMessage(e,"*"),this.subscribe("theme",this.applyPluginTheme),window.addEventListener("pointerdown",()=>{this.invoke("onPointerDown")})}invoke(t,...e){return this.invokeTransferable(t,void 0,...e)}invokeTransferable(t,e,...o){return new Promise((r,s)=>{let l={args:o,methodName:t,id:We(this,ce)._++,type:"methodInvocation"},y=r;d(this,B).set(l.id,{resolve:y,reject:s}),this.queueMessage(l,e)})}subscribe(t,e){this.queueMessage({type:"subscribe",topic:t});let o=this.subscriptions.get(t)??new Set;return o.add(e),this.subscriptions.set(t,o),()=>{let r=this.subscriptions.get(t)??new Set;r.delete(e),r.size===0&&this.queueMessage({type:"unsubscribe",topic:t}),this.subscriptions.set(t,r)}}queueMessage(t,e){if(!d(this,L)){d(this,U).push([t,e]);return}d(this,L).call(this,t,e)}async showUI(t={}){return this.invoke("showUI",t)}async hideUI(){return this.invoke("hideUI")}async closePlugin(t,e){return this.invoke("closePlugin",t,e)}async getMode(){return d(this,pe)}async getCurrentUser(){return this.invoke("getCurrentUser")}async getSelection(){return(await this.invoke("getSelection")).map(e=>{let o=h(e,this);return u(ue(o)),o})}async setSelection(t){let e=c(t)?[t]:Array.from(t);return this.invoke("setSelection",e)}subscribeToSelection(t){return this.subscribe("selection",e=>{let o=e.map(r=>{let s=h(r,this);return u(ue(s)),s});t(o)})}async getCanvasRoot(){let t=await this.invoke("getCanvasRoot");return h(t,this)}subscribeToCanvasRoot(t){return this.subscribe("canvasRoot",e=>{let o=h(e,this);u(Je(o)),t(o)})}async getPublishInfo(){return this.invoke("getPublishInfo")}subscribeToPublishInfo(t){return this.subscribe("publishInfo",t)}async createFrameNode(t,e){let o=de(t),r=await this.invoke("createNode","FrameNode",e??null,o);if(!r)return null;let s=h(r,this);return u(s instanceof w),s}async createSVGNode(t,e){let o=de(t),r=await this.invoke("createNode","SVGNode",e??null,o);if(!r)return null;let s=h(r,this);return u(s instanceof E),s}async removeNode(t){return this.invoke("removeNode",t)}async cloneNode(t){let e=await this.invoke("cloneNode",t);return e?h(e,this):null}async getNode(t){let e=await this.invoke("getNode",t);return e?h(e,this):null}async getParent(t){let e=await this.invoke("getParent",t);return e?h(e,this):null}async getChildren(t){return(await this.invoke("getChildren",t)).map(o=>{let r=h(o,this);return u(ue(r)),r})}async getRect(t){return this.invoke("getRect",t)}async setAttributes(t,e){let o=de(e),r=await this.invoke("setAttributes",t,o);return r?h(r,this):null}async setParent(t,e,o){return this.invoke("setParent",t,e,o)}async getImage(){let t=await this.invoke("getImage");return t?new p(t,this):null}subscribeToImage(t){return this.subscribe("image",e=>{if(!e){t(null);return}t(new p(e,this))})}async addImage(t){let e=await X(t instanceof File?t:t.image),o=O(e);return this.invokeTransferable("addImage",o,{...e,name:t?.name})}async setImage(t){let e=await X(t instanceof File?t:t.image),o=O(e);return this.invokeTransferable("setImage",o,{...e,name:t?.name})}async uploadImage(t){let e=await X(t instanceof File?t:t.image),o=O(e),r=await this.invokeTransferable("uploadImage",o,{...e,name:t?.name});return new p(r,this)}async addImages(t){let e=await be(t),o=e.flatMap(O);await this.invokeTransferable("addImages",o,e)}async uploadImages(t){let e=await be(t),o=e.flatMap(O),r=await this.invokeTransferable("uploadImages",o,e),s=[];for(let l of r)s.push(new p(l,this));return s}async addSVG(t){return console.error("HELLO"),this.invoke("addSVG",t)}async addComponent(t,e,o){let r=D(e),s=D(o),l=await this.invoke("addComponent",t,g(r)?r:void 0,g(s)?s:void 0);if(!l)return null;let y=h(l,this);return u(le(y),"Code component node must be defined"),y}async getText(){return this.invoke("getText")}async setText(t,e){return this.invoke("setText",t,e)}async addText(t,e){return this.invoke("addText",t,e)}async setCustomCode(t){return this.invoke("setCustomCode",t)}async getCustomCode(){return this.invoke("getCustomCode")}subscribeToCustomHTML(t){return this.subscribe("customCode",t)}subscribeToText(t){return this.subscribe("text",t)}makeDraggable(t,e){return je(this,t,e)}};ce=new WeakMap,U=new WeakMap,L=new WeakMap,B=new WeakMap,H=new WeakMap,pe=new WeakMap;var Qn=m({width:_,height:_,position:we("center","top left","bottom left","top right","bottom right"),title:C,resizable:I(re([b(!0),b(!1),b("width"),b("height")])),minWidth:_,minHeight:_}),Kt=W("info","success","error"),Jn=De({variant:I(Kt)});var xe=new me;function Ie(n,t){let e=qt(()=>te(t)?t():t);Yt(()=>{let o=n.current;if(o instanceof HTMLElement)return xe.makeDraggable(o,e)},[e])}function qt(n){let t=$t(n);return t.current=n,Xt((...e)=>t.current(...e),[])}var Qt=G.forwardRef(function({data:t,children:e,...o},r){let s=G.useRef(null);if(Ie(s,t),G.isValidElement(e)){let l=Object.assign({},o);return g(e.props)&&Object.assign(l,e.props),l.ref=en(s,r,e.ref),G.cloneElement(e,l)}return G.Children.count(e)>1&&G.Children.only(e),null}),Jt="current";function Zt(n){return g(n)&&Jt in n}function en(...n){return t=>{for(let e of n)te(e)?e(t):Zt(e)&&(e.current=t)}}var tn={fixed:!0,sticky:!0,absolute:!0,relative:!0},et="position";function go(n){if(!(et in n))return!1;let t=n[et];return c(t)&&tn[t]===!0}var tt="top";function ho(n){if(!(tt in n))return!1;let t=n[tt];return c(t)||x(t)}var nt="width";function fo(n){if(!(nt in n))return!1;let t=n[nt];return c(t)||x(t)}var ot="maxWidth";function bo(n){if(!(ot in n))return!1;let t=n[ot];return c(t)||x(t)}var it="aspectRatio";function yo(n){if(!(it in n))return!1;let t=n[it];return ee(t)||x(t)}var rt="name";function Po(n){if(!(rt in n))return!1;let t=n[rt];return c(t)||x(t)}var st="visible";function xo(n){if(!(st in n))return!1;let t=n[st];return he(t)}var at="locked";function Io(n){if(!(at in n))return!1;let t=n[at];return he(t)}var dt="backgroundColor";function No(n){if(!(dt in n))return!1;let t=n[dt];return c(t)||x(t)}var lt="backgroundImage";function vo(n){if(!(lt in n))return!1;let t=n[lt];return t instanceof p||x(t)}var ut="backgroundImage";function So(n){if(!(ut in n))return!1;let t=n[ut];return t instanceof p?!1:se(t)||x(t)}var mt="backgroundGradient";function Ao(n){if(!(mt in n))return!1;let t=n[mt];return c(t)||x(t)}var ct="rotation";function To(n){if(!(ct in n))return!1;let t=n[ct];return ee(t)}var pt="opacity";function Co(n){if(!(pt in n))return!1;let t=n[pt];return ee(t)}var gt="borderRadius";function ko(n){if(!(gt in n))return!1;let t=n[gt];return c(t)||x(t)}var ht="html";function Wo(n){if(!(ht in n))return!1;let t=n[ht];return c(t)}var ft="svg";function Ro(n){if(!(ft in n))return!1;let t=n[ft];return c(t)}export{$ as CodeComponentNode,Qt as Draggable,w as FrameNode,E as SVGNode,Q as SmartComponentNode,Y as TextNode,q as WebPageNode,xe as framer,le as isCodeComponentNode,Xe as isFrameNode,$e as isSVGNode,Qe as isSmartComponentNode,Ye as isTextNode,qe as isWebPageNode,Ie as useMakeDraggable,yo as withAspectRatio,No as withBackgroundColor,Ao as withBackgroundGradient,vo as withBackgroundImage,So as withBackgroundImageData,ko as withBorderRadius,Wo as withHTML,Io as withLocked,Po as withName,Co as withOpacity,ho as withPins,go as withPosition,To as withRotation,Ro as withSVG,fo as withSize,bo as withSizeConstraints,xo as withVisible};
`))}catch{}throw e}import*as a from"valibot";function I(n){return a.optional(n)}var Re=a.boolean(),M=a.number(),_=I(M),S=a.string(),k=I(S);function m(n){return a.object(n)}function De(n){return I(m(n))}function W(...n){return a.union(n.map(t=>a.literal(t)))}function we(...n){return I(a.union(n.map(t=>a.literal(t))))}var Ee=n=>a.instance(n),T=a.merge;var ie=a.record,re=a.unknown();var F=a.union,f=a.literal,Le=a.special,Me=a.is;var un=m({id:S}),xt="ImageAsset",It="__class";function se(n){return g(n)?n[It]===xt:!1}var R,K,p=class{constructor(t,e){i(this,"id");i(this,"url");i(this,"thumbnailUrl");h(this,R,void 0);h(this,K,void 0);u(ee(e)),this.url=t.url,v(this,K,e),this.id=t.id,this.thumbnailUrl=t.thumbnailUrl}async measure(){return Wt(this.url)}async getData(){if(d(this,R)&&d(this,R).bytes.length>0)return d(this,R);let t=await d(this,K).invoke("getImageData",{id:this.id});if(!t)throw new Error("Failed to load image data");return v(this,R,t),t}async loadBitmap(){let{mimeType:t,bytes:e}=await this.getData(),o=new Blob([e],{type:t});return createImageBitmap(o)}async loadImage(){let t=await this.getData(),e=URL.createObjectURL(new Blob([t.bytes]));return new Promise((o,r)=>{let s=new Image;s.onload=()=>o(s),s.onerror=()=>r(),s.src=e})}};R=new WeakMap,K=new WeakMap;var Nt=m({name:k}),Fe=m({bytes:Ee(Uint8Array),mimeType:S}),vt=T([Fe,m({type:f("bytes")})]),St=m({type:f("url"),url:S}),At=F([vt,St]),mn=Pt([Nt,At]),Ve=m({svg:S,name:k});function V(n){return n.type==="bytes"?[n.bytes.buffer]:[]}async function X(n){return Me(Fe,n)?{type:"bytes",...n}:n instanceof File?Tt(n):{type:"url",url:n}}function Ct(n,t){return{...n,name:t}}function fe(n){return Promise.all(n.map(async t=>{let e=await X(t.image);return Ct(e,t.name)}))}function kt(n){if(!n.startsWith("image/"))throw new Error(`Unsupported mime type: ${n}`)}async function Tt(n){return new Promise((t,e)=>{let o=new FileReader;o.onload=r=>{let s=n.type;kt(n.type);let l=r.target?.result;if(!l||!(l instanceof ArrayBuffer)){e(new Error("Failed to read file, arrayBuffer is null"));return}let y=new Uint8Array(l);t({bytes:y,mimeType:s,type:"bytes"})},o.onerror=r=>{e(r)},o.readAsArrayBuffer(n)})}async function Wt(n){let t=n instanceof File,e=t?URL.createObjectURL(n):n,o=new Image;return o.crossOrigin="anonymous",o.src=e,await o.decode().finally(()=>{t&&URL.revokeObjectURL(e)}),{height:o.height,width:o.width}}function D(n){if(Dt(n))return wt(n);if(he(n))return n.map(D);if(g(n)){let t={};for(let e in n)t[e]=D(n[e]);return t}return n}function Oe(n,t){let e={};for(let o in n)e[o]=be(n[o],t);return e}function be(n,t){if(Rt(n)&&n.__class==="ImageAsset")return new p(n,t);if(g(n)){let e={};for(let o in n)e[o]=be(n[o],t);return e}return he(n)?n.map(e=>be(e,t)):n}function Rt(n){return!!se(n)}function Dt(n){return n instanceof p}function wt(n){if(n instanceof p)return{__class:"ImageAsset",id:n.id,thumbnailUrl:n.thumbnailUrl,url:n.url};oe(n)}var Et=(()=>{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 t=()=>{n&&(document.head.removeChild(n),n=null,r())},e=s=>{s.buttons>0&&s.buttons&1||t()},o=()=>{t()};window.addEventListener("pointerup",e,!0),window.addEventListener("pointermove",e,!0),window.addEventListener("blur",o);function r(){window.removeEventListener("pointerup",e,!0),window.removeEventListener("pointermove",e,!0),window.removeEventListener("blur",o)}}}})(),Ue=5,ye=m({dragSessionId:S}),Lt=T([m({type:f("svg")}),Ve]),Mt=m({type:f("image"),image:S,name:k,previewImage:k}),Ft=m({type:f("component"),moduleUrl:S,attributes:I(Le(g)),controlAttributes:I(ie(re))}),In=F([Lt,Mt,Ft]),Be=m({x:M,y:M}),He=m({width:M,height:M}),Vt=T([Be,He]),ze=m({mouse:Be}),Ot=m({elementRect:Vt,svgSize:I(He)}),Nn=T([ye,Ot,ze]),vn=T([ye,ze]),Sn=T([ye,m({cancelled:Re})]),Ut=(()=>{let n=1;return{next:()=>`drag-${n++}`}})();function Ge(n,t,e){u(ee(n));let o=document.body.style.cursor,r={type:"idle"},s=document.body,l=P=>{if(r.type==="idle")return;let{dragSessionId:C}=r.dragStart;r.type==="dragging"&&n.invoke("onDragEnd",{...P,dragSessionId:C}),r={type:"idle"},ht()},y=P=>{if(r.type==="idle")return;let{dragSessionId:C}=r.dragStart;if(!(P.buttons>0&&!!(P.buttons&1))){l({cancelled:!1});return}let{clientX:G,clientY:j}=P;if(r.type==="pointerDown"){let L=G-r.dragStart.mouse.x,Ce=j-r.dragStart.mouse.y;if(Math.abs(L)<Ue&&Math.abs(Ce)<Ue)return;r={type:"dragging",dragStart:r.dragStart},n.invoke("onDragStart",r.dragStart),document.getSelection()?.empty(),Et.disableUntilMouseUp()}s.setPointerCapture(P.pointerId);let pe={x:G,y:j};n.invoke("onDrag",{dragSessionId:C,mouse:pe}).then(L=>{r.type==="dragging"&&(document.body.style.cursor=L??"")})},Ne=P=>{P.key==="Escape"&&l({cancelled:!0})},ve=()=>{l({cancelled:!0})},Se=P=>{l({cancelled:!0});let C=t.getBoundingClientRect(),Ae={x:C.x,y:C.y,width:C.width,height:C.height},G,j=t.querySelectorAll("svg");if(j.length===1){let ke=j.item(0).getBoundingClientRect();G={width:ke.width,height:ke.height}}let pe={x:P.clientX,y:P.clientY},L=Ut.next();r={type:"pointerDown",dragStart:{dragSessionId:L,elementRect:Ae,svgSize:G,mouse:pe}},n.invoke("setDragData",L,e()),s.addEventListener("pointermove",y,!0),s.addEventListener("pointerup",y,!0),window.addEventListener("keydown",Ne,!0),window.addEventListener("blur",ve)};t.addEventListener("pointerdown",Se);function ht(){document.body.style.cursor=o,s.removeEventListener("pointermove",y,!0),s.removeEventListener("pointerup",y,!0),window.removeEventListener("keydown",Ne,!0),window.removeEventListener("blur",ve)}return()=>{t.removeEventListener("pointerdown",Se),l({cancelled:!0})}}var Tn=W("default","image","editImage");var Bt={methodResponse:!0,pluginReadyResponse:!0,subscriptionMessage:!0};function Ht(n){return c(n)&&n in Bt}function je(n){return g(n)&&Ht(n["type"])}var _e=["FrameNode"],zt=["SVGNode","WebPageNode","SmartComponentNode","UnknownNode","CodeComponentNode","TextNode"],Mn=W(..._e),Fn=W(..._e,...zt),Vn=ie(re),N,A=class{constructor(t,e){i(this,"id");h(this,N,void 0);u(c(t.id),"Node must have an id"),this.id=t.id,v(this,N,e)}remove(){return d(this,N).removeNode(this.id)}select(){return d(this,N).setSelection([this.id])}clone(){return d(this,N).cloneNode(this.id)}setAttributes(t){return d(this,N).setAttributes(this.id,t)}getRect(){return d(this,N).getRect(this.id)}getParent(){return d(this,N).getParent(this.id)}getChildren(){return ae(this)?Promise.resolve([]):d(this,N).getChildren(this.id)}async*walk(){if(yield this,!ae(this))for(let t of await this.getChildren())yield*await t.walk()}};N=new WeakMap;var w=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"backgroundColor");i(this,"backgroundImage");i(this,"backgroundGradient");i(this,"rotation");i(this,"opacity");i(this,"borderRadius");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");i(this,"maxWidth");i(this,"minWidth");i(this,"maxHeight");i(this,"minHeight");i(this,"aspectRatio");u(e.__class==="FrameNode","FrameNode must have a __class property"),this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.backgroundColor=e.backgroundColor??null,this.backgroundImage=e.backgroundImage?new p(e.backgroundImage,o):null,this.backgroundGradient=e.backgroundGradient??null,this.rotation=e.rotation??0,this.opacity=e.opacity??1,this.borderRadius=e.borderRadius??null,u(e.position,"Must have a position"),this.position=e.position,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null,this.maxWidth=e.maxWidth??null,this.minWidth=e.minWidth??null,this.maxHeight=e.maxHeight??null,this.minHeight=e.minHeight??null,this.aspectRatio=e.aspectRatio??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},Y=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"rotation");i(this,"opacity");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");i(this,"maxWidth");i(this,"minWidth");i(this,"maxHeight");i(this,"minHeight");this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.rotation=e.rotation??0,this.opacity=e.opacity??1,u(e.position,"Must have a position"),this.position=e.position,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null,this.maxWidth=e.maxWidth??null,this.minWidth=e.minWidth??null,this.maxHeight=e.maxHeight??null,this.minHeight=e.minHeight??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},$=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"svg");i(this,"rotation");i(this,"opacity");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");u(e.svg,"SVG node must have a non-empty SVG string"),this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.svg=e.svg,this.rotation=e.rotation??0,this.opacity=e.opacity??1,u(e.position,"Must have a position"),this.position=e.position??null,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},q=class extends A{constructor(e,o){super(e,o);i(this,"name");i(this,"visible");i(this,"locked");i(this,"componentIdentifier");i(this,"controlAttributes");i(this,"rotation");i(this,"opacity");i(this,"position");i(this,"top");i(this,"right");i(this,"bottom");i(this,"left");i(this,"centerX");i(this,"centerY");i(this,"width");i(this,"height");i(this,"maxWidth");i(this,"minWidth");i(this,"maxHeight");i(this,"minHeight");i(this,"aspectRatio");u(e.componentIdentifier,"Code component node must have an identifier"),this.name=e.name??null,this.visible=e.visible??!0,this.locked=e.locked??!1,this.componentIdentifier=e.componentIdentifier,this.controlAttributes=Oe(e.controlAttributes??{},o),this.rotation=e.rotation??0,this.opacity=e.opacity??1,u(e.position,"Must have a position"),this.position=e.position,this.left=e.left??null,this.right=e.right??null,this.top=e.top??null,this.bottom=e.bottom??null,this.centerX=e.centerX??null,this.centerY=e.centerY??null,this.width=e.width??null,this.height=e.height??null,this.maxWidth=e.maxWidth??null,this.minWidth=e.minWidth??null,this.maxHeight=e.maxHeight??null,this.minHeight=e.minHeight??null,this.aspectRatio=e.aspectRatio??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}setControlAttributes(e){return this.setAttributes({controlAttributes:e})}},Q=class extends A{constructor(t,e){super(t,e)}clone(){return super.clone()}setAttributes(t){return super.setAttributes(t)}},J=class extends A{constructor(e,o){super(e,o);i(this,"name");this.name=e.name??null}clone(){return super.clone()}setAttributes(e){return super.setAttributes(e)}},Z=class extends A{constructor(t,e){super(t,e)}clone(){throw Error("Can not clone unknown node")}setAttributes(t){throw Error("Can not set attributes on unknown node")}};function b(n,t){switch(n.__class){case"WebPageNode":return new Q(n,t);case"SmartComponentNode":return new J(n,t);case"CodeComponentNode":return new q(n,t);case"FrameNode":return new w(n,t);case"SVGNode":return new $(n,t);case"TextNode":return new Y(n,t);case"UnknownNode":return new Z(n,t);default:return new Z(n,t)}}function Pe(n){return D(n)}function Ke(n){return n instanceof w}function Xe(n){return n instanceof Y}function Ye(n){return n instanceof $}function de(n){return n instanceof q}function $e(n){return n instanceof Q}function qe(n){return n instanceof J}function ae(n){return n instanceof Z}function le(n){return!!(Ke(n)||Xe(n)||de(n)||Ye(n)||ae(n))}function Qe(n){return!!($e(n)||qe(n)||ae(n))}var O=null;function Je(n){if(!O){let e=document.createElement("style");document.head.appendChild(e),O=e.sheet}if(!O){n();return}let t=O.insertRule("* { transition: none !important; animation: none !important; }");n(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{O&&O.deleteRule(t)})})}var Gt=0,me,U,E,B,H,ce,ue=class{constructor({isTestEnv:t}={}){h(this,me,0);h(this,U,[]);h(this,E,void 0);h(this,B,new Map);h(this,H,void 0);h(this,ce,new Promise(t=>{v(this,H,t)}));i(this,"subscriptions",new Map);i(this,"onMessage",t=>{let e=t.data;if(je(e))switch(e.type){case"pluginReadyResponse":{if(!t.source)throw new Error("No 'source' on incoming message: "+e.type);u(d(this,H)),d(this,H).call(this,e.mode),this.applyPluginTheme(e.theme),v(this,E,(r,s)=>window.parent.postMessage(r,t.origin,s));for(let r of d(this,U))d(this,E).call(this,...r);v(this,U,[]);break}case"methodResponse":{let o=d(this,B).get(e.id);if(!o)throw new Error(`No handler for response with id ${e.id}`);d(this,B).delete(e.id),e.error?o.reject(e.error):o.resolve(e.result);break}case"subscriptionMessage":{let{topic:o,payload:r}=e,s=this.subscriptions.get(o);if(!s)throw new Error("Received a subscription message but no handler present");for(let l of s)l(r);break}default:oe(e)}});i(this,"applyPluginTheme",t=>{Je(()=>{document.body.setAttribute("data-framer-theme",t.mode);for(let e in t.tokens)document.body.style.setProperty(e,t.tokens[e])})});if(t)return;window.addEventListener("message",this.onMessage);let e={type:"pluginReadySignal",breakingChangesVersion:Gt};window.parent.postMessage(e,"*"),this.subscribe("theme",this.applyPluginTheme),window.addEventListener("pointerdown",()=>{this.invoke("onPointerDown")})}invoke(t,...e){return this.invokeTransferable(t,void 0,...e)}invokeTransferable(t,e,...o){return new Promise((r,s)=>{let l={args:o,methodName:t,id:We(this,me)._++,type:"methodInvocation"},y=r;d(this,B).set(l.id,{resolve:y,reject:s}),this.queueMessage(l,e)})}subscribe(t,e){this.queueMessage({type:"subscribe",topic:t});let o=this.subscriptions.get(t)??new Set;return o.add(e),this.subscriptions.set(t,o),()=>{let r=this.subscriptions.get(t)??new Set;r.delete(e),r.size===0&&this.queueMessage({type:"unsubscribe",topic:t}),this.subscriptions.set(t,r)}}queueMessage(t,e){if(!d(this,E)){d(this,U).push([t,e]);return}d(this,E).call(this,t,e)}async showUI(t={}){return this.invoke("showUI",t)}async hideUI(){return this.invoke("hideUI")}async closePlugin(t,e){return this.invoke("closePlugin",t,e)}async getMode(){return d(this,ce)}async getCurrentUser(){return this.invoke("getCurrentUser")}async getSelection(){return(await this.invoke("getSelection")).map(e=>{let o=b(e,this);return u(le(o)),o})}async setSelection(t){let e=c(t)?[t]:Array.from(t);return this.invoke("setSelection",e)}subscribeToSelection(t){return this.subscribe("selection",e=>{let o=e.map(r=>{let s=b(r,this);return u(le(s)),s});t(o)})}async getCanvasRoot(){let t=await this.invoke("getCanvasRoot");return b(t,this)}subscribeToCanvasRoot(t){return this.subscribe("canvasRoot",e=>{let o=b(e,this);u(Qe(o)),t(o)})}async getPublishInfo(){return this.invoke("getPublishInfo")}subscribeToPublishInfo(t){return this.subscribe("publishInfo",t)}async createFrameNode(t,e){let o=Pe(t),r=await this.invoke("createNode","FrameNode",e??null,o);if(!r)return null;let s=b(r,this);return u(s instanceof w),s}async removeNode(t){return this.invoke("removeNode",t)}async cloneNode(t){let e=await this.invoke("cloneNode",t);return e?b(e,this):null}async getNode(t){let e=await this.invoke("getNode",t);return e?b(e,this):null}async getParent(t){let e=await this.invoke("getParent",t);return e?b(e,this):null}async getChildren(t){return(await this.invoke("getChildren",t)).map(o=>{let r=b(o,this);return u(le(r)),r})}async getRect(t){return this.invoke("getRect",t)}async setAttributes(t,e){let o=Pe(e),r=await this.invoke("setAttributes",t,o);return r?b(r,this):null}async setParent(t,e,o){return this.invoke("setParent",t,e,o)}async getImage(){let t=await this.invoke("getImage");return t?new p(t,this):null}subscribeToImage(t){return this.subscribe("image",e=>{if(!e){t(null);return}t(new p(e,this))})}async addImage(t){let e=await X(t instanceof File?t:t.image),o=V(e);return this.invokeTransferable("addImage",o,{...e,name:t?.name})}async setImage(t){let e=await X(t instanceof File?t:t.image),o=V(e);return this.invokeTransferable("setImage",o,{...e,name:t?.name})}async uploadImage(t){let e=await X(t instanceof File?t:t.image),o=V(e),r=await this.invokeTransferable("uploadImage",o,{...e,name:t?.name});return new p(r,this)}async addImages(t){let e=await fe(t),o=e.flatMap(V);await this.invokeTransferable("addImages",o,e)}async uploadImages(t){let e=await fe(t),o=e.flatMap(V),r=await this.invokeTransferable("uploadImages",o,e),s=[];for(let l of r)s.push(new p(l,this));return s}async addSVG(t){return this.invoke("addSVG",t)}async addComponent(t,e,o){let r=D(e),s=D(o),l=await this.invoke("addComponent",t,g(r)?r:void 0,g(s)?s:void 0);if(!l)return null;let y=b(l,this);return u(de(y),"Code component node must be defined"),y}async getText(){return this.invoke("getText")}async setText(t,e){return this.invoke("setText",t,e)}async addText(t,e){return this.invoke("addText",t,e)}async setCustomCode(t){return this.invoke("setCustomCode",t)}async getCustomCode(){return this.invoke("getCustomCode")}subscribeToCustomCode(t){return this.subscribe("customCode",t)}subscribeToText(t){return this.subscribe("text",t)}makeDraggable(t,e){return Ge(this,t,e)}};me=new WeakMap,U=new WeakMap,E=new WeakMap,B=new WeakMap,H=new WeakMap,ce=new WeakMap;var $n=m({width:_,height:_,position:we("center","top left","bottom left","top right","bottom right"),title:k,resizable:I(F([f(!0),f(!1),f("width"),f("height")])),minWidth:_,minHeight:_}),jt=W("info","success","error"),qn=De({variant:I(jt)});var xe=new ue;function Ie(n,t){let e=Yt(()=>ne(t)?t():t);Kt(()=>{let o=n.current;if(o instanceof HTMLElement)return xe.makeDraggable(o,e)},[e])}function Yt(n){let t=Xt(n);return t.current=n,_t((...e)=>t.current(...e),[])}var $t=z.forwardRef(function({data:t,children:e,...o},r){let s=z.useRef(null);if(Ie(s,t),z.isValidElement(e)){let l=Object.assign({},o);return g(e.props)&&Object.assign(l,e.props),l.ref=Jt(s,r,e.ref),z.cloneElement(e,l)}return z.Children.count(e)>1&&z.Children.only(e),null}),qt="current";function Qt(n){return g(n)&&qt in n}function Jt(...n){return t=>{for(let e of n)ne(e)?e(t):Qt(e)&&(e.current=t)}}var Zt={fixed:!0,sticky:!0,absolute:!0,relative:!0},Ze="position";function co(n){if(!(Ze in n))return!1;let t=n[Ze];return c(t)&&Zt[t]===!0}var et="top";function po(n){if(!(et in n))return!1;let t=n[et];return c(t)||x(t)}var tt="width";function go(n){if(!(tt in n))return!1;let t=n[tt];return c(t)||x(t)}var nt="maxWidth";function ho(n){if(!(nt in n))return!1;let t=n[nt];return c(t)||x(t)}var ot="aspectRatio";function fo(n){if(!(ot in n))return!1;let t=n[ot];return te(t)||x(t)}var it="name";function bo(n){if(!(it in n))return!1;let t=n[it];return c(t)||x(t)}var rt="visible";function yo(n){if(!(rt in n))return!1;let t=n[rt];return ge(t)}var st="locked";function Po(n){if(!(st in n))return!1;let t=n[st];return ge(t)}var at="backgroundColor";function xo(n){if(!(at in n))return!1;let t=n[at];return c(t)||x(t)}var dt="backgroundImage";function Io(n){if(!(dt in n))return!1;let t=n[dt];return t instanceof p||x(t)}var lt="backgroundImage";function No(n){if(!(lt in n))return!1;let t=n[lt];return t instanceof p?!1:se(t)||x(t)}var ut="backgroundGradient";function vo(n){if(!(ut in n))return!1;let t=n[ut];return c(t)||x(t)}var mt="rotation";function So(n){if(!(mt in n))return!1;let t=n[mt];return te(t)}var ct="opacity";function Ao(n){if(!(ct in n))return!1;let t=n[ct];return te(t)}var pt="borderRadius";function Co(n){if(!(pt in n))return!1;let t=n[pt];return c(t)||x(t)}var gt="svg";function ko(n){if(!(gt in n))return!1;let t=n[gt];return c(t)}export{q as CodeComponentNode,$t as Draggable,w as FrameNode,$ as SVGNode,J as SmartComponentNode,Y as TextNode,Q as WebPageNode,xe as framer,de as isCodeComponentNode,Ke as isFrameNode,Ye as isSVGNode,qe as isSmartComponentNode,Xe as isTextNode,$e as isWebPageNode,Ie as useMakeDraggable,fo as withAspectRatio,xo as withBackgroundColor,vo as withBackgroundGradient,Io as withBackgroundImage,No as withBackgroundImageData,Co as withBorderRadius,Po as withLocked,bo as withName,Ao as withOpacity,po as withPins,co as withPosition,So as withRotation,ko as withSVG,go as withSize,ho as withSizeConstraints,yo as withVisible};
{
"name": "framer-plugin",
"version": "0.1.1",
"version": "0.1.2",
"type": "module",

@@ -31,4 +31,4 @@ "main": "src/index.ts",

"devDependencies": {
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@types/react": "^18.2.67",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^6.16.0",

@@ -35,0 +35,0 @@ "@typescript-eslint/parser": "^6.16.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc