This is the package structure:

/src    -->   main sources directory
        /src/shapes     --> All shapes are implemented here
        /src/layout     --> All layouting classes (to handle complex shapes layout)
        /src/filters    --> All filters
        /src/exeptions  --> All custom exceptinos
        /src/configuration  --> All interfaces for configuring shapes
        /src/common     --> Common util classes like Point2D
        /src/_FullInternals.ts    --> Complete library index
        /src/index-types.ts     --> Main index types for typescript package

/resources    --> Assets folder for tests
/cypress      --> Cypress home testing directory
        /cypress/integration    --> Integration tests
        
/lib          --> Mackage compiling output dir
/dist         --> Assets to distribute
CODE

Adding a new Shape

To add a new Shape to this package, follow these steps:

  • Define shape class

  • Add shape typing to /src/index-types.ts

  • Add shape constructor to /src/_FullInternals.ts

Adding shape typing

Shapes typings are defined into /src/index-types.ts. They are useful when using this package in a typescript project. Every shape has to define:

export const Barcode: typeof import('./shapes/Barcode').Barcode;
export type Barcode = import('./shapes/Barcode').Barcode;
export type BarcodeConfig = import('./shapes/Barcode').BarcodeConfig;
TYPESCRIPT

Defines typing for Barcode class and its Configuration.

If a shape is not added to typings, typescript won’t be able to detect it.

Adding shape constructor to namespace

Pamela namespace is defined into /src/_FullInternals.ts. To add a new shape, simply add it to the list:

export const Pamela = Core.Util._assign(Core, {
  Arc,
  Arrow,
  Circle,
  Ellipse,
  Image,
  // ADD HERE NEW SHAPE
  ...
}
TYPESCRIPT

If a shape is not added to namespace, typescript will be able to find it, but won’t be able to instantiate it. The error will be: <name> is not constructable.

After you add a new shape, please run npm run build to generate all newer indexes, otherwise it cannot be imported