Skip to content

Commit

Permalink
Merge pull request #1 from tonik/feat/find-by-name
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-krakowski authored Jun 1, 2021
2 parents acd82cd + e7ed02f commit 2146782
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 25 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions p1/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ function traverse(node) {
for (const child of node.children) {
traverse(child);
}
// TODO: Customizable node name
}
else if (node.name === '_Specification') {
const spaceComp = node.children.find(element => element.name === 'Line' || element.name === 'Space');
const spaceComp = node.children.find(element => /^(size|space)\/(width|height)/.test(element.name));
const textNode = node.children.find(element => element.type === "TEXT");
const textToDisplay = String(`${Math.max(spaceComp.width, spaceComp.height)}px`);
const valueToDisplay = /^(size|space)\/(width)/.test(spaceComp.name) ? spaceComp === null || spaceComp === void 0 ? void 0 : spaceComp.width : spaceComp === null || spaceComp === void 0 ? void 0 : spaceComp.height;
const textToDisplay = String(`${valueToDisplay}px`);
let len = textNode.characters.length;
yield figma.loadFontAsync(textNode.getRangeFontName(0, 1));
textNode.deleteCharacters(0, len);
Expand Down
9 changes: 4 additions & 5 deletions p1/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ async function traverse(node) {
for (const child of node.children) {
traverse(child)
}
// TODO: Customizable node name
} else if (node.name === '_Specification'){
const spaceComp = node.children.find(element => element.name === 'Line' || element.name === 'Space')
} else if (node.name === '_Specification') {
const spaceComp = node.children.find(element => /^(size|space)\/(width|height)/.test(element.name))
const textNode = node.children.find(element => element.type === "TEXT")
const textToDisplay = String(`${Math.max(spaceComp.width, spaceComp.height)}px`)
const valueToDisplay = /^(size|space)\/(width)/.test(spaceComp.name) ? spaceComp?.width : spaceComp?.height
const textToDisplay = String(`${valueToDisplay}px`)

let len = textNode.characters.length
await figma.loadFontAsync(textNode.getRangeFontName(0, 1))

textNode.deleteCharacters(0, len)
textNode.insertCharacters(0, textToDisplay)

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions p1/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Tonik-P1",
"id": "980857664278952801",
"name": "p1",
"id": "981247913119685663",
"api": "1.0.0",
"main": "code.js"
}
14 changes: 0 additions & 14 deletions p1/package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion p1/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Tonik-P1",
"name": "p1",
"version": "1.0.0",
"description": "Your Figma plugin",
"main": "code.js",
Expand Down
8 changes: 8 additions & 0 deletions p1/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@figma/plugin-typings@^1.23.0":
version "1.23.0"
resolved "https://registry.yarnpkg.com/@figma/plugin-typings/-/plugin-typings-1.23.0.tgz#e82774264d2f72604856562cd7b021bd32e60852"
integrity sha512-hKSQSyE4Lwb9GI0sL92YX8QvBAwsCkKGSIxLkEn3CDLSTtOjtTs/GKsQ8zUAFtcrr0KQLEYW0rBkGU3UVpPq/Q==

0 comments on commit 2146782

Please sign in to comment.