@poveste/shared 0.1.0

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.
Files changed (59) hide show
  1. package/LICENSE +22 -0
  2. package/dist/codegen/const.d.ts +2 -0
  3. package/dist/codegen/const.d.ts.map +1 -0
  4. package/dist/codegen/const.js +17 -0
  5. package/dist/codegen/index.d.ts +4 -0
  6. package/dist/codegen/index.d.ts.map +1 -0
  7. package/dist/codegen/index.js +3 -0
  8. package/dist/codegen/serialize-js.d.ts +2 -0
  9. package/dist/codegen/serialize-js.d.ts.map +1 -0
  10. package/dist/codegen/serialize-js.js +126 -0
  11. package/dist/codegen/util.d.ts +11 -0
  12. package/dist/codegen/util.d.ts.map +1 -0
  13. package/dist/codegen/util.js +69 -0
  14. package/dist/index.d.ts +6 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +5 -0
  17. package/dist/state.d.ts +4 -0
  18. package/dist/state.d.ts.map +1 -0
  19. package/dist/state.js +40 -0
  20. package/dist/story.d.ts +2 -0
  21. package/dist/story.d.ts.map +1 -0
  22. package/dist/story.js +10 -0
  23. package/dist/type-utils.d.ts +2 -0
  24. package/dist/type-utils.d.ts.map +1 -0
  25. package/dist/type-utils.js +1 -0
  26. package/dist/types/command.d.ts +36 -0
  27. package/dist/types/command.d.ts.map +1 -0
  28. package/dist/types/command.js +1 -0
  29. package/dist/types/config.d.ts +242 -0
  30. package/dist/types/config.d.ts.map +1 -0
  31. package/dist/types/config.js +1 -0
  32. package/dist/types/index.d.ts +6 -0
  33. package/dist/types/index.d.ts.map +1 -0
  34. package/dist/types/index.js +5 -0
  35. package/dist/types/plugin.d.ts +117 -0
  36. package/dist/types/plugin.d.ts.map +1 -0
  37. package/dist/types/plugin.js +1 -0
  38. package/dist/types/prompt.d.ts +20 -0
  39. package/dist/types/prompt.d.ts.map +1 -0
  40. package/dist/types/prompt.js +1 -0
  41. package/dist/types/story.d.ts +189 -0
  42. package/dist/types/story.d.ts.map +1 -0
  43. package/dist/types/story.js +1 -0
  44. package/package.json +46 -0
  45. package/src/codegen/const.ts +17 -0
  46. package/src/codegen/index.ts +3 -0
  47. package/src/codegen/serialize-js.ts +143 -0
  48. package/src/codegen/util.ts +77 -0
  49. package/src/index.ts +5 -0
  50. package/src/state.ts +42 -0
  51. package/src/story.ts +10 -0
  52. package/src/type-utils.ts +1 -0
  53. package/src/types/command.ts +38 -0
  54. package/src/types/config.ts +252 -0
  55. package/src/types/index.ts +5 -0
  56. package/src/types/plugin.ts +135 -0
  57. package/src/types/prompt.ts +22 -0
  58. package/src/types/story.ts +204 -0
  59. package/tsconfig.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Guillaume Chau (original "histoire" project)
