126 lines
2.7 KiB
Vue
126 lines
2.7 KiB
Vue
<template>
|
|
<component
|
|
:is="self ? 'MkA' : 'a'"
|
|
ref="el"
|
|
class="ieqqeuvs url _link"
|
|
:[attr]="self ? props.url.substring(local.length) : props.url"
|
|
:title="self ? props.url.substring(local.length) : props.url"
|
|
:rel="rel"
|
|
:target="target"
|
|
@contextmenu.stop="() => {}"
|
|
@click.stop
|
|
>
|
|
<template v-if="!self">
|
|
<span class="schema">{{ schema }}{{ hostname.trim() != '' ? '://' : '' }}</span>
|
|
<span class="hostname">{{ hostname.trim() != '' ? hostname.trim() : pathname }}</span>
|
|
<!-- <span v-if="port != ''" class="port">:{{ port }}</span> -->
|
|
</template>
|
|
<template v-if="pathname === '/' && self">
|
|
<span class="self">{{ hostname }}</span>
|
|
</template>
|
|
<span v-if="pathname != '' && !!hostname" class="pathname">{{
|
|
self ? pathname.substring(1) : pathname
|
|
}}</span>
|
|
<span class="query">{{ query }}</span>
|
|
<span class="hash">{{ hash }}</span>
|
|
<i
|
|
v-if="target === '_blank'"
|
|
class="ph-arrow-square-out ph-bold ph-lg icon"
|
|
></i>
|
|
</component>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { defineAsyncComponent, ref } from "vue";
|
|
import { toUnicode as decodePunycode } from "punycode/";
|
|
import { url as local } from "@/config";
|
|
import * as os from "@/os";
|
|
import { useTooltip } from "@/scripts/use-tooltip";
|
|
import { safeURIDecode } from "@/scripts/safe-uri-decode";
|
|
import { parseUri } from "@/scripts/parse-uri"
|
|
import { SCHEMA_BROWSERSAFE } from "../../const";
|
|
|
|
const props = defineProps<{
|
|
url: string;
|
|
rel?: string;
|
|
}>();
|
|
|
|
const self = props.url.startsWith(local);
|
|
const url = parseUri(props.url);
|
|
console.log(url);
|
|
console.log(props.url);
|
|
console.log(url.scheme);
|
|
if (!SCHEMA_BROWSERSAFE.includes(url.scheme))
|
|
throw new Error("invalid url");
|
|
|
|
const el = ref();
|
|
|
|
useTooltip(el, (showing) => {
|
|
os.popup(
|
|
defineAsyncComponent(
|
|
() => import("@/components/MkUrlPreviewPopup.vue"),
|
|
),
|
|
{
|
|
showing,
|
|
url: props.url,
|
|
source: el.value,
|
|
},
|
|
{},
|
|
"closed",
|
|
);
|
|
});
|
|
|
|
const schema = url.scheme;
|
|
const hostname = decodePunycode(url.authority ?? "");
|
|
// const port = url.port;
|
|
const pathname = safeURIDecode(url.path ?? "");
|
|
const query = safeURIDecode(url.query ?? "");
|
|
const hash = safeURIDecode(url.fragment ?? "");
|
|
const attr = self ? "to" : "href";
|
|
const target = self ? null : "_blank";
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.url {
|
|
text-decoration: none !important;
|
|
> span {
|
|
text-decoration: underline var(--fgTransparent);
|
|
text-decoration-thickness: 1px;
|
|
transition: text-decoration-color 0.2s;
|
|
}
|
|
|
|
> .icon {
|
|
padding-left: 2px;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
> .self {
|
|
font-weight: bold;
|
|
}
|
|
|
|
> .schema {
|
|
opacity: 0.5;
|
|
}
|
|
|
|
> .hostname {
|
|
font-weight: bold;
|
|
}
|
|
|
|
> .pathname {
|
|
opacity: 0.8;
|
|
}
|
|
|
|
> .query {
|
|
opacity: 0.5;
|
|
}
|
|
|
|
> .hash {
|
|
font-style: italic;
|
|
}
|
|
|
|
&:hover span {
|
|
text-decoration-color: var(--link);
|
|
}
|
|
}
|
|
</style>
|