@difizen/libro-common 0.0.2-alpha.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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/array.d.ts +368 -0
  4. package/es/array.d.ts.map +1 -0
  5. package/es/array.js +577 -0
  6. package/es/display-wrapper.d.ts +6 -0
  7. package/es/display-wrapper.d.ts.map +1 -0
  8. package/es/display-wrapper.js +12 -0
  9. package/es/index.d.ts +11 -0
  10. package/es/index.d.ts.map +1 -0
  11. package/es/index.js +10 -0
  12. package/es/iter.d.ts +147 -0
  13. package/es/iter.d.ts.map +1 -0
  14. package/es/iter.js +162 -0
  15. package/es/json.d.ts +126 -0
  16. package/es/json.d.ts.map +1 -0
  17. package/es/json.js +274 -0
  18. package/es/path.d.ts +97 -0
  19. package/es/path.d.ts.map +1 -0
  20. package/es/path.js +60 -0
  21. package/es/polling/index.d.ts +3 -0
  22. package/es/polling/index.d.ts.map +1 -0
  23. package/es/polling/index.js +2 -0
  24. package/es/polling/poll.d.ts +193 -0
  25. package/es/polling/poll.d.ts.map +1 -0
  26. package/es/polling/poll.js +501 -0
  27. package/es/polling/protocol.d.ts +120 -0
  28. package/es/polling/protocol.d.ts.map +1 -0
  29. package/es/polling/protocol.js +13 -0
  30. package/es/posix.d.ts +2 -0
  31. package/es/posix.d.ts.map +1 -0
  32. package/es/posix.js +71 -0
  33. package/es/protocol/cell-protocol.d.ts +181 -0
  34. package/es/protocol/cell-protocol.d.ts.map +1 -0
  35. package/es/protocol/cell-protocol.js +1 -0
  36. package/es/protocol/index.d.ts +4 -0
  37. package/es/protocol/index.d.ts.map +1 -0
  38. package/es/protocol/index.js +3 -0
  39. package/es/protocol/notebook-protocol.d.ts +63 -0
  40. package/es/protocol/notebook-protocol.d.ts.map +1 -0
  41. package/es/protocol/notebook-protocol.js +41 -0
  42. package/es/protocol/output-protocol.d.ts +125 -0
  43. package/es/protocol/output-protocol.d.ts.map +1 -0
  44. package/es/protocol/output-protocol.js +1 -0
  45. package/es/sanitizer.d.ts +44 -0
  46. package/es/sanitizer.d.ts.map +1 -0
  47. package/es/sanitizer.js +659 -0
  48. package/es/url.d.ts +98 -0
  49. package/es/url.d.ts.map +1 -0
  50. package/es/url.js +134 -0
  51. package/es/utils.d.ts +57 -0
  52. package/es/utils.d.ts.map +1 -0
  53. package/es/utils.js +124 -0
  54. package/package.json +62 -0
  55. package/src/array.ts +608 -0
  56. package/src/display-wrapper.tsx +11 -0
  57. package/src/index.ts +10 -0
  58. package/src/iter.ts +199 -0
  59. package/src/json.ts +321 -0
  60. package/src/path.ts +138 -0
  61. package/src/polling/index.ts +2 -0
  62. package/src/polling/poll.ts +508 -0
  63. package/src/polling/protocol.ts +145 -0
  64. package/src/posix.ts +75 -0
  65. package/src/protocol/cell-protocol.ts +215 -0
  66. package/src/protocol/index.ts +3 -0
  67. package/src/protocol/notebook-protocol.ts +73 -0
  68. package/src/protocol/output-protocol.ts +162 -0
  69. package/src/sanitizer.ts +944 -0
  70. package/src/url.ts +157 -0
  71. package/src/utils.ts +145 -0
