@3birds/midori-ui 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import type { AlertState, AlertType } from './types';
2
+ export declare const alert: {
3
+ subscribe: (this: void, run: import("svelte/store").Subscriber<AlertState>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
4
+ trigger: (message: string, type?: AlertType, duration?: number) => void;
5
+ close: () => void;
6
+ };
package/dist/alert.js ADDED
@@ -0,0 +1,15 @@
1
+ import { writable } from 'svelte/store';
2
+ const initialState = {
3
+ show: false,
4
+ message: '',
5
+ type: 'info',
6
+ duration: 3000
7
+ };
8
+ const { subscribe, set } = writable(initialState);
9
+ export const alert = {
10
+ subscribe,
11
+ trigger: (message, type = 'info', duration = 3000) => {
12
+ set({ show: true, message, type, duration });
13
+ },
14
+ close: () => set(initialState)
15
+ };
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2
+ <title>magnify</title>
3
+ <path
4
+ fill="#e0f1e8"
5
+ d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z"
6
+ />
7
+ </svg>
@@ -1,7 +1,7 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2
2
  <title>magnify</title>
3
3
  <path
4
- fill="#e0f1e8"
4
+ fill="currentColor"
5
5
  d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z"
6
6
  />
7
7
  </svg>
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2
+ <title>menu</title>
3
+ <path fill="#e0f1e8" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
4
+ </svg>
@@ -1,4 +1,4 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2
2
  <title>menu</title>
3
- <path fill="#e0f1e8" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
3
+ <path fill="currentColor" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
4
4
  </svg>
package/dist/auth.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare function signIn(email: string, password: string): Promise<boolean>;
2
+ export declare function signUp(email: string, password: string): Promise<boolean>;
3
+ export declare function resetPassword(email: string): Promise<boolean>;
4
+ export declare function signOut(): Promise<void>;
5
+ export declare function toSigninErrorMessage(code: string): string;
6
+ export declare function toSignupErrorMessage(code: string): string;
7
+ export declare function toResetPasswordErrorMessage(code: string): string;
package/dist/auth.js ADDED
@@ -0,0 +1,72 @@
1
+ import { signInWithEmailAndPassword, createUserWithEmailAndPassword, sendPasswordResetEmail, signOut as firebaseSignOut } from 'firebase/auth';
2
+ import { auth } from './firebase';
3
+ import { alert } from './alert';
4
+ export async function signIn(email, password) {
5
+ try {
6
+ await signInWithEmailAndPassword(auth, email, password);
7
+ return true;
8
+ }
9
+ catch (e) {
10
+ alert.trigger(toSigninErrorMessage(e.code), 'error', 10000);
11
+ return false;
12
+ }
13
+ }
14
+ export async function signUp(email, password) {
15
+ try {
16
+ await createUserWithEmailAndPassword(auth, email, password);
17
+ return true;
18
+ }
19
+ catch (e) {
20
+ alert.trigger(toSignupErrorMessage(e.code), 'error', 10000);
21
+ return false;
22
+ }
23
+ }
24
+ export async function resetPassword(email) {
25
+ try {
26
+ await sendPasswordResetEmail(auth, email);
27
+ return true;
28
+ }
29
+ catch (e) {
30
+ alert.trigger(toResetPasswordErrorMessage(e.code), 'error', 10000);
31
+ return false;
32
+ }
33
+ }
34
+ export async function signOut() {
35
+ await firebaseSignOut(auth);
36
+ }
37
+ export function toSigninErrorMessage(code) {
38
+ switch (code) {
39
+ case 'auth/invalid-email':
40
+ return 'メールアドレスの形式が正しくありません。';
41
+ case 'auth/invalid-credential':
42
+ return 'メールアドレスまたはパスワードが正しくありません。';
43
+ case 'auth/user-disabled':
44
+ return 'このアカウントは無効化されています。';
45
+ case 'auth/too-many-requests':
46
+ return '試行回数が多すぎます。しばらく時間をおいてから再度お試しください。';
47
+ default:
48
+ return 'ログインに失敗しました。時間をおいて再度お試しください。';
49
+ }
50
+ }
51
+ export function toSignupErrorMessage(code) {
52
+ switch (code) {
53
+ case 'auth/email-already-in-use':
54
+ return 'このメールアドレスは既に登録されています。';
55
+ case 'auth/invalid-email':
56
+ return 'メールアドレスの形式が正しくありません。';
57
+ case 'auth/weak-password':
58
+ return 'パスワードが弱すぎます。英字と数字を含む6文字以上で設定してください。';
59
+ default:
60
+ return '登録に失敗しました。時間をおいて再度お試しください。';
61
+ }
62
+ }
63
+ export function toResetPasswordErrorMessage(code) {
64
+ switch (code) {
65
+ case 'auth/invalid-email':
66
+ return 'メールアドレスの形式が正しくありません。';
67
+ case 'auth/too-many-requests':
68
+ return '試行回数が多すぎます。しばらく時間をおいてから再度お試しください。';
69
+ default:
70
+ return 'パスワード再設定メールを送信できませんでした。時間をおいて再度お試しください。';
71
+ }
72
+ }
@@ -0,0 +1,5 @@
1
+ import { type User } from 'firebase/auth';
2
+ export declare const authState: {
3
+ user: User | null;
4
+ loading: boolean;
5
+ };
@@ -0,0 +1,19 @@
1
+ import { browser } from '$app/environment';
2
+ import { onAuthStateChanged } from 'firebase/auth';
3
+ import { auth } from './firebase';
4
+ let user = $state(null);
5
+ let loading = $state(true);
6
+ if (browser) {
7
+ onAuthStateChanged(auth, (firebaseUser) => {
8
+ user = firebaseUser;
9
+ loading = false;
10
+ });
11
+ }
12
+ export const authState = {
13
+ get user() {
14
+ return user;
15
+ },
16
+ get loading() {
17
+ return loading;
18
+ }
19
+ };
@@ -0,0 +1,60 @@
1
+ <script lang="ts">
2
+ import { alert } from '../alert';
3
+ import { alertSvg, checkCircleSvg, closeCircleSvg, informationSvg } from '@3birds/midori-ui';
4
+
5
+ let dialog: HTMLDialogElement | undefined;
6
+
7
+ let color: string = $derived.by(() => {
8
+ switch ($alert.type) {
9
+ case 'success':
10
+ return 'alert-success';
11
+ case 'info':
12
+ return 'alert-info';
13
+ case 'warning':
14
+ return 'alert-warning';
15
+ case 'error':
16
+ return 'alert-error';
17
+ default:
18
+ return '';
19
+ }
20
+ });
21
+
22
+ let icon: string = $derived.by(() => {
23
+ switch ($alert.type) {
24
+ case 'success':
25
+ return checkCircleSvg;
26
+ case 'info':
27
+ return informationSvg;
28
+ case 'warning':
29
+ return alertSvg;
30
+ case 'error':
31
+ return closeCircleSvg;
32
+ default:
33
+ return '';
34
+ }
35
+ });
36
+
37
+ $effect(() => {
38
+ if ($alert.show) {
39
+ dialog?.showModal();
40
+
41
+ setInterval(() => dialog?.close(), $alert.duration);
42
+ } else {
43
+ dialog?.close();
44
+ }
45
+ });
46
+
47
+ function handleClose() {
48
+ alert.close();
49
+ }
50
+ </script>
51
+
52
+ <dialog bind:this={dialog} onclose={handleClose} onclick={alert.close} class="modal">
53
+ <div class="fixed top-4 modal-box alert rounded-3xl {color} right-4 left-4" role="alert">
54
+ <img src={icon} alt="アラート" class="size-6" />
55
+ {$alert.message}
56
+ </div>
57
+ <form method="dialog" class="modal-backdrop">
58
+ <button>close</button>
59
+ </form>
60
+ </dialog>
@@ -0,0 +1,3 @@
1
+ declare const Alert: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type Alert = ReturnType<typeof Alert>;
3
+ export default Alert;
@@ -60,3 +60,15 @@
60
60
  <p class="label ml-auto whitespace-pre-wrap">{option}</p>
61
61
  {/if}
62
62
  </fieldset>
63
+
64
+ <style>
65
+ input[type='date'] {
66
+ position: relative;
67
+ }
68
+ input[type='date']::-webkit-calendar-picker-indicator {
69
+ position: absolute;
70
+ width: 100%;
71
+ height: 100%;
72
+ opacity: 0;
73
+ }
74
+ </style>
@@ -0,0 +1 @@
1
+ export declare const auth: import("@firebase/auth").Auth;
@@ -0,0 +1,13 @@
1
+ import { initializeApp, getApps, getApp } from 'firebase/app';
2
+ import { getAuth } from 'firebase/auth';
3
+ import { PUBLIC_FIREBASE_API_KEY, PUBLIC_FIREBASE_AUTH_DOMAIN, PUBLIC_FIREBASE_PROJECT_ID, PUBLIC_FIREBASE_STORAGE_BUCKET, PUBLIC_FIREBASE_MESSAGING_SENDER_ID, PUBLIC_FIREBASE_APP_ID } from '$env/static/public';
4
+ const firebaseConfig = {
5
+ apiKey: PUBLIC_FIREBASE_API_KEY,
6
+ authDomain: PUBLIC_FIREBASE_AUTH_DOMAIN,
7
+ projectId: PUBLIC_FIREBASE_PROJECT_ID,
8
+ storageBucket: PUBLIC_FIREBASE_STORAGE_BUCKET,
9
+ messagingSenderId: PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
10
+ appId: PUBLIC_FIREBASE_APP_ID
11
+ };
12
+ const app = getApps().length ? getApp() : initializeApp(firebaseConfig);
13
+ export const auth = getAuth(app);
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { default as Btn } from './components/Btn.svelte';
3
3
  export { default as Fab } from './components/Fab.svelte';
4
4
  export { default as Input } from './components/Input.svelte';
5
5
  export { default as Modal } from './components/Modal.svelte';
6
+ export { default as Alert } from './components/Alert.svelte';
6
7
  export { default as accountSvg } from './assets/account.svg';
7
8
  export { default as alertSvg } from './assets/alert.svg';
8
9
  export { default as calendarMonthSvg } from './assets/calendar-month.svg';
@@ -26,10 +27,16 @@ export { default as keySvg } from './assets/key.svg';
26
27
  export { default as loginSvg } from './assets/login.svg';
27
28
  export { default as logoutSvg } from './assets/logout.svg';
28
29
  export { default as magnifySvg } from './assets/magnify.svg';
30
+ export { default as magnifyWhiteSvg } from './assets/magnify-white.svg';
29
31
  export { default as mapOutlineSvg } from './assets/map-outline.svg';
30
32
  export { default as menuSvg } from './assets/menu.svg';
33
+ export { default as menuWhiteSvg } from './assets/menu-white.svg';
31
34
  export { default as messageStarOutlineSvg } from './assets/message-star-outline.svg';
32
35
  export { default as pencilSvg } from './assets/pencil.svg';
33
36
  export { default as refreshSvg } from './assets/refresh.svg';
34
37
  export { default as shapeOutlineSvg } from './assets/shape-outline.svg';
35
38
  export { default as StarSvg } from './assets/star.svg';
39
+ export { alert } from './alert';
40
+ export { authState } from './auth.svelte';
41
+ export * as firebase from './auth';
42
+ export { auth } from './firebase';
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export { default as Btn } from './components/Btn.svelte';
4
4
  export { default as Fab } from './components/Fab.svelte';
5
5
  export { default as Input } from './components/Input.svelte';
6
6
  export { default as Modal } from './components/Modal.svelte';
7
+ export { default as Alert } from './components/Alert.svelte';
7
8
  export { default as accountSvg } from './assets/account.svg';
8
9
  export { default as alertSvg } from './assets/alert.svg';
9
10
  export { default as calendarMonthSvg } from './assets/calendar-month.svg';
@@ -27,10 +28,16 @@ export { default as keySvg } from './assets/key.svg';
27
28
  export { default as loginSvg } from './assets/login.svg';
28
29
  export { default as logoutSvg } from './assets/logout.svg';
29
30
  export { default as magnifySvg } from './assets/magnify.svg';
31
+ export { default as magnifyWhiteSvg } from './assets/magnify-white.svg';
30
32
  export { default as mapOutlineSvg } from './assets/map-outline.svg';
31
33
  export { default as menuSvg } from './assets/menu.svg';
34
+ export { default as menuWhiteSvg } from './assets/menu-white.svg';
32
35
  export { default as messageStarOutlineSvg } from './assets/message-star-outline.svg';
33
36
  export { default as pencilSvg } from './assets/pencil.svg';
34
37
  export { default as refreshSvg } from './assets/refresh.svg';
35
38
  export { default as shapeOutlineSvg } from './assets/shape-outline.svg';
36
39
  export { default as StarSvg } from './assets/star.svg';
40
+ export { alert } from './alert';
41
+ export { authState } from './auth.svelte';
42
+ export * as firebase from './auth';
43
+ export { auth } from './firebase';
@@ -1,2 +1,9 @@
1
1
  export type BtnType = 'button' | 'submit';
2
2
  export type InputType = 'text' | 'email' | 'search' | 'tel' | 'url' | 'none' | 'numeric' | 'decimal' | 'password' | 'datetime-local' | 'date';
3
+ export type AlertType = 'info' | 'success' | 'error' | 'warning';
4
+ export interface AlertState {
5
+ show: boolean;
6
+ message: string;
7
+ type: AlertType;
8
+ duration: number;
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3birds/midori-ui",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -49,5 +49,8 @@
49
49
  "typescript": "^6.0.3",
50
50
  "typescript-eslint": "^8.60.1",
51
51
  "vite": "^8.0.16"
52
+ },
53
+ "dependencies": {
54
+ "firebase": "^12.19.0"
52
55
  }
53
56
  }