2022-09-09 12:13:52 -05:00
|
|
|
import { name, version } from '../data.mjs'
|
2018-07-22 18:54:58 +02:00
|
|
|
|
2022-07-15 11:58:10 +02:00
|
|
|
const style = `
|
|
|
|
text.title-nr {
|
|
|
|
font-size: 24pt;
|
|
|
|
font-weight: 700;
|
|
|
|
text-anchor: middle;
|
|
|
|
dominant-baseline: reset-size;
|
|
|
|
}
|
|
|
|
text.title-name {
|
|
|
|
font-size: 7pt;
|
|
|
|
font-weight: 500;
|
|
|
|
text-anchor: middle;
|
|
|
|
dominant-baseline: reset-size;
|
|
|
|
}
|
|
|
|
text.title-pattern {
|
|
|
|
font-size: 4pt;
|
|
|
|
font-weight: 500;
|
|
|
|
dominant-baseline: reset-size;
|
|
|
|
text-anchor: middle;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2022-08-28 14:06:01 +02:00
|
|
|
export const plugin = {
|
|
|
|
name,
|
|
|
|
version,
|
2018-07-22 18:54:58 +02:00
|
|
|
hooks: {
|
2022-01-19 16:23:40 +01:00
|
|
|
preRender: (svg) => {
|
2022-08-28 14:06:01 +02:00
|
|
|
if (svg.style.indexOf(`test.title-nr`) === -1) svg.style += style
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
2018-07-26 07:18:21 +00:00
|
|
|
},
|
|
|
|
macros: {
|
2022-09-27 14:08:32 +02:00
|
|
|
title: function (so, { points, scale, locale, store }) {
|
2022-08-28 14:06:01 +02:00
|
|
|
const prefix = so.prefix || ''
|
2022-07-10 16:04:58 +02:00
|
|
|
|
|
|
|
// Passing `false` will remove the title
|
|
|
|
if (so === false) {
|
|
|
|
for (const id of [
|
|
|
|
`_${prefix}_titleNr`,
|
|
|
|
`_${prefix}_titleName`,
|
|
|
|
`_${prefix}_titlePattern`,
|
|
|
|
`_${prefix}_titleFor`,
|
2022-08-29 17:42:51 +02:00
|
|
|
`_${prefix}_exportDate`,
|
2022-07-10 16:04:58 +02:00
|
|
|
])
|
2022-09-27 14:08:32 +02:00
|
|
|
delete points[id]
|
2022-07-10 16:04:58 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-08-30 11:51:22 +02:00
|
|
|
const transform = function (anchor) {
|
2021-11-27 16:46:38 +01:00
|
|
|
const cx = anchor.x - so.scale * anchor.x
|
|
|
|
const cy = anchor.y - so.scale * anchor.y
|
2018-12-22 17:20:04 +01:00
|
|
|
|
2019-08-03 15:03:33 +02:00
|
|
|
return `matrix(${so.scale}, 0, 0, ${so.scale}, ${cx}, ${cy}) rotate(${so.rotation} ${anchor.x} ${anchor.y})`
|
|
|
|
}
|
2021-11-27 16:46:38 +01:00
|
|
|
const defaults = {
|
2018-12-22 17:20:04 +01:00
|
|
|
scale: 1,
|
2021-04-24 10:16:31 +02:00
|
|
|
rotation: 0,
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|
2022-08-25 11:13:36 +02:00
|
|
|
|
2019-08-03 15:03:33 +02:00
|
|
|
so = { ...defaults, ...so }
|
2022-09-27 14:08:32 +02:00
|
|
|
so.scale = so.scale * scale
|
2019-08-03 15:03:33 +02:00
|
|
|
let overwrite = true
|
|
|
|
if (so.append) overwrite = false
|
2022-09-27 14:08:32 +02:00
|
|
|
points[`_${prefix}_titleNr`] = so.at
|
2018-12-08 15:12:00 +01:00
|
|
|
.clone()
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('data-text', so.nr, overwrite)
|
2021-12-29 09:16:47 +01:00
|
|
|
.attr('data-text-class', 'text-4xl fill-note font-bold')
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('data-text-transform', transform(so.at))
|
2022-01-18 16:26:51 +01:00
|
|
|
let shift = 8
|
2018-12-08 15:12:00 +01:00
|
|
|
if (so.title) {
|
2022-09-27 14:08:32 +02:00
|
|
|
points[`_${prefix}_titleName`] = so.at
|
2022-01-18 16:26:51 +01:00
|
|
|
.shift(-90 - so.rotation, shift * so.scale)
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('data-text', so.title)
|
2021-12-29 09:16:47 +01:00
|
|
|
.attr('data-text-class', 'text-lg fill-current font-bold')
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, 13 * so.scale)))
|
2022-01-18 16:26:51 +01:00
|
|
|
shift += 8
|
2018-09-10 12:07:36 +02:00
|
|
|
}
|
2022-09-27 14:08:32 +02:00
|
|
|
let name = store.data?.name || 'No Name'
|
2022-09-01 09:41:54 -07:00
|
|
|
name = name.replace('@freesewing/', '')
|
2022-09-27 14:08:32 +02:00
|
|
|
points[`_${prefix}_titlePattern`] = so.at
|
2018-12-22 17:20:04 +01:00
|
|
|
.shift(-90 - so.rotation, shift * so.scale)
|
2022-09-01 09:41:54 -07:00
|
|
|
.attr('data-text', name)
|
2022-09-27 14:08:32 +02:00
|
|
|
.attr('data-text', 'v' + (store.data?.version || 'No Version'))
|
2021-12-24 14:48:25 +01:00
|
|
|
.attr('data-text-class', 'fill-note')
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
2022-09-27 14:08:32 +02:00
|
|
|
if (store.data.for) {
|
2020-03-08 11:10:38 +01:00
|
|
|
shift += 8
|
2022-09-27 14:08:32 +02:00
|
|
|
points[`_${prefix}_titleFor`] = so.at
|
2020-03-08 11:10:38 +01:00
|
|
|
.shift(-90 - so.rotation, shift * so.scale)
|
2022-09-27 14:08:32 +02:00
|
|
|
.attr('data-text', '( ' + store.data.for + ' )')
|
2021-12-29 09:16:47 +01:00
|
|
|
.attr('data-text-class', 'fill-current font-bold')
|
2020-03-08 11:10:38 +01:00
|
|
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
|
|
|
}
|
2022-08-04 11:46:15 -07:00
|
|
|
shift += 6
|
2022-08-03 11:30:45 -07:00
|
|
|
const now = new Date()
|
2022-08-25 11:13:36 +02:00
|
|
|
let hours = now.getHours()
|
|
|
|
let mins = now.getMinutes()
|
|
|
|
if (hours < 10) hours = `0${hours}`
|
|
|
|
if (mins < 10) mins = `0${mins}`
|
2022-09-27 14:08:32 +02:00
|
|
|
points[`_${prefix}_exportDate`] = so.at
|
2022-08-03 11:30:45 -07:00
|
|
|
.shift(-90 - so.rotation, shift * so.scale)
|
2022-09-07 10:57:47 +02:00
|
|
|
.attr(
|
|
|
|
'data-text',
|
2022-09-27 14:08:32 +02:00
|
|
|
now.toLocaleDateString(locale || 'en', {
|
2022-09-07 10:57:47 +02:00
|
|
|
weekday: 'long',
|
|
|
|
year: 'numeric',
|
|
|
|
month: 'short',
|
|
|
|
day: 'numeric',
|
|
|
|
})
|
|
|
|
)
|
2022-08-25 11:13:36 +02:00
|
|
|
.attr('data-text', `@ ${hours}:${mins}`)
|
2022-08-04 10:16:30 -07:00
|
|
|
.attr('data-text-class', 'text-sm')
|
2022-08-03 11:30:45 -07:00
|
|
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|
2022-08-28 14:06:01 +02:00
|
|
|
|
|
|
|
// More specifically named exports
|
|
|
|
export const titlePlugin = plugin
|
|
|
|
export const pluginTitle = plugin
|