@phosart/common 0.4.22
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 +58 -0
- package/dist/FullGallery.svelte +51 -0
- package/dist/FullGallery.svelte.d.ts +17 -0
- package/dist/FullGallery.svelte.d.ts.map +1 -0
- package/dist/Gallery.svelte +30 -0
- package/dist/Gallery.svelte.d.ts +14 -0
- package/dist/Gallery.svelte.d.ts.map +1 -0
- package/dist/GalleryPreview.svelte +60 -0
- package/dist/GalleryPreview.svelte.d.ts +9 -0
- package/dist/GalleryPreview.svelte.d.ts.map +1 -0
- package/dist/HighResContext.svelte +21 -0
- package/dist/HighResContext.svelte.d.ts +8 -0
- package/dist/HighResContext.svelte.d.ts.map +1 -0
- package/dist/Image.svelte +171 -0
- package/dist/Image.svelte.d.ts +14 -0
- package/dist/Image.svelte.d.ts.map +1 -0
- package/dist/Modal.svelte +87 -0
- package/dist/Modal.svelte.d.ts +9 -0
- package/dist/Modal.svelte.d.ts.map +1 -0
- package/dist/ModalGallery/Carousel.svelte +76 -0
- package/dist/ModalGallery/Carousel.svelte.d.ts +10 -0
- package/dist/ModalGallery/Carousel.svelte.d.ts.map +1 -0
- package/dist/ModalGallery/ImageSection.svelte +156 -0
- package/dist/ModalGallery/ImageSection.svelte.d.ts +11 -0
- package/dist/ModalGallery/ImageSection.svelte.d.ts.map +1 -0
- package/dist/ModalGallery/ImageView.svelte +92 -0
- package/dist/ModalGallery/ImageView.svelte.d.ts +9 -0
- package/dist/ModalGallery/ImageView.svelte.d.ts.map +1 -0
- package/dist/ModalGallery/Spinner.svelte +71 -0
- package/dist/ModalGallery/Spinner.svelte.d.ts +7 -0
- package/dist/ModalGallery/Spinner.svelte.d.ts.map +1 -0
- package/dist/ModalGallery.svelte +165 -0
- package/dist/ModalGallery.svelte.d.ts +16 -0
- package/dist/ModalGallery.svelte.d.ts.map +1 -0
- package/dist/OpengraphMeta.svelte +125 -0
- package/dist/OpengraphMeta.svelte.d.ts +15 -0
- package/dist/OpengraphMeta.svelte.d.ts.map +1 -0
- package/dist/Postcard/ArtistLink.svelte +46 -0
- package/dist/Postcard/ArtistLink.svelte.d.ts +9 -0
- package/dist/Postcard/ArtistLink.svelte.d.ts.map +1 -0
- package/dist/Postcard/Chip.svelte +100 -0
- package/dist/Postcard/Chip.svelte.d.ts +12 -0
- package/dist/Postcard/Chip.svelte.d.ts.map +1 -0
- package/dist/Postcard/Description/Character.svelte +79 -0
- package/dist/Postcard/Description/Character.svelte.d.ts +9 -0
- package/dist/Postcard/Description/Character.svelte.d.ts.map +1 -0
- package/dist/Postcard/Description.svelte +146 -0
- package/dist/Postcard/Description.svelte.d.ts +13 -0
- package/dist/Postcard/Description.svelte.d.ts.map +1 -0
- package/dist/Postcard/Headline.svelte +70 -0
- package/dist/Postcard/Headline.svelte.d.ts +10 -0
- package/dist/Postcard/Headline.svelte.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/server/artist.d.ts +7 -0
- package/dist/server/artist.d.ts.map +1 -0
- package/dist/server/artist.js +40 -0
- package/dist/server/character.d.ts +9 -0
- package/dist/server/character.d.ts.map +1 -0
- package/dist/server/character.js +76 -0
- package/dist/server/directories.d.ts +4 -0
- package/dist/server/directories.d.ts.map +1 -0
- package/dist/server/directories.js +39 -0
- package/dist/server/fastcache.d.ts +11 -0
- package/dist/server/fastcache.d.ts.map +1 -0
- package/dist/server/fastcache.js +43 -0
- package/dist/server/filter.d.ts +6 -0
- package/dist/server/filter.d.ts.map +1 -0
- package/dist/server/filter.js +53 -0
- package/dist/server/gallery.d.ts +16 -0
- package/dist/server/gallery.d.ts.map +1 -0
- package/dist/server/gallery.js +162 -0
- package/dist/server/imageprocess.d.ts +18 -0
- package/dist/server/imageprocess.d.ts.map +1 -0
- package/dist/server/imageprocess.js +243 -0
- package/dist/server/index.d.ts +15 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +15 -0
- package/dist/server/models/Artist.d.ts +7 -0
- package/dist/server/models/Artist.d.ts.map +1 -0
- package/dist/server/models/Artist.js +15 -0
- package/dist/server/models/Character.d.ts +108 -0
- package/dist/server/models/Character.d.ts.map +1 -0
- package/dist/server/models/Character.js +21 -0
- package/dist/server/models/Gallery.d.ts +373 -0
- package/dist/server/models/Gallery.d.ts.map +1 -0
- package/dist/server/models/Gallery.js +60 -0
- package/dist/server/models/image.d.ts +64 -0
- package/dist/server/models/image.d.ts.map +1 -0
- package/dist/server/models/image.js +17 -0
- package/dist/server/pack.d.ts +3 -0
- package/dist/server/pack.d.ts.map +1 -0
- package/dist/server/pack.js +26 -0
- package/dist/server/theme/schema.d.ts +57 -0
- package/dist/server/theme/schema.d.ts.map +1 -0
- package/dist/server/theme/schema.js +217 -0
- package/dist/server/util.d.ts +24 -0
- package/dist/server/util.d.ts.map +1 -0
- package/dist/server/util.js +71 -0
- package/dist/util/art.d.ts +52 -0
- package/dist/util/art.d.ts.map +1 -0
- package/dist/util/art.js +57 -0
- package/dist/util/artistcontext.svelte.d.ts +8 -0
- package/dist/util/artistcontext.svelte.d.ts.map +1 -0
- package/dist/util/artistcontext.svelte.js +18 -0
- package/dist/util/charactercontext.svelte.d.ts +4 -0
- package/dist/util/charactercontext.svelte.d.ts.map +1 -0
- package/dist/util/charactercontext.svelte.js +11 -0
- package/dist/util/date.d.ts +2 -0
- package/dist/util/date.d.ts.map +1 -0
- package/dist/util/date.js +6 -0
- package/dist/util/index.d.ts +13 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +10 -0
- package/dist/util/markdown.d.ts +2 -0
- package/dist/util/markdown.d.ts.map +1 -0
- package/dist/util/markdown.js +16 -0
- package/dist/util/phosart_config.svelte.d.ts +44 -0
- package/dist/util/phosart_config.svelte.d.ts.map +1 -0
- package/dist/util/phosart_config.svelte.js +51 -0
- package/dist/util/search.d.ts +3 -0
- package/dist/util/search.d.ts.map +1 -0
- package/dist/util/search.js +24 -0
- package/dist/util/smoothscroll.d.ts +4 -0
- package/dist/util/smoothscroll.d.ts.map +1 -0
- package/dist/util/smoothscroll.js +21 -0
- package/dist/util/tree.d.ts +19 -0
- package/dist/util/tree.d.ts.map +1 -0
- package/dist/util/tree.js +58 -0
- package/dist/util/util.d.ts +4 -0
- package/dist/util/util.d.ts.map +1 -0
- package/dist/util/util.js +22 -0
- package/package.json +102 -0
- package/src/lib/FullGallery.svelte +51 -0
- package/src/lib/Gallery.svelte +30 -0
- package/src/lib/GalleryPreview.svelte +60 -0
- package/src/lib/HighResContext.svelte +21 -0
- package/src/lib/Image.svelte +171 -0
- package/src/lib/Modal.svelte +87 -0
- package/src/lib/ModalGallery/Carousel.svelte +76 -0
- package/src/lib/ModalGallery/ImageSection.svelte +156 -0
- package/src/lib/ModalGallery/ImageView.svelte +92 -0
- package/src/lib/ModalGallery/Spinner.svelte +71 -0
- package/src/lib/ModalGallery.svelte +165 -0
- package/src/lib/OpengraphMeta.svelte +125 -0
- package/src/lib/Postcard/ArtistLink.svelte +46 -0
- package/src/lib/Postcard/Chip.svelte +100 -0
- package/src/lib/Postcard/Description/Character.svelte +79 -0
- package/src/lib/Postcard/Description.svelte +146 -0
- package/src/lib/Postcard/Headline.svelte +70 -0
- package/src/lib/index.ts +20 -0
- package/src/lib/server/artist.ts +50 -0
- package/src/lib/server/character.ts +113 -0
- package/src/lib/server/directories.ts +45 -0
- package/src/lib/server/fastcache.ts +66 -0
- package/src/lib/server/filter.ts +71 -0
- package/src/lib/server/gallery.ts +259 -0
- package/src/lib/server/imageprocess.ts +382 -0
- package/src/lib/server/index.ts +57 -0
- package/src/lib/server/models/Artist.ts +19 -0
- package/src/lib/server/models/Character.ts +24 -0
- package/src/lib/server/models/Gallery.ts +70 -0
- package/src/lib/server/models/image.ts +20 -0
- package/src/lib/server/pack.ts +31 -0
- package/src/lib/server/theme/schema.ts +286 -0
- package/src/lib/server/util.ts +102 -0
- package/src/lib/util/art.ts +136 -0
- package/src/lib/util/artistcontext.svelte.ts +25 -0
- package/src/lib/util/charactercontext.svelte.ts +15 -0
- package/src/lib/util/date.ts +7 -0
- package/src/lib/util/index.ts +29 -0
- package/src/lib/util/markdown.ts +17 -0
- package/src/lib/util/phosart_config.svelte.ts +101 -0
- package/src/lib/util/search.ts +28 -0
- package/src/lib/util/smoothscroll.ts +21 -0
- package/src/lib/util/tree.ts +75 -0
- package/src/lib/util/util.ts +37 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import z from 'zod';
|
|
5
|
+
import { $DATA } from "../directories.js";
|
|
6
|
+
import { parse, stringify } from 'yaml';
|
|
7
|
+
import { Logger } from 'tslog';
|
|
8
|
+
import { getLogLevel } from "../util.js";
|
|
9
|
+
const ThemeLogger = new Logger({ minLevel: getLogLevel() });
|
|
10
|
+
const $THEMESCHEMA = () => path.resolve($DATA(), '.theme-schema.json');
|
|
11
|
+
const $TYPE = () => path.resolve($DATA(), 'generated-schema.ts');
|
|
12
|
+
const $THEMECONFIG = () => path.resolve($DATA(), 'theme-config.yaml');
|
|
13
|
+
const BLANK = `{
|
|
14
|
+
"$schema": "https://raw.githubusercontent.com/PhosphoriteArt/phosart-common/refs/heads/main/settings.schema.json"
|
|
15
|
+
}`;
|
|
16
|
+
const ZColorOption = z.object({ type: z.literal('color') });
|
|
17
|
+
const ZSelectionOption = z.object({
|
|
18
|
+
type: z.literal('selection'),
|
|
19
|
+
options: z.array(z.string()),
|
|
20
|
+
multi: z.literal(false).optional()
|
|
21
|
+
});
|
|
22
|
+
const ZMultiSelectionOption = z.object({
|
|
23
|
+
type: z.literal('selection'),
|
|
24
|
+
options: z.array(z.string()),
|
|
25
|
+
multi: z.literal(true)
|
|
26
|
+
});
|
|
27
|
+
const ZStringOption = z.object({ type: z.literal('string') });
|
|
28
|
+
const ZTagsOption = z.object({ type: z.literal('tag-list') });
|
|
29
|
+
const ZStringList = z.object({ type: z.literal('string-list') });
|
|
30
|
+
export const ZThemeSettingsSchema = z.record(z.string(), z.union([
|
|
31
|
+
ZColorOption,
|
|
32
|
+
ZSelectionOption,
|
|
33
|
+
ZMultiSelectionOption,
|
|
34
|
+
ZTagsOption,
|
|
35
|
+
ZStringList,
|
|
36
|
+
ZStringOption
|
|
37
|
+
]));
|
|
38
|
+
export const builtinSettings = {
|
|
39
|
+
defaultArtist: { type: 'string' }
|
|
40
|
+
};
|
|
41
|
+
export async function readThemeSchema() {
|
|
42
|
+
let text;
|
|
43
|
+
try {
|
|
44
|
+
text = await readFile($THEMESCHEMA(), { encoding: 'utf-8' });
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
ThemeLogger.warn('Error reading theme file:', err, 'recreating');
|
|
48
|
+
await writeFile($THEMESCHEMA(), BLANK, { encoding: 'utf-8' });
|
|
49
|
+
text = BLANK;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const data = JSON.parse(text);
|
|
53
|
+
if (typeof data === 'object') {
|
|
54
|
+
delete data['$schema'];
|
|
55
|
+
}
|
|
56
|
+
const settings = await ZThemeSettingsSchema.parseAsync(data);
|
|
57
|
+
await writeGeneratedSchema(settings);
|
|
58
|
+
return settings;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
ThemeLogger.warn('Error parsing theme file:', err);
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function escape(token) {
|
|
66
|
+
return token.replaceAll('\\', '\\\\').replaceAll('"', '\\"');
|
|
67
|
+
}
|
|
68
|
+
async function writeGeneratedSchema(schema) {
|
|
69
|
+
let ts = `export interface ThemeSchema {`;
|
|
70
|
+
for (const [k, v] of Object.entries(schema)) {
|
|
71
|
+
switch (v.type) {
|
|
72
|
+
case 'color':
|
|
73
|
+
ts += `\n "${escape(k)}": \`#\${string}\`;`;
|
|
74
|
+
break;
|
|
75
|
+
case 'selection': {
|
|
76
|
+
const opts = v.options
|
|
77
|
+
.map(escape)
|
|
78
|
+
.map((k) => `"${k}"`)
|
|
79
|
+
.join(' | ');
|
|
80
|
+
const typ = v.multi ? `Array<${opts}>` : opts;
|
|
81
|
+
ts += `\n "${escape(k)}": ` + typ + ';';
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'string':
|
|
85
|
+
ts += `\n "${escape(k)}": string;`;
|
|
86
|
+
break;
|
|
87
|
+
case 'string-list':
|
|
88
|
+
case 'tag-list':
|
|
89
|
+
ts += `\n "${escape(k)}": string[]`;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (Object.keys(schema).length === 0) {
|
|
94
|
+
ts = 'export type ThemeSchema = Record<string, never>;\n';
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
ts += '\n}\n';
|
|
98
|
+
}
|
|
99
|
+
await writeFile($TYPE(), ts, { encoding: 'utf-8' });
|
|
100
|
+
}
|
|
101
|
+
export function validateSchema(schema, doc) {
|
|
102
|
+
return doValidateSchema(Object.assign({}, builtinSettings, schema), doc);
|
|
103
|
+
}
|
|
104
|
+
function doValidateSchema(schema, doc) {
|
|
105
|
+
if (typeof doc !== 'object' || !doc) {
|
|
106
|
+
throw new Error("document '" +
|
|
107
|
+
JSON.stringify(doc) +
|
|
108
|
+
"' is not a truthy object and thus cannot conform to schema " +
|
|
109
|
+
JSON.stringify(schema));
|
|
110
|
+
}
|
|
111
|
+
const cast = doc;
|
|
112
|
+
for (const [k, v] of Object.entries(schema)) {
|
|
113
|
+
if (k in cast) {
|
|
114
|
+
const docval = cast[k];
|
|
115
|
+
switch (v.type) {
|
|
116
|
+
case 'color':
|
|
117
|
+
if (typeof docval !== 'string' || !docval.startsWith('#')) {
|
|
118
|
+
throw new Error("document '" +
|
|
119
|
+
JSON.stringify(doc) +
|
|
120
|
+
"' @ key '" +
|
|
121
|
+
k +
|
|
122
|
+
"' does not have type color (instead has value '" +
|
|
123
|
+
v +
|
|
124
|
+
"') and thus does not conform to schema " +
|
|
125
|
+
JSON.stringify(schema));
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case 'selection':
|
|
129
|
+
if (v.multi) {
|
|
130
|
+
if (!Array.isArray(docval) ||
|
|
131
|
+
docval.some((item) => typeof item !== 'string' || !v.options.includes(item))) {
|
|
132
|
+
throw new Error("document '" +
|
|
133
|
+
JSON.stringify(doc) +
|
|
134
|
+
"' @ key '" +
|
|
135
|
+
k +
|
|
136
|
+
"' does not have a valid selection list at that key (instead has value '" +
|
|
137
|
+
v +
|
|
138
|
+
"') and thus does not conform to schema " +
|
|
139
|
+
JSON.stringify(schema));
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (typeof docval !== 'string' || !v.options.includes(docval)) {
|
|
144
|
+
throw new Error("document '" +
|
|
145
|
+
JSON.stringify(doc) +
|
|
146
|
+
"' @ key '" +
|
|
147
|
+
k +
|
|
148
|
+
"' does not have a valid selection at that key (instead has value '" +
|
|
149
|
+
v +
|
|
150
|
+
"') and thus does not conform to schema " +
|
|
151
|
+
JSON.stringify(schema));
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
case 'string':
|
|
155
|
+
if (typeof docval !== 'string') {
|
|
156
|
+
throw new Error("document '" +
|
|
157
|
+
JSON.stringify(doc) +
|
|
158
|
+
"' @ key '" +
|
|
159
|
+
k +
|
|
160
|
+
"' does not have a valid string at that key (instead has value '" +
|
|
161
|
+
v +
|
|
162
|
+
"') and thus does not conform to schema " +
|
|
163
|
+
JSON.stringify(schema));
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
case 'string-list':
|
|
167
|
+
case 'tag-list':
|
|
168
|
+
if (!Array.isArray(docval) || docval.some((item) => typeof item !== 'string')) {
|
|
169
|
+
throw new Error("document '" +
|
|
170
|
+
JSON.stringify(doc) +
|
|
171
|
+
"' @ key '" +
|
|
172
|
+
k +
|
|
173
|
+
"' does not have a valid string list at that key (instead has value '" +
|
|
174
|
+
v +
|
|
175
|
+
"') and thus does not conform to schema " +
|
|
176
|
+
JSON.stringify(schema));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
export async function readThemeConfig(schema) {
|
|
184
|
+
let text;
|
|
185
|
+
try {
|
|
186
|
+
text = await readFile($THEMECONFIG(), { encoding: 'utf-8' });
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
ThemeLogger.warn('Error reading theme file:', err, 'recreating');
|
|
190
|
+
await writeFile($THEMECONFIG(), '', { encoding: 'utf-8' });
|
|
191
|
+
text = '';
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const doc = parse(text) ?? {};
|
|
195
|
+
if (validateSchema(schema, doc)) {
|
|
196
|
+
return doc;
|
|
197
|
+
}
|
|
198
|
+
throw new Error('unreachable');
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
ThemeLogger.warn('Error parsing theme file:', err);
|
|
202
|
+
throw err;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
export async function writeThemeConfig(schema, config) {
|
|
206
|
+
if (validateSchema(schema, config)) {
|
|
207
|
+
await writeFile($THEMECONFIG(), stringify(config), { encoding: 'utf-8' });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function writeJsonSchema() {
|
|
211
|
+
const p = path.resolve(path.join(import.meta.dirname, '../../../settings.schema.json'));
|
|
212
|
+
writeFileSync(p, JSON.stringify(z.intersection(z.object({ $schema: z.string() }), ZThemeSettingsSchema).toJSONSchema(), null, 2), { encoding: 'utf-8' });
|
|
213
|
+
console.log('Wrote jsonschema to ' + p);
|
|
214
|
+
}
|
|
215
|
+
if (process.env.WRITE_SCHEMA) {
|
|
216
|
+
writeJsonSchema();
|
|
217
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GalleryCache, RawGalleryCache } from './gallery.ts';
|
|
2
|
+
import type { CharacterCache, RawCharacterCache } from './character.ts';
|
|
3
|
+
import type { ArtistCache } from './artist.ts';
|
|
4
|
+
export declare function hashUrl(url: string): Promise<string>;
|
|
5
|
+
export declare function hash(object: object): string;
|
|
6
|
+
export declare function relPath(startFile: string, nextFile: string): string;
|
|
7
|
+
export declare function fullPath(startFile: string, nextFile: string): string;
|
|
8
|
+
interface Cache<T> {
|
|
9
|
+
cache: T | null;
|
|
10
|
+
version: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface GlobalCache {
|
|
13
|
+
galleryCache: Cache<GalleryCache>;
|
|
14
|
+
rawGalleryCache: Cache<RawGalleryCache>;
|
|
15
|
+
characterCache: Cache<CharacterCache>;
|
|
16
|
+
rawCharacterCache: Cache<RawCharacterCache>;
|
|
17
|
+
artistCache: Cache<ArtistCache>;
|
|
18
|
+
}
|
|
19
|
+
export declare function cacheVersion(): Promise<string>;
|
|
20
|
+
export declare function getCache(): GlobalCache;
|
|
21
|
+
export declare function clearCache(): void;
|
|
22
|
+
export declare function getLogLevel(defaultLevel?: number): number;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/lib/server/util.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,mBAGxC;AAED,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,UAElC;AAED,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAG1D;AACD,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAG3D;AAsBD,UAAU,KAAK,CAAC,CAAC;IAChB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC3B,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,eAAe,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IACxC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACtC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC5C,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;CAChC;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAEpD;AAED,wBAAgB,QAAQ,IAAI,WAAW,CAoBtC;AAED,wBAAgB,UAAU,SAGzB;AAED,wBAAgB,WAAW,CAAC,YAAY,GAAE,MAAU,GAAG,MAAM,CAU5D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as crypto from 'node:crypto';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { $DATA } from "./directories.js";
|
|
5
|
+
import { $ART } from "./index.js";
|
|
6
|
+
export async function hashUrl(url) {
|
|
7
|
+
const buf = await fs.readFile(url);
|
|
8
|
+
return crypto.createHash('md5').update(buf).digest('hex').substring(24);
|
|
9
|
+
}
|
|
10
|
+
export function hash(object) {
|
|
11
|
+
return crypto.createHash('md5').update(JSON.stringify(object)).digest('hex').substring(24);
|
|
12
|
+
}
|
|
13
|
+
export function relPath(startFile, nextFile) {
|
|
14
|
+
const out = path.join(path.dirname(startFile), nextFile);
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
export function fullPath(startFile, nextFile) {
|
|
18
|
+
const out = path.join($DATA(), path.dirname(startFile), nextFile);
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
async function getStructureHash(scanPath) {
|
|
22
|
+
const list = await fs.readdir(scanPath ?? $ART(), { withFileTypes: true });
|
|
23
|
+
const structure = {};
|
|
24
|
+
for (const element of list) {
|
|
25
|
+
const next = path.join(scanPath ?? $ART(), element.name);
|
|
26
|
+
if (element.isDirectory()) {
|
|
27
|
+
structure[element.name] = await getStructureHash(next);
|
|
28
|
+
}
|
|
29
|
+
else if (element.isFile() && /\.(gallery|character|yaml|yml)$/gi.test(element.name)) {
|
|
30
|
+
structure[element.name] = await hashUrl(next);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return structure;
|
|
34
|
+
}
|
|
35
|
+
export async function cacheVersion() {
|
|
36
|
+
return hash(await getStructureHash());
|
|
37
|
+
}
|
|
38
|
+
export function getCache() {
|
|
39
|
+
if (typeof global == 'undefined') {
|
|
40
|
+
throw new Error('global is undefined');
|
|
41
|
+
}
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
let cache = global.__art_global_cache;
|
|
44
|
+
if (!cache) {
|
|
45
|
+
cache = {
|
|
46
|
+
galleryCache: { cache: null, version: null },
|
|
47
|
+
characterCache: { cache: null, version: null },
|
|
48
|
+
rawCharacterCache: { cache: null, version: null },
|
|
49
|
+
artistCache: { cache: null, version: null },
|
|
50
|
+
rawGalleryCache: { cache: null, version: null }
|
|
51
|
+
};
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
global.__art_global_cache = cache;
|
|
54
|
+
}
|
|
55
|
+
return cache;
|
|
56
|
+
}
|
|
57
|
+
export function clearCache() {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
global.__art_global_cache = null;
|
|
60
|
+
}
|
|
61
|
+
export function getLogLevel(defaultLevel = 3) {
|
|
62
|
+
try {
|
|
63
|
+
if (!process.env.LOG_LEVEL) {
|
|
64
|
+
return defaultLevel;
|
|
65
|
+
}
|
|
66
|
+
return parseInt(process.env.LOG_LEVEL);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return defaultLevel;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { FullCharacter } from '../server/models/Character.ts';
|
|
3
|
+
import type { Artist as ZArtist } from '../server/models/Artist.ts';
|
|
4
|
+
import type { Picture as ZPicture, Image as ZImage, Source as ZSource } from '../server/models/image.ts';
|
|
5
|
+
import type { FullGallery, FullArtPiece, BaseArtPiece as ZBaseArtPiece, RawGallery as ZRawGallery, BaseArtist as ZBaseArtist, BaseGallery as ZBaseGallery, ExtendedGallery as ZExtendedGallery } from '../server/models/Gallery.ts';
|
|
6
|
+
import type { ArtistCache } from '../server/artist.ts';
|
|
7
|
+
import type { CharacterCache } from '../server/character.ts';
|
|
8
|
+
export type RawGallery = z.infer<typeof ZRawGallery>;
|
|
9
|
+
export type BaseGallery = z.infer<typeof ZBaseGallery>;
|
|
10
|
+
export type ExtendedGallery = z.infer<typeof ZExtendedGallery>;
|
|
11
|
+
export type Gallery = z.infer<typeof FullGallery>;
|
|
12
|
+
export type Character = z.infer<typeof FullCharacter>;
|
|
13
|
+
export type BaseArtist = z.infer<typeof ZBaseArtist>;
|
|
14
|
+
export type Artist = z.infer<typeof ZArtist>;
|
|
15
|
+
export type ArtPiece = z.infer<typeof FullArtPiece>;
|
|
16
|
+
export type BaseArtPiece = z.infer<typeof ZBaseArtPiece>;
|
|
17
|
+
export type Picture = z.infer<typeof ZPicture>;
|
|
18
|
+
export type Image = z.infer<typeof ZImage>;
|
|
19
|
+
export type Source = z.infer<typeof ZSource>;
|
|
20
|
+
export type CharacterRef = ArtPiece['characters'][number];
|
|
21
|
+
export interface NormalizedCharacter {
|
|
22
|
+
name: string;
|
|
23
|
+
from: string | null;
|
|
24
|
+
info: Character | null;
|
|
25
|
+
}
|
|
26
|
+
export declare function normalizeCharacter(ref: CharacterRef, characters?: CharacterCache): NormalizedCharacter;
|
|
27
|
+
export declare function normalizeCharacter(ref: Array<CharacterRef>, characters?: CharacterCache): Array<NormalizedCharacter>;
|
|
28
|
+
export interface NormalizedArtist {
|
|
29
|
+
name: string;
|
|
30
|
+
anonymous: boolean;
|
|
31
|
+
info: Artist | null;
|
|
32
|
+
}
|
|
33
|
+
export declare function normalizeArtist(as: ArtPiece['artist'], artists?: ArtistCache): Array<NormalizedArtist>;
|
|
34
|
+
export declare function no4K(image: Image): Image;
|
|
35
|
+
export declare function onlyHighRes(image: Image): Image;
|
|
36
|
+
export type ResourceRef = {
|
|
37
|
+
type: 'character';
|
|
38
|
+
resource: NormalizedCharacter;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'artist';
|
|
41
|
+
resource: NormalizedArtist;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'tag';
|
|
44
|
+
resource: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'piece';
|
|
47
|
+
resource: ArtPiece;
|
|
48
|
+
} | {
|
|
49
|
+
type: undefined;
|
|
50
|
+
resource: undefined;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=art.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"art.d.ts","sourceRoot":"","sources":["../../src/lib/util/art.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EACX,OAAO,IAAI,QAAQ,EACnB,KAAK,IAAI,MAAM,EACf,MAAM,IAAI,OAAO,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,YAAY,IAAI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/util/art.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function normalizeCharacter(ref, characters) {
|
|
2
|
+
if (Array.isArray(ref)) {
|
|
3
|
+
return ref.map((ch) => normalizeCharacter(ch, characters));
|
|
4
|
+
}
|
|
5
|
+
if (typeof ref === 'string') {
|
|
6
|
+
return { name: ref, from: null, info: characters?.[ref] ?? null };
|
|
7
|
+
}
|
|
8
|
+
return { ...ref, info: null };
|
|
9
|
+
}
|
|
10
|
+
function normalizeSingleArtist(a, artists) {
|
|
11
|
+
const name = typeof a === 'string' ? a : a.name;
|
|
12
|
+
const foundArtist = artists?.[name] ?? null;
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
anonymous: typeof a === 'string' ? false : a.anonymous,
|
|
16
|
+
info: foundArtist
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function normalizeArtist(as, artists) {
|
|
20
|
+
if (!as) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(as)) {
|
|
24
|
+
return [normalizeSingleArtist(as, artists)];
|
|
25
|
+
}
|
|
26
|
+
return as.map((a) => normalizeSingleArtist(a, artists));
|
|
27
|
+
}
|
|
28
|
+
export function no4K(image) {
|
|
29
|
+
const sources = Object.entries(image.sources).reduce((prev, [k, sources]) => ({ ...prev, [k]: sources.filter((source) => source.w < 3840) }), {});
|
|
30
|
+
const [, best] = bestSource(sources);
|
|
31
|
+
return {
|
|
32
|
+
...image,
|
|
33
|
+
fallback: best,
|
|
34
|
+
sources: sources
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function onlyHighRes(image) {
|
|
38
|
+
const [key, best] = bestSource(image.sources);
|
|
39
|
+
return {
|
|
40
|
+
...image,
|
|
41
|
+
fallback: best,
|
|
42
|
+
sources: {
|
|
43
|
+
[key]: [best]
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function bestSource(sources) {
|
|
48
|
+
const [key, bestSourceType] = sources.webp ? ['webp', sources.webp] : Object.entries(sources)[0];
|
|
49
|
+
const bestImage = bestSourceType.reduce((p, v) => (v.w > p.max ? { max: v.w, source: v } : p), {
|
|
50
|
+
max: 0,
|
|
51
|
+
source: null
|
|
52
|
+
});
|
|
53
|
+
if (bestImage.source === null) {
|
|
54
|
+
throw new Error('Could not find any sources?');
|
|
55
|
+
}
|
|
56
|
+
return [key, bestImage.source];
|
|
57
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ArtPiece, type NormalizedArtist } from './art.ts';
|
|
2
|
+
import type { ArtistCache } from '../server/index.ts';
|
|
3
|
+
export declare function useArtistsContext(artists: ArtistCache): void;
|
|
4
|
+
export declare function useArtists(): ArtistCache;
|
|
5
|
+
export declare function useArtist(piece: null): null;
|
|
6
|
+
export declare function useArtist(piece: ArtPiece): Array<NormalizedArtist>;
|
|
7
|
+
export declare function useArtist(name: string): Array<NormalizedArtist>;
|
|
8
|
+
//# sourceMappingURL=artistcontext.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artistcontext.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/util/artistcontext.svelte.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAItD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,QAKrD;AAED,wBAAgB,UAAU,IAAI,WAAW,CAExC;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;AAC7C,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACpE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
import { normalizeArtist } from "./art.js";
|
|
3
|
+
const key = Symbol();
|
|
4
|
+
export function useArtistsContext(artists) {
|
|
5
|
+
setContext(key, artists);
|
|
6
|
+
$effect(() => {
|
|
7
|
+
setContext(key, artists);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export function useArtists() {
|
|
11
|
+
return getContext(key);
|
|
12
|
+
}
|
|
13
|
+
export function useArtist(piece) {
|
|
14
|
+
const allArtists = useArtists();
|
|
15
|
+
if (!piece)
|
|
16
|
+
return null;
|
|
17
|
+
return normalizeArtist(typeof piece === 'string' ? piece : piece.artist, allArtists);
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charactercontext.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/util/charactercontext.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI7D,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,cAAc,QAK7D;AAED,wBAAgB,aAAa,IAAI,cAAc,CAE9C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
const key = Symbol();
|
|
3
|
+
export function useCharacterContext(characters) {
|
|
4
|
+
setContext(key, characters);
|
|
5
|
+
$effect(() => {
|
|
6
|
+
setContext(key, characters);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export function useCharacters() {
|
|
10
|
+
return getContext(key);
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/lib/util/date.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,UAM1C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { no4K, normalizeArtist, normalizeCharacter, onlyHighRes } from './art.ts';
|
|
2
|
+
export type { ArtPiece, Artist, Character, CharacterRef, Gallery, RawGallery, Image, NormalizedArtist, Picture, Source, BaseArtist, BaseArtPiece, BaseGallery, ExtendedGallery, NormalizedCharacter, ResourceRef } from './art.ts';
|
|
3
|
+
export { executeSearch } from './search.ts';
|
|
4
|
+
export { useArtist, useArtists, useArtistsContext } from './artistcontext.svelte.ts';
|
|
5
|
+
export { useCharacterContext, useCharacters } from './charactercontext.svelte.ts';
|
|
6
|
+
export { formatDate } from './date.ts';
|
|
7
|
+
export { markdown } from './markdown.ts';
|
|
8
|
+
export { smoothScroll } from './smoothscroll.ts';
|
|
9
|
+
export { setLibraryConfig, type LibraryConfig } from './phosart_config.svelte.ts';
|
|
10
|
+
export { asRecord, multiRecordBy, deduplicateBy } from './util.ts';
|
|
11
|
+
export { asTree, pathView } from './tree.ts';
|
|
12
|
+
export type { FolderElement, GalleryElement, GalleryTree, TreeElement } from './tree.ts';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAClF,YAAY,EACX,QAAQ,EACR,MAAM,EACN,SAAS,EACT,YAAY,EACZ,OAAO,EACP,UAAU,EACV,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,MAAM,EACN,UAAU,EACV,YAAY,EACZ,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { no4K, normalizeArtist, normalizeCharacter, onlyHighRes } from "./art.js";
|
|
2
|
+
export { executeSearch } from "./search.js";
|
|
3
|
+
export { useArtist, useArtists, useArtistsContext } from "./artistcontext.svelte.js";
|
|
4
|
+
export { useCharacterContext, useCharacters } from "./charactercontext.svelte.js";
|
|
5
|
+
export { formatDate } from "./date.js";
|
|
6
|
+
export { markdown } from "./markdown.js";
|
|
7
|
+
export { smoothScroll } from "./smoothscroll.js";
|
|
8
|
+
export { setLibraryConfig } from "./phosart_config.svelte.js";
|
|
9
|
+
export { asRecord, multiRecordBy, deduplicateBy } from "./util.js";
|
|
10
|
+
export { asTree, pathView } from "./tree.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/lib/util/markdown.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS7C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import remarkParse from 'remark-parse';
|
|
3
|
+
import remarkGfm from 'remark-gfm';
|
|
4
|
+
import remarkRehype from 'remark-rehype';
|
|
5
|
+
import rehypeSanitize from 'rehype-sanitize';
|
|
6
|
+
import rehypeStringify from 'rehype-stringify';
|
|
7
|
+
export function markdown(text) {
|
|
8
|
+
return unified()
|
|
9
|
+
.use(remarkParse)
|
|
10
|
+
.use(remarkGfm)
|
|
11
|
+
.use(remarkRehype)
|
|
12
|
+
.use(rehypeSanitize)
|
|
13
|
+
.use(rehypeStringify)
|
|
14
|
+
.processSync(text)
|
|
15
|
+
.toString();
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type Gallery from '../Gallery.svelte';
|
|
2
|
+
import type FullGallery from '../FullGallery.svelte';
|
|
3
|
+
import { type ComponentProps } from 'svelte';
|
|
4
|
+
import type { ArtPiece, NormalizedArtist, NormalizedCharacter } from './art.ts';
|
|
5
|
+
export type ChipAction<T> = {
|
|
6
|
+
onclick: (data: T) => void;
|
|
7
|
+
makeHref?: never;
|
|
8
|
+
} | {
|
|
9
|
+
makeHref: (data: T) => string;
|
|
10
|
+
onclick?: never;
|
|
11
|
+
};
|
|
12
|
+
type ChipOptionBase<T> = {
|
|
13
|
+
action?: ChipAction<T> | null;
|
|
14
|
+
hidden?: never;
|
|
15
|
+
} | {
|
|
16
|
+
hidden?: true;
|
|
17
|
+
action?: never;
|
|
18
|
+
};
|
|
19
|
+
type ChipOptionTypes = {
|
|
20
|
+
tag: string;
|
|
21
|
+
artist: NormalizedArtist;
|
|
22
|
+
character: NormalizedCharacter;
|
|
23
|
+
permalink: ArtPiece;
|
|
24
|
+
};
|
|
25
|
+
export type ChipOptions<T> = ChipOptionBase<T>;
|
|
26
|
+
export type DataType<Type extends keyof ChipOptionTypes> = ChipOptionTypes[Type];
|
|
27
|
+
export type ChipOptionsByType = {
|
|
28
|
+
[K in keyof ChipOptionTypes]?: ChipOptions<DataType<K>>;
|
|
29
|
+
};
|
|
30
|
+
export interface LibraryConfig {
|
|
31
|
+
siteName: string;
|
|
32
|
+
gallery?: {
|
|
33
|
+
DefaultCardComponent?: NonNullable<ComponentProps<typeof FullGallery>['CardComponent']> | null;
|
|
34
|
+
DefaultPieceComponent?: NonNullable<ComponentProps<typeof Gallery>['PieceComponent']> | null;
|
|
35
|
+
};
|
|
36
|
+
modal?: {
|
|
37
|
+
chipOptionsByType?: ChipOptionsByType | null;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export declare function useChipConfig<Type extends keyof ChipOptionsByType>(type: Type): ChipOptions<DataType<Type>> | null;
|
|
41
|
+
export declare function setLibraryConfig(config: LibraryConfig): void;
|
|
42
|
+
export declare function useLibraryConfig(): LibraryConfig;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=phosart_config.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phosart_config.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/util/phosart_config.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAIhF,MAAM,MAAM,UAAU,CAAC,CAAC,IACrB;IACA,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACA,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAC9B,OAAO,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEL,KAAK,cAAc,CAAC,CAAC,IAClB;IAAE,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GACjD;IAAE,MAAM,CAAC,EAAE,IAAI,CAAC;IAA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