package/src/posix.ts ADDED
@@ -0,0 +1,75 @@
1
+ const isString = function (x: any) {
2
+ return typeof x === 'string';
3
+ };
4
+
5
+ // resolves . and .. elements in a path array with directory names there
6
+ // must be no slashes or device names (c:\) in the array
7
+ // (so also no leading and trailing slashes - it does not distinguish
8
+ // relative and absolute paths)
9
+ function normalizeArray(parts: string[], allowAboveRoot: boolean) {
10
+ const res = [];
11
+ for (let i = 0; i < parts.length; i++) {
12
+ const p = parts[i];
13
+
14
+ // ignore empty parts
15
+ if (!p || p === '.') {
16
+ continue;
17
+ }
18
+
19
+ if (p === '..') {
20
+ if (res.length && res[res.length - 1] !== '..') {
21
+ res.pop();
22
+ } else if (allowAboveRoot) {
23
+ res.push('..');
24
+ }
25
+ } else {
26
+ res.push(p);
27
+ }
28
+ }
29
+
30
+ return res;
31
+ }
32
+
33
+ // posix version
34
+ const isAbsolute = function (path: string) {
35
+ return path.charAt(0) === '/';
36
+ };
37
+
38
+ // path.normalize(path)
39
+ // posix version
40
+ const normalize = function (source: string) {
41
+ let path = source;
42
+ const isAbs = isAbsolute(path),
43
+ trailingSlash = path.substr(-1) === '/';
44
+
45
+ // Normalize the path
46
+ path = normalizeArray(path.split('/'), !isAbs).join('/');
47
+
48
+ if (!path && !isAbs) {
49
+ path = '.';
50
+ }
51
+ if (path && trailingSlash) {
52
+ path += '/';
53
+ }
54
+
55
+ return (isAbs ? '/' : '') + path;
56
+ };
57
+
58
+ // posix version
59
+ export const join = function (...args: string[]) {
60
+ let path = '';
61
+ for (let i = 0; i < args.length; i++) {
62
+ const segment = args[i];
63
+ if (!isString(segment)) {
64
+ throw new TypeError('Arguments to path.join must be strings');
65
+ }
66
+ if (segment) {
67
+ if (!path) {
68
+ path += segment;
69
+ } else {
70
+ path += '/' + segment;
71
+ }
72
+ }
73
+ }
74
+ return normalize(path);
75
+ };
@@ -0,0 +1,215 @@
1
+ import type { PartialJSONObject } from '../json.js';
2
+
3
+ import type {
4
+ ExecutionCount,
5
+ IAttachments,
6
+ MultilineString,
7
+ } from './notebook-protocol.js';
8
+ import type { IOutput } from './output-protocol.js';
9
+
10
+ /**
11
+ * A type which describes the type of cell.
12
+ */
13
+ export type CellType = 'code' | 'markdown' | 'raw' | string;
14
+
15
+ /**
16
+ * The Jupyter metadata namespace.
17
+ */
18
+ export interface IBaseCellJupyterMetadata extends PartialJSONObject {
19
+ /**
20
+ * Whether the source is hidden.
21
+ */
22
+ source_hidden: boolean;
23
+ }
24
+
25
+ /**
26
+ * Cell-level metadata.
27
+ */
28
+ export interface IBaseCellMetadata extends PartialJSONObject {
29
+ /**
30
+ * Whether the cell is trusted.
31
+ *
32
+ * #### Notes
33
+ * This is not strictly part of the nbformat spec, but it is added by
34
+ * the contents manager.
35
+ *
36
+ * See https://jupyter-server.readthedocs.io/en/latest/operators/security.html.
37
+ */
38
+ trusted: boolean;
39
+
40
+ /**
41
+ * The cell's name. If present, must be a non-empty string.
42
+ */
43
+ name: string;
44
+
45
+ /**
46
+ * The Jupyter metadata namespace
47
+ */
48
+ jupyter: Partial<IBaseCellJupyterMetadata>;
49
+
50
+ /**
51
+ * The cell's tags. Tags must be unique, and must not contain commas.
52
+ */
53
+ tags: string[];
54
+ }
55
+
56
+ /**
57
+ * The base cell interface.
58
+ */
59
+ export interface IBaseCell extends PartialJSONObject {
60
+ /**
61
+ * String identifying the type of cell.
62
+ */
63
+ cell_type: string;
64
+
65
+ /**
66
+ * Contents of the cell, represented as an array of lines.
67
+ */
68
+ source: MultilineString;
69
+
70
+ /**
71
+ * Cell-level metadata.
72
+ */
73
+ metadata: Partial<ICellMetadata>;
74
+ }
75
+
76
+ /**
77
+ * Metadata for the raw cell.
78
+ */
79
+ export interface IRawCellMetadata extends IBaseCellMetadata {
80
+ /**
81
+ * Raw cell metadata format for nbconvert.
82
+ */
83
+ format: string;
84
+ }
85
+
86
+ /**
87
+ * A raw cell.
88
+ */
89
+ export interface IRawCell extends IBaseCell {
90
+ /**
91
+ * A string field representing the identifier of this particular cell.
92
+ *
93
+ * Notebook format 4.4 requires no id field, but format 4.5 requires an id
94
+ * field. We need to handle both cases, so we make id optional here.
95
+ */
96
+ id?: string | undefined;
97
+
98
+ /**
99
+ * String identifying the type of cell.
100
+ */
101
+ cell_type: 'raw';
102
+
103
+ /**
104
+ * Cell-level metadata.
105
+ */
106
+ metadata: Partial<IRawCellMetadata>;
107
+
108
+ /**
109
+ * Cell attachments.
110
+ */
111
+ attachments?: IAttachments | undefined;
112
+ }
113
+
114
+ /**
115
+ * A markdown cell.
116
+ */
117
+ export interface IMarkdownCell extends IBaseCell {
118
+ /**
119
+ * A string field representing the identifier of this particular cell.
120
+ *
121
+ * Notebook format 4.4 requires no id field, but format 4.5 requires an id
122
+ * field. We need to handle both cases, so we make id optional here.
123
+ */
124
+ id?: string | undefined;
125
+
126
+ /**
127
+ * String identifying the type of cell.
128
+ */
129
+ cell_type: 'markdown';
130
+
131
+ /**
132
+ * Cell attachments.
133
+ */
134
+ attachments?: IAttachments | undefined;
135
+ }
136
+
137
+ /**
138
+ * The Jupyter metadata namespace for code cells.
139
+ */
140
+ export interface ICodeCellJupyterMetadata extends IBaseCellJupyterMetadata {
141
+ /**
142
+ * Whether the outputs are hidden. See https://github.com/jupyter/nbformat/issues/137.
143
+ */
144
+ outputs_hidden: boolean;
145
+ }
146
+
147
+ /**
148
+ * Metadata for a code cell.
149
+ */
150
+ export interface ICodeCellMetadata extends IBaseCellMetadata {
151
+ /**
152
+ * Whether the cell is collapsed/expanded.
153
+ */
154
+ collapsed: boolean;
155
+
156
+ /**
157
+ * The Jupyter metadata namespace
158
+ */
159
+ jupyter: Partial<ICodeCellJupyterMetadata>;
160
+
161
+ /**
162
+ * Whether the cell's output is scrolled, unscrolled, or autoscrolled.
163
+ */
164
+ scrolled: boolean | 'auto';
165
+ }
166
+
167
+ /**
168
+ * A code cell.
169
+ */
170
+ export interface ICodeCell extends IBaseCell {
171
+ /**
172
+ * A string field representing the identifier of this particular cell.
173
+ *
174
+ * Notebook format 4.4 requires no id field, but format 4.5 requires an id
175
+ * field. We need to handle both cases, so we make id optional here.
176
+ */
177
+ id?: string | undefined;
178
+
179
+ /**
180
+ * String identifying the type of cell.
181
+ * Changed in Libro: cell_type 不再限制只能是code,以便支持多种语言的cell
182
+ */
183
+ cell_type: string;
184
+ // cell_type: 'code';
185
+
186
+ /**
187
+ * Cell-level metadata.
188
+ */
189
+ metadata: Partial<ICodeCellMetadata>;
190
+
191
+ /**
192
+ * Execution, display, or stream outputs.
193
+ */
194
+ outputs: IOutput[];
195
+
196
+ /**
197
+ * The code cell's prompt number. Will be null if the cell has not been run.
198
+ */
199
+ execution_count: ExecutionCount;
200
+ }
201
+
202
+ /**
203
+ * An unrecognized cell.
204
+ */
205
+ export type IUnrecognizedCell = IBaseCell;
206
+
207
+ /**
208
+ * A cell union type.
209
+ */
210
+ export type ICell = IRawCell | IMarkdownCell | ICodeCell | IUnrecognizedCell;
211
+
212
+ /**
213
+ * A union metadata type.
214
+ */
215
+ export type ICellMetadata = IBaseCellMetadata | IRawCellMetadata | ICodeCellMetadata;
@@ -0,0 +1,3 @@
1
+ export * from './cell-protocol.js';
2
+ export * from './notebook-protocol.js';
3
+ export * from './output-protocol.js';
@@ -0,0 +1,73 @@
1
+ import type { PartialJSONObject } from '../json.js';
2
+
3
+ import type { ICell } from './cell-protocol.js';
4
+
5
+ /**
6
+ * The earliest major version of the notebook format we support.
7
+ */
8
+ export const MAJOR_VERSION = 4;
9
+
10
+ /**
11
+ * The earliest minor version of the notebook format we support.
12
+ */
13
+ export const MINOR_VERSION = 4;
14
+
15
+ /**
16
+ * The kernelspec metadata.
17
+ */
18
+ export interface IKernelspecMetadata extends PartialJSONObject {
19
+ name: string;
20
+ display_name: string;
21
+ }
22
+
23
+ /**
24
+ * The language info metadata
25
+ */
26
+ export interface ILanguageInfoMetadata extends PartialJSONObject {
27
+ name: string;
28
+ codemirror_mode?: string | PartialJSONObject;
29
+ file_extension?: string;
30
+ mimetype?: string;
31
+ pygments_lexer?: string;
32
+ }
33
+
34
+ /**
35
+ * The default metadata for the notebook.
36
+ */
37
+ export interface INotebookMetadata extends PartialJSONObject {
38
+ kernelspec?: IKernelspecMetadata;
39
+ language_info?: ILanguageInfoMetadata;
40
+ orig_nbformat?: number;
41
+ }
42
+
43
+ /**
44
+ * The notebook content.
45
+ */
46
+ export interface INotebookContent extends PartialJSONObject {
47
+ metadata: INotebookMetadata;
48
+ nbformat_minor: number;
49
+ nbformat: number;
50
+ cells: ICell[];
51
+ }
52
+
53
+ /**
54
+ * A multiline string.
55
+ */
56
+ export type MultilineString = string | string[];
57
+
58
+ /**
59
+ * A mime-type keyed dictionary of data.
60
+ */
61
+ export interface IMimeBundle extends PartialJSONObject {
62
+ [key: string]: MultilineString | PartialJSONObject;
63
+ }
64
+
65
+ /**
66
+ * Media attachments (e.g. inline images).
67
+ */
68
+ export type IAttachments = Record<string, IMimeBundle | undefined>;
69
+
70
+ /**
71
+ * The code cell's prompt number. Will be null if the cell has not been run.
72
+ */
73
+ export type ExecutionCount = number | null;
@@ -0,0 +1,162 @@
1
+ import type { PartialJSONObject } from '../json.js';
2
+
3
+ import type {
4
+ ExecutionCount,
5
+ IMimeBundle,
6
+ MultilineString,
7
+ } from './notebook-protocol.js';
8
+
9
+ /**
10
+ * Cell output metadata.
11
+ */
12
+ export type OutputMetadata = PartialJSONObject;
13
+
14
+ /**
15
+ * The valid output types.
16
+ */
17
+ export type OutputType =
18
+ | 'execute_result'
19
+ | 'display_data'
20
+ | 'stream'
21
+ | 'error'
22
+ | 'update_display_data';
23
+
24
+ /**
25
+ * The base output type.
26
+ */
27
+ export interface IBaseOutput extends PartialJSONObject {
28
+ /**
29
+ * Type of cell output.
30
+ */
31
+ output_type: string;
32
+ }
33
+
34
+ /**
35
+ * Result of executing a code cell.
36
+ */
37
+ export interface IExecuteResult extends IBaseOutput {
38
+ /**
39
+ * Type of cell output.
40
+ */
41
+ output_type: 'execute_result';
42
+
43
+ /**
44
+ * A result's prompt number.
45
+ */
46
+ execution_count: ExecutionCount;
47
+
48
+ /**
49
+ * A mime-type keyed dictionary of data.
50
+ */
51
+ data: IMimeBundle;
52
+
53
+ /**
54
+ * Cell output metadata.
55
+ */
56
+ metadata: OutputMetadata;
57
+ }
58
+
59
+ /**
60
+ * Data displayed as a result of code cell execution.
61
+ */
62
+ export interface IDisplayData extends IBaseOutput {
63
+ /**
64
+ * Type of cell output.
65
+ */
66
+ output_type: 'display_data';
67
+
68
+ /**
69
+ * A mime-type keyed dictionary of data.
70
+ */
71
+ data: IMimeBundle;
72
+
73
+ /**
74
+ * Cell output metadata.
75
+ */
76
+ metadata: OutputMetadata;
77
+ }
78
+
79
+ /**
80
+ * Data displayed as an update to existing display data.
81
+ */
82
+ export interface IDisplayUpdate extends IBaseOutput {
83
+ /**
84
+ * Type of cell output.
85
+ */
86
+ output_type: 'update_display_data';
87
+
88
+ /**
89
+ * A mime-type keyed dictionary of data.
90
+ */
91
+ data: IMimeBundle;
92
+
93
+ /**
94
+ * Cell output metadata.
95
+ */
96
+ metadata: OutputMetadata;
97
+ }
98
+
99
+ /**
100
+ * Stream output from a code cell.
101
+ */
102
+ export interface IStream extends IBaseOutput {
103
+ /**
104
+ * Type of cell output.
105
+ */
106
+ output_type: 'stream';
107
+
108
+ /**
109
+ * The name of the stream.
110
+ */
111
+ name: StreamType;
112
+
113
+ /**
114
+ * The stream's text output.
115
+ */
116
+ text: MultilineString;
117
+ }
118
+
119
+ /**
120
+ * An alias for a stream type.
121
+ */
122
+ export type StreamType = 'stdout' | 'stderr';
123
+
124
+ /**
125
+ * Output of an error that occurred during code cell execution.
126
+ */
127
+ export interface IError extends IBaseOutput {
128
+ /**
129
+ * Type of cell output.
130
+ */
131
+ output_type: 'error';
132
+
133
+ /**
134
+ * The name of the error.
135
+ */
136
+ ename: string;
137
+
138
+ /**
139
+ * The value, or message, of the error.
140
+ */
141
+ evalue: string;
142
+
143
+ /**
144
+ * The error's traceback.
145
+ */
146
+ traceback: string[];
147
+ }
148
+
149
+ /**
150
+ * Unrecognized output.
151
+ */
152
+ export type IUnrecognizedOutput = IBaseOutput;
153
+
154
+ /**
155
+ * An output union type.
156
+ */
157
+ export type IOutput =
158
+ | IUnrecognizedOutput
159
+ | IExecuteResult
160
+ | IDisplayData
161
+ | IStream
162
+ | IError;