@nil-/doc 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 (44) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/components/Layout.svelte +63 -0
  3. package/components/Layout.svelte.d.ts +25 -0
  4. package/components/block/Block.svelte +18 -0
  5. package/components/block/Block.svelte.d.ts +16 -0
  6. package/components/block/Controls.svelte +5 -0
  7. package/components/block/Controls.svelte.d.ts +17 -0
  8. package/components/block/Params.svelte +6 -0
  9. package/components/block/Params.svelte.d.ts +17 -0
  10. package/components/block/Template.svelte +139 -0
  11. package/components/block/Template.svelte.d.ts +21 -0
  12. package/components/block/context.d.ts +11 -0
  13. package/components/block/context.js +12 -0
  14. package/components/block/controls/Number.svelte +10 -0
  15. package/components/block/controls/Number.svelte.d.ts +18 -0
  16. package/components/block/controls/Range.svelte +32 -0
  17. package/components/block/controls/Range.svelte.d.ts +18 -0
  18. package/components/block/controls/Select.svelte +14 -0
  19. package/components/block/controls/Select.svelte.d.ts +18 -0
  20. package/components/block/controls/Switch.svelte +10 -0
  21. package/components/block/controls/Switch.svelte.d.ts +18 -0
  22. package/components/block/controls/Text.svelte +10 -0
  23. package/components/block/controls/Text.svelte.d.ts +18 -0
  24. package/components/block/controls/types.d.ts +30 -0
  25. package/components/etc/Container.svelte +102 -0
  26. package/components/etc/Container.svelte.d.ts +23 -0
  27. package/components/etc/Font.svelte +5 -0
  28. package/components/etc/Font.svelte.d.ts +19 -0
  29. package/components/etc/action.d.ts +13 -0
  30. package/components/etc/action.js +47 -0
  31. package/components/load.d.ts +1 -0
  32. package/components/load.js +8 -0
  33. package/components/navigation/Nav.svelte +79 -0
  34. package/components/navigation/Nav.svelte.d.ts +24 -0
  35. package/components/navigation/Node.svelte +104 -0
  36. package/components/navigation/Node.svelte.d.ts +26 -0
  37. package/components/navigation/Tree.svelte +23 -0
  38. package/components/navigation/Tree.svelte.d.ts +24 -0
  39. package/components/navigation/types.d.ts +12 -0
  40. package/components/navigation/utils.d.ts +5 -0
  41. package/components/navigation/utils.js +35 -0
  42. package/index.d.ts +8 -0
  43. package/index.js +7 -0
  44. package/package.json +26 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @nil-/doc
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Alpha release
@@ -0,0 +1,63 @@
1
+ <style>
2
+ .wrapper {
3
+ width: 100%;
4
+ height: 100%;
5
+ font-family: "Fira Code", "Courier New", Courier, monospace;
6
+ }
7
+
8
+ .wrapper {
9
+ overflow: hidden;
10
+ background-color: rgb(34, 36, 37);
11
+ color: rgb(201, 205, 207);
12
+ }
13
+
14
+ .content {
15
+ height: 100%;
16
+ padding: 5px;
17
+ display: flex;
18
+ flex-direction: column;
19
+ }
20
+
21
+ .scrollable {
22
+ overflow: scroll;
23
+ scrollbar-width: none; /* Firefox */
24
+ -ms-overflow-style: none; /* IE and Edge */
25
+ }
26
+
27
+ .scrollable::-webkit-scrollbar {
28
+ display: none;
29
+ }
30
+ </style>
31
+
32
+ <script>import Container from "./etc/Container.svelte";
33
+ import Nav from "./navigation/Nav.svelte";
34
+ import Font from "./etc/Font.svelte";
35
+ export let data;
36
+ export let current = null;
37
+ export let sorter = null;
38
+ export let renamer = null;
39
+ </script>
40
+ <Font />
41
+ <div class="wrapper">
42
+ <Container offset={250} padding={250} vertical>
43
+ <svelte:fragment slot="a">
44
+ <Nav
45
+ info={data}
46
+ selected={current ?? ""}
47
+ sorter={sorter ?? ((l, r) => (l < r ? -1 : l > r ? +1 : 0))}
48
+ renamer={renamer ?? ((s) => s)}
49
+ on:navigate
50
+ >
51
+ <slot name="title">@nil-/doc</slot>
52
+ </Nav>
53
+ </svelte:fragment>
54
+ <svelte:fragment slot="b">
55
+ <div class="content scrollable">
56
+ {#key current}
57
+ <slot name="content" />
58
+ {/key}
59
+ </div>
60
+ </svelte:fragment>
61
+ </Container>
62
+ </div>
63
+
@@ -0,0 +1,25 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { Sorter, Renamer } from "./navigation/types";
3
+ declare const __propDef: {
4
+ props: {
5
+ data: string[];
6
+ current?: string | null | undefined;
7
+ sorter?: Sorter | null | undefined;
8
+ renamer?: Renamer | null | undefined;
9
+ };
10
+ events: {
11
+ navigate: CustomEvent<any>;
12
+ } & {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {
16
+ title: {};
17
+ content: {};
18
+ };
19
+ };
20
+ export declare type LayoutProps = typeof __propDef.props;
21
+ export declare type LayoutEvents = typeof __propDef.events;
22
+ export declare type LayoutSlots = typeof __propDef.slots;
23
+ export default class Layout extends SvelteComponentTyped<LayoutProps, LayoutEvents, LayoutSlots> {
24
+ }
25
+ export {};
@@ -0,0 +1,18 @@
1
+ <script>import { initCurrent, initParams, initControls } from "./context";
2
+ initParams();
3
+ initCurrent();
4
+ initControls();
5
+ </script>
6
+ <style>
7
+ div {
8
+ width: 100%;
9
+ display: flex;
10
+ flex-direction: column;
11
+ }
12
+ </style>
13
+
14
+
15
+ <div>
16
+ <slot />
17
+ </div>
18
+
@@ -0,0 +1,16 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {};
4
+ events: {
5
+ [evt: string]: CustomEvent<any>;
6
+ };
7
+ slots: {
8
+ default: {};
9
+ };
10
+ };
11
+ export declare type BlockProps = typeof __propDef.props;
12
+ export declare type BlockEvents = typeof __propDef.events;
13
+ export declare type BlockSlots = typeof __propDef.slots;
14
+ export default class Block extends SvelteComponentTyped<BlockProps, BlockEvents, BlockSlots> {
15
+ }
16
+ export {};
@@ -0,0 +1,5 @@
1
+
2
+ <script>import { getControls } from "./context";
3
+ export let props = [];
4
+ getControls().set(props);
5
+ </script>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { Control } from "./controls/types";
3
+ declare const __propDef: {
4
+ props: {
5
+ props?: Control[] | undefined;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export declare type ControlsProps = typeof __propDef.props;
13
+ export declare type ControlsEvents = typeof __propDef.events;
14
+ export declare type ControlsSlots = typeof __propDef.slots;
15
+ export default class Controls extends SvelteComponentTyped<ControlsProps, ControlsEvents, ControlsSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,6 @@
1
+
2
+ <script>import { getParams } from "./context";
3
+ export let tag;
4
+ export let props = {};
5
+ getParams().update((v) => [...v, { id: v.length, tag, values: props }]);
6
+ </script>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ tag: string;
5
+ props?: Record<string, unknown> | undefined;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export declare type ParamsProps = typeof __propDef.props;
13
+ export declare type ParamsEvents = typeof __propDef.events;
14
+ export declare type ParamsSlots = typeof __propDef.slots;
15
+ export default class Params extends SvelteComponentTyped<ParamsProps, ParamsEvents, ParamsSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,139 @@
1
+ <style>
2
+ .template {
3
+ display: flex;
4
+ flex-direction: column;
5
+ font-family: "Fira Code", "Courier New", Courier, monospace;
6
+ gap: 20px;
7
+ padding-bottom: 10px;
8
+ padding-top: 10px;
9
+ }
10
+
11
+ .instance {
12
+ display: flex;
13
+ flex-direction: column;
14
+ }
15
+
16
+ .content {
17
+ padding: 10px;
18
+ min-height: 100px;
19
+ border-radius: 5px 5px 5px 5px;
20
+ background-color: rgb(100, 96, 96);
21
+ }
22
+
23
+ .scrollable {
24
+ width: 100%;
25
+ overflow: scroll;
26
+ scrollbar-width: none; /* Firefox */
27
+ -ms-overflow-style: none; /* IE and Edge */
28
+ }
29
+
30
+ .scrollable::-webkit-scrollbar {
31
+ display: none;
32
+ }
33
+
34
+ .misc {
35
+ margin-top: 5px;
36
+ padding: 5px;
37
+ background-color: rgb(100, 96, 96);
38
+ border-bottom-left-radius: 5px;
39
+ border-bottom-right-radius: 5px;
40
+ user-select: none;
41
+ }
42
+
43
+ .misc > .controls {
44
+ width: 100%;
45
+ display: grid;
46
+ grid-template-columns: 1fr 200px 75px;
47
+ grid-auto-rows: 1fr;
48
+ }
49
+
50
+ .misc > .controls > .header {
51
+ text-align: center;
52
+ }
53
+ </style>
54
+ <svelte:window on:click={() => ($current = null)} />
55
+
56
+ <script>import { beforeUpdate } from "svelte";
57
+ import { getParams, getCurrent, getControls } from "./context";
58
+ import Text from "./controls/Text.svelte";
59
+ import Number from "./controls/Number.svelte";
60
+ import Range from "./controls/Range.svelte";
61
+ import Switch from "./controls/Switch.svelte";
62
+ import Select from "./controls/Select.svelte";
63
+ import Font from "../etc/Font.svelte";
64
+ import { slide } from "svelte/transition";
65
+ const params = getParams();
66
+ const current = getCurrent();
67
+ const controls = getControls();
68
+ export let defaults;
69
+ $: keys = Object.keys(defaults);
70
+ function resolve(d, p) {
71
+ if (d === undefined) {
72
+ return {};
73
+ }
74
+ const temporary = { ...d };
75
+ for (const key of keys) {
76
+ if (key in p && p[key] !== undefined) {
77
+ temporary[key] = p[key];
78
+ }
79
+ }
80
+ return temporary;
81
+ }
82
+ let hovered = null;
83
+ /**
84
+ * This flag is to rerender the whole slot component.
85
+ * If the control is disabled, we use the default value provided from the defaults field.
86
+ * If the value of a prop is undefined, we will have to forward this value to the slot.
87
+ * Problem is, if the slot component has a default value set, it is only
88
+ * evaluated during component creation, not in subsequent updates.
89
+ *
90
+ * The solution is to rerender the whole slot whenever there is an control update.
91
+ *
92
+ * Similar case to: https://github.com/sveltejs/svelte/issues/4442
93
+ */
94
+ let rerender = false;
95
+ beforeUpdate(() => (rerender = !rerender));
96
+ </script>
97
+ <Font />
98
+ <div class="template">
99
+ {#each $params as { id, tag, values } (id)}
100
+ <div
101
+ class="instance"
102
+ on:click|stopPropagation={() => ($current = id)}
103
+ on:mouseenter={() => (hovered = id)}
104
+ on:mouseleave={() => (hovered = null)}
105
+ on:keypress={null}
106
+ >
107
+ {#key rerender}
108
+ <div class="content scrollable">
109
+ <slot {tag} props={resolve(defaults, values)} />
110
+ </div>
111
+ {/key}
112
+ {#if $controls.length > 0 && ($current === id || hovered === id)}
113
+ <div class="misc scrollable" transition:slide>
114
+ <div class="controls">
115
+ <div class="header">Name</div>
116
+ <div class="header">Value</div>
117
+ <div class="header">In Use</div>
118
+ {#each $controls as info}
119
+ {@const type = info.type}
120
+ {@const name = info.name}
121
+ {#if type === "text"}
122
+ <Text {info} bind:value={values[name]} />
123
+ {:else if type === "number"}
124
+ <Number {info} bind:value={values[name]} />
125
+ {:else if type === "range"}
126
+ <Range {info} bind:value={values[name]} />
127
+ {:else if type === "select"}
128
+ <Select {info} bind:value={values[name]} />
129
+ {:else if type === "switch"}
130
+ <Switch {info} bind:value={values[name]} />
131
+ {/if}
132
+ {/each}
133
+ </div>
134
+ </div>
135
+ {/if}
136
+ </div>
137
+ {/each}
138
+ </div>
139
+
@@ -0,0 +1,21 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare class __sveltets_Render<Args> {
3
+ props(): {
4
+ defaults: Args;
5
+ };
6
+ events(): {} & {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots(): {
10
+ default: {
11
+ tag: string;
12
+ props: Args;
13
+ };
14
+ };
15
+ }
16
+ export declare type TemplateProps<Args> = ReturnType<__sveltets_Render<Args>['props']>;
17
+ export declare type TemplateEvents<Args> = ReturnType<__sveltets_Render<Args>['events']>;
18
+ export declare type TemplateSlots<Args> = ReturnType<__sveltets_Render<Args>['slots']>;
19
+ export default class Template<Args> extends SvelteComponentTyped<TemplateProps<Args>, TemplateEvents<Args>, TemplateSlots<Args>> {
20
+ }
21
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { Control } from "./controls/types";
2
+ import type { Writable } from "svelte/store";
3
+ export declare type ParamValues = Record<string, any>;
4
+ export declare type Params = {
5
+ id: number;
6
+ tag: string;
7
+ values: ParamValues;
8
+ };
9
+ export declare const initCurrent: () => Writable<number | null>, getCurrent: () => Writable<number | null>;
10
+ export declare const initParams: () => Writable<Params[]>, getParams: () => Writable<Params[]>;
11
+ export declare const initControls: () => Writable<Control[]>, getControls: () => Writable<Control[]>;
@@ -0,0 +1,12 @@
1
+ import { getContext, setContext } from "svelte";
2
+ import { writable } from "svelte/store";
3
+ function create(defaulter) {
4
+ const symbol = Symbol();
5
+ return {
6
+ init: () => setContext(symbol, writable(defaulter())),
7
+ get: () => getContext(symbol)
8
+ };
9
+ }
10
+ export const { init: initCurrent, get: getCurrent } = create(() => null);
11
+ export const { init: initParams, get: getParams } = create(() => []);
12
+ export const { init: initControls, get: getControls } = create(() => []);
@@ -0,0 +1,10 @@
1
+
2
+ <script>export let value;
3
+ export let info;
4
+ let ivalue = value ?? 0;
5
+ let enabled = value !== undefined;
6
+ $: value = enabled ? ivalue : undefined;
7
+ </script>
8
+ <span>{info.name}</span>
9
+ <input type="number" bind:value={ivalue} disabled={!enabled} />
10
+ <input type="checkbox" bind:checked={enabled} />
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { ControlNumber } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ value: number | undefined;
6
+ info: ControlNumber;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type NumberProps = typeof __propDef.props;
14
+ export declare type NumberEvents = typeof __propDef.events;
15
+ export declare type NumberSlots = typeof __propDef.slots;
16
+ export default class Number extends SvelteComponentTyped<NumberProps, NumberEvents, NumberSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,32 @@
1
+ <style>
2
+ div {
3
+ width: 100%;
4
+ display: grid;
5
+ grid-template-columns: 40px 1fr;
6
+ }
7
+
8
+ div > span {
9
+ text-align: center;
10
+ }
11
+ </style>
12
+
13
+ <script>export let value;
14
+ export let info;
15
+ let ivalue = value ?? info.min;
16
+ let enabled = value !== undefined;
17
+ $: value = enabled ? ivalue : undefined;
18
+ </script>
19
+ <span>{info.name}</span>
20
+ <div>
21
+ <span>{ivalue}</span>
22
+ <input
23
+ type="range"
24
+ bind:value={ivalue}
25
+ min={info.min}
26
+ max={info.max}
27
+ step={info.step}
28
+ disabled={!enabled}
29
+ />
30
+ </div>
31
+ <input type="checkbox" bind:checked={enabled} />
32
+
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { ControlRange } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ value: number | undefined;
6
+ info: ControlRange;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type RangeProps = typeof __propDef.props;
14
+ export declare type RangeEvents = typeof __propDef.events;
15
+ export declare type RangeSlots = typeof __propDef.slots;
16
+ export default class Range extends SvelteComponentTyped<RangeProps, RangeEvents, RangeSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,14 @@
1
+
2
+ <script>export let value;
3
+ export let info;
4
+ let ivalue = value ?? (info.values.length > 0 ? info.values[0] : undefined);
5
+ let enabled = value !== undefined;
6
+ $: value = enabled ? ivalue : undefined;
7
+ </script>
8
+ <span>{info.name}</span>
9
+ <select bind:value={ivalue} disabled={!enabled}>
10
+ {#each info.values as value}
11
+ <option {value}>{value}</option>
12
+ {/each}
13
+ </select>
14
+ <input type="checkbox" bind:checked={enabled} />
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { ControlSelect } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ value: string | undefined;
6
+ info: ControlSelect;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type SelectProps = typeof __propDef.props;
14
+ export declare type SelectEvents = typeof __propDef.events;
15
+ export declare type SelectSlots = typeof __propDef.slots;
16
+ export default class Select extends SvelteComponentTyped<SelectProps, SelectEvents, SelectSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,10 @@
1
+
2
+ <script>export let value;
3
+ export let info;
4
+ let ivalue = value ?? false;
5
+ let enabled = value !== undefined;
6
+ $: value = enabled ? ivalue : undefined;
7
+ </script>
8
+ <span>{info.name}</span>
9
+ <input type="checkbox" bind:checked={ivalue} disabled={!enabled} />
10
+ <input type="checkbox" bind:checked={enabled} />
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { ControlSwitch } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ value: boolean | undefined;
6
+ info: ControlSwitch;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type SwitchProps = typeof __propDef.props;
14
+ export declare type SwitchEvents = typeof __propDef.events;
15
+ export declare type SwitchSlots = typeof __propDef.slots;
16
+ export default class Switch extends SvelteComponentTyped<SwitchProps, SwitchEvents, SwitchSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,10 @@
1
+
2
+ <script>export let value;
3
+ export let info;
4
+ let ivalue = value ?? "";
5
+ let enabled = value !== undefined;
6
+ $: value = enabled ? ivalue : undefined;
7
+ </script>
8
+ <span>{info.name}</span>
9
+ <input type="text" bind:value={ivalue} disabled={!enabled} />
10
+ <input type="checkbox" bind:checked={enabled} />
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { ControlText } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ value: string | undefined;
6
+ info: ControlText;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type TextProps = typeof __propDef.props;
14
+ export declare type TextEvents = typeof __propDef.events;
15
+ export declare type TextSlots = typeof __propDef.slots;
16
+ export default class Text extends SvelteComponentTyped<TextProps, TextEvents, TextSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,30 @@
1
+ export type ControlText = {
2
+ name: string;
3
+ type: "text";
4
+ };
5
+
6
+ export type ControlNumber = {
7
+ name: string;
8
+ type: "number";
9
+ };
10
+
11
+ export type ControlRange = {
12
+ name: string;
13
+ type: "range";
14
+ min: number;
15
+ max: number;
16
+ step: number;
17
+ };
18
+
19
+ export type ControlSelect = {
20
+ name: string;
21
+ type: "select";
22
+ values: string[];
23
+ };
24
+
25
+ export type ControlSwitch = {
26
+ name: string;
27
+ type: "switch";
28
+ };
29
+
30
+ export type Control = ControlText | ControlNumber | ControlRange | ControlSelect | ControlSwitch;
@@ -0,0 +1,102 @@
1
+ <style>
2
+ .root {
3
+ display: flex;
4
+ position: relative;
5
+ width: 100%;
6
+ height: 100%;
7
+ }
8
+
9
+ .primary {
10
+ flex-shrink: 0;
11
+ }
12
+
13
+ .secondary {
14
+ flex-grow: 1;
15
+ flex-basis: auto;
16
+ }
17
+
18
+ .divider {
19
+ z-index: 1;
20
+ user-select: none;
21
+ }
22
+
23
+ .root > div {
24
+ outline: white solid 1px;
25
+ }
26
+ </style>
27
+
28
+ <script>import { createDraggable } from "./action";
29
+ // orientation of the layout
30
+ export let vertical = false;
31
+ // initial value where the divider is located
32
+ export let offset = 0;
33
+ // which position is offset located
34
+ // if true, the reference content is from slot="b"
35
+ // if false, the reference content is from slot="a"
36
+ export let reversed = false;
37
+ // size of the "draggable" divider
38
+ export let thickness = 10;
39
+ // min distance of divider to the edges
40
+ export let padding = 0;
41
+ let width;
42
+ let height;
43
+ const { position, draggable } = createDraggable(offset);
44
+ function update(w, h, limit, value) {
45
+ if (w == null || h == null) {
46
+ return;
47
+ }
48
+ const span = vertical ? w : h;
49
+ offset = Math.max(Math.min(value, span - limit), limit);
50
+ }
51
+ $: update(width, height, padding, $position);
52
+ $: offsetpx = `${offset}px`;
53
+ $: thicknesspx = `${thickness}px`;
54
+ </script>
55
+ <div
56
+ class="root"
57
+ bind:clientHeight={height}
58
+ bind:clientWidth={width}
59
+ style:flex-direction={vertical ? "row" : "column"}
60
+ >
61
+ {#if width != null && height != null}
62
+ <div
63
+ class:primary={!reversed}
64
+ class:secondary={reversed}
65
+ style:min-height={!vertical ? `${padding}px` : null}
66
+ style:max-height={!vertical ? `${height - padding}px` : null}
67
+ style:min-width={vertical ? `${padding}px` : null}
68
+ style:max-width={vertical ? `${width - padding}px` : null}
69
+ style:width={!reversed && vertical ? offsetpx : null}
70
+ style:height={!reversed && !vertical ? offsetpx : null}
71
+ >
72
+ <slot name="a" />
73
+ </div>
74
+ <div
75
+ class="divider"
76
+ style:width={vertical ? "0px" : null}
77
+ style:height={!vertical ? "0px" : null}
78
+ >
79
+ <div
80
+ class="overlay"
81
+ style:width={vertical ? thicknesspx : "100%"}
82
+ style:height={!vertical ? thicknesspx : "100%"}
83
+ style:cursor={vertical ? "col-resize" : "row-resize"}
84
+ style:transform={vertical ? "translateX(-50%)" : "translateY(-50%)"}
85
+ use:draggable={{ reset: () => offset, reversed, vertical }}
86
+ />
87
+ </div>
88
+ <div
89
+ class:primary={reversed}
90
+ class:secondary={!reversed}
91
+ style:min-height={!vertical ? `${padding}px` : null}
92
+ style:max-height={!vertical ? `${height - padding}px` : null}
93
+ style:min-width={vertical ? `${padding}px` : null}
94
+ style:max-width={vertical ? `${width - padding}px` : null}
95
+ style:width={reversed && vertical ? offsetpx : null}
96
+ style:height={reversed && !vertical ? offsetpx : null}
97
+ >
98
+ <slot name="b" />
99
+ </div>
100
+ {/if}
101
+ </div>
102
+
@@ -0,0 +1,23 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ vertical?: boolean | undefined;
5
+ offset?: number | undefined;
6
+ reversed?: boolean | undefined;
7
+ thickness?: number | undefined;
8
+ padding?: number | undefined;
9
+ };
10
+ events: {
11
+ [evt: string]: CustomEvent<any>;
12
+ };
13
+ slots: {
14
+ a: {};
15
+ b: {};
16
+ };
17
+ };
18
+ export declare type ContainerProps = typeof __propDef.props;
19
+ export declare type ContainerEvents = typeof __propDef.events;
20
+ export declare type ContainerSlots = typeof __propDef.slots;
21
+ export default class Container extends SvelteComponentTyped<ContainerProps, ContainerEvents, ContainerSlots> {
22
+ }
23
+ export {};
@@ -0,0 +1,5 @@
1
+ <svelte:head>
2
+ <link href="https://fonts.googleapis.com/css?family=Fira Code" rel="stylesheet" />
3
+ </svelte:head>
4
+
5
+
@@ -0,0 +1,19 @@
1
+ /** @typedef {typeof __propDef.props} FontProps */
2
+ /** @typedef {typeof __propDef.events} FontEvents */
3
+ /** @typedef {typeof __propDef.slots} FontSlots */
4
+ export default class Font extends SvelteComponentTyped<{}, {
5
+ [evt: string]: CustomEvent<any>;
6
+ }, {}> {
7
+ }
8
+ export type FontProps = typeof __propDef.props;
9
+ export type FontEvents = typeof __propDef.events;
10
+ export type FontSlots = typeof __propDef.slots;
11
+ import { SvelteComponentTyped } from "svelte";
12
+ declare const __propDef: {
13
+ props: {};
14
+ events: {
15
+ [evt: string]: CustomEvent<any>;
16
+ };
17
+ slots: {};
18
+ };
19
+ export {};
@@ -0,0 +1,13 @@
1
+ import { type Writable } from "svelte/store";
2
+ import type { ActionReturn } from "svelte/action";
3
+ declare type Parameter = {
4
+ reset: () => number;
5
+ vertical: boolean;
6
+ reversed: boolean;
7
+ };
8
+ declare type Return = {
9
+ position: Writable<number>;
10
+ draggable: (div: HTMLDivElement, parameter: Parameter) => ActionReturn<Parameter>;
11
+ };
12
+ export declare const createDraggable: (offset: number) => Return;
13
+ export {};
@@ -0,0 +1,47 @@
1
+ import { writable } from "svelte/store";
2
+ export const createDraggable = (offset) => {
3
+ const position = writable(offset);
4
+ function draggable(div, parameter) {
5
+ let param = parameter ?? { reset: () => 0, vertical: true, reversed: false };
6
+ let moving = false;
7
+ position.set(param.reset());
8
+ let current_page = 0;
9
+ function engage(e) {
10
+ moving = true;
11
+ position.set(param.reset());
12
+ current_page = param.vertical ? e.pageX : e.pageY;
13
+ }
14
+ function disengage() {
15
+ moving = false;
16
+ }
17
+ function move(e) {
18
+ if (moving) {
19
+ const page = param.vertical ? e.pageX : e.pageY;
20
+ position.update((v) => v + (page - current_page) * (param.reversed ? -1 : 1));
21
+ current_page = page;
22
+ }
23
+ }
24
+ div.addEventListener("mousedown", engage);
25
+ document.addEventListener("mouseup", disengage);
26
+ document.addEventListener("mousemove", move);
27
+ return {
28
+ update: (parameter) => {
29
+ if (param.reversed !== parameter.reversed ||
30
+ param.vertical !== parameter.vertical) {
31
+ moving = false;
32
+ }
33
+ param = parameter;
34
+ position.set(param.reset());
35
+ },
36
+ destroy: () => {
37
+ div.removeEventListener("mousedown", engage);
38
+ document.removeEventListener("mouseup", disengage);
39
+ document.removeEventListener("mousemove", move);
40
+ }
41
+ };
42
+ }
43
+ return {
44
+ position,
45
+ draggable
46
+ };
47
+ };
@@ -0,0 +1 @@
1
+ export declare function load(files_from_import_meta: Record<string, unknown>): string[];
@@ -0,0 +1,8 @@
1
+ export function load(files_from_import_meta) {
2
+ const prefix = ".".length;
3
+ const suffix = "/+page.svelte".length;
4
+ const rootlen = "./+page.svelte".length;
5
+ return Object.keys(files_from_import_meta)
6
+ .filter((p) => p.length > rootlen) // remove root page
7
+ .map((p) => p.substring(prefix, p.length - suffix));
8
+ }
@@ -0,0 +1,79 @@
1
+ <style>
2
+ .root {
3
+ gap: 10px;
4
+ padding-top: 20px;
5
+ display: flex;
6
+ flex-direction: column;
7
+ }
8
+
9
+ .logo,
10
+ .search-bar {
11
+ padding-left: 20px;
12
+ padding-right: 20px;
13
+ }
14
+
15
+ input {
16
+ height: 20px;
17
+ width: 100%;
18
+ }
19
+ </style>
20
+
21
+ <script context="module">"use strict";
22
+ function apply(paths, init, pre, next, post) {
23
+ const retval = {};
24
+ for (const path of paths) {
25
+ const parts = path.split("/");
26
+ if (parts.length <= 1) {
27
+ continue;
28
+ }
29
+ let t = retval;
30
+ for (let i = 1; i < parts.length; ++i) {
31
+ const part = parts[i];
32
+ if (t[part] == null) {
33
+ t[part] = init();
34
+ }
35
+ if (i !== parts.length - 1) {
36
+ t[part] = pre(t[part], path);
37
+ }
38
+ if (i !== parts.length - 1) {
39
+ t = next(t[part]);
40
+ }
41
+ else if (post) {
42
+ post(t[part], path);
43
+ }
44
+ }
45
+ }
46
+ return retval;
47
+ }
48
+ </script>
49
+ <script>import Tree from "./Tree.svelte";
50
+ export let info;
51
+ export let selected;
52
+ export let sorter;
53
+ export let renamer;
54
+ let filter = "";
55
+ let states = apply(info, () => ({ expanded: false, sub: {} }), (t, path) => ({ expanded: t.expanded || selected === path, sub: t.sub }), (t) => t.sub);
56
+ function populate(f, i) {
57
+ return apply(f.length > 0 ? i.filter((d) => d.includes(f)) : i, () => ({ url: null, sub: {} }), (t) => t, (t) => t.sub, (t, p) => {
58
+ t.url = p;
59
+ });
60
+ }
61
+ </script>
62
+ <div class="root">
63
+ <div class="logo"><slot /></div>
64
+ <div class="search-bar">
65
+ <input bind:value={filter} type="text" />
66
+ </div>
67
+ <div class="tree">
68
+ <Tree
69
+ tree={populate(filter, info)}
70
+ {selected}
71
+ {sorter}
72
+ {renamer}
73
+ bind:states
74
+ on:navigate
75
+ force_expand={filter.length > 0}
76
+ />
77
+ </div>
78
+ </div>
79
+
@@ -0,0 +1,24 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { Sorter, Renamer } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ info: string[];
6
+ selected: string;
7
+ sorter: Sorter;
8
+ renamer: Renamer;
9
+ };
10
+ events: {
11
+ navigate: CustomEvent<any>;
12
+ } & {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {
16
+ default: {};
17
+ };
18
+ };
19
+ export declare type NavProps = typeof __propDef.props;
20
+ export declare type NavEvents = typeof __propDef.events;
21
+ export declare type NavSlots = typeof __propDef.slots;
22
+ export default class Nav extends SvelteComponentTyped<NavProps, NavEvents, NavSlots> {
23
+ }
24
+ export {};
@@ -0,0 +1,104 @@
1
+ <style>
2
+ .wrapper {
3
+ user-select: none;
4
+ }
5
+
6
+ .wrapper,
7
+ .sub,
8
+ .icon {
9
+ display: flex;
10
+ flex-direction: column;
11
+ }
12
+
13
+ .header {
14
+ height: 30px;
15
+ display: grid;
16
+ grid-template-columns: 15px 1fr;
17
+ align-items: center;
18
+ cursor: pointer;
19
+ }
20
+
21
+ .header > div {
22
+ justify-content: center;
23
+ height: 15px;
24
+ width: 15px;
25
+ }
26
+
27
+ .header > div.expanded {
28
+ transform: rotate(90deg);
29
+ }
30
+
31
+ .header > div > div {
32
+ margin: auto;
33
+ }
34
+
35
+ .header:hover {
36
+ background-color: rgba(2, 156, 253, 0.07);
37
+ }
38
+
39
+ .header.selected {
40
+ background-color: rgba(2, 157, 253, 0.822);
41
+ }
42
+ </style>
43
+
44
+ <script>import { slide } from "svelte/transition";
45
+ import { sort } from "./utils";
46
+ import { createEventDispatcher } from "svelte";
47
+ export let key;
48
+ export let value;
49
+ export let depth;
50
+ export let selected;
51
+ export let force_expand;
52
+ export let states;
53
+ export let sorter;
54
+ export let renamer;
55
+ const dispatch = createEventDispatcher();
56
+ $: style = `padding-left: ${10 + depth * 10}px;`;
57
+ $: has_children = Object.keys(value.sub).length > 0;
58
+ function click(link) {
59
+ if (link != null && selected !== link) {
60
+ dispatch("navigate", link);
61
+ }
62
+ else if (has_children) {
63
+ states.expanded = !states.expanded;
64
+ }
65
+ }
66
+ </script>
67
+ <div class="wrapper">
68
+ <div
69
+ class="header"
70
+ on:click={() => click(value.url)}
71
+ on:keypress={null}
72
+ {style}
73
+ class:selected={selected === value.url}
74
+ >
75
+ <div class="icon" class:expanded={has_children && states.expanded}>
76
+ <div>
77
+ {#if Object.keys(value.sub).length > 0}
78
+ >
79
+ {:else}
80
+ -
81
+ {/if}
82
+ </div>
83
+ </div>
84
+ <span>{renamer(key)}</span>
85
+ </div>
86
+ {#if force_expand || states.expanded}
87
+ <div class="sub" transition:slide|local>
88
+ {#each sort(value.sub, sorter) as [k, v] (k)}
89
+ <svelte:self
90
+ key={k}
91
+ value={v}
92
+ depth={depth + 1}
93
+ {selected}
94
+ {renamer}
95
+ {sorter}
96
+ {force_expand}
97
+ bind:states={states.sub[k]}
98
+ on:navigate
99
+ />
100
+ {/each}
101
+ </div>
102
+ {/if}
103
+ </div>
104
+
@@ -0,0 +1,26 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { Tree, States, Sorter, Renamer } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ key: string;
6
+ value: Tree;
7
+ depth: number;
8
+ selected: string;
9
+ force_expand: boolean;
10
+ states: States;
11
+ sorter: Sorter;
12
+ renamer: Renamer;
13
+ };
14
+ events: {
15
+ navigate: CustomEvent<any>;
16
+ } & {
17
+ [evt: string]: CustomEvent<any>;
18
+ };
19
+ slots: {};
20
+ };
21
+ export declare type NodeProps = typeof __propDef.props;
22
+ export declare type NodeEvents = typeof __propDef.events;
23
+ export declare type NodeSlots = typeof __propDef.slots;
24
+ export default class Node extends SvelteComponentTyped<NodeProps, NodeEvents, NodeSlots> {
25
+ }
26
+ export {};
@@ -0,0 +1,23 @@
1
+
2
+ <script>import Node from "./Node.svelte";
3
+ import { sort } from "./utils";
4
+ export let tree;
5
+ export let states;
6
+ export let sorter;
7
+ export let renamer;
8
+ export let force_expand;
9
+ export let selected;
10
+ </script>
11
+ {#each sort(tree, sorter) as [key, value] (key)}
12
+ <Node
13
+ {key}
14
+ {value}
15
+ depth={0}
16
+ {selected}
17
+ {sorter}
18
+ {renamer}
19
+ {force_expand}
20
+ bind:states={states[key]}
21
+ on:navigate
22
+ />
23
+ {/each}
@@ -0,0 +1,24 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { Tree, States, Sorter, Renamer } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ tree: Record<string, Tree>;
6
+ states: Record<string, States>;
7
+ sorter: Sorter;
8
+ renamer: Renamer;
9
+ force_expand: boolean;
10
+ selected: string;
11
+ };
12
+ events: {
13
+ navigate: CustomEvent<any>;
14
+ } & {
15
+ [evt: string]: CustomEvent<any>;
16
+ };
17
+ slots: {};
18
+ };
19
+ export declare type TreeProps = typeof __propDef.props;
20
+ export declare type TreeEvents = typeof __propDef.events;
21
+ export declare type TreeSlots = typeof __propDef.slots;
22
+ export default class Tree extends SvelteComponentTyped<TreeProps, TreeEvents, TreeSlots> {
23
+ }
24
+ export {};
@@ -0,0 +1,12 @@
1
+ export interface Tree {
2
+ url: string | null;
3
+ sub: Record<string, Tree>;
4
+ }
5
+
6
+ export interface States {
7
+ expanded: boolean;
8
+ sub: Record<string, States>;
9
+ }
10
+
11
+ export type Sorter = (l: string, r: string) => 1 | 0 | -1;
12
+ export type Renamer = (s: string) => string;
@@ -0,0 +1,5 @@
1
+ import type { Tree, Sorter, Renamer } from "./types";
2
+ declare const sorter: Sorter;
3
+ declare const renamer: Renamer;
4
+ export declare function sort(t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1): [string, Tree][];
5
+ export { sorter, renamer };
@@ -0,0 +1,35 @@
1
+ const match = /(\d+)-(.+)/;
2
+ function sorterT(l, r) {
3
+ if (l < r) {
4
+ return -1;
5
+ }
6
+ if (l > r) {
7
+ return +1;
8
+ }
9
+ return 0;
10
+ }
11
+ const sorter = (l, r) => {
12
+ const lmatch = match.exec(l);
13
+ const rmatch = match.exec(r);
14
+ if (lmatch == null && rmatch == null) {
15
+ return sorterT(l, r);
16
+ }
17
+ if (lmatch == null) {
18
+ return 1;
19
+ }
20
+ if (rmatch == null) {
21
+ return -1;
22
+ }
23
+ return sorterT(parseInt(lmatch[1]), parseInt(rmatch[1]));
24
+ };
25
+ const renamer = (t) => {
26
+ const m = match.exec(t);
27
+ if (m) {
28
+ return m[2];
29
+ }
30
+ return t;
31
+ };
32
+ export function sort(t, order) {
33
+ return Object.entries(t).sort(([l], [r]) => order(l, r));
34
+ }
35
+ export { sorter, renamer };
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { load } from "./components/load";
2
+ export { renamer, sorter } from "./components/navigation/utils";
3
+ export type { Control } from "./components/block/controls/types";
4
+ export { default as Layout } from "./components/Layout.svelte";
5
+ export { default as Block } from "./components/block/Block.svelte";
6
+ export { default as Template } from "./components/block/Template.svelte";
7
+ export { default as Controls } from "./components/block/Controls.svelte";
8
+ export { default as Params } from "./components/block/Params.svelte";
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { load } from "./components/load";
2
+ export { renamer, sorter } from "./components/navigation/utils";
3
+ export { default as Layout } from "./components/Layout.svelte";
4
+ export { default as Block } from "./components/block/Block.svelte";
5
+ export { default as Template } from "./components/block/Template.svelte";
6
+ export { default as Controls } from "./components/block/Controls.svelte";
7
+ export { default as Params } from "./components/block/Params.svelte";
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@nil-/doc",
3
+ "version": "0.1.0",
4
+ "devDependencies": {
5
+ "@sveltejs/adapter-auto": "1.0.0-next.87",
6
+ "@sveltejs/kit": "1.0.0-next.553",
7
+ "@sveltejs/package": "next",
8
+ "mdsvex": "^0.10.6",
9
+ "svelte": "^3.53.1",
10
+ "svelte-check": "^2.9.2",
11
+ "svelte-markdown": "^0.2.3",
12
+ "svelte-preprocess": "^4.10.7",
13
+ "tslib": "^2.4.1",
14
+ "typescript": "^4.8.4",
15
+ "vite": "^3.2.4"
16
+ },
17
+ "type": "module",
18
+ "publishConfig": {
19
+ "linkDirectory": true
20
+ },
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": "./index.js"
24
+ },
25
+ "svelte": "./index.js"
26
+ }