chore (plugin-annotations) add cutlist title support back in
This commit is contained in:
parent
08d664e39b
commit
46b167ea34
1 changed files with 59 additions and 36 deletions
|
@ -1,8 +1,9 @@
|
|||
const titleMacro = function (so, { points, scale, locale, store }) {
|
||||
const titleMacro = function (so, { points, scale, locale, store, part }) {
|
||||
const prefix = so.prefix || ''
|
||||
let overwrite = !so.append
|
||||
|
||||
// Passing `false` will remove the title
|
||||
if (so === false) {
|
||||
if (so === false || overwrite) {
|
||||
for (const id of [
|
||||
`_${prefix}_titleNr`,
|
||||
`_${prefix}_titleName`,
|
||||
|
@ -11,7 +12,8 @@ const titleMacro = function (so, { points, scale, locale, store }) {
|
|||
`_${prefix}_exportDate`,
|
||||
])
|
||||
delete points[id]
|
||||
return true
|
||||
|
||||
if (so === false) return true
|
||||
}
|
||||
|
||||
const transform = function (anchor) {
|
||||
|
@ -20,44 +22,72 @@ const titleMacro = function (so, { points, scale, locale, store }) {
|
|||
|
||||
return `matrix(${so.scale}, 0, 0, ${so.scale}, ${cx}, ${cy}) rotate(${so.rotation} ${anchor.x} ${anchor.y})`
|
||||
}
|
||||
let shift = 8
|
||||
const nextPoint = (text, textClass, shiftAmt = shift) => {
|
||||
const newPoint = so.at.shift(-90 - so.rotation, shiftAmt * so.scale).addText(text, textClass)
|
||||
newPoint.attr('data-text-transform', transform(newPoint))
|
||||
return newPoint
|
||||
}
|
||||
const defaults = {
|
||||
scale: 1,
|
||||
rotation: 0,
|
||||
cutlist: true,
|
||||
}
|
||||
|
||||
so = { ...defaults, ...so }
|
||||
so.scale = so.scale * scale
|
||||
let overwrite = true
|
||||
if (so.append) overwrite = false
|
||||
|
||||
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-transform', transform(so.at))
|
||||
let shift = 8
|
||||
|
||||
if (so.title) {
|
||||
points[`_${prefix}_titleName`] = so.at
|
||||
.shift(-90 - so.rotation, shift * so.scale)
|
||||
.attr('data-text', so.title)
|
||||
.attr('data-text-class', 'text-lg fill-current font-bold')
|
||||
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, 13 * so.scale)))
|
||||
points[`_${prefix}_titleName`] = nextPoint(so.title, 'text-lg fill-current font-bold')
|
||||
shift += 8
|
||||
}
|
||||
|
||||
// Cut List instructions
|
||||
const partCutlist = store.get(['cutlist', part.name])
|
||||
// if there's a cutlist and it should be included
|
||||
if (so.cutlist && partCutlist?.materials) {
|
||||
// get the default cutonfold
|
||||
const cutonfold = partCutlist.cutOnFold
|
||||
// each material
|
||||
for (const material in partCutlist.materials) {
|
||||
// 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)
|
||||
|
||||
// if they're not identical, add that to the point's text
|
||||
if (!identical && cut > 1) cutPoint.addText('plugin:mirrored')
|
||||
|
||||
// if they should be cut on the fold add that, with bias or without
|
||||
if (cutonfold && !ignoreOnFold)
|
||||
cutPoint.addText(bias ? 'plugin:onFoldAndBias' : 'plugin:onFoldLower')
|
||||
// otherwise if they should be on the bias, say so
|
||||
else if (bias) cutPoint.addText('plugin:onBias')
|
||||
|
||||
// add 'from' the material
|
||||
cutPoint.addText('plugin:from').addText('plugin:' + material)
|
||||
|
||||
// save and shift
|
||||
points[`_${prefix}_titleCut_${material}_${c}`] = cutPoint
|
||||
shift += 8
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let name = store.data?.name || 'No Name'
|
||||
name = name.replace('@freesewing/', '')
|
||||
points[`_${prefix}_titlePattern`] = so.at
|
||||
.shift(-90 - so.rotation, shift * so.scale)
|
||||
.attr('data-text', name)
|
||||
.attr('data-text', 'v' + (store.data?.version || 'No Version'))
|
||||
.attr('data-text-class', 'fill-note')
|
||||
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
||||
name += ' v' + (store.data?.version || 'No Version')
|
||||
points[`_${prefix}_titlePattern`] = nextPoint(name, 'fill-note')
|
||||
|
||||
if (store.data.for) {
|
||||
shift += 8
|
||||
points[`_${prefix}_titleFor`] = so.at
|
||||
.shift(-90 - so.rotation, shift * so.scale)
|
||||
.attr('data-text', '( ' + store.data.for + ' )')
|
||||
.attr('data-text-class', 'fill-current font-bold')
|
||||
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
||||
points[`_${prefix}_titleFor`] = nextPoint(`( ${store.data.for} )`, 'fill-current font-bold')
|
||||
}
|
||||
shift += 6
|
||||
const now = new Date()
|
||||
|
@ -65,20 +95,13 @@ const titleMacro = function (so, { points, scale, locale, store }) {
|
|||
let mins = now.getMinutes()
|
||||
if (hours < 10) hours = `0${hours}`
|
||||
if (mins < 10) mins = `0${mins}`
|
||||
points[`_${prefix}_exportDate`] = so.at
|
||||
.shift(-90 - so.rotation, shift * so.scale)
|
||||
.attr(
|
||||
'data-text',
|
||||
now.toLocaleDateString(locale || 'en', {
|
||||
const exportDate = now.toLocaleDateString(locale || 'en', {
|
||||
weekday: 'long',
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
)
|
||||
.attr('data-text', `@ ${hours}:${mins}`)
|
||||
.attr('data-text-class', 'text-sm')
|
||||
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
||||
points[`_${prefix}_exportDate`] = nextPoint(`${exportDate}@ ${hours}:${mins}`, 'text-sm')
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue