Initialize Compose Launcher source and deployment
This commit is contained in:
commit
12a8c24441
77 files changed
+9594
No files matched your search
@@ -0,0 +1,67 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import {
|
||||
backgroundStyle, clamp, deviceMapper, devices, iconColor, sortedItems,
|
||||
type Layout, type LayoutItem, type Page,
|
||||
} from "./layout";
|
||||
|
||||
const props = defineProps<{
|
||||
layout: Layout;
|
||||
page: Page;
|
||||
device?: typeof devices[number];
|
||||
selectedId?: string;
|
||||
editable?: boolean;
|
||||
guides?: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
startDrag: [event: PointerEvent, item: LayoutItem, resize: boolean];
|
||||
clear: [];
|
||||
}>();
|
||||
const canvas = computed(() => props.layout.canvas);
|
||||
const width = computed(() => props.device?.w ?? canvas.value.designWidth);
|
||||
const height = computed(() => props.device?.h ?? canvas.value.designHeight);
|
||||
const mapper = computed(() => props.device
|
||||
? deviceMapper(canvas.value, props.layout.fit, props.page.items, props.device)
|
||||
: { sx: 1, sy: 1, x: (n: number) => n, y: (n: number) => n });
|
||||
const items = computed(() => sortedItems(props.page));
|
||||
const known = new Set(["app_icon", "widget", "shortcut", "dock_bg"]);
|
||||
const visible = computed(() => props.editable ? items.value : items.value.filter(item => known.has(item.type)));
|
||||
const percent = (n: number, total: number) => (n / total * 100) + "%";
|
||||
function itemStyle(item: LayoutItem) {
|
||||
const m = mapper.value;
|
||||
return {
|
||||
left: percent(m.x(item.x), width.value),
|
||||
top: percent(m.y(item.y), height.value),
|
||||
width: percent(item.w * m.sx, width.value),
|
||||
height: percent(item.h * m.sy, height.value),
|
||||
borderRadius: item.type === "dock_bg" ? Math.max(0, item.payload.radius ?? 56) * m.sx / width.value * 100 + "cqw" : undefined,
|
||||
"--icon-fill": iconColor(item),
|
||||
};
|
||||
}
|
||||
function title(item: LayoutItem) {
|
||||
return item.payload.label || item.payload.package || item.payload.provider || item.payload.intent || item.type;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="layout-surface" :class="{ editable, 'with-guides': guides }"
|
||||
:style="{ aspectRatio: width + '/' + height, background: backgroundStyle(page.background) }"
|
||||
@pointerdown="editable && emit('clear')">
|
||||
<template v-if="editable">
|
||||
<div class="safe-zone top" :style="{ height: percent(clamp(canvas.safeTop, 0, height), height) }"></div>
|
||||
<div class="safe-zone bottom" :style="{ height: percent(clamp(canvas.safeBottom, 0, height), height) }"></div>
|
||||
</template>
|
||||
<div v-for="item in visible" :key="item.id" class="layout-item"
|
||||
:class="[item.type, { selected: item.id === selectedId }]" :style="itemStyle(item)"
|
||||
:title="title(item)" :tabindex="editable ? 0 : undefined"
|
||||
@pointerdown="editable && emit('startDrag', $event, item, false)">
|
||||
<template v-if="item.type === 'app_icon' || item.type === 'shortcut'">
|
||||
<span class="icon-art">{{ (item.payload.label || title(item)).slice(0, 1).toUpperCase() }}</span>
|
||||
<span class="icon-label">{{ title(item) }}</span>
|
||||
</template>
|
||||
<span v-else-if="item.type !== 'dock_bg'" class="widget-label">{{ title(item) }}</span>
|
||||
<span v-if="editable" class="resize-handle" aria-hidden="true"
|
||||
@pointerdown="emit('startDrag', $event, item, true)"></span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user