@nil-/doc 0.2.50 → 0.2.52

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 (64) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/components/Base.svelte +65 -0
  3. package/components/Base.svelte.d.ts +19 -0
  4. package/components/block/Block.svelte +71 -24
  5. package/components/block/Controls.svelte +3 -5
  6. package/components/block/Controls.svelte.d.ts +2 -2
  7. package/components/block/Instance.svelte +39 -89
  8. package/components/block/context.d.ts +2 -2
  9. package/components/block/context.js +2 -1
  10. package/components/block/controls/events/Events.svelte +14 -5
  11. package/components/block/controls/events/misc/Styler.svelte +16 -46
  12. package/components/block/controls/events/misc/Styler.svelte.d.ts +17 -6
  13. package/components/block/controls/props/Color.svelte +86 -0
  14. package/components/block/controls/props/Color.svelte.d.ts +21 -0
  15. package/components/block/controls/props/Component.svelte +5 -0
  16. package/components/block/controls/props/Number.svelte +4 -5
  17. package/components/block/controls/props/Object.svelte +9 -12
  18. package/components/block/controls/props/Props.svelte +2 -5
  19. package/components/block/controls/props/Range.svelte +5 -4
  20. package/components/block/controls/props/Select.svelte +5 -8
  21. package/components/block/controls/props/Switch.svelte +4 -5
  22. package/components/block/controls/props/Text.svelte +8 -9
  23. package/components/block/controls/props/Tuple.svelte +13 -26
  24. package/components/block/controls/props/misc/Name.svelte +6 -7
  25. package/components/block/controls/props/misc/Styler.svelte +22 -34
  26. package/components/block/controls/props/misc/Styler.svelte.d.ts +17 -6
  27. package/components/block/controls/props/misc/defaulter.d.ts +9 -8
  28. package/components/block/controls/props/misc/defaulter.js +28 -48
  29. package/components/block/controls/props/misc/utils.d.ts +12 -0
  30. package/components/block/controls/props/misc/utils.js +37 -0
  31. package/components/block/controls/types.d.ts +12 -2
  32. package/components/block/icons/Button.svelte +30 -0
  33. package/components/block/icons/Button.svelte.d.ts +35 -0
  34. package/components/block/icons/ControlView.svelte +30 -0
  35. package/components/block/icons/ControlView.svelte.d.ts +16 -0
  36. package/components/block/icons/Position.svelte +29 -0
  37. package/components/block/icons/Position.svelte.d.ts +16 -0
  38. package/components/{etc → layout}/Container.svelte +24 -37
  39. package/components/{etc → layout}/Container.svelte.d.ts +0 -0
  40. package/components/layout/Content.svelte +23 -0
  41. package/components/layout/Content.svelte.d.ts +27 -0
  42. package/components/layout/Layout.svelte +124 -0
  43. package/components/{Layout.svelte.d.ts → layout/Layout.svelte.d.ts} +3 -2
  44. package/components/layout/Scrollable.svelte +20 -0
  45. package/components/layout/Scrollable.svelte.d.ts +27 -0
  46. package/components/layout/VerticalPanel.svelte +12 -0
  47. package/components/layout/VerticalPanel.svelte.d.ts +27 -0
  48. package/components/{etc → layout}/action.d.ts +0 -0
  49. package/components/{etc → layout}/action.js +0 -0
  50. package/components/{title → layout/icons}/Icon.svelte +3 -3
  51. package/components/{title → layout/icons}/Icon.svelte.d.ts +0 -0
  52. package/components/{icons/NilDoc.svelte → layout/icons/Nil.svelte} +3 -3
  53. package/components/layout/icons/Nil.svelte.d.ts +14 -0
  54. package/components/{icons → layout/icons}/Theme.svelte +41 -28
  55. package/components/{icons → layout/icons}/Theme.svelte.d.ts +1 -1
  56. package/components/navigation/Nav.svelte +6 -10
  57. package/components/navigation/Node.svelte +19 -11
  58. package/index.d.ts +4 -4
  59. package/index.js +4 -4
  60. package/package.json +8 -5
  61. package/sveltekit/index.d.ts +7 -1
  62. package/sveltekit/index.js +9 -5
  63. package/components/Layout.svelte +0 -151
  64. package/components/icons/NilDoc.svelte.d.ts +0 -14
