@opendesign/octopus-fig
Advanced tools
Comparing version 3.0.0-rc.23 to 3.0.0-rc.24
{ | ||
"name": "@opendesign/octopus-fig", | ||
"version": "3.0.0-rc.23", | ||
"version": "3.0.0-rc.24", | ||
"description": "Figma HTTP API format to Octopus 3+ converter.", | ||
@@ -17,3 +17,3 @@ "license": "Apache-2.0", | ||
"prepack": "rimraf ./lib && yarn run build", | ||
"test": "yarn test:unit && yarn test:integration", | ||
"test": "yarn test:unit && yarn test:integration && yarn test:squid", | ||
"test:unit": "yarn jest", | ||
@@ -24,2 +24,4 @@ "test:integration": "ts-node test/integration", | ||
"test:integration:update:tests": "ts-node test/integration/update-tests.ts", | ||
"test:squid": "ts-node test/squid-plugin", | ||
"test:squid:update": "ts-node test/squid-plugin/update-tests.ts", | ||
"types:check": "tsc --noEmit", | ||
@@ -26,0 +28,0 @@ "typedoc": "typedoc --excludePrivate src/index-node.ts src/index-web.ts", |
@@ -208,3 +208,6 @@ "use strict"; | ||
return null; | ||
const image = { ref: { type: 'PATH', value: `images/${imageRef}.png` } }; | ||
const exportedPath = this._parentLayer.parentComponent.getImageExportedPath(imageRef); | ||
const image = exportedPath | ||
? { ref: { type: 'PATH', value: exportedPath } } | ||
: { ref: { type: 'RESOURCE_REF', value: imageRef } }; | ||
const visible = this.visible; | ||
@@ -211,0 +214,0 @@ const blendMode = this.blendMode; |
import { SourceEntity } from './source-entity'; | ||
import type { SourceLayer } from '../../factories/create-source-layer'; | ||
import type { ImageSizeMap } from '../../services/conversion/design-converter'; | ||
import type { ImageMap } from '../../services/conversion/design-converter'; | ||
import type { RawBlendMode, RawLayer } from '../../typings/raw'; | ||
@@ -9,3 +9,3 @@ import type { SourceBounds } from '../../typings/source'; | ||
isPasteboard?: boolean; | ||
imageSizeMap?: ImageSizeMap; | ||
imageSizeMap?: ImageMap; | ||
}; | ||
@@ -16,3 +16,3 @@ export declare class SourceComponent extends SourceEntity { | ||
private _isPasteboard; | ||
private _imageSizeMap; | ||
private _imageMap; | ||
static DEFAULT_ID: string; | ||
@@ -22,2 +22,3 @@ static DEFAULT_NAME: string; | ||
private _initializeSourceLayer; | ||
get imageMap(): ImageMap; | ||
getImageSize(ref: string | undefined): { | ||
@@ -27,2 +28,3 @@ width: number; | ||
} | undefined; | ||
getImageExportedPath(ref: string | undefined): string | undefined; | ||
private _getAssetFonts; | ||
@@ -29,0 +31,0 @@ get dependencies(): { |
@@ -22,3 +22,3 @@ "use strict"; | ||
this._isPasteboard = (_a = options.isPasteboard) !== null && _a !== void 0 ? _a : false; | ||
this._imageSizeMap = (_b = options.imageSizeMap) !== null && _b !== void 0 ? _b : {}; | ||
this._imageMap = (_b = options.imageSizeMap) !== null && _b !== void 0 ? _b : {}; | ||
this._sourceLayer = this._initializeSourceLayer(options.rawFrame); | ||
@@ -30,5 +30,13 @@ } | ||
} | ||
get imageMap() { | ||
return this._imageMap; | ||
} | ||
getImageSize(ref) { | ||
return ref ? this._imageSizeMap[ref] : undefined; | ||
var _a; | ||
return ref ? (_a = this.imageMap[ref]) === null || _a === void 0 ? void 0 : _a.imageSize : undefined; | ||
} | ||
getImageExportedPath(ref) { | ||
var _a; | ||
return ref ? (_a = this.imageMap[ref]) === null || _a === void 0 ? void 0 : _a.exportedPath : undefined; | ||
} | ||
_getAssetFonts() { | ||
@@ -35,0 +43,0 @@ const entries = (0, common_1.traverseAndFind)(this._rawValue, (obj) => { |
@@ -6,4 +6,7 @@ import { OctopusManifest } from '../../entities/octopus/octopus-manifest'; | ||
import type { ImageSize } from '../general/image-size/image-size'; | ||
export declare type ImageSizeMap = { | ||
[key: string]: ImageSize; | ||
export declare type ImageMap = { | ||
[key: string]: { | ||
imageSize?: ImageSize; | ||
exportedPath?: string; | ||
}; | ||
}; | ||
@@ -36,3 +39,3 @@ export declare type ComponentConversionResult = { | ||
private _shouldReturn; | ||
private _imageSizeMap; | ||
private _imageMap; | ||
private _queue; | ||
@@ -39,0 +42,0 @@ private _awaitingComponents; |
@@ -18,3 +18,3 @@ "use strict"; | ||
var _a; | ||
this._imageSizeMap = {}; | ||
this._imageMap = {}; | ||
this._awaitingComponents = []; | ||
@@ -133,3 +133,3 @@ this._conversionResult = { manifest: undefined, components: [], images: [], previews: [] }; | ||
(_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, imageSizeMap: this._imageMap }); | ||
const componentPromise = this._queue.exec(sourceComponent); | ||
@@ -148,3 +148,3 @@ this._awaitingComponents.push(componentPromise); | ||
async _convertFill(fill) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
if (typeof fill.buffer === 'string') | ||
@@ -154,6 +154,6 @@ fill.buffer = this._octopusConverter.base64ToUint8Array(fill.buffer); // @TODO investigate Buffer.buffer safety | ||
const imageSize = fill.size ? fill.size : await this._octopusConverter.imageSize(fill.buffer); | ||
if (imageSize) | ||
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 exportedPath = (_a = this._exporter) === null || _a === void 0 ? void 0 : _a.getImagePath(fillName); | ||
this._imageMap[fillName] = { imageSize, exportedPath }; | ||
const fillPath = await ((_c = (_b = this._exporter) === null || _b === void 0 ? void 0 : _b.exportImage) === null || _c === void 0 ? void 0 : _c.call(_b, fillName, fill.buffer)); | ||
(_d = this.octopusManifest) === null || _d === void 0 ? void 0 : _d.setExportedImagePath(fillName, fillPath); | ||
if (this._shouldReturn) | ||
@@ -160,0 +160,0 @@ this._conversionResult.images.push({ name: fillName, data: fill.buffer }); |
@@ -8,2 +8,3 @@ import type { Manifest } from '../../typings/manifest'; | ||
exportComponent(_result: ComponentConversionResult, _role?: Manifest['Component']['role']): Promise<string | null>; | ||
getImagePath(_name: string): string; | ||
exportImage?(_name: string, _data: ArrayBuffer): Promise<string>; | ||
@@ -10,0 +11,0 @@ exportPreview?(_name: string, _data: ArrayBuffer): Promise<string>; |
@@ -17,2 +17,5 @@ "use strict"; | ||
} | ||
getImagePath(_name) { | ||
throw new Error('Subclass of "Exporter" has no "getImagePath" method implemented!'); | ||
} | ||
exportImage(_name, _data) { | ||
@@ -19,0 +22,0 @@ throw new Error('Subclass of "Exporter" has no "exportImage" method implemented!'); |
@@ -15,4 +15,5 @@ import type { RawLayer } from '../../../typings/raw'; | ||
private _normalizeGroup; | ||
private _normalizeTopLayerTransform; | ||
private _normalizeLayer; | ||
normalize(): RawLayer; | ||
} |
@@ -145,3 +145,13 @@ "use strict"; | ||
} | ||
_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; | ||
@@ -166,2 +176,4 @@ this._normalizeSize(raw); | ||
this._normalizeText(raw); | ||
if (isTopLayer) | ||
this._normalizeTopLayerTransform(raw); | ||
if (isArray(raw.children)) | ||
@@ -172,5 +184,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; |
{ | ||
"name": "@opendesign/octopus-fig", | ||
"version": "3.0.0-rc.23", | ||
"version": "3.0.0-rc.24", | ||
"description": "Figma HTTP API format to Octopus 3+ converter.", | ||
@@ -17,3 +17,3 @@ "license": "Apache-2.0", | ||
"prepack": "rimraf ./lib && yarn run build", | ||
"test": "yarn test:unit && yarn test:integration", | ||
"test": "yarn test:unit && yarn test:integration && yarn test:squid", | ||
"test:unit": "yarn jest", | ||
@@ -24,2 +24,4 @@ "test:integration": "ts-node test/integration", | ||
"test:integration:update:tests": "ts-node test/integration/update-tests.ts", | ||
"test:squid": "ts-node test/squid-plugin", | ||
"test:squid:update": "ts-node test/squid-plugin/update-tests.ts", | ||
"types:check": "tsc --noEmit", | ||
@@ -26,0 +28,0 @@ "typedoc": "typedoc --excludePrivate src/index-node.ts src/index-web.ts", |
284557
6544