@wz927/codedesign 0.2.17 → 0.2.18
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/main.js +1 -1
- package/figma-plugin/dist/code.js +71 -4
- package/package.json +1 -1
|
@@ -144,7 +144,7 @@ async function loadFontFor(props) {
|
|
|
144
144
|
}
|
|
145
145
|
// ─── Ops ─────────────────────────────────────────────────────────────────
|
|
146
146
|
async function handle(req) {
|
|
147
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
147
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
148
148
|
const p = (_a = req.params) !== null && _a !== void 0 ? _a : {};
|
|
149
149
|
switch (req.op) {
|
|
150
150
|
case 'getCurrentPage':
|
|
@@ -343,7 +343,14 @@ async function handle(req) {
|
|
|
343
343
|
}));
|
|
344
344
|
case 'createInstance': {
|
|
345
345
|
const all = figma.root.findAllWithCriteria({ types: ['COMPONENT'] });
|
|
346
|
-
|
|
346
|
+
let comp = all.find((c) => c.key === p.componentKey || c.id === p.componentKey);
|
|
347
|
+
// If not found locally, try to import from a team library by component key.
|
|
348
|
+
if (!comp && p.componentKey) {
|
|
349
|
+
try {
|
|
350
|
+
comp = await figma.importComponentByKeyAsync(p.componentKey);
|
|
351
|
+
}
|
|
352
|
+
catch { /* not in library either; throw below */ }
|
|
353
|
+
}
|
|
347
354
|
if (!comp)
|
|
348
355
|
throw new Error('Component not found: ' + p.componentKey);
|
|
349
356
|
const inst = comp.createInstance();
|
|
@@ -352,8 +359,68 @@ async function handle(req) {
|
|
|
352
359
|
inst.x = p.x;
|
|
353
360
|
if (typeof p.y === 'number')
|
|
354
361
|
inst.y = p.y;
|
|
362
|
+
if (typeof p.width === 'number' && typeof p.height === 'number')
|
|
363
|
+
inst.resize(p.width, p.height);
|
|
355
364
|
return nodeSummary(inst);
|
|
356
365
|
}
|
|
366
|
+
case 'createVector': {
|
|
367
|
+
// Draw an icon/shape using SVG path data.
|
|
368
|
+
// params: { parentId?, vectorPaths: [{windingRule, data}], fills, strokes, strokeWeight, x, y, width, height, name }
|
|
369
|
+
const vec = figma.createVector();
|
|
370
|
+
getParent(p.parentId).appendChild(vec);
|
|
371
|
+
if (p.vectorPaths)
|
|
372
|
+
vec.vectorPaths = p.vectorPaths;
|
|
373
|
+
if (p.fills)
|
|
374
|
+
vec.fills = p.fills.map(toPaint);
|
|
375
|
+
if (p.strokes)
|
|
376
|
+
vec.strokes = p.strokes.map(toPaint);
|
|
377
|
+
if (typeof p.strokeWeight === 'number')
|
|
378
|
+
vec.strokeWeight = p.strokeWeight;
|
|
379
|
+
if (typeof p.x === 'number')
|
|
380
|
+
vec.x = p.x;
|
|
381
|
+
if (typeof p.y === 'number')
|
|
382
|
+
vec.y = p.y;
|
|
383
|
+
if (typeof p.width === 'number' && typeof p.height === 'number')
|
|
384
|
+
vec.resize(p.width, p.height);
|
|
385
|
+
if (typeof p.name === 'string')
|
|
386
|
+
vec.name = p.name;
|
|
387
|
+
return nodeSummary(vec);
|
|
388
|
+
}
|
|
389
|
+
case 'createLine': {
|
|
390
|
+
// A simple line / divider.
|
|
391
|
+
// params: { parentId?, x, y, length, vertical?, strokeWeight, color:{r,g,b}, name }
|
|
392
|
+
const line = figma.createLine();
|
|
393
|
+
getParent(p.parentId).appendChild(line);
|
|
394
|
+
if (typeof p.x === 'number')
|
|
395
|
+
line.x = p.x;
|
|
396
|
+
if (typeof p.y === 'number')
|
|
397
|
+
line.y = p.y;
|
|
398
|
+
const len = (_g = p.length) !== null && _g !== void 0 ? _g : 100;
|
|
399
|
+
line.resize(p.vertical ? 0 : len, p.vertical ? len : 0);
|
|
400
|
+
if (p.color)
|
|
401
|
+
line.strokes = [{ type: 'SOLID', color: p.color, opacity: (_h = p.color.a) !== null && _h !== void 0 ? _h : 1 }];
|
|
402
|
+
if (typeof p.strokeWeight === 'number')
|
|
403
|
+
line.strokeWeight = p.strokeWeight;
|
|
404
|
+
if (typeof p.name === 'string')
|
|
405
|
+
line.name = p.name;
|
|
406
|
+
return nodeSummary(line);
|
|
407
|
+
}
|
|
408
|
+
case 'applyStyle': {
|
|
409
|
+
// Apply a local Figma style (paint/text/effect) to a node by style id.
|
|
410
|
+
// params: { id, fillStyleId?, strokeStyleId?, textStyleId?, effectStyleId? }
|
|
411
|
+
const n = figma.getNodeById(p.id);
|
|
412
|
+
if (!n)
|
|
413
|
+
throw new Error('Not found: ' + p.id);
|
|
414
|
+
if (p.fillStyleId !== undefined)
|
|
415
|
+
n.fillStyleId = p.fillStyleId;
|
|
416
|
+
if (p.strokeStyleId !== undefined)
|
|
417
|
+
n.strokeStyleId = p.strokeStyleId;
|
|
418
|
+
if (p.textStyleId !== undefined)
|
|
419
|
+
n.textStyleId = p.textStyleId;
|
|
420
|
+
if (p.effectStyleId !== undefined)
|
|
421
|
+
n.effectStyleId = p.effectStyleId;
|
|
422
|
+
return nodeSummary(n);
|
|
423
|
+
}
|
|
357
424
|
case 'viewport': {
|
|
358
425
|
const n = figma.getNodeById(p.id);
|
|
359
426
|
if (!n)
|
|
@@ -367,10 +434,10 @@ async function handle(req) {
|
|
|
367
434
|
const n = figma.getNodeById(p.id);
|
|
368
435
|
if (!n || !('exportAsync' in n))
|
|
369
436
|
throw new Error('Node not exportable');
|
|
370
|
-
const format = ((
|
|
437
|
+
const format = ((_j = p.format) !== null && _j !== void 0 ? _j : 'PNG').toUpperCase();
|
|
371
438
|
const settings = { format };
|
|
372
439
|
if (format === 'PNG' || format === 'JPG')
|
|
373
|
-
settings.constraint = { type: 'SCALE', value: (
|
|
440
|
+
settings.constraint = { type: 'SCALE', value: (_k = p.scale) !== null && _k !== void 0 ? _k : 2 };
|
|
374
441
|
const bytes = await n.exportAsync(settings);
|
|
375
442
|
const b64 = figma.base64Encode(bytes);
|
|
376
443
|
return { bytesBase64: b64, format };
|