@@ -1,70 +1,50 @@
1
+ import { getType, getValues, getMin } from "./utils";
1
2
  // eslint-disable-next-line func-style
2
- export function getDefault(i) {
3
- if (i instanceof Array) {
4
- switch (i[1]) {
5
- case "object":
6
- // eslint-disable-next-line no-use-before-define
7
- return getObjectDefaults(i);
8
- case "tuple":
9
- // eslint-disable-next-line no-use-before-define
10
- return getTupleDefaults(i);
11
- case "text":
12
- return "";
13
- case "select":
14
- return i[2].length > 0 ? i[2][0] : "";
15
- case "number":
16
- return 0;
17
- case "range":
18
- return i[2];
19
- case "switch":
20
- default:
21
- return false;
22
- }
23
- }
24
- else {
25
- switch (i.type) {
26
- case "object":
27
- // eslint-disable-next-line no-use-before-define
28
- return getObjectDefaults(i);
29
- case "tuple":
30
- // eslint-disable-next-line no-use-before-define
31
- return getTupleDefaults(i);
32
- case "text":
33
- return "";
34
- case "select":
35
- return i.values.length > 0 ? i.values[0] : "";
36
- case "number":
37
- return 0;
38
- case "range":
39
- return i.min;
40
- case "switch":
41
- default:
42
- return false;
43
- }
3
+ export function defaulter(i) {
4
+ switch (getType(i)) {
5
+ case "object":
6
+ // eslint-disable-next-line no-use-before-define
7
+ return defaulterO(i);
8
+ case "tuple":
9
+ // eslint-disable-next-line no-use-before-define
10
+ return defaulterT(i);
11
+ case "text":
12
+ return "";
13
+ case "color":
14
+ return "#ffffffff";
15
+ case "select":
16
+ return getValues(i)[0] ?? "";
17
+ case "number":
18
+ return 0;
19
+ case "range":
20
+ return getMin(i);
21
+ case "switch":
22
+ default:
23
+ return false;
44
24
  }
45
25
  }
46
- const getObjectDefaults = (info) => {
26
+ const defaulterO = (info) => {
47
27
  const ret = {};
48
28
  const values = info instanceof Array ? info[2] : info.values;
49
29
  for (const v of values) {
50
30
  if (v instanceof Array) {
51
- ret[v[0]] = getDefault(v);
31
+ ret[v[0]] = defaulter(v);
52
32
  }
53
33
  else {
54
- ret[v.name] = getDefault(v);
34
+ ret[v.name] = defaulter(v);
55
35
  }
56
36
  }
57
37
  return ret;
58
38
  };
59
- const getTupleDefaults = (info) => {
39
+ const defaulterT = (info) => {
60
40
  const ret = [];
61
41
  const values = info instanceof Array ? info[2] : info.values;
62
42
  for (const [i, v] of values.entries()) {
63
43
  if (v instanceof Array) {
64
- ret.push(getDefault([`${i}`, ...v]));
44
+ ret.push(defaulter([`${i}`, ...v]));
65
45
  }
66
46
  else {
67
- ret.push(getDefault({ name: `${i}`, ...v }));
47
+ ret.push(defaulter({ name: `${i}`, ...v }));
68
48
  }
69
49
  }
70
50
  return ret;
@@ -0,0 +1,12 @@
1
+ import type { Detailed, Unionized, PropType, Prop, NonNamedProp } from "../../types";
2
+ type TypesWithValue = "object" | "tuple" | "select";
3
+ type Values<T extends TypesWithValue> = Detailed<PropType<T>>["values"];
4
+ export declare function getValues(info: Unionized<PropType<"select">>): Values<"select">;
5
+ export declare function getValues(info: Unionized<PropType<"object">>): Values<"object">;
6
+ export declare function getValues(info: Unionized<PropType<"tuple">>): Values<"tuple">;
7
+ export declare const getMin: (info: Unionized<PropType<"range">>) => number;
8
+ export declare const getType: (info: Prop) => "number" | "object" | "select" | "text" | "switch" | "range" | "tuple" | "color";
9
+ export declare const getFormat: (info: Unionized<PropType<"color">>) => import("../../types").ColorFormat;
10
+ export declare const getName: (info: Prop) => string;
11
+ export declare const addName: (name: string, info: NonNamedProp) => Prop;
12
+ export {};
@@ -0,0 +1,37 @@
1
+ // eslint-disable-next-line func-style
2
+ export function getValues(info) {
3
+ if (info instanceof Array) {
4
+ return info[2];
5
+ }
6
+ return info.values;
7
+ }
8
+ export const getMin = (info) => {
9
+ if (info instanceof Array) {
10
+ return info[2];
11
+ }
12
+ return info.min;
13
+ };
14
+ export const getType = (info) => {
15
+ if (info instanceof Array) {
16
+ return info[1];
17
+ }
18
+ return info.type;
19
+ };
20
+ export const getFormat = (info) => {
21
+ if (info instanceof Array) {
22
+ return info[2];
23
+ }
24
+ return info.format;
25
+ };
26
+ export const getName = (info) => {
27
+ if (info instanceof Array) {
28
+ return info[0];
29
+ }
30
+ return info.name;
31
+ };
32
+ export const addName = (name, info) => {
33
+ if (info instanceof Array) {
34
+ return [name, ...info];
35
+ }
36
+ return { ...info, name };
37
+ };
@@ -1,4 +1,6 @@
1
- type Types = "text" | "number" | "select" | "range" | "switch" | "tuple" | "object";
1
+ type Types = "text" | "color" | "number" | "select" | "range" | "switch" | "tuple" | "object";
2
+
3
+ type ColorFormat = "hsl" | "hsla" | "rgb" | "rgba" | "hex" | "hexa";
2
4
 
3
5
  // prettier-ignore
4
6
  export type PropType<T extends Types> =
@@ -6,6 +8,10 @@ export type PropType<T extends Types> =
6
8
  [ name: string, type: T ],
7
9
  { name: string; type: T; }
8
10
  ]
11
+ : T extends "color" ? [
12
+ [ name: string, type: T, format: ColorFormat ],
13
+ { name: string; type: T; format: ColorFormat; }
14
+ ]
9
15
  : T extends "number" ? [
10
16
  [ name: string, type: T ],
11
17
  { name: string; type: T; }
@@ -44,6 +50,8 @@ export type Unionized<T extends PropTyoe> = T[number];
44
50
  export type Prop =
45
51
  | [ name: string, type: "text" ]
46
52
  | { name: string; type: "text"; }
53
+ | [ name: string, type: "color", format: ColorFormat ]
54
+ | { name: string; type: "color"; format: ColorFormat; }
47
55
  | [ name: string, type: "number" ]
48
56
  | { name: string; type: "number"; }
49
57
  | [ name: string, type: "switch" ]
@@ -60,9 +68,11 @@ export type Prop =
60
68
  | { name: string; type: "object"; values: Prop[]; };
61
69
 
62
70
  // prettier-ignore
63
- type NonNamedProp =
71
+ export type NonNamedProp =
64
72
  | [ type: "text" ]
65
73
  | { type: "text"; }
74
+ | [ type: "color", format: ColorFormat ]
75
+ | { type: "color"; format: ColorFormat; }
66
76
  | [ type: "number" ]
67
77
  | { type: "number"; }
68
78
  | [ type: "switch" ]
@@ -0,0 +1,30 @@
1
+ <script>
2
+ export let title = "";
3
+ export let scale = false;
4
+ </script>
5
+
6
+ <div on:click on:keypress {title} class:scale>
7
+ <slot />
8
+ </div>
9
+
10
+ <style>
11
+ div {
12
+ width: 100%;
13
+ height: 100%;
14
+ display: grid;
15
+ place-items: center;
16
+ transition: transform var(--i-nil-doc-transition-time);
17
+ }
18
+
19
+ div.scale:hover {
20
+ transform: scale(1.5);
21
+ }
22
+
23
+ div > :global(svg) {
24
+ width: 100%;
25
+ height: 100%;
26
+ stroke-width: 3;
27
+ stroke: currentColor;
28
+ fill: currentColor;
29
+ }
30
+ </style>
@@ -0,0 +1,35 @@
1
+ /** @typedef {typeof __propDef.props} ButtonProps */
2
+ /** @typedef {typeof __propDef.events} ButtonEvents */
3
+ /** @typedef {typeof __propDef.slots} ButtonSlots */
4
+ export default class Button extends SvelteComponentTyped<{
5
+ title?: string | undefined;
6
+ scale?: boolean | undefined;
7
+ }, {
8
+ click: MouseEvent;
9
+ keypress: KeyboardEvent;
10
+ } & {
11
+ [evt: string]: CustomEvent<any>;
12
+ }, {
13
+ default: {};
14
+ }> {
15
+ }
16
+ export type ButtonProps = typeof __propDef.props;
17
+ export type ButtonEvents = typeof __propDef.events;
18
+ export type ButtonSlots = typeof __propDef.slots;
19
+ import { SvelteComponentTyped } from "svelte";
20
+ declare const __propDef: {
21
+ props: {
22
+ title?: string | undefined;
23
+ scale?: boolean | undefined;
24
+ };
25
+ events: {
26
+ click: MouseEvent;
27
+ keypress: KeyboardEvent;
28
+ } & {
29
+ [evt: string]: CustomEvent<any>;
30
+ };
31
+ slots: {
32
+ default: {};
33
+ };
34
+ };
35
+ export {};
@@ -0,0 +1,30 @@
1
+ <script context="module"></script>
2
+
3
+ <script>export let mode = "prop";
4
+ </script>
5
+
6
+ <svg viewBox="-50 -50 100 100">
7
+ <rect width="60" height="60" x="-30" y="-30" fill="transparent" />
8
+ <rect
9
+ class:right={mode === "prop"}
10
+ class="mv"
11
+ height="40"
12
+ width="20"
13
+ y="-20"
14
+ rx="2"
15
+ ry="2"
16
+ fill="transparent"
17
+ />
18
+ <polygon transform="translate(5, 0)" points="-15,-2 1,-2, 1,-6 6,0 1,6 1,2 -15,2" />
19
+ </svg>
20
+
21
+ <style>
22
+ .mv {
23
+ transition: x var(--i-nil-doc-transition-time);
24
+ x: -20px;
25
+ }
26
+
27
+ .mv.right {
28
+ x: 0px;
29
+ }
30
+ </style>
@@ -0,0 +1,16 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ mode?: "prop" | "event" | undefined;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ };
11
+ export type ControlViewProps = typeof __propDef.props;
12
+ export type ControlViewEvents = typeof __propDef.events;
13
+ export type ControlViewSlots = typeof __propDef.slots;
14
+ export default class ControlView extends SvelteComponentTyped<ControlViewProps, ControlViewEvents, ControlViewSlots> {
15
+ }
16
+ export {};
@@ -0,0 +1,29 @@
1
+ <script>export let position = "hidden";
2
+ </script>
3
+
4
+ <svg viewBox="-50 -50 100 100">
5
+ <rect width="60" height="60" x="-30" y="-30" fill="transparent" />
6
+ <rect class:show={position === "bottom"} />
7
+ <rect class:show={position === "right"} transform="rotate(-90)" />
8
+ </svg>
9
+
10
+ <style>
11
+ svg {
12
+ stroke-width: 3;
13
+ fill: currentColor;
14
+ }
15
+
16
+ rect:not(:first-child) {
17
+ transition: height 350ms, x 350ms, y 350ms;
18
+ width: 60px;
19
+ height: 0px;
20
+ x: -30px;
21
+ y: 30px;
22
+ }
23
+
24
+ rect:not(:first-child).show {
25
+ height: 20px;
26
+ x: -30px;
27
+ y: 10px;
28
+ }
29
+ </style>
@@ -0,0 +1,16 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ position?: "bottom" | "right" | "hidden" | undefined;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ };
11
+ export type PositionProps = typeof __propDef.props;
12
+ export type PositionEvents = typeof __propDef.events;
13
+ export type PositionSlots = typeof __propDef.slots;
14
+ export default class Position extends SvelteComponentTyped<PositionProps, PositionEvents, PositionSlots> {
15
+ }
16
+ export {};
@@ -1,8 +1,6 @@
1
1
  <script>import { writable } from "svelte/store";
2
2
  import { tweened } from "svelte/motion";
3
3
  import { createDraggable } from "./action";
4
- import { getTheme } from "../context";
5
- const dark = getTheme();
6
4
  export let vertical = false;
7
5
  export let offset = 0;
8
6
  export let b = false;
@@ -18,16 +16,17 @@ const update = (limit, value) => {
18
16
  offset = Math.max(Math.min(value, span - limit), limit);
19
17
  };
20
18
  const off = tweened(offset, { duration: 50 });
19
+ const min = 4;
21
20
  let last = [];
22
21
  $:
23
- update(10, $position);
22
+ update(min, $position);
24
23
  $:
25
24
  $off = offset;
26
25
  $:
27
- style = !b ? `auto 5px ${$off}px` : `${$off}px 5px auto`;
26
+ style = !b ? `auto 0.2rem ${$off}px` : `${$off}px 0.2rem auto`;
28
27
  const moving = writable(false);
29
28
  const addLast = (v) => {
30
- if (v > 10) {
29
+ if (v > min) {
31
30
  if (last.length < 2) {
32
31
  last = [...last, v];
33
32
  } else {
@@ -36,18 +35,18 @@ const addLast = (v) => {
36
35
  }
37
36
  };
38
37
  const dbltap = () => {
39
- if ($off > 10) {
38
+ if ($off > min) {
40
39
  addLast(offset);
41
- offset = 10;
40
+ offset = min;
42
41
  } else if (last.length > 0) {
43
42
  offset = last.pop();
44
43
  }
45
44
  };
46
45
  const check = (v, flag, s) => {
47
46
  if (flag) {
48
- return v < s - 10;
47
+ return v < s - min;
49
48
  } else {
50
- return v > 10;
49
+ return v > min;
51
50
  }
52
51
  };
53
52
  </script>
@@ -56,7 +55,6 @@ const check = (v, flag, s) => {
56
55
  class="container"
57
56
  class:vertical
58
57
  class:b
59
- class:dark={$dark}
60
58
  class:moving={$moving}
61
59
  bind:clientWidth={width}
62
60
  bind:clientHeight={height}
@@ -72,6 +70,7 @@ const check = (v, flag, s) => {
72
70
  <div class="divider">
73
71
  <div
74
72
  class="overlay"
73
+ title={`Collapse ${vertical ? (b ? "left" : "right") : b ? "top" : "bottom"}`}
75
74
  use:draggable={{
76
75
  reset: () => offset,
77
76
  reversed: !b,
@@ -91,10 +90,6 @@ const check = (v, flag, s) => {
91
90
  </div>
92
91
 
93
92
  <style>
94
- div {
95
- box-sizing: border-box;
96
- }
97
-
98
93
  .container {
99
94
  width: 100%;
100
95
  height: 100%;
@@ -129,62 +124,54 @@ const check = (v, flag, s) => {
129
124
 
130
125
  .container > .divider > .overlay {
131
126
  width: 100%;
132
- height: 20px;
127
+ height: 1.5rem;
133
128
  cursor: ns-resize;
134
129
  transform: translateY(-50%);
135
130
  }
136
131
 
137
132
  .container.vertical > .divider > .overlay {
138
- width: 20px;
133
+ width: 1.5rem;
139
134
  height: 100%;
140
135
  cursor: ew-resize;
141
136
  transform: translateX(-50%);
142
137
  }
143
138
 
144
139
  /* colors */
145
- .container {
146
- --color-p: hsl(0, 2%, 70%);
147
- --color-s: hsl(0, 0%, 0%);
148
- }
149
-
150
- .container.dark {
151
- --color-p: hsl(0, 2%, 40%);
152
- --color-s: hsl(0, 0%, 100%);
153
- }
154
-
155
140
  .divider {
156
- transition: border-color 350ms, background-color 350ms;
141
+ transition: border-color var(--i-nil-doc-transition-time),
142
+ background-color var(--i-nil-doc-transition-time);
143
+ --width: 0.0625rem;
157
144
  }
158
145
 
159
146
  .container:not(.vertical) > .divider {
160
- border-bottom: var(--color-p) solid 2.5px;
161
- border-top: var(--color-p) solid 2.5px;
162
- background-color: var(--color-p);
147
+ border-bottom: var(--i-nil-doc-container-p) solid var(--width);
148
+ border-top: var(--i-nil-doc-container-p) solid var(--width);
149
+ background-color: var(--i-nil-doc-container-p);
163
150
  }
164
151
 
165
152
  .container.vertical > .divider {
166
- border-right: var(--color-p) solid 2.5px;
167
- border-left: var(--color-p) solid 2.5px;
168
- background-color: var(--color-p);
153
+ border-right: var(--i-nil-doc-container-p) solid var(--width);
154
+ border-left: var(--i-nil-doc-container-p) solid var(--width);
155
+ background-color: var(--i-nil-doc-container-p);
169
156
  }
170
157
 
171
158
  .container:not(.b):not(.vertical) > .divider:hover,
172
159
  .container.moving:not(.b):not(.vertical) > .divider {
173
- border-bottom: var(--color-s) solid 2.5px;
160
+ border-bottom: var(--i-nil-doc-container-s) solid var(--width);
174
161
  }
175
162
 
176
163
  .container.b:not(.vertical) > .divider:hover,
177
164
  .container.moving.b:not(.vertical) > .divider {
178
- border-top: var(--color-s) solid 2.5px;
165
+ border-top: var(--i-nil-doc-container-s) solid var(--width);
179
166
  }
180
167
 
181
168
  .container:not(.b).vertical > .divider:hover,
182
169
  .container.moving:not(.b).vertical > .divider {
183
- border-right: var(--color-s) solid 2.5px;
170
+ border-right: var(--i-nil-doc-container-s) solid var(--width);
184
171
  }
185
172
 
186
173
  .container.vertical.b > .divider:hover,
187
174
  .container.moving.vertical.b > .divider {
188
- border-left: var(--color-s) solid 2.5px;
175
+ border-left: var(--i-nil-doc-container-s) solid var(--width);
189
176
  }
190
177
  </style>
File without changes
@@ -0,0 +1,23 @@
1
+ <div>
2
+ <slot />
3
+ </div>
4
+
5
+ <style>
6
+ div {
7
+ display: flex;
8
+ box-sizing: border-box;
9
+ margin: 0.5rem;
10
+ padding: 0.5rem;
11
+ border-radius: 0.5rem;
12
+ width: min-content;
13
+ height: min-content;
14
+ min-width: calc(100% - 1rem);
15
+ min-height: calc(100% - 1rem);
16
+ }
17
+
18
+ /* color */
19
+ div {
20
+ border: solid 1px var(--i-nil-doc-content-outline-color);
21
+ box-shadow: 0 0 0.5rem 0 var(--i-nil-doc-content-outline-color);
22
+ }
23
+ </style>
@@ -0,0 +1,27 @@
1
+ /** @typedef {typeof __propDef.props} ContentProps */
2
+ /** @typedef {typeof __propDef.events} ContentEvents */
3
+ /** @typedef {typeof __propDef.slots} ContentSlots */
4
+ export default class Content extends SvelteComponentTyped<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {
9
+ default: {};
10
+ }> {
11
+ }
12
+ export type ContentProps = typeof __propDef.props;
13
+ export type ContentEvents = typeof __propDef.events;
14
+ export type ContentSlots = typeof __propDef.slots;
15
+ import { SvelteComponentTyped } from "svelte";
16
+ declare const __propDef: {
17
+ props: {
18
+ [x: string]: never;
19
+ };
20
+ events: {
21
+ [evt: string]: CustomEvent<any>;
22
+ };
23
+ slots: {
24
+ default: {};
25
+ };
26
+ };
27
+ export {};