@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.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/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +176 -5
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +13 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +58 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +9 -15
- package/dist/copy.js.map +1 -1
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +2 -1
- package/dist/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +30 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +63 -131
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +1 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +15 -3
- package/dist/graph.js.map +1 -1
- package/dist/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +42 -29
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +36 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/swap.js +288 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +84 -32
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +2 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +19 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/scaling/tree.js +1 -1
- package/dist/shared-styles.d.ts +14 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +63 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +2 -0
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/index.js +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +27 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +28 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +104 -14
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/index.d.ts +3 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +23 -8
- package/dist/variables/index.js.map +1 -1
- package/package.json +7 -1
- package/src/arrow-caps.ts +2 -5
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +251 -4
- package/src/components/properties.ts +92 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/copy.ts +9 -15
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +1 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +78 -198
- package/src/graph.ts +27 -3
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +67 -54
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +58 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/swap.ts +451 -0
- package/src/instances/sync.ts +141 -42
- package/src/node-defaults.ts +2 -1
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/plugin-data/fields.ts +15 -2
- package/src/shared-styles.ts +82 -1
- package/src/slots/content.ts +2 -0
- package/src/slots/frames.ts +9 -7
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +28 -0
- package/src/variables/bindings.ts +125 -14
- package/src/variables/fields.ts +46 -1
- package/src/variables/index.ts +35 -2
package/dist/figjam/palette.js
CHANGED
|
@@ -222,6 +222,28 @@ function figJamColorName(color) {
|
|
|
222
222
|
function figJamOutlineColorName(color) {
|
|
223
223
|
return figJamColorName(color) ?? FIGJAM_COLOR_NAMES.find((name) => sameColor(color, parseColor(PALETTE[name].sectionStroke))) ?? null;
|
|
224
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* How FigJam draws a section's title on a board, measured in FigJam: a pill in the colour of the
|
|
227
|
+
* outline drawn on top, with white text on the palette's darkest colours and black on the rest;
|
|
228
|
+
* null for a section without an outline from the palette. `colorOf` reads an outline's colour as
|
|
229
|
+
* drawn, such as a variable's value in the active mode.
|
|
230
|
+
*/
|
|
231
|
+
function figJamSectionTitleColors(section, colorOf = (stroke) => stroke.color) {
|
|
232
|
+
const strokeIndex = section.strokes.findLastIndex((stroke) => stroke.visible && stroke.opacity > 0);
|
|
233
|
+
const outline = section.strokes.at(strokeIndex);
|
|
234
|
+
if (strokeIndex === -1 || !outline) return null;
|
|
235
|
+
const color = colorOf(outline, strokeIndex);
|
|
236
|
+
const name = figJamOutlineColorName(color);
|
|
237
|
+
if (!name) return null;
|
|
238
|
+
return {
|
|
239
|
+
strokeIndex,
|
|
240
|
+
background: {
|
|
241
|
+
...color,
|
|
242
|
+
a: 1
|
|
243
|
+
},
|
|
244
|
+
lightText: PALETTE[name].lightLabel
|
|
245
|
+
};
|
|
246
|
+
}
|
|
225
247
|
/** The fill mode a shape's first fill shows. */
|
|
226
248
|
function figJamFillMode(fill) {
|
|
227
249
|
if (!fill || !fill.visible || fill.opacity === 0) return "none";
|
|
@@ -344,6 +366,12 @@ function strokesIn(strokes, color, weight) {
|
|
|
344
366
|
/** A section painted `name`, as FigJam's colour menu paints one: a pale tint outlined in the colour. */
|
|
345
367
|
function figJamSectionColorFields(section, name) {
|
|
346
368
|
const { sectionFill, sectionStroke } = PALETTE[name];
|
|
369
|
+
const strokes = strokesIn(section.strokes, parseColor(sectionStroke), SECTION_STROKE_WEIGHT).map((stroke) => stroke.opacity === 0 ? stroke : {
|
|
370
|
+
...stroke,
|
|
371
|
+
opacity: 1,
|
|
372
|
+
visible: true,
|
|
373
|
+
weight: SECTION_STROKE_WEIGHT
|
|
374
|
+
});
|
|
347
375
|
return {
|
|
348
376
|
fills: [{
|
|
349
377
|
type: "SOLID",
|
|
@@ -351,7 +379,7 @@ function figJamSectionColorFields(section, name) {
|
|
|
351
379
|
opacity: 1,
|
|
352
380
|
visible: true
|
|
353
381
|
}],
|
|
354
|
-
strokes
|
|
382
|
+
strokes,
|
|
355
383
|
strokeWeight: SECTION_STROKE_WEIGHT
|
|
356
384
|
};
|
|
357
385
|
}
|
|
@@ -406,6 +434,6 @@ function figJamLayerColorName(node) {
|
|
|
406
434
|
return figJamColorName(drawnPaint(colorsStroke(node) ? node.strokes : node.fills)?.color);
|
|
407
435
|
}
|
|
408
436
|
//#endregion
|
|
409
|
-
export { FIGJAM_COLOR_NAMES, FIGJAM_SHAPE_DASH, figJamColor, figJamColorName, figJamFillMode, figJamLayerColorFields, figJamLayerColorName, figJamLineColorFields, figJamLineStyle, figJamLineStyleFields, figJamOutlineColorName, figJamPairedStroke, figJamSectionColorFields, figJamSectionColorName, figJamShapePaint };
|
|
437
|
+
export { FIGJAM_COLOR_NAMES, FIGJAM_SHAPE_DASH, figJamColor, figJamColorName, figJamFillMode, figJamLayerColorFields, figJamLayerColorName, figJamLineColorFields, figJamLineStyle, figJamLineStyleFields, figJamOutlineColorName, figJamPairedStroke, figJamSectionColorFields, figJamSectionColorName, figJamSectionTitleColors, figJamShapePaint };
|
|
410
438
|
|
|
411
439
|
//# sourceMappingURL=palette.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"palette.js","names":[],"sources":["../../src/figjam/palette.ts"],"sourcesContent":["import { omit } from 'es-toolkit'\n\nimport { parseColor } from '../color'\nimport { BLACK, WHITE } from '../constants'\nimport type { Color } from '../primitives'\nimport type { Fill, SceneNode, Stroke } from '../types'\n\n/**\n * FigJam's board palette, in its menus' order, as its colour menu paints a shape with text: each\n * fill pairs with a darker stroke, a light label on the darkest fills, and, made transparent, a\n * lighter fill and its own stroke. Its line menu and connectors take the fills as line colours, and\n * a section takes a pale tint of each with the colour itself as its outline.\n */\nconst PALETTE = {\n black: {\n fill: '#1e1e1e',\n stroke: '#242424',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#929292',\n sectionFill: '#dddddd',\n sectionStroke: '#2c2c2c'\n },\n darkGray: {\n fill: '#757575',\n stroke: '#424242',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a1a1a1',\n sectionFill: '#eaeaea',\n sectionStroke: '#757575'\n },\n red: {\n fill: '#f24822',\n stroke: '#bd2915',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#c7968f',\n sectionFill: '#ffe2e0',\n sectionStroke: '#f24822'\n },\n orange: {\n fill: '#ff9e42',\n stroke: '#eb7500',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#e9b780',\n sectionFill: '#ffead6',\n sectionStroke: '#ff9e42'\n },\n yellow: {\n fill: '#ffc943',\n stroke: '#e8a302',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f5d280',\n sectionFill: '#fff3d6',\n sectionStroke: '#ffc943'\n },\n green: {\n fill: '#66d575',\n stroke: '#3e9b4b',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c79e',\n sectionFill: '#ddf8e2',\n sectionStroke: '#66d575'\n },\n teal: {\n fill: '#5ad8cc',\n stroke: '#369e94',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c9c6',\n sectionFill: '#defcfa',\n sectionStroke: '#5ad8cc'\n },\n blue: {\n fill: '#3dadff',\n stroke: '#007ad2',\n lightLabel: true,\n transparent: 0.7,\n transparentStroke: '#4d99d3',\n sectionFill: '#dbf0ff',\n sectionStroke: '#3dadff'\n },\n violet: {\n fill: '#874fff',\n stroke: '#5427b4',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a792d0',\n sectionFill: '#eae1ff',\n sectionStroke: '#874fff'\n },\n pink: {\n fill: '#f849c1',\n stroke: '#b42487',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#ce92bb',\n sectionFill: '#ffd6f2',\n sectionStroke: '#f849c1'\n },\n white: {\n fill: '#ffffff',\n stroke: '#757575',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f1f1f1',\n sectionFill: '#ffffff',\n sectionStroke: '#e6e6e6'\n },\n gray: {\n fill: '#b3b3b3',\n stroke: '#797979',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcbcbc',\n sectionFill: '#f4f4f4',\n sectionStroke: '#b3b3b3'\n },\n lightGray: {\n fill: '#d9d9d9',\n stroke: '#a5a5a5',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#c0c0c0',\n sectionFill: '#f9f9f9',\n sectionStroke: '#d9d9d9'\n },\n lightRed: {\n fill: '#ffc7c2',\n stroke: '#f24822',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#ff9d8f',\n sectionFill: '#fff5f5',\n sectionStroke: '#ffc7c2'\n },\n lightOrange: {\n fill: '#ffe0c2',\n stroke: '#ff9e42',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#f6c34d',\n sectionFill: '#fff7f0',\n sectionStroke: '#ffe0c2'\n },\n lightYellow: {\n fill: '#ffecbd',\n stroke: '#ffc943',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#efd54d',\n sectionFill: '#fffbf0',\n sectionStroke: '#ffecbd'\n },\n lightGreen: {\n fill: '#cdf4d3',\n stroke: '#66d575',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#a8d7b4',\n sectionFill: '#ebffee',\n sectionStroke: '#cdf4d3'\n },\n lightTeal: {\n fill: '#c6faf6',\n stroke: '#5ad8cc',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcebeb',\n sectionFill: '#f1fefd',\n sectionStroke: '#c6faf6'\n },\n lightBlue: {\n fill: '#c2e5ff',\n stroke: '#3dadff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#76ccff',\n sectionFill: '#f5fbff',\n sectionStroke: '#c2e5ff'\n },\n lightViolet: {\n fill: '#dcccff',\n stroke: '#874fff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#d5a3ff',\n sectionFill: '#f8f5ff',\n sectionStroke: '#dcccff'\n },\n lightPink: {\n fill: '#ffc2ec',\n stroke: '#f849c1',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#ffaaeb',\n sectionFill: '#fff0fa',\n sectionStroke: '#ffc2ec'\n }\n} as const\n\nexport type FigJamColorName = keyof typeof PALETTE\n\nexport const FIGJAM_COLOR_NAMES = Object.keys(PALETTE) as FigJamColorName[]\n\n/** How a shape's colour fills it: solid, see-through, or not at all, as FigJam's menu sets it. */\nexport type FigJamFillMode = 'fill' | 'transparent' | 'none'\n\n/** How a shape's outline is drawn, as FigJam's line menu sets it. */\nexport type FigJamLineStyle = 'solid' | 'dashed' | 'none'\n\n/** The dash FigJam's line menu draws a shape's outline with. */\nexport const FIGJAM_SHAPE_DASH = [16, 10] as const\n\n/** A palette colour as a colour. */\nexport function figJamColor(name: FigJamColorName): Color {\n return parseColor(PALETTE[name].fill)\n}\n\nfunction sameColor(a: Color | undefined, b: Color): boolean {\n if (!a) return false\n const close = (x: number, y: number) => Math.abs(x - y) < 1 / 512\n return close(a.r, b.r) && close(a.g, b.g) && close(a.b, b.b)\n}\n\n/** The palette colour a paint is, if any. */\nexport function figJamColorName(color: Color | undefined): FigJamColorName | null {\n return FIGJAM_COLOR_NAMES.find((name) => sameColor(color, figJamColor(name))) ?? null\n}\n\n/**\n * The palette colour an outline is drawn in: a colour itself, or the outline a section of that\n * colour takes, which is darker for black and lighter for white.\n */\nexport function figJamOutlineColorName(color: Color | undefined): FigJamColorName | null {\n return (\n figJamColorName(color) ??\n FIGJAM_COLOR_NAMES.find((name) => sameColor(color, parseColor(PALETTE[name].sectionStroke))) ??\n null\n )\n}\n\n/** The fill mode a shape's first fill shows. */\nexport function figJamFillMode(fill: Fill | undefined): FigJamFillMode {\n if (!fill || !fill.visible || fill.opacity === 0) return 'none'\n return fill.opacity < 1 ? 'transparent' : 'fill'\n}\n\n/** The outline FigJam pairs with a colour in a fill mode. */\nexport function figJamPairedStroke(name: FigJamColorName, mode: FigJamFillMode): Color {\n const entry = PALETTE[name]\n return parseColor(mode === 'fill' ? entry.stroke : entry.transparentStroke)\n}\n\n/** The label paint FigJam pairs with a colour in a fill mode. */\nfunction pairedLabel(name: FigJamColorName, mode: FigJamFillMode): Fill {\n const light = PALETTE[name].lightLabel && (mode === 'fill' || name === 'black') && mode !== 'none'\n return light\n ? { type: 'SOLID', color: { ...WHITE }, opacity: 1, visible: true }\n : { type: 'SOLID', color: { ...BLACK }, opacity: 0.8, visible: true }\n}\n\n/** How opaque FigJam fills a colour in a fill mode. */\nfunction fillOpacity(name: FigJamColorName, mode: FigJamFillMode): number {\n if (mode === 'transparent') return PALETTE[name].transparent\n return mode === 'fill' ? 1 : 0\n}\n\n/** What a shape with text and its label become when painted `name` in `mode`. */\nexport interface FigJamShapePaint {\n shape: Partial<SceneNode>\n label: Partial<SceneNode>\n}\n\n/**\n * A shape painted `name` in `mode`, as FigJam's colour menu paints it. The stroke and label follow\n * the colour only while they are still the ones FigJam paired with the current paint: a line or\n * text colour set by hand stays.\n */\nexport function figJamShapePaint(\n shape: Pick<SceneNode, 'fills' | 'strokes'>,\n label: Pick<SceneNode, 'fills'> | null,\n name: FigJamColorName,\n mode: FigJamFillMode\n): FigJamShapePaint {\n const fill = shape.fills.at(0)\n const current = figJamColorName(fill?.color)\n const currentMode = figJamFillMode(fill)\n const opacity = fillOpacity(name, mode)\n const result: FigJamShapePaint = {\n shape: { fills: [{ type: 'SOLID', color: figJamColor(name), opacity, visible: true }] },\n label: {}\n }\n const stroke = shape.strokes.at(0)\n const strokeFollows =\n !stroke || !current || sameColor(stroke.color, figJamPairedStroke(current, currentMode))\n if (stroke && strokeFollows) {\n result.shape.strokes = [\n { ...stroke, color: figJamPairedStroke(name, mode) },\n ...shape.strokes.slice(1)\n ]\n }\n const labelFill = label?.fills.at(0)\n const paired = current ? pairedLabel(current, currentMode) : null\n const labelFollows =\n !labelFill ||\n !paired ||\n (sameColor(labelFill.color, paired.color) &&\n Math.abs(labelFill.opacity - paired.opacity) < 0.01)\n if (label && labelFollows) result.label = { fills: [pairedLabel(name, mode)] }\n return result\n}\n\n/**\n * A shape's outline drawn `style`, as FigJam's line menu draws it; the weight stays. The dash is\n * the layer's, as files keep it, and each stroke's, as it is drawn.\n */\nexport function figJamLineStyleFields(\n shape: Pick<SceneNode, 'strokes'>,\n style: FigJamLineStyle\n): Partial<SceneNode> {\n const dashPattern = style === 'dashed' ? [...FIGJAM_SHAPE_DASH] : []\n const strokes = shape.strokes.map((stroke): Stroke => ({\n ...stroke,\n opacity: style === 'none' ? 0 : 1,\n dashPattern: [...dashPattern]\n }))\n return { strokes, dashPattern }\n}\n\n/** The line style a shape's outline shows. */\nexport function figJamLineStyle(shape: Pick<SceneNode, 'strokes'>): FigJamLineStyle {\n const stroke = shape.strokes.at(0)\n if (!stroke || !stroke.visible || stroke.opacity === 0) return 'none'\n return (stroke.dashPattern?.length ?? 0) > 0 ? 'dashed' : 'solid'\n}\n\n/**\n * A shape's outline in palette colour `name`, as FigJam's line menu colours it; a hidden outline\n * shows again, keeping its dash.\n */\nexport function figJamLineColorFields(\n shape: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const strokes =\n shape.strokes.length > 0\n ? shape.strokes.map((stroke): Stroke => ({ ...stroke, color, opacity: 1 }))\n : [\n {\n type: 'SOLID',\n color,\n opacity: 1,\n visible: true,\n weight: 4,\n align: 'CENTER'\n } satisfies Stroke\n ]\n return { strokes }\n}\n\n/** How heavy FigJam outlines a coloured section, and a coloured layer that had no stroke. */\nconst SECTION_STROKE_WEIGHT = 2\nconst LAYER_STROKE_WEIGHT = 1\n\n/** `strokes` recoloured, or a new stroke of `weight` when there are none. */\nfunction strokesIn(strokes: Stroke[], color: Color, weight: number): Stroke[] {\n if (strokes.length > 0) return strokes.map((stroke) => ({ ...stroke, type: 'SOLID', color }))\n return [{ type: 'SOLID', color, opacity: 1, visible: true, weight, align: 'INSIDE' }]\n}\n\n/** A section painted `name`, as FigJam's colour menu paints one: a pale tint outlined in the colour. */\nexport function figJamSectionColorFields(\n section: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const { sectionFill, sectionStroke } = PALETTE[name]\n return {\n fills: [{ type: 'SOLID', color: parseColor(sectionFill), opacity: 1, visible: true }],\n strokes: strokesIn(section.strokes, parseColor(sectionStroke), SECTION_STROKE_WEIGHT),\n strokeWeight: SECTION_STROKE_WEIGHT\n }\n}\n\n/**\n * The paint of `paints` the canvas shows on top: the last it draws, skipping hidden and fully\n * transparent ones, which show nothing.\n */\nfunction drawnPaint<P extends Fill>(paints: readonly P[]): P | undefined {\n return paints.findLast((paint) => paint.visible && paint.opacity > 0)\n}\n\n/** The palette colour a section is painted, by its tint. */\nexport function figJamSectionColorName(section: Pick<SceneNode, 'fills'>): FigJamColorName | null {\n const fill = drawnPaint(section.fills)?.color\n return (\n FIGJAM_COLOR_NAMES.find((name) => sameColor(fill, parseColor(PALETTE[name].sectionFill))) ??\n null\n )\n}\n\n/**\n * Whether a layer takes a palette colour as its stroke alone: a line, or a pen stroke, which is a\n * vector with nothing filled. A filled vector takes it as any other layer does.\n */\nfunction colorsStroke(node: Pick<SceneNode, 'type' | 'fills'>): boolean {\n if (node.type === 'LINE') return true\n return node.type === 'VECTOR' && !drawnPaint(node.fills)\n}\n\n/**\n * A plain layer painted `name`, as FigJam's colour menu paints one: text takes it as its fill, a\n * line or a pen stroke as its stroke, and any other layer as its fill and a stroke of the same\n * colour.\n */\nexport function figJamLayerColorFields(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes' | 'styleRuns'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const fills: Fill[] = [{ type: 'SOLID', color, opacity: 1, visible: true }]\n if (node.type === 'TEXT') {\n // The whole text takes the colour, ranges coloured on their own included.\n const styleRuns = node.styleRuns.map((run) => ({\n ...run,\n style: omit(run.style, ['fills', 'fillStyleId'])\n }))\n return { fills, styleRuns }\n }\n const strokes = strokesIn(node.strokes, color, LAYER_STROKE_WEIGHT)\n return colorsStroke(node) ? { strokes } : { fills, strokes }\n}\n\n/** The palette colour a plain layer shows, read where {@link figJamLayerColorFields} paints it. */\nexport function figJamLayerColorName(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes'>\n): FigJamColorName | null {\n const paints: Fill[] = colorsStroke(node) ? node.strokes : node.fills\n return figJamColorName(drawnPaint(paints)?.color)\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,UAAU;CACd,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,UAAU;EACR,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,KAAK;EACH,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;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,KAAK,CAAC,EAAE;CACxC,OACE,mBAAmB,MAAM,SAAS,UAAU,MAAM,WAAW,QAAQ,KAAK,CAAC,WAAW,CAAC,CAAC,KACxF;AAEJ;;;;;AAMA,SAAS,aAAa,MAAkD;CACtE,IAAI,KAAK,SAAS,QAAQ,OAAO;CACjC,OAAO,KAAK,SAAS,YAAY,CAAC,WAAW,KAAK,KAAK;AACzD;;;;;;AAOA,SAAgB,uBACd,MACA,MACoB;CACpB,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,QAAgB,CAAC;EAAE,MAAM;EAAS;EAAO,SAAS;EAAG,SAAS;CAAK,CAAC;CAC1E,IAAI,KAAK,SAAS,QAMhB,OAAO;EAAE;EAAO,WAJE,KAAK,UAAU,KAAK,SAAS;GAC7C,GAAG;GACH,OAAO,KAAK,IAAI,OAAO,CAAC,SAAS,aAAa,CAAC;EACjD,EACwB;CAAE;CAE5B,MAAM,UAAU,UAAU,KAAK,SAAS,OAAO,mBAAmB;CAClE,OAAO,aAAa,IAAI,IAAI,EAAE,QAAQ,IAAI;EAAE;EAAO;CAAQ;AAC7D;;AAGA,SAAgB,qBACd,MACwB;CAExB,OAAO,gBAAgB,WADA,aAAa,IAAI,IAAI,KAAK,UAAU,KAAK,KACxB,CAAC,EAAE,KAAK;AAClD"}
|
|
1
|
+
{"version":3,"file":"palette.js","names":[],"sources":["../../src/figjam/palette.ts"],"sourcesContent":["import { omit } from 'es-toolkit'\n\nimport { parseColor } from '../color'\nimport { BLACK, WHITE } from '../constants'\nimport type { Color } from '../primitives'\nimport type { Fill, SceneNode, Stroke } from '../types'\n\n/**\n * FigJam's board palette, in its menus' order, as its colour menu paints a shape with text: each\n * fill pairs with a darker stroke, a light label on the darkest fills, and, made transparent, a\n * lighter fill and its own stroke. Its line menu and connectors take the fills as line colours, and\n * a section takes a pale tint of each with the colour itself as its outline.\n */\nconst PALETTE = {\n black: {\n fill: '#1e1e1e',\n stroke: '#242424',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#929292',\n sectionFill: '#dddddd',\n sectionStroke: '#2c2c2c'\n },\n darkGray: {\n fill: '#757575',\n stroke: '#424242',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a1a1a1',\n sectionFill: '#eaeaea',\n sectionStroke: '#757575'\n },\n red: {\n fill: '#f24822',\n stroke: '#bd2915',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#c7968f',\n sectionFill: '#ffe2e0',\n sectionStroke: '#f24822'\n },\n orange: {\n fill: '#ff9e42',\n stroke: '#eb7500',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#e9b780',\n sectionFill: '#ffead6',\n sectionStroke: '#ff9e42'\n },\n yellow: {\n fill: '#ffc943',\n stroke: '#e8a302',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f5d280',\n sectionFill: '#fff3d6',\n sectionStroke: '#ffc943'\n },\n green: {\n fill: '#66d575',\n stroke: '#3e9b4b',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c79e',\n sectionFill: '#ddf8e2',\n sectionStroke: '#66d575'\n },\n teal: {\n fill: '#5ad8cc',\n stroke: '#369e94',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c9c6',\n sectionFill: '#defcfa',\n sectionStroke: '#5ad8cc'\n },\n blue: {\n fill: '#3dadff',\n stroke: '#007ad2',\n lightLabel: true,\n transparent: 0.7,\n transparentStroke: '#4d99d3',\n sectionFill: '#dbf0ff',\n sectionStroke: '#3dadff'\n },\n violet: {\n fill: '#874fff',\n stroke: '#5427b4',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a792d0',\n sectionFill: '#eae1ff',\n sectionStroke: '#874fff'\n },\n pink: {\n fill: '#f849c1',\n stroke: '#b42487',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#ce92bb',\n sectionFill: '#ffd6f2',\n sectionStroke: '#f849c1'\n },\n white: {\n fill: '#ffffff',\n stroke: '#757575',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f1f1f1',\n sectionFill: '#ffffff',\n sectionStroke: '#e6e6e6'\n },\n gray: {\n fill: '#b3b3b3',\n stroke: '#797979',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcbcbc',\n sectionFill: '#f4f4f4',\n sectionStroke: '#b3b3b3'\n },\n lightGray: {\n fill: '#d9d9d9',\n stroke: '#a5a5a5',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#c0c0c0',\n sectionFill: '#f9f9f9',\n sectionStroke: '#d9d9d9'\n },\n lightRed: {\n fill: '#ffc7c2',\n stroke: '#f24822',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#ff9d8f',\n sectionFill: '#fff5f5',\n sectionStroke: '#ffc7c2'\n },\n lightOrange: {\n fill: '#ffe0c2',\n stroke: '#ff9e42',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#f6c34d',\n sectionFill: '#fff7f0',\n sectionStroke: '#ffe0c2'\n },\n lightYellow: {\n fill: '#ffecbd',\n stroke: '#ffc943',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#efd54d',\n sectionFill: '#fffbf0',\n sectionStroke: '#ffecbd'\n },\n lightGreen: {\n fill: '#cdf4d3',\n stroke: '#66d575',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#a8d7b4',\n sectionFill: '#ebffee',\n sectionStroke: '#cdf4d3'\n },\n lightTeal: {\n fill: '#c6faf6',\n stroke: '#5ad8cc',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcebeb',\n sectionFill: '#f1fefd',\n sectionStroke: '#c6faf6'\n },\n lightBlue: {\n fill: '#c2e5ff',\n stroke: '#3dadff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#76ccff',\n sectionFill: '#f5fbff',\n sectionStroke: '#c2e5ff'\n },\n lightViolet: {\n fill: '#dcccff',\n stroke: '#874fff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#d5a3ff',\n sectionFill: '#f8f5ff',\n sectionStroke: '#dcccff'\n },\n lightPink: {\n fill: '#ffc2ec',\n stroke: '#f849c1',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#ffaaeb',\n sectionFill: '#fff0fa',\n sectionStroke: '#ffc2ec'\n }\n} as const\n\nexport type FigJamColorName = keyof typeof PALETTE\n\nexport const FIGJAM_COLOR_NAMES = Object.keys(PALETTE) as FigJamColorName[]\n\n/** How a shape's colour fills it: solid, see-through, or not at all, as FigJam's menu sets it. */\nexport type FigJamFillMode = 'fill' | 'transparent' | 'none'\n\n/** How a shape's outline is drawn, as FigJam's line menu sets it. */\nexport type FigJamLineStyle = 'solid' | 'dashed' | 'none'\n\n/** The dash FigJam's line menu draws a shape's outline with. */\nexport const FIGJAM_SHAPE_DASH = [16, 10] as const\n\n/** A palette colour as a colour. */\nexport function figJamColor(name: FigJamColorName): Color {\n return parseColor(PALETTE[name].fill)\n}\n\nfunction sameColor(a: Color | undefined, b: Color): boolean {\n if (!a) return false\n const close = (x: number, y: number) => Math.abs(x - y) < 1 / 512\n return close(a.r, b.r) && close(a.g, b.g) && close(a.b, b.b)\n}\n\n/** The palette colour a paint is, if any. */\nexport function figJamColorName(color: Color | undefined): FigJamColorName | null {\n return FIGJAM_COLOR_NAMES.find((name) => sameColor(color, figJamColor(name))) ?? null\n}\n\n/**\n * The palette colour an outline is drawn in: a colour itself, or the outline a section of that\n * colour takes, which is darker for black and lighter for white.\n */\nexport function figJamOutlineColorName(color: Color | undefined): FigJamColorName | null {\n return (\n figJamColorName(color) ??\n FIGJAM_COLOR_NAMES.find((name) => sameColor(color, parseColor(PALETTE[name].sectionStroke))) ??\n null\n )\n}\n\n/**\n * How FigJam draws a section's title on a board, measured in FigJam: a pill in the colour of the\n * outline drawn on top, with white text on the palette's darkest colours and black on the rest;\n * null for a section without an outline from the palette. `colorOf` reads an outline's colour as\n * drawn, such as a variable's value in the active mode.\n */\nexport function figJamSectionTitleColors(\n section: Pick<SceneNode, 'strokes'>,\n colorOf: (stroke: Stroke, index: number) => Color = (stroke) => stroke.color\n): { strokeIndex: number; background: Color; lightText: boolean } | null {\n const strokeIndex = section.strokes.findLastIndex(\n (stroke) => stroke.visible && stroke.opacity > 0\n )\n const outline = section.strokes.at(strokeIndex)\n if (strokeIndex === -1 || !outline) return null\n const color = colorOf(outline, strokeIndex)\n const name = figJamOutlineColorName(color)\n if (!name) return null\n return { strokeIndex, background: { ...color, a: 1 }, lightText: PALETTE[name].lightLabel }\n}\n\n/** The fill mode a shape's first fill shows. */\nexport function figJamFillMode(fill: Fill | undefined): FigJamFillMode {\n if (!fill || !fill.visible || fill.opacity === 0) return 'none'\n return fill.opacity < 1 ? 'transparent' : 'fill'\n}\n\n/** The outline FigJam pairs with a colour in a fill mode. */\nexport function figJamPairedStroke(name: FigJamColorName, mode: FigJamFillMode): Color {\n const entry = PALETTE[name]\n return parseColor(mode === 'fill' ? entry.stroke : entry.transparentStroke)\n}\n\n/** The label paint FigJam pairs with a colour in a fill mode. */\nfunction pairedLabel(name: FigJamColorName, mode: FigJamFillMode): Fill {\n const light = PALETTE[name].lightLabel && (mode === 'fill' || name === 'black') && mode !== 'none'\n return light\n ? { type: 'SOLID', color: { ...WHITE }, opacity: 1, visible: true }\n : { type: 'SOLID', color: { ...BLACK }, opacity: 0.8, visible: true }\n}\n\n/** How opaque FigJam fills a colour in a fill mode. */\nfunction fillOpacity(name: FigJamColorName, mode: FigJamFillMode): number {\n if (mode === 'transparent') return PALETTE[name].transparent\n return mode === 'fill' ? 1 : 0\n}\n\n/** What a shape with text and its label become when painted `name` in `mode`. */\nexport interface FigJamShapePaint {\n shape: Partial<SceneNode>\n label: Partial<SceneNode>\n}\n\n/**\n * A shape painted `name` in `mode`, as FigJam's colour menu paints it. The stroke and label follow\n * the colour only while they are still the ones FigJam paired with the current paint: a line or\n * text colour set by hand stays.\n */\nexport function figJamShapePaint(\n shape: Pick<SceneNode, 'fills' | 'strokes'>,\n label: Pick<SceneNode, 'fills'> | null,\n name: FigJamColorName,\n mode: FigJamFillMode\n): FigJamShapePaint {\n const fill = shape.fills.at(0)\n const current = figJamColorName(fill?.color)\n const currentMode = figJamFillMode(fill)\n const opacity = fillOpacity(name, mode)\n const result: FigJamShapePaint = {\n shape: { fills: [{ type: 'SOLID', color: figJamColor(name), opacity, visible: true }] },\n label: {}\n }\n const stroke = shape.strokes.at(0)\n const strokeFollows =\n !stroke || !current || sameColor(stroke.color, figJamPairedStroke(current, currentMode))\n if (stroke && strokeFollows) {\n result.shape.strokes = [\n { ...stroke, color: figJamPairedStroke(name, mode) },\n ...shape.strokes.slice(1)\n ]\n }\n const labelFill = label?.fills.at(0)\n const paired = current ? pairedLabel(current, currentMode) : null\n const labelFollows =\n !labelFill ||\n !paired ||\n (sameColor(labelFill.color, paired.color) &&\n Math.abs(labelFill.opacity - paired.opacity) < 0.01)\n if (label && labelFollows) result.label = { fills: [pairedLabel(name, mode)] }\n return result\n}\n\n/**\n * A shape's outline drawn `style`, as FigJam's line menu draws it; the weight stays. The dash is\n * the layer's, as files keep it, and each stroke's, as it is drawn.\n */\nexport function figJamLineStyleFields(\n shape: Pick<SceneNode, 'strokes'>,\n style: FigJamLineStyle\n): Partial<SceneNode> {\n const dashPattern = style === 'dashed' ? [...FIGJAM_SHAPE_DASH] : []\n const strokes = shape.strokes.map((stroke): Stroke => ({\n ...stroke,\n opacity: style === 'none' ? 0 : 1,\n dashPattern: [...dashPattern]\n }))\n return { strokes, dashPattern }\n}\n\n/** The line style a shape's outline shows. */\nexport function figJamLineStyle(shape: Pick<SceneNode, 'strokes'>): FigJamLineStyle {\n const stroke = shape.strokes.at(0)\n if (!stroke || !stroke.visible || stroke.opacity === 0) return 'none'\n return (stroke.dashPattern?.length ?? 0) > 0 ? 'dashed' : 'solid'\n}\n\n/**\n * A shape's outline in palette colour `name`, as FigJam's line menu colours it; a hidden outline\n * shows again, keeping its dash.\n */\nexport function figJamLineColorFields(\n shape: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const strokes =\n shape.strokes.length > 0\n ? shape.strokes.map((stroke): Stroke => ({ ...stroke, color, opacity: 1 }))\n : [\n {\n type: 'SOLID',\n color,\n opacity: 1,\n visible: true,\n weight: 4,\n align: 'CENTER'\n } satisfies Stroke\n ]\n return { strokes }\n}\n\n/** How heavy FigJam outlines a coloured section, and a coloured layer that had no stroke. */\nconst SECTION_STROKE_WEIGHT = 2\nconst LAYER_STROKE_WEIGHT = 1\n\n/** `strokes` recoloured, or a new stroke of `weight` when there are none. */\nfunction strokesIn(strokes: Stroke[], color: Color, weight: number): Stroke[] {\n if (strokes.length > 0) return strokes.map((stroke) => ({ ...stroke, type: 'SOLID', color }))\n return [{ type: 'SOLID', color, opacity: 1, visible: true, weight, align: 'INSIDE' }]\n}\n\n/** A section painted `name`, as FigJam's colour menu paints one: a pale tint outlined in the colour. */\nexport function figJamSectionColorFields(\n section: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const { sectionFill, sectionStroke } = PALETTE[name]\n // The outline shows in full at FigJam's 2, as its menu draws it, unless the line menu hid it.\n const strokes = strokesIn(section.strokes, parseColor(sectionStroke), SECTION_STROKE_WEIGHT).map(\n (stroke): Stroke =>\n stroke.opacity === 0\n ? stroke\n : { ...stroke, opacity: 1, visible: true, weight: SECTION_STROKE_WEIGHT }\n )\n return {\n fills: [{ type: 'SOLID', color: parseColor(sectionFill), opacity: 1, visible: true }],\n strokes,\n strokeWeight: SECTION_STROKE_WEIGHT\n }\n}\n\n/**\n * The paint of `paints` the canvas shows on top: the last it draws, skipping hidden and fully\n * transparent ones, which show nothing.\n */\nfunction drawnPaint<P extends Fill>(paints: readonly P[]): P | undefined {\n return paints.findLast((paint) => paint.visible && paint.opacity > 0)\n}\n\n/** The palette colour a section is painted, by its tint. */\nexport function figJamSectionColorName(section: Pick<SceneNode, 'fills'>): FigJamColorName | null {\n const fill = drawnPaint(section.fills)?.color\n return (\n FIGJAM_COLOR_NAMES.find((name) => sameColor(fill, parseColor(PALETTE[name].sectionFill))) ??\n null\n )\n}\n\n/**\n * Whether a layer takes a palette colour as its stroke alone: a line, or a pen stroke, which is a\n * vector with nothing filled. A filled vector takes it as any other layer does.\n */\nfunction colorsStroke(node: Pick<SceneNode, 'type' | 'fills'>): boolean {\n if (node.type === 'LINE') return true\n return node.type === 'VECTOR' && !drawnPaint(node.fills)\n}\n\n/**\n * A plain layer painted `name`, as FigJam's colour menu paints one: text takes it as its fill, a\n * line or a pen stroke as its stroke, and any other layer as its fill and a stroke of the same\n * colour.\n */\nexport function figJamLayerColorFields(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes' | 'styleRuns'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const fills: Fill[] = [{ type: 'SOLID', color, opacity: 1, visible: true }]\n if (node.type === 'TEXT') {\n // The whole text takes the colour, ranges coloured on their own included.\n const styleRuns = node.styleRuns.map((run) => ({\n ...run,\n style: omit(run.style, ['fills', 'fillStyleId'])\n }))\n return { fills, styleRuns }\n }\n const strokes = strokesIn(node.strokes, color, LAYER_STROKE_WEIGHT)\n return colorsStroke(node) ? { strokes } : { fills, strokes }\n}\n\n/** The palette colour a plain layer shows, read where {@link figJamLayerColorFields} paints it. */\nexport function figJamLayerColorName(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes'>\n): FigJamColorName | null {\n const paints: Fill[] = colorsStroke(node) ? node.strokes : node.fills\n return figJamColorName(drawnPaint(paints)?.color)\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,UAAU;CACd,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,UAAU;EACR,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,KAAK;EACH,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aA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,KACxF;AAEJ;;;;;AAMA,SAAS,aAAa,MAAkD;CACtE,IAAI,KAAK,SAAS,QAAQ,OAAO;CACjC,OAAO,KAAK,SAAS,YAAY,CAAC,WAAW,KAAK,KAAK;AACzD;;;;;;AAOA,SAAgB,uBACd,MACA,MACoB;CACpB,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,QAAgB,CAAC;EAAE,MAAM;EAAS;EAAO,SAAS;EAAG,SAAS;CAAK,CAAC;CAC1E,IAAI,KAAK,SAAS,QAMhB,OAAO;EAAE;EAAO,WAJE,KAAK,UAAU,KAAK,SAAS;GAC7C,GAAG;GACH,OAAO,KAAK,IAAI,OAAO,CAAC,SAAS,aAAa,CAAC;EACjD,EACwB;CAAE;CAE5B,MAAM,UAAU,UAAU,KAAK,SAAS,OAAO,mBAAmB;CAClE,OAAO,aAAa,IAAI,IAAI,EAAE,QAAQ,IAAI;EAAE;EAAO;CAAQ;AAC7D;;AAGA,SAAgB,qBACd,MACwB;CAExB,OAAO,gBAAgB,WADA,aAAa,IAAI,IAAI,KAAK,UAAU,KAAK,KACxB,CAAC,EAAE,KAAK;AAClD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SceneGraph } from "../graph.js";
|
|
2
2
|
import { NodeType, SceneNode } from "../types.js";
|
|
3
3
|
import { GeneratedFrameKind } from "./kind.js";
|
|
4
|
-
import { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextLabel, shapeWithTextLabelFields } from "./shape-with-text.js";
|
|
4
|
+
import { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextKindFields, shapeWithTextLabel, shapeWithTextLabelFields } from "./shape-with-text.js";
|
|
5
5
|
import { DEFAULT_STICKY_COLOR, STICKY_AUTHOR_FONT_SIZE, STICKY_BODY_FONT_SIZE, STICKY_COLORS, STICKY_FONT_FAMILY, STICKY_FONT_WEIGHT, STICKY_KIND, STICKY_SIZE, STICKY_SUBLAYER_LAYOUT, STICKY_WIDE_WIDTH, StickyContent, StickySublayers, StickyTextRole, buildStickySublayers, createSticky, isWideSticky, stickyFrameFields, stickyScale, stickyShadows, stickySublayers, stickyTextFields, stickyWidth } from "./sticky.js";
|
|
6
6
|
//#region src/generated/index.d.ts
|
|
7
7
|
/**
|
|
@@ -40,5 +40,5 @@ declare function layerRotates(node: Pick<SceneNode, 'type'>): boolean;
|
|
|
40
40
|
/** Whether a layer's resize handles and W and H fields resize it freely. */
|
|
41
41
|
declare function layerResizes(node: Pick<SceneNode, 'type'>): boolean;
|
|
42
42
|
//#endregion
|
|
43
|
-
export { DEFAULT_STICKY_COLOR, GENERATED_FRAME_TYPES, type GeneratedFrameKind, GeneratedFrameType, SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, STICKY_AUTHOR_FONT_SIZE, STICKY_BODY_FONT_SIZE, STICKY_COLORS, STICKY_FONT_FAMILY, STICKY_FONT_WEIGHT, STICKY_KIND, STICKY_SIZE, STICKY_SUBLAYER_LAYOUT, STICKY_WIDE_WIDTH, StickyContent, StickySublayers, StickyTextRole, buildShapeWithTextLabel, buildStickySublayers, createShapeWithText, createSticky, generatedFrameKind, generatedFrameOwner, generatedFrameText, isGeneratedFrame, isWideSticky, layerResizes, layerRotates, shapeWithTextFrameFields, shapeWithTextLabel, shapeWithTextLabelFields, stickyFrameFields, stickyScale, stickyShadows, stickySublayers, stickyTextFields, stickyWidth, withGeneratedFrameSize };
|
|
43
|
+
export { DEFAULT_STICKY_COLOR, GENERATED_FRAME_TYPES, type GeneratedFrameKind, GeneratedFrameType, SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, STICKY_AUTHOR_FONT_SIZE, STICKY_BODY_FONT_SIZE, STICKY_COLORS, STICKY_FONT_FAMILY, STICKY_FONT_WEIGHT, STICKY_KIND, STICKY_SIZE, STICKY_SUBLAYER_LAYOUT, STICKY_WIDE_WIDTH, StickyContent, StickySublayers, StickyTextRole, buildShapeWithTextLabel, buildStickySublayers, createShapeWithText, createSticky, generatedFrameKind, generatedFrameOwner, generatedFrameText, isGeneratedFrame, isWideSticky, layerResizes, layerRotates, shapeWithTextFrameFields, shapeWithTextKindFields, shapeWithTextLabel, shapeWithTextLabelFields, stickyFrameFields, stickyScale, stickyShadows, stickySublayers, stickyTextFields, stickyWidth, withGeneratedFrameSize };
|
|
44
44
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/generated/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CONNECTOR_KIND } from "../connectors/sublayers.js";
|
|
2
|
-
import { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextLabel, shapeWithTextLabelFields } from "./shape-with-text.js";
|
|
2
|
+
import { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextKindFields, shapeWithTextLabel, shapeWithTextLabelFields } from "./shape-with-text.js";
|
|
3
3
|
import { DEFAULT_STICKY_COLOR, STICKY_AUTHOR_FONT_SIZE, STICKY_BODY_FONT_SIZE, STICKY_COLORS, STICKY_FONT_FAMILY, STICKY_FONT_WEIGHT, STICKY_KIND, STICKY_SIZE, STICKY_SUBLAYER_LAYOUT, STICKY_WIDE_WIDTH, buildStickySublayers, createSticky, isWideSticky, stickyFrameFields, stickyScale, stickyShadows, stickySublayers, stickyTextFields, stickyWidth } from "./sticky.js";
|
|
4
4
|
//#region src/generated/index.ts
|
|
5
5
|
/**
|
|
@@ -53,6 +53,6 @@ function layerResizes(node) {
|
|
|
53
53
|
return generatedFrameKind(node)?.resizes ?? true;
|
|
54
54
|
}
|
|
55
55
|
//#endregion
|
|
56
|
-
export { DEFAULT_STICKY_COLOR, GENERATED_FRAME_TYPES, SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, STICKY_AUTHOR_FONT_SIZE, STICKY_BODY_FONT_SIZE, STICKY_COLORS, STICKY_FONT_FAMILY, STICKY_FONT_WEIGHT, STICKY_KIND, STICKY_SIZE, STICKY_SUBLAYER_LAYOUT, STICKY_WIDE_WIDTH, buildShapeWithTextLabel, buildStickySublayers, createShapeWithText, createSticky, generatedFrameKind, generatedFrameOwner, generatedFrameText, isGeneratedFrame, isWideSticky, layerResizes, layerRotates, shapeWithTextFrameFields, shapeWithTextLabel, shapeWithTextLabelFields, stickyFrameFields, stickyScale, stickyShadows, stickySublayers, stickyTextFields, stickyWidth, withGeneratedFrameSize };
|
|
56
|
+
export { DEFAULT_STICKY_COLOR, GENERATED_FRAME_TYPES, SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, STICKY_AUTHOR_FONT_SIZE, STICKY_BODY_FONT_SIZE, STICKY_COLORS, STICKY_FONT_FAMILY, STICKY_FONT_WEIGHT, STICKY_KIND, STICKY_SIZE, STICKY_SUBLAYER_LAYOUT, STICKY_WIDE_WIDTH, buildShapeWithTextLabel, buildStickySublayers, createShapeWithText, createSticky, generatedFrameKind, generatedFrameOwner, generatedFrameText, isGeneratedFrame, isWideSticky, layerResizes, layerRotates, shapeWithTextFrameFields, shapeWithTextKindFields, shapeWithTextLabel, shapeWithTextLabelFields, stickyFrameFields, stickyScale, stickyShadows, stickySublayers, stickyTextFields, stickyWidth, withGeneratedFrameSize };
|
|
57
57
|
|
|
58
58
|
//# sourceMappingURL=index.js.map
|
|
@@ -5,7 +5,7 @@ import { GeneratedFrameKind } from "./kind.js";
|
|
|
5
5
|
//#region src/generated/shape-with-text.d.ts
|
|
6
6
|
/** FigJam makes a shape with text 176 px square, from its tool and from its plugin API. */
|
|
7
7
|
declare const SHAPE_WITH_TEXT_SIZE = 176;
|
|
8
|
-
/** FigJam rounds every corner of a shape by 6 px. */
|
|
8
|
+
/** FigJam rounds every corner of a shape by 6 px, but a rounded rectangle's. */
|
|
9
9
|
declare const SHAPE_WITH_TEXT_CORNER_RADIUS = 6;
|
|
10
10
|
/** How the label sits in its shape: as wide as the label box, as tall as its text. */
|
|
11
11
|
declare const SHAPE_WITH_TEXT_LABEL_LAYOUT: {
|
|
@@ -18,6 +18,11 @@ declare const SHAPE_WITH_TEXT_LABEL_LAYOUT: {
|
|
|
18
18
|
* whenever either changes.
|
|
19
19
|
*/
|
|
20
20
|
declare function shapeWithTextFrameFields(kind: ShapeWithTextType, width: number, height: number): Partial<SceneNode>;
|
|
21
|
+
/**
|
|
22
|
+
* What turning a shape into `kind` changes, keeping its size, as FigJam's shape switcher does: the
|
|
23
|
+
* label area, and the corners a rounded rectangle leaves go back to FigJam's 6.
|
|
24
|
+
*/
|
|
25
|
+
declare function shapeWithTextKindFields(shape: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height'>, kind: ShapeWithTextType): Partial<SceneNode>;
|
|
21
26
|
/** The label's text style as FigJam starts it: Inter Medium at its Small size, black at 80%. */
|
|
22
27
|
declare function shapeWithTextLabelFields(): Partial<SceneNode>;
|
|
23
28
|
/** A shape's label: its one text sublayer. */
|
|
@@ -34,5 +39,5 @@ declare function buildShapeWithTextLabel(graph: SceneGraph, shape: SceneNode, pr
|
|
|
34
39
|
/** A new shape with text and its label; the caller lays it out to grow it to its text. */
|
|
35
40
|
declare function createShapeWithText(graph: SceneGraph, parentId: string, props?: Partial<SceneNode>, label?: Partial<SceneNode>): SceneNode;
|
|
36
41
|
//#endregion
|
|
37
|
-
export { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextLabel, shapeWithTextLabelFields };
|
|
42
|
+
export { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextKindFields, shapeWithTextLabel, shapeWithTextLabelFields };
|
|
38
43
|
//# sourceMappingURL=shape-with-text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape-with-text.d.ts","names":[],"sources":["../../src/generated/shape-with-text.ts"],"mappings":";;;;;;cAUa;;cAEA;;
|
|
1
|
+
{"version":3,"file":"shape-with-text.d.ts","names":[],"sources":["../../src/generated/shape-with-text.ts"],"mappings":";;;;;;cAUa;;cAEA;;cAWA;WAAA;WAAA;;;;;;;iBAUG,yBACd,MAAM,mBACN,eACA,iBACC,QAAQ;;;;;iBAwBK,wBACd,OAAO,KAAK,sDACZ,MAAM,oBACL,QAAQ;;iBAWK,4BAA4B,QAAQ;;iBAcpC,mBAAmB,OAAO,YAAY,OAAO,YAAY;;;;;;;cAc5D,sBAAsB;;iBAanB,wBACd,OAAO,YACP,OAAO,WACP,QAAO,QAAQ,aACd;;iBAea,oBACd,OAAO,YACP,kBACA,QAAO,QAAQ,YACf,QAAO,QAAQ,aACd"}
|
|
@@ -5,8 +5,13 @@ import { shapeWithTextLabelBox } from "../shape-with-text/fit.js";
|
|
|
5
5
|
//#region src/generated/shape-with-text.ts
|
|
6
6
|
/** FigJam makes a shape with text 176 px square, from its tool and from its plugin API. */
|
|
7
7
|
const SHAPE_WITH_TEXT_SIZE = 176;
|
|
8
|
-
/** FigJam rounds every corner of a shape by 6 px. */
|
|
8
|
+
/** FigJam rounds every corner of a shape by 6 px, but a rounded rectangle's. */
|
|
9
9
|
const SHAPE_WITH_TEXT_CORNER_RADIUS = 6;
|
|
10
|
+
/**
|
|
11
|
+
* FigJam keeps a rounded rectangle's corner radius at 0.4 of its shorter side, through resizes,
|
|
12
|
+
* measured in FigJam; Figma draws the shape from that radius.
|
|
13
|
+
*/
|
|
14
|
+
const ROUNDED_RECTANGLE_RADIUS = .4;
|
|
10
15
|
const LABEL_FILL = {
|
|
11
16
|
type: "SOLID",
|
|
12
17
|
color: { ...BLACK },
|
|
@@ -36,7 +41,19 @@ function shapeWithTextFrameFields(kind, width, height) {
|
|
|
36
41
|
paddingRight: Math.max(0, width - box.x - box.width),
|
|
37
42
|
paddingBottom: Math.max(0, height - box.y - box.height),
|
|
38
43
|
paddingLeft: box.x,
|
|
39
|
-
clipsContent: false
|
|
44
|
+
clipsContent: false,
|
|
45
|
+
...kind === "ROUNDED_RECTANGLE" ? { cornerRadius: ROUNDED_RECTANGLE_RADIUS * Math.min(width, height) } : {}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What turning a shape into `kind` changes, keeping its size, as FigJam's shape switcher does: the
|
|
50
|
+
* label area, and the corners a rounded rectangle leaves go back to FigJam's 6.
|
|
51
|
+
*/
|
|
52
|
+
function shapeWithTextKindFields(shape, kind) {
|
|
53
|
+
return {
|
|
54
|
+
shapeWithTextType: kind,
|
|
55
|
+
...shape.shapeWithTextType === "ROUNDED_RECTANGLE" && kind !== shape.shapeWithTextType ? { cornerRadius: 6 } : {},
|
|
56
|
+
...shapeWithTextFrameFields(kind, shape.width, shape.height)
|
|
40
57
|
};
|
|
41
58
|
}
|
|
42
59
|
/** The label's text style as FigJam starts it: Inter Medium at its Small size, black at 80%. */
|
|
@@ -113,6 +130,6 @@ function createShapeWithText(graph, parentId, props = {}, label = {}) {
|
|
|
113
130
|
return shape;
|
|
114
131
|
}
|
|
115
132
|
//#endregion
|
|
116
|
-
export { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextLabel, shapeWithTextLabelFields };
|
|
133
|
+
export { SHAPE_WITH_TEXT_CORNER_RADIUS, SHAPE_WITH_TEXT_KIND, SHAPE_WITH_TEXT_LABEL_LAYOUT, SHAPE_WITH_TEXT_SIZE, buildShapeWithTextLabel, createShapeWithText, shapeWithTextFrameFields, shapeWithTextKindFields, shapeWithTextLabel, shapeWithTextLabelFields };
|
|
117
134
|
|
|
118
135
|
//# sourceMappingURL=shape-with-text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape-with-text.js","names":[],"sources":["../../src/generated/shape-with-text.ts"],"sourcesContent":["import { BLACK } from '../constants'\nimport { FIGJAM_TYPEFACES, figJamTextSizeFields } from '../figjam/text'\nimport type { SceneGraph } from '../index'\nimport { shapeWithTextLabelBox } from '../shape-with-text/fit'\nimport type { ShapeWithTextType } from '../shape-with-text/kinds'\nimport { lineHeightPixels } from '../text/lengths'\nimport type { Fill, SceneNode } from '../types'\nimport type { GeneratedFrameKind } from './kind'\n\n/** FigJam makes a shape with text 176 px square, from its tool and from its plugin API. */\nexport const SHAPE_WITH_TEXT_SIZE = 176\n/** FigJam rounds every corner of a shape by 6 px. */\nexport const SHAPE_WITH_TEXT_CORNER_RADIUS = 6\n\nconst LABEL_FILL: Fill = { type: 'SOLID', color: { ...BLACK }, opacity: 0.8, visible: true }\n\n/** How the label sits in its shape: as wide as the label box, as tall as its text. */\nexport const SHAPE_WITH_TEXT_LABEL_LAYOUT = {\n textAutoResize: 'HEIGHT',\n layoutAlignSelf: 'STRETCH'\n} as const satisfies Partial<SceneNode>\n\n/**\n * The shape's own layout: a vertical auto layout that centres the label in the label box of its\n * kind, which the padding leaves free. The padding follows the kind and size, so it is set again\n * whenever either changes.\n */\nexport function shapeWithTextFrameFields(\n kind: ShapeWithTextType,\n width: number,\n height: number\n): Partial<SceneNode> {\n const box = shapeWithTextLabelBox(kind, width, height)\n return {\n layoutMode: 'VERTICAL',\n primaryAxisAlign: 'CENTER',\n counterAxisAlign: 'CENTER',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n paddingTop: box.y,\n paddingRight: Math.max(0, width - box.x - box.width),\n paddingBottom: Math.max(0, height - box.y - box.height),\n paddingLeft: box.x,\n clipsContent: false\n }\n}\n\n/** The label's text style as FigJam starts it: Inter Medium at its Small size, black at 80%. */\nexport function shapeWithTextLabelFields(): Partial<SceneNode> {\n return {\n name: 'Text',\n fontFamily: FIGJAM_TYPEFACES.simple.fontFamily,\n fontWeight: FIGJAM_TYPEFACES.simple.fontWeight,\n ...figJamTextSizeFields('small'),\n textAlignHorizontal: 'CENTER',\n textAlignVertical: 'TOP',\n fills: [{ ...LABEL_FILL, color: { ...LABEL_FILL.color } }],\n ...SHAPE_WITH_TEXT_LABEL_LAYOUT\n }\n}\n\n/** A shape's label: its one text sublayer. */\nexport function shapeWithTextLabel(graph: SceneGraph, shape: SceneNode): SceneNode | null {\n if (shape.type !== 'SHAPE_WITH_TEXT') return null\n const children = graph.getChildren(shape.id)\n if (children.length !== 1) return null\n const [label] = children\n return label.type === 'TEXT' ? label : null\n}\n\n/**\n * A shape with text edits its label in place, turns and resizes freely, and, as in FigJam, takes\n * its name from its label until it is named. A height set on it by a resize, a field or a script\n * is the height it was given, which layout grows it from when its label needs more room; once\n * that height changes, FigJam keeps it and truncates the label instead.\n */\nexport const SHAPE_WITH_TEXT_KIND: GeneratedFrameKind = {\n complete: (graph, frame) => shapeWithTextLabel(graph, frame) !== null,\n text: (graph, frame) => shapeWithTextLabel(graph, frame) ?? undefined,\n rotates: true,\n resizes: true,\n namedByText: true,\n sized: ({ height }, shape) =>\n height === undefined || height === shape.height\n ? {}\n : { shapeUserHeight: height, shapeTruncates: true }\n}\n\n/** Adds the label to a SHAPE_WITH_TEXT the caller created, styled as FigJam generates it. */\nexport function buildShapeWithTextLabel(\n graph: SceneGraph,\n shape: SceneNode,\n props: Partial<SceneNode> = {}\n): SceneNode {\n const box = shapeWithTextLabelBox(shape.shapeWithTextType, shape.width, shape.height)\n const fields = shapeWithTextLabelFields()\n return graph.createNode('TEXT', shape.id, {\n ...fields,\n x: box.x,\n y: box.y,\n width: box.width,\n height: lineHeightPixels(fields.lineHeight ?? null, fields.fontSize ?? 0) ?? undefined,\n text: '',\n ...props\n })\n}\n\n/** A new shape with text and its label; the caller lays it out to grow it to its text. */\nexport function createShapeWithText(\n graph: SceneGraph,\n parentId: string,\n props: Partial<SceneNode> = {},\n label: Partial<SceneNode> = {}\n): SceneNode {\n const kind = props.shapeWithTextType ?? 'SQUARE'\n const width = props.width ?? SHAPE_WITH_TEXT_SIZE\n const height = props.height ?? SHAPE_WITH_TEXT_SIZE\n const shape = graph.createNode('SHAPE_WITH_TEXT', parentId, {\n name: 'Shape with text',\n cornerRadius: SHAPE_WITH_TEXT_CORNER_RADIUS,\n ...props,\n shapeWithTextType: kind,\n width,\n height,\n shapeUserHeight: props.shapeUserHeight ?? height,\n ...shapeWithTextFrameFields(kind, width, height)\n })\n buildShapeWithTextLabel(graph, shape, label)\n return shape\n}\n"],"mappings":";;;;;;AAUA,MAAa,uBAAuB;;AAEpC,MAAa,gCAAgC;
|
|
1
|
+
{"version":3,"file":"shape-with-text.js","names":[],"sources":["../../src/generated/shape-with-text.ts"],"sourcesContent":["import { BLACK } from '../constants'\nimport { FIGJAM_TYPEFACES, figJamTextSizeFields } from '../figjam/text'\nimport type { SceneGraph } from '../index'\nimport { shapeWithTextLabelBox } from '../shape-with-text/fit'\nimport type { ShapeWithTextType } from '../shape-with-text/kinds'\nimport { lineHeightPixels } from '../text/lengths'\nimport type { Fill, SceneNode } from '../types'\nimport type { GeneratedFrameKind } from './kind'\n\n/** FigJam makes a shape with text 176 px square, from its tool and from its plugin API. */\nexport const SHAPE_WITH_TEXT_SIZE = 176\n/** FigJam rounds every corner of a shape by 6 px, but a rounded rectangle's. */\nexport const SHAPE_WITH_TEXT_CORNER_RADIUS = 6\n\n/**\n * FigJam keeps a rounded rectangle's corner radius at 0.4 of its shorter side, through resizes,\n * measured in FigJam; Figma draws the shape from that radius.\n */\nconst ROUNDED_RECTANGLE_RADIUS = 0.4\n\nconst LABEL_FILL: Fill = { type: 'SOLID', color: { ...BLACK }, opacity: 0.8, visible: true }\n\n/** How the label sits in its shape: as wide as the label box, as tall as its text. */\nexport const SHAPE_WITH_TEXT_LABEL_LAYOUT = {\n textAutoResize: 'HEIGHT',\n layoutAlignSelf: 'STRETCH'\n} as const satisfies Partial<SceneNode>\n\n/**\n * The shape's own layout: a vertical auto layout that centres the label in the label box of its\n * kind, which the padding leaves free. The padding follows the kind and size, so it is set again\n * whenever either changes.\n */\nexport function shapeWithTextFrameFields(\n kind: ShapeWithTextType,\n width: number,\n height: number\n): Partial<SceneNode> {\n const box = shapeWithTextLabelBox(kind, width, height)\n return {\n layoutMode: 'VERTICAL',\n primaryAxisAlign: 'CENTER',\n counterAxisAlign: 'CENTER',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n paddingTop: box.y,\n paddingRight: Math.max(0, width - box.x - box.width),\n paddingBottom: Math.max(0, height - box.y - box.height),\n paddingLeft: box.x,\n clipsContent: false,\n ...(kind === 'ROUNDED_RECTANGLE'\n ? { cornerRadius: ROUNDED_RECTANGLE_RADIUS * Math.min(width, height) }\n : {})\n }\n}\n\n/**\n * What turning a shape into `kind` changes, keeping its size, as FigJam's shape switcher does: the\n * label area, and the corners a rounded rectangle leaves go back to FigJam's 6.\n */\nexport function shapeWithTextKindFields(\n shape: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height'>,\n kind: ShapeWithTextType\n): Partial<SceneNode> {\n const leavesRounded =\n shape.shapeWithTextType === 'ROUNDED_RECTANGLE' && kind !== shape.shapeWithTextType\n return {\n shapeWithTextType: kind,\n ...(leavesRounded ? { cornerRadius: SHAPE_WITH_TEXT_CORNER_RADIUS } : {}),\n ...shapeWithTextFrameFields(kind, shape.width, shape.height)\n }\n}\n\n/** The label's text style as FigJam starts it: Inter Medium at its Small size, black at 80%. */\nexport function shapeWithTextLabelFields(): Partial<SceneNode> {\n return {\n name: 'Text',\n fontFamily: FIGJAM_TYPEFACES.simple.fontFamily,\n fontWeight: FIGJAM_TYPEFACES.simple.fontWeight,\n ...figJamTextSizeFields('small'),\n textAlignHorizontal: 'CENTER',\n textAlignVertical: 'TOP',\n fills: [{ ...LABEL_FILL, color: { ...LABEL_FILL.color } }],\n ...SHAPE_WITH_TEXT_LABEL_LAYOUT\n }\n}\n\n/** A shape's label: its one text sublayer. */\nexport function shapeWithTextLabel(graph: SceneGraph, shape: SceneNode): SceneNode | null {\n if (shape.type !== 'SHAPE_WITH_TEXT') return null\n const children = graph.getChildren(shape.id)\n if (children.length !== 1) return null\n const [label] = children\n return label.type === 'TEXT' ? label : null\n}\n\n/**\n * A shape with text edits its label in place, turns and resizes freely, and, as in FigJam, takes\n * its name from its label until it is named. A height set on it by a resize, a field or a script\n * is the height it was given, which layout grows it from when its label needs more room; once\n * that height changes, FigJam keeps it and truncates the label instead.\n */\nexport const SHAPE_WITH_TEXT_KIND: GeneratedFrameKind = {\n complete: (graph, frame) => shapeWithTextLabel(graph, frame) !== null,\n text: (graph, frame) => shapeWithTextLabel(graph, frame) ?? undefined,\n rotates: true,\n resizes: true,\n namedByText: true,\n sized: ({ height }, shape) =>\n height === undefined || height === shape.height\n ? {}\n : { shapeUserHeight: height, shapeTruncates: true }\n}\n\n/** Adds the label to a SHAPE_WITH_TEXT the caller created, styled as FigJam generates it. */\nexport function buildShapeWithTextLabel(\n graph: SceneGraph,\n shape: SceneNode,\n props: Partial<SceneNode> = {}\n): SceneNode {\n const box = shapeWithTextLabelBox(shape.shapeWithTextType, shape.width, shape.height)\n const fields = shapeWithTextLabelFields()\n return graph.createNode('TEXT', shape.id, {\n ...fields,\n x: box.x,\n y: box.y,\n width: box.width,\n height: lineHeightPixels(fields.lineHeight ?? null, fields.fontSize ?? 0) ?? undefined,\n text: '',\n ...props\n })\n}\n\n/** A new shape with text and its label; the caller lays it out to grow it to its text. */\nexport function createShapeWithText(\n graph: SceneGraph,\n parentId: string,\n props: Partial<SceneNode> = {},\n label: Partial<SceneNode> = {}\n): SceneNode {\n const kind = props.shapeWithTextType ?? 'SQUARE'\n const width = props.width ?? SHAPE_WITH_TEXT_SIZE\n const height = props.height ?? SHAPE_WITH_TEXT_SIZE\n const shape = graph.createNode('SHAPE_WITH_TEXT', parentId, {\n name: 'Shape with text',\n cornerRadius: SHAPE_WITH_TEXT_CORNER_RADIUS,\n ...props,\n shapeWithTextType: kind,\n width,\n height,\n shapeUserHeight: props.shapeUserHeight ?? height,\n ...shapeWithTextFrameFields(kind, width, height)\n })\n buildShapeWithTextLabel(graph, shape, label)\n return shape\n}\n"],"mappings":";;;;;;AAUA,MAAa,uBAAuB;;AAEpC,MAAa,gCAAgC;;;;;AAM7C,MAAM,2BAA2B;AAEjC,MAAM,aAAmB;CAAE,MAAM;CAAS,OAAO,EAAE,GAAG,MAAM;CAAG,SAAS;CAAK,SAAS;AAAK;;AAG3F,MAAa,+BAA+B;CAC1C,gBAAgB;CAChB,iBAAiB;AACnB;;;;;;AAOA,SAAgB,yBACd,MACA,OACA,QACoB;CACpB,MAAM,MAAM,sBAAsB,MAAM,OAAO,MAAM;CACrD,OAAO;EACL,YAAY;EACZ,kBAAkB;EACl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M,SACrC,CAAC,IACD;EAAE,iBAAiB;EAAQ,gBAAgB;CAAK;AACxD;;AAGA,SAAgB,wBACd,OACA,OACA,QAA4B,CAAC,GAClB;CACX,MAAM,MAAM,sBAAsB,MAAM,mBAAmB,MAAM,OAAO,MAAM,MAAM;CACpF,MAAM,SAAS,yBAAyB;CACxC,OAAO,MAAM,WAAW,QAAQ,MAAM,IAAI;EACxC,GAAG;EACH,GAAG,IAAI;EACP,GAAG,IAAI;EACP,OAAO,IAAI;EACX,QAAQ,iBAAiB,OAAO,cAAc,MAAM,OAAO,YAAY,CAAC,KAAK,KAAA;EAC7E,MAAM;EACN,GAAG;CACL,CAAC;AACH;;AAGA,SAAgB,oBACd,OACA,UACA,QAA4B,CAAC,GAC7B,QAA4B,CAAC,GAClB;CACX,MAAM,OAAO,MAAM,qBAAqB;CACxC,MAAM,QAAQ,MAAM,SAAA;CACpB,MAAM,SAAS,MAAM,UAAA;CACrB,MAAM,QAAQ,MAAM,WAAW,mBAAmB,UAAU;EAC1D,MAAM;EACN,cAAA;EACA,GAAG;EACH,mBAAmB;EACnB;EACA;EACA,iBAAiB,MAAM,mBAAmB;EAC1C,GAAG,yBAAyB,MAAM,OAAO,MAAM;CACjD,CAAC;CACD,wBAAwB,OAAO,OAAO,KAAK;CAC3C,OAAO;AACT"}
|
package/dist/geometry.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Rect, Vector } from "./primitives/index.js";
|
|
2
|
-
import { Effect, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from "./types.js";
|
|
2
|
+
import { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from "./types.js";
|
|
3
|
+
import { cubicPoint } from "./cubic.js";
|
|
3
4
|
//#region src/geometry.d.ts
|
|
4
5
|
declare function degToRad(degrees: number): number;
|
|
5
6
|
declare function radToDeg(radians: number): number;
|
|
@@ -37,6 +38,19 @@ interface StrokeShape {
|
|
|
37
38
|
strokeMiterLimit?: number;
|
|
38
39
|
}
|
|
39
40
|
declare function strokeOverflow(strokes?: Stroke[], fallbackCap?: StrokeCap, network?: VectorNetwork | null, shape?: StrokeShape): number;
|
|
41
|
+
/**
|
|
42
|
+
* The blur radius Figma draws: a negative one, which only a bound variable can give, draws as no
|
|
43
|
+
* blur, though the layer keeps the value.
|
|
44
|
+
*/
|
|
45
|
+
declare function drawnBlurRadius(radius: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,
|
|
48
|
+
* layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's
|
|
49
|
+
* SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).
|
|
50
|
+
*/
|
|
51
|
+
declare function blurSigma(radius: number): number;
|
|
52
|
+
/** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */
|
|
53
|
+
declare function blurRadiusForSigma(sigma: number): number;
|
|
40
54
|
declare function effectOverflow(effects?: Effect[]): {
|
|
41
55
|
left: number;
|
|
42
56
|
right: number;
|
|
@@ -48,58 +62,28 @@ declare function computeAbsoluteBounds(nodes: Iterable<{
|
|
|
48
62
|
width: number;
|
|
49
63
|
height: number;
|
|
50
64
|
}>, getAbsolutePosition: (id: string) => Vector): Rect;
|
|
51
|
-
declare function computeVisualBounds(nodes: Iterable<{
|
|
52
|
-
id: string;
|
|
53
|
-
width: number;
|
|
54
|
-
height: number;
|
|
55
|
-
rotation?: number;
|
|
56
|
-
strokes?: Stroke[];
|
|
57
|
-
strokeCap?: StrokeCap;
|
|
58
|
-
vectorNetwork?: VectorNetwork | null;
|
|
59
|
-
effects?: Effect[];
|
|
60
|
-
} & StrokeShape>, getAbsolutePosition: (id: string) => Vector): Rect;
|
|
61
|
-
interface VisualBoundsNode {
|
|
62
|
-
id: string;
|
|
63
|
-
width: number;
|
|
64
|
-
height: number;
|
|
65
|
-
rotation?: number;
|
|
66
|
-
flipX?: boolean;
|
|
67
|
-
flipY?: boolean;
|
|
68
|
-
strokes?: Stroke[];
|
|
69
|
-
strokeCap?: StrokeCap;
|
|
70
|
-
vectorNetwork?: VectorNetwork | null;
|
|
71
|
-
effects?: Effect[];
|
|
72
|
-
fillGeometry?: Array<{
|
|
73
|
-
commandsBlob: Uint8Array;
|
|
74
|
-
}>;
|
|
75
|
-
strokeGeometry?: Array<{
|
|
76
|
-
commandsBlob: Uint8Array;
|
|
77
|
-
}>;
|
|
78
|
-
childIds?: string[];
|
|
79
|
-
visible?: boolean;
|
|
80
|
-
type?: string;
|
|
81
|
-
clipsContent?: boolean;
|
|
82
|
-
fontSize?: number;
|
|
83
|
-
textDecoration?: string;
|
|
84
|
-
textUnderlineOffset?: number | null;
|
|
85
|
-
textDecorationThickness?: number | null;
|
|
86
|
-
derivedTextHeight?: number | null;
|
|
87
|
-
}
|
|
88
65
|
declare function unionVisualBounds(a: VisualBounds | null, b: VisualBounds | null): VisualBounds | null;
|
|
89
66
|
declare function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null;
|
|
67
|
+
/** The path commands of a Figma geometry blob, by their byte code. */
|
|
68
|
+
declare const GeometryCommand: {
|
|
69
|
+
readonly CLOSE: 0;
|
|
70
|
+
readonly MOVE: 1;
|
|
71
|
+
readonly LINE: 2;
|
|
72
|
+
readonly QUAD: 3;
|
|
73
|
+
readonly CUBIC: 4;
|
|
74
|
+
};
|
|
75
|
+
type GeometryCommand = (typeof GeometryCommand)[keyof typeof GeometryCommand];
|
|
90
76
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
77
|
+
* Walks a Figma geometry blob: `visit` gets each command, its coordinates as x, y pairs in one
|
|
78
|
+
* array reused between calls, and the byte offset of the first coordinate. It stops at an
|
|
79
|
+
* unknown command or one cut short.
|
|
94
80
|
*/
|
|
95
|
-
declare function
|
|
81
|
+
declare function readGeometryBlob(blob: Uint8Array, visit: (command: GeometryCommand, coords: readonly number[], offset: number) => void): void;
|
|
96
82
|
declare function geometryBlobBounds(paths: Array<{
|
|
97
83
|
commandsBlob: Uint8Array;
|
|
98
84
|
}>): Rect | null;
|
|
99
|
-
declare function nodeVisualBounds(node: VisualBoundsNode, getAbsolutePosition: (id: string) => Vector): VisualBounds;
|
|
100
85
|
/** How far a text node's underline or strikethrough reaches below its box. */
|
|
101
|
-
declare function textDecorationOverflow(node:
|
|
102
|
-
declare function computeDescendantVisualBounds(nodeIds: string[], getNode: (id: string) => VisualBoundsNode | undefined, getAbsolutePosition: (id: string) => Vector): VisualBounds | null;
|
|
86
|
+
declare function textDecorationOverflow(node: Pick<SceneNode, 'type' | 'fontSize' | 'textDecoration' | 'textUnderlineOffset' | 'textDecorationThickness'>): number;
|
|
103
87
|
//#endregion
|
|
104
|
-
export { StrokeShape, VisualBounds,
|
|
88
|
+
export { GeometryCommand, StrokeShape, VisualBounds, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, effectOverflow, geometryBlobBounds, intersectVisualBounds, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
|
|
105
89
|
//# sourceMappingURL=geometry.d.ts.map
|
package/dist/geometry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;;iBAMgB,SAAS;iBAIT,SAAS;iBAIT,YAAY,YAAY,YAAY,YAAY,YAAY,cAAc;iBAS1E,eACd,YACA,YACA,YACA,YACA,uBACE,QAAQ,QAAQ,QAAQ;iBAYZ,YACd,WACA,WACA,WACA,WACA;EACG;EAAc;EAAe;EAAa;EAAgB;EAAiB;;UAyB/D;EACf;EACA;EACA;EACA;;iBAgCc,cAAc,OAAO,SAAS,QAAQ;iBAMtC,gBAAgB;EAC9B;EACA;EACA;EACA;EACA;IACE;;;;;UA0Ba;EACf;EACA,aAAa;EACb;;iBAGc,eACd,UAAU,UACV,cAAc,WACd,UAAU,sBACV,QAAQ;;;;;iBAmEM,gBAAgB;;;;;;iBAWhB,UAAU;;iBAKV,mBAAmB;iBAInB,eAAe,UAAU;;;;;;iBAyBzB,sBACd,OAAO;EAAW;EAAY;EAAe;IAC7C,sBAAsB,eAAe,SACpC;iBASa,kBACd,GAAG,qBACH,GAAG,sBACF;iBAWa,sBAAsB,GAAG,cAAc,GAAG,eAAe;;cAS5D;;;;;;;KACD,0BAA0B,8BAA8B;;;;;;iBAmBpD,iBACd,MAAM,YACN,QAAQ,SAAS,iBAAiB,2BAA2B;iBAmB/C,mBAAmB,OAAO;EAAQ,cAAc;KAAgB;;iBAYhE,uBACd,MAAM,KACJ"}
|