@tyrsolutions/quasar-app-extension-qogimage
v0.0.1
Published
A Quasar App Extension
Downloads
3
Readme
Quasar App Extension qogimage
The QOGImage App Extension allows you to seamlessly add the QOGImage component into your Quasar application. It manages the boot file file and all other configuration for you.
Currently this component converts any template to svg. Work is being done to replicate the same functionality of Nuxt-ogimage component in quasar.
Install
quasar ext add @tyrsolutions/qogimage
Quasar CLI will retrieve it from NPM and install the extension.
Uninstall
quasar ext remove qogimage
Info
The app extension will add a component QOGImage
and a directive v-q-og-image
to the quasar app globally. Both do the same thing, generate a dynamic svg from a vue template, but work in different ways. The component is just that, a component, while the directive allows you to specify an html tag to apply the image to.
Component QOGImage
The component uses satori and satori-html to generate an svg image of a vue component file. By adding the component to your template with QOGImage
and providing attributes
:template="{imported temlate goes here}"
along with
:templateProps="{template props object}"
and
:config="{satori configuration object}"
the template provided will recieve the props, then be converted to html string. This string is then applied to a vue render function returned by the component.
Directive v-q-og-image
Similar to above, though the three component element attributes are wrapped into an object and directive can be added to most html tags with an object
{
template: ogTemplate,
templateProps: tempProps,
config: config,
}
provided to it.
Usage
Quasar CLI project
Install the App Extension.
OR:
Create and register a boot file:
import Vue from 'vue'
import Plugin from '@tyrsolutions/quasar-ui-qogimage'
Vue.use(Plugin)
OR:
<template>
<QOGImage :template="{imported temlate goes here}" :templateProps="{template props object}" :config="{satori configuration object}" />
<div v-q-og-image="{ template: {imported temlate goes here}, templateProps: {template props object}, config: {satori configuration object}, }"></div>
</template>
<script>
import { Component as QOGImage, Directive } from '@tyrsolutions/quasar-ui-qogimage'
imp
export default {
components: {
QOGImage
},
directives: {
Directive
}
}
</script>
Vue CLI project
import Vue from 'vue'
import Plugin from '@tyrsolutions/quasar-ui-qogimage'
Vue.use(Plugin)
OR:
<template>
<QOGImage :template="{imported temlate goes here}" :templateProps="{template props object}" config: config />
<div v-q-og-image="{ template: ogTemplate, templateProps: tempProps, config: config }"></div>
</template>
<script>
import { Component as QOGImage, Directive } from '@tyrsolutions/quasar-ui-qogimage'
export default {
components: {
QOGImage
},
directives: {
Directive
}
}
</script>
Component & Directive inputs
Both component and directive expect 3 seperate objects:
Template
The template object, is a vue component import. Simply import the template and add it to the directive or component.
Template props
The props object expects an object of key / value pairs that will match your template props. These props then get passed to the template when rendered, before the template is converted to svg.
Config
The config requires a modified satori configuraiton object. As of right now, the only difference is the fonts attribute of the config object. Normally satori expects an array buffer of a font file, which satori requires, for generating the svg file and is part of teh svg calculations. As of right now, the data attribute of the font declaration is removed and url attribute added. The object looks something like:
{
height: 628,
width: 1200,
fonts: [
{
name: 'Roboto',
url: 'https://cdn.jsdelivr.net/fontsource/fonts/roboto@latest/latin-400-normal.ttf',
weight: 400,
style: 'normal',
},
],
}
The url field will be used to fetch the font file, create an array buffer of it, and pass it to satori as a data attribute. Multiple font declarations may be used in the fonts array and each one will be converted for satori.
License
MIT (c) Matthew Marino [email protected]