-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e41e06
commit 0e25f0d
Showing
8 changed files
with
448 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"ignorePatterns": ["node_modules", "out", "outdir", "dist", "storybook-static"], | ||
"extends": ["xo", "plugin:prettier/recommended", "plugin:import/errors", "plugin:import/warnings"], | ||
"plugins": ["import", "unicorn"], | ||
"overrides": [ | ||
{ | ||
"files": ["**/*.ts"], | ||
"extends": ["plugin:@typescript-eslint/recommended","plugin:import/typescript"], | ||
"parser": "@typescript-eslint/parser", | ||
"rules": { | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/consistent-type-imports": "error" | ||
} | ||
} | ||
], | ||
"rules": { | ||
"max-params": ["off"], | ||
"complexity": ["off"], | ||
"react/jsx-boolean-value": ["error", "always"], | ||
"prefer-destructuring": [ | ||
"error", | ||
{ | ||
"object": true | ||
} | ||
], | ||
"guard-for-in": ["off"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,65 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
const __awaiter = | ||
(this && this.__awaiter) || | ||
function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P | ||
? value | ||
: new P(function (resolve) { | ||
resolve(value) | ||
}) | ||
} | ||
|
||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
} | ||
|
||
function rejected(value) { | ||
try { | ||
step(generator.throw(value)) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
} | ||
|
||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected) | ||
} | ||
|
||
step((generator = generator.apply(thisArg, _arguments || [])).next()) | ||
}) | ||
} | ||
|
||
function traverse(node) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if ("children" in node) { | ||
if (node.type !== "INSTANCE") { | ||
for (const child of node.children) { | ||
traverse(child); | ||
} | ||
} | ||
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 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); | ||
textNode.insertCharacters(0, textToDisplay); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if ('children' in node) { | ||
if (node.type !== 'INSTANCE') { | ||
for (const child of node.children) { | ||
traverse(child) | ||
} | ||
}); | ||
} 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 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`) | ||
const len = textNode.characters.length | ||
yield figma.loadFontAsync(textNode.getRangeFontName(0, 1)) | ||
textNode.deleteCharacters(0, len) | ||
textNode.insertCharacters(0, textToDisplay) | ||
} | ||
} | ||
}) | ||
} | ||
traverse(figma.root); | ||
figma.closePlugin(); | ||
|
||
traverse(figma.root) | ||
figma.closePlugin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,65 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
const __awaiter = | ||
(this && this.__awaiter) || | ||
function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P | ||
? value | ||
: new P(function (resolve) { | ||
resolve(value) | ||
}) | ||
} | ||
|
||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
} | ||
|
||
function rejected(value) { | ||
try { | ||
step(generator.throw(value)) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
} | ||
|
||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected) | ||
} | ||
|
||
step((generator = generator.apply(thisArg, _arguments || [])).next()) | ||
}) | ||
} | ||
|
||
function traverse(node) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if ("children" in node) { | ||
if (node.type !== "INSTANCE") { | ||
for (const child of node.children) { | ||
traverse(child); | ||
} | ||
} | ||
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 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); | ||
textNode.insertCharacters(0, textToDisplay); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if ('children' in node) { | ||
if (node.type !== 'INSTANCE') { | ||
for (const child of node.children) { | ||
traverse(child) | ||
} | ||
}); | ||
} 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 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`) | ||
const len = textNode.characters.length | ||
yield figma.loadFontAsync(textNode.getRangeFontName(0, 1)) | ||
textNode.deleteCharacters(0, len) | ||
textNode.insertCharacters(0, textToDisplay) | ||
} | ||
} | ||
}) | ||
} | ||
traverse(figma.root); | ||
figma.closePlugin(); | ||
|
||
traverse(figma.root) | ||
figma.closePlugin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
const ColorLuminance = (hex: string, lums: Array<number>) => { | ||
if (/[^0-9a-f]/gi.test(hex)) { | ||
throw new Error ('Invalid color') | ||
if (/[^0-9a-f]/gi.test(hex)) { | ||
throw new Error('Invalid color') | ||
} | ||
|
||
const colors = [] | ||
|
||
if (hex.length < 6) { | ||
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]; | ||
} | ||
if (hex.length < 6) { | ||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] | ||
} | ||
|
||
for (const lum of lums) { | ||
let color = "#" | ||
let color = '#' | ||
|
||
for (let i = 0; i < 3; i++) { | ||
let cNumber = parseInt(hex.substr(i*2,2), 16); | ||
const colorParh = Math.round(Math.min(Math.max(0, cNumber + (cNumber * lum)), 255)).toString(16); | ||
color += ('00'+colorParh).substr(colorParh.length); | ||
const cNumber = parseInt(hex.substr(i * 2, 2), 16) | ||
const colorParh = Math.round(Math.min(Math.max(0, cNumber + cNumber * lum), 255)).toString(16) | ||
color += ('00' + colorParh).substr(colorParh.length) | ||
} | ||
|
||
colors.push(color) | ||
} | ||
|
||
return colors; | ||
return colors | ||
} | ||
|
||
// console.log(ColorLuminance("6699C", [0, 1, 2])) | ||
|
||
// Console.log(ColorLuminance("6699C", [0, 1, 2])) | ||
|
||
figma.closePlugin() |
Oops, something went wrong.