2023-09-29 18:20:28 +02:00
|
|
|
// __SDEFILE__ - This file is a dependency for the stand-alone environment
|
2023-06-07 10:06:30 -05:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2023-06-01 18:28:22 +02:00
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
export const getProps = (obj) => {
|
|
|
|
/** I can't believe it but there seems to be no method on NPM todo this */
|
|
|
|
const cssKey = (key) => {
|
|
|
|
let chunks = key.split('-')
|
|
|
|
if (chunks.length > 1) {
|
|
|
|
key = chunks.shift()
|
|
|
|
for (let s of chunks) key += s.charAt(0).toUpperCase() + s.slice(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
|
|
|
|
const convert = (css) => {
|
|
|
|
let style = {}
|
|
|
|
let rules = css.split(';')
|
|
|
|
for (let rule of rules) {
|
|
|
|
let chunks = rule.split(':')
|
|
|
|
if (chunks.length === 2) style[cssKey(chunks[0].trim())] = chunks[1].trim()
|
|
|
|
}
|
|
|
|
return style
|
|
|
|
}
|
|
|
|
|
|
|
|
let rename = {
|
|
|
|
class: 'className',
|
|
|
|
'marker-start': 'markerStart',
|
|
|
|
'marker-end': 'markerEnd',
|
|
|
|
}
|
|
|
|
let props = {}
|
|
|
|
for (let key in obj.attributes.list) {
|
|
|
|
if (key === 'style') props[key] = convert(obj.attributes.list[key].join(' '))
|
|
|
|
if (Object.keys(rename).indexOf(key) !== -1)
|
|
|
|
props[rename[key]] = obj.attributes.list[key].join(' ')
|
|
|
|
else if (key !== 'style') props[key] = obj.attributes.list[key].join(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
return props
|
|
|
|
}
|
|
|
|
|
|
|
|
export const withinPartBounds = (point, part) =>
|
|
|
|
point.x >= part.topLeft.x &&
|
|
|
|
point.x <= part.bottomRight.x &&
|
|
|
|
point.y >= part.topLeft.y &&
|
|
|
|
point.y <= part.bottomRight.y
|
|
|
|
? true
|
|
|
|
: false
|
|
|
|
|
|
|
|
export const getId = ({
|
2023-06-02 18:21:40 +02:00
|
|
|
settings = {},
|
2023-06-01 18:28:22 +02:00
|
|
|
stackName = false,
|
|
|
|
partName = false,
|
|
|
|
pathName = false,
|
|
|
|
pointName = false,
|
|
|
|
snippetName = false,
|
|
|
|
name = false,
|
|
|
|
}) => {
|
|
|
|
let id = settings.idPrefix || ''
|
|
|
|
if (stackName) id += `${stackName}-`
|
|
|
|
if (partName) id += `${partName}-`
|
|
|
|
if (pathName) id += `${pathName}-`
|
|
|
|
if (pointName) id += `${pointName}-`
|
|
|
|
if (snippetName) id += `${snippetName}-`
|
|
|
|
if (name) id += name
|
|
|
|
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
export const translateStrings = (t, list) => {
|
|
|
|
let translated = ''
|
|
|
|
for (const string of list) {
|
feat: Support notes in title macro
This started out as a fix for #5753 after I felt the approach in #5760
was not the best way to handle this.
The problem lies in the way the cutlist data is added to the pattern by
the title plugin. The whole cutlist thing was added by a less
experienced contributor, and they were a little too focussed on what
they were trying to accomplish, rather than keeping an eye on the big
picture.
In this case, a bunch of points get added to the part to anchor all of
the text for the cutlist. This causes problems when inheriting parts
because points are added per material, and now we don't know what
materials were used and how to remove these points.
I appreciate @woutervdub effort to resolve this in #5760 but as I
mentioned above, I don't love the approach.
Rather than finding a clever way to remove these points, I am of the
opinion that they should never have been added in the first place.
Specifically, all we are doing is adding one or more lines of text. The
idea that you need multiple points for this is an incorrect assumption,
and therein lies the root of this problem.
So, this refactor adds support to the title macro for 'notes'. These
notes will be added below the title. The cutlist info is now just
prepended to the notes. So it stops being something 'special' (which it
never should have been) and instead just behaves like other text that is
placed on the part by the title macro.
The only flanking measure required to make this happen was to add
support for nested arrays in handling text.
This way, you can pass a nested array to concatenate strings in such a
way that each part will still be individually translated.
And as all text in FreeSewing, to force a linebreak, you just use "\n"
as The Dark Lord intended.
2024-01-06 17:54:11 +01:00
|
|
|
if (Array.isArray(string)) translated += translateStrings(t, string)
|
|
|
|
else if (string) translated += t(string.toString()).replace(/"/g, '"') + ' '
|
2023-06-01 18:28:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return translated
|
|
|
|
}
|