Skip to content

Commit

Permalink
fix(components): added WeakHardwareOverlay
Browse files Browse the repository at this point in the history
- added tests
- fix entry setupSpeedkitLayer
  • Loading branch information
ThornWalli committed Jun 12, 2023
1 parent d3adc73 commit 43f255e
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 11 deletions.
2 changes: 1 addition & 1 deletion playground/components/InfoLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<div class="info-layer-buttons">
<base-button
id="nuxt-speedkit-button-init-nojs"
tag="label"
for="nuxt-speedkit-layer-close">
Yes
</base-button>
<base-button
id="nuxt-speedkit-button-init-reduced-view"
tag="label"
for="nuxt-speedkit-layer-close">
No
</base-button>
Expand Down
51 changes: 51 additions & 0 deletions playground/components/WeakHardwareOverlay.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<speedkit-weak-hardware-overlay>
<div v-font="$getFont('Montserrat Alternates', 400, 'normal')">
<p>{{ text }}</p>
<base-button id="nuxt-speedkit-button-init-app">
{{ buttonText }}
</base-button>
</div>
</speedkit-weak-hardware-overlay>
</template>

<script setup>
import SpeedkitWeakHardwareOverlay from '#speedkit/components/WeakHardwareOverlay';
import BaseButton from '@/components/base/Button';
import useFonts from '#speedkit/composables/fonts';
const { $getFont } = useFonts();
defineProps({
text: {
type: String,
default:
'To improve your experience, extensive features have been disabled.'
},
buttonText: {
type: String,
default: 'Click here to enable them.'
}
});
</script>

