Renaming general.utils to general.util

This commit is contained in:
Peaceultime 2025-01-29 22:51:55 +01:00
parent f32c51ca38
commit f3c453b1b2
19 changed files with 26 additions and 33 deletions

View File

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import type { Position } from '#shared/canvas.util'; import { type Position, InfiniteGrid } from '#shared/canvas.util';
import type CanvasNodeEditor from './canvas/CanvasNodeEditor.vue'; import type CanvasNodeEditor from './canvas/CanvasNodeEditor.vue';
import type CanvasEdgeEditor from './canvas/CanvasEdgeEditor.vue'; import type CanvasEdgeEditor from './canvas/CanvasEdgeEditor.vue';
export type Element = { type: 'node' | 'edge', id: string }; export type Element = { type: 'node' | 'edge', id: string };
@ -52,15 +52,11 @@ function distance(touches: TouchList): number
const [A, B] = touches; const [A, B] = touches;
return Math.hypot(B.clientX - A.clientX, B.clientY - A.clientY); return Math.hypot(B.clientX - A.clientX, B.clientY - A.clientY);
} }
function contains(group: CanvasNode, node: CanvasNode): boolean
{
return group.x < node.x && group.y < node.y && group.x + group.width > node.x + node.width && group.y + group.height > node.y + node.height;
}
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import { Icon } from '@iconify/vue/dist/iconify.js'; import { Icon } from '@iconify/vue/dist/iconify.js';
import { clamp } from '#shared/general.utils'; import { clamp } from '#shared/general.util';
import type { CanvasContent, CanvasEdge, CanvasNode } from '~/types/canvas'; import type { CanvasContent, CanvasEdge, CanvasNode } from '~/types/canvas';
const canvas = defineModel<CanvasContent>({ required: true, }); const canvas = defineModel<CanvasContent>({ required: true, });

View File

