lucid-extension-sdk 0.0.145 → 0.0.147

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.
package/commandtypes.d.ts CHANGED
@@ -55,6 +55,7 @@ export declare const enum CommandName {
55
55
  GetDataItemField = "gdif",
56
56
  GetElementType = "get",
57
57
  GetItemPageId = "gip",
58
+ GetItemsAt = "gia",
58
59
  GetPackageSettings = "gps",
59
60
  GetProduct = "gpr",
60
61
  GetProperty = "gp",
@@ -115,7 +116,8 @@ export declare const enum CommandName {
115
116
  UnhookCreateItems = "uci",
116
117
  UnhookDeleteItems = "udi",
117
118
  UnhookSelection = "us",
118
- UnhookTextEdit = "ute"
119
+ UnhookTextEdit = "ute",
120
+ ZOrder = "z"
119
121
  }
120
122
  /** @ignore */
121
123
  export declare const commandTitles: Map<CommandName, string>;
@@ -265,6 +267,10 @@ export declare type CommandArgs = {
265
267
  query: GetItemPageIdQuery;
266
268
  result: GetItemPageIdResult;
267
269
  };
270
+ [CommandName.GetItemsAt]: {
271
+ query: GetItemsAtQuery;
272
+ result: GetItemsAtResult;
273
+ };
268
274
  [CommandName.GetPackageSettings]: {
269
275
  query: GetPackageSettingsQuery;
270
276
  result: GetPackageSettingsResult;
@@ -509,6 +515,10 @@ export declare type CommandArgs = {
509
515
  query: UnhookTextEditQuery;
510
516
  result: UnhookTextEditResult;
511
517
  };
518
+ [CommandName.ZOrder]: {
519
+ query: ZOrderQuery;
520
+ result: ZOrderResult;
521
+ };
512
522
  };
513
523
  export declare type AddCardIntegrationQuery = {
514
524
  /** Title/name */
@@ -857,6 +867,21 @@ export declare type GetDataItemFieldQuery = {
857
867
  export declare type GetDataItemFieldResult = SerializedFieldType;
858
868
  export declare type GetItemPageIdQuery = string;
859
869
  export declare type GetItemPageIdResult = string;
870
+ export declare enum GetItemsAtSearchType {
871
+ PossiblyOverlapping = 0,
872
+ Overlapping = 1,
873
+ Contained = 2
874
+ }
875
+ export declare type GetItemsAtQuery = {
876
+ /** Page ID to search */
877
+ 'p': string;
878
+ /** Bounding box to search */
879
+ 'bb': Box;
880
+ /** Search type */
881
+ 's': GetItemsAtSearchType;
882
+ };
883
+ /** IDs of the items found */
884
+ export declare type GetItemsAtResult = string[];
860
885
  export declare type GetReferenceKeyQuery = {
861
886
  /** ID of the LucidElement to read a reference key from, or undefined to read from the LucidDocument */
862
887
  'id'?: string | undefined;
@@ -1242,3 +1267,16 @@ export declare type UnhookTextEditQuery = {
1242
1267
  'n': string;
1243
1268
  };
1244
1269
  export declare type UnhookTextEditResult = undefined;
1270
+ export declare enum ZOrderOperation {
1271
+ UP = 1,
1272
+ TOP = 2,
1273
+ DOWN = 3,
1274
+ BOTTOM = 4
1275
+ }
1276
+ export declare type ZOrderQuery = {
1277
+ /** IDs of the items to adjust Z order */
1278
+ 'i': string[];
1279
+ /** Operation to perform on these items */
1280
+ 'o': ZOrderOperation;
1281
+ };
1282
+ export declare type ZOrderResult = undefined;
package/commandtypes.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRawSendXHRResponse = exports.commandTitles = void 0;
3
+ exports.ZOrderOperation = exports.isRawSendXHRResponse = exports.GetItemsAtSearchType = exports.commandTitles = void 0;
4
4
  const checks_1 = require("./core/checks");
5
5
  /** @ignore */
6
6
  exports.commandTitles = new Map([
@@ -37,6 +37,7 @@ exports.commandTitles = new Map([
37
37
  ["gdif" /* CommandName.GetDataItemField */, 'GetDataItemField'],
38
38
  ["get" /* CommandName.GetElementType */, 'GetElementType'],
39
39
  ["gip" /* CommandName.GetItemPageId */, 'GetItemPageId'],
40
+ ["gia" /* CommandName.GetItemsAt */, 'GetItemsAt'],
40
41
  ["gps" /* CommandName.GetPackageSettings */, 'GetPackageSettings'],
41
42
  ["gpr" /* CommandName.GetProduct */, 'GetProduct'],
42
43
  ["gp" /* CommandName.GetProperty */, 'GetProperty'],
@@ -96,8 +97,22 @@ exports.commandTitles = new Map([
96
97
  ["udi" /* CommandName.UnhookDeleteItems */, 'UnhookDeleteItems'],
97
98
  ["us" /* CommandName.UnhookSelection */, 'UnhookSelection'],
98
99
  ["ute" /* CommandName.UnhookTextEdit */, 'UnhookTextEdit'],
100
+ ["z" /* CommandName.ZOrder */, 'ZOrder'],
99
101
  ]);
102
+ var GetItemsAtSearchType;
103
+ (function (GetItemsAtSearchType) {
104
+ GetItemsAtSearchType[GetItemsAtSearchType["PossiblyOverlapping"] = 0] = "PossiblyOverlapping";
105
+ GetItemsAtSearchType[GetItemsAtSearchType["Overlapping"] = 1] = "Overlapping";
106
+ GetItemsAtSearchType[GetItemsAtSearchType["Contained"] = 2] = "Contained";
107
+ })(GetItemsAtSearchType = exports.GetItemsAtSearchType || (exports.GetItemsAtSearchType = {}));
100
108
  function isRawSendXHRResponse(val) {
101
109
  return (0, checks_1.isString)(val['url']) && (0, checks_1.isString)(val['t']) && (0, checks_1.isNumber)(val['s']) && (0, checks_1.isObject)(val['h']);
102
110
  }
103
111
  exports.isRawSendXHRResponse = isRawSendXHRResponse;
112
+ var ZOrderOperation;
113
+ (function (ZOrderOperation) {
114
+ ZOrderOperation[ZOrderOperation["UP"] = 1] = "UP";
115
+ ZOrderOperation[ZOrderOperation["TOP"] = 2] = "TOP";
116
+ ZOrderOperation[ZOrderOperation["DOWN"] = 3] = "DOWN";
117
+ ZOrderOperation[ZOrderOperation["BOTTOM"] = 4] = "BOTTOM";
118
+ })(ZOrderOperation = exports.ZOrderOperation || (exports.ZOrderOperation = {}));
@@ -3,5 +3,6 @@
3
3
  */
4
4
  export declare enum LucidProduct {
5
5
  Chart = "chart",
6
- Spark = "spark"
6
+ Spark = "spark",
7
+ TeamSpaces = "teamspaces"
7
8
  }
@@ -8,4 +8,5 @@ var LucidProduct;
8
8
  (function (LucidProduct) {
9
9
  LucidProduct["Chart"] = "chart";
10
10
  LucidProduct["Spark"] = "spark";
11
+ LucidProduct["TeamSpaces"] = "teamspaces";
11
12
  })(LucidProduct = exports.LucidProduct || (exports.LucidProduct = {}));
@@ -5,6 +5,7 @@ const cardblockproxy_1 = require("./cardblockproxy");
5
5
  const customblockproxy_1 = require("./customblockproxy");
6
6
  const erdblockproxy_1 = require("./erdblockproxy");
7
7
  const linkunfurlblockproxy_1 = require("./linkunfurlblockproxy");
8
+ const swimlaneblockproxy_1 = require("./swimlaneblockproxy");
8
9
  const tableblockproxy_1 = require("./tableblockproxy");
9
10
  const allProxyClasses = [
10
11
  erdblockproxy_1.ERDBlockProxy,
@@ -12,6 +13,7 @@ const allProxyClasses = [
12
13
  linkunfurlblockproxy_1.LinkUnfurlBlockProxy,
13
14
  cardblockproxy_1.CardBlockProxy,
14
15
  tableblockproxy_1.TableBlockProxy,
16
+ swimlaneblockproxy_1.SwimLaneBlockProxy,
15
17
  ];
16
18
  function findProxyClass(className) {
17
19
  return allProxyClasses.find((proxy) => proxy.classNameRegex.test(className));
@@ -0,0 +1,39 @@
1
+ import { SimpleFillStyle } from '../../core/properties/fillcolor';
2
+ import { Box } from '../../math';
3
+ import { BlockProxy } from '../blockproxy';
4
+ export declare class SwimLanePrimaryLaneProxy {
5
+ readonly swimlane: SwimLaneBlockProxy;
6
+ readonly index: number;
7
+ constructor(swimlane: SwimLaneBlockProxy, index: number);
8
+ /**
9
+ * For horizontal lanes, the lane height.
10
+ * For vertical lanes, the lane width.
11
+ */
12
+ getSize(): number;
13
+ getBoundingBox(): {
14
+ x: number;
15
+ y: number;
16
+ w: number;
17
+ h: number;
18
+ };
19
+ private getTitleTextAreaId;
20
+ getTitle(): string;
21
+ setTitle(title: string): undefined;
22
+ setFill(fill: SimpleFillStyle): void;
23
+ }
24
+ export declare class SwimLaneBlockProxy extends BlockProxy {
25
+ static classNameRegex: RegExp;
26
+ getPrimaryLaneSizes(): number[];
27
+ setPrimaryLaneSizes(sizes: number[]): void;
28
+ getPrimaryLanes(): SwimLanePrimaryLaneProxy[];
29
+ getPrimaryLanesVertical(): boolean;
30
+ getMagnetized(): boolean;
31
+ setMagnetized(magnetize: boolean): void;
32
+ /** @ignore */
33
+ updateTextAreaNames(): void;
34
+ /**
35
+ * Swim lanes only use the normal BoundingBox property for location.
36
+ * For size, it uses the PrimaryLane and SecondaryLane properties.
37
+ */
38
+ setBoundingBox(bb: Box): void;
39
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SwimLaneBlockProxy = exports.SwimLanePrimaryLaneProxy = void 0;
4
+ const fillcolor_1 = require("../../core/properties/fillcolor");
5
+ const blockproxy_1 = require("../blockproxy");
6
+ class SwimLanePrimaryLaneProxy {
7
+ constructor(swimlane, index) {
8
+ this.swimlane = swimlane;
9
+ this.index = index;
10
+ }
11
+ /**
12
+ * For horizontal lanes, the lane height.
13
+ * For vertical lanes, the lane width.
14
+ */
15
+ getSize() {
16
+ return this.swimlane.getPrimaryLaneSizes()[this.index];
17
+ }
18
+ getBoundingBox() {
19
+ const bb = this.swimlane.getBoundingBox();
20
+ const sizes = this.swimlane.getPrimaryLaneSizes();
21
+ if (this.swimlane.getPrimaryLanesVertical()) {
22
+ return {
23
+ x: bb.x + sizes.slice(0, this.index).reduce((a, b) => a + b, 0),
24
+ y: bb.y,
25
+ w: sizes[this.index],
26
+ h: bb.h,
27
+ };
28
+ }
29
+ else {
30
+ return {
31
+ x: bb.x,
32
+ y: bb.y + sizes.slice(0, this.index).reduce((a, b) => a + b, 0),
33
+ w: bb.w,
34
+ h: sizes[this.index],
35
+ };
36
+ }
37
+ }
38
+ getTitleTextAreaId() {
39
+ const existing = this.swimlane.properties.get('PrimaryLaneTextAreaIds')[this.index];
40
+ if (existing) {
41
+ return existing;
42
+ }
43
+ this.swimlane.updateTextAreaNames();
44
+ return this.swimlane.properties.get('PrimaryLaneTextAreaIds')[this.index];
45
+ }
46
+ getTitle() {
47
+ return this.swimlane.textAreas.get(this.getTitleTextAreaId());
48
+ }
49
+ setTitle(title) {
50
+ return this.swimlane.textAreas.set(this.getTitleTextAreaId(), title);
51
+ }
52
+ setFill(fill) {
53
+ this.swimlane.properties.set(`CellFill_0,${this.index}`, (0, fillcolor_1.serializeSimpleFill)(fill));
54
+ }
55
+ }
56
+ exports.SwimLanePrimaryLaneProxy = SwimLanePrimaryLaneProxy;
57
+ class SwimLaneBlockProxy extends blockproxy_1.BlockProxy {
58
+ getPrimaryLaneSizes() {
59
+ return this.properties.get('PrimaryLane');
60
+ }
61
+ setPrimaryLaneSizes(sizes) {
62
+ this.properties.set('PrimaryLane', sizes);
63
+ this.updateTextAreaNames();
64
+ }
65
+ getPrimaryLanes() {
66
+ return this.getPrimaryLaneSizes().map((size, index) => new SwimLanePrimaryLaneProxy(this, index));
67
+ }
68
+ getPrimaryLanesVertical() {
69
+ return this.properties.get('IsPrimaryLaneVertical');
70
+ }
71
+ getMagnetized() {
72
+ return this.properties.get('Magnetize');
73
+ }
74
+ setMagnetized(magnetize) {
75
+ this.properties.set('Magnetize', magnetize);
76
+ }
77
+ /** @ignore */
78
+ updateTextAreaNames() {
79
+ this.properties.set('PrimaryLaneTextAreaIds', this.getPrimaryLaneSizes().map((_, index) => 'Primary_' + index));
80
+ }
81
+ /**
82
+ * Swim lanes only use the normal BoundingBox property for location.
83
+ * For size, it uses the PrimaryLane and SecondaryLane properties.
84
+ */
85
+ setBoundingBox(bb) {
86
+ super.setBoundingBox(bb); //To get position correct
87
+ const minLaneSize = 40;
88
+ const oldBB = this.getBoundingBox();
89
+ const primarySizes = this.getPrimaryLaneSizes();
90
+ const secondarySizes = this.properties.get('SecondaryLane');
91
+ const adjustLanesByDelta = (lanes, delta, laneIndex = lanes.length - 1) => {
92
+ if (laneIndex >= 0 && laneIndex < lanes.length) {
93
+ lanes[laneIndex] += delta;
94
+ if (lanes[laneIndex] < minLaneSize) {
95
+ const deltaLeft = minLaneSize - lanes[laneIndex];
96
+ lanes[laneIndex] = minLaneSize;
97
+ adjustLanesByDelta(lanes, deltaLeft, laneIndex - 1);
98
+ }
99
+ }
100
+ };
101
+ if (bb.w != oldBB.w) {
102
+ if (this.getPrimaryLanesVertical()) {
103
+ adjustLanesByDelta(primarySizes, bb.w - oldBB.w);
104
+ this.setPrimaryLaneSizes(primarySizes);
105
+ }
106
+ else {
107
+ adjustLanesByDelta(secondarySizes, bb.w - oldBB.w);
108
+ this.properties.set('SecondaryLane', secondarySizes);
109
+ }
110
+ }
111
+ if (bb.h != oldBB.h) {
112
+ if (this.getPrimaryLanesVertical()) {
113
+ adjustLanesByDelta(secondarySizes, bb.h - oldBB.h);
114
+ this.properties.set('SecondaryLane', secondarySizes);
115
+ }
116
+ else {
117
+ adjustLanesByDelta(primarySizes, bb.h - oldBB.h);
118
+ this.setPrimaryLaneSizes(primarySizes);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ exports.SwimLaneBlockProxy = SwimLaneBlockProxy;
124
+ SwimLaneBlockProxy.classNameRegex = /^AdvancedSwimLaneBlock$/;
@@ -1,4 +1,5 @@
1
1
  import { SimpleFillStyle } from '../../core/properties/fillcolor';
2
+ import { Box } from '../../math';
2
3
  import { BlockProxy } from '../blockproxy';
3
4
  import { TextStyle } from '../text/textstyle';
4
5
  export declare class TableCellProxy {
@@ -43,6 +44,7 @@ export declare class TableCellProxy {
43
44
  * @returns the pixel height of the cell, including any cells it is merged with.
44
45
  */
45
46
  getHeight(): number;
47
+ getBoundingBox(): Box;
46
48
  }
47
49
  export declare class TableRowProxy {
48
50
  readonly table: TableBlockProxy;
@@ -65,6 +65,20 @@ class TableCellProxy {
65
65
  .slice(this.row, this.row + this.getMergedCellSize().h)
66
66
  .reduce((a, b) => a + b, 0);
67
67
  }
68
+ getBoundingBox() {
69
+ const tableBB = this.table.getBoundingBox();
70
+ const x = tableBB.x +
71
+ this.table
72
+ .getColumnWidths()
73
+ .slice(0, this.column)
74
+ .reduce((a, b) => a + b, 0);
75
+ const y = tableBB.y +
76
+ this.table
77
+ .getRowHeights()
78
+ .slice(0, this.row)
79
+ .reduce((a, b) => a + b, 0);
80
+ return { x, y, w: this.getWidth(), h: this.getHeight() };
81
+ }
68
82
  }
69
83
  exports.TableCellProxy = TableCellProxy;
70
84
  class TableRowProxy {
@@ -1,3 +1,4 @@
1
+ import { ZOrderOperation } from '../commandtypes';
1
2
  import { LinearOffsetType } from '../core/offsettype';
2
3
  import { EditorClient } from '../editorclient';
3
4
  import { Box, Point } from '../math';
@@ -71,4 +72,8 @@ export declare class ItemProxy extends ElementProxy {
71
72
  * @returns An array of blocks whose bounding boxes contain this item's upper-left corner
72
73
  */
73
74
  getContainers(): import("./blockproxy").BlockProxy[];
75
+ /**
76
+ * @param operation How to adjust the Z order of this item relative to the other items it overlaps on the page
77
+ */
78
+ changeZOrder(operation: ZOrderOperation): void;
74
79
  }
@@ -115,5 +115,11 @@ class ItemProxy extends elementproxy_1.ElementProxy {
115
115
  const containers = this.executeFormula('LABEL(CONTAINEDBY)');
116
116
  return containers.map((id) => this.client.getBlockProxy(id));
117
117
  }
118
+ /**
119
+ * @param operation How to adjust the Z order of this item relative to the other items it overlaps on the page
120
+ */
121
+ changeZOrder(operation) {
122
+ this.client.sendCommand("z" /* CommandName.ZOrder */, { 'i': [this.id], 'o': operation });
123
+ }
118
124
  }
119
125
  exports.ItemProxy = ItemProxy;
@@ -3,6 +3,11 @@ import { BlockProxy } from './blockproxy';
3
3
  import { ItemProxy } from './itemproxy';
4
4
  import { EndpointDefinition } from './linedefinition';
5
5
  import { LineTextAreaPositioning } from './linetextareapositioning';
6
+ export declare enum LineShape {
7
+ Curve = "curve",
8
+ Elbow = "elbow",
9
+ Straight = "straight"
10
+ }
6
11
  /**
7
12
  * A line on the current Lucid document
8
13
  */
@@ -78,4 +83,6 @@ export declare class LineProxy extends ItemProxy {
78
83
  * @param name
79
84
  */
80
85
  deleteTextArea(name: string): void;
86
+ getShape(): LineShape;
87
+ setShape(shape: LineShape): void;
81
88
  }
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LineProxy = void 0;
3
+ exports.LineProxy = exports.LineShape = void 0;
4
4
  const checks_1 = require("../core/checks");
5
5
  const blockproxy_1 = require("./blockproxy");
6
6
  const itemproxy_1 = require("./itemproxy");
7
7
  const linetextareapositioning_1 = require("./linetextareapositioning");
8
+ var LineShape;
9
+ (function (LineShape) {
10
+ LineShape["Curve"] = "curve";
11
+ LineShape["Elbow"] = "elbow";
12
+ LineShape["Straight"] = "straight";
13
+ })(LineShape = exports.LineShape || (exports.LineShape = {}));
8
14
  /**
9
15
  * A line on the current Lucid document
10
16
  */
@@ -182,5 +188,11 @@ class LineProxy extends itemproxy_1.ItemProxy {
182
188
  deleteTextArea(name) {
183
189
  this.properties.set('TextAreas', { [name]: null });
184
190
  }
191
+ getShape() {
192
+ return this.properties.get('Shape');
193
+ }
194
+ setShape(shape) {
195
+ this.properties.set('Shape', shape);
196
+ }
185
197
  }
186
198
  exports.LineProxy = LineProxy;
@@ -1,4 +1,6 @@
1
+ import { GetItemsAtSearchType } from '../commandtypes';
1
2
  import { EditorClient } from '../editorclient';
3
+ import { Box } from '../math';
2
4
  import { BlockDefinition } from './blockdefinition';
3
5
  import { BlockProxy } from './blockproxy';
4
6
  import { ElementProxy } from './elementproxy';
@@ -70,4 +72,11 @@ export declare class PageProxy extends ElementProxy {
70
72
  * Delete this page from the document if possible
71
73
  */
72
74
  delete(): void;
75
+ /**
76
+ *
77
+ * @param boundingBox An area of this page to search for blocks, lines, and groups
78
+ * @param searchType
79
+ * @returns Items in the given bounding box, based on the search type
80
+ */
81
+ findItems(boundingBox: Box, searchType: GetItemsAtSearchType): (BlockProxy | LineProxy | GroupProxy)[];
73
82
  }
@@ -105,5 +105,16 @@ class PageProxy extends elementproxy_1.ElementProxy {
105
105
  delete() {
106
106
  this.client.sendCommand("dp" /* CommandName.DeletePage */, this.id);
107
107
  }
108
+ /**
109
+ *
110
+ * @param boundingBox An area of this page to search for blocks, lines, and groups
111
+ * @param searchType
112
+ * @returns Items in the given bounding box, based on the search type
113
+ */
114
+ findItems(boundingBox, searchType) {
115
+ return this.client
116
+ .sendCommand("gia" /* CommandName.GetItemsAt */, { 'p': this.id, 'bb': boundingBox, 's': searchType })
117
+ .map((id) => this.client.getItemProxy(id));
118
+ }
108
119
  }
109
120
  exports.PageProxy = PageProxy;
package/index.d.ts CHANGED
@@ -77,6 +77,8 @@ export * from './document/blockclasses/cardblockproxy';
77
77
  export * from './document/blockclasses/customblockproxy';
78
78
  export * from './document/blockclasses/erdblockproxy';
79
79
  export * from './document/blockclasses/linkunfurlblockproxy';
80
+ export * from './document/blockclasses/swimlaneblockproxy';
81
+ export * from './document/blockclasses/tableblockproxy';
80
82
  export * from './document/blockdefinition';
81
83
  export * from './document/blockproxy';
82
84
  export * from './document/documentproxy';
package/index.js CHANGED
@@ -93,6 +93,8 @@ __exportStar(require("./document/blockclasses/cardblockproxy"), exports);
93
93
  __exportStar(require("./document/blockclasses/customblockproxy"), exports);
94
94
  __exportStar(require("./document/blockclasses/erdblockproxy"), exports);
95
95
  __exportStar(require("./document/blockclasses/linkunfurlblockproxy"), exports);
96
+ __exportStar(require("./document/blockclasses/swimlaneblockproxy"), exports);
97
+ __exportStar(require("./document/blockclasses/tableblockproxy"), exports);
96
98
  __exportStar(require("./document/blockdefinition"), exports);
97
99
  __exportStar(require("./document/blockproxy"), exports);
98
100
  __exportStar(require("./document/documentproxy"), exports);
package/math.d.ts CHANGED
@@ -11,3 +11,23 @@ export declare type Box = {
11
11
  export declare function combinedBoundingBox(boxes: [Box, ...Box[]]): Box;
12
12
  export declare function combinedBoundingBox(boxes: Box[]): Box | undefined;
13
13
  export declare function padBox(box: Box, padding: number): Box;
14
+ /**
15
+ * Is box a completely within box b?
16
+ */
17
+ export declare function isBoxWithin(a: Box, b: Box): boolean;
18
+ /**
19
+ * Do two boxes overlap?
20
+ */
21
+ export declare function boxesOverlap(a: Box, b: Box): boolean;
22
+ /**
23
+ * return the percentage of a that overlaps with b.
24
+ * if a is entirely within b, it returns 1 (or a number a little less than 1
25
+ * (e.g., 0.99999999999) due to numerical inaccuracy); if a is entirely
26
+ * outside b, it returns 0.
27
+ */
28
+ export declare function percentBoxesOverlap(a: Box, b: Box): number;
29
+ /**
30
+ * Gets the intersection of two boxes
31
+ * @return a clipped to b
32
+ */
33
+ export declare function clip(a: Box, b: Box): Box;
package/math.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.padBox = exports.combinedBoundingBox = void 0;
3
+ exports.clip = exports.percentBoxesOverlap = exports.boxesOverlap = exports.isBoxWithin = exports.padBox = exports.combinedBoundingBox = void 0;
4
4
  function combinedBoundingBox(boxes) {
5
5
  if (boxes.length == 0) {
6
6
  return undefined;
@@ -22,3 +22,45 @@ function padBox(box, padding) {
22
22
  return { x: box.x - padding, y: box.y - padding, w: box.w + padding * 2, h: box.h + padding * 2 };
23
23
  }
24
24
  exports.padBox = padBox;
25
+ /**
26
+ * Is box a completely within box b?
27
+ */
28
+ function isBoxWithin(a, b) {
29
+ return a.x >= b.x && a.y >= b.y && a.x + a.w <= b.x + b.w && a.y + a.h <= b.y + b.h;
30
+ }
31
+ exports.isBoxWithin = isBoxWithin;
32
+ /**
33
+ * Do two boxes overlap?
34
+ */
35
+ function boxesOverlap(a, b) {
36
+ return a.x + a.w >= b.x && a.y + a.h >= b.y && b.x + b.w >= a.x && b.y + b.h >= a.y;
37
+ }
38
+ exports.boxesOverlap = boxesOverlap;
39
+ /**
40
+ * return the percentage of a that overlaps with b.
41
+ * if a is entirely within b, it returns 1 (or a number a little less than 1
42
+ * (e.g., 0.99999999999) due to numerical inaccuracy); if a is entirely
43
+ * outside b, it returns 0.
44
+ */
45
+ function percentBoxesOverlap(a, b) {
46
+ const intersection = clip(a, b);
47
+ // if either dimension is negative return zero
48
+ if (intersection.w <= 0 || intersection.h <= 0) {
49
+ return 0;
50
+ }
51
+ const area = intersection.w * intersection.h;
52
+ return area / (a.w * a.h);
53
+ }
54
+ exports.percentBoxesOverlap = percentBoxesOverlap;
55
+ /**
56
+ * Gets the intersection of two boxes
57
+ * @return a clipped to b
58
+ */
59
+ function clip(a, b) {
60
+ const x = Math.max(a.x, b.x);
61
+ const y = Math.max(a.y, b.y);
62
+ const w = Math.min(a.x + a.w, b.x + b.w) - x;
63
+ const h = Math.min(a.y + a.h, b.y + b.h) - y;
64
+ return { x, y, w, h };
65
+ }
66
+ exports.clip = clip;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.145",
3
+ "version": "0.0.147",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",