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

ferns

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ferns - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

2

dist/dom/sizing.js

@@ -10,3 +10,3 @@ "use strict";

let width = options.maxWidth;
const treeWidth = trees.reduce((acc, tree) => acc + tree_1.computeWidth(ctx, options.style, tree) + tree_1.HORIZONTAL_TREE_SPACING, -tree_1.HORIZONTAL_TREE_SPACING);
const treeWidth = trees.reduce((acc, tree) => acc + tree_1.computeWidth(ctx, options.style, tree)[0] + tree_1.HORIZONTAL_TREE_SPACING, -tree_1.HORIZONTAL_TREE_SPACING);
const totalWidth = Math.max(MIN_TREE_WIDTH, treeWidth);

@@ -13,0 +13,0 @@ const idealHeight = (width / totalWidth) * treeHeight;

import { TreeStyle } from "../design/style";
import { ProjectedRenderingContext2D } from "./viewport/projected-context";
export declare const CHILDREN_VERTICAL_SPACING: number;
export declare function drawArrow(ctx: ProjectedRenderingContext2D, style: TreeStyle, fromX: number, fromY: number, toX: number[], toY: number, label?: string): void;
export declare function drawArrow(ctx: ProjectedRenderingContext2D, style: TreeStyle, fromX: number, fromY: number, toX: number[], toY: number, straightLine: boolean, label?: string): void;

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

exports.CHILDREN_VERTICAL_SPACING = ARROW_TOP_HEIGHT + ARROW_LABEL_HEIGHT + ARROW_BOTTOM_HEIGHT;
function drawArrow(ctx, style, fromX, fromY, toX, toY, label) {
const centerX = toX[0] + (toX[toX.length - 1] - toX[0]) / 2;
function drawArrow(ctx, style, fromX, fromY, toX, toY, straightLine, label) {
const centerX = straightLine
? fromX
: toX[0] + (toX[toX.length - 1] - toX[0]) / 2;
ctx.set({

@@ -24,0 +26,0 @@ lineJoin: "bevel",

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

const ATTRIBUTE_FONT_SIZE = 18;
const TEXT_HORIZONTAL_PADDING = 8;
const TEXT_HORIZONTAL_PADDING = 16;
/**

@@ -41,3 +41,3 @@ * Draws a particular node and returns its height.

function computeNodeWidth(ctx, style, node) {
const label = node.label || node.type.toUpperCase();
const label = node.label || node.type;
const attributes = node.attributes || [];

@@ -44,0 +44,0 @@ const labelMinWidth = text_1.measureText(ctx, style.fontFamily, TYPE_LABEL_FONT_SIZE, label) +

@@ -135,2 +135,27 @@ "use strict";

});
it("aligns large and small nodes correctly", () => {
const rendered = renderCanvas(`
block
--instructions-->
block
--instructions-->
variable declaration
id = 100
name = a
assignment
id = 100
--value-->
1
block
--instructions-->
variable declaration
id = 100
name = a
assignment
id = 100
--value-->
2
`);
expect(rendered).toMatchImageSnapshot();
});
});

@@ -137,0 +162,0 @@ function renderCanvas(code, style) {

@@ -10,3 +10,3 @@ import { Node } from "../data/tree-node";

export declare function drawTree(ctx: ProjectedRenderingContext2D, style: TreeStyle, x: number, y: number, tree: Node): number;
export declare function computeWidth(ctx: CanvasRenderingContext2D, style: TreeStyle, tree: Node): number;
export declare function computeWidth(ctx: CanvasRenderingContext2D, style: TreeStyle, tree: Node): [totalWidth: number, childrenShift: number];
export declare function computeHeight(tree: Node): number;

@@ -12,3 +12,4 @@ "use strict";

function drawTree(ctx, style, x, y, tree) {
const allocatedWidth = computeWidth(ctx.rawContext, style, tree);
var _a;
const [allocatedWidth, childrenShift] = computeWidth(ctx.rawContext, style, tree);
const [nodeWidth] = node_1.computeNodeWidth(ctx.rawContext, style, tree);

@@ -18,3 +19,3 @@ const nodeX = x + (allocatedWidth - nodeWidth) / 2;

let childrenY = y + height + arrow_1.CHILDREN_VERTICAL_SPACING;
let nextChildX = x;
let nextChildX = x + childrenShift;
for (const group of tree.children || []) {

@@ -28,3 +29,3 @@ const childrenX = [];

if (childrenX.length > 0) {
arrow_1.drawArrow(ctx, style, nodeX + nodeWidth / 2, y + height, childrenX, childrenY, group.label);
arrow_1.drawArrow(ctx, style, nodeX + nodeWidth / 2, y + height, childrenX, childrenY, ((_a = tree.children) === null || _a === void 0 ? void 0 : _a.length) === 1, group.label);
}

@@ -38,3 +39,5 @@ }

const [nodeWidth] = node_1.computeNodeWidth(ctx, style, tree);
return Math.max(nodeWidth, allChildren.reduce((acc, child) => acc + computeWidth(ctx, style, child) + exports.HORIZONTAL_NODE_SPACING, -exports.HORIZONTAL_NODE_SPACING));
const childrenWidth = allChildren.reduce((acc, child) => acc + computeWidth(ctx, style, child)[0] + exports.HORIZONTAL_NODE_SPACING, -exports.HORIZONTAL_NODE_SPACING);
const totalWidth = Math.max(nodeWidth, childrenWidth);
return [totalWidth, (totalWidth - childrenWidth) / 2];
}

@@ -41,0 +44,0 @@ exports.computeWidth = computeWidth;

{
"name": "ferns",
"version": "0.0.14",
"version": "0.0.15",
"author": "Francois Wouts",

@@ -5,0 +5,0 @@ "license": "MIT",

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