From bf81c089f658ebf8cc8413e0e12d875f0a8224e9 Mon Sep 17 00:00:00 2001 From: XiNGRZ Date: Mon, 1 Apr 2024 00:01:29 +0800 Subject: [PATCH] Clean up parsing of rows --- src/components/BSMap.vue | 14 +++------- src/components/BSMap/BSCell.vue | 16 +++++------ src/components/BSMap/BSIcon.vue | 47 +++++++++++++-------------------- src/components/BSMap/BSRow.vue | 41 +++++++++------------------- src/components/BSMap/BSText.vue | 9 ++++--- src/utils/splitWithOffset.ts | 8 ++++++ 6 files changed, 54 insertions(+), 81 deletions(-) create mode 100644 src/utils/splitWithOffset.ts diff --git a/src/components/BSMap.vue b/src/components/BSMap.vue index 3ebf17c..62bea1b 100644 --- a/src/components/BSMap.vue +++ b/src/components/BSMap.vue @@ -1,6 +1,6 @@ @@ -11,6 +11,8 @@ import { defineProps, } from 'vue'; +import { max } from 'radash'; + import BSRow from './BSMap/BSRow.vue'; const props = defineProps<{ @@ -19,15 +21,7 @@ const props = defineProps<{ }>(); const rows = computed(() => props.content.split('\n')); - -const cols = computed(() => { - let cols = 0; - for (const row of rows.value) { - const c = Math.max(cols, row.split('\\').length); - if (c > cols) cols = c; - } - return cols; -}); +const cols = computed(() => max(rows.value.map((row) => row.split('\\').length)) || 1); const style = computed(() => ({ '--bs-map-size': props.size, diff --git a/src/components/BSMap/BSCell.vue b/src/components/BSMap/BSCell.vue index 5582073..d74dfe4 100644 --- a/src/components/BSMap/BSCell.vue +++ b/src/components/BSMap/BSCell.vue @@ -1,7 +1,7 @@