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

elk-svg

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elk-svg - npm Package Compare versions

Comparing version 2.0.0-alpha.4 to 2.0.0-alpha.5

1

dist/checker.js

@@ -8,2 +8,3 @@ export var Check;

export class Checker {
m;
constructor() {

@@ -10,0 +11,0 @@ this.m = new Map();

11

dist/components/edge.js

@@ -11,6 +11,5 @@ import { svg, transform } from "../utils";

render: (ctx, ee) => {
var _a, _b;
const arrowSize = (_b = (_a = ee.svg) === null || _a === void 0 ? void 0 : _a.arrowSize) !== null && _b !== void 0 ? _b : 8;
const arrowSize = ee.svg?.arrowSize ?? 8;
const modifiedEe = structuredClone(ee);
modifiedEe.svg = Object.assign(Object.assign({}, modifiedEe.svg), { arrowSize });
modifiedEe.svg = { ...modifiedEe.svg, arrowSize };
const af = getArrowFunction(ctx, ee);

@@ -20,7 +19,6 @@ const g = svg("g");

ee.sections.forEach((e) => {
var _a;
let lastX = e.startPoint.x;
let lastY = e.startPoint.y;
paths.push(`M ${e.startPoint.x},${e.startPoint.y}`);
(_a = e.bendPoints) === null || _a === void 0 ? void 0 : _a.forEach(({ x, y }) => {
e.bendPoints?.forEach(({ x, y }) => {
paths.push(`L ${x},${y}`);

@@ -55,4 +53,3 @@ lastX = x;

function getArrowFunction(ctx, ee) {
var _a;
const arrow = (_a = ee.svg) === null || _a === void 0 ? void 0 : _a.arrow;
const arrow = ee.svg?.arrow;
if (!arrow) {

@@ -59,0 +56,0 @@ return null;

@@ -7,8 +7,6 @@ export const nodeComponent = {

key: (ee) => {
var _a;
return `${(_a = ee.svg) === null || _a === void 0 ? void 0 : _a.shape}`;
return `${ee.svg?.shape}`;
},
render: (ctx, ee) => {
var _a;
const shape = (_a = ee.svg) === null || _a === void 0 ? void 0 : _a.shape;
const shape = ee.svg?.shape;
if (!shape) {

@@ -15,0 +13,0 @@ return null;

export class ElementRegistry {
name;
m;
constructor(name, m) {

@@ -17,4 +19,3 @@ this.name = name;

getOrNull(id) {
var _a;
return (_a = this.m.get(id)) !== null && _a !== void 0 ? _a : null;
return this.m.get(id) ?? null;
}

@@ -21,0 +22,0 @@ unset(id) {

@@ -13,23 +13,29 @@ import { defaultClassnames, defaultEdgeArrowFunctions, defaultLogger, defaultNodeShapeFunctions, } from "./defaults";

export class ElkSvg {
logger;
nodeShapeFunctions;
edgeArrowFunctions;
classnames;
defaultOptions;
groupRegistry = new ElementRegistry("group");
componentRegistry = new ElementRegistry("component");
volatileElements = [];
keyChecker = new Checker();
parentIdChecker = new Checker();
topLevelGroup;
renderContxt = {
groupRegistryForDeletion: "unreachable",
parent: null,
parentId: null,
};
idAttribute;
constructor(options) {
var _a, _b, _c, _d, _e, _f;
this.groupRegistry = new ElementRegistry("group");
this.componentRegistry = new ElementRegistry("component");
this.volatileElements = [];
this.keyChecker = new Checker();
this.parentIdChecker = new Checker();
this.renderContxt = {
groupRegistryForDeletion: "unreachable",
parent: null,
parentId: null,
};
this.nodeShapeFunctions = freezeMerge(defaultNodeShapeFunctions, options.nodeShapeFunctions);
this.edgeArrowFunctions = freezeMerge(defaultEdgeArrowFunctions, options.edgeArrowFunctions);
this.classnames = freezeMerge(defaultClassnames, options.classnames);
this.logger = (_a = options.logger) !== null && _a !== void 0 ? _a : defaultLogger;
this.logger = options.logger ?? defaultLogger;
this.defaultOptions = Object.freeze({
node: freezeMerge((_b = options.defaultOptions) === null || _b === void 0 ? void 0 : _b.node),
edge: freezeMerge((_c = options.defaultOptions) === null || _c === void 0 ? void 0 : _c.edge),
port: freezeMerge((_d = options.defaultOptions) === null || _d === void 0 ? void 0 : _d.port),
label: freezeMerge((_e = options.defaultOptions) === null || _e === void 0 ? void 0 : _e.label),
node: freezeMerge(options.defaultOptions?.node),
edge: freezeMerge(options.defaultOptions?.edge),
port: freezeMerge(options.defaultOptions?.port),
label: freezeMerge(options.defaultOptions?.label),
});

@@ -39,3 +45,3 @@ this.topLevelGroup = svg("g");

options.container.appendChild(this.topLevelGroup);
this.idAttribute = (_f = options.idAttribute) !== null && _f !== void 0 ? _f : null;
this.idAttribute = options.idAttribute ?? null;
}

@@ -54,5 +60,4 @@ getGroupElement(id) {

const cb = (node) => {
var _a, _b, _c, _d;
const g = this.renderElkElement(nodeComponent, node);
(_a = node.children) === null || _a === void 0 ? void 0 : _a.forEach((v) => {
node.children?.forEach((v) => {
this.renderContxt.parent = g;

@@ -62,17 +67,15 @@ this.renderContxt.parentId = node.id;

});
(_b = node.edges) === null || _b === void 0 ? void 0 : _b.forEach((edge) => {
var _a;
node.edges?.forEach((edge) => {
this.renderContxt.parent = g;
this.renderContxt.parentId = node.id;
this.renderElkElement(edgeComponent, edge);
(_a = edge.labels) === null || _a === void 0 ? void 0 : _a.forEach((label) => {
edge.labels?.forEach((label) => {
this.renderElkElement(labelComponent, label);
});
});
(_c = node.ports) === null || _c === void 0 ? void 0 : _c.forEach((port) => {
var _a;
node.ports?.forEach((port) => {
this.renderContxt.parent = g;
this.renderContxt.parentId = node.id;
const portG = this.renderElkElement(portComponent, port);
(_a = port.labels) === null || _a === void 0 ? void 0 : _a.forEach((label) => {
port.labels?.forEach((label) => {
this.renderContxt.parent = portG;

@@ -83,3 +86,3 @@ this.renderContxt.parentId = port.id;

});
(_d = node.labels) === null || _d === void 0 ? void 0 : _d.forEach((label) => {
node.labels?.forEach((label) => {
this.renderContxt.parent = g;

@@ -86,0 +89,0 @@ this.renderContxt.parentId = node.id;

@@ -33,4 +33,3 @@ import { svg } from "./utils";

export const roundRect = (ctx, node) => {
var _a, _b;
const r = (_b = (_a = node.svg) === null || _a === void 0 ? void 0 : _a.radius) !== null && _b !== void 0 ? _b : Math.min(node.width / 3, node.height / 3, 30);
const r = node.svg?.radius ?? Math.min(node.width / 3, node.height / 3, 30);
const e = svg("rect");

@@ -37,0 +36,0 @@ e.setAttribute("width", node.width.toString());

@@ -12,3 +12,3 @@ import type { ComponentRenderContext } from "./components/types";

edgeArrowFunctions?: Record<string, EdgeArrowFunction>;
classnames?: Classnames;
classnames?: Partial<Classnames>;
logger?: Logger;

@@ -15,0 +15,0 @@ defaultOptions?: {

@@ -11,6 +11,5 @@ export function ntos(v, suffix = "") {

export function transform(e, t) {
var _a, _b;
const r = [];
const x = (_a = t.translate) === null || _a === void 0 ? void 0 : _a.x;
const y = (_b = t.translate) === null || _b === void 0 ? void 0 : _b.y;
const x = t.translate?.x;
const y = t.translate?.y;
if (x !== undefined || y !== undefined) {

@@ -17,0 +16,0 @@ r.push(`translate(${ntos(x)} ${ntos(y)})`);

@@ -30,3 +30,3 @@ {

},
"version": "2.0.0-alpha.4"
"version": "2.0.0-alpha.5"
}

@@ -7,5 +7,5 @@ ![NPM Version](https://img.shields.io/npm/v/elk-svg)

* **Lightweight**: elk-svg is a zero-dependency library renders [ELK json format](https://eclipse.dev/elk/documentation/tooldevelopers/graphdatastructure/jsonformat.html) into SVG.
**Lightweight**: elk-svg is a zero-dependency library renders [ELK json format](https://eclipse.dev/elk/documentation/tooldevelopers/graphdatastructure/jsonformat.html) into SVG.
* **Customizable**: There is no additional abstraction layer. You can do whatever if SVG supports it.
**Customizable**: There is no additional abstraction layer. You can do whatever if SVG supports it.
`elk-svg` manages internal state and modifies DOM only if necessary: it means CSS animation will works well.

@@ -12,0 +12,0 @@

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