@leapfrog/interactive-canvas 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/dimensions/pixel-canvas-dimensions.d.ts +13 -0
  2. package/dist/dimensions/print-6-col-canvas-dimensions.d.ts +18 -0
  3. package/dist/dimensions/print-8-col-canvas-dimensions.d.ts +18 -0
  4. package/dist/font/font-library.d.ts +22 -0
  5. package/dist/font/font-library.interface.d.ts +20 -0
  6. package/dist/font/font.interface.d.ts +20 -0
  7. package/dist/font/unknown-font.d.ts +6 -0
  8. package/dist/index.d.ts +47 -0
  9. package/dist/interactive-canvas.impl.d.ts +305 -0
  10. package/dist/interactive-canvas.interface.d.ts +221 -0
  11. package/dist/interactive-canvas.js +34 -0
  12. package/dist/interactive-canvas.js.map +1 -0
  13. package/dist/interactive-canvas.nomin.js +57456 -0
  14. package/dist/layout/abstract-layout-manager.d.ts +18 -0
  15. package/dist/layout/advanced-layout-manager.d.ts +15 -0
  16. package/dist/layout/function/pin-to-bottom.layout-function.d.ts +4 -0
  17. package/dist/layout/function/redraw-all.layout-function.d.ts +4 -0
  18. package/dist/layout/function/reposition-borders.layout-function.d.ts +4 -0
  19. package/dist/layout/function/reposition-cutoffs.layout-function.d.ts +4 -0
  20. package/dist/layout/function/resize-canvas.layout-function.d.ts +4 -0
  21. package/dist/layout/function/stack-objects.layout-function.d.ts +11 -0
  22. package/dist/layout/function/update-object-dimensions.layout-function.d.ts +4 -0
  23. package/dist/layout/layout-manager.enum.d.ts +5 -0
  24. package/dist/layout/layout-manager.interface.d.ts +13 -0
  25. package/dist/layout/standard-layout-manager.d.ts +36 -0
  26. package/dist/mutator/mutable-background-color.interface.d.ts +15 -0
  27. package/dist/mutator/mutable-color.interface.d.ts +6 -0
  28. package/dist/mutator/mutable-image.interface.d.ts +28 -0
  29. package/dist/mutator/mutable-position.interface.d.ts +33 -0
  30. package/dist/mutator/mutable-text-style.interface.d.ts +149 -0
  31. package/dist/mutator/mutable-text.interface.d.ts +40 -0
  32. package/dist/object/abstract-canvas-object.d.ts +155 -0
  33. package/dist/object/canvas-object-data.d.ts +23 -0
  34. package/dist/object/canvas-object.interface.d.ts +96 -0
  35. package/dist/object/impl/border.d.ts +60 -0
  36. package/dist/object/impl/cutoff.d.ts +60 -0
  37. package/dist/object/impl/horizontal-rule.d.ts +89 -0
  38. package/dist/object/impl/image.d.ts +82 -0
  39. package/dist/object/impl/rectangle.d.ts +59 -0
  40. package/dist/object/impl/text.d.ts +255 -0
  41. package/dist/object/impl/vertical-rule.d.ts +89 -0
  42. package/dist/profile/canvas-profile.interface.d.ts +22 -0
  43. package/dist/profile/default-canvas-profile.d.ts +23 -0
  44. package/dist/types/canvas-dimension-restrictions.interface.d.ts +14 -0
  45. package/dist/types/canvas-dimensions.interface.d.ts +21 -0
  46. package/dist/types/canvas-state.interface.d.ts +11 -0
  47. package/dist/types/dimension-restrictions.interface.d.ts +6 -0
  48. package/dist/types/image-type.enum.d.ts +6 -0
  49. package/dist/types/margin.interface.d.ts +6 -0
  50. package/dist/types/object-dimensions.interface.d.ts +23 -0
  51. package/dist/types/object-type.enum.d.ts +10 -0
  52. package/dist/types/overflow.interface.d.ts +4 -0
  53. package/dist/types/position.interface.d.ts +6 -0
  54. package/dist/types/rect.interface.d.ts +6 -0
  55. package/dist/types/selection-data.interface.d.ts +19 -0
  56. package/dist/types/text-alignment.interface.d.ts +1 -0
  57. package/package.json +32 -0
  58. package/readme.md +43 -0
