feat(Emoji): Functions improvements (#673)
- Introduced `format] argument for `parse` function - New `iconId(text)` function
This commit is contained in:
parent
9741f98b70
commit
1b25ddd2b5
@ -14,17 +14,26 @@ QtObject {
|
|||||||
"small": "18x18",
|
"small": "18x18",
|
||||||
"verySmall": "16x16"
|
"verySmall": "16x16"
|
||||||
}
|
}
|
||||||
|
readonly property var format: {
|
||||||
|
"png": "png",
|
||||||
|
"svg": "svg"
|
||||||
|
}
|
||||||
property string base: Qt.resolvedUrl("../../../assets/twemoji/")
|
property string base: Qt.resolvedUrl("../../../assets/twemoji/")
|
||||||
function parse(text, renderSize = size.small) {
|
|
||||||
|
function parse(text, renderSize = size.small, renderFormat = format.svg) {
|
||||||
const renderSizes = renderSize.split("x");
|
const renderSizes = renderSize.split("x");
|
||||||
if (!renderSize.includes("x") || renderSizes.length !== 2) {
|
if (!renderSize.includes("x") || renderSizes.length !== 2) {
|
||||||
throw new Error("Invalid value for 'renderSize' parameter: ", renderSize);
|
throw new Error("Invalid value for 'renderSize' parameter: ", renderSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
Twemoji.twemoji.base = base
|
const path = renderFormat == format.svg ? "svg/" : "72x72/"
|
||||||
Twemoji.twemoji.ext = ".svg"
|
Twemoji.twemoji.base = base + path
|
||||||
Twemoji.twemoji.size = "svg"
|
Twemoji.twemoji.ext = `.${renderFormat}`
|
||||||
|
|
||||||
return Twemoji.twemoji.parse(text, {
|
return Twemoji.twemoji.parse(text, {
|
||||||
|
callback: (iconId, options) => {
|
||||||
|
return options.base + iconId + options.ext;
|
||||||
|
},
|
||||||
attributes: function() {
|
attributes: function() {
|
||||||
return {
|
return {
|
||||||
width: renderSizes[0],
|
width: renderSizes[0],
|
||||||
@ -34,6 +43,10 @@ QtObject {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function iconId(text) {
|
||||||
|
const parsed = parse(text);
|
||||||
|
return parsed.match('src=".*\/(.+?).svg')[1]
|
||||||
|
}
|
||||||
function fromCodePoint(value) {
|
function fromCodePoint(value) {
|
||||||
return Twemoji.twemoji.convert.fromCodePoint(value)
|
return Twemoji.twemoji.convert.fromCodePoint(value)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user