diff --git a/package-lock.json b/package-lock.json index e8ba9c27..f2547533 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,8 @@ "@sveltejs/kit": "^1.20.4", "@sveltejs/vite-plugin-svelte": "^2.4.2", "@theaninova/prettier-config": "^1.0.0", + "@types/dom-view-transitions": "^1.0.1", + "@types/flexsearch": "^0.7.3", "@types/w3c-web-serial": "^1.0.3", "@vite-pwa/sveltekit": "^0.2.5", "autoprefixer": "^10.4.14", @@ -26,6 +28,7 @@ "glob": "^10.3.1", "jsdom": "^22.1.0", "npm-run-all": "^4.1.5", + "patch-package": "^8.0.0", "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.10.1", "sass": "^1.63.6", @@ -2926,12 +2929,24 @@ "integrity": "sha512-COUnqfB2+ckwXXSFInsFdOAWQzCCx+a5hq2ruyj+Vjund94RJQd4LG2u9hnvJrTgunKAaax7ancBYlDrNYxA0g==", "dev": true }, + "node_modules/@types/dom-view-transitions": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/dom-view-transitions/-/dom-view-transitions-1.0.1.tgz", + "integrity": "sha512-A9S1ijj/4MX06I1W/6on8lhaYyq1Ir7gaOvfllW1o4RzVWW88HAeqX0pUx9VgOLnNpdiGeUW2CTkg18p5LWIrA==", + "dev": true + }, "node_modules/@types/estree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", "dev": true }, + "node_modules/@types/flexsearch": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@types/flexsearch/-/flexsearch-0.7.3.tgz", + "integrity": "sha512-HXwADeHEP4exXkCIwy2n1+i0f1ilP1ETQOH5KDOugjkTFZPntWo0Gr8stZOaebkxsdx+k0X/K6obU/+it07ocg==", + "dev": true + }, "node_modules/@types/minimist": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz", @@ -3098,6 +3113,12 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/@yarnpkg/lockfile": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", + "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==", + "dev": true + }, "node_modules/abab": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", @@ -5204,6 +5225,15 @@ "node": ">=8" } }, + "node_modules/find-yarn-workspace-root": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz", + "integrity": "sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ==", + "dev": true, + "dependencies": { + "micromatch": "^4.0.2" + } + }, "node_modules/flat-cache": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", @@ -6133,6 +6163,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "dev": true, + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -6400,6 +6445,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -6690,6 +6747,18 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true }, + "node_modules/json-stable-stringify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.2.tgz", + "integrity": "sha512-eunSSaEnxV12z+Z73y/j5N37/In40GK4GmsSy+tEHJMxknvqnA7/djeYtAgW0GsWHUfg+847WJjKaEylk2y09g==", + "dev": true, + "dependencies": { + "jsonify": "^0.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -6726,6 +6795,15 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jsonify": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.1.tgz", + "integrity": "sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/jsonpointer": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.1.tgz", @@ -6759,6 +6837,15 @@ "node": ">=0.10.0" } }, + "node_modules/klaw-sync": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz", + "integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.1.11" + } + }, "node_modules/kleur": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", @@ -7623,6 +7710,31 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/open": { + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", + "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0", + "is-wsl": "^2.1.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/ospath": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/ospath/-/ospath-1.2.2.tgz", @@ -7728,6 +7840,127 @@ "url": "https://github.com/inikulin/parse5?sponsor=1" } }, + "node_modules/patch-package": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/patch-package/-/patch-package-8.0.0.tgz", + "integrity": "sha512-da8BVIhzjtgScwDJ2TtKsfT5JFWz1hYoBl9rUQ1f38MC2HwnEIkK8VN3dKMKcP7P7bvvgzNDbfNHtx3MsQb5vA==", + "dev": true, + "dependencies": { + "@yarnpkg/lockfile": "^1.1.0", + "chalk": "^4.1.2", + "ci-info": "^3.7.0", + "cross-spawn": "^7.0.3", + "find-yarn-workspace-root": "^2.0.0", + "fs-extra": "^9.0.0", + "json-stable-stringify": "^1.0.2", + "klaw-sync": "^6.0.0", + "minimist": "^1.2.6", + "open": "^7.4.2", + "rimraf": "^2.6.3", + "semver": "^7.5.3", + "slash": "^2.0.0", + "tmp": "^0.0.33", + "yaml": "^2.2.2" + }, + "bin": { + "patch-package": "index.js" + }, + "engines": { + "node": ">=14", + "npm": ">5" + } + }, + "node_modules/patch-package/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/patch-package/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/patch-package/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/patch-package/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/patch-package/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/patch-package/node_modules/slash": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz", + "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/patch-package/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/patch-package/node_modules/tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "dependencies": { + "os-tmpdir": "~1.0.2" + }, + "engines": { + "node": ">=0.6.0" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -11001,6 +11234,15 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/yaml": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz", + "integrity": "sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==", + "dev": true, + "engines": { + "node": ">= 14" + } + }, "node_modules/yargs-parser": { "version": "20.2.9", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", diff --git a/package.json b/package.json index 41c58770..4b2e27c8 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ "devDependencies": { "@theaninova/prettier-config": "^1.0.0", "@types/w3c-web-serial": "^1.0.3", + "@types/dom-view-transitions": "^1.0.1", + "@types/flexsearch": "^0.7.3", "@vite-pwa/sveltekit": "^0.2.5", "@fontsource-variable/noto-sans-mono": "^5.0.4", "@fontsource-variable/material-symbols-rounded": "^5.0.4", @@ -39,6 +41,7 @@ "fontkit": "^2.0.2", "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.10.1", + "patch-package": "^8.0.0", "svelte": "^4.0.0", "svelte-check": "^3.4.3", "ts-node": "^10.9.1", diff --git a/patches/@types+flexsearch+0.7.3.patch b/patches/@types+flexsearch+0.7.3.patch new file mode 100644 index 00000000..af7b9596 --- /dev/null +++ b/patches/@types+flexsearch+0.7.3.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/@types/flexsearch/index.d.ts b/node_modules/@types/flexsearch/index.d.ts +index ecde8e7..4173464 100755 +--- a/node_modules/@types/flexsearch/index.d.ts ++++ b/node_modules/@types/flexsearch/index.d.ts +@@ -165,7 +165,7 @@ export type IndexSearchResult = Id[]; + * * Usage: https://github.com/nextapps-de/flexsearch#usage + */ + +-export class Index { ++export default class Index { + constructor(x?: Preset | IndexOptions); + add(id: Id, item: string): this; + append(id: Id, item: string): this; diff --git a/patches/flexsearch+0.7.31.patch b/patches/flexsearch+0.7.31.patch new file mode 100644 index 00000000..f9065764 --- /dev/null +++ b/patches/flexsearch+0.7.31.patch @@ -0,0 +1,153 @@ +diff --git a/node_modules/flexsearch/index.d.ts b/node_modules/flexsearch/index.d.ts +deleted file mode 100644 +index 9f39f41..0000000 +--- a/node_modules/flexsearch/index.d.ts ++++ /dev/null +@@ -1,147 +0,0 @@ +-declare module "flexsearch" { +- export interface Index { +- readonly id: string; +- readonly index: string; +- readonly length: number; +- +- init(options?: CreateOptions): this; +- info(): { +- id: any; +- items: any; +- cache: any; +- matcher: number; +- worker: any; +- threshold: any; +- depth: any; +- resolution: any; +- contextual: boolean; +- }; +- add(o: T): this; +- add(id: number, o: string): this; +- +- // Result without pagination -> T[] +- search( +- query: string, +- options: number | SearchOptions, +- callback: (results: T[]) => void +- ): void; +- search(query: string, options?: number | SearchOptions): Promise; +- search( +- options: SearchOptions & { query: string }, +- callback: (results: T[]) => void +- ): void; +- search(options: SearchOptions & { query: string }): Promise; +- +- // Result with pagination -> SearchResults +- search( +- query: string, +- options: number | (SearchOptions & { page?: boolean | Cursor }), +- callback: (results: SearchResults) => void +- ): void; +- search( +- query: string, +- options?: number | (SearchOptions & { page?: boolean | Cursor }) +- ): Promise>; +- search( +- options: SearchOptions & { query: string; page?: boolean | Cursor }, +- callback: (results: SearchResults) => void +- ): void; +- search( +- options: SearchOptions & { query: string; page?: boolean | Cursor } +- ): Promise>; +- +- update(id: number, o: T): this; +- remove(id: number): this; +- clear(): this; +- destroy(): this; +- addMatcher(matcher: Matcher): this; +- +- where(whereObj: { [key: string]: string } | ((o: T) => boolean)): T[]; +- encode(str: string): string; +- export( +- callback: (key: string, data: any) => any, +- self?: this, +- field?: string, +- index_doc?: Number, +- index?: Number +- ): Promise; +- import(exported: string): this; +- } +- +- interface SearchOptions { +- limit?: number; +- suggest?: boolean; +- where?: { [key: string]: string }; +- field?: string | string[]; +- bool?: "and" | "or" | "not"; +- //TODO: Sorting +- } +- +- interface SearchResults { +- page?: Cursor; +- next?: Cursor; +- result: T[]; +- } +- +- interface Document { +- id: string; +- field: any; +- } +- +- export type CreateOptions = { +- profile?: IndexProfile; +- tokenize?: DefaultTokenizer | TokenizerFn; +- split?: RegExp; +- encode?: DefaultEncoder | EncoderFn | false; +- cache?: boolean | number; +- async?: boolean; +- worker?: false | number; +- depth?: false | number; +- threshold?: false | number; +- resolution?: number; +- stemmer?: Stemmer | string | false; +- filter?: FilterFn | string | false; +- rtl?: boolean; +- doc?: Document; +- }; +- +- // limit number Sets the limit of results. +- // suggest true, false Enables suggestions in results. +- // where object Use a where-clause for non-indexed fields. +- // field string, Array Sets the document fields which should be searched. When no field is set, all fields will be searched. Custom options per field are also supported. +- // bool "and", "or" Sets the used logical operator when searching through multiple fields. +- // page true, false, cursor Enables paginated results. +- +- type IndexProfile = +- | "memory" +- | "speed" +- | "match" +- | "score" +- | "balance" +- | "fast"; +- type DefaultTokenizer = "strict" | "forward" | "reverse" | "full"; +- type TokenizerFn = (str: string) => string[]; +- type DefaultEncoder = "icase" | "simple" | "advanced" | "extra" | "balance"; +- type EncoderFn = (str: string) => string; +- type Stemmer = { [key: string]: string }; +- type Matcher = { [key: string]: string }; +- type FilterFn = (str: string) => boolean; +- type Cursor = string; +- +- export default class FlexSearch { +- static create(options?: CreateOptions): Index; +- static registerMatcher(matcher: Matcher): typeof FlexSearch; +- static registerEncoder(name: string, encoder: EncoderFn): typeof FlexSearch; +- static registerLanguage( +- lang: string, +- options: { stemmer?: Stemmer; filter?: string[] } +- ): typeof FlexSearch; +- static encode(name: string, str: string): string; +- } +-} +- +-// FlexSearch.create() +-// FlexSearch.registerMatcher({KEY: VALUE}) +-// FlexSearch.registerEncoder(name, encoder) +-// FlexSearch.registerLanguage(lang, {stemmer:{}, filter:[]}) +-// FlexSearch.encode(name, string) diff --git a/src/lib/search-engine.ts b/src/lib/search-engine.ts new file mode 100644 index 00000000..5a2f9c87 --- /dev/null +++ b/src/lib/search-engine.ts @@ -0,0 +1,4 @@ +import type {Index} from "flexsearch" +import FlexSearch from "flexsearch" + +export function createIndex() {} diff --git a/src/routes/Theme.svelte b/src/routes/Theme.svelte index a8071864..c96f1562 100644 --- a/src/routes/Theme.svelte +++ b/src/routes/Theme.svelte @@ -1,5 +1,6 @@
@@ -7,7 +8,10 @@