@@ -0,0 +1,89 @@
1
+ import { Observable } from "rxjs";
2
+ import { ICanvasObject } from "../canvas-object.interface";
3
+ import { IMutableColor, IMutablePosition } from "../..";
4
+ import { AbstractCanvasObject } from "../abstract-canvas-object";
5
+ import { CanvasObjectData } from "../canvas-object-data";
6
+ import { InteractiveCanvas } from "../../interactive-canvas.impl";
7
+ import { fabric } from "fabric";
8
+ /**
9
+ * Vertical rule. A basic block of color that spans the canvas/row height.
10
+ */
11
+ export interface IVerticalRule extends ICanvasObject, IMutableColor, IMutablePosition {
12
+ /**
13
+ * Get the width of the rule.
14
+ */
15
+ getStrokeWidth(): number;
16
+ /**
17
+ * Get an observable of the width of the rule.
18
+ */
19
+ getStrokeWidth$(): Observable<number>;
20
+ /**
21
+ * Set the rule width.
22
+ * @param width New width.
23
+ */
24
+ setStrokeWidth(width: number): void;
25
+ }
26
+ export declare class VerticalRule extends AbstractCanvasObject<fabric.Rect> implements IVerticalRule {
27
+ private readonly strokeWidth$;
28
+ constructor(canvas: InteractiveCanvas, fabricObject: fabric.Rect, persistedField?: CanvasObjectData);
29
+ /**
30
+ * @override
31
+ * @inheritDoc
32
+ */
33
+ getStrokeWidth(): number;
34
+ /**
35
+ * @override
36
+ * @inheritDoc
37
+ */
38
+ getStrokeWidth$(): Observable<number>;
39
+ /**
40
+ * @override
41
+ * @inheritDoc
42
+ */
43
+ setStrokeWidth(width: number): void;
44
+ /**
45
+ * @override
46
+ * @inheritDoc
47
+ */
48
+ getColor(): string;
49
+ /**
50
+ * @override
51
+ * @inheritDoc
52
+ */
53
+ setColor(color: string): void;
54
+ /**
55
+ * @override
56
+ * @inheritDoc
57
+ */
58
+ centerHorizontally(): void;
59
+ /**
60
+ * @override
61
+ * @inheritDoc
62
+ */
63
+ centerVertically(): void;
64
+ /**
65
+ * @override
66
+ * @inheritDoc
67
+ */
68
+ setHeight(height: number): void;
69
+ /**
70
+ * @override
71
+ * @inheritDoc
72
+ */
73
+ nudgeUp(): void;
74
+ /**
75
+ * @override
76
+ * @inheritDoc
77
+ */
78
+ nudgeDown(): void;
79
+ /**
80
+ * @override
81
+ * @inheritDoc
82
+ */
83
+ nudgeLeft(): void;
84
+ /**
85
+ * @override
86
+ * @inheritDoc
87
+ */
88
+ nudgeRight(): void;
89
+ }
@@ -0,0 +1,22 @@
1
+ import { TextAlignment } from "..";
2
+ /**
3
+ * Defines the set of behaviors that can be adjusted on the interactive canvas, and provides an interface for grouping feature settings into a reusable profile.
4
+ */
5
+ export interface ICanvasProfile {
6
+ readonly allowMultiSelect: boolean;
7
+ readonly allowObjectsToLeaveCanvas: boolean;
8
+ readonly enterTextEditImmediatelyOnSelect: boolean;
9
+ readonly allowMove: boolean;
10
+ readonly allowRotate: boolean;
11
+ readonly allowScale: boolean;
12
+ readonly defaultFont?: string;
13
+ readonly defaultFontSize: number;
14
+ readonly defaultFontColor: string;
15
+ readonly defaultLineHeight: number;
16
+ readonly defaultCharacterSpacing: number;
17
+ readonly defaultTextAlignment: TextAlignment;
18
+ readonly defaultBorderColor: string;
19
+ readonly defaultBorderWidth: number;
20
+ readonly defaultCutoffColor: string;
21
+ readonly defaultCutoffWidth: number;
22
+ }
@@ -0,0 +1,23 @@
1
+ import { TextAlignment } from "..";
2
+ import { ICanvasProfile } from "./canvas-profile.interface";
3
+ /**
4
+ * Profile with as many features disabled as possible.
5
+ */
6
+ export declare class DefaultCanvasProfile implements ICanvasProfile {
7
+ readonly allowMultiSelect: boolean;
8
+ readonly enterTextEditImmediatelyOnSelect: boolean;
9
+ readonly allowObjectsToLeaveCanvas: boolean;
10
+ readonly allowMove: boolean;
11
+ readonly allowRotate: boolean;
12
+ readonly allowScale: boolean;
13
+ readonly defaultFont?: string;
14
+ readonly defaultFontSize: number;
15
+ readonly defaultFontColor: string;
16
+ readonly defaultLineHeight: number;
17
+ readonly defaultCharacterSpacing: number;
18
+ readonly defaultTextAlignment: TextAlignment;
19
+ readonly defaultBorderColor: string;
20
+ readonly defaultBorderWidth: number;
21
+ readonly defaultCutoffColor: string;
22
+ readonly defaultCutoffWidth: number;
23
+ }
@@ -0,0 +1,14 @@
1
+ export interface ICanvasDimensionRestrictions {
2
+ readonly width?: {
3
+ min?: number;
4
+ max?: number;
5
+ };
6
+ readonly height?: {
7
+ min?: number;
8
+ max?: number;
9
+ };
10
+ readonly volume?: {
11
+ min?: number;
12
+ max?: number;
13
+ };
14
+ }
@@ -0,0 +1,21 @@
1
+ export interface ICanvasDimensions {
2
+ readonly width: number;
3
+ readonly widthPx: number;
4
+ readonly widthMm?: number;
5
+ readonly widthUnit: string;
6
+ readonly height: number;
7
+ readonly heightPx: number;
8
+ readonly heightMm?: number;
9
+ readonly heightUnit: string;
10
+ withSize(width: number, height: number): ICanvasDimensions;
11
+ /**
12
+ * Convert a number of pixels on the width to millimeters.
13
+ * @param px Pixel count.
14
+ */
15
+ widthPxToMm(px: number): number | undefined;
16
+ /**
17
+ * Convert a number of pixels on the height to millimeters.
18
+ * @param px Pixel count.
19
+ */
20
+ heightPxToMm(px: number): number | undefined;
21
+ }
@@ -0,0 +1,11 @@
1
+ import { ICanvasDimensions } from "./canvas-dimensions.interface";
2
+ import { CanvasObjectData } from "..";
3
+ /**
4
+ * Serialized canvas state that can be used to save the canvas.
5
+ */
6
+ export interface ICanvasState {
7
+ readonly dimensions: ICanvasDimensions;
8
+ readonly canvasJson: string;
9
+ readonly objects: CanvasObjectData[];
10
+ readonly backgroundColor?: string;
11
+ }
@@ -0,0 +1,6 @@
1
+ export interface IDimensionRestrictions {
2
+ minWidth: number;
3
+ minHeight: number;
4
+ maxWidth?: number;
5
+ maxHeight?: number;
6
+ }
@@ -0,0 +1,6 @@
1
+ export declare enum ImageType {
2
+ DEFAULT = "DEFAULT",
3
+ BACKGROUND = "BACKGROUND",
4
+ LOGO = "LOGO",
5
+ PHOTO = "PHOTO"
6
+ }
@@ -0,0 +1,6 @@
1
+ export interface IMargin {
2
+ top?: number | null;
3
+ right?: number | null;
4
+ bottom?: number | null;
5
+ left?: number | null;
6
+ }
@@ -0,0 +1,23 @@
1
+ export interface IObjectDimensions {
2
+ readonly top: {
3
+ readonly px: number;
4
+ readonly mm: number;
5
+ };
6
+ readonly left: {
7
+ readonly px: number;
8
+ readonly mm: number;
9
+ };
10
+ readonly width: {
11
+ readonly px: number;
12
+ readonly mm: number;
13
+ };
14
+ readonly height: {
15
+ readonly px: number;
16
+ readonly mm: number;
17
+ };
18
+ readonly angle: number;
19
+ readonly scale: {
20
+ readonly x: number;
21
+ readonly y: number;
22
+ };
23
+ }
@@ -0,0 +1,10 @@
1
+ export declare enum ObjectType {
2
+ TEXT = "TEXT",
3
+ BORDER = "BORDER",
4
+ IMAGE = "IMAGE",
5
+ RECTANGLE = "RECTANGLE",
6
+ LIBRARY_IMAGE = "LIBRARY_IMAGE",
7
+ CUTOFF = "CUTOFF",
8
+ VERTICAL_RULE = "VERTICAL_RULE",
9
+ HORIZONTAL_RULE = "HORIZONTAL_RULE"
10
+ }
@@ -0,0 +1,4 @@
1
+ import { IRect } from "./rect.interface";
2
+ export interface IOverflow extends IRect {
3
+ readonly hasOverflow: boolean;
4
+ }
@@ -0,0 +1,6 @@
1
+ export interface IPosition {
2
+ readonly top?: number;
3
+ readonly left?: number;
4
+ readonly width?: number;
5
+ readonly height?: number;
6
+ }
@@ -0,0 +1,6 @@
1
+ export interface IRect {
2
+ readonly top: number;
3
+ readonly right: number;
4
+ readonly bottom: number;
5
+ readonly left: number;
6
+ }
@@ -0,0 +1,19 @@
1
+ import { ICanvasObject, ITextSelection } from "..";
2
+ export interface ISelectionData {
3
+ /**
4
+ * The currently selected fields.
5
+ */
6
+ readonly objects: ICanvasObject[];
7
+ /**
8
+ * True if there is nothing selected.
9
+ */
10
+ readonly empty: boolean;
11
+ /**
12
+ * True if text is currently being edited.
13
+ */
14
+ readonly isText: boolean;
15
+ /**
16
+ * Text selection data.
17
+ */
18
+ readonly textSelection: ITextSelection | null;
19
+ }
@@ -0,0 +1 @@
1
+ export declare type TextAlignment = "left" | "center" | "right" | "justify";
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@leapfrog/interactive-canvas",
3
+ "version": "0.1.0",
4
+ "description": "Leapfrog interactive canvas",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "types": "dist/index.d.ts",
9
+ "main": "dist/interactive-canvas.js",
10
+ "scripts": {
11
+ "build": "webpack --mode=production",
12
+ "watch": "webpack --mode=production --watch"
13
+ },
14
+ "devDependencies": {
15
+ "@types/fabric": "^3.6.5",
16
+ "@types/lodash": "^4.14.153",
17
+ "clean-webpack-plugin": "^3.0.0",
18
+ "ts-loader": "^6.0.4",
19
+ "typescript": "^3.5.3",
20
+ "unminified-webpack-plugin": "^2.0.0",
21
+ "webpack": "^4.39.3",
22
+ "webpack-cli": "^3.3.7"
23
+ },
24
+ "dependencies": {
25
+ "fabric": "^3.6.3",
26
+ "lodash": "^4.17.15",
27
+ "rxjs": "^6.5.5",
28
+ "ts-optchain": "^0.1.8"
29
+ },
30
+ "author": "",
31
+ "license": "UNLICENSED"
32
+ }
package/readme.md ADDED
@@ -0,0 +1,43 @@
1
+ # Leapfrog Interactive Canvas #
2
+
3
+ A set of APIs wrapping the fabric.js library, providing Leapfrog-specific behavior and interactions.
4
+
5
+ ### Building
6
+ npm run build
7
+
8
+ or
9
+
10
+ npm run watch
11
+
12
+ ### Using library in another Project
13
+ `npm install @leapfrog/interactive-canvas`
14
+
15
+ ### Linking for local development
16
+
17
+ You can use `npm link` to see changes to the library immediately in a linked project.
18
+
19
+ Add the following lines to the `package.json` `scripts` config in the project that uses this library:
20
+ ```json
21
+ {
22
+ "scripts": {
23
+ "link:lic": "npm link @leapfrog/interactive-canvas",
24
+ "upgrade:lic": "npm install @leapfrog/interactive-canvas@latest"
25
+ }
26
+ }
27
+ ```
28
+
29
+ * In this project: `npm link`
30
+ * In the calling project: `npm run link:lic`
31
+ * In this project: `npm run watch`
32
+
33
+ Changes in the library will be visible in the calling project.
34
+
35
+ Once complete, publish the changes then run `npm run upgrade:lic` to get the latest published version of the
36
+ library in the calling project.
37
+
38
+ ### Publishing
39
+ The `.npmrc` file contains the access token needed to publish to the `@leapfrog` npm repo.
40
+ * Increment the version number in `package.json`.
41
+ * `npm install` to update the `package-lock.json`.
42
+ * `npm run build`
43
+ * `npm publish`