<style lang="postcss" scoped>
.nuxt-speedkit-weak-hardware-overlay {
position: absolute;
top: 0;
left: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background: rgb(0 0 0 / 60%);
backdrop-filter: blur(em(4px));
& div {
font-size: 14px;
text-align: center;
}
}
</style>
9 changes: 6 additions & 3 deletions playground/components/base/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ export default {

<style lang="postcss" scoped>
.base-button {
padding: em(8px) em(16px);
--font-size: 16;
padding: em(8px, var(--font-size)) em(16px, var(--font-size));
font-size: em(var(--font-size));
color: currentColor;
appearance: none;
cursor: pointer;
background: transparent;
border: solid currentColor em(1px);
border-radius: em(5px);
border: solid currentColor em(1px, var(--font-size));
border-radius: em(5px, var(--font-size));
outline: none;
transition: transform 0.1s ease-in;
will-change: transform;
Expand Down
4 changes: 4 additions & 0 deletions playground/components/modules/VideoVimeo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
<template #default="{ videoData }">
<div class="description" v-html="videoData && videoData.description" />
</template>
<template #afterPlayer>
<weak-hardware-overlay />
</template>
</speedkit-vimeo>
</section>
</template>

<script setup>
import SpeedkitVimeo from '#speedkit/components/SpeedkitVimeo';
import WeakHardwareOverlay from '@/components/WeakHardwareOverlay';
import useFonts from '#speedkit/composables/fonts';
const { $getFont } = useFonts();
defineProps({
Expand Down
5 changes: 4 additions & 1 deletion playground/components/modules/VideoYoutube.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<template>
<section v-font="[$getFont('Merriweather', 400)]" class="video-youtube">
<speedkit-youtube v-bind="$attrs" />
<speedkit-youtube v-bind="$attrs">
<template #afterPlayer> <weak-hardware-overlay /> </template
></speedkit-youtube>
<p v-if="text" v-html="text" />
</section>
</template>

<script setup>
import SpeedkitYoutube from '#speedkit/components/SpeedkitYoutube';
import WeakHardwareOverlay from '@/components/WeakHardwareOverlay';
import useFonts from '#speedkit/composables/fonts';
const { $getFont } = useFonts();
defineProps({
Expand Down
26 changes: 26 additions & 0 deletions playground/pages/tests/weak-hardware-overlay/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<main :class="{ mounted }" tag="main">
<div>
WeakHardwareOverlay
<speedkit-weak-hardware-overlay />
</div>
<speedkit-layer />
</main>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import SpeedkitLayer from '#speedkit/components/SpeedkitLayer';
import SpeedkitWeakHardwareOverlay from '#speedkit/components/WeakHardwareOverlay';
const mounted = ref(false);
onMounted(() => {
mounted.value = true;
});
defineOptions({
layout: 'blank'
});
</script>
6 changes: 6 additions & 0 deletions src/runtime/components/SpeedkitVimeo.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<base-vimeo class="nuxt-speedkit-vimeo" v-bind="$attrs">
<template #beforePlayer>
<slot name="beforePlayer" />
</template>
<template #loading-spinner>
<slot name="loading-spinner">
<div class="loading-spinner">
Expand Down Expand Up @@ -42,6 +45,9 @@
<template #default="context">
<slot name="default" v-bind="context" />
</template>
<template #afterPlayer>
<slot name="afterPlayer" />
</template>
</base-vimeo>
</template>

Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/SpeedkitVimeo/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div :class="{ ready, playing, 'iframe-mode': iframeMode }">
<slot name="background" v-bind="{ playing, videoData }" />
<div class="player">
<slot name="beforePlayer" />
<iframe
ref="player"
:key="src"
Expand All @@ -16,6 +17,7 @@
<slot v-if="loading" name="loading-spinner" />
<slot v-if="!ready && !loading" name="play" />
</default-button>
<slot name="afterPlayer" />
</div>
<slot v-bind="{ playing, videoData }" />
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/components/SpeedkitYoutube.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<base-youtube class="nuxt-speedkit-youtube" v-bind="$attrs">
<template #beforePlayer>
<slot name="beforePlayer" />
</template>
<template #loading-spinner>
<slot name="loading-spinner">
<svg
Expand Down Expand Up @@ -36,6 +39,9 @@
</svg>
</slot>
</template>
<template #afterPlayer>
<slot name="afterPlayer" />
</template>
</base-youtube>
</template>

Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/SpeedkitYoutube/Base.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div :class="{ ready, playing }">
<slot name="beforePlayer" />
<iframe
v-if="src"
ref="player"
Expand All @@ -14,6 +15,7 @@
<slot v-if="loading" name="loading-spinner" />
<slot v-if="!ready && !loading" name="play" />
</default-button>
<slot name="afterPlayer" />
</div>
</template>

Expand Down
26 changes: 26 additions & 0 deletions src/runtime/components/WeakHardwareOverlay.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div v-if="isServer" class="nuxt-speedkit-weak-hardware-overlay">
<slot>
Area is disabled for performance reasons.<br />
<button id="nuxt-speedkit-button-init-app">Click for activation</button>
</slot>
</div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
const isServer = ref(true);
onMounted(() => (isServer.value = false));
</script>

<style lang="postcss" scoped>
/*! purgecss start ignore */
.nuxt-speedkit-weak-hardware-overlay {
@nest html:not(.nuxt-speedkit-reduced-view) & {
display: none;
}
}
/*! purgecss end ignore */
</style>
2 changes: 1 addition & 1 deletion src/runtime/tmpl/entry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function client () {
if(('__NUXT_SPEEDKIT_AUTO_INIT__' in window && window.__NUXT_SPEEDKIT_AUTO_INIT__) || ((<%= !options.ignorePerformance %> && hasSufficientPerformance()) && supportedBrowser)) {
initApp();
} else {
setupSpeedkitLayer(supportedBrowser)
setupSpeedkitLayer(layerEl, supportedBrowser)
}

}
Expand Down
7 changes: 5 additions & 2 deletions src/runtime/utils/entry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ export function updateSpeedkitLayerMessage(layerEl, id) {
}
}

export function setupSpeedkitLayer(supportedBrowser) {
export function setupSpeedkitLayer(layerEl, supportedBrowser) {
if (!supportedBrowser) {
updateSpeedkitLayerMessage('nuxt-speedkit-message-unsupported-browser');
}
if (!hasSufficientDownloadPerformance()) {
updateSpeedkitLayerMessage('nuxt-speedkit-message-reduced-bandwidth');
updateSpeedkitLayerMessage(
layerEl,
'nuxt-speedkit-message-reduced-bandwidth'
);
}
}

Expand Down
33 changes: 30 additions & 3 deletions test/tests/browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,33 @@ export default runtime => {

// #endregion /tests/speedkit-layer

// #region /tests/weak-hardware-overlay

it('WeakHardwareOverlay (Visible & Init App)', async () => {
const page = await createPage('/weak-hardware-overlay/');

expect(
await page.evaluate(() =>
document.querySelector('.nuxt-speedkit-weak-hardware-overlay')
)
).not.toBeFalsy();

await page.evaluate(() =>
document
.querySelector('.nuxt-speedkit-weak-hardware-overlay button')
.click()
);
await page.waitForSelector('main.mounted');

expect(
await page.evaluate(() =>
document.querySelector('.nuxt-speedkit-weak-hardware-overlay')
)
).toBeFalsy();
});

// #endregion /tests/weak-hardware-overlay

// #region /tests/speedkit-loader

it('speedkitHydrate', async () => {
Expand Down Expand Up @@ -351,7 +378,7 @@ export default runtime => {

// #region /tests/iframe

it('iframe', async () => {
it('SpeedkitIframe', async () => {
const page = await createPage('/iframe/');
await page.waitForLoadState('networkidle');
await page.evaluate(() => {
Expand All @@ -363,7 +390,7 @@ export default runtime => {
// #endregion

// #region /tests/youtube
it('youtube ready, play and autoplay', async () => {
it('SpeedkitYoutube ready, play and autoplay', async () => {
const page = await createPage('/youtube/');
await page.waitForLoadState('networkidle');

Expand Down Expand Up @@ -400,7 +427,7 @@ export default runtime => {

// #region /tests/vimeo

// it('vimeo ready & play', async () => {
// it('SpeedkitVimeo ready & play', async () => {
// const page = await createPage('/vimeo/');
// await page.waitForLoadState('networkidle');

Expand Down

0 comments on commit 43f255e

Please sign in to comment.