Git Product home page Git Product logo

figma-plugin-helpers's Introduction

Figma Plugin Helper functions

npm npm bundle size

A collection of useful helper functions to import to your Figma plugin project

Installation

npm i @figma-plugin/helpers
# or
yarn add @figma-plugin/helpers

Usage

import { isTextNode } from "@figma-plugin/helpers";

const firstTextNode = figma.currentPage.findOne(node => isTextNode(node));

Documentation

Find more information about each helper function in /docs directory.

Roadmap

  • Write a contribution guidelines
  • Source additional helper functions from the community
  • Write a docs

figma-plugin-helpers's People

Contributors

actions-user avatar alexandrtovmach avatar andreslav avatar borulday avatar dependabot[bot] avatar github-actions[bot] avatar jackiecorn avatar liammartens avatar lukefinch avatar sicking avatar thomas-lowry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

figma-plugin-helpers's Issues

Issue with rotation/radius in extractRadialOrDiamondGradientParams

I think there is something off about how rotation and radius are computed based on the transform. I've created a test file with two equivalent radial gradients. The results look like this (numbers rounded for clarity):

// both have size 300x600

// A
transform = [[ 0, -0.5, 1], [ 0.5, 0, 0.5]]
radius = [300, 600]
rotation = 90

// B
transform = [[0.5, 0, 0.5], [0, -0.5, 1]]
radius = [300, 600]
rotation = 0

Notice that A has a rotation of 90, whereas B as a rotation of 0. Since all other params are the same and they render the same, if I were to convert the radius and rotation to SVG params then A would render incorrectly.

It also may be the case that radius and rotation cannot be used in conjunction, then I will need a different solution, perhaps using the matrix directly in an SVG.

image

Test coverage

import { createFigma } from "figma-api-stub";
import { isPageNode } from '../helpers/isTypeNode';

const figma = createFigma({});

describe('isPageNode', () => {
  test('return "true" for PageNode', () => {
    const PageNode = figma.createPage();
    expect(isPageNode(PageNode)).toBe(true);
  });
  test('return "false" for non-PageNode', () => {
    const textNode = figma.createText();
    expect(isPageNode(textNode)).toBe(false);
  });
})

apply exact Hex in Figma

Given a hex color #010b1d I convert it to "Figma RBG" by using hexToFigmaRGB("#010b1d") then apply the color to a node in Figma. The end color applied to the node is #000A22 which is very similar but not exactly the same. I assume is due to the Math Figma does to convert from "Figma RGB" to "Web RGB".

Is there any way I can ensure the color applied in Figma is my source value?

Thanks.
Regards

lodash bloats bundle size

When importing functions that use lodash, the bundle size increases because it's importing every lodash function.

Changing the import syntax like so should fix these instances:
from: import { foo } from 'lodash'
to: import foo from 'lodash/foo'.

Runtime Error

image

Hi, When I add `import { extractLinearGradientParamsFromTransform } from "@figma-plugin/helpers";` to code.ts and run my plugin which is empty. This error becomes.

Helper functions documentation

What is the best...lightweight way to document what each plugin function does?

We could definitely add to the readme, but I was thinking as a starting point if everyone can make sure there is a comment line or two in each function that explains what they do so its more obvious to users.

Thoughts?

TypeError: Cannot read property 'Symbol' of undefined

Hey,
I seem to get an error every time I try to use an helper function (specifically loadUniqueFonts or getBoundingRect, didn't try others) and then run the plugin locally on Figma for Windows 10. When I remove all of the usages my plugin runs, adding a call to an helper function prevents the plugin from opening and yields this error on Figma console:

TypeError: Cannot read property 'Symbol' of undefined
    at Object../node_modules/lodash/_Symbol.js (VM1261 PLUGIN_9_SOURCE:18085)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/_baseGetTag.js (VM1261 PLUGIN_9_SOURCE:18902)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/isSymbol.js (VM1261 PLUGIN_9_SOURCE:23264)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/_isKey.js (VM1261 PLUGIN_9_SOURCE:21458)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/_castPath.js (VM1261 PLUGIN_9_SOURCE:19909)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)

I understand it may seem like a lodash error, but as I mentioned when I remove all of @figma-plugin/helpers usages, there's no error. BTW, running the same code with all the usages on Mac seems to work without having this error.

Worth adding, on version 0.14.3 the same behavior happens, with a different error that is more indicative towards the helpers package. I updated to the latest version before opening the issue to check if it was already fixed.

Let me know if I can provide more details about it. Thanks!

setCharacters helper

Idea to add helper that will handle all stuff to set characters to TextNode:

  1. load font (load and set fallback if fails)
  2. set characters

Think about ways how to keep multifont styling

Question: Why is findAll x1000 faster than Figma's one

Hi! I was reading the docs and saw that the findAll method is a "Custom implementation of the figma.findAll method, which runs x1000 times faster". I looked at the code but couldn't understand why. Do you mind explaining?

Circular dependency problem

I'm getting an error when using the clone() helper. I believe it's because of a circular dependency problem, but that's just a hunch.

When I run clone(figma.createFrame()) I now get the following error:

RangeError: Maximum call stack size exceeded
<ref *1> LayoutMixinStub {
      type: 'FRAME',
      children: [],
      parent: ChildrenMixinStub {
        type: 'PAGE',
        children: [ [Circular *1] ],
        parent: ChildrenMixinStub { type: 'DOCUMENT', children: [Array] }
      }
    } []

Could it by trying to loop through the parent, which then loops through the children and then through the parent again?

npm package?

How about to make these helpers as npm-package?

Provide license.

Am i allowed to copy the code and use it for commercial usage? Or should i only use it by the package itself?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.