New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@opendesign/octopus-fig

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opendesign/octopus-fig - npm Package Compare versions

Comparing version 3.0.0-rc.27 to 3.0.0-rc.28

{
"name": "@opendesign/octopus-fig",
"version": "3.0.0-rc.27",
"version": "3.0.0-rc.28",
"description": "Figma HTTP API format to Octopus 3+ converter.",

@@ -11,14 +11,17 @@ "license": "Apache-2.0",

"clean:workdir": "rimraf ./workdir/*",
"clean": "rimraf ./node_modules ./lib ./dist ./workdir ./test/integration/report",
"clean": "rimraf ./node_modules ./lib ./dist ./workdir ./test/**/report",
"convert:api:debug": "ts-node ./examples/node/convert-api-debug.ts",
"convert:api:local": "ts-node ./examples/node/convert-api-local.ts",
"convert:source:debug": "ts-node ./examples/node/convert-plugin-source-debug.ts",
"convert:source:local": "ts-node ./examples/node/convert-plugin-source-local.ts",
"convert:squid:debug": "ts-node ./examples/node/convert-plugin-squid-debug.ts",
"convert:squid:local": "ts-node ./examples/node/convert-plugin-squid-local.ts",
"prepack": "rimraf ./lib && yarn run build",
"test": "yarn test:unit && yarn test:integration",
"test:unit": "yarn jest",
"test:integration": "ts-node test/integration",
"test:integration:update": "yarn test:integration:update:assets && yarn test:integration:update:tests",
"test:integration:update:assets": "ts-node test/integration/update-assets.ts",
"test:integration:update:tests": "ts-node test/integration/update-tests.ts",
"test:integration": "yarn test:integration:parser && yarn test:integration:squid",
"test:integration:parser": "ts-node test/integration/figma-parser",
"test:integration:parser:update": "yarn test:integration:parser:update:assets && yarn test:integration:parser:update:tests",
"test:integration:parser:update:assets": "ts-node test/integration/figma-parser/update-assets.ts",
"test:integration:parser:update:tests": "ts-node test/integration/figma-parser/update-tests.ts",
"test:integration:squid": "ts-node test/integration/squid-plugin",
"test:integration:squid:update": "ts-node test/integration/squid-plugin/update-tests.ts",
"types:check": "tsc --noEmit",

@@ -30,5 +33,5 @@ "typedoc": "typedoc --excludePrivate src/index-node.ts src/index-web.ts",

"@opendesign/figma-parser": "3.0.0-rc.17",
"@opendesign/manifest-ts": "3.0.0-alpha.40",
"@opendesign/octopus-common": "3.0.0-rc.27",
"@opendesign/octopus-ts": "3.0.0-alpha.40",
"@opendesign/manifest-ts": "3.0.1",
"@opendesign/octopus-common": "3.0.0-rc.28",
"@opendesign/octopus-ts": "3.0.1",
"@types/lodash": "^4.14.178",

@@ -35,0 +38,0 @@ "@types/uuid": "^8.3.1",

import type { SourceLayer } from '../../factories/create-source-layer';
import type { DesignConverter } from '../../services/conversion/design-converter';
import type { Octopus } from '../../typings/octopus';
import type { SourceComponent } from '../source/source-component';
import type { OctopusManifest } from './octopus-manifest';
declare type OctopusComponentOptions = {
designConverter: DesignConverter;
source: SourceComponent;
version: string;
};
export declare class OctopusComponent {
private _designConverter;
private _sourceComponent;
private _version;
constructor(options: OctopusComponentOptions);

@@ -15,8 +17,10 @@ get parentComponent(): OctopusComponent;

get sourceLayer(): SourceLayer;
get designConverter(): DesignConverter;
get octopusManifest(): OctopusManifest;
get dimensions(): Octopus['Dimensions'] | undefined;
get id(): string;
get version(): string;
private get _content();
private _content;
convert(): Promise<Octopus['OctopusComponent']>;
}
export {};

@@ -9,4 +9,4 @@ "use strict";

constructor(options) {
this._designConverter = options.designConverter;
this._sourceComponent = options.source;
this._version = options.version;
}

@@ -22,2 +22,8 @@ get parentComponent() {

}
get designConverter() {
return this._designConverter;
}
get octopusManifest() {
return this.designConverter.octopusManifest;
}
get dimensions() {

@@ -34,9 +40,9 @@ const bounds = services_1.env.NODE_ENV === 'debug' ? this.sourceComponent.bounds : this.sourceComponent.boundingBox; // TODO remove when ISSUE is fixed https://gitlab.avcd.cz/opendesign/open-design-engine/-/issues/21

get version() {
return this._version;
return this._designConverter.pkgMeta.octopusSpecVersion;
}
get _content() {
var _a;
async _content() {
const sourceLayer = this.sourceLayer;
const layer = (0, create_octopus_layer_1.createOctopusLayer)({ parent: this, layer: sourceLayer });
return (_a = layer === null || layer === void 0 ? void 0 : layer.convert()) !== null && _a !== void 0 ? _a : undefined;
const converted = await (layer === null || layer === void 0 ? void 0 : layer.convert());
return converted !== null && converted !== void 0 ? converted : undefined;
}

@@ -46,6 +52,6 @@ async convert() {

id: this.id,
type: 'ARTBOARD',
type: 'OCTOPUS_COMPONENT',
version: this.version,
dimensions: this.dimensions,
content: this._content,
content: await this._content(),
};

@@ -52,0 +58,0 @@ }

@@ -0,7 +1,7 @@

import type { OctopusLayer } from '../../factories/create-octopus-layer';
import type { Octopus } from '../../typings/octopus';
import type { SourceLayerCommon } from '../source/source-layer-common';
import type { SourcePaint } from '../source/source-paint';
declare type OctopusFillOptions = {
fill: SourcePaint;
parentLayer: SourceLayerCommon;
parentLayer: OctopusLayer;
};

@@ -11,3 +11,3 @@ export declare class OctopusFill {

private _parentLayer;
static convertFills(fills: SourcePaint[], parentLayer: SourceLayerCommon): Octopus['Fill'][];
static convertFills(fills: SourcePaint[], parentLayer: OctopusLayer): Promise<Octopus['Fill'][]>;
constructor(options: OctopusFillOptions);

@@ -29,5 +29,5 @@ get fillType(): Octopus['FillType'] | null;

private get _filterAdjustment();
private get _fillImage();
convert(): Octopus['Fill'] | null;
private _fillImage;
convert(): Promise<Octopus['Fill'] | null>;
}
export {};

@@ -15,6 +15,4 @@ "use strict";

static convertFills(fills, parentLayer) {
return fills.reduce((fills, fill) => {
const newFill = new OctopusFill({ fill, parentLayer }).convert();
return newFill ? (0, common_1.push)(fills, newFill) : fills;
}, []);
const octopusFills = fills.map((fill) => new OctopusFill({ fill, parentLayer }));
return (0, common_1.getConvertedAsync)(octopusFills);
}

@@ -95,3 +93,3 @@ get fillType() {

get _transform() {
const size = this._parentLayer.size;
const size = this._parentLayer.sourceLayer.size;
if (size === null)

@@ -157,3 +155,3 @@ return null;

return null;
const imageSize = this._parentLayer.parentComponent.getImageSize(imageRef);
const imageSize = this._parentLayer.parentComponent.designConverter.getImageSize(imageRef);
if (!imageSize)

@@ -166,3 +164,3 @@ return null;

}
const size = this._parentLayer.size;
const size = this._parentLayer.sourceLayer.size;
if (!size)

@@ -177,2 +175,9 @@ return null;

}
if (this._fill.rotation) {
const transform = (0, paper_1.createMatrix)([1, 0, 0, 1, 0, 0])
.rotate(this._fill.rotation, 0.5, 0.5)
.invert()
.prepend((0, paper_1.createMatrix)([x, 0, 0, y, 0, 0])).values;
return { layout, origin, transform };
}
const transform = [x, 0, 0, y, 0, 0];

@@ -209,7 +214,10 @@ return { layout, origin, transform };

}
get _fillImage() {
async _fillImage() {
const imageRef = this._fill.imageRef;
if (!imageRef)
return null;
const image = { ref: { type: 'PATH', value: `images/${imageRef}.png` } };
const exportedPath = await this._parentLayer.parentComponent.octopusManifest.getExportedImagePath(imageRef);
const image = exportedPath
? { ref: { type: 'PATH', value: exportedPath } }
: { ref: { type: 'RESOURCE_REF', value: imageRef } };
const visible = this.visible;

@@ -223,3 +231,3 @@ const blendMode = this.blendMode;

}
convert() {
async convert() {
switch (this.fillType) {

@@ -231,3 +239,3 @@ case 'COLOR':

case 'IMAGE':
return this._fillImage;
return this._fillImage();
default:

@@ -234,0 +242,0 @@ return null;

@@ -20,4 +20,4 @@ import { OctopusLayerBase } from './octopus-layer-base';

private _convertTypeSpecific;
convert(): Octopus['GroupLayer'] | null;
convert(): Promise<Octopus['GroupLayer'] | null>;
}
export {};

@@ -35,14 +35,14 @@ "use strict";

}
_convertTypeSpecific() {
async _convertTypeSpecific() {
return {
type: 'GROUP',
layers: (0, common_1.getConverted)(this._layers),
layers: await (0, common_1.getConvertedAsync)(this.layers),
meta: this.meta,
};
}
convert() {
async convert() {
const common = this.convertBase();
if (!common)
return null;
const specific = this._convertTypeSpecific();
const specific = await this._convertTypeSpecific();
if (!specific)

@@ -49,0 +49,0 @@ return null;

import { OctopusComponent } from './octopus-component';
import type { OctopusLayer } from '../../factories/create-octopus-layer';
import type { SourceLayer } from '../../factories/create-source-layer';
import type { Octopus } from '../../typings/octopus';

@@ -66,4 +67,5 @@ import type { RawBlendMode } from '../../typings/raw';

get meta(): Octopus['LayerMeta'] | undefined;
convert(): Octopus['MaskGroupLayer'] | null;
get sourceLayer(): SourceLayer;
convert(): Promise<Octopus['MaskGroupLayer'] | null>;
}
export {};

@@ -135,5 +135,8 @@ "use strict";

}
convert() {
const mask = this.mask.convert();
if (!mask)
get sourceLayer() {
return this._parent.sourceLayer;
}
async convert() {
const convertedMask = await this.mask.convert();
if (!convertedMask)
return null;

@@ -149,5 +152,5 @@ return {

maskChannels: this.maskChannels,
mask,
mask: convertedMask,
transform: this.transform,
layers: (0, common_1.getConverted)(this._layers),
layers: await (0, common_1.getConvertedAsync)(this.layers),
meta: this.meta,

@@ -154,0 +157,0 @@ };

@@ -18,6 +18,6 @@ import { OctopusLayerBase } from './octopus-layer-base';

private get _strokes();
private get _shape();
private _shape;
private _convertTypeSpecific;
convert(): Octopus['ShapeLayer'] | null;
convert(): Promise<Octopus['ShapeLayer'] | null>;
}
export {};

@@ -17,26 +17,26 @@ "use strict";

get _fills() {
return octopus_fill_1.OctopusFill.convertFills(this.sourceLayer.fills, this.sourceLayer);
return octopus_fill_1.OctopusFill.convertFills(this.sourceLayer.fills, this);
}
get _strokes() {
return octopus_stroke_1.OctopusStroke.convertStrokes(this.sourceLayer.strokes, this.sourceLayer);
return octopus_stroke_1.OctopusStroke.convertStrokes(this.sourceLayer.strokes, this);
}
get _shape() {
async _shape() {
return {
path: this._path.convert(),
fillRule: this._path.fillRule,
fills: this._fills,
strokes: this._strokes,
fills: await this._fills,
strokes: await this._strokes,
};
}
_convertTypeSpecific() {
async _convertTypeSpecific() {
return {
type: 'SHAPE',
shape: this._shape,
shape: await this._shape(),
};
}
convert() {
async convert() {
const common = this.convertBase();
if (!common)
return null;
const specific = this._convertTypeSpecific();
const specific = await this._convertTypeSpecific();
if (!specific)

@@ -43,0 +43,0 @@ return null;

@@ -34,4 +34,4 @@ import { OctopusLayerBase } from './octopus-layer-base';

private _getFills;
private get _fills();
private get _strokes();
private _fills;
private _strokes;
private _parsePostScriptName;

@@ -41,10 +41,10 @@ private _getFont;

private _getStyle;
private get _defaultStyle();
private get _styles();
private _defaultStyle;
private _styles;
get horizontalAlign(): Octopus['Text']['horizontalAlign'];
private get _frame();
private get _text();
private _text;
private _convertTypeSpecific;
convert(): Octopus['TextLayer'] | null;
convert(): Promise<Octopus['TextLayer'] | null>;
}
export {};

@@ -27,16 +27,13 @@ "use strict";

}
_getFills(fills) {
return fills.reduce((fills, fill) => {
const newFill = new octopus_fill_1.OctopusFill({ fill, parentLayer: this.sourceLayer }).convert();
return newFill ? (0, common_1.push)(fills, newFill) : fills;
}, []);
async _getFills(fills) {
const converted = await Promise.all(fills.map((fill) => new octopus_fill_1.OctopusFill({ fill, parentLayer: this }).convert()));
return converted.filter((fill) => Boolean(fill));
}
get _fills() {
async _fills() {
return this._getFills(this.sourceLayer.fills);
}
get _strokes() {
return this.sourceLayer.strokes.reduce((strokes, fill) => {
const stroke = new octopus_stroke_1.OctopusStroke({ fill, sourceLayer: this.sourceLayer }).convert();
return stroke ? (0, common_1.push)(strokes, stroke) : strokes;
}, []);
async _strokes() {
const strokes = this.sourceLayer.strokes;
const converted = await Promise.all(strokes.map((fill) => new octopus_stroke_1.OctopusStroke({ fill, parentLayer: this }).convert()));
return converted.filter((stroke) => Boolean(stroke));
}

@@ -64,3 +61,3 @@ _parsePostScriptName(textStyle) {

}
_getStyle(textStyle) {
async _getStyle(textStyle) {
const font = this._getFont(textStyle);

@@ -75,6 +72,6 @@ const fontSize = textStyle.fontSize;

const linethrough = textDecoration === undefined ? undefined : textDecoration === 'STRIKETHROUGH';
const fills = textStyle.textFills && this._getFills(textStyle.textFills);
const fills = textStyle.textFills && (await this._getFills(textStyle.textFills));
return { font, fontSize, lineHeight, kerning, letterSpacing, underline, linethrough, letterCase, fills };
}
get _defaultStyle() {
async _defaultStyle() {
var _a, _b;

@@ -97,7 +94,7 @@ const textStyle = this.sourceLayer.defaultStyle;

const linethrough = textDecoration === 'STRIKETHROUGH' ? true : undefined;
const fills = ((_b = textStyle.textFills) === null || _b === void 0 ? void 0 : _b.length) ? this._getFills(textStyle.textFills) : this._fills;
const strokes = this._strokes;
const fills = ((_b = textStyle.textFills) === null || _b === void 0 ? void 0 : _b.length) ? await this._getFills(textStyle.textFills) : await this._fills();
const strokes = await this._strokes();
return { font, fontSize, lineHeight, kerning, letterSpacing, underline, linethrough, letterCase, fills, strokes };
}
get _styles() {
async _styles() {
const overrideMap = this.sourceLayer.characterStyleOverrides.reduce((overrideMap, key, index) => {

@@ -114,15 +111,16 @@ const arr = overrideMap[key];

const overrideTable = this.sourceLayer.styleOverrideTable;
return Object.keys(overrideMap).reduce((styleRanges, key) => {
const styles = await Promise.all(Object.keys(overrideMap).map(async (key) => {
const sourceStyle = overrideTable[key];
if (!sourceStyle)
return styleRanges;
const style = this._getStyle(sourceStyle);
return null;
const style = await this._getStyle(sourceStyle);
if (!style)
return styleRanges;
return null;
const positions = overrideMap[key];
if (!positions)
return styleRanges;
return null;
const ranges = positions.map((from) => ({ from, to: from + 1 }));
return (0, common_1.push)(styleRanges, { style, ranges });
}, []);
return { style, ranges };
}));
return styles.filter((style) => Boolean(style));
}

@@ -146,9 +144,9 @@ get horizontalAlign() {

}
get _text() {
async _text() {
var _a;
const value = this.sourceLayer.characters;
const defaultStyle = this._defaultStyle;
const defaultStyle = await this._defaultStyle();
if (!defaultStyle)
return null;
const styles = this._styles;
const styles = await this._styles();
const horizontalAlign = this.horizontalAlign;

@@ -161,4 +159,4 @@ const verticalAlign = (_a = this.sourceLayer.defaultStyle) === null || _a === void 0 ? void 0 : _a.textAlignVertical;

}
_convertTypeSpecific() {
const text = this._text;
async _convertTypeSpecific() {
const text = await this._text();
if (!text)

@@ -168,7 +166,7 @@ return null;

}
convert() {
async convert() {
const common = this.convertBase();
if (!common)
return null;
const specific = this._convertTypeSpecific();
const specific = await this._convertTypeSpecific();
if (!specific)

@@ -175,0 +173,0 @@ return null;

@@ -34,4 +34,5 @@ import type { OctopusFigConverter } from '../../octopus-fig-converter';

constructor(options: OctopusManifestOptions);
setExportedImagePath(name: string, path: string | undefined): void;
getExportedImagePath(name: string): string | undefined;
finalize(): void;
setExportedImagePath(name: string, pathPromise?: Promise<string>): Promise<void>;
getExportedImagePath(name: string): Promise<string | undefined> | undefined;
setExportedPreviewPath(componentId: string, path: string | undefined): void;

@@ -53,2 +54,3 @@ getExportedPreviewPath(componentId: string): string | undefined;

get manifestVersion(): string;
get meta(): Manifest['OctopusManifestMeta'];
get figVersion(): string;

@@ -72,5 +74,5 @@ get name(): string;

private _getComponent;
get components(): Manifest['Component'][];
components(): Promise<Manifest['Component'][]>;
convert(): Promise<Manifest['OctopusManifest']>;
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OctopusManifest = void 0;
const async_1 = require("@opendesign/octopus-common/dist/utils/async");
const common_1 = require("@opendesign/octopus-common/dist/utils/common");

@@ -22,7 +23,22 @@ const services_1 = require("../../services");

}
setExportedImagePath(name, path) {
this._exports.images.set(name, path);
finalize() {
const imageNames = [...this._exports.images.keys()]; // let's finish all the pending stuff with rejection
imageNames.forEach((name) => {
var _a;
(_a = this._exports.images.get(name)) === null || _a === void 0 ? void 0 : _a.reject(new Error(`Image with name '${name}' is missing`));
});
}
async setExportedImagePath(name, pathPromise) {
var _a;
if (!this._exports.images.has(name)) {
this._exports.images.set(name, (0, async_1.detachPromiseControls)());
}
(_a = this._exports.images.get(name)) === null || _a === void 0 ? void 0 : _a.resolve(pathPromise);
}
getExportedImagePath(name) {
return this._exports.images.get(name);
var _a;
if (!this._exports.images.has(name)) {
this._exports.images.set(name, (0, async_1.detachPromiseControls)());
}
return (_a = this._exports.images.get(name)) === null || _a === void 0 ? void 0 : _a.promise;
}

@@ -81,4 +97,8 @@ setExportedPreviewPath(componentId, path) {

get manifestVersion() {
return this._octopusConverter.pkg.version;
return this._octopusConverter.pkg.manifestSpecVersion;
}
get meta() {
const converterVersion = this._octopusConverter.pkg.version;
return { converterVersion };
}
get figVersion() {

@@ -103,3 +123,3 @@ var _a;

get pages() {
return this._sourceDesign.pages.map((page) => ({
const converted = this._sourceDesign.pages.map((page) => ({
id: (0, convert_1.convertId)(page.id),

@@ -110,2 +130,3 @@ name: page.name,

}));
return [...converted].sort((a, b) => (0, common_1.compareStrings)(a.id, b.id));
}

@@ -123,13 +144,16 @@ _getStatus(source) {

}
_getAssetImage(imageName) {
async _getAssetImage(imageName) {
var _a;
const path = (_a = this.getExportedImagePath(imageName)) !== null && _a !== void 0 ? _a : '';
const path = (_a = (await this.getExportedImagePath(imageName))) !== null && _a !== void 0 ? _a : '';
const location = { type: 'RELATIVE', path };
return { location, refId: imageName };
}
_getAssetImages(imageNames) {
return imageNames.reduce((assetImages, imageName) => {
const assetImage = this._getAssetImage(imageName);
return assetImage ? (0, common_1.push)(assetImages, assetImage) : assetImages;
}, []);
async _getAssetImages(imageNames) {
const assetImages = [];
for (const imageName of imageNames) {
const assetImage = await this._getAssetImage(imageName);
if (assetImage)
assetImages.push(assetImage);
}
return assetImages;
}

@@ -139,6 +163,6 @@ _getAssetFonts(fonts) {

}
_getAssets(source) {
async _getAssets(source) {
var _a;
const imageIds = (_a = this.getExportedComponentImageMap(source.id)) !== null && _a !== void 0 ? _a : [];
const images = this._getAssetImages(imageIds);
const images = await this._getAssetImages(imageIds);
const fonts = this._getAssetFonts(source.dependencies.fonts);

@@ -213,3 +237,3 @@ return { images, fonts };

}
_getComponent(source) {
async _getComponent(source) {
var _a, _b;

@@ -221,3 +245,3 @@ const id = (0, convert_1.convertId)(source.id);

const location = { type: 'RELATIVE', path };
const assets = this._getAssets(source);
const assets = await this._getAssets(source);
const artifacts = this._getArtifacts(source);

@@ -243,4 +267,6 @@ const role = (0, source_1.getRole)(source);

}
get components() {
return Array.from(this._exports.components.values()).map((component) => this._getComponent(component.source));
async components() {
const componentSources = Array.from(this._exports.components.values());
const converted = await Promise.all(componentSources.map((component) => this._getComponent(component.source)));
return [...converted].sort((a, b) => (0, common_1.compareStrings)(a.id, b.id));
}

@@ -255,4 +281,5 @@ async convert() {

name: this.name,
meta: this.meta,
pages: this.pages,
components: this.components,
components: await this.components(),
chunks: this.chunks,

@@ -259,0 +286,0 @@ libraries: this.libraries,

import { OctopusPath } from './octopus-path';
import type { OctopusLayer } from '../../factories/create-octopus-layer';
import type { SourceLayer } from '../../factories/create-source-layer';
import type { Octopus } from '../../typings/octopus';
import type { SourceLayerContainer } from '../source/source-layer-container';
import type { SourceLayerShape } from '../source/source-layer-shape';
import type { SourceLayerText } from '../source/source-layer-text';
import type { SourcePaint } from '../source/source-paint';
declare type SourceLayer = SourceLayerShape | SourceLayerText | SourceLayerContainer;
declare type OctopusStrokeOptions = {
sourceLayer: SourceLayer;
parentLayer: OctopusLayer;
fill: SourcePaint;
};
export declare class OctopusStroke {
protected _sourceLayer: SourceLayer;
protected _parentLayer: OctopusLayer;
private _fill;

@@ -23,8 +21,9 @@ protected _path: OctopusPath;

};
static convertStrokes(strokes: SourcePaint[], sourceLayer: SourceLayer): Octopus['VectorStroke'][];
static convertStrokes(strokes: SourcePaint[], parentLayer: OctopusLayer): Promise<Octopus['VectorStroke'][]>;
constructor(options: OctopusStrokeOptions);
get sourceLayer(): SourceLayer;
get position(): 'CENTER' | 'INSIDE' | 'OUTSIDE' | null;
get lineCap(): 'BUTT' | 'ROUND' | 'SQUARE';
get lineJoin(): 'ROUND' | 'MITER' | 'BEVEL' | null;
get fill(): Octopus['Fill'] | null;
fill(): Promise<Octopus['Fill'] | null>;
get style(): Octopus['VectorStroke']['style'];

@@ -37,4 +36,4 @@ get dashing(): number[];

get fillRule(): Octopus['FillRule'];
convert(): Octopus['VectorStroke'] | null;
convert(): Promise<Octopus['VectorStroke'] | null>;
}
export {};

@@ -18,14 +18,15 @@ "use strict";

constructor(options) {
this._sourceLayer = options.sourceLayer;
this._parentLayer = options.parentLayer;
this._fill = options.fill;
this._path = new octopus_path_1.OctopusPath({ sourceLayer: options.sourceLayer, isStroke: true });
this._path = new octopus_path_1.OctopusPath({ sourceLayer: options.parentLayer.sourceLayer, isStroke: true });
}
static convertStrokes(strokes, sourceLayer) {
return strokes.reduce((strokes, fill) => {
const stroke = new OctopusStroke({ fill, sourceLayer }).convert();
return stroke ? (0, common_1.push)(strokes, stroke) : strokes;
}, []);
static convertStrokes(strokes, parentLayer) {
const octopusStrokes = strokes.map((fill) => new OctopusStroke({ fill, parentLayer }));
return (0, common_1.getConvertedAsync)(octopusStrokes);
}
get sourceLayer() {
return this._parentLayer.sourceLayer;
}
get position() {
const strokeAlign = this._sourceLayer.strokeAlign;
const strokeAlign = this.sourceLayer.strokeAlign;
if (!OctopusStroke.STROKE_ALIGNS.includes(strokeAlign)) {

@@ -38,3 +39,3 @@ services_1.logger === null || services_1.logger === void 0 ? void 0 : services_1.logger.warn('Unknown Stroke Align', { strokeAlign });

get lineCap() {
const strokeCap = this._sourceLayer.strokeCap;
const strokeCap = this.sourceLayer.strokeCap;
const result = (0, common_1.getMapped)(strokeCap, OctopusStroke.STROKE_CAP_MAP, undefined);

@@ -48,3 +49,3 @@ if (!result) {

get lineJoin() {
const strokeJoin = this._sourceLayer.strokeJoin;
const strokeJoin = this.sourceLayer.strokeJoin;
if (!OctopusStroke.STROKE_JOINS.includes(strokeJoin)) {

@@ -56,4 +57,4 @@ services_1.logger === null || services_1.logger === void 0 ? void 0 : services_1.logger.warn('Unknown Stroke join', { strokeJoin });

}
get fill() {
return new octopus_fill_1.OctopusFill({ fill: this._fill, parentLayer: this._sourceLayer }).convert();
async fill() {
return new octopus_fill_1.OctopusFill({ fill: this._fill, parentLayer: this._parentLayer }).convert();
}

@@ -65,3 +66,3 @@ get style() {

var _a;
return (_a = this._sourceLayer.strokeDashes) !== null && _a !== void 0 ? _a : [];
return (_a = this.sourceLayer.strokeDashes) !== null && _a !== void 0 ? _a : [];
}

@@ -72,6 +73,6 @@ get visible() {

get thickness() {
return this._sourceLayer.strokeWeight;
return this.sourceLayer.strokeWeight;
}
get miterLimit() {
return this._sourceLayer.strokeMiterAngle;
return this.sourceLayer.strokeMiterAngle;
}

@@ -85,4 +86,4 @@ get path() {

}
convert() {
const fill = this.fill;
async convert() {
const fill = await this.fill();
const position = this.position;

@@ -89,0 +90,0 @@ const lineJoin = this.lineJoin;

import { SourceEntity } from './source-entity';
import type { SourceLayer } from '../../factories/create-source-layer';
import type { ImageSizeMap } from '../../services/conversion/design-converter';
import type { RawBlendMode, RawLayer } from '../../typings/raw';
import type { RawBlendMode, RawLayer, RawParentType } from '../../typings/raw';
import type { SourceBounds } from '../../typings/source';

@@ -9,3 +8,2 @@ declare type SourceComponentOptions = {

isPasteboard?: boolean;
imageSizeMap?: ImageSizeMap;
};

@@ -16,3 +14,2 @@ export declare class SourceComponent extends SourceEntity {

private _isPasteboard;
private _imageSizeMap;
static DEFAULT_ID: string;

@@ -22,6 +19,2 @@ static DEFAULT_NAME: string;

private _initializeSourceLayer;
getImageSize(ref: string | undefined): {
width: number;
height: number;
} | undefined;
private _getAssetFonts;

@@ -41,3 +34,4 @@ get dependencies(): {

get clipsContent(): boolean;
get parentType(): RawParentType | undefined;
}
export {};

@@ -19,6 +19,5 @@ "use strict";

constructor(options) {
var _a, _b;
var _a;
super(options.rawFrame);
this._isPasteboard = (_a = options.isPasteboard) !== null && _a !== void 0 ? _a : false;
this._imageSizeMap = (_b = options.imageSizeMap) !== null && _b !== void 0 ? _b : {};
this._sourceLayer = this._initializeSourceLayer(options.rawFrame);

@@ -30,5 +29,2 @@ }

}
getImageSize(ref) {
return ref ? this._imageSizeMap[ref] : undefined;
}
_getAssetFonts() {

@@ -81,2 +77,6 @@ const entries = (0, common_1.traverseAndFind)(this._rawValue, (obj) => {

}
get parentType() {
var _a;
return (_a = this._rawValue.parent) === null || _a === void 0 ? void 0 : _a.type;
}
}

@@ -83,0 +83,0 @@ SourceComponent.DEFAULT_ID = 'component-1';

@@ -5,3 +5,3 @@ import { SourceEntity } from './source-entity';

declare type SourceDesignOptions = {
raw: RawDesign;
raw?: RawDesign;
designId: string;

@@ -8,0 +8,0 @@ };

@@ -8,5 +8,5 @@ "use strict";

constructor(options) {
var _a, _b, _c, _d;
super(options.raw);
this._pages = (_d = (_c = (_b = (_a = options.raw) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.map((page) => new source_page_1.SourcePage(page))) !== null && _d !== void 0 ? _d : [];
var _a, _b, _c, _d, _e;
super((_a = options.raw) !== null && _a !== void 0 ? _a : {});
this._pages = (_e = (_d = (_c = (_b = options.raw) === null || _b === void 0 ? void 0 : _b.document) === null || _c === void 0 ? void 0 : _c.children) === null || _d === void 0 ? void 0 : _d.map((page) => new source_page_1.SourcePage(page))) !== null && _e !== void 0 ? _e : [];
this._designId = options.designId;

@@ -13,0 +13,0 @@ }

@@ -18,2 +18,3 @@ import { SourceEntity } from './source-entity';

get imageTransform(): SourceTransform | null;
get rotation(): number | undefined;
get scalingFactor(): number;

@@ -20,0 +21,0 @@ get gradientStops(): RawStop[];

@@ -34,2 +34,8 @@ "use strict";

}
get rotation() {
var _a;
const rotation = (_a = this._rawValue.rotation) !== null && _a !== void 0 ? _a : 0;
const result = (0, math_1.mod)(-rotation, 360);
return result ? result : undefined;
}
get scalingFactor() {

@@ -36,0 +42,0 @@ var _a;

@@ -6,2 +6,3 @@ import type { DesignConversionResult } from './services/conversion/design-converter';

import type { Logger } from './typings';
import type { PackageMeta } from './utils/read-pkg-meta';
import type EventEmitter from 'eventemitter3';

@@ -55,7 +56,4 @@ export declare type OctopusConverterOptions = {

private _setGlobals;
get pkg(): {
name: string;
version: string;
};
get pkg(): PackageMeta;
convertDesign(options: DesignConverterOptions): Promise<DesignConversionResult | null>;
}
import type { SourceComponent } from '../../entities/source/source-component';
import type { Octopus } from '../../typings/octopus';
import type { DesignConverter } from './design-converter';
export declare type ComponentConverterOptions = {
designConverter: DesignConverter;
source: SourceComponent;
version: string;
};
export declare class ComponentConverter {
private _designConverter;
private _source;
private _version;
constructor(options: ComponentConverterOptions);
convert(): Promise<Octopus['OctopusComponent']>;
}

@@ -7,13 +7,9 @@ "use strict";

constructor(options) {
this._designConverter = options.designConverter;
this._source = options.source;
this._version = options.version;
}
convert() {
const component = new octopus_component_1.OctopusComponent({
source: this._source,
version: this._version,
});
return component.convert();
return new octopus_component_1.OctopusComponent({ designConverter: this._designConverter, source: this._source }).convert();
}
}
exports.ComponentConverter = ComponentConverter;

@@ -5,2 +5,3 @@ import { OctopusManifest } from '../../entities/octopus/octopus-manifest';

import type { Octopus } from '../../typings/octopus';
import type { PackageMeta } from '../../utils/read-pkg-meta';
import type { ImageSize } from '../general/image-size/image-size';

@@ -46,3 +47,9 @@ export declare type ImageSizeMap = {

get id(): string;
get octopusManifest(): OctopusManifest | undefined;
get octopusManifest(): OctopusManifest;
get imageSizeMap(): ImageSizeMap;
getImageSize(ref: string | undefined): {
width: number;
height: number;
} | undefined;
get pkgMeta(): PackageMeta;
private _convertSourceComponentSafe;

@@ -49,0 +56,0 @@ private _convertSourceComponent;

@@ -36,6 +36,14 @@ "use strict";

}
get imageSizeMap() {
return this._imageSizeMap;
}
getImageSize(ref) {
return ref ? this._imageSizeMap[ref] : undefined;
}
get pkgMeta() {
return this._octopusConverter.pkg;
}
async _convertSourceComponentSafe(source) {
try {
const version = this._octopusConverter.pkg.version;
const value = await new component_converter_1.ComponentConverter({ source, version }).convert();
const value = await new component_converter_1.ComponentConverter({ source, designConverter: this }).convert();
return { value, error: null };

@@ -102,8 +110,8 @@ }

async _convertDesign(design) {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e;
const designId = design.designId;
const raw = design.design;
const sourceDesign = new source_design_1.SourceDesign({ designId, raw });
this._octopusManifest = new octopus_manifest_1.OctopusManifest({ sourceDesign, octopusConverter: this._octopusConverter });
if (sourceDesign.raw) {
this._octopusManifest = new octopus_manifest_1.OctopusManifest({ sourceDesign, octopusConverter: this._octopusConverter });
(_b = (_a = this._exporter) === null || _a === void 0 ? void 0 : _a.exportRawDesign) === null || _b === void 0 ? void 0 : _b.call(_a, sourceDesign.raw);

@@ -116,2 +124,3 @@ } // skip this for partial converts (FigmaPlugin source)

await design.content;
(_c = this.octopusManifest) === null || _c === void 0 ? void 0 : _c.finalize();
await Promise.all(this._awaitingComponents);

@@ -123,3 +132,3 @@ /** At this moment all components + dependencies should be converted and exported */

/** Trigger finalizer */
(_d = (_c = this._exporter) === null || _c === void 0 ? void 0 : _c.finalizeExport) === null || _d === void 0 ? void 0 : _d.call(_c);
(_e = (_d = this._exporter) === null || _d === void 0 ? void 0 : _d.finalizeExport) === null || _e === void 0 ? void 0 : _e.call(_d);
this._finalizeConvert.resolve();

@@ -136,3 +145,3 @@ }

(_d = this.octopusManifest) === null || _d === void 0 ? void 0 : _d.setExportedComponentImageMap(nodeId, fillIds);
const sourceComponent = new source_component_1.SourceComponent({ rawFrame, imageSizeMap: this._imageSizeMap });
const sourceComponent = new source_component_1.SourceComponent({ rawFrame });
const componentPromise = this._queue.exec(sourceComponent);

@@ -158,4 +167,4 @@ this._awaitingComponents.push(componentPromise);

this._imageSizeMap[fillName] = imageSize;
const fillPath = await ((_b = (_a = this._exporter) === null || _a === void 0 ? void 0 : _a.exportImage) === null || _b === void 0 ? void 0 : _b.call(_a, fillName, fill.buffer));
(_c = this.octopusManifest) === null || _c === void 0 ? void 0 : _c.setExportedImagePath(fillName, fillPath);
const fillPathPromise = (_b = (_a = this._exporter) === null || _a === void 0 ? void 0 : _a.exportImage) === null || _b === void 0 ? void 0 : _b.call(_a, fillName, fill.buffer);
(_c = this.octopusManifest) === null || _c === void 0 ? void 0 : _c.setExportedImagePath(fillName, fillPathPromise);
if (this._shouldReturn)

@@ -162,0 +171,0 @@ this._conversionResult.images.push({ name: fillName, data: fill.buffer });

@@ -15,4 +15,5 @@ import type { RawLayer } from '../../../typings/raw';

private _normalizeGroup;
private _normalizeTopLayerTransform;
private _normalizeLayer;
normalize(): RawLayer;
}

@@ -47,2 +47,5 @@ "use strict";

}
if (fill.type === 'IMAGE' && fill.scaleMode === 'FILL') {
fill.imageTransform = undefined; // Image with FILL scale mode don't need imageTransform and the one that we receive from plugin api is not correct
}
}

@@ -146,3 +149,13 @@ _normalizeSize(raw) {

}
_normalizeLayer(raw) {
_normalizeTopLayerTransform(raw) {
const transform = raw.type === 'BOOLEAN_OPERATION' ? DEFAULT_TRANSFORM : raw.absoluteTransform;
const [[a, c, tx], [b, d, ty]] = transform;
const { x, y } = raw.absoluteRenderBounds;
raw.relativeTransform = [
[a, c, tx - x],
[b, d, ty - y],
];
return raw;
}
_normalizeLayer(raw, isTopLayer = false) {
const { type } = raw;

@@ -167,2 +180,4 @@ this._normalizeSize(raw);

this._normalizeText(raw);
if (isTopLayer)
this._normalizeTopLayerTransform(raw);
if (isArray(raw.children))

@@ -173,5 +188,6 @@ raw.children.forEach((child) => this._normalizeLayer(child));

normalize() {
return this._normalizeLayer(this._raw);
const IS_TOP_LAYER = true;
return this._normalizeLayer(this._raw, IS_TOP_LAYER);
}
}
exports.SourceNormalizer = SourceNormalizer;

@@ -7,2 +7,3 @@ import type { RawEffect } from './effect';

export declare type RawLayerType = RawLayer['type'];
export declare type RawParentType = RawLayerContainer['type'] | 'PAGE';
export declare type RawSlice = {

@@ -20,3 +21,3 @@ id?: string;

id?: string;
type?: RawLayerContainer['type'] | 'PAGE';
type?: RawParentType;
};

@@ -23,0 +24,0 @@ export declare type RawLayerBase = {

@@ -1,4 +0,7 @@

export declare function readPackageMeta(): {
export declare type PackageMeta = {
name: string;
version: string;
manifestSpecVersion: string;
octopusSpecVersion: string;
};
export declare function readPackageMeta(): PackageMeta;

@@ -32,4 +32,6 @@ "use strict";

version: pkg.version,
manifestSpecVersion: pkg.dependencies['@opendesign/manifest-ts'],
octopusSpecVersion: pkg.dependencies['@opendesign/octopus-ts'],
};
}
exports.readPackageMeta = readPackageMeta;

@@ -10,4 +10,4 @@ import type { SourceComponent } from '../entities/source/source-component';

export declare function getGeometryFor(values?: RawGeometry[]): SourceGeometry[];
export declare function getRole(source: SourceComponent): 'ARTBOARD' | 'COMPONENT' | 'PASTEBOARD';
export declare function getRole(source: SourceComponent): 'ARTBOARD' | 'COMPONENT' | 'PASTEBOARD' | 'PARTIAL';
export declare function getColorFor(color: RawColor | undefined): SourceColor | undefined;
export declare function getTopComponentTransform(sourceLayer: SourceLayerContainer): number[] | undefined;

@@ -53,2 +53,4 @@ "use strict";

return 'COMPONENT';
if (source.parentType && source.parentType !== 'PAGE')
return 'PARTIAL';
return 'ARTBOARD';

@@ -55,0 +57,0 @@ }

{
"name": "@opendesign/octopus-fig",
"version": "3.0.0-rc.27",
"version": "3.0.0-rc.28",
"description": "Figma HTTP API format to Octopus 3+ converter.",

@@ -11,14 +11,17 @@ "license": "Apache-2.0",

"clean:workdir": "rimraf ./workdir/*",
"clean": "rimraf ./node_modules ./lib ./dist ./workdir ./test/integration/report",
"clean": "rimraf ./node_modules ./lib ./dist ./workdir ./test/**/report",
"convert:api:debug": "ts-node ./examples/node/convert-api-debug.ts",
"convert:api:local": "ts-node ./examples/node/convert-api-local.ts",
"convert:source:debug": "ts-node ./examples/node/convert-plugin-source-debug.ts",
"convert:source:local": "ts-node ./examples/node/convert-plugin-source-local.ts",
"convert:squid:debug": "ts-node ./examples/node/convert-plugin-squid-debug.ts",
"convert:squid:local": "ts-node ./examples/node/convert-plugin-squid-local.ts",
"prepack": "rimraf ./lib && yarn run build",
"test": "yarn test:unit && yarn test:integration",
"test:unit": "yarn jest",
"test:integration": "ts-node test/integration",
"test:integration:update": "yarn test:integration:update:assets && yarn test:integration:update:tests",
"test:integration:update:assets": "ts-node test/integration/update-assets.ts",
"test:integration:update:tests": "ts-node test/integration/update-tests.ts",
"test:integration": "yarn test:integration:parser && yarn test:integration:squid",
"test:integration:parser": "ts-node test/integration/figma-parser",
"test:integration:parser:update": "yarn test:integration:parser:update:assets && yarn test:integration:parser:update:tests",
"test:integration:parser:update:assets": "ts-node test/integration/figma-parser/update-assets.ts",
"test:integration:parser:update:tests": "ts-node test/integration/figma-parser/update-tests.ts",
"test:integration:squid": "ts-node test/integration/squid-plugin",
"test:integration:squid:update": "ts-node test/integration/squid-plugin/update-tests.ts",
"types:check": "tsc --noEmit",

@@ -30,5 +33,5 @@ "typedoc": "typedoc --excludePrivate src/index-node.ts src/index-web.ts",

"@opendesign/figma-parser": "3.0.0-rc.17",
"@opendesign/manifest-ts": "3.0.0-alpha.40",
"@opendesign/octopus-common": "3.0.0-rc.27",
"@opendesign/octopus-ts": "3.0.0-alpha.40",
"@opendesign/manifest-ts": "3.0.1",
"@opendesign/octopus-common": "3.0.0-rc.28",
"@opendesign/octopus-ts": "3.0.1",
"@types/lodash": "^4.14.178",

@@ -35,0 +38,0 @@ "@types/uuid": "^8.3.1",