@nil-/doc 0.2.23 → 0.2.25

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,20 @@
1
1
  # @nil-/doc
2
2
 
3
+ ## 0.2.25
4
+
5
+ ### Patch Changes
6
+
7
+ - 186187c: [doc][breaking] removed layout slot prop for content. all unnamed slots will be part of the default slot
8
+ - 186187c: [doc] fix range tooltip styling
9
+ - a82c0de: [doc] support dark/light mode
10
+
11
+ ## 0.2.24
12
+
13
+ ### Patch Changes
14
+
15
+ - 782e6fa: [doc][breaking] simplified sveltekit glue layer
16
+ - 782e6fa: [doc] added documentation to public methods
17
+
3
18
  ## 0.2.23
4
19
 
5
20
  ### Patch Changes
@@ -2,8 +2,6 @@
2
2
  .layout {
3
3
  width: 100%;
4
4
  height: 100%;
5
- color: rgb(201, 205, 207);
6
- background-color: rgb(34, 36, 37);
7
5
  font-family: "Fira Code", "Courier New", Courier, monospace;
8
6
  }
9
7
 
@@ -38,18 +36,35 @@
38
36
  .scrollable::-webkit-scrollbar {
39
37
  display: none;
40
38
  }
39
+
40
+ /* colors */
41
+ .layout {
42
+ background-color: hsl(0, 0%, 100%);
43
+ color: hsl(0, 100%, 0%);
44
+ color-scheme: light;
45
+ }
46
+
47
+ .layout.dark {
48
+ background-color: hsl(200, 4%, 14%);
49
+ color: hsl(200, 6%, 80%);
50
+ color-scheme: dark;
51
+ }
41
52
  </style>
42
53
 
43
54
  <script>import Container from "./etc/Container.svelte";
44
55
  import Nav from "./navigation/Nav.svelte";
45
- import { inRoot } from "./context";
56
+ import { inRoot, getTheme, initTheme, evalTheme } from "./context";
46
57
  export let data;
47
58
  export let current = null;
48
59
  export let sorter = null;
49
60
  export let renamer = null;
61
+ export let theme = undefined;
50
62
  const r = inRoot();
63
+ const parentTheme = getTheme();
64
+ const isDark = initTheme();
65
+ $: $isDark = evalTheme(parentTheme ? $parentTheme : true, theme);
51
66
  </script>
52
- <div class="layout" class:reset={r}>
67
+ <div class="layout" class:reset={r} class:dark={$isDark}>
53
68
  <Container offset={250} padding={250} vertical secondary>
54
69
  <svelte:fragment slot="primary">
55
70
  <div class="content scrollable">
@@ -67,7 +82,7 @@ const r = inRoot();
67
82
  <svelte:fragment slot="secondary">
68
83
  <div class="content scrollable">
69
84
  {#key current}
70
- <slot name="content" />
85
+ <slot />
71
86
  {/key}
72
87
  </div>
73
88
  </svelte:fragment>
@@ -1,11 +1,13 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { Sorter, Renamer } from "./navigation/types";
3
+ import { type Theme } from "./context";
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  data: string[];
6
7
  current?: string | null | undefined;
7
8
  sorter?: Sorter | null | undefined;
8
9
  renamer?: Renamer | null | undefined;
10
+ theme?: Theme;
9
11
  };
10
12
  events: {
11
13
  navigate: CustomEvent<any>;
@@ -14,7 +16,7 @@ declare const __propDef: {
14
16
  };
15
17
  slots: {
16
18
  title: {};
17
- content: {};
19
+ default: {};
18
20
  };
19
21
  };
20
22
  export type LayoutProps = typeof __propDef.props;
@@ -1,12 +1,3 @@
1
- <script>import { initParams, initCurrent, initDefaults, initControls, initControlsState } from "./context";
2
- import { inRoot } from "../context";
3
- initParams();
4
- initCurrent();
5
- initDefaults();
6
- initControls();
7
- initControlsState();
8
- const r = inRoot();
9
- </script>
10
1
  <style>
11
2
  div {
12
3
  display: flex;
@@ -26,10 +17,33 @@ const r = inRoot();
26
17
  box-sizing: border-box;
27
18
  font-family: "Fira Code", "Courier New", Courier, monospace;
28
19
  }
29
- </style>
30
20
 
21
+ /* colors */
22
+ div {
23
+ color-scheme: light;
24
+ color: hsl(0, 100%, 0%);
25
+ }
26
+
27
+ div.dark {
28
+ color-scheme: dark;
29
+ color: hsl(200, 6%, 80%);
30
+ }
31
+ </style>
31
32
 
