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

figma-api-stub

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

figma-api-stub - npm Package Compare versions

Comparing version 0.0.50 to 0.0.51

dist/componentStubs.d.ts

4

dist/fonts.d.ts
/// <reference types="plugin-typings" />
export declare const Roboto: Font[];
export declare const Helvetica: Font[];
export declare class Fonts {
static loadedFonts: Array<FontName>;
static isFontLoaded(fontName: any): FontName;
}

@@ -115,2 +115,12 @@ "use strict";

];
var Fonts = /** @class */ (function () {
function Fonts() {
}
Fonts.isFontLoaded = function (fontName) {
return this.loadedFonts.find(function (font) { return font.family === fontName.family && font.style === fontName.style; });
};
Fonts.loadedFonts = [];
return Fonts;
}());
exports.Fonts = Fonts;
//# sourceMappingURL=fonts.js.map

8

dist/stubs.d.ts
/// <reference types="plugin-typings" />
declare type TConfig = {
simulateErrors?: boolean;
isWithoutTimeout?: boolean;
};
export declare const createFigma: (config: TConfig) => PluginAPI;
import { TConfig } from "./config";
export declare const createFigma: (paramConfig: TConfig) => PluginAPI;
export declare const createParentPostMessage: (figma: PluginAPI, isWithoutTimeout?: boolean) => (message: {
pluginMessage: any;
}, target: string) => void;
export {};
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {

@@ -26,61 +13,84 @@ __assign = Object.assign || function(t) {

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var cloneDeep = require("clone-deep");
var nanoid_1 = require("nanoid");
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var styleStubs_1 = require("./styleStubs");
var applyMixins_1 = require("./applyMixins");
var componentStubs_1 = require("./componentStubs");
var config_1 = require("./config");
var fonts_1 = require("./fonts");
var nanoid_1 = require("nanoid");
var defaultConfig = {
simulateErrors: false,
isWithoutTimeout: false
};
var isInsideInstance = function (node) {
if (!node.parent) {
return;
}
return node.parent.type === "INSTANCE" || isInsideInstance(node.parent);
};
exports.createFigma = function (config) {
var joinedConfig = __assign({}, defaultConfig, config);
var loadedFonts = [];
var isFontLoaded = function (fontName) {
return loadedFonts.find(function (font) { return font.family === fontName.family && font.style === fontName.style; });
};
var selectionChangeSubject = new rxjs_1.Subject();
var mixins_1 = require("./mixins");
exports.createFigma = function (paramConfig) {
var config = __assign({}, config_1.defaultConfig, paramConfig);
var BaseNodeMixinStub = mixins_1.getBaseNodeMixinStub(config);
var LayoutMixinStub = mixins_1.getLayoutMixinStub(config);
var ChildrenMixinStub = mixins_1.getChildrenMixinStub(config);
applyMixins_1.applyMixins(componentStubs_1.RectangleNodeStub, [
BaseNodeMixinStub,
LayoutMixinStub,
mixins_1.ExportMixinStub,
mixins_1.GeometryMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.TextNodeStub, [
BaseNodeMixinStub,
LayoutMixinStub,
mixins_1.ExportMixinStub,
mixins_1.GeometryMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.ShapeWithTextNodeStub, [
BaseNodeMixinStub,
LayoutMixinStub,
mixins_1.ExportMixinStub,
mixins_1.GeometryMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.StickyNodeStub, [
BaseNodeMixinStub,
LayoutMixinStub,
mixins_1.ExportMixinStub,
mixins_1.GeometryMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.ConnectorNodeStub, [
BaseNodeMixinStub,
LayoutMixinStub,
mixins_1.ExportMixinStub,
mixins_1.GeometryMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.DocumentNodeStub, [BaseNodeMixinStub, ChildrenMixinStub]);
applyMixins_1.applyMixins(componentStubs_1.PageNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
mixins_1.ExportMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.FrameNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
LayoutMixinStub,
mixins_1.ExportMixinStub,
mixins_1.GeometryMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.GroupNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
mixins_1.ExportMixinStub,
LayoutMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.BooleanOperationNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
mixins_1.ExportMixinStub,
LayoutMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.ComponentNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
mixins_1.ExportMixinStub,
LayoutMixinStub,
mixins_1.GeometryMixinStub
]);
applyMixins_1.applyMixins(componentStubs_1.InstanceNodeStub, [
BaseNodeMixinStub,
mixins_1.ExportMixinStub,
LayoutMixinStub
]);
var selectionChangeSubscribes = new Map();

@@ -131,556 +141,14 @@ var currentPageChangeSubject = new rxjs_1.Subject();

}());
var ChildrenMixinStub = /** @class */ (function () {
function ChildrenMixinStub() {
}
ChildrenMixinStub.prototype.appendChild = function (item) {
if (!this.children) {
this.children = [];
}
if (item.parent) {
item.parent.children = item.parent.children.filter(function (child) { return child !== item; });
}
if (joinedConfig.simulateErrors && !item) {
throw new Error("Error: empty child");
}
if (joinedConfig.simulateErrors &&
// @ts-ignore
this.type === "DOCUMENT" &&
item.type !== "PAGE") {
throw new Error("Error: The root node cannot have children of type other than PAGE");
}
item.parent = this;
this.children.push(item);
};
ChildrenMixinStub.prototype.insertChild = function (index, child) {
if (!this.children) {
this.children = [];
}
if (joinedConfig.simulateErrors && !child) {
throw new Error("Error: empty child");
}
// @ts-ignore
if (joinedConfig.simulateErrors && child.parent === this) {
throw new Error("Error: Node already inside parent");
}
if (joinedConfig.simulateErrors &&
// @ts-ignore
this.type === "DOCUMENT" &&
child.type !== "PAGE") {
throw new Error("Error: The root node cannot have children of type other than PAGE");
}
if (child.parent) {
child.parent.children = child.parent.children.filter(function (_child) { return child !== _child; });
}
// @ts-ignore
child.parent = this;
this.children.splice(index, 0, child);
};
ChildrenMixinStub.prototype.findAllWithCriteria = function (criteria) {
var typeLookup = new Set(criteria.types);
return this.findAll(function () { return true; }).filter(function (child) {
return typeLookup.has(child.type);
});
};
ChildrenMixinStub.prototype.findAll = function (callback) {
if (!this.children) {
return [];
}
var matchingChildren = [];
this.children.forEach(function (child) {
if (callback(child)) {
matchingChildren.push(child);
}
if ("findAll" in child) {
matchingChildren.push.apply(matchingChildren, child.findAll(callback));
}
});
return matchingChildren;
};
ChildrenMixinStub.prototype.findOne = function (callback) {
var matches = this.findAll(callback);
if (matches.length > 0) {
return matches[0];
}
return null;
};
ChildrenMixinStub.prototype.findChild = function (callback) {
if (!this.children) {
return null;
}
return this.children.find(callback);
};
ChildrenMixinStub.prototype.findChildren = function (callback) {
if (!this.children) {
return null;
}
return this.children.filter(callback);
};
return ChildrenMixinStub;
}());
var BaseNodeMixinStub = /** @class */ (function () {
function BaseNodeMixinStub() {
}
BaseNodeMixinStub.prototype.setPluginData = function (key, value) {
if (!this.pluginData) {
this.pluginData = {};
}
this.pluginData[key] = value;
};
BaseNodeMixinStub.prototype.getPluginData = function (key) {
if (joinedConfig.simulateErrors && this.removed) {
throw new Error("The node with id " + this.id + " does not exist");
}
if (!this.pluginData) {
return;
}
return this.pluginData[key];
};
BaseNodeMixinStub.prototype.getPluginDataKeys = function () {
if (joinedConfig.simulateErrors && this.removed) {
throw new Error("The node with id " + this.id + " does not exist");
}
if (!this.pluginData) {
return [];
}
return Object.keys(this.pluginData);
};
BaseNodeMixinStub.prototype.setSharedPluginData = function (namespace, key, value) {
if (!this.sharedPluginData) {
this.sharedPluginData = {};
}
if (!this.sharedPluginData[namespace]) {
this.sharedPluginData[namespace] = {};
}
this.sharedPluginData[namespace][key] = value;
};
BaseNodeMixinStub.prototype.getSharedPluginData = function (namespace, key) {
if (!this.sharedPluginData || !this.sharedPluginData[namespace]) {
return;
}
return this.sharedPluginData[namespace][key];
};
BaseNodeMixinStub.prototype.getSharedPluginDataKeys = function (namespace) {
if (!this.sharedPluginData || !this.sharedPluginData[namespace]) {
return;
}
return Object.keys(this.sharedPluginData[namespace]);
};
BaseNodeMixinStub.prototype.setRelaunchData = function (data) {
this.relaunchData = data;
};
BaseNodeMixinStub.prototype.getRelaunchData = function () {
return this.relaunchData || {};
};
BaseNodeMixinStub.prototype.remove = function () {
var _this = this;
this.removed = true;
if (joinedConfig.simulateErrors && isInsideInstance(this)) {
throw new Error("Error: can't remove item");
}
if (this.parent) {
// @ts-ignore
this.parent.children = this.parent.children.filter(function (child) { return child !== _this; });
}
};
return BaseNodeMixinStub;
}());
var LayoutMixinStub = /** @class */ (function () {
function LayoutMixinStub() {
}
LayoutMixinStub.prototype.rescale = function (scale) {
if (joinedConfig.simulateErrors && scale < 0.01) {
throw new Error('Error: in rescale: Expected "scale" to have value >= 0.01');
}
this.width = this.width * scale;
this.height = this.height * scale;
};
LayoutMixinStub.prototype.resize = function (width, height) {
if (joinedConfig.simulateErrors && isInsideInstance(this)) {
throw new Error("Error: can't change layout inside item");
}
if (joinedConfig.simulateErrors && width < 0.01) {
throw new Error('Error: in resize: Expected "width" to have value >= 0.01');
}
if (joinedConfig.simulateErrors && height < 0.01) {
throw new Error('Error: in resize: Expected "height" to have value >= 0.01');
}
this.width = width;
this.height = height;
};
LayoutMixinStub.prototype.resizeWithoutConstraints = function (width, height) {
this.width = width;
this.height = height;
};
return LayoutMixinStub;
}());
var ExportMixinStub = /** @class */ (function () {
function ExportMixinStub() {
}
ExportMixinStub.prototype.exportAsync = function (settings) {
// "exportAsync" is not implemented in stubs
return Promise.resolve(new Uint8Array());
};
return ExportMixinStub;
}());
var GeometryMixinStub = /** @class */ (function () {
function GeometryMixinStub() {
}
Object.defineProperty(GeometryMixinStub.prototype, "fills", {
get: function () {
return this._fills || [];
},
set: function (theFills) {
this._fills = theFills;
},
enumerable: true,
configurable: true
});
GeometryMixinStub.prototype.outlineStroke = function () {
return null;
};
return GeometryMixinStub;
}());
var RectangleNodeStub = /** @class */ (function () {
function RectangleNodeStub() {
this.type = "RECTANGLE";
}
return RectangleNodeStub;
}());
applyMixins_1.applyMixins(RectangleNodeStub, [
BaseNodeMixinStub,
LayoutMixinStub,
ExportMixinStub,
GeometryMixinStub
]);
var TextNodeStub = /** @class */ (function () {
function TextNodeStub() {
this.type = "TEXT";
}
Object.defineProperty(TextNodeStub.prototype, "fontName", {
get: function () {
return this._fontName || { family: "Roboto", style: "Regular" };
},
set: function (fontName) {
if (joinedConfig.simulateErrors && !fontName) {
throw new Error("Error: fontName is undefined");
}
this._fontName = fontName;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextNodeStub.prototype, "characters", {
get: function () {
return this._characters || "";
},
set: function (characters) {
if (joinedConfig.simulateErrors && !isFontLoaded(this.fontName)) {
throw new Error("Error: font is not loaded " + this.fontName.family + " " + this.fontName.style);
}
this._characters = characters;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextNodeStub.prototype, "textAutoResize", {
get: function () {
return this._textAutoResize;
},
set: function (value) {
if (joinedConfig.simulateErrors && !isFontLoaded(this.fontName)) {
throw new Error("Error: font is not loaded " + this.fontName.family + " " + this.fontName.style);
}
this._textAutoResize = value;
},
enumerable: true,
configurable: true
});
TextNodeStub.prototype.getRangeFontName = function (start, end) {
if (joinedConfig.simulateErrors && start < 0) {
throw new Error("Error: Expected \"start\" to have value >=0");
}
if (joinedConfig.simulateErrors && end < 0) {
throw new Error("Error: Expected \"end\" to have value >=0");
}
if (joinedConfig.simulateErrors && end > this._characters.length) {
throw new Error("Error: Range outside of available characters. 'start' must be less than node.characters.length and 'end' must be less than or equal to node.characters.length");
}
if (joinedConfig.simulateErrors && end === start) {
throw new Error("Error: Empty range selected. 'end' must be greater than 'start'");
}
return this._fontName || { family: "Roboto", style: "Regular" };
};
TextNodeStub.prototype.deleteCharacters = function (start, end) {
if (joinedConfig.simulateErrors && !isFontLoaded(this.fontName)) {
throw new Error("Error: font is not loaded " + this.fontName.family + " " + this.fontName.style);
}
if (joinedConfig.simulateErrors && start < 0) {
throw new Error("Error: Expected \"start\" to have value >=0");
}
if (joinedConfig.simulateErrors && end < 0) {
throw new Error("Error: Expected \"end\" to have value >=0");
}
if (joinedConfig.simulateErrors && end > this._characters.length) {
throw new Error("Error: Cannot delete characters at index greater than the length of the text");
}
this._characters =
this._characters.slice(start, end) +
(end === this._characters.length
? ""
: this._characters.slice(end + 1));
};
TextNodeStub.prototype.insertCharacters = function (start, characters, _useStyle) {
if (_useStyle === void 0) { _useStyle = "BEFORE"; }
if (joinedConfig.simulateErrors && !isFontLoaded(this.fontName)) {
throw new Error("Error: font is not loaded " + this.fontName.family + " " + this.fontName.style);
}
if (joinedConfig.simulateErrors && start < 0) {
throw new Error("Error: Expected \"start\" to have value >=0");
}
if (joinedConfig.simulateErrors && start > this._characters.length) {
throw new Error("Error: Cannot insert characters at index greater than the length of the text");
}
this._characters = [
this._characters.slice(0, start),
characters,
this._characters.slice(start)
].join("");
};
return TextNodeStub;
}());
applyMixins_1.applyMixins(TextNodeStub, [
BaseNodeMixinStub,
LayoutMixinStub,
ExportMixinStub,
GeometryMixinStub
]);
var DocumentNodeStub = /** @class */ (function () {
function DocumentNodeStub() {
this.type = "DOCUMENT";
this.children = [];
}
return DocumentNodeStub;
}());
applyMixins_1.applyMixins(DocumentNodeStub, [BaseNodeMixinStub, ChildrenMixinStub]);
var PageNodeStub = /** @class */ (function () {
function PageNodeStub() {
this.type = "PAGE";
this.children = [];
}
Object.defineProperty(PageNodeStub.prototype, "selection", {
get: function () {
return this._selection || [];
},
set: function (value) {
this._selection = value;
selectionChangeSubject.next();
},
enumerable: true,
configurable: true
});
return PageNodeStub;
}());
applyMixins_1.applyMixins(PageNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
ExportMixinStub
]);
var FrameNodeStub = /** @class */ (function () {
function FrameNodeStub() {
this.type = "FRAME";
this.children = [];
}
return FrameNodeStub;
}());
applyMixins_1.applyMixins(FrameNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
LayoutMixinStub,
ExportMixinStub,
GeometryMixinStub
]);
var GroupNodeStub = /** @class */ (function () {
function GroupNodeStub() {
this.type = "GROUP";
}
Object.defineProperty(GroupNodeStub.prototype, "constraints", {
set: function (value) {
if (joinedConfig.simulateErrors) {
throw new Error("Error: Cannot add property constraints, object is not extensible");
}
},
enumerable: true,
configurable: true
});
return GroupNodeStub;
}());
applyMixins_1.applyMixins(GroupNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
ExportMixinStub,
LayoutMixinStub
]);
var ComponentNodeStub = /** @class */ (function () {
function ComponentNodeStub() {
this.type = "COMPONENT";
this.key = nanoid_1.nanoid(40);
this.children = [];
}
ComponentNodeStub.prototype.createInstance = function () {
var instance = new InstanceNodeStub();
instance.children = cloneDeep(this.children);
instance.mainComponent = this;
return instance;
};
return ComponentNodeStub;
}());
applyMixins_1.applyMixins(ComponentNodeStub, [
BaseNodeMixinStub,
ChildrenMixinStub,
ExportMixinStub,
LayoutMixinStub,
GeometryMixinStub
]);
var InstanceNodeStub = /** @class */ (function () {
function InstanceNodeStub() {
this.type = "INSTANCE";
}
InstanceNodeStub.prototype.detachInstance = function () {
this.type = "FRAME";
};
return InstanceNodeStub;
}());
applyMixins_1.applyMixins(InstanceNodeStub, [
BaseNodeMixinStub,
ExportMixinStub,
LayoutMixinStub
]);
// --- styles
var styles = new Map();
var paintStyles = [];
var effectStyles = [];
var textStyles = [];
var gridStyles = [];
var BaseStyleStub = /** @class */ (function () {
function BaseStyleStub() {
this.remote = false;
}
BaseStyleStub.prototype.setPluginData = function (key, value) {
if (!this.pluginData) {
this.pluginData = {};
}
this.pluginData[key] = value;
};
BaseStyleStub.prototype.getPluginData = function (key) {
if (joinedConfig.simulateErrors && this.removed) {
throw new Error("The style with id " + this.id + " does not exist");
}
if (!this.pluginData) {
return;
}
return this.pluginData[key];
};
BaseStyleStub.prototype.getPluginDataKeys = function () {
if (joinedConfig.simulateErrors && this.removed) {
throw new Error("The style with id " + this.id + " does not exist");
}
if (!this.pluginData) {
return [];
}
return Object.keys(this.pluginData);
};
BaseStyleStub.prototype.setSharedPluginData = function (namespace, key, value) {
if (!this.sharedPluginData) {
this.sharedPluginData = {};
}
if (!this.sharedPluginData[namespace]) {
this.sharedPluginData[namespace] = {};
}
this.sharedPluginData[namespace][key] = value;
};
BaseStyleStub.prototype.getSharedPluginData = function (namespace, key) {
if (!this.sharedPluginData || !this.sharedPluginData[namespace]) {
return;
}
return this.sharedPluginData[namespace][key];
};
BaseStyleStub.prototype.getSharedPluginDataKeys = function (namespace) {
if (!this.sharedPluginData || !this.sharedPluginData[namespace]) {
return;
}
return Object.keys(this.sharedPluginData[namespace]);
};
BaseStyleStub.prototype.remove = function () {
this.removed = true;
styles.delete(this.id);
};
BaseStyleStub.prototype.getPublishStatusAsync = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, "UNPUBLISHED"];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
return BaseStyleStub;
}());
applyMixins_1.applyMixins(BaseStyleStub, []);
var PaintStyleStub = /** @class */ (function (_super) {
__extends(PaintStyleStub, _super);
function PaintStyleStub() {
var _this = _super !== null && _super.apply(this, arguments) || this;
// @ts-ignore
_this.type = "PAINT";
return _this;
}
PaintStyleStub.prototype.remove = function () {
_super.prototype.remove.call(this);
paintStyles.splice(paintStyles.indexOf(this), 1);
};
return PaintStyleStub;
}(BaseStyleStub));
var EffectStyleStub = /** @class */ (function (_super) {
__extends(EffectStyleStub, _super);
function EffectStyleStub() {
var _this = _super !== null && _super.apply(this, arguments) || this;
// @ts-ignore
_this.type = "EFFECT";
return _this;
}
EffectStyleStub.prototype.remove = function () {
_super.prototype.remove.call(this);
effectStyles.splice(effectStyles.indexOf(this), 1);
};
return EffectStyleStub;
}(BaseStyleStub));
var TextStyleStub = /** @class */ (function (_super) {
__extends(TextStyleStub, _super);
function TextStyleStub() {
var _this = _super !== null && _super.apply(this, arguments) || this;
// @ts-ignore
_this.type = "TEXT";
return _this;
}
TextStyleStub.prototype.remove = function () {
_super.prototype.remove.call(this);
textStyles.splice(textStyles.indexOf(this), 1);
};
return TextStyleStub;
}(BaseStyleStub));
var GridStyleStub = /** @class */ (function (_super) {
__extends(GridStyleStub, _super);
function GridStyleStub() {
var _this = _super !== null && _super.apply(this, arguments) || this;
// @ts-ignore
_this.type = "GRID";
return _this;
}
GridStyleStub.prototype.remove = function () {
_super.prototype.remove.call(this);
gridStyles.splice(gridStyles.indexOf(this), 1);
};
return GridStyleStub;
}(BaseStyleStub));
var PaintStyleStub = styleStubs_1.getPaintStyleStub(config);
var EffectStyleStub = styleStubs_1.getEffectStyleStub(config);
var TextStyleStub = styleStubs_1.getTextStyleStub(config);
var GridStyleStub = styleStubs_1.getGridStyleStub(config);
var styleBasics = {
styles: new Map(),
paintStyles: [],
effectStyles: [],
textStyles: [],
gridStyles: []
};
// @ts-ignore

@@ -690,7 +158,7 @@ var PluginApiStub = /** @class */ (function () {

// @ts-ignore
this.root = new DocumentNodeStub();
this.root = new componentStubs_1.DocumentNodeStub();
// @ts-ignore
this.root.id = "0:0";
// @ts-ignore
this._currentPage = new PageNodeStub();
this._currentPage = new componentStubs_1.PageNodeStub();
// @ts-ignore

@@ -715,3 +183,3 @@ this._currentPage.id = "0:1";

PluginApiStub.prototype.createPage = function () {
var result = new PageNodeStub();
var result = new componentStubs_1.PageNodeStub(config);
allocateNodeId(result, true);

@@ -723,3 +191,3 @@ this.root.appendChild(result);

PluginApiStub.prototype.createFrame = function () {
var result = new FrameNodeStub();
var result = new componentStubs_1.FrameNodeStub(config);
allocateNodeId(result);

@@ -730,4 +198,18 @@ this.currentPage.appendChild(result);

// @ts-ignore
PluginApiStub.prototype.createShapeWithText = function () {
var result = new componentStubs_1.ShapeWithTextNodeStub(config);
allocateNodeId(result);
this.root.appendChild(result);
return result;
};
// @ts-ignore
PluginApiStub.prototype.createSticky = function () {
var result = new componentStubs_1.StickyNodeStub(config);
allocateNodeId(result);
this.root.appendChild(result);
return result;
};
// @ts-ignore
PluginApiStub.prototype.createComponent = function () {
var result = new ComponentNodeStub();
var result = new componentStubs_1.ComponentNodeStub(config);
allocateNodeId(result);

@@ -739,3 +221,3 @@ this.currentPage.appendChild(result);

PluginApiStub.prototype.createRectangle = function () {
var result = new RectangleNodeStub();
var result = new componentStubs_1.RectangleNodeStub(config);
allocateNodeId(result);

@@ -747,3 +229,3 @@ this.currentPage.appendChild(result);

PluginApiStub.prototype.createText = function () {
var result = new TextNodeStub();
var result = new componentStubs_1.TextNodeStub(config);
allocateNodeId(result);

@@ -753,5 +235,11 @@ this.currentPage.appendChild(result);

};
PluginApiStub.prototype.createConnector = function () {
var result = new componentStubs_1.ConnectorNodeStub(config);
allocateNodeId(result);
this.currentPage.appendChild(result);
return result;
};
PluginApiStub.prototype.getStyleById = function (id) {
if (styles.has(id)) {
return styles.get(id);
if (styleBasics.styles.has(id)) {
return styleBasics.styles.get(id);
}

@@ -761,19 +249,19 @@ return null;

PluginApiStub.prototype.getLocalPaintStyles = function () {
return paintStyles;
return styleBasics.paintStyles;
};
PluginApiStub.prototype.getLocalEffectStyles = function () {
return effectStyles;
return styleBasics.effectStyles;
};
PluginApiStub.prototype.getLocalTextStyles = function () {
return textStyles;
return styleBasics.textStyles;
};
PluginApiStub.prototype.getLocalGridStyles = function () {
return gridStyles;
return styleBasics.gridStyles;
};
// @ts-ignore
PluginApiStub.prototype.createPaintStyle = function () {
var style = new PaintStyleStub();
var style = new PaintStyleStub(styleBasics);
allocateStyleId(style);
styles.set(style.id, style);
paintStyles.push(style);
styleBasics.styles.set(style.id, style);
styleBasics.paintStyles.push(style);
return style;

@@ -783,6 +271,6 @@ };

PluginApiStub.prototype.createEffectStyle = function () {
var style = new EffectStyleStub();
var style = new EffectStyleStub(styleBasics);
allocateStyleId(style);
styles.set(style.id, style);
effectStyles.push(style);
styleBasics.styles.set(style.id, style);
styleBasics.effectStyles.push(style);
return style;

@@ -792,6 +280,6 @@ };

PluginApiStub.prototype.createTextStyle = function () {
var style = new TextStyleStub();
var style = new TextStyleStub(styleBasics);
allocateStyleId(style);
styles.set(style.id, style);
textStyles.push(style);
styleBasics.styles.set(style.id, style);
styleBasics.textStyles.push(style);
return style;

@@ -801,6 +289,6 @@ };

PluginApiStub.prototype.createGridStyle = function () {
var style = new GridStyleStub();
var style = new GridStyleStub(styleBasics);
allocateStyleId(style);
styles.set(style.id, style);
gridStyles.push(style);
styleBasics.styles.set(style.id, style);
styleBasics.gridStyles.push(style);
return style;

@@ -815,8 +303,44 @@ };

};
PluginApiStub.prototype.union = function (nodes, parent, index) {
var booleanOperation = this.booleanOperate(nodes, parent, index);
booleanOperation.booleanOperation = "UNION";
return booleanOperation;
};
PluginApiStub.prototype.intersect = function (nodes, parent, index) {
var booleanOperation = this.booleanOperate(nodes, parent, index);
booleanOperation.booleanOperation = "INTERSECT";
return booleanOperation;
};
PluginApiStub.prototype.subtract = function (nodes, parent, index) {
var booleanOperation = this.booleanOperate(nodes, parent, index);
booleanOperation.booleanOperation = "SUBTRACT";
return booleanOperation;
};
PluginApiStub.prototype.exlude = function (nodes, parent, index) {
var booleanOperation = this.booleanOperate(nodes, parent, index);
booleanOperation.booleanOperation = "EXCLUDE";
return booleanOperation;
};
PluginApiStub.prototype.booleanOperate = function (nodes, parent, index) {
if (config.simulateErrors && (!nodes || nodes.length === 0)) {
throw new Error("Error: First argument must be an array of at least one node");
}
var booleanOperation = new componentStubs_1.BooleanOperationNodeStub(config);
allocateNodeId(booleanOperation);
nodes.forEach(function (node) { return booleanOperation.appendChild(node); });
if (index) {
parent.insertChild(index, booleanOperation);
}
else {
parent.appendChild(booleanOperation);
}
booleanOperation.parent = parent;
return booleanOperation;
};
// @ts-ignore
PluginApiStub.prototype.group = function (nodes, parent, index) {
if (joinedConfig.simulateErrors && (!nodes || nodes.length === 0)) {
if (config.simulateErrors && (!nodes || nodes.length === 0)) {
throw new Error("Error: First argument must be an array of at least one node");
}
var group = new GroupNodeStub();
var group = new componentStubs_1.GroupNodeStub(config);
allocateNodeId(group);

@@ -835,7 +359,7 @@ nodes.forEach(function (node) { return group.appendChild(node); });

PluginApiStub.prototype.loadFontAsync = function (fontName) {
if (isFontLoaded(fontName)) {
if (fonts_1.Fonts.isFontLoaded(fontName)) {
return;
}
return new Promise(function (resolve) {
loadedFonts.push(fontName);
fonts_1.Fonts.loadedFonts.push(fontName);
resolve();

@@ -849,3 +373,3 @@ });

if (type === "selectionchange") {
selectionChangeSubscribes.set(callback, selectionChangeSubject.subscribe(callback));
selectionChangeSubscribes.set(callback, componentStubs_1.selectionChangeSubject.subscribe(callback));
}

@@ -858,3 +382,3 @@ if (type === "currentpagechange") {

if (type === "selectionchange") {
selectionChangeSubscribes.set(callback, selectionChangeSubject.pipe(operators_1.take(1)).subscribe(callback));
selectionChangeSubscribes.set(callback, componentStubs_1.selectionChangeSubject.pipe(operators_1.take(1)).subscribe(callback));
}

@@ -861,0 +385,0 @@ if (type === "currentpagechange") {

{
"name": "figma-api-stub",
"version": "0.0.50",
"version": "0.0.51",
"description": "Figma API stub",
"main": "./dist/index.js",
"scripts": {
"tsc": "tsc -p tsconfig.json",
"tsc": "tsc -p tsconfig.build.json",
"prettify": "prettier \"src/**/*.{js,jsx,ts,tsx}\" --ignore-path ./.prettierignore --write && git add . && git status",
"build": "npm run build:clean && npm run build:lib",
"build:clean": "rimraf dist",
"build:lib": "cross-env BABEL_ENV=production tsc -p tsconfig.json",
"build:lib": "cross-env BABEL_ENV=production tsc -p tsconfig.build.json",
"prepublishOnly": "npm run build",

@@ -38,3 +38,3 @@ "test": "jest"

"devDependencies": {
"@figma/plugin-typings": "^1.42.0",
"@figma/plugin-typings": "^1.42.1",
"@types/jest": "^24.0.23",

@@ -41,0 +41,0 @@ "cross-env": "^6.0.3",

@@ -34,5 +34,4 @@ {

"node_modules",
"dist",
"**/__tests__/**"
"dist"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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