Skip to content

Commit

Permalink
added style for non solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Nicolle committed Oct 31, 2023
1 parent 2c7cf06 commit f54651c
Show file tree
Hide file tree
Showing 18 changed files with 2,792 additions and 75 deletions.
1,318 changes: 1,318 additions & 0 deletions client/public/test-db-4.json

Large diffs are not rendered by default.

1,330 changes: 1,330 additions & 0 deletions client/public/test-db-5.json

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { Grid } from 'grid';
import { Idatabase, SupaDB, setDatabase } from 'database';
import axios from 'axios';
const debugMigration = false;
const debugMigration = true;
class API {
public idb: Idatabase;
public supadb: SupaDB;
public _mode: string;
constructor(mode: string = 'unknown') {
let prepromise: Promise<unknown> = Promise.resolve();
if (debugMigration) {
prepromise = prepromise
.then(() => axios.get('/test-db.json'))
.then(({ data }) => setDatabase(data, 4))
}
this.idb = new Idatabase(prepromise);
// axios.get('/test-db-5.json')
// .then(({ data }) => {
// setDatabase(data, 5)
// });
this.idb = new Idatabase();
this.supadb = new SupaDB('https://tnvxmrqhkdlynhtdzmpw.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InRudnhtcnFoa2RseW5odGR6bXB3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODIyNTM0MTEsImV4cCI6MTk5NzgyOTQxMX0.4PczPPAxbkwBvig7NTHNbR8JumuwPPqfyS_kGnkxP5I');
this._mode = mode;
}
Expand Down
11 changes: 9 additions & 2 deletions client/src/components/fonts/FontLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</template>

<script setup lang="ts">
import { defineProps, ref } from "vue";
import { defineProps, onMounted, ref } from "vue";
import { watch } from "vue";
import { loadFont } from "./load-font";
import axios from "axios";
Expand All @@ -15,7 +15,8 @@ const props = defineProps<{
isEmbedded?: boolean;
}>();
const url = ref<string | null>(null);
watch([props], () => {
function update() {
const { value } = props;
if (isGoogleFont(value)) {
let weightUrl = `https://fonts.googleapis.com/css?family=${value.family}:${value.weight}`;
Expand All @@ -31,6 +32,12 @@ watch([props], () => {
}
url.value = null;
loadFont(value);
}
watch([props], () => {
update();
});
onMounted(() => {
update();
});
</script>

Expand Down
2 changes: 2 additions & 0 deletions client/src/components/fonts/FontSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
v-else
:role="`${rolePrefix}-size`"
v-model:value="value.size"
:precision="2"
:step="0.1"
/>
</n-form-item>
<n-form-item :label="$t('forms.color')" path="color">
Expand Down
17 changes: 14 additions & 3 deletions client/src/components/fonts/load-font.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { LocalFont } from "grid";
import { api } from "../../api";
export const loadedFonts = new Set();

export function loadFont(font: LocalFont) {
const fontface = new FontFace(font.family, `url(${font.content})`);
return fontface.load()
.then((fontface) => document.fonts.add(fontface));
if (loadedFonts.has(font.family)) {
return Promise.resolve();
}
return api.db.getFont(font.family)
.then((font) => {
const fontface = new FontFace(font.family, `url(${font.content})`);
return fontface.load();
})
.then((fontface) => {
loadedFonts.add(font.family);
document.fonts.add(fontface);
});
}
14 changes: 13 additions & 1 deletion client/src/components/forms/GridStyleForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
<n-input-number role="space" v-model:value="value.grid.spaceSize" />
</n-form-item>
</div>
<h3>{{ $t("forms.solutions") }}</h3>
<FontSelector v-model="value.solutions" role-prefix="solutions" />
<n-form-item :label="$t('forms.offset')" path="top">
<n-input-number
v-model:value="value.solutions.top"
:step="0.5"
:precision="1"
role="solutions-top"
/>
</n-form-item>
<div v-if="definition">
<h3>{{ $t("forms.definitions") }}</h3>
<FontSelector v-model="value.definition" rolePrefix="definition" />
Expand Down Expand Up @@ -126,7 +136,9 @@ const emit = defineEmits<{
(event: "update:modelValue", value: GridStyle): void;
}>();
const value = useModel<GridStyle>(props, emit);
watch(value.value, () => {
emit("update:modelValue", value.value);
});
</script>

<style scoped>
Expand Down
40 changes: 27 additions & 13 deletions client/src/components/svg-renderer/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
@mouseout="onMouseLeave"
xmlns="http://www.w3.org/2000/svg"
>
<FontLoader :value="style.definition"/>
<FontLoader :value="style.definition" />
<FontLoader v-if="isSolutionStyle(style)" :value="style.solutions" />
<defs></defs>
<g
class="cells"
Expand Down Expand Up @@ -60,10 +61,13 @@
</text>
<text
:x="xText(cell)"
:y="yText(cell) + (6 * cellWidth(style)) / 7"
:font-family="textFont"
:y="yText(cell) + cellWidth(style) / 2 + textTopOffset"
alignment-baseline="central"
dominant-baseline="center"
:font-family="textFontFamily"
:font-weight="textFontWeight"
:fill="textFontColor"
:font-size="textSize"
dominant-baseline="alphabetic"
v-else-if="!cell.definition && exportOptions.texts"
>
{{ cell.text || cell.suggestion }}
Expand Down Expand Up @@ -182,6 +186,8 @@ import {
getLines,
arrowPositions,
ArrowDir,
SolutionStyle,
isSolutionStyle,
} from "grid";
import { ExportOptions } from "../../types";
import { getCellClass } from "../../js/utils";
Expand All @@ -197,7 +203,7 @@ const props = defineProps<{
/**
* The style of the grid
*/
style: GridStyle;
style: SolutionStyle | GridStyle;
/**
* The focused cell (can be nullCell)
*/
Expand Down Expand Up @@ -237,9 +243,20 @@ const lineColor = computed(() => props.style.grid.borderColor);
const spaceStroke = computed(() => props.style.grid.spaceSize);
const outerLineStroke = computed(() => props.style.grid.outerBorderSize);
const outerLineColor = computed(() => props.style.grid.outerBorderColor);
const defSize = computed(() => props.style.definition.size);
const textSize = computed(() => props.style.grid.cellSize);
const textFont = computed(() => `roboto`);
const defSize = computed(
() => (props.style.grid.cellSize / 4) * props.style.definition.size
);
const textSize = computed(() => {
return (
(isSolutionStyle(props.style) ? props.style.solutions.size : 1) *
props.style.grid.cellSize
);
});
const textFontFamily = computed(() => props.style.solutions.family);
const textFontWeight = computed(() => props.style.solutions.weight);
const textFontColor = computed(() => props.style.solutions.color);
const textTopOffset = computed(() => props.style.solutions.top);
const defFontFamily = computed(() => `${props.style.definition.family}`);
const defFontWeight = computed(() => `${props.style.definition.weight}`);
Expand Down Expand Up @@ -313,8 +330,7 @@ const splits = computed(() =>
ratio * cellWidth(props.style);
return {
x1: cell.x * cellAndBorderWidth(props.style),
x2:
cell.x * cellAndBorderWidth(props.style) + cellWidth(props.style),
x2: cell.x * cellAndBorderWidth(props.style) + cellWidth(props.style),
y1: y,
y2: y,
};
Expand Down Expand Up @@ -352,9 +368,7 @@ const spaces = computed(() => {
});
function xText(cell: Cell) {
return (
cell.x * cellAndBorderWidth(props.style) + cellWidth(props.style) / 2
);
return cell.x * cellAndBorderWidth(props.style) + cellWidth(props.style) / 2;
}
function yText(cell: Cell) {
return cell.y * cellAndBorderWidth(props.style);
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/languages/en-en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const lang = {
randomize: "Randomize",
fontFamily: "Font family",
fontWeight: "Font weight",
offset: "Offset",
},
tooltips: {
incomplete: "is incomplete",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/languages/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const lang = {
randomize: "Randomizar",
fontFamily: "Fuente",
fontWeight: "Peso",
offset: "Desplazamiento",
},
tooltips: {
incomplete: "esta incompleto",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/languages/fr-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const lang = {
randomize: "Regénérer",
fontFamily: "Police",
fontWeight: "Epaisseur",
offset: "Décalage",

},
tooltips: {
Expand Down
2 changes: 0 additions & 2 deletions client/src/views/Fonts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ function onUpload(filesContents: [string, string][]) {
.replace(/\..*/, "")
.replace(/[^\w]/gi, "")
.replace(/[0-9]+/gi, "");
debugger;
return api.db.pushFont({
id: uuid(),
family,
updated: Date.now(),
content: dataURL,
Expand Down
5 changes: 3 additions & 2 deletions client/src/views/editors/SolutionsEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Layout>
<template #left-panel v-if="grids.length && style">
<OptionsForm v-model="style" @update:modelValue="save" grid format>
<SolutionsForm v-model="style" @update:modelValue="save" />
<SolutionsForm v-model="style" @update:modelValue="save"/>
</OptionsForm>
</template>
<template #body>
Expand Down Expand Up @@ -81,10 +81,11 @@ function fetch() {
}
function save() {
console.log("on update");
clearTimeout(saveTimeout.value);
saveTimeout.value = +setTimeout(() => {
if (!style.value) return;
// api.db.pushStyle(toRaw(style.value) as unknown as SolutionStyle);
api.db.pushStyle(toRaw(style.value) as unknown as SolutionStyle);
}, 100);
}
Expand Down
1 change: 1 addition & 0 deletions client/src/views/editors/StyleEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function fetch() {
}
function onUpdate() {
console.log('on update');
clearTimeout(saveTimeout.value);
saveTimeout.value = setTimeout(() => {
if (!style.value) return;
Expand Down
Loading

0 comments on commit f54651c

Please sign in to comment.