@ -8,7 +8,7 @@
import type { Component } from 'vue'; import type { Component } from 'vue';
import { heading } from 'hast-util-heading'; import { heading } from 'hast-util-heading';
import { headingRank } from 'hast-util-heading-rank'; import { headingRank } from 'hast-util-heading-rank';
import { parseId } from '~/shared/general.utils'; import { parseId } from '~/shared/general.util';
import type { Root } from 'hast'; import type { Root } from 'hast';
const { content, proses, filter } = defineProps<{ const { content, proses, filter } = defineProps<{

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useDrag, useHover, usePinch, useWheel } from '@vueuse/gesture'; import { useDrag, useHover, usePinch, useWheel } from '@vueuse/gesture';
import { Icon } from '@iconify/vue/dist/iconify.js'; import { Icon } from '@iconify/vue/dist/iconify.js';
import { clamp } from '#shared/general.utils'; import { clamp } from '#shared/general.util';
const { path } = defineProps<{ path: string }>(); const { path } = defineProps<{ path: string }>();
const { user } = useUserSession(); const { user } = useUserSession();

View File

@ -16,7 +16,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { parseURL } from 'ufo'; import { parseURL } from 'ufo';
import { Icon } from '@iconify/vue/dist/iconify.js'; import { Icon } from '@iconify/vue/dist/iconify.js';
import { iconByType } from '#shared/general.utils'; import { iconByType } from '#shared/general.util';
const { href } = defineProps<{ const { href } = defineProps<{
href: string href: string

View File

@ -5,6 +5,6 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { parseId } from '#shared/general.utils'; import { parseId } from '#shared/general.util';
const props = defineProps<{ id?: string }>() const props = defineProps<{ id?: string }>()
</script> </script>

View File

@ -5,7 +5,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { parseId } from '#shared/general.utils'; import { parseId } from '#shared/general.util';
const props = defineProps<{ id?: string }>() const props = defineProps<{ id?: string }>()
const generate = computed(() => props.id) const generate = computed(() => props.id)

View File

@ -5,7 +5,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { parseId } from '#shared/general.utils'; import { parseId } from '#shared/general.util';
const props = defineProps<{ id?: string }>() const props = defineProps<{ id?: string }>()
const generate = computed(() => props.id) const generate = computed(() => props.id)

View File

@ -5,6 +5,6 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { parseId } from '#shared/general.utils'; import { parseId } from '#shared/general.util';
const props = defineProps<{ id?: string }>() const props = defineProps<{ id?: string }>()
</script> </script>

View File

@ -5,7 +5,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { parseId } from '#shared/general.utils'; import { parseId } from '#shared/general.util';
const props = defineProps<{ id?: string }>() const props = defineProps<{ id?: string }>()
const generate = computed(() => props.id) const generate = computed(() => props.id)

View File

@ -5,7 +5,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { parseId } from '#shared/general.utils'; import { parseId } from '#shared/general.util';
const props = defineProps<{ id?: string }>() const props = defineProps<{ id?: string }>()
const generate = computed(() => props.id) const generate = computed(() => props.id)

View File

@ -89,7 +89,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { Icon } from '@iconify/vue/dist/iconify.js'; import { Icon } from '@iconify/vue/dist/iconify.js';
import { iconByType } from '#shared/general.utils'; import { iconByType } from '#shared/general.util';
import type { DropdownOption } from '~/components/base/DropdownMenu.vue'; import type { DropdownOption } from '~/components/base/DropdownMenu.vue';
import { hasPermissions } from '~/shared/auth.util'; import { hasPermissions } from '~/shared/auth.util';
import type { TreeItem } from '~/types/content'; import type { TreeItem } from '~/types/content';

View File

@ -31,7 +31,7 @@
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import { format, iconByType } from '~/shared/general.utils'; import { format, iconByType } from '~/shared/general.util';
import { Icon } from '@iconify/vue/dist/iconify.js'; import { Icon } from '@iconify/vue/dist/iconify.js';
interface File interface File

View File

@ -206,9 +206,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { Icon } from '@iconify/vue/dist/iconify.js'; import { Icon } from '@iconify/vue/dist/iconify.js';
import type { Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/dist/types/tree-item'; import type { Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/dist/types/tree-item';
import { convertContentFromText, convertContentToText, parsePath } from '#shared/general.utils'; import { iconByType, convertContentFromText, convertContentToText, parsePath } from '#shared/general.util';
import type { CanvasContent, ExploreContent, FileType, TreeItem } from '~/types/content'; import type { ExploreContent, FileType, TreeItem } from '~/types/content';
import { iconByType } from '#shared/general.utils';
import FakeA from '~/components/prose/FakeA.vue'; import FakeA from '~/components/prose/FakeA.vue';
export type TreeItemEditable = TreeItem & export type TreeItemEditable = TreeItem &

View File

@ -1,7 +1,7 @@
import useDatabase from '~/composables/useDatabase'; import useDatabase from '~/composables/useDatabase';
import { explorerContentTable } from '~/db/schema'; import { explorerContentTable } from '~/db/schema';
import { schema } from '~/schemas/file'; import { schema } from '~/schemas/file';
import { parsePath } from '~/shared/general.utils'; import { parsePath } from '~/shared/general.util';
export default defineEventHandler(async (e) => { export default defineEventHandler(async (e) => {
const body = await readValidatedBody(e, schema.safeParse); const body = await readValidatedBody(e, schema.safeParse);

View File

@ -1,7 +1,7 @@
import { eq, sql } from 'drizzle-orm'; import { eq, sql } from 'drizzle-orm';
import useDatabase from '~/composables/useDatabase'; import useDatabase from '~/composables/useDatabase';
import { explorerContentTable } from '~/db/schema'; import { explorerContentTable } from '~/db/schema';
import { convertContentFromText } from '~/shared/general.utils'; import { convertContentFromText } from '~/shared/general.util';
export default defineEventHandler(async (e) => { export default defineEventHandler(async (e) => {
const path = decodeURIComponent(getRouterParam(e, "path") ?? ''); const path = decodeURIComponent(getRouterParam(e, "path") ?? '');

View File

@ -2,7 +2,7 @@ import { hasPermissions } from "#shared/auth.util";
import useDatabase from '~/composables/useDatabase'; import useDatabase from '~/composables/useDatabase';
import { explorerContentTable } from '~/db/schema'; import { explorerContentTable } from '~/db/schema';
import { project, type ProjectItem } from '~/schemas/project'; import { project, type ProjectItem } from '~/schemas/project';
import { parsePath } from "#shared/general.utils"; import { parsePath } from "#shared/general.util";
import { eq, getTableColumns, sql } from "drizzle-orm"; import { eq, getTableColumns, sql } from "drizzle-orm";
import type { ExploreContent, TreeItem } from "~/types/content"; import type { ExploreContent, TreeItem } from "~/types/content";
import type { TreeItemEditable } from "~/pages/explore/edit/index.vue"; import type { TreeItemEditable } from "~/pages/explore/edit/index.vue";

View File

@ -17,7 +17,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'; import { computed } from 'vue';
import Bun from 'bun'; import Bun from 'bun';
import { format } from '~/shared/general.utils'; import { format } from '~/shared/general.util';
const { id, userId, username, timestamp } = defineProps<{ const { id, userId, username, timestamp } = defineProps<{
id: number id: number

View File

@ -1,5 +1,5 @@
import type { CanvasNode } from "~/types/canvas"; import type { CanvasNode } from "~/types/canvas";
import { clamp } from "#shared/general.utils"; import { clamp } from "#shared/general.util";
export type Direction = 'bottom' | 'top' | 'left' | 'right'; export type Direction = 'bottom' | 'top' | 'left' | 'right';
export type Position = { x: number, y: number }; export type Position = { x: number, y: number };

View File

@ -40,15 +40,13 @@ export function format(date: Date, template: string): string
return template; return template;
} }
export function clamp(x: number, min: number, max: number): number { export function clamp(x: number, min: number, max: number): number
if (x > max) {
return max; return x > max ? max : x < min ? min : x;
if (x < min)
return min;
return x;
} }
export function lerp(a: number, b: number, t: number) { export function lerp(x: number, a: number, b: number): number
return a + t * (b - a); {
return (1-x)*a+x*b;
} }
export function convertContentFromText(type: FileType, content: string): CanvasContent | string { export function convertContentFromText(type: FileType, content: string): CanvasContent | string {
switch(type) switch(type)