@g9tm/lynxcontrols-code 0.0.0-stage → 2.10.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sources":["../../src/log/model.ts"],"sourcesContent":["// The plain-TS core of G9LogView (2.9.0, G9ProxyManager): a bounded store that takes thousands of lines a minute,\n// level filters, search hits, the time text and the copy text. No JSX, no Intl: Node and hosts load it at\n// `@g9tm/lynxcontrols-code/log-core`.\n\n/** The six levels, least to most severe. */\nexport type G9LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';\n\n/** Every level in order. */\nexport const g9LogLevels: readonly G9LogLevel[] = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];\n\n/** A line the app appends. `time`: ms since the epoch (a `Date` works too). */\nexport interface G9LogInput {\n readonly time: number | Date;\n readonly level: G9LogLevel;\n readonly category?: string;\n readonly message: string;\n}\n\n/** A stored line: the input with its sequence number (unique and rising for the store's life; the row's key). */\nexport interface G9LogEntry {\n readonly seq: number;\n readonly time: number;\n readonly level: G9LogLevel;\n readonly category: string;\n readonly message: string;\n}\n\n/**\n * What a store change was: the lines added at the end that it keeps, how many older lines the cap dropped from the\n * start, or a clear.\n */\nexport interface G9LogChange {\n readonly added: readonly G9LogEntry[];\n readonly dropped: number;\n readonly cleared: boolean;\n}\n\n/** The severity rank of a level (trace 0 … fatal 5); an unknown level counts as info. */\nexport function logLevelRank(level: string): number {\n const i = g9LogLevels.indexOf(level as G9LogLevel);\n return i < 0 ? 2 : i;\n}\n\n/**\n * A bounded, append-only log: the newest `capacity` lines (default 50 000), the oldest dropped. `append` costs only\n * the new lines; listeners hear each change at once (a view coalesces them).\n */\nexport class G9LogStore {\n private items: G9LogEntry[] = [];\n private start = 0;\n private nextSeq = 1;\n private readonly listeners = new Set<(change: G9LogChange) => void>();\n readonly capacity: number;\n\n constructor(options: { readonly capacity?: number } = {}) {\n this.capacity = Math.max(1, Math.floor(options.capacity ?? 50_000));\n }\n\n /** How many lines it holds. */\n get size(): number {\n return this.items.length - this.start;\n }\n\n /** The line at an index (0: the oldest kept). */\n at(index: number): G9LogEntry | undefined {\n return index < 0 || index >= this.size ? undefined : this.items[this.start + index];\n }\n\n /** The kept lines, oldest first (a copy). */\n entries(): G9LogEntry[] {\n return this.items.slice(this.start);\n }\n\n /** Adds one line or many at the end; answers the stored lines. */\n append(input: G9LogInput | readonly G9LogInput[]): G9LogEntry[] {\n const list: readonly G9LogInput[] = Array.isArray(input) ? input : [input as G9LogInput];\n if (list.length === 0) return [];\n const added: G9LogEntry[] = list.map((l) => ({\n seq: this.nextSeq++,\n time: l.time instanceof Date ? l.time.getTime() : l.time,\n level: l.level,\n category: l.category ?? '',\n message: l.message,\n }));\n const before = this.size;\n for (const e of added) this.items.push(e);\n const over = this.size - this.capacity;\n if (over > 0) {\n this.start += over;\n // compact now and then, not per line\n if (this.start >= this.capacity) {\n this.items = this.items.slice(this.start);\n this.start = 0;\n }\n }\n const kept = over > 0 ? added.slice(Math.max(0, added.length - this.capacity)) : added;\n const dropped = over > 0 ? Math.min(before, over) : 0;\n this.emit({ added: kept, dropped, cleared: false });\n return added;\n }\n\n /** Removes every line (sequence numbers keep rising). */\n clear(): void {\n this.items = [];\n this.start = 0;\n this.emit({ added: [], dropped: 0, cleared: true });\n }\n\n /** Hears every change; answers the unsubscribe. */\n subscribe(listener: (change: G9LogChange) => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n private emit(change: G9LogChange): void {\n for (const l of [...this.listeners]) l(change);\n }\n}\n\n/** What a view shows: the levels on (all when omitted) and a search (case-insensitive, in category and message). */\nexport interface G9LogFilter {\n readonly levels?: ReadonlySet<G9LogLevel> | readonly G9LogLevel[];\n readonly query?: string;\n}\n\n/** A filter as one fast test. */\nexport function logFilterTest(filter: G9LogFilter): (entry: G9LogEntry) => boolean {\n const lv = filter.levels;\n const levels: ReadonlySet<G9LogLevel> | null =\n lv === undefined ? null : lv instanceof Set ? lv : new Set(lv as readonly G9LogLevel[]);\n const q = (filter.query ?? '').trim().toLowerCase();\n if (!levels && !q) return () => true;\n return (e) =>\n (!levels || levels.has(e.level)) &&\n (!q || e.message.toLowerCase().includes(q) || e.category.toLowerCase().includes(q));\n}\n\n/** The lines a filter keeps, oldest first. */\nexport function filterLog(entries: readonly G9LogEntry[], filter: G9LogFilter): G9LogEntry[] {\n return entries.filter(logFilterTest(filter));\n}\n\n/** Where a search hits a text (case-insensitive, not overlapping): [start, end) pairs. */\nexport function logHighlights(text: string, query: string): Array<readonly [number, number]> {\n const q = query.trim().toLowerCase();\n if (!q) return [];\n const t = text.toLowerCase();\n const out: Array<readonly [number, number]> = [];\n let i = t.indexOf(q);\n while (i >= 0) {\n out.push([i, i + q.length]);\n i = t.indexOf(q, i + q.length);\n }\n return out;\n}\n\n/** A text cut into plain and hit runs by {@link logHighlights}. */\nexport function logRuns(text: string, query: string): Array<{ readonly text: string; readonly hit: boolean }> {\n const hits = logHighlights(text, query);\n if (hits.length === 0) return [{ text, hit: false }];\n const out: Array<{ text: string; hit: boolean }> = [];\n let at = 0;\n for (const [a, b] of hits) {\n if (a > at) out.push({ text: text.slice(at, a), hit: false });\n out.push({ text: text.slice(a, b), hit: true });\n at = b;\n }\n if (at < text.length) out.push({ text: text.slice(at), hit: false });\n return out;\n}\n\nconst pad = (v: number, n = 2) => String(v).padStart(n, '0');\n\n/** Options of {@link formatLogTime}. */\nexport interface G9LogTimeOptions {\n /** UTC instead of local time. */\n readonly utc?: boolean | undefined;\n /** `.mmm` after the seconds. Default true. */\n readonly millis?: boolean | undefined;\n /** `YYYY-MM-DD ` in front. */\n readonly date?: boolean | undefined;\n}\n\n/** A time as `HH:MM:SS.mmm` (24 h, ASCII digits — a log is read and pasted as code). */\nexport function formatLogTime(time: number, options: G9LogTimeOptions = {}): string {\n const d = new Date(time);\n if (Number.isNaN(d.getTime())) return '--:--:--';\n const u = options.utc === true;\n const h = u ? d.getUTCHours() : d.getHours();\n const m = u ? d.getUTCMinutes() : d.getMinutes();\n const s = u ? d.getUTCSeconds() : d.getSeconds();\n let out = `${pad(h)}:${pad(m)}:${pad(s)}`;\n if (options.millis !== false) out += `.${pad(u ? d.getUTCMilliseconds() : d.getMilliseconds(), 3)}`;\n if (options.date) {\n const y = u ? d.getUTCFullYear() : d.getFullYear();\n const mo = (u ? d.getUTCMonth() : d.getMonth()) + 1;\n const da = u ? d.getUTCDate() : d.getDate();\n out = `${y}-${pad(mo)}-${pad(da)} ${out}`;\n }\n return out;\n}\n\n/** One line as copied: `time LEVEL [category] message`. */\nexport function formatLogEntry(entry: G9LogEntry, options: Omit<G9LogTimeOptions, 'millis'> = {}): string {\n const cat = entry.category ? ` [${entry.category}]` : '';\n return `${formatLogTime(entry.time, { ...options, millis: true })} ${entry.level.toUpperCase().padEnd(5)}${cat} ${entry.message}`;\n}\n\n/** Lines as copied, one per line, oldest first. */\nexport function formatLogEntries(\n entries: readonly G9LogEntry[],\n options: Omit<G9LogTimeOptions, 'millis'> = {},\n): string {\n return [...entries]\n .sort((a, b) => a.seq - b.seq)\n .map((e) => formatLogEntry(e, options))\n .join('\\n');\n}\n\n/** The selection after a click on a line: alone, added / removed (`toggle`, Ctrl), or the range from `anchor` (Shift). */\nexport function nextLogSelection(\n selected: readonly number[],\n visible: readonly G9LogEntry[],\n seq: number,\n mode: 'single' | 'toggle' | 'range',\n anchor: number | null,\n): number[] {\n if (mode === 'toggle') return selected.includes(seq) ? selected.filter((s) => s !== seq) : [...selected, seq];\n if (mode === 'range' && anchor !== null) {\n const a = visible.findIndex((e) => e.seq === anchor);\n const b = visible.findIndex((e) => e.seq === seq);\n if (a >= 0 && b >= 0) return visible.slice(Math.min(a, b), Math.max(a, b) + 1).map((e) => e.seq);\n }\n return [seq];\n}\n"],"names":["g9LogLevels","logLevelRank","level","i","G9LogStore","index","undefined","input","list","Array","added","l","_l_category","Date","before","e","over","kept","Math","dropped","listener","change","options","_options_capacity","Set","logFilterTest","filter","_filter_query","lv","levels","q","filterLog","entries","logHighlights","text","query","t","out","logRuns","hits","at","a","b","pad","v","n","String","formatLogTime","time","d","Number","u","h","m","s","y","mo","da","formatLogEntry","entry","cat","formatLogEntries","nextLogSelection","selected","visible","seq","mode","anchor"],"mappings":"AAI0C;;;;;;;;;;AAInC,MAAMA,cAAqC;IAAC;IAAS;IAAS;IAAQ;IAAQ;IAAS;CAAQ;AA8B/F,SAASC,aAAaC,KAAa;IACxC,MAAMC,IAAIH,YAAY,OAAO,CAACE;IAC9B,OAAOC,IAAI,IAAI,IAAIA;AACrB;AAMO,MAAMC;IAYX,IAAI,OAAe;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK;IACvC;IAGA,GAAGC,KAAa,EAA0B;QACxC,OAAOA,QAAQ,KAAKA,SAAS,IAAI,CAAC,IAAI,GAAGC,SAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAGD,MAAM;IACrF;IAGA,UAAwB;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;IACpC;IAGA,OAAOE,KAAyC,EAAgB;QAC9D,MAAMC,OAA8BC,MAAM,OAAO,CAACF,SAASA,QAAQ;YAACA;SAAoB;QACxF,IAAIC,AAAgB,MAAhBA,KAAK,MAAM,EAAQ,OAAO,EAAE;QAChC,MAAME,QAAsBF,KAAK,GAAG,CAAC,CAACG;gBAI1BC;mBAJiC;gBAC3C,KAAK,IAAI,CAAC,OAAO;gBACjB,MAAMD,EAAE,IAAI,YAAYE,OAAOF,EAAE,IAAI,CAAC,OAAO,KAAKA,EAAE,IAAI;gBACxD,OAAOA,EAAE,KAAK;gBACd,UAAU,QAAAC,CAAAA,cAAAA,EAAE,QAAQ,AAAD,IAATA,cAAc;gBACxB,SAASD,EAAE,OAAO;YACpB;;QACA,MAAMG,SAAS,IAAI,CAAC,IAAI;QACxB,K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7C,MAAMzB,IAAIsB,QAAQ,SAAS,CAAC,CAACjD,IAAMA,EAAE,GAAG,KAAKkD;QAC7C,IAAIxB,KAAK,KAAKC,KAAK,GAAG,OAAOsB,QAAQ,KAAK,CAAC9C,KAAK,GAAG,CAACuB,GAAGC,IAAIxB,KAAK,GAAG,CAACuB,GAAGC,KAAK,GAAG,GAAG,CAAC,CAAC3B,IAAMA,EAAE,GAAG;IACjG;IACA,OAAO;QAACkD;KAAI;AACd"}
@@ -0,0 +1,194 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) Object.defineProperty(obj, key, {
3
+ value: value,
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true
7
+ });
8
+ else obj[key] = value;
9
+ return obj;
10
+ }
11
+ const g9LogLevels = [
12
+ 'trace',
13
+ 'debug',
14
+ 'info',
15
+ 'warn',
16
+ 'error',
17
+ 'fatal'
18
+ ];
19
+ function logLevelRank(level) {
20
+ const i = g9LogLevels.indexOf(level);
21
+ return i < 0 ? 2 : i;
22
+ }
23
+ class G9LogStore {
24
+ get size() {
25
+ return this.items.length - this.start;
26
+ }
27
+ at(index) {
28
+ return index < 0 || index >= this.size ? void 0 : this.items[this.start + index];
29
+ }
30
+ entries() {
31
+ return this.items.slice(this.start);
32
+ }
33
+ append(input) {
34
+ const list = Array.isArray(input) ? input : [
35
+ input
36
+ ];
37
+ if (0 === list.length) return [];
38
+ const added = list.map((l)=>{
39
+ var _l_category;
40
+ return {
41
+ seq: this.nextSeq++,
42
+ time: l.time instanceof Date ? l.time.getTime() : l.time,
43
+ level: l.level,
44
+ category: null != (_l_category = l.category) ? _l_category : '',
45
+ message: l.message
46
+ };
47
+ });
48
+ const before = this.size;
49
+ for (const e of added)this.items.push(e);
50
+ const over = this.size - this.capacity;
51
+ if (over > 0) {
52
+ this.start += over;
53
+ if (this.start >= this.capacity) {
54
+ this.items = this.items.slice(this.start);
55
+ this.start = 0;
56
+ }
57
+ }
58
+ const kept = over > 0 ? added.slice(Math.max(0, added.length - this.capacity)) : added;
59
+ const dropped = over > 0 ? Math.min(before, over) : 0;
60
+ this.emit({
61
+ added: kept,
62
+ dropped,
63
+ cleared: false
64
+ });
65
+ return added;
66
+ }
67
+ clear() {
68
+ this.items = [];
69
+ this.start = 0;
70
+ this.emit({
71
+ added: [],
72
+ dropped: 0,
73
+ cleared: true
74
+ });
75
+ }
76
+ subscribe(listener) {
77
+ this.listeners.add(listener);
78
+ return ()=>{
79
+ this.listeners.delete(listener);
80
+ };
81
+ }
82
+ emit(change) {
83
+ for (const l of [
84
+ ...this.listeners
85
+ ])l(change);
86
+ }
87
+ constructor(options = {}){
88
+ var _options_capacity;
89
+ _define_property(this, "items", []);
90
+ _define_property(this, "start", 0);
91
+ _define_property(this, "nextSeq", 1);
92
+ _define_property(this, "listeners", new Set());
93
+ _define_property(this, "capacity", void 0);
94
+ this.capacity = Math.max(1, Math.floor(null != (_options_capacity = options.capacity) ? _options_capacity : 50000));
95
+ }
96
+ }
97
+ function logFilterTest(filter) {
98
+ var _filter_query;
99
+ const lv = filter.levels;
100
+ const levels = void 0 === lv ? null : lv instanceof Set ? lv : new Set(lv);
101
+ const q = (null != (_filter_query = filter.query) ? _filter_query : '').trim().toLowerCase();
102
+ if (!levels && !q) return ()=>true;
103
+ return (e)=>(!levels || levels.has(e.level)) && (!q || e.message.toLowerCase().includes(q) || e.category.toLowerCase().includes(q));
104
+ }
105
+ function filterLog(entries, filter) {
106
+ return entries.filter(logFilterTest(filter));
107
+ }
108
+ function logHighlights(text, query) {
109
+ const q = query.trim().toLowerCase();
110
+ if (!q) return [];
111
+ const t = text.toLowerCase();
112
+ const out = [];
113
+ let i = t.indexOf(q);
114
+ while(i >= 0){
115
+ out.push([
116
+ i,
117
+ i + q.length
118
+ ]);
119
+ i = t.indexOf(q, i + q.length);
120
+ }
121
+ return out;
122
+ }
123
+ function logRuns(text, query) {
124
+ const hits = logHighlights(text, query);
125
+ if (0 === hits.length) return [
126
+ {
127
+ text,
128
+ hit: false
129
+ }
130
+ ];
131
+ const out = [];
132
+ let at = 0;
133
+ for (const [a, b] of hits){
134
+ if (a > at) out.push({
135
+ text: text.slice(at, a),
136
+ hit: false
137
+ });
138
+ out.push({
139
+ text: text.slice(a, b),
140
+ hit: true
141
+ });
142
+ at = b;
143
+ }
144
+ if (at < text.length) out.push({
145
+ text: text.slice(at),
146
+ hit: false
147
+ });
148
+ return out;
149
+ }
150
+ const pad = (v, n = 2)=>String(v).padStart(n, '0');
151
+ function formatLogTime(time, options = {}) {
152
+ const d = new Date(time);
153
+ if (Number.isNaN(d.getTime())) return '--:--:--';
154
+ const u = true === options.utc;
155
+ const h = u ? d.getUTCHours() : d.getHours();
156
+ const m = u ? d.getUTCMinutes() : d.getMinutes();
157
+ const s = u ? d.getUTCSeconds() : d.getSeconds();
158
+ let out = `${pad(h)}:${pad(m)}:${pad(s)}`;
159
+ if (false !== options.millis) out += `.${pad(u ? d.getUTCMilliseconds() : d.getMilliseconds(), 3)}`;
160
+ if (options.date) {
161
+ const y = u ? d.getUTCFullYear() : d.getFullYear();
162
+ const mo = (u ? d.getUTCMonth() : d.getMonth()) + 1;
163
+ const da = u ? d.getUTCDate() : d.getDate();
164
+ out = `${y}-${pad(mo)}-${pad(da)} ${out}`;
165
+ }
166
+ return out;
167
+ }
168
+ function formatLogEntry(entry, options = {}) {
169
+ const cat = entry.category ? ` [${entry.category}]` : '';
170
+ return `${formatLogTime(entry.time, {
171
+ ...options,
172
+ millis: true
173
+ })} ${entry.level.toUpperCase().padEnd(5)}${cat} ${entry.message}`;
174
+ }
175
+ function formatLogEntries(entries, options = {}) {
176
+ return [
177
+ ...entries
178
+ ].sort((a, b)=>a.seq - b.seq).map((e)=>formatLogEntry(e, options)).join('\n');
179
+ }
180
+ function nextLogSelection(selected, visible, seq, mode, anchor) {
181
+ if ('toggle' === mode) return selected.includes(seq) ? selected.filter((s)=>s !== seq) : [
182
+ ...selected,
183
+ seq
184
+ ];
185
+ if ('range' === mode && null !== anchor) {
186
+ const a = visible.findIndex((e)=>e.seq === anchor);
187
+ const b = visible.findIndex((e)=>e.seq === seq);
188
+ if (a >= 0 && b >= 0) return visible.slice(Math.min(a, b), Math.max(a, b) + 1).map((e)=>e.seq);
189
+ }
190
+ return [
191
+ seq
192
+ ];
193
+ }
194
+ export { G9LogStore, filterLog, formatLogEntries, formatLogEntry, formatLogTime, g9LogLevels, logFilterTest, logHighlights, logLevelRank, logRuns, nextLogSelection };
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@g9tm/lynxcontrols-code",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.10.0",
4
+ "description": "G9CodeEditor and G9LogView for ReactLynx: an editable monospace text with line numbers, JSON colours, error marks, find, undo / redo and a read-only mode that types without lag on 1 MB (only the visible lines are drawn); a live, virtualised log that follows the end, pauses when scrolled up, filters by level and search and copies selected rows. Their plain-TS cores at /editor-core and /log-core.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": [
8
+ "**/*.css"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "source": "./src/index.ts",
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.jsx"
15
+ },
16
+ "./editor": {
17
+ "source": "./src/editor/index.ts",
18
+ "types": "./dist/editor/index.d.ts",
19
+ "default": "./dist/editor/index.jsx"
20
+ },
21
+ "./log": {
22
+ "source": "./src/log/index.ts",
23
+ "types": "./dist/log/index.d.ts",
24
+ "default": "./dist/log/index.jsx"
25
+ },
26
+ "./editor-core": {
27
+ "source": "./src/editor/model.ts",
28
+ "types": "./dist/editor/model.d.ts",
29
+ "default": "./dist/editor/model.js"
30
+ },
31
+ "./log-core": {
32
+ "source": "./src/log/model.ts",
33
+ "types": "./dist/log/model.d.ts",
34
+ "default": "./dist/log/model.js"
35
+ },
36
+ "./catalog": "./catalog/catalog.json"
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md",
41
+ "catalog"
42
+ ],
43
+ "scripts": {
44
+ "build": "rslib build"
45
+ },
46
+ "dependencies": {
47
+ "@g9tm/lynxcontrols-foundation": "2.10.0"
48
+ },
49
+ "peerDependencies": {
50
+ "@g9tm/lynxcontrols": "2.10.0",
51
+ "@lynx-js/react": ">=0.129.3 <0.130.0"
52
+ }
53
+ }