+
@@ -17,6 +17,7 @@
import { computed, defineProps } from 'vue';
import { useEditorStore } from '@/stores/editor';
+import styleFromParams from '@/utils/styleFromParams';
import BSCell from './BSCell.vue';
import BSText from './BSText.vue';
@@ -47,7 +48,7 @@ const cells = computed(() => {
});
const texts = computed(() => {
- const texts = parts.value.slice(1)
+ const texts = parts.value.slice(1, 5)
.map(({ part, offset }, i) => ({ text: part, offset, align: i + 1 }));
// Shorthand that the only text is treated as the main (the 2nd) text
@@ -58,6 +59,8 @@ const texts = computed(() => {
return texts.filter(({ text }) => text != '' && text != ' ');
});
+const rowStyle = computed(() => styleFromParams(parts.value[5]?.part));
+
function isFocused(row: number, offset: number, length: number): boolean {
const { selection } = editorStore;
return (
diff --git a/src/utils/styleFromParams.ts b/src/utils/styleFromParams.ts
new file mode 100644
index 0000000..a591f37
--- /dev/null
+++ b/src/utils/styleFromParams.ts
@@ -0,0 +1,51 @@
+import { parse } from 'qs';
+import type { CSSProperties } from 'vue';
+
+const YES = ['1', 'yes', 'y', 'true'];
+const LEFT = ['l', 'left'];
+const RIGHT = ['r', 'right'];
+const TOP_LEFT = ['la', 'tl', 'c4', 'nw', 'top-left', 'topleft'];
+const TOP_RIGHT = ['ra', 'tr', 'c1', 'ne', 'top-right', 'topright'];
+const BOTTOM_LEFT = ['le', 'bl', 'c3', 'sw', 'bottom-left', 'bottomleft'];
+const BOTTOM_RIGHT = ['re', 'br', 'c2', 'se', 'bottom-right', 'bottomright'];
+
+export default function styleFromParams(text: string | undefined): CSSProperties {
+ const style = {} as CSSProperties;
+ const params = parse(text ?? '', { delimiter: ',' }) as Record;
+
+ if (params.bg) {
+ style.backgroundColor = params.bg;
+ } else if (params.background) {
+ style.backgroundColor = params.background;
+ } else if (params.bgcolor) {
+ style.backgroundColor = params.bgcolor;
+ }
+
+ if (params.color) {
+ style.color = params.color;
+ } else if (params.colour) {
+ style.color = params.colour;
+ }
+
+ if (YES.includes(params.b ?? params.bold)) {
+ style.fontWeight = 'bold';
+ }
+
+ if (YES.includes(params.i ?? params.it ?? params.italic)) {
+ style.fontStyle = 'italic';
+ }
+
+ if ([...LEFT, ...TOP_LEFT].includes(params.align)) {
+ style['--bs-map-cell-halign'] = 'left';
+ } else if ([...RIGHT, ...TOP_RIGHT].includes(params.align)) {
+ style['--bs-map-cell-halign'] = 'right';
+ }
+
+ if ([...TOP_LEFT, ...TOP_RIGHT].includes(params.align)) {
+ style['--bs-map-cell-valign'] = 'top';
+ } else if ([...BOTTOM_LEFT, ...BOTTOM_RIGHT].includes(params.align)) {
+ style['--bs-map-cell-valign'] = 'bottom';
+ }
+
+ return style;
+}