4
+ Copyright (c) 2026 Sorin Gitlan (poveste fork)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export declare const voidElements: string[];
2
+ //# sourceMappingURL=const.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/codegen/const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,UAgBxB,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const voidElements = [
2
+ 'area',
3
+ 'base',
4
+ 'br',
5
+ 'col',
6
+ 'embed',
7
+ 'hr',
8
+ 'img',
9
+ 'input',
10
+ 'keygen',
11
+ 'link',
12
+ 'meta',
13
+ 'param',
14
+ 'source',
15
+ 'track',
16
+ 'wbr',
17
+ ];
@@ -0,0 +1,4 @@
1
+ export * from './const.js';
2
+ export * from './serialize-js.js';
3
+ export * from './util.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './const.js';
2
+ export * from './serialize-js.js';
3
+ export * from './util.js';
@@ -0,0 +1,2 @@
1
+ export declare function serializeJs(value: any): string;
2
+ //# sourceMappingURL=serialize-js.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-js.d.ts","sourceRoot":"","sources":["../../src/codegen/serialize-js.ts"],"names":[],"mappings":"AAQA,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CA4B9C"}
@@ -0,0 +1,126 @@
1
+ const KEY_ESCAPE_REG = /[\s\-.:|#@$£*%]/;
2
+ const MAX_SINGLE_LINE_ARRAY_LENGTH = 3;
3
+ export function serializeJs(value) {
4
+ const seen = new Set();
5
+ if (value === undefined) {
6
+ return 'undefined';
7
+ }
8
+ if (value === null) {
9
+ return 'null';
10
+ }
11
+ if (typeof value === 'string') {
12
+ return `'${value}'`;
13
+ }
14
+ if (typeof value === 'boolean') {
15
+ return value ? 'true' : 'false';
16
+ }
17
+ if (Array.isArray(value)) {
18
+ return printLines(arrayToSourceLines(value, seen));
19
+ }
20
+ if (typeof value === 'object') {
21
+ return printLines(objectToSourceLines(value, seen));
22
+ }
23
+ if (value?.__autoBuildingObject) {
24
+ return value;
25
+ }
26
+ if (typeof value === 'function' && value.name) {
27
+ return value.name;
28
+ }
29
+ return value.toString();
30
+ }
31
+ function printLines(lines) {
32
+ return lines.map(line => ' '.repeat(line.spaces) + line.line).join('\n');
33
+ }
34
+ function objectToSourceLines(object, seen, indentCount = 0) {
35
+ if (seen.has(object)) {
36
+ object = {};
37
+ }
38
+ else {
39
+ seen.add(object);
40
+ }
41
+ return createLines(indentCount, (lines) => {
42
+ lines.push('{');
43
+ lines.push(...createLines(1, (lines) => {
44
+ for (const key in object) {
45
+ const value = object[key];
46
+ let printedKey = key;
47
+ if (KEY_ESCAPE_REG.test(key)) {
48
+ printedKey = `'${printedKey}'`;
49
+ }
50
+ addLinesFromValue(lines, value, `${printedKey}: `, ',', seen);
51
+ }
52
+ }));
53
+ lines.push('}');
54
+ });
55
+ }
56
+ function arrayToSourceLines(array, seen, indentCount = 0) {
57
+ if (seen.has(array)) {
58
+ array = [];
59
+ }
60
+ else {
61
+ seen.add(array);
62
+ }
63
+ return createLines(indentCount, (lines) => {
64
+ const contentLines = createLines(1, (lines) => {
65
+ for (const value of array) {
66
+ addLinesFromValue(lines, value, '', ',', seen);
67
+ }
68
+ });
69
+ if (contentLines.length === 0) {
70
+ lines.push('[]');
71
+ }
72
+ else if (contentLines.length <= MAX_SINGLE_LINE_ARRAY_LENGTH && !contentLines.some(line => line.spaces > 1)) {
73
+ const [first] = contentLines;
74
+ first.line = contentLines.map(({ line }) => line.substring(0, line.length - 1)).join(', ');
75
+ first.line = `[${first.line}]`;
76
+ first.spaces--;
77
+ lines.push(first);
78
+ }
79
+ else {
80
+ lines.push('[', ...contentLines, ']');
81
+ }
82
+ });
83
+ }
84
+ function createLines(indentCount, handler) {
85
+ const lines = [];
86
+ handler(lines);
87
+ return lines.map((line) => {
88
+ if (line.spaces != null) {
89
+ line.spaces += indentCount;
90
+ return line;
91
+ }
92
+ return { spaces: indentCount, line };
93
+ });
94
+ }
95
+ function addLinesFromValue(lines, value, before, after, seen) {
96
+ let result;
97
+ if (Array.isArray(value)) {
98
+ lines.push(...wrap(arrayToSourceLines(value, seen), before, after));
99
+ return;
100
+ }
101
+ else if (value && typeof value === 'object') {
102
+ lines.push(...wrap(objectToSourceLines(value, seen), before, after));
103
+ return;
104
+ }
105
+ else if (typeof value === 'string') {
106
+ result = value.includes('\'') ? `\`${value}\`` : `'${value}'`;
107
+ }
108
+ else if (typeof value === 'undefined') {
109
+ result = 'undefined';
110
+ }
111
+ else if (value === null) {
112
+ result = 'null';
113
+ }
114
+ else if (typeof value === 'boolean') {
115
+ result = value ? 'true' : 'false';
116
+ }
117
+ else {
118
+ result = value;
119
+ }
120
+ lines.push(before + result + after);
121
+ }
122
+ function wrap(lines, before, after) {
123
+ lines[0].line = before + lines[0].line;
124
+ lines[lines.length - 1].line += after;
125
+ return lines;
126
+ }
@@ -0,0 +1,11 @@
1
+ export declare function indent(lines: string[], count?: number): string[];
2
+ export declare function unindent(code: string): string;
3
+ interface AutoBuildingOject {
4
+ key: string;
5
+ cache: Record<string | symbol, AutoBuildingOject>;
6
+ target: any;
7
+ proxy: any;
8
+ }
9
+ export declare function createAutoBuildingObject(format?: (key: string) => string, specialKeysHandler?: (target: any, p: string | symbol) => (() => unknown) | null, key?: string, depth?: number): AutoBuildingOject;
10
+ export {};
11
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/codegen/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,SAAI,YAEhD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,UAiBpC;AAED,UAAU,iBAAiB;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,iBAAiB,CAAC,CAAA;IACjD,MAAM,EAAE,GAAG,CAAA;IACX,KAAK,EAAE,GAAG,CAAA;CACX;AAED,wBAAgB,wBAAwB,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,SAAK,EAAE,KAAK,SAAI,GAAG,iBAAiB,CA8CnM"}
@@ -0,0 +1,69 @@
1
+ export function indent(lines, count = 1) {
2
+ return lines.map(line => `${' '.repeat(count)}${line}`);
3
+ }
4
+ export function unindent(code) {
5
+ const lines = code.split('\n');
6
+ let indentLevel = -1;
7
+ let indentText;
8
+ const linesToAnalyze = lines.filter(line => line.trim().length > 0);
9
+ for (const line of linesToAnalyze) {
10
+ const match = /^\s*/.exec(line);
11
+ if (match && (indentLevel === -1 || indentLevel > match[0].length)) {
12
+ indentLevel = match[0].length;
13
+ indentText = match[0];
14
+ }
15
+ }
16
+ const result = [];
17
+ for (const line of lines) {
18
+ result.push(line.replace(indentText, ''));
19
+ }
20
+ return result.join('\n').trim();
21
+ }
22
+ export function createAutoBuildingObject(format, specialKeysHandler, key = '', depth = 0) {
23
+ const cache = {};
24
+ if (depth > 32)
25
+ return { key, cache, target: {}, proxy: () => key };
26
+ const target = () => {
27
+ const k = `${key}()`;
28
+ return format ? format(k) : k;
29
+ };
30
+ const proxy = new Proxy(target, {
31
+ get(_, p) {
32
+ if (p === '__autoBuildingObject') {
33
+ return true;
34
+ }
35
+ if (p === '__autoBuildingObjectGetKey') {
36
+ return key;
37
+ }
38
+ if (specialKeysHandler) {
39
+ const fn = specialKeysHandler(target, p);
40
+ if (fn) {
41
+ return fn();
42
+ }
43
+ }
44
+ if (p === 'toString') {
45
+ const k = `${key}.toString()`;
46
+ return () => format ? format(k) : k;
47
+ }
48
+ if (p === Symbol.toPrimitive) {
49
+ return () => format ? format(key) : key;
50
+ }
51
+ if (!cache[p]) {
52
+ const childKey = key ? `${key}.${p.toString()}` : p.toString();
53
+ const child = createAutoBuildingObject(format, specialKeysHandler, childKey, depth + 1);
54
+ cache[p] = { key: childKey, ...child };
55
+ }
56
+ return cache[p].proxy;
57
+ },
58
+ apply(_, thisArg, args) {
59
+ const k = `${key}(${args.join(', ')})`;
60
+ return format ? format(k) : k;
61
+ },
62
+ });
63
+ return {
64
+ key,
65
+ cache,
66
+ target,
67
+ proxy,
68
+ };
69
+ }
@@ -0,0 +1,6 @@
1
+ export * from './codegen/index.js';
2
+ export * from './state.js';
3
+ export * from './story.js';
4
+ export * from './type-utils.js';
5
+ export * from './types/index.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './codegen/index.js';
2
+ export * from './state.js';
3
+ export * from './story.js';
4
+ export * from './type-utils.js';
5
+ export * from './types/index.js';
@@ -0,0 +1,4 @@
1
+ export declare function clone(data: any): any;
2
+ export declare function omit(data: any, keys: string[]): {};
3
+ export declare function applyState(target: any, state: any, override?: boolean): void;
4
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,IAAI,KAAA,OAczB;AAED,wBAAgB,IAAI,CAAC,IAAI,KAAA,EAAE,IAAI,EAAE,MAAM,EAAE,MAQxC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,UAAQ,QAenE"}
package/dist/state.js ADDED
@@ -0,0 +1,40 @@
1
+ export function clone(data) {
2
+ try {
3
+ return structuredClone(data);
4
+ }
5
+ catch (e) {
6
+ console.warn(e, `Fallback to JSON cloning`);
7
+ try {
8
+ return JSON.parse(JSON.stringify(data));
9
+ }
10
+ catch (e) {
11
+ console.error(e);
12
+ }
13
+ return data;
14
+ }
15
+ }
16
+ export function omit(data, keys) {
17
+ const copy = {};
18
+ for (const key in data) {
19
+ if (!keys.includes(key)) {
20
+ copy[key] = data[key];
21
+ }
22
+ }
23
+ return copy;
24
+ }
25
+ export function applyState(target, state, override = false) {
26
+ for (const key in state) {
27
+ // iframe sync needs to update properties without overriding them
28
+ if (!override && target[key] && !key.startsWith('_h') && typeof target[key] === 'object' && !Array.isArray(target[key])) {
29
+ Object.assign(target[key], state[key]);
30
+ }
31
+ else {
32
+ try {
33
+ target[key] = state[key];
34
+ }
35
+ catch (e) {
36
+ // noop
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,2 @@
1
+ export declare const omitInheritStoryProps: string[];
2
+ //# sourceMappingURL=story.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"story.d.ts","sourceRoot":"","sources":["../src/story.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,UASjC,CAAA"}
package/dist/story.js ADDED
@@ -0,0 +1,10 @@
1
+ export const omitInheritStoryProps = [
2
+ 'id',
3
+ 'title',
4
+ 'group',
5
+ 'layout',
6
+ 'variants',
7
+ 'file',
8
+ 'slots',
9
+ 'lastSelectedVariant',
10
+ ];
@@ -0,0 +1,2 @@
1
+ export type Awaitable<T> = Promise<T> | T;
2
+ //# sourceMappingURL=type-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-utils.d.ts","sourceRoot":"","sources":["../src/type-utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { RouteLocationNormalizedLoaded } from 'vue-router';
2
+ import type { Prompt } from './prompt.js';
3
+ import type { Story, Variant } from './story.js';
4
+ export interface CommonCommandOptions {
5
+ icon?: string;
6
+ searchText?: string;
7
+ prompts?: Prompt[];
8
+ }
9
+ export interface Command extends CommonCommandOptions {
10
+ id: string;
11
+ label: string;
12
+ }
13
+ export interface ClientCommandOptions extends CommonCommandOptions {
14
+ showIf?: (ctx: ClientCommandContext) => boolean;
15
+ getParams?: (ctx: ClientCommandContext & {
16
+ answers?: Record<string, any>;
17
+ }) => Record<string, any>;
18
+ clientAction?: (params: Record<string, any>, ctx: ClientCommandContext) => unknown;
19
+ }
20
+ /**
21
+ * A command that can be executed from the search bar.
22
+ */
23
+ export type ClientCommand = Command & ClientCommandOptions;
24
+ export interface ClientCommandContext {
25
+ route: RouteLocationNormalizedLoaded;
26
+ currentStory: Story;
27
+ currentVariant: Variant;
28
+ }
29
+ export interface PluginCommand<TParams = Record<string, any>> extends Command {
30
+ serverAction?: (params: TParams) => unknown;
31
+ clientSetupFile?: string | {
32
+ file: string;
33
+ importName: string;
34
+ };
35
+ }
36
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/types/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEhD,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,WAAW,OAAQ,SAAQ,oBAAoB;IACnD,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;IAChE,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,OAAO,CAAA;IAC/C,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAClG,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,oBAAoB,KAAK,OAAO,CAAA;CACnF;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,oBAAoB,CAAA;AAE1D,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,6BAA6B,CAAA;IACpC,YAAY,EAAE,KAAK,CAAA;IACnB,cAAc,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,aAAa,CAC5B,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAC7B,SAAQ,OAAO;IACf,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAA;IAC3C,eAAe,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;CAChE"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,242 @@
1
+ import type MarkdownIt from 'markdown-it';
2
+ import type { UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite';
3
+ import type { Plugin } from './plugin.js';
4
+ import type { ServerTreeFile, StoryProps } from './story.js';
5
+ export interface SupportMatchPattern {
6
+ id: string;
7
+ patterns: string[];
8
+ pluginIds: string[];
9
+ }
10
+ export type CustomizableColors = 'primary' | 'gray';
11
+ export type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
12
+ export type GrayColorKeys = ColorKeys | '750' | '850' | '950';
13
+ export interface ResponsivePreset {
14
+ label: string;
15
+ width: number;
16
+ height?: number;
17
+ }
18
+ export interface BackgroundPreset {
19
+ label: string;
20
+ color: string;
21
+ contrastColor?: string;
22
+ }
23
+ export interface TreeGroupConfig {
24
+ title: string;
25
+ id?: string;
26
+ include?: (file: ServerTreeFile) => boolean;
27
+ }
28
+ /**
29
+ * @deprecated Use `PovesteConfig` instead. Kept for drop-in compat with histoire.
30
+ */
31
+ export type HistoireConfig = PovesteConfig;
32
+ export interface PovesteConfig {
33
+ plugins: Plugin[];
34
+ /**
35
+ * Output directory.
36
+ */
37
+ outDir: string;
38
+ /**
39
+ * Glob patterns for story files to include.
40
+ */
41
+ storyMatch: string[];
42
+ /**
43
+ * Glob patterns to ignore files while searching for story files.
44
+ */
45
+ storyIgnored: string[];
46
+ /**
47
+ * Patterns to match stories to support plugins automatically.
48
+ */
49
+ supportMatch: SupportMatchPattern[];
50
+ /**
51
+ * How to generate the story tree.
52
+ */
53
+ tree: {
54
+ /**
55
+ * Use `'title'` to create the path from the title of the story, using `/` as the separator.
56
+ *
57
+ * Use `'path'` use the real folder structure on your computer.
58
+ */
59
+ file?: 'title' | 'path' | ((file: ServerTreeFile) => string[]);
60
+ order?: 'asc' | ((a: string, b: string) => number);
61
+ groups?: TreeGroupConfig[];
62
+ };
63
+ /**
64
+ * Customize the look of the histoire book.
65
+ */
66
+ theme: {
67
+ /**
68
+ * Main page title. For example: 'Acme Inc.'
69
+ */
70
+ title?: string;
71
+ /**
72
+ * Custom logo files. Should be import paths (processed by Vite).
73
+ *
74
+ * Example: `'/src/assets/my-logo.svg'`
75
+ */
76
+ logo?: {
77
+ /**
78
+ * Square logo without text.
79
+ */
80
+ square?: string;
81
+ /**
82
+ * Full logo for light theme.
83
+ */
84
+ light?: string;
85
+ /**
86
+ * Full logo for dark theme.
87
+ */
88
+ dark?: string;
89
+ };
90
+ /**
91
+ * Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
92
+ *
93
+ * Example: `'/favicon.ico'`
94
+ */
95
+ favicon?: string;
96
+ /**
97
+ * Customize the colors. Each color should be an object with shades as keys.
98
+ *
99
+ * Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
100
+ *
101
+ * You can import `defaultColors` from `'poveste'` to use predefined colors or you can create your own colors from scratch.
102
+ */
103
+ colors?: {
104
+ [key in CustomizableColors]?: key extends 'gray' ? {
105
+ [key in GrayColorKeys]?: string;
106
+ } : {
107
+ [key in ColorKeys]?: string;
108
+ };
109
+ };
110
+ /**
111
+ * Add a link to the main logo
112
+ */
113
+ logoHref?: string;
114
+ /**
115
+ * Default color scheme for the app.
116
+ */
117
+ defaultColorScheme?: 'light' | 'dark' | 'auto';
118
+ /**
119
+ * Hides the dark mode button in the toolbar.
120
+ */
121
+ hideColorSchemeSwitch?: boolean;
122
+ /**
123
+ * Enable persistence of the color scheme in the browser.
124
+ */
125
+ storeColorScheme?: boolean;
126
+ /**
127
+ * Class added to the story preview when dark mode is enabled.
128
+ */
129
+ darkClass?: string;
130
+ };
131
+ /**
132
+ * Setup file exporting a default function executed when setting up each story preview.
133
+ *
134
+ * Import custom CSS files from this file.
135
+ *
136
+ * Example: `'/src/histoire-setup.ts'`
137
+ */
138
+ setupFile?: string | {
139
+ /**
140
+ * Only loaded in the browser client.
141
+ */
142
+ browser: string;
143
+ } | {
144
+ /**
145
+ * Only loaded while collecting stories in the node server.
146
+ */
147
+ server: string;
148
+ } | {
149
+ /**
150
+ * Only loaded in the browser client.
151
+ */
152
+ browser: string;
153
+ /**
154
+ * Only loaded while collecting stories in the node server.
155
+ */
156
+ server: string;
157
+ };
158
+ /**
159
+ * Setup code created by plugins
160
+ */
161
+ setupCode?: string[];
162
+ /**
163
+ * Predefined responsive sizes for story playgrounds.
164
+ */
165
+ responsivePresets?: ResponsivePreset[];
166
+ /**
167
+ * Background color of the story preview.
168
+ */
169
+ backgroundPresets?: BackgroundPreset[];
170
+ /**
171
+ * Automatically apply the current background preset's contrast color to the story preview text.
172
+ */
173
+ autoApplyContrastColor?: boolean;
174
+ /**
175
+ * Class added to the html root of the story preview when dark mode is enabled.
176
+ * @deprecated use `theme.darkClass` instead
177
+ */
178
+ sandboxDarkClass?: string;
179
+ /**
180
+ * Default props for stories.
181
+ */
182
+ defaultStoryProps?: Omit<StoryProps, 'id' | 'setupApp' | 'title' | 'source'>;
183
+ /**
184
+ * Customize the markdown-it renderer
185
+ */
186
+ markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>;
187
+ /**
188
+ * Change the router mode.
189
+ * - history: use HTML history with cleaner URLs
190
+ * - hash: use hashtag hack in the URL to support more hosting services
191
+ */
192
+ routerMode?: 'history' | 'hash';
193
+ /**
194
+ * Vite config override
195
+ */
196
+ vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>);
197
+ /**
198
+ * Remove those plugins from the Vite configuration
199
+ */
200
+ viteIgnorePlugins?: string[];
201
+ /**
202
+ * Transpile dependencies when collecting stories on Node.js
203
+ */
204
+ viteNodeInlineDeps?: (string | RegExp)[];
205
+ /**
206
+ * Determine the transform method of modules
207
+ */
208
+ viteNodeTransformMode?: {
209
+ /**
210
+ * Use SSR transform pipeline for the specified files.
211
+ * Vite plugins will receive `ssr: true` flag when processing those files.
212
+ *
213
+ * @default [/\.([cm]?[jt]sx?|json)$/]
214
+ */
215
+ ssr?: RegExp[];
216
+ /**
217
+ * First do a normal transform pipeline (targeting browser),
218
+ * then then do a SSR rewrite to run the code in Node.
219
+ * Vite plugins will receive `ssr: false` flag when processing those files.
220
+ *
221
+ * @default other than `ssr`
222
+ */
223
+ web?: RegExp[];
224
+ };
225
+ /**
226
+ * Maximum number of threads used to collect stories.
227
+ * By default based on available number of cores.
228
+ */
229
+ collectMaxThreads?: number;
230
+ /**
231
+ * Build options
232
+ */
233
+ build?: {
234
+ /**
235
+ * By default all dependencies in `node_modules` are bundled into a single 'vendors' file.
236
+ * You can use this option to exclude some dependencies from this file.
237
+ */
238
+ excludeFromVendorsChunk?: (string | RegExp)[];
239
+ };
240
+ }
241
+ export type ConfigMode = 'build' | 'dev';
242
+ //# sourceMappingURL=config.d.ts.map