This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: wip * fix: convert `pwa.d.ts` into declaration (#42) * chore: use edge * feat: implement composable Co-authored-by: Daniel Roe <[email protected]>
- Loading branch information
1 parent
431c0c9
commit adfac55
Showing
13 changed files
with
164 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<template> | ||
<main class="container h-screen mx-auto flex justify-center items-center"> | ||
<div class="justify-center items-center"> | ||
<img :src="usePWAIcon(192)"> | ||
<span class="text-lg">This page should work offline.</span> | ||
</div> | ||
</main> | ||
</template> | ||
|
||
<style lang="postcss"> | ||
html { | ||
@apply bg-cool-gray-900 text-white | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
defineConfig, | ||
presetUno, | ||
transformerDirectives | ||
} from 'unocss' | ||
|
||
export default defineConfig({ | ||
presets: [ | ||
presetUno() | ||
], | ||
transformers: [ | ||
transformerDirectives() | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { ManifestIcon } from '../../parts/manifest/types' | ||
import type { IconSize } from '#pwa' | ||
import { useRuntimeConfig } from '#imports' | ||
|
||
export function usePWAIcon (size: IconSize, { maskable } = { maskable: false }) { | ||
return (useRuntimeConfig().public.pwaManifest.icons as ManifestIcon[]) | ||
.find(i => i.sizes === `${+size}x${+size}` && i.purpose === (maskable ? 'maskable' : 'any')) | ||
?.src || '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
import { defineEventHandler } from 'h3' | ||
import { useRuntimeConfig } from '#imports' | ||
|
||
export default defineEventHandler(() => { | ||
const { pwaManifest } = useRuntimeConfig() | ||
return pwaManifest | ||
}) | ||
export default defineEventHandler(() => useRuntimeConfig().public.pwaManifest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { setup } from '@nuxt/test-utils' | ||
import { describe, it, expect, vi } from 'vitest' | ||
import { usePWAIcon } from '../src/runtime/composables/usePWAIcon' | ||
|
||
import './setup' | ||
|
||
vi.mock('#imports', () => ({ | ||
useRuntimeConfig: () => ({ | ||
public: { | ||
pwaManifest: { | ||
icons: [ | ||
{ sizes: '64x64', purpose: 'any', src: '/assets/icons/64x64.png' }, | ||
{ sizes: '64x64', purpose: 'maskable', src: '/assets/icons/64x64.maskable.png' } | ||
] | ||
} | ||
} | ||
}) | ||
})) | ||
|
||
describe('composables', async () => { | ||
await setup({}) | ||
|
||
describe('usePWAIcon', () => { | ||
it('returns icon url', () => { | ||
expect(usePWAIcon(64)).toBe('/assets/icons/64x64.png') | ||
}) | ||
|
||
it('returns maskable icon url when maskable option is true', () => { | ||
expect(usePWAIcon(64, { maskable: true })).toBe('/assets/icons/64x64.maskable.png') | ||
}) | ||
|
||
it('returns empty string when icon not found', () => { | ||
expect(usePWAIcon(0)).toBe('') | ||
}) | ||
}) | ||
}) |