@hangox/mg-cli 1.1.0 → 1.1.2
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/dist/cli.js +157 -10
- package/dist/cli.js.map +1 -1
- package/dist/daemon-runner.js.map +1 -1
- package/dist/{index-cEKly9mt.d.ts → index-CM3G8ywC.d.ts} +6 -0
- package/dist/index.d.ts +39 -6
- package/dist/index.js +65 -5
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -216,6 +216,32 @@ function normalizePageUrl(url) {
|
|
|
216
216
|
return url;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
+
function normalizePageUrlWithPageId(url) {
|
|
220
|
+
try {
|
|
221
|
+
let urlObj;
|
|
222
|
+
if (!url.includes("://") && !url.startsWith("//")) {
|
|
223
|
+
urlObj = new URL(`https://${url}`);
|
|
224
|
+
} else {
|
|
225
|
+
urlObj = new URL(url);
|
|
226
|
+
}
|
|
227
|
+
const basePath = `${urlObj.host}${urlObj.pathname}`;
|
|
228
|
+
const pageId = urlObj.searchParams.get("page_id");
|
|
229
|
+
if (pageId) {
|
|
230
|
+
const decodedPageId = decodeURIComponent(pageId);
|
|
231
|
+
return `${basePath}?page_id=${decodedPageId}`;
|
|
232
|
+
}
|
|
233
|
+
return basePath;
|
|
234
|
+
} catch {
|
|
235
|
+
const withoutProtocol = url.replace(/^https?:\/\//, "").replace(/^\/\//, "");
|
|
236
|
+
const pageIdMatch = withoutProtocol.match(/[?&]page_id=([^&#]+)/);
|
|
237
|
+
const basePath = withoutProtocol.split("?")[0].split("#")[0];
|
|
238
|
+
if (pageIdMatch) {
|
|
239
|
+
const decodedPageId = decodeURIComponent(pageIdMatch[1]);
|
|
240
|
+
return `${basePath}?page_id=${decodedPageId}`;
|
|
241
|
+
}
|
|
242
|
+
return basePath;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
219
245
|
function isDesignPageUrl(url) {
|
|
220
246
|
return /\/file\/\d+/.test(url);
|
|
221
247
|
}
|
|
@@ -229,17 +255,22 @@ function parseMgpLink(link) {
|
|
|
229
255
|
if (questionMarkIndex === -1) {
|
|
230
256
|
return null;
|
|
231
257
|
}
|
|
232
|
-
const
|
|
258
|
+
const basePath = urlPart.slice(0, questionMarkIndex);
|
|
233
259
|
const queryString = urlPart.slice(questionMarkIndex + 1);
|
|
234
260
|
const params = new URLSearchParams(queryString);
|
|
235
261
|
const encodedNodeId = params.get("nodeId");
|
|
236
262
|
const encodedPageId = params.get("pageId");
|
|
263
|
+
const mgPageId = params.get("page_id");
|
|
237
264
|
if (!encodedNodeId && !encodedPageId) {
|
|
238
265
|
return null;
|
|
239
266
|
}
|
|
240
267
|
if (encodedNodeId && encodedPageId) {
|
|
241
268
|
return null;
|
|
242
269
|
}
|
|
270
|
+
let pageUrl = basePath;
|
|
271
|
+
if (mgPageId) {
|
|
272
|
+
pageUrl = `${basePath}?page_id=${mgPageId}`;
|
|
273
|
+
}
|
|
243
274
|
if (encodedNodeId) {
|
|
244
275
|
const nodeId = decodeURIComponent(encodedNodeId);
|
|
245
276
|
if (!/^(\d+:\d+)(\/\d+:\d+)*$/.test(nodeId)) {
|
|
@@ -254,10 +285,19 @@ function parseMgpLink(link) {
|
|
|
254
285
|
return null;
|
|
255
286
|
}
|
|
256
287
|
}
|
|
288
|
+
const childNodeIdsRaw = params.get("childNodeIds");
|
|
289
|
+
let childNodeIds;
|
|
290
|
+
if (childNodeIdsRaw) {
|
|
291
|
+
childNodeIds = childNodeIdsRaw.split(",").map((id) => decodeURIComponent(id));
|
|
292
|
+
if (!childNodeIds.every((id) => /^(\d+:\d+)(\/\d+:\d+)*$/.test(id))) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
257
296
|
return {
|
|
258
297
|
pageUrl,
|
|
259
298
|
nodeId,
|
|
260
|
-
nodePath
|
|
299
|
+
nodePath,
|
|
300
|
+
childNodeIds
|
|
261
301
|
};
|
|
262
302
|
}
|
|
263
303
|
if (encodedPageId) {
|
|
@@ -276,9 +316,10 @@ function parseMgpLink(link) {
|
|
|
276
316
|
}
|
|
277
317
|
}
|
|
278
318
|
function generateMgpLink(pageUrl, nodeId, nodePath) {
|
|
279
|
-
const normalizedUrl =
|
|
319
|
+
const normalizedUrl = normalizePageUrlWithPageId(pageUrl);
|
|
280
320
|
const encodedNodeId = encodeURIComponent(nodeId);
|
|
281
|
-
|
|
321
|
+
const separator = normalizedUrl.includes("?") ? "&" : "?";
|
|
322
|
+
let link = `mgp://${normalizedUrl}${separator}nodeId=${encodedNodeId}`;
|
|
282
323
|
if (nodePath && nodePath.length > 0) {
|
|
283
324
|
const encodedNodePath = encodeURIComponent(nodePath.join("/"));
|
|
284
325
|
link += `&nodePath=${encodedNodePath}`;
|
|
@@ -290,6 +331,15 @@ function generatePageLink(pageUrl, pageId) {
|
|
|
290
331
|
const encodedPageId = encodeURIComponent(pageId);
|
|
291
332
|
return `mgp://${normalizedUrl}?pageId=${encodedPageId}`;
|
|
292
333
|
}
|
|
334
|
+
function generateMultiNodeMgpLink(pageUrl, parentNodeId, childNodeIds) {
|
|
335
|
+
const normalizedUrl = normalizePageUrlWithPageId(pageUrl);
|
|
336
|
+
const encodedParentNodeId = encodeURIComponent(parentNodeId);
|
|
337
|
+
const separator = normalizedUrl.includes("?") ? "&" : "?";
|
|
338
|
+
let link = `mgp://${normalizedUrl}${separator}nodeId=${encodedParentNodeId}`;
|
|
339
|
+
const encodedChildIds = childNodeIds.map((id) => encodeURIComponent(id)).join(",");
|
|
340
|
+
link += `&childNodeIds=${encodedChildIds}`;
|
|
341
|
+
return link;
|
|
342
|
+
}
|
|
293
343
|
function formatFileSize(bytes) {
|
|
294
344
|
if (bytes < 1024) {
|
|
295
345
|
return `${bytes} \u5B57\u8282`;
|
|
@@ -408,6 +458,8 @@ var NODE_DEFAULTS = {
|
|
|
408
458
|
dashCap: "NONE",
|
|
409
459
|
fillStyleId: "",
|
|
410
460
|
strokeStyleId: "",
|
|
461
|
+
strokeFillStyleId: "",
|
|
462
|
+
strokeWidthStyleId: "",
|
|
411
463
|
// Corner 属性
|
|
412
464
|
cornerSmooth: 0,
|
|
413
465
|
cornerRadius: 0,
|
|
@@ -415,6 +467,7 @@ var NODE_DEFAULTS = {
|
|
|
415
467
|
topRightRadius: 0,
|
|
416
468
|
bottomLeftRadius: 0,
|
|
417
469
|
bottomRightRadius: 0,
|
|
470
|
+
cornerRadiusStyleId: "",
|
|
418
471
|
// Layout 属性
|
|
419
472
|
rotation: 0,
|
|
420
473
|
flexGrow: 0,
|
|
@@ -430,9 +483,13 @@ var NODE_DEFAULTS = {
|
|
|
430
483
|
paddingRight: 0,
|
|
431
484
|
paddingBottom: 0,
|
|
432
485
|
paddingLeft: 0,
|
|
486
|
+
paddingStyleId: "",
|
|
487
|
+
spacingStyleId: "",
|
|
433
488
|
clipsContent: false,
|
|
434
489
|
itemReverseZIndex: false,
|
|
435
490
|
strokesIncludedInLayout: false,
|
|
491
|
+
overflowDirection: "NONE",
|
|
492
|
+
gridStyleId: "",
|
|
436
493
|
// 其他属性
|
|
437
494
|
componentPropertyReferences: null
|
|
438
495
|
};
|
|
@@ -443,7 +500,8 @@ var EMPTY_ARRAY_FIELDS = [
|
|
|
443
500
|
"strokeDashes",
|
|
444
501
|
"exportSettings",
|
|
445
502
|
"reactions",
|
|
446
|
-
"attachedConnectors"
|
|
503
|
+
"attachedConnectors",
|
|
504
|
+
"layoutGrids"
|
|
447
505
|
];
|
|
448
506
|
function isEmptyArray(value) {
|
|
449
507
|
return Array.isArray(value) && value.length === 0;
|
|
@@ -1738,12 +1796,14 @@ export {
|
|
|
1738
1796
|
formatLogTime,
|
|
1739
1797
|
generateId,
|
|
1740
1798
|
generateMgpLink,
|
|
1799
|
+
generateMultiNodeMgpLink,
|
|
1741
1800
|
generatePageLink,
|
|
1742
1801
|
getCurrentISOTime,
|
|
1743
1802
|
isDesignPageUrl,
|
|
1744
1803
|
isProcessRunning,
|
|
1745
1804
|
killProcess,
|
|
1746
1805
|
normalizePageUrl,
|
|
1806
|
+
normalizePageUrlWithPageId,
|
|
1747
1807
|
parseMgpLink,
|
|
1748
1808
|
readServerInfo,
|
|
1749
1809
|
resolveOutputPath,
|