@nil-/doc 0.2.30 → 0.2.32

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @nil-/doc
2
2
 
3
+ ## 0.2.32
4
+
5
+ ### Patch Changes
6
+
7
+ - [doc] relaxed file extension for sveltekit helper ([#47](https://github.com/njaldea/mono/pull/47))
8
+
9
+ ## 0.2.31
10
+
11
+ ### Patch Changes
12
+
13
+ - [doc] better container style ([#45](https://github.com/njaldea/mono/pull/45))
14
+
15
+ - [doc] improved ThemeIcon ([#45](https://github.com/njaldea/mono/pull/45))
16
+
3
17
  ## 0.2.30
4
18
 
5
19
  ### Patch Changes
@@ -70,6 +70,8 @@
70
70
  }
71
71
  </style>
72
72
 
73
+ <script context="module">const defaultSorter = (l, r) => l.localeCompare(r);
74
+ </script>
73
75
  <script>import Container from "./etc/Container.svelte";
74
76
  import Nav from "./navigation/Nav.svelte";
75
77
  import { inRoot, getTheme, initTheme, evalTheme } from "./context";
@@ -90,13 +92,13 @@ $:
90
92
  <slot name="title"><span>@nil-/doc</span></slot>
91
93
  <ThemeIcon bind:dark={$isDark} />
92
94
  </div>
93
- <Container offset={250} padding={250} vertical secondary>
95
+ <Container offset={250} vertical secondary>
94
96
  <svelte:fragment slot="primary">
95
97
  <div class="content scrollable">
96
98
  <Nav
97
99
  info={data}
98
100
  selected={current ?? ""}
99
- sorter={sorter ?? ((l, r) => (l === r ? 0 : l < r ? -1 : +1))}
101
+ sorter={sorter ?? defaultSorter}
100
102
  renamer={renamer ?? ((s) => s)}
101
103
  on:navigate
102
104
  />
@@ -81,10 +81,10 @@ const isDark = getTheme();
81
81
  export let defaults = void 0;
82
82
  export let noreset = false;
83
83
  export let columns = false;
84
- function reset() {
84
+ const reset = () => {
85
85
  $params = [];
86
86
  $defaultsStore = defaults;
87
- }
87
+ };
88
88
  $:
89
89
  $defaultsStore, reset();
90
90
  let hovered = null;
@@ -1,12 +1,12 @@
1
1
  import { getContext, setContext } from "svelte";
2
2
  import { writable } from "svelte/store";
3
- function create(defaulter) {
3
+ const create = (defaulter) => {
4
4
  const symbol = Symbol();
5
5
  return {
6
6
  init: () => setContext(symbol, writable(defaulter())),
7
7
  get: () => getContext(symbol)
8
8
  };
9
- }
9
+ };
10
10
  export const { init: initCurrent, get: getCurrent } = create(() => null);
11
11
  export const { init: initParams, get: getParams } = create(() => []);
12
12
  export const { init: initControls, get: getControls } = create(() => []);
@@ -11,18 +11,18 @@ export let info;
11
11
  export let depth;
12
12
  export let disabled = false;
13
13
  </script>
14
- {#if info.type === "object"}
14
+ {#if "object" === info.type}
15
15
  <Object {info} bind:value {depth} {disabled} />
16
- {:else if info.type === "tuple"}
16
+ {:else if "tuple" === info.type}
17
17
  <Tuple {info} bind:value {depth} {disabled} />
18
- {:else if info.type === "text"}
18
+ {:else if "text" === info.type}
19
19
  <Text {info} bind:value {depth} {disabled} />
20
- {:else if info.type === "number"}
20
+ {:else if "number" === info.type}
21
21
  <Number {info} bind:value {depth} {disabled} />
22
- {:else if info.type === "range"}
22
+ {:else if "range" === info.type}
23
23
  <Range {info} bind:value {depth} {disabled} />
24
- {:else if info.type === "select"}
24
+ {:else if "select" === info.type}
25
25
  <Select {info} bind:value {depth} {disabled} />
26
- {:else if info.type === "switch"}
26
+ {:else if "switch" === info.type}
27
27
  <Switch {info} bind:value {depth} {disabled} />
28
28
  {/if}
@@ -10,7 +10,7 @@ $:
10
10
  value = enabled && !disabled ? ivalue : void 0;
11
11
  </script>
12
12
  <div>
13
- <div style:padding-left={`${depth}px`}>- {info.name}</div>
13
+ <div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
14
14
  <div><input type="number" bind:value={ivalue} disabled={!enabled || disabled} /></div>
15
15
  <div><input type="checkbox" bind:checked={enabled} {disabled} /></div>
16
16
  </div>
@@ -43,7 +43,7 @@ $:
43
43
  value = enabled && !disabled ? ivalue : void 0;
44
44
  </script>
45
45
  <div>
46
- <div style:padding-left={`${depth}px`}>- {info.name}</div>
46
+ <div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
47
47
  <div class="input">
48
48
  <div class="tooltip">
49
49
  Current Value: {ivalue}
@@ -10,7 +10,7 @@ $:
10
10
  value = enabled && !disabled ? ivalue : void 0;
11
11
  </script>
12
12
  <div>
13
- <div style:padding-left={`${depth}px`}>- {info.name}</div>
13
+ <div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
14
14
  <div>
15
15
  <select bind:value={ivalue} disabled={!enabled || disabled}>
16
16
  {#each info.values as value}
@@ -10,7 +10,7 @@ $:
10
10
  value = enabled && !disabled ? ivalue : void 0;
11
11
  </script>
12
12
  <div>
13
- <div style:padding-left={`${depth}px`}>- {info.name}</div>
13
+ <div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
14
14
  <div><input type="checkbox" bind:checked={ivalue} disabled={!enabled || disabled} /></div>
15
15
  <div><input type="checkbox" bind:checked={enabled} {disabled} /></div>
16
16
  </div>
@@ -10,7 +10,7 @@ $:
10
10
  value = ienabled && !disabled ? ivalue : void 0;
11
11
  </script>
12
12
  <div>
13
- <div style:padding-left={`${depth}px`}>- {info.name}</div>
13
+ <div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
14
14
  <div><input type="text" bind:value={ivalue} disabled={!ienabled || disabled} /></div>
15
15
  <div><input type="checkbox" bind:checked={ienabled} {disabled} /></div>
16
16
  </div>
@@ -10,7 +10,7 @@ export let checked;
10
10
  export let disabled = false;
11
11
  </script>
12
12
  <div>
13
- <div style:padding-left={`${depth}px`}>
13
+ <div style:padding-left={`${depth}px`} title={name}>
14
14
  {`> ${name}`}
15
15
  </div>
16
16
  <div class="value">-</div>
@@ -47,6 +47,14 @@ const isDark = getTheme();
47
47
  background-color: hsl(210, 100%, 90%);
48
48
  }
49
49
 
50
+ div > :global(div:nth-child(n + 2) > div:first-child) {
51
+ overflow: hidden;
52
+ white-space: nowrap;
53
+ text-overflow: ellipsis;
54
+ padding-right: 10px;
55
+ display: block;
56
+ }
57
+
50
58
  div > :global(div:hover .tooltip) {
51
59
  background-color: hsl(0, 0%, 100%);
52
60
  outline: hsl(0, 100%, 0%) 1px solid;
@@ -1,5 +1,5 @@
1
1
  import type { ValueType } from "../../context";
2
2
  import type { Control, ControlTuple, ControlObject } from "../types";
3
- export declare function getObjectDefaults(info: ControlObject): Record<string, ValueType>;
4
- export declare function getTupleDefaults(i: ControlTuple): ValueType[];
5
- export declare function getDefault(i: Control): ValueType;
3
+ export declare const getDefault: (i: Control) => ValueType;
4
+ export declare const getObjectDefaults: (info: ControlObject) => Record<string, ValueType>;
5
+ export declare const getTupleDefaults: (i: ControlTuple) => ValueType[];
@@ -1,38 +1,40 @@
1
- export function getObjectDefaults(info) {
2
- const ret = {};
3
- for (const i of info.values) {
4
- ret[i.name] = getDefault(i);
5
- }
6
- return ret;
7
- }
8
- export function getTupleDefaults(i) {
9
- const ret = [];
10
- for (const info of i.values) {
11
- ret.push(getDefault(info));
12
- }
13
- return ret;
14
- }
15
- export function getDefault(i) {
16
- if (i.type === "switch") {
1
+ export const getDefault = (i) => {
2
+ if ("switch" === i.type) {
17
3
  return false;
18
4
  }
19
- if (i.type === "number") {
5
+ if ("number" === i.type) {
20
6
  return 0;
21
7
  }
22
- if (i.type === "range") {
8
+ if ("range" === i.type) {
23
9
  return i.min;
24
10
  }
25
- if (i.type === "text") {
11
+ if ("text" === i.type) {
26
12
  return "";
27
13
  }
28
- if (i.type === "select") {
14
+ if ("select" === i.type) {
29
15
  return i.values.length > 0 ? i.values[0] : "";
30
16
  }
31
- if (i.type === "tuple") {
17
+ if ("tuple" === i.type) {
18
+ // eslint-disable-next-line no-use-before-define
32
19
  return [...getTupleDefaults(i)];
33
20
  }
34
- if (i.type === "object") {
21
+ if ("object" === i.type) {
22
+ // eslint-disable-next-line no-use-before-define
35
23
  return getObjectDefaults(i);
36
24
  }
37
25
  return undefined;
38
- }
26
+ };
27
+ export const getObjectDefaults = (info) => {
28
+ const ret = {};
29
+ for (const i of info.values) {
30
+ ret[i.name] = getDefault(i);
31
+ }
32
+ return ret;
33
+ };
34
+ export const getTupleDefaults = (i) => {
35
+ const ret = [];
36
+ for (const info of i.values) {
37
+ ret.push(getDefault(info));
38
+ }
39
+ return ret;
40
+ };
@@ -1,22 +1,14 @@
1
- export type NonNamed<T> = Omit<T, "name">;
2
- export type NonNamedControl =
3
- | NonNamed<ControlTuple>
4
- | NonNamed<ControlObject>
5
- | NonNamed<ControlText>
6
- | NonNamed<ControlNumber>
7
- | NonNamed<ControlRange>
8
- | NonNamed<ControlSelect>
9
- | NonNamed<ControlSwitch>;
10
-
11
1
  export type ControlTuple = {
12
2
  name: string;
13
3
  type: "tuple";
4
+ // eslint-disable-next-line no-use-before-define
14
5
  values: NonNamedControl[];
15
6
  };
16
7
 
17
8
  export type ControlObject = {
18
9
  name: string;
19
10
  type: "object";
11
+ // eslint-disable-next-line no-use-before-define
20
12
  values: Control[];
21
13
  };
22
14
 
@@ -57,3 +49,12 @@ export type Control =
57
49
  | ControlRange
58
50
  | ControlSelect
59
51
  | ControlSwitch;
52
+
53
+ type NonNamedControl =
54
+ | Omit<ControlTuple, "name">
55
+ | Omit<ControlObject, "name">
56
+ | Omit<ControlText, "name">
57
+ | Omit<ControlNumber, "name">
58
+ | Omit<ControlRange, "name">
59
+ | Omit<ControlSelect, "name">
60
+ | Omit<ControlSwitch, "name">;
@@ -2,5 +2,5 @@ import type { ValueType } from "./context";
2
2
  type VTObject = {
3
3
  [key: string]: ValueType;
4
4
  };
5
- export declare function resolve<Args>(d: VTObject | undefined, p: VTObject): Args;
5
+ export declare const resolve: <Args>(d: VTObject | undefined, p: VTObject) => Args;
6
6
  export {};
@@ -1,4 +1,4 @@
1
- function resolveArray(d, p) {
1
+ const resolveArray = (d, p) => {
2
2
  if (d === undefined) {
3
3
  return undefined;
4
4
  }
@@ -8,6 +8,7 @@ function resolveArray(d, p) {
8
8
  ret.push(resolveArray(d[i], p[i] ?? []));
9
9
  }
10
10
  else if (d[i] instanceof Object) {
11
+ // eslint-disable-next-line no-use-before-define
11
12
  ret.push(resolveObject(d[i], p[i] ?? {}));
12
13
  }
13
14
  else {
@@ -15,8 +16,8 @@ function resolveArray(d, p) {
15
16
  }
16
17
  }
17
18
  return ret;
18
- }
19
- function resolveObject(d, p) {
19
+ };
20
+ const resolveObject = (d, p) => {
20
21
  if (d === undefined) {
21
22
  return undefined;
22
23
  }
@@ -33,7 +34,5 @@ function resolveObject(d, p) {
33
34
  }
34
35
  }
35
36
  return ret;
36
- }
37
- export function resolve(d, p) {
38
- return resolveObject(d ?? {}, p);
39
- }
37
+ };
38
+ export const resolve = (d, p) => resolveObject(d ?? {}, p);
@@ -1,6 +1,6 @@
1
1
  import type { Writable } from "svelte/store";
2
- export declare function inRoot(): boolean;
2
+ export declare const inRoot: () => boolean;
3
3
  export type Theme = undefined | "light" | "dark";
4
- export declare function getTheme(): Writable<boolean>;
5
- export declare function initTheme(): Writable<boolean>;
6
- export declare function evalTheme(parent: boolean, theme: Theme): boolean;
4
+ export declare const getTheme: () => Writable<boolean>;
5
+ export declare const initTheme: () => Writable<boolean>;
6
+ export declare const evalTheme: (parent: boolean, theme: Theme) => boolean;
@@ -1,18 +1,17 @@
1
1
  import { setContext, getContext } from "svelte";
2
2
  import { writable } from "svelte/store";
3
3
  const root = Symbol();
4
- export function inRoot() {
4
+ export const inRoot = () => {
5
5
  const value = getContext(root);
6
6
  setContext(root, false);
7
7
  return value !== false;
8
- }
8
+ };
9
9
  const theme = Symbol();
10
- export function getTheme() {
11
- return getContext(theme);
12
- }
13
- export function initTheme() {
14
- return setContext(theme, writable(true));
15
- }
16
- export function evalTheme(parent, theme) {
17
- return theme === undefined ? parent : theme === "dark";
18
- }
10
+ export const getTheme = () => getContext(theme);
11
+ export const initTheme = () => setContext(theme, writable(true));
12
+ export const evalTheme = (parent, theme) => {
13
+ if (theme === undefined) {
14
+ return parent;
15
+ }
16
+ return "dark" === theme;
17
+ };
@@ -1,4 +1,8 @@
1
1
  <style>
2
+ div {
3
+ box-sizing: border-box;
4
+ }
5
+
2
6
  .container {
3
7
  width: 100%;
4
8
  height: 100%;
@@ -20,110 +24,156 @@
20
24
  overflow: hidden;
21
25
  }
22
26
 
23
- /* need higher specificity than above */
24
27
  .container > .divider {
25
28
  z-index: 10;
26
- width: auto;
27
- height: 0px;
28
29
  overflow: visible;
29
30
  user-select: none;
30
31
  grid-area: divider;
31
32
  }
32
33
 
33
- .container > .divider.vertical {
34
- width: 0px;
35
- height: auto;
34
+ .overlay {
35
+ touch-action: none;
36
36
  }
37
37
 
38
38
  .container > .divider > .overlay {
39
39
  width: 100%;
40
40
  height: 20px;
41
- cursor: row-resize;
41
+ cursor: ns-resize;
42
42
  transform: translateY(-50%);
43
- touch-action: none;
44
43
  }
45
44
 
46
- .container > .divider.vertical > .overlay {
45
+ .container.vertical > .divider > .overlay {
47
46
  width: 20px;
48
47
  height: 100%;
49
- cursor: col-resize;
48
+ cursor: ew-resize;
50
49
  transform: translateX(-50%);
51
50
  }
52
51
 
53
52
  /* colors */
54
- .container > .divider {
55
- outline: hsl(0, 2%, 70%) solid 1px;
53
+ .container {
54
+ --color-p: hsl(0, 2%, 70%);
55
+ --color-s: hsl(0, 0%, 0%);
56
56
  }
57
57
 
58
- .container > .divider.moving {
59
- outline: hsl(0, 0%, 0%) solid 1px;
58
+ .container.dark {
59
+ --color-p: hsl(0, 2%, 38%);
60
+ --color-s: hsl(0, 0%, 100%);
60
61
  }
61
62
 
62
- .container.dark > .divider {
63
- outline: hsl(0, 2%, 38%) solid 1px;
63
+ .container:not(.vertical) > .divider {
64
+ border-bottom: var(--color-p) solid 2.5px;
65
+ border-top: var(--color-p) solid 2.5px;
66
+ background-color: var(--color-p);
64
67
  }
65
68
 
66
- .container.dark > .divider.moving {
67
- outline: hsl(0, 0%, 100%) solid 1px;
69
+ .container.vertical > .divider {
70
+ border-right: var(--color-p) solid 2.5px;
71
+ border-left: var(--color-p) solid 2.5px;
72
+ background-color: var(--color-p);
73
+ }
74
+
75
+ .container.moving:not(.secondary):not(.vertical) > .divider {
76
+ border-bottom: var(--color-s) solid 2.5px;
77
+ }
78
+
79
+ .container.moving.secondary:not(.vertical) > .divider {
80
+ border-top: var(--color-s) solid 2.5px;
81
+ }
82
+
83
+ .container.moving:not(.secondary).vertical > .divider {
84
+ border-right: var(--color-s) solid 2.5px;
85
+ }
86
+
87
+ .container.moving.vertical.secondary > .divider {
88
+ border-left: var(--color-s) solid 2.5px;
68
89
  }
69
90
  </style>
70
91
 
71
92
  <script>import { writable } from "svelte/store";
93
+ import { tweened } from "svelte/motion";
72
94
  import { createDraggable } from "./action";
73
95
  import { getTheme } from "../context";
74
96
  const isDark = getTheme();
75
97
  export let vertical = false;
76
98
  export let offset = 0;
77
99
  export let secondary = false;
78
- export let padding = 0;
79
100
  let width;
80
101
  let height;
81
- let collapse = false;
82
102
  const { position, draggable } = createDraggable(offset);
83
- function update(w, h, limit, value) {
84
- if (w == null || h == null || collapse) {
103
+ $:
104
+ span = vertical ? width : height;
105
+ const update = (limit, value) => {
106
+ if (null == span) {
85
107
  return;
86
108
  }
87
- const span = vertical ? w : h;
88
109
  offset = Math.max(Math.min(value, span - limit), limit);
89
- }
110
+ };
111
+ const off = tweened(offset, { duration: 50 });
112
+ let last = [];
90
113
  $:
91
- update(width, height, padding, $position);
114
+ update(10, $position);
92
115
  $:
93
- offsetpx = collapse ? "10px" : `${offset}px`;
116
+ $off = offset;
94
117
  $:
95
- style = !secondary ? `auto 0px ${offsetpx}` : `${offsetpx} 0px auto`;
118
+ style = !secondary ? `auto 5px ${$off}px` : `${$off}px 5px auto`;
96
119
  const moving = writable(false);
120
+ const addLast = (v) => {
121
+ if (v > 10) {
122
+ if (last.length < 2) {
123
+ last = [...last, v];
124
+ } else {
125
+ last = [last[1], v];
126
+ }
127
+ }
128
+ };
129
+ const dbltap = () => {
130
+ if ($off > 10) {
131
+ addLast(offset);
132
+ offset = 10;
133
+ } else if (last.length > 0) {
134
+ offset = last.pop();
135
+ }
136
+ };
137
+ const check = (v, flag, s) => {
138
+ if (flag) {
139
+ return v < s - 10;
140
+ } else {
141
+ return v > 10;
142
+ }
143
+ };
97
144
  </script>
98
145
  <div
99
146
  class="container"
100
147
  class:vertical
148
+ class:secondary
101
149
  class:dark={$isDark}
102
- bind:clientHeight={height}
150
+ class:moving={$moving}
103
151
  bind:clientWidth={width}
152
+ bind:clientHeight={height}
104
153
  style:grid-template-columns={vertical ? style : null}
105
154
  style:grid-template-rows={!vertical ? style : null}
106
155
  >
107
156
  {#if width != null && height != null}
108
157
  <div style:grid-area="primary">
109
- {#if !collapse || !secondary}
158
+ {#if check($off, !secondary, span)}
110
159
  <slot name="primary" />
111
160
  {/if}
112
161
  </div>
113
- <div class="divider" class:vertical class:moving={$moving}>
162
+ <div class="divider">
114
163
  <div
115
164
  class="overlay"
116
165
  use:draggable={{
117
166
  reset: () => offset,
118
167
  reversed: !secondary,
119
168
  vertical,
120
- dbltap: () => (collapse = !collapse),
169
+ dbltap: dbltap,
170
+ tap: () => addLast($off),
121
171
  moving
122
172
  }}
123
173
  />
124
174
  </div>
125
175
  <div style:grid-area="secondary">
126
- {#if !collapse || secondary}
176
+ {#if check($off, secondary, span)}
127
177
  <slot name="secondary" />
128
178
  {/if}
129
179
  </div>
@@ -4,7 +4,6 @@ declare const __propDef: {
4
4
  vertical?: boolean | undefined;
5
5
  offset?: number | undefined;
6
6
  secondary?: boolean | undefined;
7
- padding?: number | undefined;
8
7
  };
9
8
  events: {
10
9
  [evt: string]: CustomEvent<any>;
@@ -1,78 +1,76 @@
1
- <script>export let dark = true;
2
- import { tweened } from "svelte/motion";
3
- const values = tweened(dark ? vdark : vlight, { duration: 350 });
1
+ <script>import { tweened } from "svelte/motion";
2
+ import { elasticOut } from "svelte/easing";
3
+ export let dark = true;
4
+ const values = tweened(dark ? vdark : vlight, { duration: 1e3, easing: elasticOut });
4
5
  $:
5
- values.set(dark ? vdark : vlight);
6
+ $values = dark ? vdark : vlight;
6
7
  const index = indexer++;
7
8
  </script>
8
9
  <style>
9
10
  svg {
10
- all: unset;
11
- width: 50%;
12
- height: 50%;
13
- margin: auto;
14
-
15
11
  cursor: pointer;
16
- color: black;
17
- fill: none;
18
-
12
+ fill: currentColor;
19
13
  stroke: currentColor;
20
- stroke-width: 2;
21
- stroke-linecap: round;
22
- stroke-linejoin: round;
23
14
 
24
15
  -webkit-tap-highlight-color: transparent;
25
16
  -moz-tap-highlight-color: transparent;
26
17
  -o-tap-highlight-color: transparent;
27
- tap-highlight-color: transparent;
18
+ /* tap-highlight-color: transparent; */
28
19
  }
29
20
 
30
- svg.dark {
31
- color: white;
21
+ svg,
22
+ rect {
23
+ width: 100%;
24
+ height: 100%;
25
+ }
26
+
27
+ line {
28
+ stroke-width: 2;
29
+ stroke-linecap: round;
30
+ stroke-linejoin: round;
32
31
  }
33
32
  </style>
34
33
 
35
34
  <script context="module">let indexer = 0;
36
35
  const vlight = {
37
36
  rotate: 40,
38
- mask: {
39
- cx: 12,
40
- cy: 4
41
- },
37
+ mcy: -8,
42
38
  cr: 10,
43
- opacity: 0
39
+ v: 0
44
40
  };
45
41
  const vdark = {
46
42
  rotate: 180,
47
- mask: {
48
- cx: 30,
49
- cy: 0
50
- },
43
+ mcy: -24,
51
44
  cr: 5,
52
- opacity: 1
45
+ v: 1
53
46
  };
54
47
  </script>
55
48
  <svg
56
49
  class:dark
57
- viewBox="0 0 24 24"
58
- style={`transform: rotate(${$values.rotate}deg)`}
50
+ viewBox="-25 -25 50 50"
51
+ transform={`rotate(${$values.rotate})`}
52
+ style={`color: hsl(0, 0%, ${$values.v * 100}%);`}
59
53
  on:click={() => (dark = !dark)}
60
54
  on:keypress={null}
61
55
  >
62
- <mask id={`theme_icon_${index}`}>
63
- <rect x="0" y="0" width="100%" height="100%" fill="white" />
64
- <circle cx={$values.mask.cx} cy={$values.mask.cy} r="11" fill="currentColor" />
56
+ <mask id={`nil_doc_theme_icon_${index}`}>
57
+ <rect x="-25" y="-25" fill="white" />
58
+ <circle cy={$values.mcy} r="11" />
65
59
  </mask>
66
- <circle cx="12" cy="12" r={$values.cr} fill="currentColor" mask={`url(#theme_icon_${index})`} />
67
- <g style={`opacity: ${$values.opacity}`}>
68
- <line x1="12" y1="1" x2="12" y2="3" />
69
- <line x1="12" y1="21" x2="12" y2="23" />
70
- <line x1="4.22" y1="4.22" x2="5.64" y2="5.64" />
71
- <line x1="18.36" y1="18.36" x2="19.78" y2="19.78" />
72
- <line x1="1" y1="12" x2="3" y2="12" />
73
- <line x1="21" y1="12" x2="23" y2="12" />
74
- <line x1="4.22" y1="19.78" x2="5.64" y2="18.36" />
75
- <line x1="18.36" y1="5.64" x2="19.78" y2="4.22" />
60
+ <circle r={$values.cr} mask={`url(#nil_doc_theme_icon_${index})`} />
61
+ <g style={`opacity: ${$values.v}`}>
62
+ <g>
63
+ <line x1="0" y1="9" x2="0" y2="11" />
64
+ <line x1="9" y1="0" x2="11" y2="0" />
65
+ <line x1="0" y1="-11" x2="0" y2="-9" />
66
+ <line x1="-11" y1="0" x2="-9" y2="0" />
67
+ </g>
68
+ <g transform="rotate(45)">
69
+ <line x1="0" y1="9" x2="0" y2="11" />
70
+ <line x1="9" y1="0" x2="11" y2="0" />
71
+ <line x1="0" y1="-11" x2="0" y2="-9" />
72
+ <line x1="-11" y1="0" x2="-9" y2="0" />
73
+ </g>
76
74
  </g>
77
75
  </svg>
78
76
 
@@ -5,6 +5,7 @@ type Parameter = {
5
5
  vertical: boolean;
6
6
  reversed: boolean;
7
7
  dbltap?: () => void;
8
+ tap?: () => void;
8
9
  moving: Writable<boolean>;
9
10
  };
10
11
  type Return = {
@@ -1,21 +1,19 @@
1
1
  import { get, writable } from "svelte/store";
2
2
  export const createDraggable = (offset) => {
3
3
  const position = writable(offset);
4
- function draggable(div, parameter) {
4
+ const draggable = (div, parameter) => {
5
5
  let tm = new Date().getTime();
6
6
  let param = parameter ?? { reset: () => 0, vertical: true, reversed: false };
7
7
  position.set(param.reset());
8
8
  let current_page = 0;
9
- function disengage() {
10
- param.moving.set(false);
11
- }
12
- function checkDoubleTap() {
9
+ const disengage = () => param.moving.set(false);
10
+ const checkDoubleTap = () => {
13
11
  const tm2 = new Date().getTime();
14
12
  const diff = tm2 - tm;
15
13
  tm = tm2;
16
14
  return diff < 200;
17
- }
18
- function engage(e) {
15
+ };
16
+ const engage = (e) => {
19
17
  if (checkDoubleTap()) {
20
18
  param?.dbltap?.();
21
19
  disengage();
@@ -24,14 +22,15 @@ export const createDraggable = (offset) => {
24
22
  param.moving.set(true);
25
23
  position.set(param.reset());
26
24
  current_page = param.vertical ? e.pageX : e.pageY;
27
- }
28
- function move(e) {
25
+ param?.tap?.();
26
+ };
27
+ const move = (e) => {
29
28
  if (get(param.moving)) {
30
29
  const page = param.vertical ? e.pageX : e.pageY;
31
30
  position.update((v) => v + (page - current_page) * (param.reversed ? -1 : 1));
32
31
  current_page = page;
33
32
  }
34
- }
33
+ };
35
34
  div.addEventListener("pointerdown", engage);
36
35
  window.addEventListener("pointerup", disengage);
37
36
  window.addEventListener("pointercancel", disengage);
@@ -47,7 +46,7 @@ export const createDraggable = (offset) => {
47
46
  window.removeEventListener("pointermove", move);
48
47
  }
49
48
  };
50
- }
49
+ };
51
50
  return {
52
51
  position,
53
52
  draggable
@@ -3,7 +3,6 @@
3
3
  width: 100%;
4
4
  height: 100%;
5
5
  gap: 10px;
6
- padding-top: 20px;
7
6
  display: flex;
8
7
  flex-direction: column;
9
8
  }
@@ -26,7 +25,7 @@
26
25
  }
27
26
  </style>
28
27
 
29
- <script context="module">function apply(paths, init, pre, next, post) {
28
+ <script context="module">const apply = (paths, init, pre, next, post) => {
30
29
  const retval = {};
31
30
  for (const path of paths) {
32
31
  const parts = path.split("/");
@@ -36,7 +35,7 @@
36
35
  let t = retval;
37
36
  for (let i = 1; i < parts.length; ++i) {
38
37
  const part = parts[i];
39
- if (t[part] == null) {
38
+ if (null == t[part]) {
40
39
  t[part] = init();
41
40
  }
42
41
  if (i !== parts.length - 1) {
@@ -50,21 +49,17 @@
50
49
  }
51
50
  }
52
51
  return retval;
53
- }
54
- function filt(path, filter, renamer) {
55
- return path.includes(filter) || path.split("/").map(renamer).join("/").includes(filter);
56
- }
57
- function populate(filter, info, renamer) {
58
- return apply(
59
- filter.length > 0 ? info.filter((path) => filt(path, filter, renamer)) : info,
60
- () => ({ url: null, sub: {} }),
61
- (t) => t,
62
- (t) => t.sub,
63
- (t, p) => {
64
- t.url = p;
65
- }
66
- );
67
- }
52
+ };
53
+ const filt = (path, filter, renamer) => path.includes(filter) || path.split("/").map(renamer).join("/").includes(filter);
54
+ const populate = (filter, info, renamer) => apply(
55
+ filter.length > 0 ? info.filter((path) => filt(path, filter, renamer)) : info,
56
+ () => ({ url: null, sub: {} }),
57
+ (t) => t,
58
+ (t) => t.sub,
59
+ (t, p) => {
60
+ t.url = p;
61
+ }
62
+ );
68
63
  </script>
69
64
  <script>import Tree from "./Tree.svelte";
70
65
  export let info;
@@ -78,7 +73,7 @@ let states = apply(
78
73
  (t, path) => ({ expanded: t.expanded || selected === path, sub: t.sub }),
79
74
  (t) => t.sub
80
75
  );
81
- function update(selected2) {
76
+ const update = (selected2) => {
82
77
  if (!info.includes(selected2)) {
83
78
  return;
84
79
  }
@@ -90,7 +85,7 @@ function update(selected2) {
90
85
  }
91
86
  node = node[p].sub;
92
87
  }
93
- }
88
+ };
94
89
  $:
95
90
  update(selected);
96
91
  </script>
@@ -58,13 +58,13 @@ $:
58
58
  style = `padding-left: ${10 + depth * 10}px;`;
59
59
  $:
60
60
  has_children = Object.keys(value.sub).length > 0;
61
- function click(link) {
61
+ const click = (link) => {
62
62
  if (link != null && selected !== link) {
63
63
  dispatch("navigate", link);
64
64
  } else if (has_children) {
65
65
  states.expanded = !states.expanded;
66
66
  }
67
- }
67
+ };
68
68
  </script>
69
69
  <div class="wrapper">
70
70
  <div
@@ -23,5 +23,5 @@ declare const sorter: Sorter;
23
23
  * @returns `<Name>`
24
24
  */
25
25
  declare const renamer: Renamer;
26
- export declare function sort(t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1): [string, Tree][];
26
+ export declare const sort: (t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1) => [string, Tree][];
27
27
  export { sorter, renamer };
@@ -1,5 +1,5 @@
1
1
  const match = /(\d+)-(.+)/;
2
- function sorterT(l, r) {
2
+ const sorterT = (l, r) => {
3
3
  if (l < r) {
4
4
  return -1;
5
5
  }
@@ -7,7 +7,7 @@ function sorterT(l, r) {
7
7
  return +1;
8
8
  }
9
9
  return 0;
10
- }
10
+ };
11
11
  /**
12
12
  * Compares two texts for sorting.
13
13
  *
@@ -26,13 +26,13 @@ function sorterT(l, r) {
26
26
  const sorter = (l, r) => {
27
27
  const lmatch = match.exec(l);
28
28
  const rmatch = match.exec(r);
29
- if (lmatch == null && rmatch == null) {
29
+ if (null == lmatch && null == rmatch) {
30
30
  return sorterT(l, r);
31
31
  }
32
- if (lmatch == null) {
32
+ if (null == lmatch) {
33
33
  return 1;
34
34
  }
35
- if (rmatch == null) {
35
+ if (null == rmatch) {
36
36
  return -1;
37
37
  }
38
38
  return sorterT(parseInt(lmatch[1]), parseInt(rmatch[1]));
@@ -51,7 +51,5 @@ const renamer = (text) => {
51
51
  }
52
52
  return text;
53
53
  };
54
- export function sort(t, order) {
55
- return Object.entries(t).sort(([l], [r]) => order(l, r));
56
- }
54
+ export const sort = (t, order) => Object.entries(t).sort(([l], [r]) => order(l, r));
57
55
  export { sorter, renamer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nil-/doc",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "author": {
5
5
  "email": "njaldea@gmail.com",
6
6
  "name": "Neil Aldea"
@@ -12,7 +12,6 @@
12
12
  "@sveltejs/package": "^1.0.1",
13
13
  "mdsvex": "^0.10.6",
14
14
  "svelte-check": "^2.10.3",
15
- "svelte-markdown": "^0.2.3",
16
15
  "tslib": "^2.4.1",
17
16
  "typescript": "^4.9.4",
18
17
  "vite": "^4.0.3"
@@ -20,5 +20,5 @@ type Routes = {
20
20
  * @param prefix - only use when layout is not in the root route
21
21
  * @returns Routes
22
22
  */
23
- export declare function sveltekit(detail: Record<string, unknown>, prefix?: string | null): Routes;
23
+ export declare const sveltekit: (detail: Record<string, unknown>, prefix?: string | null) => Routes;
24
24
  export {};
@@ -1,47 +1,35 @@
1
1
  import { derived } from "svelte/store";
2
2
  import { page } from "$app/stores";
3
3
  import { goto } from "$app/navigation";
4
- const PREFIX = ".";
5
- const SUFFIX = "/+page.svelte";
6
- function toRoute(p) {
7
- return p.substring(PREFIX.length, p.length - SUFFIX.length);
8
- }
4
+ const toRoute = (p) => p.substring(1, p.lastIndexOf("/"));
9
5
  const route_advanced_layout_match = /\(.*\)/;
10
- function collapseLayout(p) {
11
- return p
12
- .split("/")
13
- .filter((p) => route_advanced_layout_match.exec(p) == null)
14
- .join("/");
15
- }
16
- function isNotRoot(p) {
17
- return p !== "/";
18
- }
6
+ const collapseLayout = (p) => p
7
+ .split("/")
8
+ .filter((p) => null == route_advanced_layout_match.exec(p))
9
+ .join("/");
10
+ const isNotRoot = (p) => p !== "/";
19
11
  const route_rest_match = /.*\[.*\].*/;
20
- function isRouteDynamic(p) {
21
- return route_rest_match.exec(p) == null;
22
- }
12
+ const isRouteDynamic = (p) => null == route_rest_match.exec(p);
23
13
  /**
24
14
  * Dedicated helper method to be used for sveltekit
25
15
  * @param detail - vite's `import.meta.glob(..., { eager: true })`
26
16
  * @param prefix - only use when layout is not in the root route
27
17
  * @returns Routes
28
18
  */
29
- export function sveltekit(detail, prefix = null) {
30
- return {
31
- data: Object.keys(detail)
32
- .map(toRoute)
33
- .map(collapseLayout)
34
- .filter(isNotRoot)
35
- .filter(isRouteDynamic),
36
- current: derived(page, ($page) => {
37
- if ($page.route.id) {
38
- if (prefix) {
39
- return collapseLayout($page.route.id.substring(prefix.length));
40
- }
41
- return collapseLayout($page.route.id);
19
+ export const sveltekit = (detail, prefix = null) => ({
20
+ data: Object.keys(detail)
21
+ .map(toRoute)
22
+ .map(collapseLayout)
23
+ .filter(isNotRoot)
24
+ .filter(isRouteDynamic),
25
+ current: derived(page, ($page) => {
26
+ if ($page.route.id) {
27
+ if (prefix) {
28
+ return collapseLayout($page.route.id.substring(prefix.length));
42
29
  }
43
- return null;
44
- }),
45
- navigate: prefix ? (e) => goto(`${prefix}${e.detail}`) : (e) => goto(e.detail)
46
- };
47
- }
30
+ return collapseLayout($page.route.id);
31
+ }
32
+ return null;
33
+ }),
34
+ navigate: prefix ? (e) => goto(`${prefix}${e.detail}`) : (e) => goto(e.detail)
35
+ });