-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from st-tech/refactor
Refactor
- Loading branch information
Showing
25 changed files
with
1,461 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["svelte.svelte-vscode", "biomejs.biome"] | ||
} |
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,4 +1,11 @@ | ||
{ | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"editor.formatOnSave": true | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"quickfix.biome": "explicit", | ||
"source.organizeImports.biome": "explicit" | ||
}, | ||
"[svelte]": { | ||
"editor.defaultFormatter": "svelte.svelte-vscode" | ||
} | ||
} |
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,6 @@ | ||
# Demo | ||
|
||
```sh | ||
pnpm install | ||
pnpm dev # to start the dev server | ||
``` |
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>apple-app-site-association Demo</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
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,28 @@ | ||
{ | ||
"name": "demo", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/vite-plugin-svelte": "^5.0.0", | ||
"@tsconfig/svelte": "^5.0.4", | ||
"svelte": "^5.2.7", | ||
"svelte-check": "^4.1.0", | ||
"tslib": "^2.8.1", | ||
"typescript": "~5.6.2", | ||
"vite": "^6.0.1" | ||
}, | ||
"dependencies": { | ||
"@tailwindcss/vite": "4.0.0-beta.6", | ||
"apple-app-site-association": "workspace:*", | ||
"lz-string": "^1.5.0", | ||
"monaco-editor": "^0.52.0", | ||
"tailwindcss": "4.0.0-beta.6" | ||
} | ||
} |
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,108 @@ | ||
<script lang="ts"> | ||
import { createVerify } from "apple-app-site-association/sim"; | ||
import Editor from "./Editor.svelte"; | ||
import { getHash, parseHash } from "./hash"; | ||
const uuid = () => window.crypto.randomUUID(); | ||
const getHashOptions = (hash: string): { json: unknown; paths: string[] } => { | ||
const fallback = { | ||
json: { | ||
applinks: { | ||
details: [ | ||
{ | ||
appIDs: ["HOGE.com.example.app"], | ||
components: [ | ||
{ "#": "nondeeplinking", exclude: true }, | ||
{ "/": "/search/" }, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
paths: ["/search/", "/", "/search/#nondeeplinking"], | ||
} satisfies { json: unknown; paths: string[] }; | ||
if (!hash) return fallback; | ||
try { | ||
return parseHash(hash); | ||
} catch { | ||
return fallback; | ||
} | ||
}; | ||
const initial = getHashOptions(window.location.hash.slice(1)); | ||
let json = $state(JSON.stringify(initial.json, null, 2)); | ||
let paths = $state(initial.paths.map((p) => ({ id: uuid(), value: p }))); | ||
let verify = $derived(createVerify(json)); | ||
</script> | ||
|
||
<div class="grid grid-rows-[auto_1fr] h-full"> | ||
<header class="flex justify-between p-4 border-b border-gray-400"> | ||
<h1 class="font-bold">apple-app-site-association check</h1> | ||
<button | ||
type="button" | ||
onclick={() => { | ||
const hash = getHash( | ||
json, | ||
paths.map((p) => p.value) | ||
); | ||
const url = new URL(location.href); | ||
url.hash = hash; | ||
window.history.replaceState(null, "", url.href); | ||
navigator.clipboard.writeText(url.href).then(() => { | ||
alert("URL copied to clipboard"); | ||
}); | ||
}} | ||
> | ||
Share | ||
</button> | ||
</header> | ||
<main class="grid grid-cols-2"> | ||
<Editor bind:value={json} /> | ||
<div class="p-4"> | ||
<h2 class="font-bold">Paths</h2> | ||
<ul class="grid grid-cols-[auto_1fr_auto] gap-1 font-mono"> | ||
{#each paths as path (path.id)} | ||
<li class="contents"> | ||
<button | ||
type="button" | ||
onclick={() => { | ||
paths = paths.filter((p) => p.id !== path.id); | ||
}} | ||
title="Remove" | ||
> | ||
- | ||
</button> | ||
<span | ||
class="grow focus-within:outline-2 outline-blue-400/50 rounded-sm" | ||
> | ||
<input | ||
bind:value={path.value} | ||
class="p-1 border-b border-gray-300 size-full focus:outline-none" | ||
type="text" | ||
autocomplete="off" | ||
data-1p-ignore | ||
/> | ||
</span> | ||
{#await verify(path.value)} | ||
<span>...</span> | ||
{:then result} | ||
<output>{result}</output> | ||
{:catch error} | ||
<output>{error}</output> | ||
{/await} | ||
</li> | ||
{/each} | ||
<li class="contents"> | ||
<span></span> | ||
<button | ||
type="button" | ||
onclick={() => paths.push({ id: uuid(), value: "/" })} | ||
> | ||
+ Add more | ||
</button> | ||
</li> | ||
</ul> | ||
</div> | ||
</main> | ||
</div> |
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,38 @@ | ||
<script lang="ts"> | ||
import * as monaco from "monaco-editor"; | ||
import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker"; | ||
import JsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker"; | ||
let ref = $state<HTMLDivElement>(); | ||
let { value = $bindable("") } = $props(); | ||
let editor = $state<monaco.editor.IStandaloneCodeEditor>(); | ||
// @ts-ignore | ||
globalThis.MonacoEnvironment = { | ||
getWorker: (_, label) => { | ||
if (label === "json") return new JsonWorker(); | ||
return new EditorWorker(); | ||
}, | ||
} satisfies monaco.Environment; | ||
$effect(() => { | ||
if (!ref) return; | ||
const e = monaco.editor.create(ref, { | ||
tabSize: 2, | ||
language: "json", | ||
}); | ||
e.onDidChangeModelContent(() => { | ||
value = e.getValue(); | ||
}); | ||
editor = e; | ||
return () => e.dispose(); | ||
}); | ||
$effect(() => { | ||
if (!editor) return; | ||
if (value !== editor.getValue()) { | ||
editor.setValue(value); | ||
} | ||
}); | ||
</script> | ||
|
||
<div bind:this={ref} class="size-full"></div> |
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,10 @@ | ||
@import "tailwindcss"; | ||
:root, | ||
body, | ||
#app { | ||
@apply h-full; | ||
} | ||
button, | ||
[role="button"] { | ||
@apply cursor-pointer; | ||
} |
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,20 @@ | ||
import { | ||
compressToEncodedURIComponent, | ||
decompressFromEncodedURIComponent, | ||
} from "lz-string"; | ||
|
||
const jsonKey = "j"; | ||
const pathsKey = "p"; | ||
|
||
export const getHash = (aasa: string, paths: string[]) => { | ||
return compressToEncodedURIComponent( | ||
JSON.stringify({ | ||
[jsonKey]: JSON.parse(aasa), | ||
[pathsKey]: paths, | ||
}), | ||
); | ||
}; | ||
export const parseHash = (hash: string): { json: unknown; paths: string[] } => { | ||
const parsed = JSON.parse(decompressFromEncodedURIComponent(hash)); | ||
return { json: parsed[jsonKey], paths: parsed[pathsKey] }; | ||
}; |
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,8 @@ | ||
import { mount } from "svelte"; | ||
import "./app.css"; | ||
import App from "./App.svelte"; | ||
|
||
const target = document.getElementById("app"); | ||
const app = target && mount(App, { target }); | ||
|
||
export default app; |
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,2 @@ | ||
/// <reference types="svelte" /> | ||
/// <reference types="vite/client" /> |
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,7 @@ | ||
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; | ||
|
||
export default { | ||
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess | ||
// for more information about preprocessors | ||
preprocess: vitePreprocess(), | ||
}; |
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,21 @@ | ||
{ | ||
"extends": "@tsconfig/svelte/tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"resolveJsonModule": true, | ||
/** | ||
* Typecheck JS in `.svelte` and `.js` files by default. | ||
* Disable checkJs if you'd like to use dynamic types in JS. | ||
* Note that setting allowJs false does not prevent the use | ||
* of JS in `.svelte` files. | ||
*/ | ||
"allowJs": true, | ||
"checkJs": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force" | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", | ||
"skipLibCheck": true, | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"strict": true, | ||
"noEmit": true, | ||
"noUncheckedSideEffectImports": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
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,8 @@ | ||
import { svelte } from "@sveltejs/vite-plugin-svelte"; | ||
import tailwindcss from "@tailwindcss/vite"; | ||
import { defineConfig } from "vite"; | ||
|
||
// https://vite.dev/config/ | ||
export default defineConfig({ | ||
plugins: [svelte(), tailwindcss()], | ||
}); |
Oops, something went wrong.