From aafdc040a904c78e1218482ef5993b6e41aa70dd Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 23 Apr 2024 23:41:58 +0300 Subject: [PATCH] chore: working recent icons list --- README.md | 2 +- dist/index.html | 80 ++++++++++++++++++++++++------------------------- dist/plugin.js | 2 +- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 9ffd46a..efbf09e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ This is a preview version. Functions that do not work yet: -- Various pages (About, Recent icons) +- About page ### New features diff --git a/dist/index.html b/dist/index.html index fe2603c..adffc3d 100644 --- a/dist/index.html +++ b/dist/index.html @@ -4,7 +4,7 @@ Iconify - - diff --git a/dist/plugin.js b/dist/plugin.js index 548e7e4..eace5b8 100644 --- a/dist/plugin.js +++ b/dist/plugin.js @@ -1 +1 @@ -const b={compactWidth:!1,windowAction:"none",selectAfterImport:"auto",customizeDrop:!1,dropToFrame:!0,v3Notice:!1},m=Object.assign({},b);function ie(e){var o;m.v3Notice=!0;const t=["compactWidth","windowAction","selectAfterImport","customizeDrop","dropToFrame"];for(const n of t){const i=(o=e.options)==null?void 0:o[n];i!==void 0&&(m[n]=i)}return m}async function ce(){try{const e=await figma.clientStorage.getAsync("config");switch(e==null?void 0:e.version){case 2:ie(e);break;case 3:Object.assign(m,e);break}}catch(e){}return m}function re(){const e={version:3};let t;for(t in b){const o=m[t],n=b[t];n!==void 0&&n!==o&&(e[t]=o)}figma.clientStorage.setAsync("config",e).catch()}function se(){const e=figma;try{const t=e.editorType;switch(t){case"figma":case"figjam":return t}}catch(t){console.error(t)}try{if(typeof e.createSticky=="function")return"figjam"}catch(t){console.error(t)}return"figma"}const p={app:se(),loaded:!1,minimized:!1,config:m};function F(){const e=p.app;return e==="figjam"?"FigJam":e.slice(0,1).toUpperCase()+e.slice(1)}const O={mini:{width:200,height:104},full:{width:480,min:580,max:720},compact:{width:352,min:520,max:640},innerDiff:90,outerDiff:150};function E(){const e=p.config.compactWidth,t=O[e?"compact":"full"];let o;if(p.windowInnerHeight){const n=p.windowOuterHeight?p.windowOuterHeight-O.outerDiff:p.windowInnerHeight-O.innerDiff;o=Math.max(Math.min(n,t.max),t.min)}else o=t.max;return{width:t.width,height:o}}function y(e){figma.ui.postMessage(e)}function ae(e){switch(e.type){case"PAGE":case"COMPONENT":case"FRAME":case"SECTION":case"GROUP":return e}}function le(e){switch(e.type){case"FRAME":case"COMPONENT":return e}}function fe(e){function t(){if(e.getSharedPluginData("iconify","source")==="iconify"){const n=JSON.parse(e.getSharedPluginData("iconify","props")),c=n.name.split(":");if(c.length===2)switch(n.version){case 3:return n;default:{const r=n.props;let s;return typeof n.color=="string"?s=n.color:typeof r=="object"&&(s=r.color),{version:3,name:n.name,color:s,route:{type:"icon-set",prefix:c[0],parent:{type:"icon-sets"}}}}}}}try{return t()}catch(o){}}function B(e){return{nodes:e.nodes||Object.create(null),ignoreIconNode:e.ignoreIconNode||!1,iconNodeID:e.iconNodeID||null,iconNodeData:e.iconNodeData||null}}function A(e,t,o){function n(i,c,r){const s=i.id,l=t.nodes[s];if(l)return r&&l.children.push(r),l;let a="invalid",h=!1,u,g;const f=le(i);f&&(u=fe(f),u&&(g=f.height,t.iconNodeID?t.ignoreIconNode=!0:(t.iconNodeID=s,t.iconNodeData=u)));const d=ae(i);d?d.type==="PAGE"?(a="valid",h=!0):(d.locked||(a="valid"),(!c||d.locked)&&(t.ignoreIconNode=!0),h=d.type!=="FRAME"):i.type==="COMPONENT_SET"?a="ignored":t.ignoreIconNode=!0;const N={type:i.type,id:s,name:i.name,target:a,children:r?[r]:[],primary:c,relative:h,icon:u,height:g};return t.nodes[s]=N,i.parent&&i.type!=="PAGE"&&n(i.parent,c,i.id),N}return n(e,o)}const ge=16;function $(){const e=figma.currentPage,t=e.selection,o=B({}),n=A(e,o,!1);t.forEach((d,N)=>{A(d,o,!N)});const{nodes:i,iconNodeData:c,iconNodeID:r,ignoreIconNode:s}=o,l=[];let a=n.id,h;function u(d,N=0){switch(d.target){case"ignored":{d.children.forEach(I=>{u(i[I],N)});break}case"valid":switch(d.type){case"PAGE":case"COMPONENT":case"FRAME":case"SECTION":case"GROUP":const I={id:d.id,name:d.name,depth:N,type:d.type};!s&&c&&r===d.id&&(I.icon=c,I.height=d.height,h=I),d.icon||(l.push(I),d.primary&&!d.icon&&(a=d.id),d.children.forEach(oe=>{u(i[oe],N+1)}))}}}u(n);let g=!1,f=ge;for(;l.length>f;)l.pop()===h&&(g=!0,f--);return g&&h&&l.push(h),{nodes:l,defaultNode:a,iconNode:h}}let J=$();function L(){return J}function ue(e){J=e}const T="style:";function _(e){function t(o){const n=Math.round(o*255).toString(16);return n.length<2?"0"+n:n}return"#"+t(e.r)+t(e.g)+t(e.b)}function R(e){const t=e.paints[0].color;return{id:e.id,name:e.name,color:_(t),remote:e.remote}}function H(e){return e.type==="SOLID"&&e.visible!==!1&&e.blendMode==="NORMAL"&&e.opacity===1?e:void 0}function k(e){if(e.paints.length===1)return H(e.paints[0])}function Y(e){const t=figma.getStyleById(e);if((t==null?void 0:t.type)==="PAINT"&&k(t))return t.id}const v=new Set;async function de(){const e=[];return(await figma.getLocalPaintStylesAsync()).forEach(t=>{try{v.add(t.id),k(t)&&e.push(R(t))}catch(o){console.log("Error parsing color style:",o)}}),e}function X(){const e=figma.getSelectionColors(),t=[];return e==null||e.styles.forEach(o=>{const n=o.id;v.has(n)||(v.add(n),k(o)&&t.push(R(o)))}),t.length?t:void 0}function he(e){async function t(o){const n=[];for(const i of o)if(i.startsWith(T)){const c=i.slice(T.length);if(!v.has(c)){v.add(c);const r=await figma.getStyleByIdAsync(c);(r==null?void 0:r.type)==="PAINT"&&k(r)&&n.push(R(r))}}n.length&&y({type:"plugin:color-styles",styles:n})}e&&setTimeout(()=>{t(e).catch(console.error)})}let x=!1;function pe(){const e=$();if(JSON.stringify(e)!==JSON.stringify(L())){ue(e);const t=X();y({type:"plugin:nodes",nodes:e,styles:t})}}function D(){x||(x=!0,setTimeout(()=>{x=!1,pe()},250))}async function S(e,t=void 0,o){try{const n=await figma.clientStorage.getAsync(e);if(n)return o?o(n):n}catch(n){}return t}function P(e,t){figma.clientStorage.setAsync(e,t).catch()}const q="recent";let w=[];const me=64;async function ye(){const e=await S(q);return e&&(w=e),e}let C=!1;function Ne(){C||(C=!0,setTimeout(()=>{C=!1,P(q,w),y({type:"plugin:recent-icons",icons:w})},1e3))}function Q(e){for(const t of e){const o=w.indexOf(t);o!==-1&&w.splice(o,1),w.unshift(t),w.length>me&&w.pop(),Ne()}}async function Z(e,t){function o(c){try{if(c.length===1){const r=c[0];if(H(c[0]))return!0}}catch(r){}}async function n(c){o(c.fills)&&(typeof t=="string"?await c.setFillStyleIdAsync(t):c.fills=[t]),o(c.strokes)&&(typeof t=="string"?await c.setStrokeStyleIdAsync(t):c.strokes=[t])}async function i(c){const r=c;if(r.locked||r.isMask)return;try{await n(r)}catch(l){}const s=c.children;if(s)for(const l of s)await i(l)}for(const c of e.children)await i(c)}const we={replace:"Replace icon",code:"Icon code"};function ee(e,t,o,n){e.name=t,e.setSharedPluginData("iconify","source","iconify");const i={version:3,name:t,props:o,route:n};e.setSharedPluginData("iconify","props",JSON.stringify(i)),e.setRelaunchData(we)}function te(e,t){const o=figma.createNodeFromSvg(e);let n;if(t.replace?n=t.replace:t.component&&(n=figma.createComponent()),n){for(;n.children.length>0;)n.children[0].remove();n.resizeWithoutConstraints(o.width,o.height);for(const c of o.children)n.appendChild(c);if(o.remove(),t.replace)return n}const i=n||o;if(t.parent){const c=t.parent;let r=!0;const s=c.layoutMode;s&&s!=="NONE"&&(r=!1),r?c.appendChild(i):c.insertChild(0,i),t.x&&(i.x=t.x),t.y&&(i.y=t.y)}return i.constrainProportions=!0,i}function W(e,t,o,n){if(e.type==="PAGE")return t;let i=0,c=n?e.width:e.height;if(e.type==="GROUP"&&(i=n?e.x:e.y),tr?Math.max(i,r):t}function ne(e,t,o){const n=t.icons.reduce((s,l)=>s+Math.ceil(l.width),0);let i=W(e,Math.round(o.targetX-n/2),n,!0),c;t.props.style&&(c=Y(t.props.style));const r=[];for(const s of t.icons){const l=W(e,Math.round(o.targetY-s.height/2),s.height,!1),a=te(s.content,{parent:e,x:i,y:l,component:o.component});ee(a,s.name,t.props,t.route),i+=Math.ceil(s.width),r.push(a),s.monotone&&c&&Z(a,c).catch(console.error)}return Q(Object.keys(t.icons)),y({type:"plugin:notice",color:"success",text:`Imported ${t.icons.length>1?t.icons.length+" icons":t.icons[0].name} to ${F()}`}),figma.currentPage.selection=r,D(),r}function z(){y({type:"plugin:notice",color:"error",text:"Error dropping icon(s) to "+F()})}function Ie(e){let t=e.x,o=e.y;const n=e.node;n.type==="GROUP"&&(t+=n.x,o+=n.y);const i=B({});A(n,i,!0);const c=i.nodes[figma.currentPage.id];if(!c){console.error("Cannot find current page item in scanned nodes list"),z();return}let r=0,s=0,l=!0,a=c,h=c;for(;a.children.length;){const g=a.children[0];if(a=i.nodes[g],a.icon||a.target==="invalid"?l=!1:l&&a.target==="valid"&&(h=a),!l&&a.relative){const f=figma.getNodeById(a.id);f&&(r+=f.x||0,s+=f.y||0)}}const u=figma.getNodeById(h.id);if(!u){console.error("Failed to get target node"),z();return}ne(u,e.dropMetadata,{targetX:r+t,targetY:s+o})}function M(){y({type:"plugin:notice",color:"error",text:"Error importing icon(s) to "+F()})}function Se(e,t){const o=figma.getNodeById(e);if(!o){M();return}const n=o.name;let i,c;const r=figma.currentPage.selection;if(r.length===1&&r[0].id===o.id){const s=figma.getSelectionColors();if(s){const l=s.paints,a=s.styles;l.length+a.length===1?(a.length&&k(a[0])&&(i=a[0].id,c=T+i),l.length&&(i=H(l[0]),i&&(c=_(i.color)))):t.props.style&&(i=Y(t.props.style))}}for(const s of t.icons){const l=s.name,a=te(s.content,{replace:o,x:o.x,y:o.y});ee(a,l,t.props,t.route),Q([l]),y({type:"plugin:notice",color:"success",text:`Replaced ${n} with ${l}`}),figma.currentPage.selection=[a],D(),s.monotone&&i&&Z(a,i).catch(console.error),s.monotone&&c&&y({type:"plugin:recent-color",color:c});return}M()}function Pe(e,t,o){const n=figma.getNodeById(e);if(!n){M();return}let i,c;switch(n.type){case"PAGE":{const r=figma.viewport.center;i=r.x,c=r.y;break}case"GROUP":{i=n.x+n.width/2,c=n.y+n.height/2;break}default:{i=n.width/2,c=n.height/2;break}}ne(n,t,{component:o,targetX:i,targetY:c})}const G="icon-sets",U="route-v3",j="icon-sets-filters",K="recent-colors",V="customisations";(async()=>{var h;console.log("Starting plugin..."),await ce();const e=await S(G,void 0,u=>u.version===3?u.data:void 0);let t=await S(U);const o=await ye(),n=await S(j),i=await S(K),c=await S(V),r=L(),s=X();let l;if(figma.command==="replace"){const u=(h=r.iconNode)==null?void 0:h.icon;u!=null&&u.route&&(t=u.route,l=u.name)}figma.on("selectionchange",D),figma.on("currentpagechange",D),figma.on("drop",Ie),figma.ui.onmessage=u=>{try{if(typeof u.type!="string")return}catch(f){console.error(f)}const g=u;switch(g.type){case"ui:fatal-error":{figma.closePlugin(g.error);break}case"ui:loaded":{if(g.innerHeight||g.outerHeight){p.windowInnerHeight=g.innerHeight,p.windowOuterHeight=g.outerHeight;const f=E();f.height!==p.lastWindowHeight&&(p.lastWindowHeight=f.height,figma.ui.resize(f.width,f.height))}y({type:"plugin:starting",app:p.app,command:figma.command,config:m,nodes:r,styles:s,lists:e,recent:o,route:t,filters:n,selectIcon:l,recentColors:i,custom:c}),de().then(f=>{f.length&&y({type:"plugin:color-styles",styles:f})}).catch(console.error),he(i);break}case"ui:close":{figma.closePlugin();break}case"ui:compact":{m.compactWidth=!m.compactWidth;const f=E();f.height!==p.lastWindowHeight&&(p.lastWindowHeight=f.height,figma.ui.resize(f.width,f.height)),y({type:"plugin:resize",compactWidth:m.compactWidth,minimized:!1}),re();break}case"ui:lists":{const f={version:3,data:g.lists};P(G,f);break}case"ui:route":{P(U,g.route);break}case"ui:filters":{P(j,g.filters);break}case"ui:replace-icon":{Se(g.node,g.data);break}case"ui:import-icons":{Pe(g.node,g.data,g.component||!1);break}case"ui:recent-colors":{P(K,g.colors);break}case"ui:customisations":{P(V,g.custom);break}}};const a=E();p.lastWindowHeight=a.height,figma.showUI(__html__,Object.assign({themeColors:!1},a))})(); +const b={compactWidth:!1,v3Notice:!1},m=Object.assign({},b);function ce(e){var o;m.v3Notice=!0;const t=["compactWidth","windowAction","selectAfterImport","customizeDrop","dropToFrame"];for(const n of t){const i=(o=e.options)==null?void 0:o[n];i!==void 0&&(m[n]=i)}return m}async function re(){try{const e=await figma.clientStorage.getAsync("config");switch(e==null?void 0:e.version){case 2:ce(e);break;case 3:Object.assign(m,e);break}}catch(e){}return m}function se(){const e={version:3};let t;for(t in b){const o=m[t],n=b[t];n!==void 0&&n!==o&&(e[t]=o)}figma.clientStorage.setAsync("config",e).catch()}function ae(){const e=figma;try{const t=e.editorType;switch(t){case"figma":case"figjam":return t}}catch(t){console.error(t)}try{if(typeof e.createSticky=="function")return"figjam"}catch(t){console.error(t)}return"figma"}const p={app:ae(),loaded:!1,minimized:!1,config:m};function R(){const e=p.app;return e==="figjam"?"FigJam":e.slice(0,1).toUpperCase()+e.slice(1)}const E={mini:{width:200,height:104},full:{width:480,min:580,max:720},compact:{width:352,min:520,max:640},innerDiff:90,outerDiff:150};function O(){const e=p.config.compactWidth,t=E[e?"compact":"full"];let o;if(p.windowInnerHeight){const n=p.windowOuterHeight?p.windowOuterHeight-E.outerDiff:p.windowInnerHeight-E.innerDiff;o=Math.max(Math.min(n,t.max),t.min)}else o=t.max;return{width:t.width,height:o}}function y(e){figma.ui.postMessage(e)}function le(e){switch(e.type){case"PAGE":case"COMPONENT":case"FRAME":case"SECTION":case"GROUP":return e}}function fe(e){switch(e.type){case"FRAME":case"COMPONENT":return e}}function ge(e){function t(){if(e.getSharedPluginData("iconify","source")==="iconify"){const n=JSON.parse(e.getSharedPluginData("iconify","props")),c=n.name.split(":");if(c.length===2)switch(n.version){case 3:return n;default:{const r=n.props;let s;return typeof n.color=="string"?s=n.color:typeof r=="object"&&(s=r.color),{version:3,name:n.name,color:s,route:{type:"icon-set",prefix:c[0],parent:{type:"icon-sets"}}}}}}}try{return t()}catch(o){}}function B(e){return{nodes:e.nodes||Object.create(null),ignoreIconNode:e.ignoreIconNode||!1,iconNodeID:e.iconNodeID||null,iconNodeData:e.iconNodeData||null}}function T(e,t,o){function n(i,c,r){const s=i.id,l=t.nodes[s];if(l)return r&&l.children.push(r),l;let a="invalid",h=!1,u,g;const f=fe(i);f&&(u=ge(f),u&&(g=f.height,t.iconNodeID?t.ignoreIconNode=!0:(t.iconNodeID=s,t.iconNodeData=u)));const d=le(i);d?d.type==="PAGE"?(a="valid",h=!0):(d.locked||(a="valid"),(!c||d.locked)&&(t.ignoreIconNode=!0),h=d.type!=="FRAME"):i.type==="COMPONENT_SET"?a="ignored":t.ignoreIconNode=!0;const w={type:i.type,id:s,name:i.name,target:a,children:r?[r]:[],primary:c,relative:h,icon:u,height:g};return t.nodes[s]=w,i.parent&&i.type!=="PAGE"&&n(i.parent,c,i.id),w}return n(e,o)}const ue=16;function $(){const e=figma.currentPage,t=e.selection,o=B({}),n=T(e,o,!1);t.forEach((d,w)=>{T(d,o,!w)});const{nodes:i,iconNodeData:c,iconNodeID:r,ignoreIconNode:s}=o,l=[];let a=n.id,h;function u(d,w=0){switch(d.target){case"ignored":{d.children.forEach(I=>{u(i[I],w)});break}case"valid":switch(d.type){case"PAGE":case"COMPONENT":case"FRAME":case"SECTION":case"GROUP":const I={id:d.id,name:d.name,depth:w,type:d.type};!s&&c&&r===d.id&&(I.icon=c,I.height=d.height,h=I),d.icon||(l.push(I),d.primary&&!d.icon&&(a=d.id),d.children.forEach(ie=>{u(i[ie],w+1)}))}}}u(n);let g=!1,f=ue;for(;l.length>f;)l.pop()===h&&(g=!0,f--);return g&&h&&l.push(h),{nodes:l,defaultNode:a,iconNode:h}}let J=$();function L(){return J}function de(e){J=e}const A="style:";function _(e){function t(o){const n=Math.round(o*255).toString(16);return n.length<2?"0"+n:n}return"#"+t(e.r)+t(e.g)+t(e.b)}function F(e){const t=e.paints[0].color;return{id:e.id,name:e.name,color:_(t),remote:e.remote}}function H(e){return e.type==="SOLID"&&e.visible!==!1&&e.blendMode==="NORMAL"&&e.opacity===1?e:void 0}function k(e){if(e.paints.length===1)return H(e.paints[0])}function Y(e){const t=figma.getStyleById(e);if((t==null?void 0:t.type)==="PAINT"&&k(t))return t.id}const v=new Set;async function he(){const e=[];return(await figma.getLocalPaintStylesAsync()).forEach(t=>{try{v.add(t.id),k(t)&&e.push(F(t))}catch(o){console.log("Error parsing color style:",o)}}),e}function X(){const e=figma.getSelectionColors(),t=[];return e==null||e.styles.forEach(o=>{const n=o.id;v.has(n)||(v.add(n),k(o)&&t.push(F(o)))}),t.length?t:void 0}function pe(e){async function t(o){const n=[];for(const i of o)if(i.startsWith(A)){const c=i.slice(A.length);if(!v.has(c)){v.add(c);const r=await figma.getStyleByIdAsync(c);(r==null?void 0:r.type)==="PAINT"&&k(r)&&n.push(F(r))}}n.length&&y({type:"plugin:color-styles",styles:n})}e&&setTimeout(()=>{t(e).catch(console.error)})}let x=!1;function me(){const e=$();if(JSON.stringify(e)!==JSON.stringify(L())){de(e);const t=X();y({type:"plugin:nodes",nodes:e,styles:t})}}function D(){x||(x=!0,setTimeout(()=>{x=!1,me()},250))}async function S(e,t=void 0,o){try{const n=await figma.clientStorage.getAsync(e);if(n)return o?o(n):n}catch(n){}return t}function P(e,t){figma.clientStorage.setAsync(e,t).catch()}const q="recent";let N=[];const ye=64;async function Ne(){const e=await S(q);return e&&(N=e),e}let C=!1;function Q(){C||(C=!0,setTimeout(()=>{C=!1,P(q,N),y({type:"plugin:recent-icons",icons:N})},1e3))}function Z(e){for(const t of e){const o=N.indexOf(t);o!==-1&&N.splice(o,1),N.unshift(t),N.length>ye&&N.pop(),Q()}}function we(){N=[],Q()}async function ee(e,t){function o(c){try{if(c.length===1){const r=c[0];if(H(c[0]))return!0}}catch(r){}}async function n(c){o(c.fills)&&(typeof t=="string"?await c.setFillStyleIdAsync(t):c.fills=[t]),o(c.strokes)&&(typeof t=="string"?await c.setStrokeStyleIdAsync(t):c.strokes=[t])}async function i(c){const r=c;if(r.locked||r.isMask)return;try{await n(r)}catch(l){}const s=c.children;if(s)for(const l of s)await i(l)}for(const c of e.children)await i(c)}const Ie={replace:"Replace icon",code:"Icon code"};function te(e,t,o,n){e.name=t,e.setSharedPluginData("iconify","source","iconify");const i={version:3,name:t,props:o,route:n};e.setSharedPluginData("iconify","props",JSON.stringify(i)),e.setRelaunchData(Ie)}function ne(e,t){const o=figma.createNodeFromSvg(e);let n;if(t.replace?n=t.replace:t.component&&(n=figma.createComponent()),n){for(;n.children.length>0;)n.children[0].remove();n.resizeWithoutConstraints(o.width,o.height);for(const c of o.children)n.appendChild(c);if(o.remove(),t.replace)return n}const i=n||o;if(t.parent){const c=t.parent;let r=!0;const s=c.layoutMode;s&&s!=="NONE"&&(r=!1),r?c.appendChild(i):c.insertChild(0,i),t.x&&(i.x=t.x),t.y&&(i.y=t.y)}return i.constrainProportions=!0,i}function W(e,t,o,n){if(e.type==="PAGE")return t;let i=0,c=n?e.width:e.height;if(e.type==="GROUP"&&(i=n?e.x:e.y),tr?Math.max(i,r):t}function oe(e,t,o){const n=t.icons.reduce((s,l)=>s+Math.ceil(l.width),0);let i=W(e,Math.round(o.targetX-n/2),n,!0),c;t.props.style&&(c=Y(t.props.style));const r=[];for(const s of t.icons){const l=W(e,Math.round(o.targetY-s.height/2),s.height,!1),a=ne(s.content,{parent:e,x:i,y:l,component:o.component});te(a,s.name,t.props,t.route),i+=Math.ceil(s.width),r.push(a),s.monotone&&c&&ee(a,c).catch(console.error)}return Z(t.icons.map(s=>s.name)),y({type:"plugin:notice",color:"success",text:`Imported ${t.icons.length>1?t.icons.length+" icons":t.icons[0].name} to ${R()}`}),figma.currentPage.selection=r,D(),r}function G(){y({type:"plugin:notice",color:"error",text:"Error dropping icon(s) to "+R()})}function Se(e){let t=e.x,o=e.y;const n=e.node;n.type==="GROUP"&&(t+=n.x,o+=n.y);const i=B({});T(n,i,!0);const c=i.nodes[figma.currentPage.id];if(!c){console.error("Cannot find current page item in scanned nodes list"),G();return}let r=0,s=0,l=!0,a=c,h=c;for(;a.children.length;){const g=a.children[0];if(a=i.nodes[g],a.icon||a.target==="invalid"?l=!1:l&&a.target==="valid"&&(h=a),!l&&a.relative){const f=figma.getNodeById(a.id);f&&(r+=f.x||0,s+=f.y||0)}}const u=figma.getNodeById(h.id);if(!u){console.error("Failed to get target node"),G();return}oe(u,e.dropMetadata,{targetX:r+t,targetY:s+o})}function M(){y({type:"plugin:notice",color:"error",text:"Error importing icon(s) to "+R()})}function Pe(e,t){const o=figma.getNodeById(e);if(!o){M();return}const n=o.name;let i,c;const r=figma.currentPage.selection;if(r.length===1&&r[0].id===o.id){const s=figma.getSelectionColors();if(s){const l=s.paints,a=s.styles;l.length+a.length===1?(a.length&&k(a[0])&&(i=a[0].id,c=A+i),l.length&&(i=H(l[0]),i&&(c=_(i.color)))):t.props.style&&(i=Y(t.props.style))}}for(const s of t.icons){const l=s.name,a=ne(s.content,{replace:o,x:o.x,y:o.y});te(a,l,t.props,t.route),Z([l]),y({type:"plugin:notice",color:"success",text:`Replaced ${n} with ${l}`}),figma.currentPage.selection=[a],D(),s.monotone&&i&&ee(a,i).catch(console.error),s.monotone&&c&&y({type:"plugin:recent-color",color:c});return}M()}function ve(e,t,o){const n=figma.getNodeById(e);if(!n){M();return}let i,c;switch(n.type){case"PAGE":{const r=figma.viewport.center;i=r.x,c=r.y;break}case"GROUP":{i=n.x+n.width/2,c=n.y+n.height/2;break}default:{i=n.width/2,c=n.height/2;break}}oe(n,t,{component:o,targetX:i,targetY:c})}const z="icon-sets",U="route-v3",j="icon-sets-filters",K="recent-colors",V="customisations";(async()=>{var h;console.log("Starting plugin..."),await re();const e=await S(z,void 0,u=>u.version===3?u.data:void 0);let t=await S(U);const o=await Ne(),n=await S(j),i=await S(K),c=await S(V),r=L(),s=X();let l;if(figma.command==="replace"){const u=(h=r.iconNode)==null?void 0:h.icon;u!=null&&u.route&&(t=u.route,l=u.name)}figma.on("selectionchange",D),figma.on("currentpagechange",D),figma.on("drop",Se),figma.ui.onmessage=u=>{try{if(typeof u.type!="string")return}catch(f){console.error(f)}const g=u;switch(g.type){case"ui:fatal-error":{figma.closePlugin(g.error);break}case"ui:loaded":{if(g.innerHeight||g.outerHeight){p.windowInnerHeight=g.innerHeight,p.windowOuterHeight=g.outerHeight;const f=O();f.height!==p.lastWindowHeight&&(p.lastWindowHeight=f.height,figma.ui.resize(f.width,f.height))}y({type:"plugin:starting",app:p.app,command:figma.command,config:m,nodes:r,styles:s,lists:e,recent:o,route:t,filters:n,selectIcon:l,recentColors:i,custom:c}),he().then(f=>{f.length&&y({type:"plugin:color-styles",styles:f})}).catch(console.error),pe(i);break}case"ui:close":{figma.closePlugin();break}case"ui:compact":{m.compactWidth=!m.compactWidth;const f=O();f.height!==p.lastWindowHeight&&(p.lastWindowHeight=f.height,figma.ui.resize(f.width,f.height)),y({type:"plugin:resize",compactWidth:m.compactWidth,minimized:!1}),se();break}case"ui:lists":{const f={version:3,data:g.lists};P(z,f);break}case"ui:route":{P(U,g.route);break}case"ui:filters":{P(j,g.filters);break}case"ui:replace-icon":{Pe(g.node,g.data);break}case"ui:import-icons":{ve(g.node,g.data,g.component||!1);break}case"ui:recent-colors":{P(K,g.colors);break}case"ui:customisations":{P(V,g.custom);break}case"ui:reset-recent-icons":{we();break}}};const a=O();p.lastWindowHeight=a.height,figma.showUI(__html__,Object.assign({themeColors:!1},a))})();