@hkdigital/lib-sveltekit 0.0.31
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.
- package/README.md +104 -0
- package/dist/classes/index.d.ts +2 -0
- package/dist/classes/index.js +2 -0
- package/dist/classes/stores/SubscribersCount.d.ts +39 -0
- package/dist/classes/stores/SubscribersCount.js +107 -0
- package/dist/classes/stores/index.d.ts +1 -0
- package/dist/classes/stores/index.js +1 -0
- package/dist/classes/streams/LogTransformStream.d.ts +4 -0
- package/dist/classes/streams/LogTransformStream.js +19 -0
- package/dist/classes/streams/ServerEventsStore.d.ts +22 -0
- package/dist/classes/streams/ServerEventsStore.js +110 -0
- package/dist/classes/streams/TimeStampSource.d.ts +13 -0
- package/dist/classes/streams/TimeStampSource.js +26 -0
- package/dist/classes/streams/index.d.ts +3 -0
- package/dist/classes/streams/index.js +3 -0
- package/dist/components/area/HkArea.svelte +49 -0
- package/dist/components/area/HkArea.svelte.d.ts +12 -0
- package/dist/components/area/HkGridArea.svelte +77 -0
- package/dist/components/area/HkGridArea.svelte.d.ts +20 -0
- package/dist/components/area/index.d.ts +2 -0
- package/dist/components/area/index.js +2 -0
- package/dist/components/icon/HkIcon.svelte +86 -0
- package/dist/components/icon/HkIcon.svelte.d.ts +10 -0
- package/dist/components/icon/HkTabIcon.svelte +112 -0
- package/dist/components/icon/HkTabIcon.svelte.d.ts +19 -0
- package/dist/components/icon/index.d.ts +3 -0
- package/dist/components/icon/index.js +4 -0
- package/dist/components/icon/typedef.d.ts +13 -0
- package/dist/components/icon/typedef.js +16 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +2 -0
- package/dist/components/layout/HkAppLayout.state.svelte.d.ts +6 -0
- package/dist/components/layout/HkAppLayout.state.svelte.js +25 -0
- package/dist/components/layout/HkAppLayout.svelte +251 -0
- package/dist/components/layout/HkAppLayout.svelte.d.ts +8 -0
- package/dist/components/layout/HkGridLayers.svelte +72 -0
- package/dist/components/layout/HkGridLayers.svelte.d.ts +20 -0
- package/dist/components/layout/index.d.ts +3 -0
- package/dist/components/layout/index.js +9 -0
- package/dist/components/tab-bar/HkTabBar.state.svelte.d.ts +54 -0
- package/dist/components/tab-bar/HkTabBar.state.svelte.js +149 -0
- package/dist/components/tab-bar/HkTabBar.svelte +74 -0
- package/dist/components/tab-bar/HkTabBar.svelte.d.ts +16 -0
- package/dist/components/tab-bar/HkTabBarSelector.state.svelte.d.ts +19 -0
- package/dist/components/tab-bar/HkTabBarSelector.state.svelte.js +93 -0
- package/dist/components/tab-bar/HkTabBarSelector.svelte +49 -0
- package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +17 -0
- package/dist/components/tab-bar/index.d.ts +5 -0
- package/dist/components/tab-bar/index.js +17 -0
- package/dist/components/tab-bar/typedef.d.ts +6 -0
- package/dist/components/tab-bar/typedef.js +8 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/constants/regexp/index.d.ts +3 -0
- package/dist/constants/regexp/index.js +31 -0
- package/dist/constants/regexp/inspiratie.js__ +95 -0
- package/dist/constants/regexp/text.d.ts +47 -0
- package/dist/constants/regexp/text.js +49 -0
- package/dist/constants/regexp/user.d.ts +6 -0
- package/dist/constants/regexp/user.js +33 -0
- package/dist/constants/regexp/web.d.ts +1 -0
- package/dist/constants/regexp/web.js +3 -0
- package/dist/constants/time.d.ts +19 -0
- package/dist/constants/time.js +28 -0
- package/dist/css/test.css +3 -0
- package/dist/css/utilities.postcss +44 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/logger.d.ts +24 -0
- package/dist/server/logger.js +94 -0
- package/dist/states/index.d.ts +1 -0
- package/dist/states/index.js +1 -0
- package/dist/states/navigation.svelte.d.ts +23 -0
- package/dist/states/navigation.svelte.js +55 -0
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.js +1 -0
- package/dist/stores/theme.d.ts +28 -0
- package/dist/stores/theme.js +80 -0
- package/dist/util/expect/index.d.ts +39 -0
- package/dist/util/expect/index.js +145 -0
- package/dist/util/function.js__ +150 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +2 -0
- package/dist/util/singleton/index.d.ts +34 -0
- package/dist/util/singleton/index.js +97 -0
- package/dist/util/svelte/index.d.ts +2 -0
- package/dist/util/svelte/index.js +2 -0
- package/dist/util/svelte/observe/index.d.ts +10 -0
- package/dist/util/svelte/observe/index.js +49 -0
- package/dist/util/svelte/state-context/index.d.ts +17 -0
- package/dist/util/svelte/state-context/index.js +83 -0
- package/dist/util/time.js__ +330 -0
- package/dist/valibot/index.d.ts +3 -0
- package/dist/valibot/index.js +30 -0
- package/dist/valibot/user.d.ts +6 -0
- package/dist/valibot/user.js +23 -0
- package/dist/zod/all.d.ts +6 -0
- package/dist/zod/all.js +33 -0
- package/dist/zod/generic.d.ts +6 -0
- package/dist/zod/generic.js +11 -0
- package/dist/zod/javascript.d.ts +8 -0
- package/dist/zod/javascript.js +32 -0
- package/dist/zod/user.d.ts +9 -0
- package/dist/zod/user.js +16 -0
- package/dist/zod/web.d.ts +21 -0
- package/dist/zod/web.js +57 -0
- package/package.json +144 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
/**
|
2
|
+
* Text related regexp's
|
3
|
+
*
|
4
|
+
* Letter (any language): \p{L}
|
5
|
+
* Letter latin: \p{Script=Latin}
|
6
|
+
*
|
7
|
+
* Number (any language): \p{N}
|
8
|
+
* Number (exclude letter numbers, e.g. roman): \p{Nd}
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* import { Latin_Char_Number as lcn } from './latin.js';
|
12
|
+
* export const User_Username = `^[${lcn}]+${lcn}_-]{1,38}[${lcn}]$`;
|
13
|
+
*
|
14
|
+
* const re = new RegExp('^[${Latin_Number}]', 'u');
|
15
|
+
*
|
16
|
+
* Emoji:
|
17
|
+
*
|
18
|
+
* The v flag enables support
|
19
|
+
*
|
20
|
+
* RGI_Emoji in Unicode is defined as “the subset of all valid emoji
|
21
|
+
* (characters and sequences) recommended for general interchange”.
|
22
|
+
* With this, we can now match emoji regardless of how many code points
|
23
|
+
* they consist of under the hood!
|
24
|
+
*
|
25
|
+
* @see https://v8.dev/features/regexp-v-flag
|
26
|
+
*
|
27
|
+
* Punctuation:
|
28
|
+
* Puntuation marks are periods, commas, exclamation marks, question marks etc.
|
29
|
+
* Astral symbols are emoji
|
30
|
+
*
|
31
|
+
* @note
|
32
|
+
* \p{Punctuation} matches a small subset: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
33
|
+
* \p{IsPunctuation} matches a wide subset, including e.g. «, », ¿, ¡, §,
|
34
|
+
* ¶, ‘, ’, “, ”, and ‽.
|
35
|
+
*
|
36
|
+
* @see https://stackoverflow.com/questions/4328500/
|
37
|
+
* how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex
|
38
|
+
*
|
39
|
+
* @see https://en.wikipedia.org/
|
40
|
+
* wiki/Unicode_character_property#General_Category
|
41
|
+
*/
|
42
|
+
export const CHAR: "\\p{Script=Latin}";
|
43
|
+
export const NUMBER: "\\p{Nd}";
|
44
|
+
export const CHAR_NUMBER: "\\p{Script=Latin}\\p{Nd}";
|
45
|
+
export const EMOJI: "\\p{RGI_Emoji}";
|
46
|
+
export const PUNCTUATION: "\\p{Punctuation}$+<=>\\^`\\|~";
|
47
|
+
export const PUNCT: "\\p{Punctuation}$+<=>\\^`\\|~";
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* Text related regexp's
|
3
|
+
*
|
4
|
+
* Letter (any language): \p{L}
|
5
|
+
* Letter latin: \p{Script=Latin}
|
6
|
+
*
|
7
|
+
* Number (any language): \p{N}
|
8
|
+
* Number (exclude letter numbers, e.g. roman): \p{Nd}
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* import { Latin_Char_Number as lcn } from './latin.js';
|
12
|
+
* export const User_Username = `^[${lcn}]+${lcn}_-]{1,38}[${lcn}]$`;
|
13
|
+
*
|
14
|
+
* const re = new RegExp('^[${Latin_Number}]', 'u');
|
15
|
+
*
|
16
|
+
* Emoji:
|
17
|
+
*
|
18
|
+
* The v flag enables support
|
19
|
+
*
|
20
|
+
* RGI_Emoji in Unicode is defined as “the subset of all valid emoji
|
21
|
+
* (characters and sequences) recommended for general interchange”.
|
22
|
+
* With this, we can now match emoji regardless of how many code points
|
23
|
+
* they consist of under the hood!
|
24
|
+
*
|
25
|
+
* @see https://v8.dev/features/regexp-v-flag
|
26
|
+
*
|
27
|
+
* Punctuation:
|
28
|
+
* Puntuation marks are periods, commas, exclamation marks, question marks etc.
|
29
|
+
* Astral symbols are emoji
|
30
|
+
*
|
31
|
+
* @note
|
32
|
+
* \p{Punctuation} matches a small subset: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
33
|
+
* \p{IsPunctuation} matches a wide subset, including e.g. «, », ¿, ¡, §,
|
34
|
+
* ¶, ‘, ’, “, ”, and ‽.
|
35
|
+
*
|
36
|
+
* @see https://stackoverflow.com/questions/4328500/
|
37
|
+
* how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex
|
38
|
+
*
|
39
|
+
* @see https://en.wikipedia.org/
|
40
|
+
* wiki/Unicode_character_property#General_Category
|
41
|
+
*/
|
42
|
+
|
43
|
+
export const CHAR = '\\p{Script=Latin}';
|
44
|
+
export const NUMBER = '\\p{Nd}';
|
45
|
+
export const CHAR_NUMBER = `${CHAR}${NUMBER}`;
|
46
|
+
|
47
|
+
export const EMOJI = '\\p{RGI_Emoji}';
|
48
|
+
export const PUNCTUATION = '\\p{Punctuation}$+<=>\\^`\\|~';
|
49
|
+
export const PUNCT = PUNCTUATION;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* User related regexps
|
3
|
+
*
|
4
|
+
* Inspired by
|
5
|
+
* @see https://ihateregex.io/expr/username/
|
6
|
+
* @see https://ihateregex.io/expr/discord-username/
|
7
|
+
*/
|
8
|
+
|
9
|
+
import { NUMBER as N, CHAR, CHAR_NUMBER as CN } from './text.js';
|
10
|
+
|
11
|
+
export const RE_NAME = new RegExp(
|
12
|
+
`^[${CHAR}]+(([\\s'\\-\\.]{1}|[\\s]{1}[']{0,1})[${CHAR}]+){0,8}$`, 'v'
|
13
|
+
);
|
14
|
+
|
15
|
+
export const RE_FULLNAME = new RegExp(
|
16
|
+
`^[${CHAR}]{2,}[\\s][']?[${CHAR}]{1,}([\\s]?['\\-]?[${CHAR}]{1,})*$`, 'v'
|
17
|
+
);
|
18
|
+
|
19
|
+
export const RE_SURNAME = new RegExp(
|
20
|
+
`^[']?[${CHAR}]{1,}([\\s]?['\\-]?[${CHAR}]{1,})*$`, 'v'
|
21
|
+
)
|
22
|
+
|
23
|
+
export const RE_USERNAME = new RegExp(
|
24
|
+
`^[${CN}]{2,40}([\\-_\\.][${CN}]{1,40}){0,3}([#][${N}]{1,10}){0,1}$`, 'v'
|
25
|
+
);
|
26
|
+
|
27
|
+
export const RE_EMAIL = new RegExp(
|
28
|
+
`[^@ \t\r\n]+@[^@ \t\r\n]+\.[^@ \t\r\n]+`, 'v'
|
29
|
+
);
|
30
|
+
|
31
|
+
export const RE_PHONENUMBER = new RegExp(
|
32
|
+
`^[\\+]?[\\(]?[0-9]{3}[\\)]?[\\-\\s\\.]?[0-9]{3}[\\-\\s\\.]?[0-9]{4,6}$`, 'v'
|
33
|
+
)
|
@@ -0,0 +1 @@
|
|
1
|
+
export const URL_SLUG: "^[\\p{Script=Latin}\\p{Nd}]+([-]{0,1}[\\p{Script=Latin}\\p{Nd}]+)*$";
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export const SECOND_MS: 1000;
|
2
|
+
export const MINUTE_MS: number;
|
3
|
+
export const HOUR_MS: number;
|
4
|
+
export const DAY_MS: number;
|
5
|
+
export const WEEK_MS: number;
|
6
|
+
export const HOURLY: "hourly";
|
7
|
+
export const DAILY: "daily";
|
8
|
+
export const WEEKLY: "weekly";
|
9
|
+
export const TWO_WEEKLY: "two-weekly";
|
10
|
+
export const FOUR_WEEKLY: "four-weekly";
|
11
|
+
export const INTERVALS_MS: {
|
12
|
+
hourly: number;
|
13
|
+
daily: number;
|
14
|
+
weekly: number;
|
15
|
+
"two-weekly": number;
|
16
|
+
"four-weekly": number;
|
17
|
+
};
|
18
|
+
export const TIME_2020_01_01: 1577836800000;
|
19
|
+
export const TIME_2100_01_01: 4102444800000;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// > Units
|
2
|
+
|
3
|
+
export const SECOND_MS = 1000;
|
4
|
+
export const MINUTE_MS = 60 * SECOND_MS;
|
5
|
+
export const HOUR_MS = 60 * MINUTE_MS;
|
6
|
+
export const DAY_MS = 24 * HOUR_MS;
|
7
|
+
export const WEEK_MS = 7 * DAY_MS;
|
8
|
+
|
9
|
+
// > Fixed length intervals
|
10
|
+
|
11
|
+
export const HOURLY = 'hourly';
|
12
|
+
export const DAILY = 'daily';
|
13
|
+
export const WEEKLY = 'weekly';
|
14
|
+
export const TWO_WEEKLY = 'two-weekly';
|
15
|
+
export const FOUR_WEEKLY = 'four-weekly';
|
16
|
+
|
17
|
+
export const INTERVALS_MS = {
|
18
|
+
[HOURLY]: HOUR_MS,
|
19
|
+
[DAILY]: DAY_MS,
|
20
|
+
[WEEKLY]: WEEK_MS,
|
21
|
+
[TWO_WEEKLY]: WEEK_MS * 2,
|
22
|
+
[FOUR_WEEKLY]: WEEK_MS * 4
|
23
|
+
};
|
24
|
+
|
25
|
+
// > Offsets
|
26
|
+
|
27
|
+
export const TIME_2020_01_01 = 1577836800000; // 2020-01-01T00:00:00.000Z
|
28
|
+
export const TIME_2100_01_01 = 4102444800000; // 2100-01-01T00:00:00.000Z
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
* Common utility CSS classes
|
3
|
+
*
|
4
|
+
* Using tailwind layers
|
5
|
+
* @see https://tailwindcss.com/docs/functions-and-directives
|
6
|
+
*/
|
7
|
+
|
8
|
+
@layer utilities {
|
9
|
+
.g-no-select {
|
10
|
+
user-select: none;
|
11
|
+
-webkit-user-select: none; /* ios safari */
|
12
|
+
}
|
13
|
+
|
14
|
+
input[type=text].g-no-select, textarea.g-no-select
|
15
|
+
{
|
16
|
+
user-select: text !important;
|
17
|
+
cursor: text;
|
18
|
+
}
|
19
|
+
|
20
|
+
.g-no-double-tab-zoom {
|
21
|
+
/* tailwind touch-manipulation */
|
22
|
+
touch-action: manipulation;
|
23
|
+
}
|
24
|
+
|
25
|
+
.g-no-pinch-zoom
|
26
|
+
{
|
27
|
+
touch-action: pan-x pan-y; /* no pinch zoom, but allow scroll */
|
28
|
+
}
|
29
|
+
|
30
|
+
.g-no-highlights {
|
31
|
+
-webkit-tap-highlight-color: transparent;
|
32
|
+
}
|
33
|
+
|
34
|
+
}
|
35
|
+
|
36
|
+
/* .g-grid-layers {
|
37
|
+
display: grid;
|
38
|
+
grid-template-columns: 1fr;
|
39
|
+
grid-template-rows: 1fr;
|
40
|
+
|
41
|
+
& > * {
|
42
|
+
grid-area: 1/1/2/2;
|
43
|
+
}
|
44
|
+
} */
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./logger.js";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './logger.js';
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export type LoggerContext = {
|
2
|
+
route?: {
|
3
|
+
id: string;
|
4
|
+
};
|
5
|
+
componentName?: string;
|
6
|
+
};
|
7
|
+
export type ExtendedLogger = pino.Logger & LoggerExtension;
|
8
|
+
export type LoggerExtension = {
|
9
|
+
context: (context: LoggerContext) => ExtendedLogger;
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* @typedef {object} LoggerContext
|
13
|
+
* @property {{ id: string }} [route]
|
14
|
+
* @property {string} [componentName]
|
15
|
+
*/
|
16
|
+
/**
|
17
|
+
* @typedef {pino.Logger & LoggerExtension} ExtendedLogger
|
18
|
+
*/
|
19
|
+
/**
|
20
|
+
* @typedef {Object} LoggerExtension
|
21
|
+
* @property {( context: LoggerContext )=> ExtendedLogger} context
|
22
|
+
*/
|
23
|
+
/** @type {pino.Logger & LoggerExtension} */
|
24
|
+
export const logger: pino.Logger & LoggerExtension;
|
@@ -0,0 +1,94 @@
|
|
1
|
+
/**
|
2
|
+
* @example
|
3
|
+
*
|
4
|
+
* import { logger } from './logger.js';
|
5
|
+
*
|
6
|
+
* logger.info('Hello there!');
|
7
|
+
* logger.info( { a: 1, b: 2 }, 'Test vars');
|
8
|
+
*
|
9
|
+
* export function load({ route }) {
|
10
|
+
* logger.context({route}).info('Log');
|
11
|
+
* }
|
12
|
+
*
|
13
|
+
* @note
|
14
|
+
* Set a 'handleError' hook to log errors captured by svelte
|
15
|
+
*
|
16
|
+
* // hooks.server.js
|
17
|
+
* export const handleError = ({ status, error, message }) => {
|
18
|
+
* if (status !== 404) {
|
19
|
+
* logger.error(error);
|
20
|
+
* }
|
21
|
+
*
|
22
|
+
* // do not return sensitive data here as it will be sent to the client
|
23
|
+
* return { message };
|
24
|
+
* };
|
25
|
+
*
|
26
|
+
* @see https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror
|
27
|
+
* @see https://stolthq.com/blog/structured-logging-sveltekit
|
28
|
+
*/
|
29
|
+
|
30
|
+
import pino from 'pino';
|
31
|
+
import { dev } from '$app/environment';
|
32
|
+
|
33
|
+
// import { browser, building, dev, version } from '$app/environment';
|
34
|
+
|
35
|
+
// > Setup
|
36
|
+
|
37
|
+
/** @type {pino.LoggerOptions} */
|
38
|
+
let options = {};
|
39
|
+
|
40
|
+
if (dev) {
|
41
|
+
options = {
|
42
|
+
level: 'debug',
|
43
|
+
transport: {
|
44
|
+
target: 'pino-pretty',
|
45
|
+
options: {
|
46
|
+
colorize: true
|
47
|
+
}
|
48
|
+
}
|
49
|
+
};
|
50
|
+
}
|
51
|
+
|
52
|
+
// > Exports
|
53
|
+
|
54
|
+
// ?? function routeLogger( ... )
|
55
|
+
|
56
|
+
/**
|
57
|
+
* @typedef {object} LoggerContext
|
58
|
+
* @property {{ id: string }} [route]
|
59
|
+
* @property {string} [componentName]
|
60
|
+
*/
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @typedef {pino.Logger & LoggerExtension} ExtendedLogger
|
64
|
+
*/
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @typedef {Object} LoggerExtension
|
68
|
+
* @property {( context: LoggerContext )=> ExtendedLogger} context
|
69
|
+
*/
|
70
|
+
|
71
|
+
/** @type {pino.Logger & LoggerExtension} */
|
72
|
+
// @ts-ignore
|
73
|
+
const logger = pino(options);
|
74
|
+
|
75
|
+
Object.assign(logger, {
|
76
|
+
/**
|
77
|
+
* @param {LoggerContext} _
|
78
|
+
*
|
79
|
+
* @returns {pino.Logger}
|
80
|
+
*/
|
81
|
+
context({ route, componentName }) {
|
82
|
+
if (route) {
|
83
|
+
// @ts-ignore
|
84
|
+
return this.child({ route: route.id });
|
85
|
+
} else if (componentName) {
|
86
|
+
// @ts-ignore
|
87
|
+
return this.child({ componentName });
|
88
|
+
} else {
|
89
|
+
throw new Error(`Missing input parameter`);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
});
|
93
|
+
|
94
|
+
export { logger };
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./navigation.svelte.js";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './navigation.svelte.js';
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* @note call nav.init() during component initialization phase
|
3
|
+
*/
|
4
|
+
export const nav: Navigation & {
|
5
|
+
init: () => null;
|
6
|
+
};
|
7
|
+
declare class Navigation {
|
8
|
+
/** @type {{ url: { pathname: string } }} */
|
9
|
+
page: {
|
10
|
+
url: {
|
11
|
+
pathname: string;
|
12
|
+
};
|
13
|
+
};
|
14
|
+
/** @type {string} */
|
15
|
+
pathname: string;
|
16
|
+
stage: {
|
17
|
+
before: boolean;
|
18
|
+
navigating: boolean;
|
19
|
+
after: boolean;
|
20
|
+
};
|
21
|
+
init(): void;
|
22
|
+
}
|
23
|
+
export {};
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { onMount } from 'svelte';
|
2
|
+
|
3
|
+
import { lazySingleton } from '../util/singleton/index.js';
|
4
|
+
|
5
|
+
import { beforeNavigate, onNavigate, afterNavigate } from '$app/navigation';
|
6
|
+
|
7
|
+
import { page } from '$app/stores';
|
8
|
+
import { get } from 'svelte/store';
|
9
|
+
|
10
|
+
class Navigation {
|
11
|
+
// TODO: complete page type
|
12
|
+
|
13
|
+
/** @type {{ url: { pathname: string } }} */
|
14
|
+
page = $state(get(page));
|
15
|
+
|
16
|
+
/** @type {string} */
|
17
|
+
pathname = $derived(this.page.url.pathname);
|
18
|
+
|
19
|
+
stage = $state.raw({ before: false, navigating: true, after: false });
|
20
|
+
|
21
|
+
constructor() {
|
22
|
+
beforeNavigate(() => {
|
23
|
+
this.stage = { before: true, navigating: false, after: false };
|
24
|
+
});
|
25
|
+
|
26
|
+
onNavigate(() => {
|
27
|
+
this.stage = { before: false, navigating: true, after: false };
|
28
|
+
});
|
29
|
+
|
30
|
+
// onNavigate(async () => {
|
31
|
+
// console.log('onNavigate can be used to perform async page transitions');
|
32
|
+
// return new Promise((resolve) => {
|
33
|
+
// setTimeout(resolve, 1000);
|
34
|
+
// });
|
35
|
+
// });
|
36
|
+
|
37
|
+
afterNavigate(() => {
|
38
|
+
this.stage = { before: false, navigating: false, after: true };
|
39
|
+
});
|
40
|
+
|
41
|
+
onMount(() => {
|
42
|
+
return page.subscribe((value) => {
|
43
|
+
// console.log('***update page url');
|
44
|
+
this.page = value;
|
45
|
+
});
|
46
|
+
});
|
47
|
+
} // end constructor
|
48
|
+
|
49
|
+
init() {}
|
50
|
+
} // end class
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @note call nav.init() during component initialization phase
|
54
|
+
*/
|
55
|
+
export const nav = lazySingleton({ class: Navigation });
|
@@ -0,0 +1 @@
|
|
1
|
+
export * as theme from "./theme.js";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * as theme from './theme.js';
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* Set meta theme color for both light and dark mode
|
3
|
+
*
|
4
|
+
* @param {string} value - HTML Color
|
5
|
+
*/
|
6
|
+
export function setMetaThemeColor(value: string): void;
|
7
|
+
/**
|
8
|
+
* Set meta theme color for light mode
|
9
|
+
*
|
10
|
+
* @param {string} value - HTML Color
|
11
|
+
*/
|
12
|
+
export function setMetaThemeColorBase(value: string): void;
|
13
|
+
/**
|
14
|
+
* Set meta theme color for dark mode only
|
15
|
+
*
|
16
|
+
* @param {string} value - HTML Color
|
17
|
+
*/
|
18
|
+
export function setMetaThemeColorDark(value: string): void;
|
19
|
+
export namespace metaThemeColorBase {
|
20
|
+
let subscribe: (this: void, run: import("svelte/store").Subscriber<string>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
|
21
|
+
function get(): void;
|
22
|
+
}
|
23
|
+
export namespace metaThemeColorDark {
|
24
|
+
let subscribe_1: (this: void, run: import("svelte/store").Subscriber<string>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
|
25
|
+
export { subscribe_1 as subscribe };
|
26
|
+
export function get_1(): void;
|
27
|
+
export { get_1 as get };
|
28
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
/**
|
2
|
+
* @example Set theme color in a layout file
|
3
|
+
*
|
4
|
+
* // +layout.svelte
|
5
|
+
* <script>
|
6
|
+
* import { theme as themeStore } from './theme.js';
|
7
|
+
*
|
8
|
+
* const { metaThemeColorBase, metaThemeColorDark } = themeStore;
|
9
|
+
* </script>
|
10
|
+
*
|
11
|
+
* <svelte:head>
|
12
|
+
* <meta
|
13
|
+
* name="theme-color"
|
14
|
+
* media="(prefers-color-scheme: light)"
|
15
|
+
* content={$metaThemeColorBase}
|
16
|
+
* />
|
17
|
+
* <meta
|
18
|
+
* name="theme-color"
|
19
|
+
* media="(prefers-color-scheme: dark)"
|
20
|
+
* content={$metaThemeColorDark}
|
21
|
+
* />
|
22
|
+
* </svelte:head>
|
23
|
+
*/
|
24
|
+
|
25
|
+
import { writable, get } from 'svelte/store';
|
26
|
+
|
27
|
+
// > Internals
|
28
|
+
|
29
|
+
const DEFAULT_THEME_COLOR_BASE = '#fffffe';
|
30
|
+
const DEFAULT_THEME_COLOR_DARK = '#000001';
|
31
|
+
|
32
|
+
/** @type {import('svelte/store').Writable<string>} */
|
33
|
+
const themeColorBase = writable(DEFAULT_THEME_COLOR_BASE);
|
34
|
+
|
35
|
+
/** @type {import('svelte/store').Writable<string|null>} */
|
36
|
+
const themeColorDark = writable(DEFAULT_THEME_COLOR_DARK);
|
37
|
+
|
38
|
+
// > Exports
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Set meta theme color for both light and dark mode
|
42
|
+
*
|
43
|
+
* @param {string} value - HTML Color
|
44
|
+
*/
|
45
|
+
export function setMetaThemeColor(value) {
|
46
|
+
themeColorBase.set(value);
|
47
|
+
themeColorDark.set(value);
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Set meta theme color for light mode
|
52
|
+
*
|
53
|
+
* @param {string} value - HTML Color
|
54
|
+
*/
|
55
|
+
export function setMetaThemeColorBase(value) {
|
56
|
+
themeColorBase.set(value);
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Set meta theme color for dark mode only
|
61
|
+
*
|
62
|
+
* @param {string} value - HTML Color
|
63
|
+
*/
|
64
|
+
export function setMetaThemeColorDark(value) {
|
65
|
+
themeColorDark.set(value);
|
66
|
+
}
|
67
|
+
|
68
|
+
export const metaThemeColorBase = {
|
69
|
+
subscribe: themeColorBase.subscribe,
|
70
|
+
get: () => {
|
71
|
+
get(themeColorBase);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
export const metaThemeColorDark = {
|
76
|
+
subscribe: themeColorDark.subscribe,
|
77
|
+
get: () => {
|
78
|
+
get(themeColorDark);
|
79
|
+
}
|
80
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/** Reusable schema's */
|
2
|
+
/** Exports */
|
3
|
+
/**
|
4
|
+
* Throws a validation error if value is not a string
|
5
|
+
*
|
6
|
+
* @param {*} value
|
7
|
+
*/
|
8
|
+
export function string(value: any): void;
|
9
|
+
/**
|
10
|
+
* Throws a validation error if value is not an array of strings
|
11
|
+
*
|
12
|
+
* @param {*} value
|
13
|
+
*/
|
14
|
+
export function stringArray(value: any): void;
|
15
|
+
/**
|
16
|
+
* Throws a validation error if value is not an array of objects
|
17
|
+
*
|
18
|
+
* @param {*} value
|
19
|
+
*/
|
20
|
+
export function objectArray(value: any): void;
|
21
|
+
/**
|
22
|
+
* Expect a value to be a boolean and true
|
23
|
+
*
|
24
|
+
* @param {*} value
|
25
|
+
*/
|
26
|
+
export function _true(value: any): void;
|
27
|
+
/**
|
28
|
+
* Throws a validation error if value is not a string
|
29
|
+
*
|
30
|
+
* @param {*} value
|
31
|
+
*/
|
32
|
+
export function notEmptyString(value: any): void;
|
33
|
+
/**
|
34
|
+
* Throws a validation error if value is not a function
|
35
|
+
*
|
36
|
+
* @param {*} value
|
37
|
+
*/
|
38
|
+
declare function _function(value: any): void;
|
39
|
+
export { _function as function, _function as function, _function as class, _class as class, _true as true, _true as true };
|