2019-08-03 15:03:33 +02:00
|
|
|
import style from './lib/style'
|
|
|
|
import { version, name } from '../package.json'
|
2018-07-22 18:54:58 +02:00
|
|
|
|
2018-07-26 07:18:21 +00:00
|
|
|
export default {
|
2018-08-07 16:50:10 +02:00
|
|
|
name: name,
|
|
|
|
version: version,
|
2018-07-22 18:54:58 +02:00
|
|
|
hooks: {
|
2021-11-27 16:46:38 +01:00
|
|
|
preRender: svg => {
|
2019-08-03 15:03:33 +02:00
|
|
|
if (svg.attributes.get('freesewing:plugin-title') === false) {
|
|
|
|
svg.attributes.set('freesewing:plugin-title', version)
|
|
|
|
svg.style += style
|
2018-12-08 17:44:30 +01:00
|
|
|
}
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
2018-07-26 07:18:21 +00:00
|
|
|
},
|
|
|
|
macros: {
|
2020-08-30 11:51:22 +02:00
|
|
|
title: function (so) {
|
|
|
|
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
|
|
|
}
|
|
|
|
so = { ...defaults, ...so }
|
|
|
|
let overwrite = true
|
|
|
|
if (so.append) overwrite = false
|
|
|
|
let prefix = ''
|
|
|
|
if (so.prefix) prefix = so.prefix
|
2018-09-10 12:07:36 +02:00
|
|
|
this.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))
|
|
|
|
let shift = 10
|
2018-12-08 15:12:00 +01:00
|
|
|
if (so.title) {
|
2018-09-10 12:07:36 +02:00
|
|
|
this.points[`_${prefix}_titleName`] = so.at
|
2018-12-22 17:20:04 +01:00
|
|
|
.shift(-90 - so.rotation, 13 * 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)))
|
|
|
|
shift += 10
|
2018-09-10 12:07:36 +02:00
|
|
|
}
|
|
|
|
this.points[`_${prefix}_titlePattern`] = so.at
|
2018-12-22 17:20:04 +01:00
|
|
|
.shift(-90 - so.rotation, shift * so.scale)
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('data-text', this.context.config.name)
|
|
|
|
.attr('data-text', 'v' + this.context.config.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)))
|
2020-03-08 11:10:38 +01:00
|
|
|
if (this.context.settings.metadata && this.context.settings.metadata.for) {
|
|
|
|
shift += 8
|
|
|
|
this.points[`_${prefix}_titleFor`] = so.at
|
|
|
|
.shift(-90 - so.rotation, shift * so.scale)
|
|
|
|
.attr('data-text', '( ' + this.context.settings.metadata.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)))
|
|
|
|
}
|
2020-08-30 11:51:22 +02:00
|
|
|
if (this.context.config.cut && this.context.config.cut[this.name]) {
|
|
|
|
shift += 8
|
|
|
|
let cid = `_${prefix}_titleCut`
|
|
|
|
let cut = this.context.config.cut[this.name]
|
|
|
|
this.points[cid] = so.at
|
|
|
|
.shift(-90 - so.rotation, shift * so.scale)
|
|
|
|
.attr('data-text', 'cut')
|
|
|
|
.attr('data-text-class', 'title-pattern')
|
|
|
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
|
|
|
if (typeof cut === 'number') this.points[cid].attr('data-text', ` ${cut}x`)
|
|
|
|
else if (Array.isArray(cut)) {
|
|
|
|
cut = Array.from(cut) // Don't change the original array
|
|
|
|
this.points[cid].attr('data-text', ` ${cut.shift()}x`)
|
|
|
|
for (const txt of cut) this.points[cid].attr('data-text', txt)
|
|
|
|
}
|
|
|
|
}
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|