32
- <div class:reset={r}>
33
+ <script>import { initParams, initCurrent, initDefaults, initControls, initControlsState } from "./context";
34
+ import { inRoot, getTheme, initTheme, evalTheme } from "../context";
35
+ initParams();
36
+ initCurrent();
37
+ initDefaults();
38
+ initControls();
39
+ initControlsState();
40
+ const r = inRoot();
41
+ export let theme = undefined;
42
+ const parentTheme = getTheme();
43
+ const isDark = initTheme();
44
+ $: $isDark = evalTheme(parentTheme ? $parentTheme : false, theme);
45
+ </script>
46
+ <div class:reset={r} class:dark={$isDark}>
33
47
  <slot />
34
48
  </div>
35
49
 
@@ -1,6 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type Theme } from "../context";
2
3
  declare const __propDef: {
3
- props: Record<string, never>;
4
+ props: {
5
+ theme?: Theme;
6
+ };
4
7
  events: {
5
8
  [evt: string]: CustomEvent<any>;
6
9
  };
@@ -21,12 +21,9 @@
21
21
  .content {
22
22
  min-height: 100px;
23
23
  border-radius: 5px 5px 5px 5px;
24
- border: rgb(100, 96, 96) solid 1px;
25
- background-color: rgb(33, 36, 37);
26
24
  }
27
25
 
28
26
  .misc {
29
- outline: rgb(100, 96, 96) solid 1px;
30
27
  border-bottom-left-radius: 5px;
31
28
  border-bottom-right-radius: 5px;
32
29
  user-select: none;
@@ -46,12 +43,32 @@
46
43
  .scrollable::-webkit-scrollbar {
47
44
  display: none;
48
45
  }
46
+
47
+ /* colors */
48
+ .content {
49
+ border: hsl(0, 2%, 60%) solid 1px;
50
+ background-color: hsl(0, 0%, 100%);
51
+ }
52
+
53
+ .misc {
54
+ border: hsl(0, 2%, 60%) solid 1px;
55
+ }
56
+
57
+ .content.dark {
58
+ border: hsl(0, 2%, 40%) solid 1px;
59
+ background-color: hsl(200, 4%, 14%);
60
+ }
61
+
62
+ .misc.dark {
63
+ outline: hsl(0, 2%, 40%) solid 1px;
64
+ }
49
65
  </style>
50
66
  <svelte:window on:click={() => ($current = null)} />
51
67
 
52
68
  <script>import { getParams, getCurrent, getDefaults } from "./context";
53
69
  import { getControls, getControlsState } from "./context";
54
70
  import { resolve } from "./utils";
71
+ import { getTheme } from "../context";
55
72
  import Controls from "./controls/Controls.svelte";
56
73
  import { beforeUpdate } from "svelte";
57
74
  import { slide } from "svelte/transition";
@@ -60,6 +77,7 @@ const current = getCurrent();
60
77
  const controls = getControls();
61
78
  const controlsState = getControlsState();
62
79
  const defaultsStore = getDefaults();
80
+ const isDark = getTheme();
63
81
  export let defaults = undefined;
64
82
  export let noreset = false;
65
83
  export let columns = false;
@@ -94,7 +112,7 @@ const resolveArgs = (resolve);
94
112
  on:keypress={null}
95
113
  >
96
114
  {#if noreset}
97
- <div class="content scrollable">
115
+ <div class="content scrollable" class:dark={$isDark}>
98
116
  <slot
99
117
  id={param.id}
100
118
  tag={param.tag}
@@ -104,7 +122,7 @@ const resolveArgs = (resolve);
104
122
  </div>
105
123
  {:else}
106
124
  {#key key}
107
- <div class="content scrollable">
125
+ <div class="content scrollable" class:dark={$isDark}>
108
126
  <slot
109
127
  id={param.id}
110
128
  tag={param.tag}
@@ -115,7 +133,7 @@ const resolveArgs = (resolve);
115
133
  {/key}
116
134
  {/if}
117
135
  {#if $controls.length > 0 && ($controlsState.expand || $current === param.id || hovered === param.id)}
118
- <div class="misc scrollable" transition:slide|local>
136
+ <div class="misc scrollable" class:dark={$isDark} transition:slide|local>
119
137
  <Controls infos={$controls} bind:values={param.values} />
120
138
  </div>
121
139
  {/if}
@@ -1,3 +1,6 @@
1
+ <script>import { getTheme } from "../../../context";
2
+ const isDark = getTheme();
3
+ </script>
1
4
  <style>
2
5
  div {
3
6
  width: 100%;
@@ -8,7 +11,9 @@
8
11
  box-sizing: border-box;
9
12
  }
10
13
 
11
- div :global(*) {
14
+ div :global(*),
15
+ div :global(*::before),
16
+ div :global(*::after) {
12
17
  box-sizing: inherit;
13
18
  }
14
19
 
@@ -17,16 +22,6 @@
17
22
  display: grid;
18
23
  padding: 2px 0px;
19
24
  grid-template-columns: minmax(250px, 1fr) 200px 40px;
20
- background-color: hsl(205, 50%, 5%);
21
- }
22
-
23
- div > :global(div:nth-child(even)) {
24
- background-color: hsl(205, 15%, 15%);
25
- }
26
-
27
- div > :global(div:hover .tooltip),
28
- div > :global(div:nth-child(n + 2):hover) {
29
- background-color: hsl(203, 100%, 15%);
30
25
  }
31
26
 
32
27
  div > :global(div > div) {
@@ -38,9 +33,45 @@
38
33
  width: 100%;
39
34
  height: 100%;
40
35
  }
36
+
37
+ /* colors */
38
+ div > :global(div) {
39
+ background-color: hsl(0, 0%, 100%);
40
+ }
41
+
42
+ div > :global(div:nth-child(even)) {
43
+ background-color: hsl(210, 29%, 97%);
44
+ }
45
+
46
+ div > :global(div:nth-child(n + 2):hover) {
47
+ background-color: hsl(210, 100%, 90%);
48
+ }
49
+
50
+ div > :global(div:hover .tooltip) {
51
+ background-color: hsl(0, 0%, 100%);
52
+ outline: hsl(0, 100%, 0%) 1px solid;
53
+ }
54
+
55
+ div.dark > :global(div) {
56
+ background-color: hsl(213, 26%, 7%);
57
+ }
58
+
59
+ div.dark > :global(div:nth-child(even)) {
60
+ background-color: hsl(213, 26%, 11%);
61
+ }
62
+
63
+ div.dark > :global(div:nth-child(n + 2):hover) {
64
+ background-color: hsl(203, 100%, 15%);
65
+ }
66
+
67
+ div.dark > :global(div:hover .tooltip) {
68
+ background-color: hsl(213, 26%, 7%);
69
+ outline: hsl(200, 6%, 80%) 1px solid;
70
+ }
41
71
  </style>
42
72
 
43
- <div>
73
+
74
+ <div class:dark={$isDark}>
44
75
  <slot />
45
76
  </div>
46
77
 
@@ -1,22 +1,6 @@
1
- /** @typedef {typeof __propDef.props} StylerProps */
2
- /** @typedef {typeof __propDef.events} StylerEvents */
3
- /** @typedef {typeof __propDef.slots} StylerSlots */
4
- export default class Styler extends SvelteComponentTyped<{
5
- [x: string]: never;
6
- }, {
7
- [evt: string]: CustomEvent<any>;
8
- }, {
9
- default: {};
10
- }> {
11
- }
12
- export type StylerProps = typeof __propDef.props;
13
- export type StylerEvents = typeof __propDef.events;
14
- export type StylerSlots = typeof __propDef.slots;
15
1
  import { SvelteComponentTyped } from "svelte";
16
2
  declare const __propDef: {
17
- props: {
18
- [x: string]: never;
19
- };
3
+ props: Record<string, never>;
20
4
  events: {
21
5
  [evt: string]: CustomEvent<any>;
22
6
  };
@@ -24,4 +8,9 @@ declare const __propDef: {
24
8
  default: {};
25
9
  };
26
10
  };
11
+ export type StylerProps = typeof __propDef.props;
12
+ export type StylerEvents = typeof __propDef.events;
13
+ export type StylerSlots = typeof __propDef.slots;
14
+ export default class Styler extends SvelteComponentTyped<StylerProps, StylerEvents, StylerSlots> {
15
+ }
27
16
  export {};
@@ -1 +1,6 @@
1
+ import type { Writable } from "svelte/store";
1
2
  export declare function inRoot(): boolean;
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;
@@ -1,7 +1,18 @@
1
1
  import { setContext, getContext } from "svelte";
2
+ import { writable } from "svelte/store";
2
3
  const root = Symbol();
3
4
  export function inRoot() {
4
5
  const value = getContext(root);
5
6
  setContext(root, false);
6
7
  return value !== false;
7
8
  }
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
+ }
@@ -28,11 +28,6 @@
28
28
  overflow: visible;
29
29
  user-select: none;
30
30
  grid-area: divider;
31
- outline: rgb(100, 96, 96) solid 1px;
32
- }
33
-
34
- .container > .divider.moving {
35
- outline: rgb(255, 255, 255) solid 1px;
36
31
  }
37
32
 
38
33
  .container > .divider.vertical {
@@ -54,10 +49,29 @@
54
49
  cursor: col-resize;
55
50
  transform: translateX(-50%);
56
51
  }
52
+
53
+ /* colors */
54
+ .container > .divider {
55
+ outline: hsl(0, 2%, 70%) solid 1px;
56
+ }
57
+
58
+ .container > .divider.moving {
59
+ outline: hsl(0, 0%, 0%) solid 1px;
60
+ }
61
+
62
+ .container.dark > .divider {
63
+ outline: hsl(0, 2%, 38%) solid 1px;
64
+ }
65
+
66
+ .container.dark > .divider.moving {
67
+ outline: hsl(0, 0%, 100%) solid 1px;
68
+ }
57
69
  </style>
58
70
 
59
71
  <script>import { writable } from "svelte/store";
60
72
  import { createDraggable } from "./action";
73
+ import { getTheme } from "../context";
74
+ const isDark = getTheme();
61
75
  // orientation of the layout
62
76
  export let vertical = false;
63
77
  // initial value where the divider is located
@@ -86,6 +100,7 @@ const moving = writable(false);
86
100
  <div
87
101
  class="container"
88
102
  class:vertical
103
+ class:dark={$isDark}
89
104
  bind:clientHeight={height}
90
105
  bind:clientWidth={width}
91
106
  style:grid-template-columns={vertical ? style : null}
@@ -1,5 +1,27 @@
1
1
  import type { Tree, Sorter, Renamer } from "./types";
2
+ /**
3
+ * Compares two texts for sorting.
4
+ *
5
+ * If the texts follows `<I>-<Name>` format,
6
+ * sorting is done by comparing the numbers in the prefix.
7
+ *
8
+ * If only one of the texts follows `<I>-<Name>` format,
9
+ * the text that follows the format is considered as higher in order.
10
+ *
11
+ * Else comparison is done using built-in `string` comparison.
12
+ *
13
+ * @param {string} l
14
+ * @param {string} r
15
+ * @returns `-1 | 0 | +1`
16
+ */
2
17
  declare const sorter: Sorter;
18
+ /**
19
+ * If a text follows `<I>-<Name>` format,
20
+ * this method simply removes the Prefix.
21
+ *
22
+ * @param {string} text
23
+ * @returns `<Name>`
24
+ */
3
25
  declare const renamer: Renamer;
4
26
  export declare function sort(t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1): [string, Tree][];
5
27
  export { sorter, renamer };
@@ -8,6 +8,21 @@ function sorterT(l, r) {
8
8
  }
9
9
  return 0;
10
10
  }
11
+ /**
12
+ * Compares two texts for sorting.
13
+ *
14
+ * If the texts follows `<I>-<Name>` format,
15
+ * sorting is done by comparing the numbers in the prefix.
16
+ *
17
+ * If only one of the texts follows `<I>-<Name>` format,
18
+ * the text that follows the format is considered as higher in order.
19
+ *
20
+ * Else comparison is done using built-in `string` comparison.
21
+ *
22
+ * @param {string} l
23
+ * @param {string} r
24
+ * @returns `-1 | 0 | +1`
25
+ */
11
26
  const sorter = (l, r) => {
12
27
  const lmatch = match.exec(l);
13
28
  const rmatch = match.exec(r);
@@ -22,12 +37,19 @@ const sorter = (l, r) => {
22
37
  }
23
38
  return sorterT(parseInt(lmatch[1]), parseInt(rmatch[1]));
24
39
  };
25
- const renamer = (t) => {
26
- const m = match.exec(t);
40
+ /**
41
+ * If a text follows `<I>-<Name>` format,
42
+ * this method simply removes the Prefix.
43
+ *
44
+ * @param {string} text
45
+ * @returns `<Name>`
46
+ */
47
+ const renamer = (text) => {
48
+ const m = match.exec(text);
27
49
  if (m) {
28
50
  return m[2];
29
51
  }
30
- return t;
52
+ return text;
31
53
  };
32
54
  export function sort(t, order) {
33
55
  return Object.entries(t).sort(([l], [r]) => order(l, r));
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { routes } from "./components/routes";
2
1
  export { renamer, sorter } from "./components/navigation/utils";
3
2
  export type { Control } from "./components/block/controls/types";
4
3
  export { default as Layout } from "./components/Layout.svelte";
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export { routes } from "./components/routes";
2
1
  export { renamer, sorter } from "./components/navigation/utils";
3
2
  export { default as Layout } from "./components/Layout.svelte";
4
3
  export { default as Block } from "./components/block/Block.svelte";
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@nil-/doc",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "author": {
5
5
  "email": "njaldea@gmail.com",
6
6
  "name": "Neil Aldea"
7
7
  },
8
8
  "peerDependencies": {
9
- "svelte": "^3.54.0"
9
+ "svelte": "^3.55.0"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@sveltejs/adapter-vercel": "^1.0.0",
13
- "@sveltejs/kit": "^1.0.0",
14
- "@sveltejs/package": "^1.0.0",
13
+ "@sveltejs/kit": "^1.0.1",
14
+ "@sveltejs/package": "^1.0.1",
15
15
  "mdsvex": "^0.10.6",
16
16
  "svelte-check": "^2.10.2",
17
17
  "svelte-markdown": "^0.2.3",
18
18
  "svelte-preprocess": "^4.10.7",
19
19
  "tslib": "^2.4.1",
20
20
  "typescript": "^4.9.4",
21
- "vite": "^4.0.0"
21
+ "vite": "^4.0.1"
22
22
  },
23
23
  "type": "module",
24
24
  "publishConfig": {
@@ -32,7 +32,8 @@
32
32
  "license": "ISC",
33
33
  "exports": {
34
34
  "./package.json": "./package.json",
35
- ".": "./index.js"
35
+ ".": "./index.js",
36
+ "./sveltekit": "./sveltekit/index.js"
36
37
  },
37
38
  "svelte": "./index.js"
38
39
  }
@@ -0,0 +1,22 @@
1
+ import { type Readable } from "svelte/store";
2
+ type Routes = {
3
+ /**
4
+ * Routes
5
+ */
6
+ data: string[];
7
+ /**
8
+ * Removes unneeded group layout in the route
9
+ * @param {string} route
10
+ * @returns
11
+ */
12
+ current: Readable<string | null>;
13
+ navigate: (e: CustomEvent<string>) => void;
14
+ };
15
+ /**
16
+ * Dedicated helper method to be used for sveltekit
17
+ * @param detail - vite's `import.meta.glob(..., { eager: true })`
18
+ * @param prefix - only use when layout is not in the root route
19
+ * @returns Routes
20
+ */
21
+ export declare function sveltekit(detail: Record<string, unknown>, prefix?: string | null): Routes;
22
+ export {};
@@ -0,0 +1,47 @@
1
+ import { derived } from "svelte/store";
2
+ import { page } from "$app/stores";
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
+ }
9
+ 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
+ }
19
+ const route_rest_match = /.*\[.*\].*/;
20
+ function isRouteDynamic(p) {
21
+ return route_rest_match.exec(p) == null;
22
+ }
23
+ /**
24
+ * Dedicated helper method to be used for sveltekit
25
+ * @param detail - vite's `import.meta.glob(..., { eager: true })`
26
+ * @param prefix - only use when layout is not in the root route
27
+ * @returns Routes
28
+ */
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);
42
+ }
43
+ return null;
44
+ }),
45
+ navigate: prefix ? (e) => goto(`${prefix}${e.detail}`) : (e) => goto(e.detail)
46
+ };
47
+ }
@@ -1,6 +0,0 @@
1
- type Routes = {
2
- data: string[];
3
- process: (r: string | null) => string | null;
4
- };
5
- export declare function routes(files_from_import_meta: Record<string, unknown>): Routes;
6
- export {};
@@ -1,29 +0,0 @@
1
- const prefix = ".".length;
2
- const suffix = "/+page.svelte".length;
3
- function toRoute(p) {
4
- return p.substring(prefix, p.length - suffix);
5
- }
6
- const route_advanced_layout_match = /\(.*\)/;
7
- function collapseLayout(p) {
8
- return p
9
- .split("/")
10
- .filter((p) => route_advanced_layout_match.exec(p) == null)
11
- .join("/");
12
- }
13
- function isNotRoot(p) {
14
- return p !== "/";
15
- }
16
- const route_rest_match = /.*\[.*\].*/;
17
- function isRouteDynamic(p) {
18
- return route_rest_match.exec(p) == null;
19
- }
20
- export function routes(files_from_import_meta) {
21
- return {
22
- data: Object.keys(files_from_import_meta)
23
- .map(toRoute)
24
- .map(collapseLayout)
25
- .filter(isNotRoot)
26
- .filter(isRouteDynamic),
27
- process: (r) => (r ? collapseLayout(r) : null)
28
- };
29
- }