@opendesign/octopus-fig
Advanced tools
Comparing version 3.0.0-rc.35 to 3.0.0-rc.36
{ | ||
"name": "@opendesign/octopus-fig", | ||
"version": "3.0.0-rc.35", | ||
"version": "3.0.0-rc.36", | ||
"description": "Figma HTTP API format to Octopus 3+ converter.", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -16,3 +16,2 @@ "use strict"; | ||
const convert_1 = require("../../utils/convert"); | ||
const defaults_1 = require("../../utils/defaults"); | ||
const octopus_component_1 = require("./octopus-component"); | ||
@@ -53,7 +52,12 @@ const octopus_effect_1 = require("./octopus-effect"); | ||
const { isFrameLike } = this._sourceLayer; | ||
return (0, convert_1.convertLayerBlendMode)(this._sourceLayer.blendMode, { isFrameLike }); | ||
const blendMode = (0, convert_1.convertLayerBlendMode)(this._sourceLayer.blendMode, { isFrameLike }); | ||
if (blendMode === 'PASS_THROUGH') { | ||
const hasBlur = this._sourceLayer.effects.some((effect) => effect.type === 'LAYER_BLUR'); | ||
if (hasBlur) | ||
return 'NORMAL'; // https://github.com/opendesigndev/open-design-engine/issues/11 | ||
} | ||
return blendMode; | ||
} | ||
get transform() { | ||
var _a; | ||
return (_a = this.sourceLayer.transform) !== null && _a !== void 0 ? _a : defaults_1.DEFAULTS.TRANSFORM; | ||
return (0, convert_1.convertTransform)(this.sourceLayer.transform); | ||
} | ||
@@ -60,0 +64,0 @@ get opacity() { |
@@ -7,2 +7,3 @@ "use strict"; | ||
const services_1 = require("../../services"); | ||
const convert_1 = require("../../utils/convert"); | ||
const defaults_1 = require("../../utils/defaults"); | ||
@@ -21,3 +22,3 @@ const misc_1 = require("../../utils/misc"); | ||
get transform() { | ||
var _a, _b; | ||
var _a; | ||
if (this.isTopLayer) | ||
@@ -27,3 +28,3 @@ return services_1.env.NODE_ENV === 'debug' // TODO remove when ISSUE is fixed https://gitlab.avcd.cz/opendesign/open-design-engine/-/issues/21 | ||
: defaults_1.DEFAULTS.TRANSFORM; | ||
return (_b = this.sourceLayer.transform) !== null && _b !== void 0 ? _b : defaults_1.DEFAULTS.TRANSFORM; | ||
return (0, convert_1.convertTransform)(this.sourceLayer.transform); | ||
} | ||
@@ -30,0 +31,0 @@ get meta() { |
@@ -41,7 +41,7 @@ "use strict"; | ||
static createBackgroundMaskGroup({ sourceLayer, parent, }) { | ||
var _a, _b; | ||
var _a; | ||
const id = `${sourceLayer.id}-Background`; | ||
const isTopLayer = parent instanceof octopus_component_1.OctopusComponent; | ||
const topComponentTransform = isTopLayer && services_1.env.NODE_ENV === 'debug' ? (0, source_1.getTopComponentTransform)(sourceLayer) : undefined; // TODO remove when ISSUE is fixed https://gitlab.avcd.cz/opendesign/open-design-engine/-/issues/21 | ||
const transform = isTopLayer ? topComponentTransform : (_a = sourceLayer.transform) !== null && _a !== void 0 ? _a : undefined; | ||
const transform = isTopLayer ? topComponentTransform : (0, convert_1.convertTransform)(sourceLayer.transform); | ||
const mask = OctopusLayerMaskGroup.createBackgroundLayer(sourceLayer, parent); | ||
@@ -52,3 +52,3 @@ if (!mask) | ||
const { visible, blendMode, opacity, name, isArtboard } = sourceLayer; | ||
const boundingBox = (_b = sourceLayer.boundingBox) !== null && _b !== void 0 ? _b : undefined; | ||
const boundingBox = (_a = sourceLayer.boundingBox) !== null && _a !== void 0 ? _a : undefined; | ||
const maskLayer = new OctopusLayerMaskGroup({ | ||
@@ -55,0 +55,0 @@ id, |
@@ -39,4 +39,5 @@ "use strict"; | ||
_transform({ sourceLayer, isTopLayer }) { | ||
var _a; | ||
return isTopLayer ? defaults_1.DEFAULTS.TRANSFORM : (_a = sourceLayer.transform) !== null && _a !== void 0 ? _a : defaults_1.DEFAULTS.TRANSFORM; | ||
if (isTopLayer) | ||
return defaults_1.DEFAULTS.TRANSFORM; | ||
return (0, convert_1.convertTransform)(sourceLayer.transform); | ||
} | ||
@@ -46,3 +47,4 @@ _geometries(sourceLayer) { | ||
return sourceLayer.strokeGeometry; | ||
return sourceLayer.fillGeometry.length ? sourceLayer.fillGeometry : sourceLayer.strokeGeometry; | ||
const isFillGeometry = sourceLayer.fills.length && sourceLayer.fillGeometry.length; | ||
return isFillGeometry ? sourceLayer.fillGeometry : sourceLayer.strokeGeometry; | ||
} | ||
@@ -59,2 +61,4 @@ _firstGeometry(sourceLayer) { | ||
_isRectangle(sourceLayer) { | ||
if (sourceLayer.parent.type === 'SHAPE' && sourceLayer.parent.shapeType === 'BOOLEAN_OPERATION') | ||
return false; // issue with rectangles inside boolean operations, act as they are just Path | ||
return sourceLayer.shapeType === 'RECTANGLE' && !sourceLayer.cornerRadii; | ||
@@ -61,0 +65,0 @@ } |
@@ -27,2 +27,3 @@ import { SourceEntity } from './source-entity'; | ||
get name(): string; | ||
get type(): 'SOURCE_COMPONENT'; | ||
get isPasteboard(): boolean; | ||
@@ -29,0 +30,0 @@ get opacity(): number; |
@@ -61,2 +61,5 @@ "use strict"; | ||
} | ||
get type() { | ||
return 'SOURCE_COMPONENT'; | ||
} | ||
get isPasteboard() { | ||
@@ -63,0 +66,0 @@ return this._isPasteboard; |
@@ -33,3 +33,3 @@ "use strict"; | ||
var _a; | ||
return (_a = this._rawValue.clipsContent) !== null && _a !== void 0 ? _a : true; | ||
return (_a = this._rawValue.clipsContent) !== null && _a !== void 0 ? _a : false; | ||
} | ||
@@ -36,0 +36,0 @@ get layers() { |
@@ -9,2 +9,5 @@ "use strict"; | ||
const max_1 = __importDefault(require("lodash/max")); | ||
const paper_1 = require("../../../utils/paper"); | ||
const source_1 = require("../../../utils/source"); | ||
const utils_1 = require("./utils"); | ||
const DEFAULT_TRANSFORM = [ | ||
@@ -15,3 +18,2 @@ [1, 0, 0], | ||
const isArray = Array.isArray; | ||
const isNumber = (value) => typeof value === 'number'; | ||
class SourceNormalizer { | ||
@@ -27,13 +29,11 @@ constructor(raw) { | ||
} | ||
_normalizeChildTransform(layer, subTx, subTy) { | ||
var _e; | ||
const [[a, c, tx], [b, d, ty]] = (_e = layer.relativeTransform) !== null && _e !== void 0 ? _e : [[], []]; | ||
if (!isNumber(tx) || !isNumber(ty)) | ||
_normalizeChildTransform(layer, parentTransform) { | ||
const relativeTransform = (0, source_1.getTransformFor)(layer.relativeTransform); | ||
const parentSourceTransform = (0, source_1.getTransformFor)(parentTransform); | ||
if (!relativeTransform || !parentSourceTransform) | ||
return layer; | ||
layer.relativeTransform = [ | ||
[a, c, tx - subTx], | ||
[b, d, ty - subTy], | ||
]; | ||
const resultTransform = (0, paper_1.createMatrix)(parentSourceTransform).invert().append((0, paper_1.createMatrix)(relativeTransform)).values; | ||
layer.relativeTransform = (0, utils_1.convertToRawTransform)(resultTransform); | ||
if (layer.type === 'GROUP' && isArray(layer.children)) { | ||
layer.children.forEach((child) => this._normalizeChildTransform(child, subTx, subTy)); | ||
layer.children.forEach((child) => this._normalizeChildTransform(child, parentTransform)); | ||
} | ||
@@ -145,5 +145,4 @@ return layer; | ||
_normalizeGroup(raw) { | ||
const [[_a, _c, tx], [_b, _d, ty]] = raw.relativeTransform; | ||
if (isArray(raw.children) && isNumber(tx) && isNumber(ty)) { | ||
raw.children.forEach((child) => this._normalizeChildTransform(child, tx, ty)); | ||
if (isArray(raw.children) && isArray(raw.relativeTransform)) { | ||
raw.children.forEach((child) => this._normalizeChildTransform(child, raw.relativeTransform)); | ||
} | ||
@@ -150,0 +149,0 @@ return raw; |
@@ -0,1 +1,3 @@ | ||
import type { RawTransform } from '../../../typings/raw'; | ||
export declare function isBase64(data: string): boolean; | ||
export declare function convertToRawTransform([a, b, c, d, tx, ty]: number[]): RawTransform; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isBase64 = void 0; | ||
exports.convertToRawTransform = exports.isBase64 = void 0; | ||
function isBase64(data) { | ||
@@ -9,1 +9,8 @@ const regex = /^[a-zA-Z0-9+/]*={0,2}$/; | ||
exports.isBase64 = isBase64; | ||
function convertToRawTransform([a, b, c, d, tx, ty]) { | ||
return [ | ||
[a, c, tx], | ||
[b, d, ty], | ||
]; | ||
} | ||
exports.convertToRawTransform = convertToRawTransform; |
@@ -29,2 +29,3 @@ import type { StyledTextSegment } from './plugin-api'; | ||
name?: string; | ||
fileKey?: string; | ||
}; | ||
@@ -31,0 +32,0 @@ export declare type PluginSourceCurrentPage = { |
@@ -12,4 +12,5 @@ import type { Octopus } from '../typings/octopus'; | ||
export declare function convertRectangle({ x, y }: SourceVector): Octopus['Rectangle']; | ||
export declare function convertTransform(transform: number[] | null): number[]; | ||
export declare function convertLinearGradientTransform(gradientTransform: SourceTransform, width: number, height: number): number[]; | ||
export declare function convertRadialGradientTransform(gradientTransform: SourceTransform, width: number, height: number): number[]; | ||
export declare function convertGradientPositions(positions: SourceGradientPositions | null, width: number, height: number): number[] | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertGradientPositions = exports.convertRadialGradientTransform = exports.convertLinearGradientTransform = exports.convertRectangle = exports.convertStop = exports.convertColor = exports.convertLayerBlendMode = exports.convertBlendMode = exports.convertId = void 0; | ||
exports.convertGradientPositions = exports.convertRadialGradientTransform = exports.convertLinearGradientTransform = exports.convertTransform = exports.convertRectangle = exports.convertStop = exports.convertColor = exports.convertLayerBlendMode = exports.convertBlendMode = exports.convertId = void 0; | ||
const as_1 = require("@opendesign/octopus-common/dist/utils/as"); | ||
@@ -66,2 +66,8 @@ const math_1 = require("@opendesign/octopus-common/dist/utils/math"); | ||
exports.convertRectangle = convertRectangle; | ||
function convertTransform(transform) { | ||
if (!transform) | ||
return defaults_1.DEFAULTS.TRANSFORM; | ||
return transform.map((value) => (0, math_1.round)(value, 4)); | ||
} | ||
exports.convertTransform = convertTransform; | ||
function convertLinearGradientTransform(gradientTransform, width, height) { | ||
@@ -68,0 +74,0 @@ return (0, paper_1.createMatrix)(gradientTransform) |
{ | ||
"name": "@opendesign/octopus-fig", | ||
"version": "3.0.0-rc.35", | ||
"version": "3.0.0-rc.36", | ||
"description": "Figma HTTP API format to Octopus 3+ converter.", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
300520
6875