lucid-extension-sdk 0.0.217 → 0.0.218

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
@@ -1096,11 +1096,19 @@ export type GetItemsAtQuery = {
1096
1096
  };
1097
1097
  /** IDs of the items found */
1098
1098
  export type GetItemsAtResult = string[];
1099
+ export declare enum GetLLMContextType {
1100
+ /** Get context in a format for LLMs where relationships among connected and contained items is preserved */
1101
+ Relational = 1,
1102
+ /** Get context containing only plain text displayed on the given items, more suitable for embeddings */
1103
+ PlainText = 2
1104
+ }
1099
1105
  export type GetLLMContextFromItemsQuery = {
1100
1106
  /** Page ID to find closely-related items */
1101
1107
  'p': string;
1102
1108
  /** List of item IDs to return LLM-readable context for */
1103
1109
  'i': string[];
1110
+ /** Type of context to get */
1111
+ 't'?: GetLLMContextType | undefined;
1104
1112
  };
1105
1113
  export type GetLLMContextFromItemsResult = {
1106
1114
  /**
package/commandtypes.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZOrderOperation = exports.isRawSendXHRResponse = exports.GetItemsAtSearchType = exports.HashAlgorithmEnum = exports.commandTitles = void 0;
3
+ exports.ZOrderOperation = exports.isRawSendXHRResponse = exports.GetLLMContextType = exports.GetItemsAtSearchType = exports.HashAlgorithmEnum = exports.commandTitles = void 0;
4
4
  const checks_1 = require("./core/checks");
5
5
  /** @ignore */
6
6
  exports.commandTitles = new Map([
@@ -135,6 +135,13 @@ var GetItemsAtSearchType;
135
135
  GetItemsAtSearchType[GetItemsAtSearchType["Overlapping"] = 1] = "Overlapping";
136
136
  GetItemsAtSearchType[GetItemsAtSearchType["Contained"] = 2] = "Contained";
137
137
  })(GetItemsAtSearchType = exports.GetItemsAtSearchType || (exports.GetItemsAtSearchType = {}));
138
+ var GetLLMContextType;
139
+ (function (GetLLMContextType) {
140
+ /** Get context in a format for LLMs where relationships among connected and contained items is preserved */
141
+ GetLLMContextType[GetLLMContextType["Relational"] = 1] = "Relational";
142
+ /** Get context containing only plain text displayed on the given items, more suitable for embeddings */
143
+ GetLLMContextType[GetLLMContextType["PlainText"] = 2] = "PlainText";
144
+ })(GetLLMContextType = exports.GetLLMContextType || (exports.GetLLMContextType = {}));
138
145
  function isRawSendXHRResponse(val) {
139
146
  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']);
140
147
  }
@@ -19,6 +19,10 @@ export declare class BlockProxy extends ItemProxy {
19
19
  * @returns The amount this block is rotated around its own center, in radians.
20
20
  */
21
21
  getRotation(): number;
22
+ /**
23
+ * @returns An axis-aligned bounding box containing this full item after any rotation it might have
24
+ */
25
+ getRotatedBoundingBox(): import("../math").Box;
22
26
  /**
23
27
  * @param radians Angle the block should be rotated
24
28
  */
@@ -5,6 +5,7 @@ const badgeposition_1 = require("../core/properties/datagraphic/badgeposition");
5
5
  const staticdatagraphicsettings_1 = require("../core/properties/datagraphic/staticdatagraphicsettings");
6
6
  const fillcolor_1 = require("../core/properties/fillcolor");
7
7
  const shadow_1 = require("../core/properties/shadow");
8
+ const math_1 = require("../math");
8
9
  const itemproxy_1 = require("./itemproxy");
9
10
  /**
10
11
  * A block is a single shape on the document. A BlockProxy provides an interface to
@@ -26,6 +27,12 @@ class BlockProxy extends itemproxy_1.ItemProxy {
26
27
  getRotation() {
27
28
  return this.properties.get('Rotation');
28
29
  }
30
+ /**
31
+ * @returns An axis-aligned bounding box containing this full item after any rotation it might have
32
+ */
33
+ getRotatedBoundingBox() {
34
+ return (0, math_1.rotatedBoundingBox)(this.getBoundingBox(), this.getRotation());
35
+ }
29
36
  /**
30
37
  * @param radians Angle the block should be rotated
31
38
  */
@@ -1,4 +1,4 @@
1
- import { GetItemsAtSearchType } from '../commandtypes';
1
+ import { GetItemsAtSearchType, GetLLMContextType } from '../commandtypes';
2
2
  import { EditorClient } from '../editorclient';
3
3
  import { Box } from '../math';
4
4
  import { BlockDefinition } from './blockdefinition';
@@ -114,7 +114,7 @@ export declare class PageProxy extends ElementProxy {
114
114
  * necessary, in a format that is easily understandable by LLMs like ChatGPT. Also a map of IDs, from the shortened
115
115
  * IDs provided for the items in the context to the actual Lucid item IDs.
116
116
  */
117
- getLLMContextForItems(items: ItemProxy[]): {
117
+ getLLMContextForItems(items: ItemProxy[], contextType?: GetLLMContextType): {
118
118
  prompt: string;
119
119
  idToLucidId: Map<string, string>;
120
120
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PageProxy = void 0;
4
+ const commandtypes_1 = require("../commandtypes");
4
5
  const ruleproxy_1 = require("./documentelement/ruleproxy");
5
6
  const elementproxy_1 = require("./elementproxy");
6
7
  const groupproxy_1 = require("./groupproxy");
@@ -180,12 +181,13 @@ class PageProxy extends elementproxy_1.ElementProxy {
180
181
  * necessary, in a format that is easily understandable by LLMs like ChatGPT. Also a map of IDs, from the shortened
181
182
  * IDs provided for the items in the context to the actual Lucid item IDs.
182
183
  */
183
- getLLMContextForItems(items) {
184
+ getLLMContextForItems(items, contextType = commandtypes_1.GetLLMContextType.Relational) {
184
185
  //We don't check that the items are on this page here; that is done in the implementation
185
186
  //of the API command. It would be a lot of extra API calls for no benefit.
186
187
  const result = this.client.sendCommand("llm" /* CommandName.GetLLMContextFromItems */, {
187
188
  'p': this.id,
188
189
  'i': items.map((item) => item.id),
190
+ 't': contextType,
189
191
  });
190
192
  return {
191
193
  prompt: result['p'],
package/math.d.ts CHANGED
@@ -31,3 +31,16 @@ export declare function percentBoxesOverlap(a: Box, b: Box): number;
31
31
  * @return a clipped to b
32
32
  */
33
33
  export declare function clip(a: Box, b: Box): Box;
34
+ export declare function boxCenter(b: Box): {
35
+ x: number;
36
+ y: number;
37
+ };
38
+ /**
39
+ * Returns the bounding box that would surround the given
40
+ * box when rotated the given amount.
41
+ */
42
+ export declare function rotatedBoundingBox(b: Box, angle: number, center?: Point): Box;
43
+ export declare function rotateBox(b: Box, angle: number, center?: Point): [Point, Point, Point, Point];
44
+ export declare function boxFrom4Points(a: Point, b: Point, c: Point, d: Point): Box;
45
+ export declare function toCornersAsArray(box: Box): [Point, Point, Point, Point];
46
+ export declare function rotateAroundFn(anchor: Point, angle: number): (p1: Point) => Point;
package/math.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clip = exports.percentBoxesOverlap = exports.boxesOverlap = exports.isBoxWithin = exports.padBox = exports.combinedBoundingBox = void 0;
3
+ exports.rotateAroundFn = exports.toCornersAsArray = exports.boxFrom4Points = exports.rotateBox = exports.rotatedBoundingBox = exports.boxCenter = 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;
@@ -64,3 +64,57 @@ function clip(a, b) {
64
64
  return { x, y, w, h };
65
65
  }
66
66
  exports.clip = clip;
67
+ function boxCenter(b) {
68
+ return { x: b.x + b.w / 2, y: b.y + b.h / 2 };
69
+ }
70
+ exports.boxCenter = boxCenter;
71
+ /**
72
+ * Returns the bounding box that would surround the given
73
+ * box when rotated the given amount.
74
+ */
75
+ function rotatedBoundingBox(b, angle, center) {
76
+ if (!angle) {
77
+ return b;
78
+ }
79
+ center = center || boxCenter(b);
80
+ return boxFrom4Points.apply(null, rotateBox(b, angle, center));
81
+ }
82
+ exports.rotatedBoundingBox = rotatedBoundingBox;
83
+ function rotateBox(b, angle, center) {
84
+ const ret = toCornersAsArray(b);
85
+ center = center || boxCenter(b);
86
+ if (angle != 0) {
87
+ return ret.map(rotateAroundFn(center, angle));
88
+ }
89
+ return ret;
90
+ }
91
+ exports.rotateBox = rotateBox;
92
+ function boxFrom4Points(a, b, c, d) {
93
+ const xMin = Math.min(a.x, b.x, c.x, d.x);
94
+ const xMax = Math.max(a.x, b.x, c.x, d.x);
95
+ const yMin = Math.min(a.y, b.y, c.y, d.y);
96
+ const yMax = Math.max(a.y, b.y, c.y, d.y);
97
+ return { x: xMin, y: yMin, w: xMax - xMin, h: yMax - yMin };
98
+ }
99
+ exports.boxFrom4Points = boxFrom4Points;
100
+ function toCornersAsArray(box) {
101
+ return [
102
+ { x: box.x, y: box.y },
103
+ { x: box.x + box.w, y: box.y },
104
+ { x: box.x + box.w, y: box.y + box.h },
105
+ { x: box.x, y: box.y + box.h },
106
+ ];
107
+ }
108
+ exports.toCornersAsArray = toCornersAsArray;
109
+ function rotateAroundFn(anchor, angle) {
110
+ const cos = Math.cos(angle);
111
+ const sin = Math.sin(angle);
112
+ return (p) => {
113
+ const anchorX = anchor.x;
114
+ const anchorY = anchor.y;
115
+ const x = p.x - anchorX;
116
+ const y = p.y - anchorY;
117
+ return { x: x * cos - y * sin + anchorX, y: y * cos + x * sin + anchorY };
118
+ };
119
+ }
120
+ exports.rotateAroundFn = rotateAroundFn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.217",
3
+ "version": "0.0.218",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",