From e972c7279355b4d808e5bd2221658f149941bc58 Mon Sep 17 00:00:00 2001 From: Benjamin F Date: Thu, 4 May 2023 15:24:48 -0700 Subject: [PATCH] enhancement(title): Add alignment property --- markdown/dev/reference/macros/title/en.md | 2 ++ plugins/plugin-annotations/src/title.mjs | 25 +++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/markdown/dev/reference/macros/title/en.md b/markdown/dev/reference/macros/title/en.md index 6c1049221b2..acdd7abb95e 100644 --- a/markdown/dev/reference/macros/title/en.md +++ b/markdown/dev/reference/macros/title/en.md @@ -9,6 +9,7 @@ It is provided by the [annotations plugin](/reference/plugins/annotations). ```js macro('title', { + String align, Boolean append, Point at, Boolean cutlist @@ -51,6 +52,7 @@ macro('title', { | Property | Default | Type | Description | | ----------:| :-----: | ------------------- | ----------- | +| `align' | 'left' | String | Horizontal text alignment. Valid values: 'left', 'right', 'center' | | `append` | `false` | Boolean | Set this to `true` to append the `nr` to any text already set in Point `at`'s attributes, rather than overwrite it | | `at` | | [Point](/reference/api/point) | The point at which to insert the title | | `cutlist` | `true` | Boolean | Whether to include cutting instructions | diff --git a/plugins/plugin-annotations/src/title.mjs b/plugins/plugin-annotations/src/title.mjs index 51c3ef5b3c1..f21a85362b6 100644 --- a/plugins/plugin-annotations/src/title.mjs +++ b/plugins/plugin-annotations/src/title.mjs @@ -32,19 +32,26 @@ const titleMacro = function (so, { points, scale, locale, store, part }) { scale: 1, rotation: 0, cutlist: true, + align: 'left', } so = { ...defaults, ...so } so.scale = so.scale * scale + const validAlignments = ['left', 'right', 'center'] + const alignment = validAlignments.includes(so.align) ? ' ' + so.align : ' left' + points[`_${prefix}_titleNr`] = so.at .clone() .attr('data-text', so.nr, overwrite) - .attr('data-text-class', 'text-4xl fill-note font-bold') + .attr('data-text-class', 'text-4xl fill-note font-bold' + alignment) .attr('data-text-transform', transform(so.at)) if (so.title) { - points[`_${prefix}_titleName`] = nextPoint(so.title, 'text-lg fill-current font-bold') + points[`_${prefix}_titleName`] = nextPoint( + so.title, + 'text-lg fill-current font-bold' + alignment + ) shift += 8 } @@ -59,7 +66,7 @@ const titleMacro = function (so, { points, scale, locale, store, part }) { // each set of instructions partCutlist.materials[material].forEach(({ cut, identical, bias, ignoreOnFold }, c) => { // make a new point for this set of instructions - const cutPoint = nextPoint('plugin:cut', 'text-md fill-current').addText(cut) + const cutPoint = nextPoint('plugin:cut', 'text-md fill-current' + alignment).addText(cut) // if they're not identical, add that to the point's text if (!identical && cut > 1) cutPoint.addText('plugin:mirrored') @@ -83,11 +90,14 @@ const titleMacro = function (so, { points, scale, locale, store, part }) { let name = store.data?.name || 'No Name' name = name.replace('@freesewing/', '') name += ' v' + (store.data?.version || 'No Version') - points[`_${prefix}_titlePattern`] = nextPoint(name, 'fill-note') + points[`_${prefix}_titlePattern`] = nextPoint(name, 'fill-note' + alignment) if (store.data.for) { shift += 8 - points[`_${prefix}_titleFor`] = nextPoint(`( ${store.data.for} )`, 'fill-current font-bold') + points[`_${prefix}_titleFor`] = nextPoint( + `( ${store.data.for} )`, + 'fill-current font-bold' + alignment + ) } shift += 6 const now = new Date() @@ -101,7 +111,10 @@ const titleMacro = function (so, { points, scale, locale, store, part }) { month: 'short', day: 'numeric', }) - points[`_${prefix}_exportDate`] = nextPoint(`${exportDate}@ ${hours}:${mins}`, 'text-sm') + points[`_${prefix}_exportDate`] = nextPoint( + `${exportDate}@ ${hours}:${mins}`, + 'text-sm' + alignment + ) } // Export macros