@graph-knowledge/api 0.1.6 → 0.1.7
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/README.md +14 -2
- package/package.json +1 -1
- package/src/lib/operations/element-operations.js +15 -0
package/README.md
CHANGED
|
@@ -191,8 +191,20 @@ await api.elements.create(documentId, nodeId, {
|
|
|
191
191
|
text: "Hello World",
|
|
192
192
|
fontSize: 24,
|
|
193
193
|
fontFamily: "Arial",
|
|
194
|
-
fillColor: "#000000"
|
|
195
|
-
|
|
194
|
+
fillColor: "#000000"
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Create centered text within a container width
|
|
198
|
+
// When you specify a width larger than the text, textAlign controls
|
|
199
|
+
// positioning within that container (like CSS text-align)
|
|
200
|
+
await api.elements.create(documentId, nodeId, {
|
|
201
|
+
type: "text",
|
|
202
|
+
x: 100,
|
|
203
|
+
y: 150,
|
|
204
|
+
width: 400, // Container width
|
|
205
|
+
text: "Centered within 400px",
|
|
206
|
+
fontSize: 20,
|
|
207
|
+
textAlign: "center" // "left" | "center" | "right"
|
|
196
208
|
});
|
|
197
209
|
|
|
198
210
|
// Create multi-line text (use \n for line breaks)
|
package/package.json
CHANGED
|
@@ -173,6 +173,21 @@ class ElementOperations {
|
|
|
173
173
|
props[key] = value;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
+
// For text elements with an explicitly specified width, set __usesTopLeft: true
|
|
177
|
+
// so the app's normalization knows that x/y is the bounding box top-left
|
|
178
|
+
// (not the text anchor point). Without this, the app would incorrectly adjust
|
|
179
|
+
// x/y based on textAlign, causing centered text to be positioned in negative
|
|
180
|
+
// coordinates.
|
|
181
|
+
//
|
|
182
|
+
// However, when width is omitted, a default width is applied elsewhere. In that
|
|
183
|
+
// case we DO NOT set __usesTopLeft, so the text plugin can treat the element as
|
|
184
|
+
// auto-sized text instead of preserving the default container width.
|
|
185
|
+
if (input.type === "text") {
|
|
186
|
+
const hasExplicitWidth = Object.prototype.hasOwnProperty.call(input, "width");
|
|
187
|
+
if (hasExplicitWidth) {
|
|
188
|
+
props["__usesTopLeft"] = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
176
191
|
return props;
|
|
177
192
|
}
|
|
178
193
|
}
|