@super-one/cli 0.76.0-alpha.2 → 0.76.0-alpha.3

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 (3) hide show
  1. package/MANIFEST.json +2 -2
  2. package/lib/cli.mjs +2666 -99
  3. package/package.json +1 -1
package/lib/cli.mjs CHANGED
@@ -114,6 +114,11 @@ function nodePaths(nodeHome) {
114
114
  providerSecretsKey: join2(nodeHome, "secrets", "provider-secrets.key"),
115
115
  logsDir: join2(nodeHome, "logs"),
116
116
  runtimeJson: join2(nodeHome, "runtime.json"),
117
+ /**
118
+ * Touched by `harness enable` in another process. The running node watches
119
+ * this file and pushes `harness_catalog_changed` when the advertised set changes.
120
+ */
121
+ harnessCatalogStamp: join2(nodeHome, "harness-catalog.stamp"),
117
122
  /** Session sync zone root — mirrors the desktop's `<userData>/sync` layout. */
118
123
  syncRoot: join2(nodeHome, "sync")
119
124
  };
@@ -137,8 +142,8 @@ import { fileURLToPath } from "node:url";
137
142
  function resolveCliReleaseVersion() {
138
143
  const fromEnv = process.env.SUPERONE_CLI_VERSION?.trim();
139
144
  if (fromEnv) return fromEnv;
140
- if ("0.76.0-alpha.2".trim()) {
141
- return "0.76.0-alpha.2".trim();
145
+ if ("0.76.0-alpha.3".trim()) {
146
+ return "0.76.0-alpha.3".trim();
142
147
  }
143
148
  const fromDist = readDistManifestVersion();
144
149
  if (fromDist) return fromDist;
@@ -5114,9 +5119,14 @@ var init_rpc = __esm({
5114
5119
  });
5115
5120
 
5116
5121
  // ../../packages/shared/src/environment/events.ts
5122
+ function harnessAdvertisementKey(ids) {
5123
+ return [...ids ?? []].sort().join("\0");
5124
+ }
5125
+ var HARNESS_CATALOG_CHANGED;
5117
5126
  var init_events = __esm({
5118
5127
  "../../packages/shared/src/environment/events.ts"() {
5119
5128
  "use strict";
5129
+ HARNESS_CATALOG_CHANGED = "harness_catalog_changed";
5120
5130
  }
5121
5131
  });
5122
5132
 
@@ -11784,6 +11794,9 @@ var init_codex_async_question = __esm({
11784
11794
  });
11785
11795
 
11786
11796
  // ../../packages/shared/src/transcript-boundary.ts
11797
+ function contentKeyStamp(block) {
11798
+ return contentKeyStamps.get(block);
11799
+ }
11787
11800
  function contentKeys(content) {
11788
11801
  const counts = /* @__PURE__ */ new Map();
11789
11802
  return content.map((block) => {
@@ -11791,6 +11804,12 @@ function contentKeys(content) {
11791
11804
  for (const [kind2, count2] of Object.entries(block.fold.keyCounts ?? {})) counts.set(kind2, (counts.get(kind2) ?? 0) + count2);
11792
11805
  return block.fold.contentKey;
11793
11806
  }
11807
+ const stamped = contentKeyStamps.get(block);
11808
+ if (stamped) {
11809
+ const ordinal = /^(.*):(\d+)$/.exec(stamped.key);
11810
+ if (ordinal) counts.set(ordinal[1], Math.max(counts.get(ordinal[1]) ?? 0, Number(ordinal[2]) + 1));
11811
+ return stamped.key;
11812
+ }
11794
11813
  if (isToolUseBlock(block)) return `tool:${block.toolUseId}`;
11795
11814
  if (isToolResultBlock(block)) return `result:${block.toolUseId}`;
11796
11815
  const kind = contentKeyKind(block);
@@ -11845,23 +11864,54 @@ function boundaryCursor(boundary, source) {
11845
11864
  function expandBoundaryCursor(boundary, source) {
11846
11865
  if (!boundary.cursor) return boundary;
11847
11866
  const items = source.metadata?.codex?.items ?? [];
11867
+ const keys = contentKeys(source.content);
11868
+ const content = boundary.at !== void 0 && !keys.includes(boundary.at) ? coverBeforeCut(source.content, boundary.at) ?? {} : edgeMap(keys, source.content.map(blockText), boundary.at, boundary.offset ?? 0, source.content.map(contentKeyStamp));
11848
11869
  return {
11849
11870
  ...boundary,
11850
- content: edgeMap(contentKeys(source.content), source.content.map(blockText), boundary.at, boundary.offset ?? 0),
11871
+ content,
11851
11872
  items: edgeMap(items.map((item) => item.id), items.map(itemText), boundary.atItem, boundary.itemOffset ?? 0),
11852
11873
  cursor: false
11853
11874
  };
11854
11875
  }
11876
+ function boundaryInWindow(boundary, source) {
11877
+ const windowed = source.metadata?.window;
11878
+ if (!windowed || windowed.omittedBefore === 0 && windowed.omittedAfter === 0) return true;
11879
+ const keys = contentKeys(source.content);
11880
+ const folded = source.content.some((block) => block.type === "notice" && block.fold);
11881
+ if (!boundary.cursor) {
11882
+ if (windowed.omittedBefore === 0) return true;
11883
+ const named = Object.keys(boundary.content ?? {});
11884
+ if (!named.length) return false;
11885
+ return folded || named.some((key3) => keys.includes(key3));
11886
+ }
11887
+ const atMissing = boundary.at !== void 0 && !keys.includes(boundary.at);
11888
+ if (atMissing && coverBeforeCut(source.content, boundary.at) === null) return false;
11889
+ const items = source.metadata?.codex?.items ?? [];
11890
+ if (boundary.atItem !== void 0 && !items.some((item) => item.id === boundary.atItem) && (boundary.at === void 0 || atMissing)) return false;
11891
+ if (boundary.at !== void 0 && !atMissing && windowed.omittedBefore > 0) {
11892
+ const index = keys.indexOf(boundary.at);
11893
+ const start = contentKeyStamp(source.content[index])?.start ?? 0;
11894
+ if (index === 0 && (boundary.offset ?? 0) < start) return false;
11895
+ }
11896
+ return true;
11897
+ }
11855
11898
  function prefixEdge(map2, keys, texts) {
11899
+ const firstAt = /* @__PURE__ */ new Map();
11900
+ for (let index = 0; index < keys.length; index++) {
11901
+ const key3 = keys[index];
11902
+ if (!firstAt.has(key3)) firstAt.set(key3, index);
11903
+ }
11856
11904
  let partial2 = null;
11857
11905
  for (let index = 0; index < keys.length; index++) {
11906
+ if (firstAt.get(keys[index]) !== index) continue;
11858
11907
  const key3 = keys[index];
11859
11908
  const saved = map2[key3];
11860
11909
  const text3 = texts[index];
11861
11910
  if (saved === void 0) {
11862
11911
  const edge = partial2 ?? { key: key3, offset: 0 };
11863
- const edgeAt = partial2 ? keys.indexOf(partial2.key) : index;
11912
+ const edgeAt = partial2 ? firstAt.get(partial2.key) : index;
11864
11913
  for (let later = edgeAt + 1; later < keys.length; later++) {
11914
+ if (firstAt.get(keys[later]) !== later) continue;
11865
11915
  if (map2[keys[later]] !== void 0) return null;
11866
11916
  }
11867
11917
  return edge;
@@ -11875,7 +11925,63 @@ function prefixEdge(map2, keys, texts) {
11875
11925
  }
11876
11926
  return partial2 ?? "end";
11877
11927
  }
11878
- function edgeMap(keys, texts, at2, offset) {
11928
+ function coverBeforeCut(content, at2) {
11929
+ const parsed = /^(.*):(\d+)$/.exec(at2);
11930
+ if (!parsed) return null;
11931
+ const kind = parsed[1];
11932
+ const target2 = Number(parsed[2]);
11933
+ const keys = contentKeys(content);
11934
+ const counts = /* @__PURE__ */ new Map();
11935
+ const map2 = {};
11936
+ let pending3 = [];
11937
+ const flush = () => {
11938
+ for (const item of pending3) map2[item.key] = item.length;
11939
+ pending3 = [];
11940
+ };
11941
+ const placed = () => (counts.get(kind) ?? 0) === target2 && Object.keys(map2).length ? map2 : null;
11942
+ for (let index = 0; index < content.length; index++) {
11943
+ const block = content[index];
11944
+ const key3 = keys[index];
11945
+ if (block.type === "notice" && block.fold) {
11946
+ const running = counts.get(kind) ?? 0;
11947
+ const declared2 = /^(.*):(\d+)$/.exec(block.fold.contentKey);
11948
+ const start = declared2?.[1] === kind ? Number(declared2[2]) : running;
11949
+ const count = block.fold.keyCounts?.[kind] ?? 0;
11950
+ for (const [name, value] of Object.entries(block.fold.keyCounts ?? {})) {
11951
+ if (name === kind) continue;
11952
+ counts.set(name, (counts.get(name) ?? 0) + value);
11953
+ }
11954
+ if (count === 0) {
11955
+ if (key3) pending3.push({ key: key3, length: -1 });
11956
+ continue;
11957
+ }
11958
+ if (target2 < start || target2 < start + count) return target2 < start ? placed() : null;
11959
+ flush();
11960
+ if (key3) map2[key3] = -1;
11961
+ counts.set(kind, Math.max(running, start + count));
11962
+ if ((counts.get(kind) ?? 0) >= target2) return placed();
11963
+ continue;
11964
+ }
11965
+ const stamped = contentKeyStamp(block);
11966
+ const ordinal = stamped ? /^(.*):(\d+)$/.exec(stamped.key) : null;
11967
+ const blockKind = ordinal ? ordinal[1] : !stamped && !isToolUseBlock(block) && !isToolResultBlock(block) ? contentKeyKind(block) : null;
11968
+ const blockN = ordinal ? Number(ordinal[2]) : blockKind ? counts.get(blockKind) ?? 0 : null;
11969
+ if (blockKind !== null && blockN !== null) {
11970
+ if (blockKind === kind && blockN >= target2) return placed();
11971
+ counts.set(blockKind, Math.max(counts.get(blockKind) ?? 0, blockN + 1));
11972
+ if (blockKind === kind) {
11973
+ flush();
11974
+ const text4 = blockText(block);
11975
+ if (key3) map2[key3] = text4 === void 0 ? -1 : text4.length;
11976
+ continue;
11977
+ }
11978
+ }
11979
+ const text3 = blockText(block);
11980
+ if (key3) pending3.push({ key: key3, length: text3 === void 0 ? -1 : text3.length });
11981
+ }
11982
+ return placed();
11983
+ }
11984
+ function edgeMap(keys, texts, at2, offset, origins) {
11879
11985
  const map2 = {};
11880
11986
  const end = at2 === void 0 ? keys.length : keys.indexOf(at2);
11881
11987
  if (end < 0) return map2;
@@ -11888,7 +11994,9 @@ function edgeMap(keys, texts, at2, offset) {
11888
11994
  if (at2 === void 0) return map2;
11889
11995
  const key3 = keys[end];
11890
11996
  const text3 = texts[end];
11891
- if (key3 !== void 0 && text3 !== void 0 && offset > 0) map2[key3] = offset;
11997
+ const origin = origins?.[end];
11998
+ const relative5 = origin ? origin.prefix + offset - origin.start : offset;
11999
+ if (key3 !== void 0 && text3 !== void 0 && relative5 > 0) map2[key3] = relative5;
11892
12000
  return map2;
11893
12001
  }
11894
12002
  function resolveTranscriptBoundaries(cuts, lengths) {
@@ -11929,13 +12037,14 @@ function anchorAsyncAnswer(message, messages) {
11929
12037
  const source = messages.findLast((row2) => row2.status === "streaming" && row2.role === "assistant" && codexAsyncQuestionItems(row2).some((item) => item.id === itemId)) ?? messages.findLast((row2) => row2.status === "streaming" && row2.role === "assistant" && row2.providerId === "codex");
11930
12038
  return source ? { ...message, metadata: { ...message.metadata, transcriptBoundary: captureTranscriptBoundary(source, messages) } } : message;
11931
12039
  }
11932
- var capturedOrders;
12040
+ var capturedOrders, contentKeyStamps;
11933
12041
  var init_transcript_boundary = __esm({
11934
12042
  "../../packages/shared/src/transcript-boundary.ts"() {
11935
12043
  "use strict";
11936
12044
  init_codex_async_question();
11937
12045
  init_content_delta();
11938
12046
  capturedOrders = /* @__PURE__ */ new Map();
12047
+ contentKeyStamps = /* @__PURE__ */ new WeakMap();
11939
12048
  }
11940
12049
  });
11941
12050
 
@@ -13109,6 +13218,8 @@ var init_agent_types = __esm({
13109
13218
  /** Sign a View's MCP server in through its harness (browser + optional loopback relay). */
13110
13219
  ENVIRONMENT_MCP_APPS_AUTHENTICATE: "environment:mcpApps.authenticate",
13111
13220
  ENVIRONMENT_HARNESS_RESOURCES: "environment:harnessResources",
13221
+ /** Node `environment.usage`: the logins on that machine, not this desktop. */
13222
+ ENVIRONMENT_USAGE: "environment:usage",
13112
13223
  /** Node session_providers CRUD. */
13113
13224
  /** Node-side collaboration agent profiles — authoritative agentIds for @-mentions on a remote session. */
13114
13225
  ENVIRONMENT_COLLAB_LIST_PROFILES: "environment:collabListProfiles",
@@ -43876,6 +43987,2157 @@ var init_dist7 = __esm({
43876
43987
  }
43877
43988
  });
43878
43989
 
43990
+ // ../../node_modules/jpeg-js/lib/encoder.js
43991
+ var require_encoder = __commonJS({
43992
+ "../../node_modules/jpeg-js/lib/encoder.js"(exports, module) {
43993
+ var btoa2 = btoa2 || function(buf) {
43994
+ return Buffer.from(buf).toString("base64");
43995
+ };
43996
+ function JPEGEncoder(quality) {
43997
+ var self = this;
43998
+ var fround = Math.round;
43999
+ var ffloor = Math.floor;
44000
+ var YTable = new Array(64);
44001
+ var UVTable = new Array(64);
44002
+ var fdtbl_Y = new Array(64);
44003
+ var fdtbl_UV = new Array(64);
44004
+ var YDC_HT;
44005
+ var UVDC_HT;
44006
+ var YAC_HT;
44007
+ var UVAC_HT;
44008
+ var bitcode = new Array(65535);
44009
+ var category = new Array(65535);
44010
+ var outputfDCTQuant = new Array(64);
44011
+ var DU = new Array(64);
44012
+ var byteout = [];
44013
+ var bytenew = 0;
44014
+ var bytepos = 7;
44015
+ var YDU = new Array(64);
44016
+ var UDU = new Array(64);
44017
+ var VDU = new Array(64);
44018
+ var clt = new Array(256);
44019
+ var RGB_YUV_TABLE = new Array(2048);
44020
+ var currentQuality;
44021
+ var ZigZag = [
44022
+ 0,
44023
+ 1,
44024
+ 5,
44025
+ 6,
44026
+ 14,
44027
+ 15,
44028
+ 27,
44029
+ 28,
44030
+ 2,
44031
+ 4,
44032
+ 7,
44033
+ 13,
44034
+ 16,
44035
+ 26,
44036
+ 29,
44037
+ 42,
44038
+ 3,
44039
+ 8,
44040
+ 12,
44041
+ 17,
44042
+ 25,
44043
+ 30,
44044
+ 41,
44045
+ 43,
44046
+ 9,
44047
+ 11,
44048
+ 18,
44049
+ 24,
44050
+ 31,
44051
+ 40,
44052
+ 44,
44053
+ 53,
44054
+ 10,
44055
+ 19,
44056
+ 23,
44057
+ 32,
44058
+ 39,
44059
+ 45,
44060
+ 52,
44061
+ 54,
44062
+ 20,
44063
+ 22,
44064
+ 33,
44065
+ 38,
44066
+ 46,
44067
+ 51,
44068
+ 55,
44069
+ 60,
44070
+ 21,
44071
+ 34,
44072
+ 37,
44073
+ 47,
44074
+ 50,
44075
+ 56,
44076
+ 59,
44077
+ 61,
44078
+ 35,
44079
+ 36,
44080
+ 48,
44081
+ 49,
44082
+ 57,
44083
+ 58,
44084
+ 62,
44085
+ 63
44086
+ ];
44087
+ var std_dc_luminance_nrcodes = [0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
44088
+ var std_dc_luminance_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
44089
+ var std_ac_luminance_nrcodes = [0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125];
44090
+ var std_ac_luminance_values = [
44091
+ 1,
44092
+ 2,
44093
+ 3,
44094
+ 0,
44095
+ 4,
44096
+ 17,
44097
+ 5,
44098
+ 18,
44099
+ 33,
44100
+ 49,
44101
+ 65,
44102
+ 6,
44103
+ 19,
44104
+ 81,
44105
+ 97,
44106
+ 7,
44107
+ 34,
44108
+ 113,
44109
+ 20,
44110
+ 50,
44111
+ 129,
44112
+ 145,
44113
+ 161,
44114
+ 8,
44115
+ 35,
44116
+ 66,
44117
+ 177,
44118
+ 193,
44119
+ 21,
44120
+ 82,
44121
+ 209,
44122
+ 240,
44123
+ 36,
44124
+ 51,
44125
+ 98,
44126
+ 114,
44127
+ 130,
44128
+ 9,
44129
+ 10,
44130
+ 22,
44131
+ 23,
44132
+ 24,
44133
+ 25,
44134
+ 26,
44135
+ 37,
44136
+ 38,
44137
+ 39,
44138
+ 40,
44139
+ 41,
44140
+ 42,
44141
+ 52,
44142
+ 53,
44143
+ 54,
44144
+ 55,
44145
+ 56,
44146
+ 57,
44147
+ 58,
44148
+ 67,
44149
+ 68,
44150
+ 69,
44151
+ 70,
44152
+ 71,
44153
+ 72,
44154
+ 73,
44155
+ 74,
44156
+ 83,
44157
+ 84,
44158
+ 85,
44159
+ 86,
44160
+ 87,
44161
+ 88,
44162
+ 89,
44163
+ 90,
44164
+ 99,
44165
+ 100,
44166
+ 101,
44167
+ 102,
44168
+ 103,
44169
+ 104,
44170
+ 105,
44171
+ 106,
44172
+ 115,
44173
+ 116,
44174
+ 117,
44175
+ 118,
44176
+ 119,
44177
+ 120,
44178
+ 121,
44179
+ 122,
44180
+ 131,
44181
+ 132,
44182
+ 133,
44183
+ 134,
44184
+ 135,
44185
+ 136,
44186
+ 137,
44187
+ 138,
44188
+ 146,
44189
+ 147,
44190
+ 148,
44191
+ 149,
44192
+ 150,
44193
+ 151,
44194
+ 152,
44195
+ 153,
44196
+ 154,
44197
+ 162,
44198
+ 163,
44199
+ 164,
44200
+ 165,
44201
+ 166,
44202
+ 167,
44203
+ 168,
44204
+ 169,
44205
+ 170,
44206
+ 178,
44207
+ 179,
44208
+ 180,
44209
+ 181,
44210
+ 182,
44211
+ 183,
44212
+ 184,
44213
+ 185,
44214
+ 186,
44215
+ 194,
44216
+ 195,
44217
+ 196,
44218
+ 197,
44219
+ 198,
44220
+ 199,
44221
+ 200,
44222
+ 201,
44223
+ 202,
44224
+ 210,
44225
+ 211,
44226
+ 212,
44227
+ 213,
44228
+ 214,
44229
+ 215,
44230
+ 216,
44231
+ 217,
44232
+ 218,
44233
+ 225,
44234
+ 226,
44235
+ 227,
44236
+ 228,
44237
+ 229,
44238
+ 230,
44239
+ 231,
44240
+ 232,
44241
+ 233,
44242
+ 234,
44243
+ 241,
44244
+ 242,
44245
+ 243,
44246
+ 244,
44247
+ 245,
44248
+ 246,
44249
+ 247,
44250
+ 248,
44251
+ 249,
44252
+ 250
44253
+ ];
44254
+ var std_dc_chrominance_nrcodes = [0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0];
44255
+ var std_dc_chrominance_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
44256
+ var std_ac_chrominance_nrcodes = [0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119];
44257
+ var std_ac_chrominance_values = [
44258
+ 0,
44259
+ 1,
44260
+ 2,
44261
+ 3,
44262
+ 17,
44263
+ 4,
44264
+ 5,
44265
+ 33,
44266
+ 49,
44267
+ 6,
44268
+ 18,
44269
+ 65,
44270
+ 81,
44271
+ 7,
44272
+ 97,
44273
+ 113,
44274
+ 19,
44275
+ 34,
44276
+ 50,
44277
+ 129,
44278
+ 8,
44279
+ 20,
44280
+ 66,
44281
+ 145,
44282
+ 161,
44283
+ 177,
44284
+ 193,
44285
+ 9,
44286
+ 35,
44287
+ 51,
44288
+ 82,
44289
+ 240,
44290
+ 21,
44291
+ 98,
44292
+ 114,
44293
+ 209,
44294
+ 10,
44295
+ 22,
44296
+ 36,
44297
+ 52,
44298
+ 225,
44299
+ 37,
44300
+ 241,
44301
+ 23,
44302
+ 24,
44303
+ 25,
44304
+ 26,
44305
+ 38,
44306
+ 39,
44307
+ 40,
44308
+ 41,
44309
+ 42,
44310
+ 53,
44311
+ 54,
44312
+ 55,
44313
+ 56,
44314
+ 57,
44315
+ 58,
44316
+ 67,
44317
+ 68,
44318
+ 69,
44319
+ 70,
44320
+ 71,
44321
+ 72,
44322
+ 73,
44323
+ 74,
44324
+ 83,
44325
+ 84,
44326
+ 85,
44327
+ 86,
44328
+ 87,
44329
+ 88,
44330
+ 89,
44331
+ 90,
44332
+ 99,
44333
+ 100,
44334
+ 101,
44335
+ 102,
44336
+ 103,
44337
+ 104,
44338
+ 105,
44339
+ 106,
44340
+ 115,
44341
+ 116,
44342
+ 117,
44343
+ 118,
44344
+ 119,
44345
+ 120,
44346
+ 121,
44347
+ 122,
44348
+ 130,
44349
+ 131,
44350
+ 132,
44351
+ 133,
44352
+ 134,
44353
+ 135,
44354
+ 136,
44355
+ 137,
44356
+ 138,
44357
+ 146,
44358
+ 147,
44359
+ 148,
44360
+ 149,
44361
+ 150,
44362
+ 151,
44363
+ 152,
44364
+ 153,
44365
+ 154,
44366
+ 162,
44367
+ 163,
44368
+ 164,
44369
+ 165,
44370
+ 166,
44371
+ 167,
44372
+ 168,
44373
+ 169,
44374
+ 170,
44375
+ 178,
44376
+ 179,
44377
+ 180,
44378
+ 181,
44379
+ 182,
44380
+ 183,
44381
+ 184,
44382
+ 185,
44383
+ 186,
44384
+ 194,
44385
+ 195,
44386
+ 196,
44387
+ 197,
44388
+ 198,
44389
+ 199,
44390
+ 200,
44391
+ 201,
44392
+ 202,
44393
+ 210,
44394
+ 211,
44395
+ 212,
44396
+ 213,
44397
+ 214,
44398
+ 215,
44399
+ 216,
44400
+ 217,
44401
+ 218,
44402
+ 226,
44403
+ 227,
44404
+ 228,
44405
+ 229,
44406
+ 230,
44407
+ 231,
44408
+ 232,
44409
+ 233,
44410
+ 234,
44411
+ 242,
44412
+ 243,
44413
+ 244,
44414
+ 245,
44415
+ 246,
44416
+ 247,
44417
+ 248,
44418
+ 249,
44419
+ 250
44420
+ ];
44421
+ function initQuantTables(sf) {
44422
+ var YQT = [
44423
+ 16,
44424
+ 11,
44425
+ 10,
44426
+ 16,
44427
+ 24,
44428
+ 40,
44429
+ 51,
44430
+ 61,
44431
+ 12,
44432
+ 12,
44433
+ 14,
44434
+ 19,
44435
+ 26,
44436
+ 58,
44437
+ 60,
44438
+ 55,
44439
+ 14,
44440
+ 13,
44441
+ 16,
44442
+ 24,
44443
+ 40,
44444
+ 57,
44445
+ 69,
44446
+ 56,
44447
+ 14,
44448
+ 17,
44449
+ 22,
44450
+ 29,
44451
+ 51,
44452
+ 87,
44453
+ 80,
44454
+ 62,
44455
+ 18,
44456
+ 22,
44457
+ 37,
44458
+ 56,
44459
+ 68,
44460
+ 109,
44461
+ 103,
44462
+ 77,
44463
+ 24,
44464
+ 35,
44465
+ 55,
44466
+ 64,
44467
+ 81,
44468
+ 104,
44469
+ 113,
44470
+ 92,
44471
+ 49,
44472
+ 64,
44473
+ 78,
44474
+ 87,
44475
+ 103,
44476
+ 121,
44477
+ 120,
44478
+ 101,
44479
+ 72,
44480
+ 92,
44481
+ 95,
44482
+ 98,
44483
+ 112,
44484
+ 100,
44485
+ 103,
44486
+ 99
44487
+ ];
44488
+ for (var i2 = 0; i2 < 64; i2++) {
44489
+ var t = ffloor((YQT[i2] * sf + 50) / 100);
44490
+ if (t < 1) {
44491
+ t = 1;
44492
+ } else if (t > 255) {
44493
+ t = 255;
44494
+ }
44495
+ YTable[ZigZag[i2]] = t;
44496
+ }
44497
+ var UVQT = [
44498
+ 17,
44499
+ 18,
44500
+ 24,
44501
+ 47,
44502
+ 99,
44503
+ 99,
44504
+ 99,
44505
+ 99,
44506
+ 18,
44507
+ 21,
44508
+ 26,
44509
+ 66,
44510
+ 99,
44511
+ 99,
44512
+ 99,
44513
+ 99,
44514
+ 24,
44515
+ 26,
44516
+ 56,
44517
+ 99,
44518
+ 99,
44519
+ 99,
44520
+ 99,
44521
+ 99,
44522
+ 47,
44523
+ 66,
44524
+ 99,
44525
+ 99,
44526
+ 99,
44527
+ 99,
44528
+ 99,
44529
+ 99,
44530
+ 99,
44531
+ 99,
44532
+ 99,
44533
+ 99,
44534
+ 99,
44535
+ 99,
44536
+ 99,
44537
+ 99,
44538
+ 99,
44539
+ 99,
44540
+ 99,
44541
+ 99,
44542
+ 99,
44543
+ 99,
44544
+ 99,
44545
+ 99,
44546
+ 99,
44547
+ 99,
44548
+ 99,
44549
+ 99,
44550
+ 99,
44551
+ 99,
44552
+ 99,
44553
+ 99,
44554
+ 99,
44555
+ 99,
44556
+ 99,
44557
+ 99,
44558
+ 99,
44559
+ 99,
44560
+ 99,
44561
+ 99
44562
+ ];
44563
+ for (var j3 = 0; j3 < 64; j3++) {
44564
+ var u3 = ffloor((UVQT[j3] * sf + 50) / 100);
44565
+ if (u3 < 1) {
44566
+ u3 = 1;
44567
+ } else if (u3 > 255) {
44568
+ u3 = 255;
44569
+ }
44570
+ UVTable[ZigZag[j3]] = u3;
44571
+ }
44572
+ var aasf = [
44573
+ 1,
44574
+ 1.387039845,
44575
+ 1.306562965,
44576
+ 1.175875602,
44577
+ 1,
44578
+ 0.785694958,
44579
+ 0.5411961,
44580
+ 0.275899379
44581
+ ];
44582
+ var k5 = 0;
44583
+ for (var row2 = 0; row2 < 8; row2++) {
44584
+ for (var col = 0; col < 8; col++) {
44585
+ fdtbl_Y[k5] = 1 / (YTable[ZigZag[k5]] * aasf[row2] * aasf[col] * 8);
44586
+ fdtbl_UV[k5] = 1 / (UVTable[ZigZag[k5]] * aasf[row2] * aasf[col] * 8);
44587
+ k5++;
44588
+ }
44589
+ }
44590
+ }
44591
+ function computeHuffmanTbl(nrcodes, std_table) {
44592
+ var codevalue = 0;
44593
+ var pos_in_table = 0;
44594
+ var HT = new Array();
44595
+ for (var k5 = 1; k5 <= 16; k5++) {
44596
+ for (var j3 = 1; j3 <= nrcodes[k5]; j3++) {
44597
+ HT[std_table[pos_in_table]] = [];
44598
+ HT[std_table[pos_in_table]][0] = codevalue;
44599
+ HT[std_table[pos_in_table]][1] = k5;
44600
+ pos_in_table++;
44601
+ codevalue++;
44602
+ }
44603
+ codevalue *= 2;
44604
+ }
44605
+ return HT;
44606
+ }
44607
+ function initHuffmanTbl() {
44608
+ YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes, std_dc_luminance_values);
44609
+ UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes, std_dc_chrominance_values);
44610
+ YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes, std_ac_luminance_values);
44611
+ UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes, std_ac_chrominance_values);
44612
+ }
44613
+ function initCategoryNumber() {
44614
+ var nrlower = 1;
44615
+ var nrupper = 2;
44616
+ for (var cat = 1; cat <= 15; cat++) {
44617
+ for (var nr2 = nrlower; nr2 < nrupper; nr2++) {
44618
+ category[32767 + nr2] = cat;
44619
+ bitcode[32767 + nr2] = [];
44620
+ bitcode[32767 + nr2][1] = cat;
44621
+ bitcode[32767 + nr2][0] = nr2;
44622
+ }
44623
+ for (var nrneg = -(nrupper - 1); nrneg <= -nrlower; nrneg++) {
44624
+ category[32767 + nrneg] = cat;
44625
+ bitcode[32767 + nrneg] = [];
44626
+ bitcode[32767 + nrneg][1] = cat;
44627
+ bitcode[32767 + nrneg][0] = nrupper - 1 + nrneg;
44628
+ }
44629
+ nrlower <<= 1;
44630
+ nrupper <<= 1;
44631
+ }
44632
+ }
44633
+ function initRGBYUVTable() {
44634
+ for (var i2 = 0; i2 < 256; i2++) {
44635
+ RGB_YUV_TABLE[i2] = 19595 * i2;
44636
+ RGB_YUV_TABLE[i2 + 256 >> 0] = 38470 * i2;
44637
+ RGB_YUV_TABLE[i2 + 512 >> 0] = 7471 * i2 + 32768;
44638
+ RGB_YUV_TABLE[i2 + 768 >> 0] = -11059 * i2;
44639
+ RGB_YUV_TABLE[i2 + 1024 >> 0] = -21709 * i2;
44640
+ RGB_YUV_TABLE[i2 + 1280 >> 0] = 32768 * i2 + 8421375;
44641
+ RGB_YUV_TABLE[i2 + 1536 >> 0] = -27439 * i2;
44642
+ RGB_YUV_TABLE[i2 + 1792 >> 0] = -5329 * i2;
44643
+ }
44644
+ }
44645
+ function writeBits(bs2) {
44646
+ var value = bs2[0];
44647
+ var posval = bs2[1] - 1;
44648
+ while (posval >= 0) {
44649
+ if (value & 1 << posval) {
44650
+ bytenew |= 1 << bytepos;
44651
+ }
44652
+ posval--;
44653
+ bytepos--;
44654
+ if (bytepos < 0) {
44655
+ if (bytenew == 255) {
44656
+ writeByte(255);
44657
+ writeByte(0);
44658
+ } else {
44659
+ writeByte(bytenew);
44660
+ }
44661
+ bytepos = 7;
44662
+ bytenew = 0;
44663
+ }
44664
+ }
44665
+ }
44666
+ function writeByte(value) {
44667
+ byteout.push(value);
44668
+ }
44669
+ function writeWord(value) {
44670
+ writeByte(value >> 8 & 255);
44671
+ writeByte(value & 255);
44672
+ }
44673
+ function fDCTQuant(data, fdtbl) {
44674
+ var d0, d1, d2, d3, d4, d5, d6, d7;
44675
+ var dataOff = 0;
44676
+ var i2;
44677
+ var I8 = 8;
44678
+ var I64 = 64;
44679
+ for (i2 = 0; i2 < I8; ++i2) {
44680
+ d0 = data[dataOff];
44681
+ d1 = data[dataOff + 1];
44682
+ d2 = data[dataOff + 2];
44683
+ d3 = data[dataOff + 3];
44684
+ d4 = data[dataOff + 4];
44685
+ d5 = data[dataOff + 5];
44686
+ d6 = data[dataOff + 6];
44687
+ d7 = data[dataOff + 7];
44688
+ var tmp0 = d0 + d7;
44689
+ var tmp7 = d0 - d7;
44690
+ var tmp1 = d1 + d6;
44691
+ var tmp6 = d1 - d6;
44692
+ var tmp2 = d2 + d5;
44693
+ var tmp5 = d2 - d5;
44694
+ var tmp3 = d3 + d4;
44695
+ var tmp4 = d3 - d4;
44696
+ var tmp10 = tmp0 + tmp3;
44697
+ var tmp13 = tmp0 - tmp3;
44698
+ var tmp11 = tmp1 + tmp2;
44699
+ var tmp12 = tmp1 - tmp2;
44700
+ data[dataOff] = tmp10 + tmp11;
44701
+ data[dataOff + 4] = tmp10 - tmp11;
44702
+ var z1 = (tmp12 + tmp13) * 0.707106781;
44703
+ data[dataOff + 2] = tmp13 + z1;
44704
+ data[dataOff + 6] = tmp13 - z1;
44705
+ tmp10 = tmp4 + tmp5;
44706
+ tmp11 = tmp5 + tmp6;
44707
+ tmp12 = tmp6 + tmp7;
44708
+ var z5 = (tmp10 - tmp12) * 0.382683433;
44709
+ var z22 = 0.5411961 * tmp10 + z5;
44710
+ var z42 = 1.306562965 * tmp12 + z5;
44711
+ var z32 = tmp11 * 0.707106781;
44712
+ var z11 = tmp7 + z32;
44713
+ var z13 = tmp7 - z32;
44714
+ data[dataOff + 5] = z13 + z22;
44715
+ data[dataOff + 3] = z13 - z22;
44716
+ data[dataOff + 1] = z11 + z42;
44717
+ data[dataOff + 7] = z11 - z42;
44718
+ dataOff += 8;
44719
+ }
44720
+ dataOff = 0;
44721
+ for (i2 = 0; i2 < I8; ++i2) {
44722
+ d0 = data[dataOff];
44723
+ d1 = data[dataOff + 8];
44724
+ d2 = data[dataOff + 16];
44725
+ d3 = data[dataOff + 24];
44726
+ d4 = data[dataOff + 32];
44727
+ d5 = data[dataOff + 40];
44728
+ d6 = data[dataOff + 48];
44729
+ d7 = data[dataOff + 56];
44730
+ var tmp0p2 = d0 + d7;
44731
+ var tmp7p2 = d0 - d7;
44732
+ var tmp1p2 = d1 + d6;
44733
+ var tmp6p2 = d1 - d6;
44734
+ var tmp2p2 = d2 + d5;
44735
+ var tmp5p2 = d2 - d5;
44736
+ var tmp3p2 = d3 + d4;
44737
+ var tmp4p2 = d3 - d4;
44738
+ var tmp10p2 = tmp0p2 + tmp3p2;
44739
+ var tmp13p2 = tmp0p2 - tmp3p2;
44740
+ var tmp11p2 = tmp1p2 + tmp2p2;
44741
+ var tmp12p2 = tmp1p2 - tmp2p2;
44742
+ data[dataOff] = tmp10p2 + tmp11p2;
44743
+ data[dataOff + 32] = tmp10p2 - tmp11p2;
44744
+ var z1p2 = (tmp12p2 + tmp13p2) * 0.707106781;
44745
+ data[dataOff + 16] = tmp13p2 + z1p2;
44746
+ data[dataOff + 48] = tmp13p2 - z1p2;
44747
+ tmp10p2 = tmp4p2 + tmp5p2;
44748
+ tmp11p2 = tmp5p2 + tmp6p2;
44749
+ tmp12p2 = tmp6p2 + tmp7p2;
44750
+ var z5p2 = (tmp10p2 - tmp12p2) * 0.382683433;
44751
+ var z2p2 = 0.5411961 * tmp10p2 + z5p2;
44752
+ var z4p2 = 1.306562965 * tmp12p2 + z5p2;
44753
+ var z3p2 = tmp11p2 * 0.707106781;
44754
+ var z11p2 = tmp7p2 + z3p2;
44755
+ var z13p2 = tmp7p2 - z3p2;
44756
+ data[dataOff + 40] = z13p2 + z2p2;
44757
+ data[dataOff + 24] = z13p2 - z2p2;
44758
+ data[dataOff + 8] = z11p2 + z4p2;
44759
+ data[dataOff + 56] = z11p2 - z4p2;
44760
+ dataOff++;
44761
+ }
44762
+ var fDCTQuant2;
44763
+ for (i2 = 0; i2 < I64; ++i2) {
44764
+ fDCTQuant2 = data[i2] * fdtbl[i2];
44765
+ outputfDCTQuant[i2] = fDCTQuant2 > 0 ? fDCTQuant2 + 0.5 | 0 : fDCTQuant2 - 0.5 | 0;
44766
+ }
44767
+ return outputfDCTQuant;
44768
+ }
44769
+ function writeAPP0() {
44770
+ writeWord(65504);
44771
+ writeWord(16);
44772
+ writeByte(74);
44773
+ writeByte(70);
44774
+ writeByte(73);
44775
+ writeByte(70);
44776
+ writeByte(0);
44777
+ writeByte(1);
44778
+ writeByte(1);
44779
+ writeByte(0);
44780
+ writeWord(1);
44781
+ writeWord(1);
44782
+ writeByte(0);
44783
+ writeByte(0);
44784
+ }
44785
+ function writeAPP1(exifBuffer) {
44786
+ if (!exifBuffer) return;
44787
+ writeWord(65505);
44788
+ if (exifBuffer[0] === 69 && exifBuffer[1] === 120 && exifBuffer[2] === 105 && exifBuffer[3] === 102) {
44789
+ writeWord(exifBuffer.length + 2);
44790
+ } else {
44791
+ writeWord(exifBuffer.length + 5 + 2);
44792
+ writeByte(69);
44793
+ writeByte(120);
44794
+ writeByte(105);
44795
+ writeByte(102);
44796
+ writeByte(0);
44797
+ }
44798
+ for (var i2 = 0; i2 < exifBuffer.length; i2++) {
44799
+ writeByte(exifBuffer[i2]);
44800
+ }
44801
+ }
44802
+ function writeSOF0(width, height) {
44803
+ writeWord(65472);
44804
+ writeWord(17);
44805
+ writeByte(8);
44806
+ writeWord(height);
44807
+ writeWord(width);
44808
+ writeByte(3);
44809
+ writeByte(1);
44810
+ writeByte(17);
44811
+ writeByte(0);
44812
+ writeByte(2);
44813
+ writeByte(17);
44814
+ writeByte(1);
44815
+ writeByte(3);
44816
+ writeByte(17);
44817
+ writeByte(1);
44818
+ }
44819
+ function writeDQT() {
44820
+ writeWord(65499);
44821
+ writeWord(132);
44822
+ writeByte(0);
44823
+ for (var i2 = 0; i2 < 64; i2++) {
44824
+ writeByte(YTable[i2]);
44825
+ }
44826
+ writeByte(1);
44827
+ for (var j3 = 0; j3 < 64; j3++) {
44828
+ writeByte(UVTable[j3]);
44829
+ }
44830
+ }
44831
+ function writeDHT() {
44832
+ writeWord(65476);
44833
+ writeWord(418);
44834
+ writeByte(0);
44835
+ for (var i2 = 0; i2 < 16; i2++) {
44836
+ writeByte(std_dc_luminance_nrcodes[i2 + 1]);
44837
+ }
44838
+ for (var j3 = 0; j3 <= 11; j3++) {
44839
+ writeByte(std_dc_luminance_values[j3]);
44840
+ }
44841
+ writeByte(16);
44842
+ for (var k5 = 0; k5 < 16; k5++) {
44843
+ writeByte(std_ac_luminance_nrcodes[k5 + 1]);
44844
+ }
44845
+ for (var l3 = 0; l3 <= 161; l3++) {
44846
+ writeByte(std_ac_luminance_values[l3]);
44847
+ }
44848
+ writeByte(1);
44849
+ for (var m5 = 0; m5 < 16; m5++) {
44850
+ writeByte(std_dc_chrominance_nrcodes[m5 + 1]);
44851
+ }
44852
+ for (var n = 0; n <= 11; n++) {
44853
+ writeByte(std_dc_chrominance_values[n]);
44854
+ }
44855
+ writeByte(17);
44856
+ for (var o3 = 0; o3 < 16; o3++) {
44857
+ writeByte(std_ac_chrominance_nrcodes[o3 + 1]);
44858
+ }
44859
+ for (var p4 = 0; p4 <= 161; p4++) {
44860
+ writeByte(std_ac_chrominance_values[p4]);
44861
+ }
44862
+ }
44863
+ function writeCOM(comments) {
44864
+ if (typeof comments === "undefined" || comments.constructor !== Array) return;
44865
+ comments.forEach((e) => {
44866
+ if (typeof e !== "string") return;
44867
+ writeWord(65534);
44868
+ var l3 = e.length;
44869
+ writeWord(l3 + 2);
44870
+ var i2;
44871
+ for (i2 = 0; i2 < l3; i2++)
44872
+ writeByte(e.charCodeAt(i2));
44873
+ });
44874
+ }
44875
+ function writeSOS() {
44876
+ writeWord(65498);
44877
+ writeWord(12);
44878
+ writeByte(3);
44879
+ writeByte(1);
44880
+ writeByte(0);
44881
+ writeByte(2);
44882
+ writeByte(17);
44883
+ writeByte(3);
44884
+ writeByte(17);
44885
+ writeByte(0);
44886
+ writeByte(63);
44887
+ writeByte(0);
44888
+ }
44889
+ function processDU(CDU, fdtbl, DC, HTDC, HTAC) {
44890
+ var EOB = HTAC[0];
44891
+ var M16zeroes = HTAC[240];
44892
+ var pos;
44893
+ var I16 = 16;
44894
+ var I63 = 63;
44895
+ var I64 = 64;
44896
+ var DU_DCT = fDCTQuant(CDU, fdtbl);
44897
+ for (var j3 = 0; j3 < I64; ++j3) {
44898
+ DU[ZigZag[j3]] = DU_DCT[j3];
44899
+ }
44900
+ var Diff4 = DU[0] - DC;
44901
+ DC = DU[0];
44902
+ if (Diff4 == 0) {
44903
+ writeBits(HTDC[0]);
44904
+ } else {
44905
+ pos = 32767 + Diff4;
44906
+ writeBits(HTDC[category[pos]]);
44907
+ writeBits(bitcode[pos]);
44908
+ }
44909
+ var end0pos = 63;
44910
+ for (; end0pos > 0 && DU[end0pos] == 0; end0pos--) {
44911
+ }
44912
+ ;
44913
+ if (end0pos == 0) {
44914
+ writeBits(EOB);
44915
+ return DC;
44916
+ }
44917
+ var i2 = 1;
44918
+ var lng;
44919
+ while (i2 <= end0pos) {
44920
+ var startpos = i2;
44921
+ for (; DU[i2] == 0 && i2 <= end0pos; ++i2) {
44922
+ }
44923
+ var nrzeroes = i2 - startpos;
44924
+ if (nrzeroes >= I16) {
44925
+ lng = nrzeroes >> 4;
44926
+ for (var nrmarker = 1; nrmarker <= lng; ++nrmarker)
44927
+ writeBits(M16zeroes);
44928
+ nrzeroes = nrzeroes & 15;
44929
+ }
44930
+ pos = 32767 + DU[i2];
44931
+ writeBits(HTAC[(nrzeroes << 4) + category[pos]]);
44932
+ writeBits(bitcode[pos]);
44933
+ i2++;
44934
+ }
44935
+ if (end0pos != I63) {
44936
+ writeBits(EOB);
44937
+ }
44938
+ return DC;
44939
+ }
44940
+ function initCharLookupTable() {
44941
+ var sfcc = String.fromCharCode;
44942
+ for (var i2 = 0; i2 < 256; i2++) {
44943
+ clt[i2] = sfcc(i2);
44944
+ }
44945
+ }
44946
+ this.encode = function(image, quality2) {
44947
+ var time_start = (/* @__PURE__ */ new Date()).getTime();
44948
+ if (quality2) setQuality(quality2);
44949
+ byteout = new Array();
44950
+ bytenew = 0;
44951
+ bytepos = 7;
44952
+ writeWord(65496);
44953
+ writeAPP0();
44954
+ writeCOM(image.comments);
44955
+ writeAPP1(image.exifBuffer);
44956
+ writeDQT();
44957
+ writeSOF0(image.width, image.height);
44958
+ writeDHT();
44959
+ writeSOS();
44960
+ var DCY = 0;
44961
+ var DCU = 0;
44962
+ var DCV = 0;
44963
+ bytenew = 0;
44964
+ bytepos = 7;
44965
+ this.encode.displayName = "_encode_";
44966
+ var imageData = image.data;
44967
+ var width = image.width;
44968
+ var height = image.height;
44969
+ var quadWidth = width * 4;
44970
+ var tripleWidth = width * 3;
44971
+ var x4, y3 = 0;
44972
+ var r4, g3, b5;
44973
+ var start, p4, col, row2, pos;
44974
+ while (y3 < height) {
44975
+ x4 = 0;
44976
+ while (x4 < quadWidth) {
44977
+ start = quadWidth * y3 + x4;
44978
+ p4 = start;
44979
+ col = -1;
44980
+ row2 = 0;
44981
+ for (pos = 0; pos < 64; pos++) {
44982
+ row2 = pos >> 3;
44983
+ col = (pos & 7) * 4;
44984
+ p4 = start + row2 * quadWidth + col;
44985
+ if (y3 + row2 >= height) {
44986
+ p4 -= quadWidth * (y3 + 1 + row2 - height);
44987
+ }
44988
+ if (x4 + col >= quadWidth) {
44989
+ p4 -= x4 + col - quadWidth + 4;
44990
+ }
44991
+ r4 = imageData[p4++];
44992
+ g3 = imageData[p4++];
44993
+ b5 = imageData[p4++];
44994
+ YDU[pos] = (RGB_YUV_TABLE[r4] + RGB_YUV_TABLE[g3 + 256 >> 0] + RGB_YUV_TABLE[b5 + 512 >> 0] >> 16) - 128;
44995
+ UDU[pos] = (RGB_YUV_TABLE[r4 + 768 >> 0] + RGB_YUV_TABLE[g3 + 1024 >> 0] + RGB_YUV_TABLE[b5 + 1280 >> 0] >> 16) - 128;
44996
+ VDU[pos] = (RGB_YUV_TABLE[r4 + 1280 >> 0] + RGB_YUV_TABLE[g3 + 1536 >> 0] + RGB_YUV_TABLE[b5 + 1792 >> 0] >> 16) - 128;
44997
+ }
44998
+ DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
44999
+ DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
45000
+ DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
45001
+ x4 += 32;
45002
+ }
45003
+ y3 += 8;
45004
+ }
45005
+ if (bytepos >= 0) {
45006
+ var fillbits = [];
45007
+ fillbits[1] = bytepos + 1;
45008
+ fillbits[0] = (1 << bytepos + 1) - 1;
45009
+ writeBits(fillbits);
45010
+ }
45011
+ writeWord(65497);
45012
+ if (typeof module === "undefined") return new Uint8Array(byteout);
45013
+ return Buffer.from(byteout);
45014
+ var jpegDataUri = "data:image/jpeg;base64," + btoa2(byteout.join(""));
45015
+ byteout = [];
45016
+ var duration3 = (/* @__PURE__ */ new Date()).getTime() - time_start;
45017
+ return jpegDataUri;
45018
+ };
45019
+ function setQuality(quality2) {
45020
+ if (quality2 <= 0) {
45021
+ quality2 = 1;
45022
+ }
45023
+ if (quality2 > 100) {
45024
+ quality2 = 100;
45025
+ }
45026
+ if (currentQuality == quality2) return;
45027
+ var sf = 0;
45028
+ if (quality2 < 50) {
45029
+ sf = Math.floor(5e3 / quality2);
45030
+ } else {
45031
+ sf = Math.floor(200 - quality2 * 2);
45032
+ }
45033
+ initQuantTables(sf);
45034
+ currentQuality = quality2;
45035
+ }
45036
+ function init() {
45037
+ var time_start = (/* @__PURE__ */ new Date()).getTime();
45038
+ if (!quality) quality = 50;
45039
+ initCharLookupTable();
45040
+ initHuffmanTbl();
45041
+ initCategoryNumber();
45042
+ initRGBYUVTable();
45043
+ setQuality(quality);
45044
+ var duration3 = (/* @__PURE__ */ new Date()).getTime() - time_start;
45045
+ }
45046
+ init();
45047
+ }
45048
+ if (typeof module !== "undefined") {
45049
+ module.exports = encode4;
45050
+ } else if (typeof window !== "undefined") {
45051
+ window["jpeg-js"] = window["jpeg-js"] || {};
45052
+ window["jpeg-js"].encode = encode4;
45053
+ }
45054
+ function encode4(imgData, qu) {
45055
+ if (typeof qu === "undefined") qu = 50;
45056
+ var encoder4 = new JPEGEncoder(qu);
45057
+ var data = encoder4.encode(imgData, qu);
45058
+ return {
45059
+ data,
45060
+ width: imgData.width,
45061
+ height: imgData.height
45062
+ };
45063
+ }
45064
+ }
45065
+ });
45066
+
45067
+ // ../../node_modules/jpeg-js/lib/decoder.js
45068
+ var require_decoder = __commonJS({
45069
+ "../../node_modules/jpeg-js/lib/decoder.js"(exports, module) {
45070
+ var JpegImage = (function jpegImage() {
45071
+ "use strict";
45072
+ var dctZigZag = new Int32Array([
45073
+ 0,
45074
+ 1,
45075
+ 8,
45076
+ 16,
45077
+ 9,
45078
+ 2,
45079
+ 3,
45080
+ 10,
45081
+ 17,
45082
+ 24,
45083
+ 32,
45084
+ 25,
45085
+ 18,
45086
+ 11,
45087
+ 4,
45088
+ 5,
45089
+ 12,
45090
+ 19,
45091
+ 26,
45092
+ 33,
45093
+ 40,
45094
+ 48,
45095
+ 41,
45096
+ 34,
45097
+ 27,
45098
+ 20,
45099
+ 13,
45100
+ 6,
45101
+ 7,
45102
+ 14,
45103
+ 21,
45104
+ 28,
45105
+ 35,
45106
+ 42,
45107
+ 49,
45108
+ 56,
45109
+ 57,
45110
+ 50,
45111
+ 43,
45112
+ 36,
45113
+ 29,
45114
+ 22,
45115
+ 15,
45116
+ 23,
45117
+ 30,
45118
+ 37,
45119
+ 44,
45120
+ 51,
45121
+ 58,
45122
+ 59,
45123
+ 52,
45124
+ 45,
45125
+ 38,
45126
+ 31,
45127
+ 39,
45128
+ 46,
45129
+ 53,
45130
+ 60,
45131
+ 61,
45132
+ 54,
45133
+ 47,
45134
+ 55,
45135
+ 62,
45136
+ 63
45137
+ ]);
45138
+ var dctCos1 = 4017;
45139
+ var dctSin1 = 799;
45140
+ var dctCos3 = 3406;
45141
+ var dctSin3 = 2276;
45142
+ var dctCos6 = 1567;
45143
+ var dctSin6 = 3784;
45144
+ var dctSqrt2 = 5793;
45145
+ var dctSqrt1d2 = 2896;
45146
+ function constructor() {
45147
+ }
45148
+ function buildHuffmanTable(codeLengths, values) {
45149
+ var k5 = 0, code = [], i2, j3, length = 16;
45150
+ while (length > 0 && !codeLengths[length - 1])
45151
+ length--;
45152
+ code.push({ children: [], index: 0 });
45153
+ var p4 = code[0], q3;
45154
+ for (i2 = 0; i2 < length; i2++) {
45155
+ for (j3 = 0; j3 < codeLengths[i2]; j3++) {
45156
+ p4 = code.pop();
45157
+ p4.children[p4.index] = values[k5];
45158
+ while (p4.index > 0) {
45159
+ if (code.length === 0)
45160
+ throw new Error("Could not recreate Huffman Table");
45161
+ p4 = code.pop();
45162
+ }
45163
+ p4.index++;
45164
+ code.push(p4);
45165
+ while (code.length <= i2) {
45166
+ code.push(q3 = { children: [], index: 0 });
45167
+ p4.children[p4.index] = q3.children;
45168
+ p4 = q3;
45169
+ }
45170
+ k5++;
45171
+ }
45172
+ if (i2 + 1 < length) {
45173
+ code.push(q3 = { children: [], index: 0 });
45174
+ p4.children[p4.index] = q3.children;
45175
+ p4 = q3;
45176
+ }
45177
+ }
45178
+ return code[0].children;
45179
+ }
45180
+ function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive, opts) {
45181
+ var precision = frame.precision;
45182
+ var samplesPerLine = frame.samplesPerLine;
45183
+ var scanLines = frame.scanLines;
45184
+ var mcusPerLine = frame.mcusPerLine;
45185
+ var progressive = frame.progressive;
45186
+ var maxH = frame.maxH, maxV = frame.maxV;
45187
+ var startOffset = offset, bitsData = 0, bitsCount = 0;
45188
+ function readBit() {
45189
+ if (bitsCount > 0) {
45190
+ bitsCount--;
45191
+ return bitsData >> bitsCount & 1;
45192
+ }
45193
+ bitsData = data[offset++];
45194
+ if (bitsData == 255) {
45195
+ var nextByte = data[offset++];
45196
+ if (nextByte) {
45197
+ throw new Error("unexpected marker: " + (bitsData << 8 | nextByte).toString(16));
45198
+ }
45199
+ }
45200
+ bitsCount = 7;
45201
+ return bitsData >>> 7;
45202
+ }
45203
+ function decodeHuffman(tree) {
45204
+ var node = tree, bit;
45205
+ while ((bit = readBit()) !== null) {
45206
+ node = node[bit];
45207
+ if (typeof node === "number")
45208
+ return node;
45209
+ if (typeof node !== "object")
45210
+ throw new Error("invalid huffman sequence");
45211
+ }
45212
+ return null;
45213
+ }
45214
+ function receive(length) {
45215
+ var n2 = 0;
45216
+ while (length > 0) {
45217
+ var bit = readBit();
45218
+ if (bit === null) return;
45219
+ n2 = n2 << 1 | bit;
45220
+ length--;
45221
+ }
45222
+ return n2;
45223
+ }
45224
+ function receiveAndExtend(length) {
45225
+ var n2 = receive(length);
45226
+ if (n2 >= 1 << length - 1)
45227
+ return n2;
45228
+ return n2 + (-1 << length) + 1;
45229
+ }
45230
+ function decodeBaseline(component2, zz) {
45231
+ var t = decodeHuffman(component2.huffmanTableDC);
45232
+ var diff = t === 0 ? 0 : receiveAndExtend(t);
45233
+ zz[0] = component2.pred += diff;
45234
+ var k6 = 1;
45235
+ while (k6 < 64) {
45236
+ var rs2 = decodeHuffman(component2.huffmanTableAC);
45237
+ var s5 = rs2 & 15, r4 = rs2 >> 4;
45238
+ if (s5 === 0) {
45239
+ if (r4 < 15)
45240
+ break;
45241
+ k6 += 16;
45242
+ continue;
45243
+ }
45244
+ k6 += r4;
45245
+ var z5 = dctZigZag[k6];
45246
+ zz[z5] = receiveAndExtend(s5);
45247
+ k6++;
45248
+ }
45249
+ }
45250
+ function decodeDCFirst(component2, zz) {
45251
+ var t = decodeHuffman(component2.huffmanTableDC);
45252
+ var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
45253
+ zz[0] = component2.pred += diff;
45254
+ }
45255
+ function decodeDCSuccessive(component2, zz) {
45256
+ zz[0] |= readBit() << successive;
45257
+ }
45258
+ var eobrun = 0;
45259
+ function decodeACFirst(component2, zz) {
45260
+ if (eobrun > 0) {
45261
+ eobrun--;
45262
+ return;
45263
+ }
45264
+ var k6 = spectralStart, e = spectralEnd;
45265
+ while (k6 <= e) {
45266
+ var rs2 = decodeHuffman(component2.huffmanTableAC);
45267
+ var s5 = rs2 & 15, r4 = rs2 >> 4;
45268
+ if (s5 === 0) {
45269
+ if (r4 < 15) {
45270
+ eobrun = receive(r4) + (1 << r4) - 1;
45271
+ break;
45272
+ }
45273
+ k6 += 16;
45274
+ continue;
45275
+ }
45276
+ k6 += r4;
45277
+ var z5 = dctZigZag[k6];
45278
+ zz[z5] = receiveAndExtend(s5) * (1 << successive);
45279
+ k6++;
45280
+ }
45281
+ }
45282
+ var successiveACState = 0, successiveACNextValue;
45283
+ function decodeACSuccessive(component2, zz) {
45284
+ var k6 = spectralStart, e = spectralEnd, r4 = 0;
45285
+ while (k6 <= e) {
45286
+ var z5 = dctZigZag[k6];
45287
+ var direction = zz[z5] < 0 ? -1 : 1;
45288
+ switch (successiveACState) {
45289
+ case 0:
45290
+ var rs2 = decodeHuffman(component2.huffmanTableAC);
45291
+ var s5 = rs2 & 15, r4 = rs2 >> 4;
45292
+ if (s5 === 0) {
45293
+ if (r4 < 15) {
45294
+ eobrun = receive(r4) + (1 << r4);
45295
+ successiveACState = 4;
45296
+ } else {
45297
+ r4 = 16;
45298
+ successiveACState = 1;
45299
+ }
45300
+ } else {
45301
+ if (s5 !== 1)
45302
+ throw new Error("invalid ACn encoding");
45303
+ successiveACNextValue = receiveAndExtend(s5);
45304
+ successiveACState = r4 ? 2 : 3;
45305
+ }
45306
+ continue;
45307
+ case 1:
45308
+ // skipping r zero items
45309
+ case 2:
45310
+ if (zz[z5])
45311
+ zz[z5] += (readBit() << successive) * direction;
45312
+ else {
45313
+ r4--;
45314
+ if (r4 === 0)
45315
+ successiveACState = successiveACState == 2 ? 3 : 0;
45316
+ }
45317
+ break;
45318
+ case 3:
45319
+ if (zz[z5])
45320
+ zz[z5] += (readBit() << successive) * direction;
45321
+ else {
45322
+ zz[z5] = successiveACNextValue << successive;
45323
+ successiveACState = 0;
45324
+ }
45325
+ break;
45326
+ case 4:
45327
+ if (zz[z5])
45328
+ zz[z5] += (readBit() << successive) * direction;
45329
+ break;
45330
+ }
45331
+ k6++;
45332
+ }
45333
+ if (successiveACState === 4) {
45334
+ eobrun--;
45335
+ if (eobrun === 0)
45336
+ successiveACState = 0;
45337
+ }
45338
+ }
45339
+ function decodeMcu(component2, decode4, mcu2, row2, col) {
45340
+ var mcuRow = mcu2 / mcusPerLine | 0;
45341
+ var mcuCol = mcu2 % mcusPerLine;
45342
+ var blockRow = mcuRow * component2.v + row2;
45343
+ var blockCol = mcuCol * component2.h + col;
45344
+ if (component2.blocks[blockRow] === void 0 && opts.tolerantDecoding)
45345
+ return;
45346
+ decode4(component2, component2.blocks[blockRow][blockCol]);
45347
+ }
45348
+ function decodeBlock(component2, decode4, mcu2) {
45349
+ var blockRow = mcu2 / component2.blocksPerLine | 0;
45350
+ var blockCol = mcu2 % component2.blocksPerLine;
45351
+ if (component2.blocks[blockRow] === void 0 && opts.tolerantDecoding)
45352
+ return;
45353
+ decode4(component2, component2.blocks[blockRow][blockCol]);
45354
+ }
45355
+ var componentsLength = components.length;
45356
+ var component, i2, j3, k5, n;
45357
+ var decodeFn;
45358
+ if (progressive) {
45359
+ if (spectralStart === 0)
45360
+ decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
45361
+ else
45362
+ decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
45363
+ } else {
45364
+ decodeFn = decodeBaseline;
45365
+ }
45366
+ var mcu = 0, marker;
45367
+ var mcuExpected;
45368
+ if (componentsLength == 1) {
45369
+ mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
45370
+ } else {
45371
+ mcuExpected = mcusPerLine * frame.mcusPerColumn;
45372
+ }
45373
+ if (!resetInterval) resetInterval = mcuExpected;
45374
+ var h2, v4;
45375
+ while (mcu < mcuExpected) {
45376
+ for (i2 = 0; i2 < componentsLength; i2++)
45377
+ components[i2].pred = 0;
45378
+ eobrun = 0;
45379
+ if (componentsLength == 1) {
45380
+ component = components[0];
45381
+ for (n = 0; n < resetInterval; n++) {
45382
+ decodeBlock(component, decodeFn, mcu);
45383
+ mcu++;
45384
+ }
45385
+ } else {
45386
+ for (n = 0; n < resetInterval; n++) {
45387
+ for (i2 = 0; i2 < componentsLength; i2++) {
45388
+ component = components[i2];
45389
+ h2 = component.h;
45390
+ v4 = component.v;
45391
+ for (j3 = 0; j3 < v4; j3++) {
45392
+ for (k5 = 0; k5 < h2; k5++) {
45393
+ decodeMcu(component, decodeFn, mcu, j3, k5);
45394
+ }
45395
+ }
45396
+ }
45397
+ mcu++;
45398
+ if (mcu === mcuExpected) break;
45399
+ }
45400
+ }
45401
+ if (mcu === mcuExpected) {
45402
+ do {
45403
+ if (data[offset] === 255) {
45404
+ if (data[offset + 1] !== 0) {
45405
+ break;
45406
+ }
45407
+ }
45408
+ offset += 1;
45409
+ } while (offset < data.length - 2);
45410
+ }
45411
+ bitsCount = 0;
45412
+ marker = data[offset] << 8 | data[offset + 1];
45413
+ if (marker < 65280) {
45414
+ throw new Error("marker was not found");
45415
+ }
45416
+ if (marker >= 65488 && marker <= 65495) {
45417
+ offset += 2;
45418
+ } else
45419
+ break;
45420
+ }
45421
+ return offset - startOffset;
45422
+ }
45423
+ function buildComponentData(frame, component) {
45424
+ var lines2 = [];
45425
+ var blocksPerLine = component.blocksPerLine;
45426
+ var blocksPerColumn = component.blocksPerColumn;
45427
+ var samplesPerLine = blocksPerLine << 3;
45428
+ var R5 = new Int32Array(64), r4 = new Uint8Array(64);
45429
+ function quantizeAndInverse(zz, dataOut, dataIn) {
45430
+ var qt2 = component.quantizationTable;
45431
+ var v0, v1, v22, v32, v4, v5, v6, v7, t;
45432
+ var p4 = dataIn;
45433
+ var i3;
45434
+ for (i3 = 0; i3 < 64; i3++)
45435
+ p4[i3] = zz[i3] * qt2[i3];
45436
+ for (i3 = 0; i3 < 8; ++i3) {
45437
+ var row2 = 8 * i3;
45438
+ if (p4[1 + row2] == 0 && p4[2 + row2] == 0 && p4[3 + row2] == 0 && p4[4 + row2] == 0 && p4[5 + row2] == 0 && p4[6 + row2] == 0 && p4[7 + row2] == 0) {
45439
+ t = dctSqrt2 * p4[0 + row2] + 512 >> 10;
45440
+ p4[0 + row2] = t;
45441
+ p4[1 + row2] = t;
45442
+ p4[2 + row2] = t;
45443
+ p4[3 + row2] = t;
45444
+ p4[4 + row2] = t;
45445
+ p4[5 + row2] = t;
45446
+ p4[6 + row2] = t;
45447
+ p4[7 + row2] = t;
45448
+ continue;
45449
+ }
45450
+ v0 = dctSqrt2 * p4[0 + row2] + 128 >> 8;
45451
+ v1 = dctSqrt2 * p4[4 + row2] + 128 >> 8;
45452
+ v22 = p4[2 + row2];
45453
+ v32 = p4[6 + row2];
45454
+ v4 = dctSqrt1d2 * (p4[1 + row2] - p4[7 + row2]) + 128 >> 8;
45455
+ v7 = dctSqrt1d2 * (p4[1 + row2] + p4[7 + row2]) + 128 >> 8;
45456
+ v5 = p4[3 + row2] << 4;
45457
+ v6 = p4[5 + row2] << 4;
45458
+ t = v0 - v1 + 1 >> 1;
45459
+ v0 = v0 + v1 + 1 >> 1;
45460
+ v1 = t;
45461
+ t = v22 * dctSin6 + v32 * dctCos6 + 128 >> 8;
45462
+ v22 = v22 * dctCos6 - v32 * dctSin6 + 128 >> 8;
45463
+ v32 = t;
45464
+ t = v4 - v6 + 1 >> 1;
45465
+ v4 = v4 + v6 + 1 >> 1;
45466
+ v6 = t;
45467
+ t = v7 + v5 + 1 >> 1;
45468
+ v5 = v7 - v5 + 1 >> 1;
45469
+ v7 = t;
45470
+ t = v0 - v32 + 1 >> 1;
45471
+ v0 = v0 + v32 + 1 >> 1;
45472
+ v32 = t;
45473
+ t = v1 - v22 + 1 >> 1;
45474
+ v1 = v1 + v22 + 1 >> 1;
45475
+ v22 = t;
45476
+ t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
45477
+ v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
45478
+ v7 = t;
45479
+ t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
45480
+ v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
45481
+ v6 = t;
45482
+ p4[0 + row2] = v0 + v7;
45483
+ p4[7 + row2] = v0 - v7;
45484
+ p4[1 + row2] = v1 + v6;
45485
+ p4[6 + row2] = v1 - v6;
45486
+ p4[2 + row2] = v22 + v5;
45487
+ p4[5 + row2] = v22 - v5;
45488
+ p4[3 + row2] = v32 + v4;
45489
+ p4[4 + row2] = v32 - v4;
45490
+ }
45491
+ for (i3 = 0; i3 < 8; ++i3) {
45492
+ var col = i3;
45493
+ if (p4[1 * 8 + col] == 0 && p4[2 * 8 + col] == 0 && p4[3 * 8 + col] == 0 && p4[4 * 8 + col] == 0 && p4[5 * 8 + col] == 0 && p4[6 * 8 + col] == 0 && p4[7 * 8 + col] == 0) {
45494
+ t = dctSqrt2 * dataIn[i3 + 0] + 8192 >> 14;
45495
+ p4[0 * 8 + col] = t;
45496
+ p4[1 * 8 + col] = t;
45497
+ p4[2 * 8 + col] = t;
45498
+ p4[3 * 8 + col] = t;
45499
+ p4[4 * 8 + col] = t;
45500
+ p4[5 * 8 + col] = t;
45501
+ p4[6 * 8 + col] = t;
45502
+ p4[7 * 8 + col] = t;
45503
+ continue;
45504
+ }
45505
+ v0 = dctSqrt2 * p4[0 * 8 + col] + 2048 >> 12;
45506
+ v1 = dctSqrt2 * p4[4 * 8 + col] + 2048 >> 12;
45507
+ v22 = p4[2 * 8 + col];
45508
+ v32 = p4[6 * 8 + col];
45509
+ v4 = dctSqrt1d2 * (p4[1 * 8 + col] - p4[7 * 8 + col]) + 2048 >> 12;
45510
+ v7 = dctSqrt1d2 * (p4[1 * 8 + col] + p4[7 * 8 + col]) + 2048 >> 12;
45511
+ v5 = p4[3 * 8 + col];
45512
+ v6 = p4[5 * 8 + col];
45513
+ t = v0 - v1 + 1 >> 1;
45514
+ v0 = v0 + v1 + 1 >> 1;
45515
+ v1 = t;
45516
+ t = v22 * dctSin6 + v32 * dctCos6 + 2048 >> 12;
45517
+ v22 = v22 * dctCos6 - v32 * dctSin6 + 2048 >> 12;
45518
+ v32 = t;
45519
+ t = v4 - v6 + 1 >> 1;
45520
+ v4 = v4 + v6 + 1 >> 1;
45521
+ v6 = t;
45522
+ t = v7 + v5 + 1 >> 1;
45523
+ v5 = v7 - v5 + 1 >> 1;
45524
+ v7 = t;
45525
+ t = v0 - v32 + 1 >> 1;
45526
+ v0 = v0 + v32 + 1 >> 1;
45527
+ v32 = t;
45528
+ t = v1 - v22 + 1 >> 1;
45529
+ v1 = v1 + v22 + 1 >> 1;
45530
+ v22 = t;
45531
+ t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
45532
+ v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
45533
+ v7 = t;
45534
+ t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
45535
+ v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
45536
+ v6 = t;
45537
+ p4[0 * 8 + col] = v0 + v7;
45538
+ p4[7 * 8 + col] = v0 - v7;
45539
+ p4[1 * 8 + col] = v1 + v6;
45540
+ p4[6 * 8 + col] = v1 - v6;
45541
+ p4[2 * 8 + col] = v22 + v5;
45542
+ p4[5 * 8 + col] = v22 - v5;
45543
+ p4[3 * 8 + col] = v32 + v4;
45544
+ p4[4 * 8 + col] = v32 - v4;
45545
+ }
45546
+ for (i3 = 0; i3 < 64; ++i3) {
45547
+ var sample2 = 128 + (p4[i3] + 8 >> 4);
45548
+ dataOut[i3] = sample2 < 0 ? 0 : sample2 > 255 ? 255 : sample2;
45549
+ }
45550
+ }
45551
+ requestMemoryAllocation(samplesPerLine * blocksPerColumn * 8);
45552
+ var i2, j3;
45553
+ for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
45554
+ var scanLine2 = blockRow << 3;
45555
+ for (i2 = 0; i2 < 8; i2++)
45556
+ lines2.push(new Uint8Array(samplesPerLine));
45557
+ for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
45558
+ quantizeAndInverse(component.blocks[blockRow][blockCol], r4, R5);
45559
+ var offset = 0, sample = blockCol << 3;
45560
+ for (j3 = 0; j3 < 8; j3++) {
45561
+ var line = lines2[scanLine2 + j3];
45562
+ for (i2 = 0; i2 < 8; i2++)
45563
+ line[sample + i2] = r4[offset++];
45564
+ }
45565
+ }
45566
+ }
45567
+ return lines2;
45568
+ }
45569
+ function clampTo8bit(a2) {
45570
+ return a2 < 0 ? 0 : a2 > 255 ? 255 : a2;
45571
+ }
45572
+ constructor.prototype = {
45573
+ load: function load(path) {
45574
+ var xhr = new XMLHttpRequest();
45575
+ xhr.open("GET", path, true);
45576
+ xhr.responseType = "arraybuffer";
45577
+ xhr.onload = (function() {
45578
+ var data = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer);
45579
+ this.parse(data);
45580
+ if (this.onload)
45581
+ this.onload();
45582
+ }).bind(this);
45583
+ xhr.send(null);
45584
+ },
45585
+ parse: function parse6(data) {
45586
+ var maxResolutionInPixels = this.opts.maxResolutionInMP * 1e3 * 1e3;
45587
+ var offset = 0, length = data.length;
45588
+ function readUint16() {
45589
+ var value = data[offset] << 8 | data[offset + 1];
45590
+ offset += 2;
45591
+ return value;
45592
+ }
45593
+ function readDataBlock() {
45594
+ var length2 = readUint16();
45595
+ var array2 = data.subarray(offset, offset + length2 - 2);
45596
+ offset += array2.length;
45597
+ return array2;
45598
+ }
45599
+ function prepareComponents(frame2) {
45600
+ var maxH2 = 1, maxV2 = 1;
45601
+ var component2, componentId2;
45602
+ for (componentId2 in frame2.components) {
45603
+ if (frame2.components.hasOwnProperty(componentId2)) {
45604
+ component2 = frame2.components[componentId2];
45605
+ if (maxH2 < component2.h) maxH2 = component2.h;
45606
+ if (maxV2 < component2.v) maxV2 = component2.v;
45607
+ }
45608
+ }
45609
+ var mcusPerLine = Math.ceil(frame2.samplesPerLine / 8 / maxH2);
45610
+ var mcusPerColumn = Math.ceil(frame2.scanLines / 8 / maxV2);
45611
+ for (componentId2 in frame2.components) {
45612
+ if (frame2.components.hasOwnProperty(componentId2)) {
45613
+ component2 = frame2.components[componentId2];
45614
+ var blocksPerLine = Math.ceil(Math.ceil(frame2.samplesPerLine / 8) * component2.h / maxH2);
45615
+ var blocksPerColumn = Math.ceil(Math.ceil(frame2.scanLines / 8) * component2.v / maxV2);
45616
+ var blocksPerLineForMcu = mcusPerLine * component2.h;
45617
+ var blocksPerColumnForMcu = mcusPerColumn * component2.v;
45618
+ var blocksToAllocate = blocksPerColumnForMcu * blocksPerLineForMcu;
45619
+ var blocks = [];
45620
+ requestMemoryAllocation(blocksToAllocate * 256);
45621
+ for (var i3 = 0; i3 < blocksPerColumnForMcu; i3++) {
45622
+ var row2 = [];
45623
+ for (var j4 = 0; j4 < blocksPerLineForMcu; j4++)
45624
+ row2.push(new Int32Array(64));
45625
+ blocks.push(row2);
45626
+ }
45627
+ component2.blocksPerLine = blocksPerLine;
45628
+ component2.blocksPerColumn = blocksPerColumn;
45629
+ component2.blocks = blocks;
45630
+ }
45631
+ }
45632
+ frame2.maxH = maxH2;
45633
+ frame2.maxV = maxV2;
45634
+ frame2.mcusPerLine = mcusPerLine;
45635
+ frame2.mcusPerColumn = mcusPerColumn;
45636
+ }
45637
+ var jfif = null;
45638
+ var adobe = null;
45639
+ var pixels = null;
45640
+ var frame, resetInterval;
45641
+ var quantizationTables = [], frames = [];
45642
+ var huffmanTablesAC = [], huffmanTablesDC = [];
45643
+ var fileMarker = readUint16();
45644
+ var malformedDataOffset = -1;
45645
+ this.comments = [];
45646
+ if (fileMarker != 65496) {
45647
+ throw new Error("SOI not found");
45648
+ }
45649
+ fileMarker = readUint16();
45650
+ while (fileMarker != 65497) {
45651
+ var i2, j3, l3;
45652
+ switch (fileMarker) {
45653
+ case 65280:
45654
+ break;
45655
+ case 65504:
45656
+ // APP0 (Application Specific)
45657
+ case 65505:
45658
+ // APP1
45659
+ case 65506:
45660
+ // APP2
45661
+ case 65507:
45662
+ // APP3
45663
+ case 65508:
45664
+ // APP4
45665
+ case 65509:
45666
+ // APP5
45667
+ case 65510:
45668
+ // APP6
45669
+ case 65511:
45670
+ // APP7
45671
+ case 65512:
45672
+ // APP8
45673
+ case 65513:
45674
+ // APP9
45675
+ case 65514:
45676
+ // APP10
45677
+ case 65515:
45678
+ // APP11
45679
+ case 65516:
45680
+ // APP12
45681
+ case 65517:
45682
+ // APP13
45683
+ case 65518:
45684
+ // APP14
45685
+ case 65519:
45686
+ // APP15
45687
+ case 65534:
45688
+ var appData = readDataBlock();
45689
+ if (fileMarker === 65534) {
45690
+ var comment2 = String.fromCharCode.apply(null, appData);
45691
+ this.comments.push(comment2);
45692
+ }
45693
+ if (fileMarker === 65504) {
45694
+ if (appData[0] === 74 && appData[1] === 70 && appData[2] === 73 && appData[3] === 70 && appData[4] === 0) {
45695
+ jfif = {
45696
+ version: { major: appData[5], minor: appData[6] },
45697
+ densityUnits: appData[7],
45698
+ xDensity: appData[8] << 8 | appData[9],
45699
+ yDensity: appData[10] << 8 | appData[11],
45700
+ thumbWidth: appData[12],
45701
+ thumbHeight: appData[13],
45702
+ thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
45703
+ };
45704
+ }
45705
+ }
45706
+ if (fileMarker === 65505) {
45707
+ if (appData[0] === 69 && appData[1] === 120 && appData[2] === 105 && appData[3] === 102 && appData[4] === 0) {
45708
+ this.exifBuffer = appData.subarray(5, appData.length);
45709
+ }
45710
+ }
45711
+ if (fileMarker === 65518) {
45712
+ if (appData[0] === 65 && appData[1] === 100 && appData[2] === 111 && appData[3] === 98 && appData[4] === 101 && appData[5] === 0) {
45713
+ adobe = {
45714
+ version: appData[6],
45715
+ flags0: appData[7] << 8 | appData[8],
45716
+ flags1: appData[9] << 8 | appData[10],
45717
+ transformCode: appData[11]
45718
+ };
45719
+ }
45720
+ }
45721
+ break;
45722
+ case 65499:
45723
+ var quantizationTablesLength = readUint16();
45724
+ var quantizationTablesEnd = quantizationTablesLength + offset - 2;
45725
+ while (offset < quantizationTablesEnd) {
45726
+ var quantizationTableSpec = data[offset++];
45727
+ requestMemoryAllocation(64 * 4);
45728
+ var tableData = new Int32Array(64);
45729
+ if (quantizationTableSpec >> 4 === 0) {
45730
+ for (j3 = 0; j3 < 64; j3++) {
45731
+ var z5 = dctZigZag[j3];
45732
+ tableData[z5] = data[offset++];
45733
+ }
45734
+ } else if (quantizationTableSpec >> 4 === 1) {
45735
+ for (j3 = 0; j3 < 64; j3++) {
45736
+ var z5 = dctZigZag[j3];
45737
+ tableData[z5] = readUint16();
45738
+ }
45739
+ } else
45740
+ throw new Error("DQT: invalid table spec");
45741
+ quantizationTables[quantizationTableSpec & 15] = tableData;
45742
+ }
45743
+ break;
45744
+ case 65472:
45745
+ // SOF0 (Start of Frame, Baseline DCT)
45746
+ case 65473:
45747
+ // SOF1 (Start of Frame, Extended DCT)
45748
+ case 65474:
45749
+ readUint16();
45750
+ frame = {};
45751
+ frame.extended = fileMarker === 65473;
45752
+ frame.progressive = fileMarker === 65474;
45753
+ frame.precision = data[offset++];
45754
+ frame.scanLines = readUint16();
45755
+ frame.samplesPerLine = readUint16();
45756
+ frame.components = {};
45757
+ frame.componentsOrder = [];
45758
+ var pixelsInFrame = frame.scanLines * frame.samplesPerLine;
45759
+ if (pixelsInFrame > maxResolutionInPixels) {
45760
+ var exceededAmount = Math.ceil((pixelsInFrame - maxResolutionInPixels) / 1e6);
45761
+ throw new Error(`maxResolutionInMP limit exceeded by ${exceededAmount}MP`);
45762
+ }
45763
+ var componentsCount = data[offset++], componentId;
45764
+ var maxH = 0, maxV = 0;
45765
+ for (i2 = 0; i2 < componentsCount; i2++) {
45766
+ componentId = data[offset];
45767
+ var h2 = data[offset + 1] >> 4;
45768
+ var v4 = data[offset + 1] & 15;
45769
+ var qId = data[offset + 2];
45770
+ if (h2 <= 0 || v4 <= 0) {
45771
+ throw new Error("Invalid sampling factor, expected values above 0");
45772
+ }
45773
+ frame.componentsOrder.push(componentId);
45774
+ frame.components[componentId] = {
45775
+ h: h2,
45776
+ v: v4,
45777
+ quantizationIdx: qId
45778
+ };
45779
+ offset += 3;
45780
+ }
45781
+ prepareComponents(frame);
45782
+ frames.push(frame);
45783
+ break;
45784
+ case 65476:
45785
+ var huffmanLength = readUint16();
45786
+ for (i2 = 2; i2 < huffmanLength; ) {
45787
+ var huffmanTableSpec = data[offset++];
45788
+ var codeLengths = new Uint8Array(16);
45789
+ var codeLengthSum = 0;
45790
+ for (j3 = 0; j3 < 16; j3++, offset++) {
45791
+ codeLengthSum += codeLengths[j3] = data[offset];
45792
+ }
45793
+ requestMemoryAllocation(16 + codeLengthSum);
45794
+ var huffmanValues = new Uint8Array(codeLengthSum);
45795
+ for (j3 = 0; j3 < codeLengthSum; j3++, offset++)
45796
+ huffmanValues[j3] = data[offset];
45797
+ i2 += 17 + codeLengthSum;
45798
+ (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
45799
+ }
45800
+ break;
45801
+ case 65501:
45802
+ readUint16();
45803
+ resetInterval = readUint16();
45804
+ break;
45805
+ case 65500:
45806
+ readUint16();
45807
+ readUint16();
45808
+ break;
45809
+ case 65498:
45810
+ var scanLength = readUint16();
45811
+ var selectorsCount = data[offset++];
45812
+ var components = [], component;
45813
+ for (i2 = 0; i2 < selectorsCount; i2++) {
45814
+ component = frame.components[data[offset++]];
45815
+ var tableSpec = data[offset++];
45816
+ component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
45817
+ component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
45818
+ components.push(component);
45819
+ }
45820
+ var spectralStart = data[offset++];
45821
+ var spectralEnd = data[offset++];
45822
+ var successiveApproximation = data[offset++];
45823
+ var processed = decodeScan(
45824
+ data,
45825
+ offset,
45826
+ frame,
45827
+ components,
45828
+ resetInterval,
45829
+ spectralStart,
45830
+ spectralEnd,
45831
+ successiveApproximation >> 4,
45832
+ successiveApproximation & 15,
45833
+ this.opts
45834
+ );
45835
+ offset += processed;
45836
+ break;
45837
+ case 65535:
45838
+ if (data[offset] !== 255) {
45839
+ offset--;
45840
+ }
45841
+ break;
45842
+ default:
45843
+ if (data[offset - 3] == 255 && data[offset - 2] >= 192 && data[offset - 2] <= 254) {
45844
+ offset -= 3;
45845
+ break;
45846
+ } else if (fileMarker === 224 || fileMarker == 225) {
45847
+ if (malformedDataOffset !== -1) {
45848
+ throw new Error(`first unknown JPEG marker at offset ${malformedDataOffset.toString(16)}, second unknown JPEG marker ${fileMarker.toString(16)} at offset ${(offset - 1).toString(16)}`);
45849
+ }
45850
+ malformedDataOffset = offset - 1;
45851
+ const nextOffset = readUint16();
45852
+ if (data[offset + nextOffset - 2] === 255) {
45853
+ offset += nextOffset - 2;
45854
+ break;
45855
+ }
45856
+ }
45857
+ throw new Error("unknown JPEG marker " + fileMarker.toString(16));
45858
+ }
45859
+ fileMarker = readUint16();
45860
+ }
45861
+ if (frames.length != 1)
45862
+ throw new Error("only single frame JPEGs supported");
45863
+ for (var i2 = 0; i2 < frames.length; i2++) {
45864
+ var cp3 = frames[i2].components;
45865
+ for (var j3 in cp3) {
45866
+ cp3[j3].quantizationTable = quantizationTables[cp3[j3].quantizationIdx];
45867
+ delete cp3[j3].quantizationIdx;
45868
+ }
45869
+ }
45870
+ this.width = frame.samplesPerLine;
45871
+ this.height = frame.scanLines;
45872
+ this.jfif = jfif;
45873
+ this.adobe = adobe;
45874
+ this.components = [];
45875
+ for (var i2 = 0; i2 < frame.componentsOrder.length; i2++) {
45876
+ var component = frame.components[frame.componentsOrder[i2]];
45877
+ this.components.push({
45878
+ lines: buildComponentData(frame, component),
45879
+ scaleX: component.h / frame.maxH,
45880
+ scaleY: component.v / frame.maxV
45881
+ });
45882
+ }
45883
+ },
45884
+ getData: function getData(width, height) {
45885
+ var scaleX = this.width / width, scaleY = this.height / height;
45886
+ var component1, component2, component3, component4;
45887
+ var component1Line, component2Line, component3Line, component4Line;
45888
+ var x4, y3;
45889
+ var offset = 0;
45890
+ var Y3, Cb, Cr2, K4, C5, M4, Ye2, R5, G3, B4;
45891
+ var colorTransform;
45892
+ var dataLength = width * height * this.components.length;
45893
+ requestMemoryAllocation(dataLength);
45894
+ var data = new Uint8Array(dataLength);
45895
+ switch (this.components.length) {
45896
+ case 1:
45897
+ component1 = this.components[0];
45898
+ for (y3 = 0; y3 < height; y3++) {
45899
+ component1Line = component1.lines[0 | y3 * component1.scaleY * scaleY];
45900
+ for (x4 = 0; x4 < width; x4++) {
45901
+ Y3 = component1Line[0 | x4 * component1.scaleX * scaleX];
45902
+ data[offset++] = Y3;
45903
+ }
45904
+ }
45905
+ break;
45906
+ case 2:
45907
+ component1 = this.components[0];
45908
+ component2 = this.components[1];
45909
+ for (y3 = 0; y3 < height; y3++) {
45910
+ component1Line = component1.lines[0 | y3 * component1.scaleY * scaleY];
45911
+ component2Line = component2.lines[0 | y3 * component2.scaleY * scaleY];
45912
+ for (x4 = 0; x4 < width; x4++) {
45913
+ Y3 = component1Line[0 | x4 * component1.scaleX * scaleX];
45914
+ data[offset++] = Y3;
45915
+ Y3 = component2Line[0 | x4 * component2.scaleX * scaleX];
45916
+ data[offset++] = Y3;
45917
+ }
45918
+ }
45919
+ break;
45920
+ case 3:
45921
+ colorTransform = true;
45922
+ if (this.adobe && this.adobe.transformCode)
45923
+ colorTransform = true;
45924
+ else if (typeof this.opts.colorTransform !== "undefined")
45925
+ colorTransform = !!this.opts.colorTransform;
45926
+ component1 = this.components[0];
45927
+ component2 = this.components[1];
45928
+ component3 = this.components[2];
45929
+ for (y3 = 0; y3 < height; y3++) {
45930
+ component1Line = component1.lines[0 | y3 * component1.scaleY * scaleY];
45931
+ component2Line = component2.lines[0 | y3 * component2.scaleY * scaleY];
45932
+ component3Line = component3.lines[0 | y3 * component3.scaleY * scaleY];
45933
+ for (x4 = 0; x4 < width; x4++) {
45934
+ if (!colorTransform) {
45935
+ R5 = component1Line[0 | x4 * component1.scaleX * scaleX];
45936
+ G3 = component2Line[0 | x4 * component2.scaleX * scaleX];
45937
+ B4 = component3Line[0 | x4 * component3.scaleX * scaleX];
45938
+ } else {
45939
+ Y3 = component1Line[0 | x4 * component1.scaleX * scaleX];
45940
+ Cb = component2Line[0 | x4 * component2.scaleX * scaleX];
45941
+ Cr2 = component3Line[0 | x4 * component3.scaleX * scaleX];
45942
+ R5 = clampTo8bit(Y3 + 1.402 * (Cr2 - 128));
45943
+ G3 = clampTo8bit(Y3 - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr2 - 128));
45944
+ B4 = clampTo8bit(Y3 + 1.772 * (Cb - 128));
45945
+ }
45946
+ data[offset++] = R5;
45947
+ data[offset++] = G3;
45948
+ data[offset++] = B4;
45949
+ }
45950
+ }
45951
+ break;
45952
+ case 4:
45953
+ if (!this.adobe)
45954
+ throw new Error("Unsupported color mode (4 components)");
45955
+ colorTransform = false;
45956
+ if (this.adobe && this.adobe.transformCode)
45957
+ colorTransform = true;
45958
+ else if (typeof this.opts.colorTransform !== "undefined")
45959
+ colorTransform = !!this.opts.colorTransform;
45960
+ component1 = this.components[0];
45961
+ component2 = this.components[1];
45962
+ component3 = this.components[2];
45963
+ component4 = this.components[3];
45964
+ for (y3 = 0; y3 < height; y3++) {
45965
+ component1Line = component1.lines[0 | y3 * component1.scaleY * scaleY];
45966
+ component2Line = component2.lines[0 | y3 * component2.scaleY * scaleY];
45967
+ component3Line = component3.lines[0 | y3 * component3.scaleY * scaleY];
45968
+ component4Line = component4.lines[0 | y3 * component4.scaleY * scaleY];
45969
+ for (x4 = 0; x4 < width; x4++) {
45970
+ if (!colorTransform) {
45971
+ C5 = component1Line[0 | x4 * component1.scaleX * scaleX];
45972
+ M4 = component2Line[0 | x4 * component2.scaleX * scaleX];
45973
+ Ye2 = component3Line[0 | x4 * component3.scaleX * scaleX];
45974
+ K4 = component4Line[0 | x4 * component4.scaleX * scaleX];
45975
+ } else {
45976
+ Y3 = component1Line[0 | x4 * component1.scaleX * scaleX];
45977
+ Cb = component2Line[0 | x4 * component2.scaleX * scaleX];
45978
+ Cr2 = component3Line[0 | x4 * component3.scaleX * scaleX];
45979
+ K4 = component4Line[0 | x4 * component4.scaleX * scaleX];
45980
+ C5 = 255 - clampTo8bit(Y3 + 1.402 * (Cr2 - 128));
45981
+ M4 = 255 - clampTo8bit(Y3 - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr2 - 128));
45982
+ Ye2 = 255 - clampTo8bit(Y3 + 1.772 * (Cb - 128));
45983
+ }
45984
+ data[offset++] = 255 - C5;
45985
+ data[offset++] = 255 - M4;
45986
+ data[offset++] = 255 - Ye2;
45987
+ data[offset++] = 255 - K4;
45988
+ }
45989
+ }
45990
+ break;
45991
+ default:
45992
+ throw new Error("Unsupported color mode");
45993
+ }
45994
+ return data;
45995
+ },
45996
+ copyToImageData: function copyToImageData(imageData, formatAsRGBA) {
45997
+ var width = imageData.width, height = imageData.height;
45998
+ var imageDataArray = imageData.data;
45999
+ var data = this.getData(width, height);
46000
+ var i2 = 0, j3 = 0, x4, y3;
46001
+ var Y3, K4, C5, M4, R5, G3, B4;
46002
+ switch (this.components.length) {
46003
+ case 1:
46004
+ for (y3 = 0; y3 < height; y3++) {
46005
+ for (x4 = 0; x4 < width; x4++) {
46006
+ Y3 = data[i2++];
46007
+ imageDataArray[j3++] = Y3;
46008
+ imageDataArray[j3++] = Y3;
46009
+ imageDataArray[j3++] = Y3;
46010
+ if (formatAsRGBA) {
46011
+ imageDataArray[j3++] = 255;
46012
+ }
46013
+ }
46014
+ }
46015
+ break;
46016
+ case 3:
46017
+ for (y3 = 0; y3 < height; y3++) {
46018
+ for (x4 = 0; x4 < width; x4++) {
46019
+ R5 = data[i2++];
46020
+ G3 = data[i2++];
46021
+ B4 = data[i2++];
46022
+ imageDataArray[j3++] = R5;
46023
+ imageDataArray[j3++] = G3;
46024
+ imageDataArray[j3++] = B4;
46025
+ if (formatAsRGBA) {
46026
+ imageDataArray[j3++] = 255;
46027
+ }
46028
+ }
46029
+ }
46030
+ break;
46031
+ case 4:
46032
+ for (y3 = 0; y3 < height; y3++) {
46033
+ for (x4 = 0; x4 < width; x4++) {
46034
+ C5 = data[i2++];
46035
+ M4 = data[i2++];
46036
+ Y3 = data[i2++];
46037
+ K4 = data[i2++];
46038
+ R5 = 255 - clampTo8bit(C5 * (1 - K4 / 255) + K4);
46039
+ G3 = 255 - clampTo8bit(M4 * (1 - K4 / 255) + K4);
46040
+ B4 = 255 - clampTo8bit(Y3 * (1 - K4 / 255) + K4);
46041
+ imageDataArray[j3++] = R5;
46042
+ imageDataArray[j3++] = G3;
46043
+ imageDataArray[j3++] = B4;
46044
+ if (formatAsRGBA) {
46045
+ imageDataArray[j3++] = 255;
46046
+ }
46047
+ }
46048
+ }
46049
+ break;
46050
+ default:
46051
+ throw new Error("Unsupported color mode");
46052
+ }
46053
+ }
46054
+ };
46055
+ var totalBytesAllocated = 0;
46056
+ var maxMemoryUsageBytes = 0;
46057
+ function requestMemoryAllocation(increaseAmount = 0) {
46058
+ var totalMemoryImpactBytes = totalBytesAllocated + increaseAmount;
46059
+ if (totalMemoryImpactBytes > maxMemoryUsageBytes) {
46060
+ var exceededAmount = Math.ceil((totalMemoryImpactBytes - maxMemoryUsageBytes) / 1024 / 1024);
46061
+ throw new Error(`maxMemoryUsageInMB limit exceeded by at least ${exceededAmount}MB`);
46062
+ }
46063
+ totalBytesAllocated = totalMemoryImpactBytes;
46064
+ }
46065
+ constructor.resetMaxMemoryUsage = function(maxMemoryUsageBytes_) {
46066
+ totalBytesAllocated = 0;
46067
+ maxMemoryUsageBytes = maxMemoryUsageBytes_;
46068
+ };
46069
+ constructor.getBytesAllocated = function() {
46070
+ return totalBytesAllocated;
46071
+ };
46072
+ constructor.requestMemoryAllocation = requestMemoryAllocation;
46073
+ return constructor;
46074
+ })();
46075
+ if (typeof module !== "undefined") {
46076
+ module.exports = decode3;
46077
+ } else if (typeof window !== "undefined") {
46078
+ window["jpeg-js"] = window["jpeg-js"] || {};
46079
+ window["jpeg-js"].decode = decode3;
46080
+ }
46081
+ function decode3(jpegData, userOpts = {}) {
46082
+ var defaultOpts = {
46083
+ // "undefined" means "Choose whether to transform colors based on the image’s color model."
46084
+ colorTransform: void 0,
46085
+ useTArray: false,
46086
+ formatAsRGBA: true,
46087
+ tolerantDecoding: true,
46088
+ maxResolutionInMP: 100,
46089
+ // Don't decode more than 100 megapixels
46090
+ maxMemoryUsageInMB: 512
46091
+ // Don't decode if memory footprint is more than 512MB
46092
+ };
46093
+ var opts = { ...defaultOpts, ...userOpts };
46094
+ var arr = new Uint8Array(jpegData);
46095
+ var decoder4 = new JpegImage();
46096
+ decoder4.opts = opts;
46097
+ JpegImage.resetMaxMemoryUsage(opts.maxMemoryUsageInMB * 1024 * 1024);
46098
+ decoder4.parse(arr);
46099
+ var channels = opts.formatAsRGBA ? 4 : 3;
46100
+ var bytesNeeded = decoder4.width * decoder4.height * channels;
46101
+ try {
46102
+ JpegImage.requestMemoryAllocation(bytesNeeded);
46103
+ var image = {
46104
+ width: decoder4.width,
46105
+ height: decoder4.height,
46106
+ exifBuffer: decoder4.exifBuffer,
46107
+ data: opts.useTArray ? new Uint8Array(bytesNeeded) : Buffer.alloc(bytesNeeded)
46108
+ };
46109
+ if (decoder4.comments.length > 0) {
46110
+ image["comments"] = decoder4.comments;
46111
+ }
46112
+ } catch (err) {
46113
+ if (err instanceof RangeError) {
46114
+ throw new Error("Could not allocate enough memory for the image. Required: " + bytesNeeded);
46115
+ }
46116
+ if (err instanceof ReferenceError) {
46117
+ if (err.message === "Buffer is not defined") {
46118
+ throw new Error("Buffer is not globally defined in this environment. Consider setting useTArray to true");
46119
+ }
46120
+ }
46121
+ throw err;
46122
+ }
46123
+ decoder4.copyToImageData(image, opts.formatAsRGBA);
46124
+ return image;
46125
+ }
46126
+ }
46127
+ });
46128
+
46129
+ // ../../node_modules/jpeg-js/index.js
46130
+ var require_jpeg_js = __commonJS({
46131
+ "../../node_modules/jpeg-js/index.js"(exports, module) {
46132
+ var encode4 = require_encoder();
46133
+ var decode3 = require_decoder();
46134
+ module.exports = {
46135
+ encode: encode4,
46136
+ decode: decode3
46137
+ };
46138
+ }
46139
+ });
46140
+
43879
46141
  // ../../packages/codex/src/account-store.ts
43880
46142
  import { randomUUID as randomUUID8 } from "node:crypto";
43881
46143
  import { copyFileSync, existsSync as existsSync16, lstatSync, mkdirSync as mkdirSync6, readFileSync as readFileSync15, readdirSync as readdirSync7, renameSync, symlinkSync, writeFileSync as writeFileSync6 } from "node:fs";
@@ -44613,12 +46875,12 @@ function createCodexMcpAppsProvider(binding, threadId, request, connectionKey =
44613
46875
  },
44614
46876
  tools,
44615
46877
  async readResource(req, signal2) {
44616
- const document = req.uri.startsWith("ui://");
44617
- if (!document && !req.transient) throw new McpAppsError("invalid", "MCP App resources must use ui://");
46878
+ const document2 = req.uri.startsWith("ui://");
46879
+ if (!document2 && !req.transient) throw new McpAppsError("invalid", "MCP App resources must use ui://");
44618
46880
  guard(signal2, req.origin);
44619
46881
  const result3 = await invoke("mcpServer/resource/read", { uri: req.uri }, signal2, req.origin, false, req.transient ? MCP_APP_OUTPUT_MAX_BYTES : MCP_APP_HTML_MAX_BYTES + MCP_APP_DATA_MAX_BYTES);
44620
46882
  const rawContents = Array.isArray(result3.contents) ? result3.contents : [];
44621
- if (!document) return { contents: rawContents, ...record9(result3._meta) ? { _meta: record9(result3._meta) } : {} };
46883
+ if (!document2) return { contents: rawContents, ...record9(result3._meta) ? { _meta: record9(result3._meta) } : {} };
44622
46884
  let listMeta;
44623
46885
  if (rawContents.some((value) => record9(value)?.uri === req.uri && !record9(record9(record9(value)?._meta)?.ui))) {
44624
46886
  const server = (await catalog("full")).find((entry3) => entry3.name === binding.server);
@@ -48461,12 +50723,12 @@ var init_provider_settings_env = __esm({
48461
50723
  });
48462
50724
 
48463
50725
  // ../../packages/claude/src/resolve-sdk-binary.ts
48464
- import { createRequire as createRequire2 } from "node:module";
50726
+ import { createRequire } from "node:module";
48465
50727
  import { existsSync as existsSync18 } from "node:fs";
48466
50728
  function resolveSdkClaudeBinary() {
48467
50729
  if (cached2 !== void 0) return cached2;
48468
50730
  try {
48469
- const req = createRequire2(import.meta.url);
50731
+ const req = createRequire(import.meta.url);
48470
50732
  const ext = process.platform === "win32" ? ".exe" : "";
48471
50733
  const candidates = process.platform === "linux" ? [
48472
50734
  `@anthropic-ai/claude-agent-sdk-linux-${process.arch}-musl/claude${ext}`,
@@ -69913,10 +72175,10 @@ var init_managed_tarball_installer = __esm({
69913
72175
  });
69914
72176
 
69915
72177
  // ../../packages/runtime/src/harness/cursor-availability.ts
69916
- import { createRequire as createRequire3 } from "node:module";
72178
+ import { createRequire as createRequire2 } from "node:module";
69917
72179
  function isCursorSdkAvailable() {
69918
72180
  try {
69919
- require3.resolve("@cursor/sdk");
72181
+ require2.resolve("@cursor/sdk");
69920
72182
  return true;
69921
72183
  } catch {
69922
72184
  return false;
@@ -69926,11 +72188,11 @@ function resolveCursorApiKeyPlain() {
69926
72188
  const v4 = process.env.CURSOR_API_KEY?.trim();
69927
72189
  return v4 || void 0;
69928
72190
  }
69929
- var require3;
72191
+ var require2;
69930
72192
  var init_cursor_availability = __esm({
69931
72193
  "../../packages/runtime/src/harness/cursor-availability.ts"() {
69932
72194
  "use strict";
69933
- require3 = createRequire3(import.meta.url);
72195
+ require2 = createRequire2(import.meta.url);
69934
72196
  }
69935
72197
  });
69936
72198
 
@@ -105877,26 +108139,26 @@ var init_cursor_config = __esm({
105877
108139
  });
105878
108140
 
105879
108141
  // ../../packages/cursor/src/cursor-sdk-available.ts
105880
- import { createRequire as createRequire4 } from "node:module";
108142
+ import { createRequire as createRequire3 } from "node:module";
105881
108143
  function isCursorSdkAvailable2() {
105882
108144
  try {
105883
- require4.resolve("@cursor/sdk");
108145
+ require3.resolve("@cursor/sdk");
105884
108146
  return true;
105885
108147
  } catch {
105886
108148
  return false;
105887
108149
  }
105888
108150
  }
105889
- var require4;
108151
+ var require3;
105890
108152
  var init_cursor_sdk_available = __esm({
105891
108153
  "../../packages/cursor/src/cursor-sdk-available.ts"() {
105892
108154
  "use strict";
105893
- require4 = createRequire4(import.meta.url);
108155
+ require3 = createRequire3(import.meta.url);
105894
108156
  }
105895
108157
  });
105896
108158
 
105897
108159
  // ../../packages/cursor/src/cursor-platform-binaries.ts
105898
108160
  import { existsSync as existsSync42, statSync as statSync12 } from "node:fs";
105899
- import { createRequire as createRequire5 } from "node:module";
108161
+ import { createRequire as createRequire4 } from "node:module";
105900
108162
  import { dirname as dirname18, join as join43 } from "node:path";
105901
108163
  function cursorPlatformPackageName(platform3 = process.platform, arch2 = process.arch) {
105902
108164
  return `@cursor/sdk-${platform3}-${arch2}`;
@@ -105916,7 +108178,7 @@ function isExecutableFile2(candidate) {
105916
108178
  }
105917
108179
  function cursorSdkRequire() {
105918
108180
  try {
105919
- return createRequire5(requireFromHere.resolve("@cursor/sdk/package.json"));
108181
+ return createRequire4(requireFromHere.resolve("@cursor/sdk/package.json"));
105920
108182
  } catch {
105921
108183
  return requireFromHere;
105922
108184
  }
@@ -106022,7 +108284,7 @@ var requireFromHere, lookupDepth, savedArgv1;
106022
108284
  var init_cursor_platform_binaries = __esm({
106023
108285
  "../../packages/cursor/src/cursor-platform-binaries.ts"() {
106024
108286
  "use strict";
106025
- requireFromHere = createRequire5(import.meta.url);
108287
+ requireFromHere = createRequire4(import.meta.url);
106026
108288
  lookupDepth = 0;
106027
108289
  }
106028
108290
  });
@@ -121310,6 +123572,7 @@ function utf8Length(input) {
121310
123572
 
121311
123573
  // ../../packages/shared/src/transcript-window/fragment-message.ts
121312
123574
  init_codex_content();
123575
+ init_transcript_boundary();
121313
123576
 
121314
123577
  // ../../packages/shared/src/transcript-window/text-cuts.ts
121315
123578
  var FRAGMENT_TEXT_CHARS = 4096;
@@ -121413,9 +123676,12 @@ var MessageFragmenter = class {
121413
123676
  const fragments = (message.attachments ?? []).map((attachment, index) => attachmentEntry(index, attachment));
121414
123677
  const blocks = fragments.map(() => -1);
121415
123678
  const keys = blockKeys(content);
123679
+ const contentKeyList = contentKeys(content);
121416
123680
  content.forEach((block, index) => {
121417
123681
  const key3 = keys[index];
121418
123682
  const memo = blockFragments(block, key3, previous?.get(key3));
123683
+ const contentKey = contentKeyList[index];
123684
+ for (const entry3 of memo.entries) if (entry3.contentKey !== contentKey) entry3.contentKey = contentKey;
121419
123685
  next.set(key3, memo);
121420
123686
  fragments.push(...memo.entries);
121421
123687
  for (let i2 = 0; i2 < memo.entries.length; i2++) blocks.push(index);
@@ -121664,7 +123930,12 @@ function selectTranscriptWindow(source, request, budget) {
121664
123930
  const message = source.at(index);
121665
123931
  const range2 = selected.get(index);
121666
123932
  const held = have.get(message.id);
121667
- const fragments = message.fragments.slice(range2.first, range2.last + 1).map((fragment) => held?.f.get(fragment.key) === fragment.digest ? { key: fragment.key, digest: fragment.digest } : { key: fragment.key, digest: fragment.digest, body: fragment.body });
123933
+ const fragments = message.fragments.slice(range2.first, range2.last + 1).map((fragment) => ({
123934
+ key: fragment.key,
123935
+ digest: fragment.digest,
123936
+ ...fragment.contentKey ? { contentKey: fragment.contentKey } : {},
123937
+ ...held?.f.get(fragment.key) === fragment.digest ? {} : { body: fragment.body }
123938
+ }));
121668
123939
  const total = message.fragments.length;
121669
123940
  return {
121670
123941
  id: message.id,
@@ -121832,7 +124103,7 @@ function transcriptView(messages) {
121832
124103
  rows.push({ id: source.id, message: source, source, final: true });
121833
124104
  continue;
121834
124105
  }
121835
- const cuts = (boundaries.get(source.id) ?? []).sort((a2, b5) => a2.metadata.transcriptBoundary.order - b5.metadata.transcriptBoundary.order);
124106
+ const cuts = (boundaries.get(source.id) ?? []).filter((cut) => boundaryInWindow(cut.metadata.transcriptBoundary, source)).sort((a2, b5) => a2.metadata.transcriptBoundary.order - b5.metadata.transcriptBoundary.order);
121836
124107
  const cached5 = cachedSegments.get(source);
121837
124108
  if (cached5 && cached5.cuts.length === cuts.length && cached5.cuts.every((cut, index) => cut === cuts[index])) {
121838
124109
  result3.push(...cached5.segments);
@@ -122882,11 +125153,57 @@ function summarizeClaudeProcessFiles(segs, opts) {
122882
125153
  var MIN_FOLD_BLOCKS = 4;
122883
125154
  var NO_FOLDS = { ranges: [], summarize: () => ({ segments: 0, toolCalls: 0, files: [], added: 0, removed: 0, contentKey: "" }) };
122884
125155
  function planProcessFolds(message, context) {
122885
- if (message.role !== "assistant" || message.status === "streaming") return NO_FOLDS;
125156
+ if (message.role !== "assistant") return NO_FOLDS;
122886
125157
  const cuts = (context?.cuts ?? []).filter((cut) => cut.metadata?.transcriptBoundary?.messageId === message.id);
125158
+ if (message.status === "streaming") {
125159
+ if (!cuts.length || !message.id || isLegacyCodexMessage(message)) return NO_FOLDS;
125160
+ return planStreamingCuts(message, cuts);
125161
+ }
122887
125162
  if (cuts.length > 0 && message.id && !isLegacyCodexMessage(message)) return planSliced(message, cuts);
122888
125163
  return planContent(message, message.content);
122889
125164
  }
125165
+ var streamingPlans = /* @__PURE__ */ new Map();
125166
+ function planStreamingCuts(message, cuts) {
125167
+ const liveFrom = openSuffixStart(message, cuts);
125168
+ if (liveFrom <= 0) return NO_FOLDS;
125169
+ const closedKeys = contentKeys(message.content.slice(0, liveFrom)).join("\n");
125170
+ const cacheKey3 = `${message.id}:${liveFrom}:${closedKeys}:${cuts.map((cut) => `${cut.id}:${cut.metadata?.transcriptBoundary?.order ?? ""}`).join("|")}`;
125171
+ const cached5 = streamingPlans.get(cacheKey3);
125172
+ if (cached5) return cached5;
125173
+ const planned = planSliced({ ...message, status: "complete" }, cuts);
125174
+ const ranges = [];
125175
+ for (const range2 of planned.ranges) {
125176
+ if (range2.start >= liveFrom) continue;
125177
+ const end = Math.min(range2.end, liveFrom - 1);
125178
+ if (end - range2.start + 1 < MIN_FOLD_BLOCKS) continue;
125179
+ ranges.push(end === range2.end ? range2 : { ...range2, end, summary: planned.summarize(range2.start, end) });
125180
+ }
125181
+ const plan = { ranges, summarize: planned.summarize, liveFrom };
125182
+ streamingPlans.set(cacheKey3, plan);
125183
+ if (streamingPlans.size > 32) streamingPlans.delete(streamingPlans.keys().next().value);
125184
+ return plan;
125185
+ }
125186
+ function openSuffixStart(message, cuts) {
125187
+ const latest = cuts.reduce((best, cut) => cut.metadata.transcriptBoundary.order > best.metadata.transcriptBoundary.order ? cut : best);
125188
+ const boundary = latest.metadata?.transcriptBoundary;
125189
+ if (!boundary) return message.content.length;
125190
+ const source = message;
125191
+ const cursor = boundary.cursor ? boundary : boundaryCursor(boundary, source);
125192
+ const keys = contentKeys(message.content);
125193
+ if (cursor.at) {
125194
+ const index = keys.indexOf(cursor.at);
125195
+ return index < 0 ? message.content.length : index;
125196
+ }
125197
+ if (cursor.cursor) return message.content.length;
125198
+ const map2 = boundary.content ?? {};
125199
+ for (let index = 0; index < keys.length; index++) {
125200
+ const saved = map2[keys[index]];
125201
+ const text3 = blockText(message.content[index]);
125202
+ if (saved === void 0) return index;
125203
+ if (text3 !== void 0 && saved < text3.length) return index;
125204
+ }
125205
+ return message.content.length;
125206
+ }
122890
125207
  function planSliced(message, cuts) {
122891
125208
  const source = {
122892
125209
  id: message.id,
@@ -122905,19 +125222,29 @@ function planSliced(message, cuts) {
122905
125222
  const anchored = /* @__PURE__ */ new Map();
122906
125223
  const calls2 = /* @__PURE__ */ new Set();
122907
125224
  const sliceEnds = /* @__PURE__ */ new Set();
125225
+ const spans = [];
122908
125226
  for (const row2 of transcriptView([source, ...cuts]).rows) {
122909
125227
  if (row2.source.id !== source.id) continue;
122910
- let last = -1;
125228
+ const indexes = [];
122911
125229
  for (const block of row2.message.content) {
122912
125230
  const index = indexOf.get(block);
122913
- if (index !== void 0) last = Math.max(last, index);
125231
+ if (index !== void 0) indexes.push(index);
122914
125232
  }
122915
- if (last >= 0) sliceEnds.add(last);
125233
+ spans.push(indexes);
122916
125234
  const slice = groupTurn(turnDisplayContent(row2.message));
122917
125235
  const following = row2.following ? groupTurn(turnDisplayContent(row2.following)) : void 0;
122918
125236
  const runs = compactTurnRuns(slice.segments, isPortablePinnedSegment, { source: grouped.segments, following: following?.segments });
122919
125237
  markFoldable(runs, (block) => indexOf.get(block), foldable, anchored, calls2);
122920
125238
  }
125239
+ spans.forEach((indexes, span) => {
125240
+ let nextStart = Number.POSITIVE_INFINITY;
125241
+ for (let later = span + 1; later < spans.length; later++) {
125242
+ for (const index of spans[later]) if (index < nextStart) nextStart = index;
125243
+ }
125244
+ let end = -1;
125245
+ for (const index of indexes) if (index < nextStart && index > end) end = index;
125246
+ if (end >= 0) sliceEnds.add(end);
125247
+ });
122921
125248
  for (const block of message.content) {
122922
125249
  const index = indexOf.get(block);
122923
125250
  if (index !== void 0 && isToolResultBlock(block) && calls2.has(block.toolUseId)) foldable[index] = block;
@@ -123124,7 +125451,7 @@ var SessionFragments = class {
123124
125451
  folded(message, cuts) {
123125
125452
  const cutKey = foldCutKey(cuts);
123126
125453
  const cached5 = this.foldedCache.get(message);
123127
- if (cached5 && (cuts === void 0 || cached5.cutKey === cutKey)) return cached5.view;
125454
+ if (cached5 && message.status !== "streaming" && (cuts === void 0 || cached5.cutKey === cutKey)) return cached5.view;
123128
125455
  const contentKey = foldContentKey(message);
123129
125456
  const stored = this.bySignature.get(message.id);
123130
125457
  if (stored && stored.contentKey === contentKey && (cuts === void 0 || stored.cutKey === cutKey)) {
@@ -123136,7 +125463,12 @@ var SessionFragments = class {
123136
125463
  const content = readableContent(projected);
123137
125464
  const planning = content === projected.content ? projected : { ...projected, content: [...content] };
123138
125465
  const plan = planProcessFolds(planning, cuts?.length ? { cuts } : void 0);
123139
- const view = { fragments: foldMessageFragments(fragments, plan.ranges), plan };
125466
+ const folded = foldMessageFragments(fragments, plan.ranges);
125467
+ if (plan.liveFrom !== void 0 && plan.liveFrom > 0) {
125468
+ const at2 = folded.blocks.findIndex((block) => block >= plan.liveFrom);
125469
+ folded.livePin = at2 < 0 ? folded.fragments.length : at2;
125470
+ }
125471
+ const view = { fragments: folded, plan };
123140
125472
  this.bySignature.set(message.id, { contentKey, cutKey, view });
123141
125473
  this.foldedCache.set(message, { cutKey, view });
123142
125474
  return view;
@@ -123198,6 +125530,20 @@ var WindowViews = class {
123198
125530
  const extend2 = input.request.anchor && input.request.direction !== "around" ? input.request.direction ?? "before" : null;
123199
125531
  const previous = session.holders.get(input.holder);
123200
125532
  const held = extend2 && previous?.folds === folds ? previous : { messages: /* @__PURE__ */ new Map(), order: [], atTail: false, total: 0, seen: /* @__PURE__ */ new Map(), folds };
125533
+ const liveBudget = Math.min(input.budget.maxBytes, LIVE_MESSAGE_BUDGET.maxBytes);
125534
+ if (!extend2) {
125535
+ selected.messages = selected.messages.map((message) => {
125536
+ const source = transcript.messageAt(message.index);
125537
+ return clipWindowMessage(message, session.fragments.of(source, folds, cuts.get(source.id)), liveBudget);
125538
+ });
125539
+ selected.messages = withCuttingRows(selected.messages, transcript, session.fragments, folds, cuts);
125540
+ const first = selected.messages[0];
125541
+ const last = selected.messages[selected.messages.length - 1];
125542
+ if (first && last) {
125543
+ selected.older = first.index === 0 && first.omittedBefore === 0 ? null : windowAnchor(first, "first");
125544
+ selected.newer = last.index === transcript.count - 1 && last.omittedAfter === 0 ? null : windowAnchor(last, "last");
125545
+ }
125546
+ }
123201
125547
  for (const message of selected.messages) {
123202
125548
  const source = transcript.messageAt(message.index);
123203
125549
  const fragments = session.fragments.of(source, folds, cuts.get(source.id));
@@ -123426,6 +125772,8 @@ function diffHeld(held, messages, fragments, cuts) {
123426
125772
  };
123427
125773
  }
123428
125774
  function diffMessage(previous, current, index, maxBytes) {
125775
+ const pin = livePin(current);
125776
+ if (pin > 0 && !(previous && previous.omittedAfter > 0)) return diffClipped(previous, current, index, maxBytes, pin);
123429
125777
  const all2 = current.fragments;
123430
125778
  let start;
123431
125779
  let end = all2.length;
@@ -123470,15 +125818,121 @@ function diffMessage(previous, current, index, maxBytes) {
123470
125818
  }
123471
125819
  };
123472
125820
  }
125821
+ function livePin(fragments) {
125822
+ const pin = fragments.livePin ?? 0;
125823
+ if (pin <= 0) return 0;
125824
+ return Math.min(pin, fragments.fragments.length);
125825
+ }
125826
+ function clipLive(current, pin, maxBytes) {
125827
+ const all2 = current.fragments;
125828
+ const closedEnd = Math.min(pin, all2.length);
125829
+ const room = Math.max(0, maxBytes - current.metaBytes);
125830
+ const suffix = all2.slice(closedEnd);
125831
+ const reserve = suffix.length ? Math.min(suffix[suffix.length - 1].bytes, room) : 0;
125832
+ const closedBudget = Math.max(0, room - reserve);
125833
+ let closedStart = closedEnd;
125834
+ let closedBytes = 0;
125835
+ while (closedStart > 0) {
125836
+ const next = all2[closedStart - 1];
125837
+ if (closedBytes + next.bytes > closedBudget && closedEnd - closedStart > 0) break;
125838
+ closedBytes += next.bytes;
125839
+ closedStart--;
125840
+ }
125841
+ const suffixBudget = Math.max(0, room - closedBytes);
125842
+ let suffixStart = suffix.length;
125843
+ let suffixBytes = 0;
125844
+ let suffixCount = 0;
125845
+ while (suffixStart > 0) {
125846
+ const next = suffix[suffixStart - 1];
125847
+ if (suffixCount > 0 && (suffixCount >= LIVE_MESSAGE_BUDGET.maxFragments || suffixBytes + next.bytes > suffixBudget)) break;
125848
+ suffixBytes += next.bytes;
125849
+ suffixCount++;
125850
+ suffixStart--;
125851
+ }
125852
+ const gapped = suffixStart > 0;
125853
+ return {
125854
+ entries: [...all2.slice(closedStart, closedEnd), ...suffix.slice(suffixStart)],
125855
+ omittedBefore: gapped ? Math.max(closedStart, 1) : closedStart
125856
+ };
125857
+ }
125858
+ function wireFragment(fragment) {
125859
+ return {
125860
+ key: fragment.key,
125861
+ digest: fragment.digest,
125862
+ ...fragment.contentKey ? { contentKey: fragment.contentKey } : {},
125863
+ body: fragment.body
125864
+ };
125865
+ }
125866
+ function withCuttingRows(messages, transcript, fragments, folds, cuts) {
125867
+ const held = new Set(messages.map((message) => message.id));
125868
+ const added = [];
125869
+ for (const message of messages) {
125870
+ const source = transcript.messageAt(message.index);
125871
+ if (!livePin(fragments.of(source, folds, cuts.get(source.id)))) continue;
125872
+ for (const cut of cuts.get(source.id) ?? []) {
125873
+ if (held.has(cut.id)) continue;
125874
+ const index = transcript.indexOf(cut.id);
125875
+ if (index < 0) continue;
125876
+ const row2 = transcript.messageAt(index);
125877
+ const view = fragments.of(row2, folds, cuts.get(row2.id));
125878
+ added.push({
125879
+ id: view.id,
125880
+ index,
125881
+ metaDigest: view.metaDigest,
125882
+ meta: view.meta,
125883
+ fragments: view.fragments.map(wireFragment),
125884
+ omittedBefore: 0,
125885
+ omittedAfter: 0
125886
+ });
125887
+ held.add(cut.id);
125888
+ }
125889
+ }
125890
+ if (!added.length) return messages;
125891
+ return [...messages, ...added].sort((a2, b5) => a2.index - b5.index);
125892
+ }
125893
+ function clipWindowMessage(message, fragments, maxBytes) {
125894
+ const pin = livePin(fragments);
125895
+ if (!pin) return message;
125896
+ const clip = clipLive(fragments, pin, maxBytes);
125897
+ return { ...message, fragments: clip.entries.map(wireFragment), omittedBefore: clip.omittedBefore, omittedAfter: 0 };
125898
+ }
125899
+ function diffClipped(previous, current, index, maxBytes, pin) {
125900
+ const clip = clipLive(current, pin, maxBytes);
125901
+ const sent = diffFragments(previous, clip.entries);
125902
+ const metaHeld = previous?.metaDigest === current.metaDigest;
125903
+ const omittedBefore = clip.omittedBefore;
125904
+ const unchanged = previous && metaHeld && previous.omittedBefore === omittedBefore && previous.omittedAfter === 0 && previous.keys.length === sent.length && sent.every((fragment, i2) => !fragment.body && fragment.append === void 0 && previous.keys[i2] === fragment.key);
125905
+ const record13 = {
125906
+ metaDigest: current.metaDigest,
125907
+ keys: sent.map((fragment) => fragment.key),
125908
+ fragments: new Map(clip.entries.map((fragment) => [fragment.key, heldFragment(fragment.digest, fragment.body)])),
125909
+ omittedBefore,
125910
+ omittedAfter: 0
125911
+ };
125912
+ if (unchanged) return { message: null, record: record13 };
125913
+ return {
125914
+ record: record13,
125915
+ message: {
125916
+ id: current.id,
125917
+ index,
125918
+ metaDigest: current.metaDigest,
125919
+ ...metaHeld ? {} : { meta: current.meta },
125920
+ fragments: sent,
125921
+ omittedBefore,
125922
+ omittedAfter: 0
125923
+ }
125924
+ };
125925
+ }
123473
125926
  function diffFragments(previous, fragments) {
123474
125927
  return fragments.map((fragment) => {
123475
125928
  const heldFragment2 = previous?.fragments.get(fragment.key);
123476
- if (heldFragment2?.digest === fragment.digest) return { key: fragment.key, digest: fragment.digest };
125929
+ const contentKey = fragment.contentKey ? { contentKey: fragment.contentKey } : {};
125930
+ if (heldFragment2?.digest === fragment.digest) return { key: fragment.key, digest: fragment.digest, ...contentKey };
123477
125931
  const body3 = fragment.body;
123478
125932
  if (heldFragment2?.textLength !== void 0 && body3.kind === "text" && body3.text.length > heldFragment2.textLength && fragmentDigest(textBody(body3.head, body3.offset, body3.text.slice(0, heldFragment2.textLength), body3.context)) === heldFragment2.digest) {
123479
- return { key: fragment.key, digest: fragment.digest, append: body3.text.slice(heldFragment2.textLength) };
125933
+ return { key: fragment.key, digest: fragment.digest, append: body3.text.slice(heldFragment2.textLength), ...contentKey };
123480
125934
  }
123481
- return { key: fragment.key, digest: fragment.digest, body: body3 };
125935
+ return { key: fragment.key, digest: fragment.digest, body: body3, ...contentKey };
123482
125936
  });
123483
125937
  }
123484
125938
  function fragmentPatchBytes(fragment) {
@@ -124540,9 +126994,7 @@ async function handleSessionCreate(payload, ctx) {
124540
126994
  };
124541
126995
  }
124542
126996
  const catalogReady = ctx.harnesses.isSessionHarnessRunnable(harnessId);
124543
- const codexOverride = harnessId === "codex" && ctx.hooks.isCodexBinaryOverrideRunnable();
124544
- const claudeOverride = harnessId === "claude" && ctx.hooks.isClaudeBinaryOverrideRunnable();
124545
- if (!catalogReady && !codexOverride && !claudeOverride) {
126997
+ if (!catalogReady) {
124546
126998
  return {
124547
126999
  error: {
124548
127000
  code: "failed_precondition",
@@ -128122,12 +130574,6 @@ async function handleDescriptor(ctx) {
128122
130574
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readEnvironment);
128123
130575
  if (denied) return denied;
128124
130576
  const harnessIds = ctx.harnesses ? [...ctx.harnesses.readySessionHarnessIds()] : [];
128125
- if (ctx.harnesses && ctx.hooks.isCodexBinaryOverrideRunnable() && !harnessIds.includes("codex")) {
128126
- harnessIds.push("codex");
128127
- }
128128
- if (ctx.harnesses && ctx.hooks.isClaudeBinaryOverrideRunnable() && !harnessIds.includes("claude")) {
128129
- harnessIds.push("claude");
128130
- }
128131
130577
  let cliVersion;
128132
130578
  try {
128133
130579
  cliVersion = ctx.hooks.resolveReleaseVersion();
@@ -128181,8 +130627,10 @@ function handleHarnessProbe(payload, ctx) {
128181
130627
  if (!isNodeHarnessId(id)) {
128182
130628
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
128183
130629
  }
130630
+ const before = advertisedHarnessKey(ctx);
128184
130631
  try {
128185
130632
  const result3 = ctx.hooks.probeHarnessReadiness(ctx.harnesses, id, ctx.providers ?? null);
130633
+ publishHarnessCatalogIfChanged(ctx, before);
128186
130634
  return { result: { ...result3, status: ctx.harnesses.get(id) } };
128187
130635
  } catch (err) {
128188
130636
  return mapThrown(err);
@@ -128196,6 +130644,7 @@ async function handleHarnessEnable(payload, ctx) {
128196
130644
  if (!isNodeHarnessId(id)) {
128197
130645
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
128198
130646
  }
130647
+ const before = advertisedHarnessKey(ctx);
128199
130648
  try {
128200
130649
  const args = Array.isArray(p4.args) ? p4.args.filter((a2) => typeof a2 === "string") : void 0;
128201
130650
  const status2 = await ctx.hooks.enableHarness(
@@ -128209,6 +130658,7 @@ async function handleHarnessEnable(payload, ctx) {
128209
130658
  },
128210
130659
  ctx.providers ?? null
128211
130660
  );
130661
+ publishHarnessCatalogIfChanged(ctx, before);
128212
130662
  return { result: status2 };
128213
130663
  } catch (err) {
128214
130664
  return mapThrown(err);
@@ -128222,12 +130672,34 @@ function handleHarnessDisable(payload, ctx) {
128222
130672
  if (!isNodeHarnessId(id)) {
128223
130673
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
128224
130674
  }
130675
+ const before = advertisedHarnessKey(ctx);
128225
130676
  try {
128226
- return { result: ctx.hooks.disableHarness(ctx.harnesses, id) };
130677
+ const status2 = ctx.hooks.disableHarness(ctx.harnesses, id);
130678
+ publishHarnessCatalogIfChanged(ctx, before);
130679
+ return { result: status2 };
128227
130680
  } catch (err) {
128228
130681
  return mapThrown(err);
128229
130682
  }
128230
130683
  }
130684
+ function advertisedHarnessKey(ctx) {
130685
+ if (!ctx.events || !ctx.harnesses) return null;
130686
+ return harnessAdvertisementKey(ctx.harnesses.readySessionHarnessIds());
130687
+ }
130688
+ function publishHarnessCatalogIfChanged(ctx, before) {
130689
+ if (!ctx.events || !ctx.harnesses || before == null) return;
130690
+ const harnessIds = [...ctx.harnesses.readySessionHarnessIds()];
130691
+ if (harnessAdvertisementKey(harnessIds) === before) return;
130692
+ try {
130693
+ ctx.events.append({
130694
+ aggregateType: "environment",
130695
+ aggregateId: ctx.identity.environmentId,
130696
+ eventType: HARNESS_CATALOG_CHANGED,
130697
+ payload: { harnessIds },
130698
+ causationRequestId: ctx.requestId
130699
+ });
130700
+ } catch {
130701
+ }
130702
+ }
128231
130703
  function handleHealth(ctx) {
128232
130704
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readEnvironment);
128233
130705
  if (denied) return denied;
@@ -130473,21 +132945,19 @@ function listWorkflowAgentsSync2(transcriptDir) {
130473
132945
  }
130474
132946
 
130475
132947
  // src/session/thumbnail-encoder.ts
130476
- import { createRequire } from "node:module";
130477
132948
  import { inflateSync } from "node:zlib";
130478
- var require2 = createRequire(import.meta.url);
130479
- var jpeg = require2("jpeg-js");
132949
+ var import_jpeg_js = __toESM(require_jpeg_js(), 1);
130480
132950
  var MAX_PIXELS = 8e3 * 8e3;
130481
132951
  function encodeNodeThumbnail(bytes, mimeType) {
130482
132952
  const decoded = mimeType === "image/png" || bytes[0] === 137 ? decodePng(bytes) : mimeType === "image/jpeg" || bytes[0] === 255 && bytes[1] === 216 ? decodeJpeg(bytes) : null;
130483
132953
  if (!decoded) return null;
130484
132954
  const fitted = fit(decoded, ATTACHMENT_THUMBNAIL_MAX_SIDE);
130485
- const encoded = jpeg.encode({ data: fitted.data, width: fitted.width, height: fitted.height }, THUMBNAIL_JPEG_QUALITY);
132955
+ const encoded = import_jpeg_js.default.encode({ data: fitted.data, width: fitted.width, height: fitted.height }, THUMBNAIL_JPEG_QUALITY);
130486
132956
  return { base64: Buffer.from(encoded.data).toString("base64"), mimeType: "image/jpeg" };
130487
132957
  }
130488
132958
  function decodeJpeg(bytes) {
130489
132959
  try {
130490
- const raw2 = jpeg.decode(bytes, { useTArray: true, formatAsRGBA: true });
132960
+ const raw2 = import_jpeg_js.default.decode(bytes, { useTArray: true, formatAsRGBA: true });
130491
132961
  if (!raw2.width || !raw2.height || raw2.width * raw2.height > MAX_PIXELS) return null;
130492
132962
  return { width: raw2.width, height: raw2.height, data: raw2.data };
130493
132963
  } catch {
@@ -130608,7 +133078,84 @@ function installNodeRemoteContent() {
130608
133078
 
130609
133079
  // src/runtime.ts
130610
133080
  init_codex_accounts2();
130611
- import { existsSync as existsSync55, readFileSync as readFileSync31, writeFileSync as writeFileSync23 } from "node:fs";
133081
+ import { existsSync as existsSync55, readFileSync as readFileSync31, writeFileSync as writeFileSync25 } from "node:fs";
133082
+
133083
+ // src/session/harness-catalog-watch.ts
133084
+ init_environment();
133085
+ init_config();
133086
+ import { watch, writeFileSync as writeFileSync20 } from "node:fs";
133087
+ import { basename as basename6 } from "node:path";
133088
+
133089
+ // src/session/harness-catalog-stamp.ts
133090
+ init_config();
133091
+ init_environment();
133092
+ import { writeFileSync as writeFileSync19 } from "node:fs";
133093
+ function signalHarnessCatalogChanged(nodeHome) {
133094
+ try {
133095
+ writeFileSync19(nodePaths(nodeHome).harnessCatalogStamp, `${Date.now()}
133096
+ `);
133097
+ } catch {
133098
+ }
133099
+ }
133100
+ function createHarnessCatalogNotifier(readIds, publish2) {
133101
+ let lastKey = harnessAdvertisementKey(readIds());
133102
+ return {
133103
+ note() {
133104
+ const ids = [...readIds()];
133105
+ const next = harnessAdvertisementKey(ids);
133106
+ if (next === lastKey) return false;
133107
+ lastKey = next;
133108
+ publish2(ids);
133109
+ return true;
133110
+ }
133111
+ };
133112
+ }
133113
+
133114
+ // src/session/harness-catalog-watch.ts
133115
+ function isHarnessCatalogStamp(filename) {
133116
+ if (!filename) return false;
133117
+ const stamp2 = basename6(nodePaths("").harnessCatalogStamp);
133118
+ return filename === stamp2 || filename.endsWith(`/${stamp2}`) || filename.endsWith(`\\${stamp2}`);
133119
+ }
133120
+ function watchHarnessCatalogStamp(opts) {
133121
+ const path = nodePaths(opts.nodeHome).harnessCatalogStamp;
133122
+ const notifier = createHarnessCatalogNotifier(opts.readIds, (ids) => {
133123
+ opts.append({
133124
+ aggregateType: "environment",
133125
+ aggregateId: opts.environmentId,
133126
+ eventType: HARNESS_CATALOG_CHANGED,
133127
+ payload: { harnessIds: [...ids] }
133128
+ });
133129
+ });
133130
+ let watcher = null;
133131
+ let closed = false;
133132
+ try {
133133
+ writeFileSync20(path, "", { flag: "a" });
133134
+ watcher = watch(opts.nodeHome, { persistent: false }, (_event, filename) => {
133135
+ if (closed || !isHarnessCatalogStamp(filename ?? null)) return;
133136
+ try {
133137
+ notifier.note();
133138
+ } catch {
133139
+ }
133140
+ });
133141
+ watcher.on("error", () => {
133142
+ closed = true;
133143
+ watcher?.close();
133144
+ watcher = null;
133145
+ });
133146
+ } catch {
133147
+ watcher = null;
133148
+ }
133149
+ return {
133150
+ close() {
133151
+ closed = true;
133152
+ watcher?.close();
133153
+ watcher = null;
133154
+ }
133155
+ };
133156
+ }
133157
+
133158
+ // src/runtime.ts
130612
133159
  init_config();
130613
133160
 
130614
133161
  // ../../packages/runtime/src/db/database.ts
@@ -134258,7 +136805,7 @@ function fetchProfile(token2, fetchImpl) {
134258
136805
  // ../../packages/runtime/src/session/claude-account-store.ts
134259
136806
  init_agent_types();
134260
136807
  import { homedir as homedir18 } from "node:os";
134261
- import { existsSync as existsSync44, copyFileSync as copyFileSync3, symlinkSync as symlinkSync2, mkdirSync as mkdirSync23, readFileSync as readFileSync27, renameSync as renameSync7, writeFileSync as writeFileSync19, lstatSync as lstatSync3, readdirSync as readdirSync15 } from "node:fs";
136808
+ import { existsSync as existsSync44, copyFileSync as copyFileSync3, symlinkSync as symlinkSync2, mkdirSync as mkdirSync23, readFileSync as readFileSync27, renameSync as renameSync7, writeFileSync as writeFileSync21, lstatSync as lstatSync3, readdirSync as readdirSync15 } from "node:fs";
134262
136809
  import { randomUUID as randomUUID20 } from "node:crypto";
134263
136810
  import { dirname as dirname20, join as join47, resolve as resolve15 } from "node:path";
134264
136811
  var key2 = (dir) => dir ?? "__cli__";
@@ -134281,7 +136828,7 @@ var ClaudeAccountStore = class {
134281
136828
  write(index) {
134282
136829
  mkdirSync23(this.root, { recursive: true, mode: 448 });
134283
136830
  const temporary = join47(this.root, `accounts-${randomUUID20()}.tmp`);
134284
- writeFileSync19(temporary, JSON.stringify(index), { mode: 384 });
136831
+ writeFileSync21(temporary, JSON.stringify(index), { mode: 384 });
134285
136832
  renameSync7(temporary, join47(this.root, "accounts.json"));
134286
136833
  }
134287
136834
  assertManaged(dir) {
@@ -134342,7 +136889,7 @@ var ClaudeAccountStore = class {
134342
136889
  if (source[name] !== void 0) target2[name] = source[name];
134343
136890
  }
134344
136891
  const temporary = join47(dir, `config-${randomUUID20()}.tmp`);
134345
- writeFileSync19(temporary, JSON.stringify(target2), { mode: 384 });
136892
+ writeFileSync21(temporary, JSON.stringify(target2), { mode: 384 });
134346
136893
  renameSync7(temporary, join47(dir, ".claude.json"));
134347
136894
  }
134348
136895
  get(dir) {
@@ -134737,9 +137284,9 @@ async function startNodeServer2(opts) {
134737
137284
  }
134738
137285
 
134739
137286
  // src/terminal/manager.ts
134740
- import { createRequire as createRequire6 } from "node:module";
137287
+ import { createRequire as createRequire5 } from "node:module";
134741
137288
  import { existsSync as existsSync46 } from "node:fs";
134742
- var nodeRequire = createRequire6(import.meta.url);
137289
+ var nodeRequire = createRequire5(import.meta.url);
134743
137290
  var { spawn: spawn6 } = nodeRequire("node-pty");
134744
137291
  var SNAPSHOT_SOFT_LIMIT = 64 * 1024;
134745
137292
  var OUTPUT_BUFFER_SOFT_LIMIT = 256 * 1024;
@@ -134956,7 +137503,7 @@ var NodeTerminalManager = class {
134956
137503
  };
134957
137504
 
134958
137505
  // ../../packages/runtime/src/workspace/project-registry.ts
134959
- import { basename as basename6, resolve as resolve17 } from "node:path";
137506
+ import { basename as basename7, resolve as resolve17 } from "node:path";
134960
137507
  import { existsSync as existsSync47, realpathSync as realpathSync10, statSync as statSync13 } from "node:fs";
134961
137508
  import { createHash as createHash19 } from "node:crypto";
134962
137509
  import { execFileSync as execFileSync6 } from "node:child_process";
@@ -135053,7 +137600,7 @@ var ProjectRegistry = class {
135053
137600
  this.db.prepare(
135054
137601
  `INSERT INTO projects (project_id, path, name, repo_identity, opened_at, last_active_at)
135055
137602
  VALUES (?, ?, ?, ?, ?, ?)`
135056
- ).run(projectId, abs, name || basename6(abs), repoIdentity, now, now);
137603
+ ).run(projectId, abs, name || basename7(abs), repoIdentity, now, now);
135057
137604
  return this.get(projectId);
135058
137605
  }
135059
137606
  /**
@@ -135159,7 +137706,7 @@ import {
135159
137706
  rmSync as rmSync10,
135160
137707
  statSync as statSync14,
135161
137708
  unlinkSync,
135162
- writeFileSync as writeFileSync20
137709
+ writeFileSync as writeFileSync22
135163
137710
  } from "node:fs";
135164
137711
  import { dirname as dirname21, join as join50, relative as relative3 } from "node:path";
135165
137712
  import { createHash as createHash20 } from "node:crypto";
@@ -135310,7 +137857,7 @@ var WorkspaceFsService = class {
135310
137857
  const tmp = `${resolved.absolutePath}.tmp-${crypto.randomUUID()}`;
135311
137858
  let renamed = false;
135312
137859
  try {
135313
- writeFileSync20(tmp, data, { mode });
137860
+ writeFileSync22(tmp, data, { mode });
135314
137861
  const again = resolveProjectPath(root2, relativePath);
135315
137862
  if (!again.ok || again.absolutePath !== resolved.absolutePath) {
135316
137863
  throw Object.assign(new Error("path changed during write"), { code: "failed_precondition" });
@@ -135850,7 +138397,7 @@ function parseBranchPorcelain(raw2) {
135850
138397
 
135851
138398
  // ../../packages/runtime/src/workspace/watch-service.ts
135852
138399
  init_fs();
135853
- import { watch } from "node:fs";
138400
+ import { watch as watch2 } from "node:fs";
135854
138401
  var WorkspaceWatchService = class {
135855
138402
  constructor(projects) {
135856
138403
  this.projects = projects;
@@ -135878,7 +138425,7 @@ var WorkspaceWatchService = class {
135878
138425
  let wake = null;
135879
138426
  let closed = false;
135880
138427
  const watchId = crypto.randomUUID();
135881
- const watcher = watch(resolved.absolutePath, { recursive: true }, (eventType2, filename) => {
138428
+ const watcher = watch2(resolved.absolutePath, { recursive: true }, (eventType2, filename) => {
135882
138429
  if (!filename) return;
135883
138430
  const rel = String(filename).split("\\").join("/");
135884
138431
  const check2 = resolveProjectPath(project.path, relativePath === "." ? rel : `${relativePath}/${rel}`);
@@ -135915,7 +138462,7 @@ var WorkspaceWatchService = class {
135915
138462
  if (!resolved.ok) {
135916
138463
  throw Object.assign(new Error(resolved.reason), { code: "invalid_argument" });
135917
138464
  }
135918
- const watcher = watch(resolved.absolutePath, { recursive: true }, (eventType2, filename) => {
138465
+ const watcher = watch2(resolved.absolutePath, { recursive: true }, (eventType2, filename) => {
135919
138466
  if (!filename) return;
135920
138467
  const rel = String(filename).split("\\").join("/");
135921
138468
  const check2 = resolveProjectPath(project.path, relativePath === "." ? rel : `${relativePath}/${rel}`);
@@ -136774,7 +139321,7 @@ import { dirname as dirname23, join as join54 } from "node:path";
136774
139321
  init_mcp_apps();
136775
139322
  init_mcp_app_resource();
136776
139323
  import { createHash as createHash22, randomUUID as randomUUID22 } from "node:crypto";
136777
- import { existsSync as existsSync51, mkdirSync as mkdirSync26, readFileSync as readFileSync29, readdirSync as readdirSync18, renameSync as renameSync10, rmSync as rmSync11, statSync as statSync17, utimesSync, writeFileSync as writeFileSync21 } from "node:fs";
139324
+ import { existsSync as existsSync51, mkdirSync as mkdirSync26, readFileSync as readFileSync29, readdirSync as readdirSync18, renameSync as renameSync10, rmSync as rmSync11, statSync as statSync17, utimesSync, writeFileSync as writeFileSync23 } from "node:fs";
136778
139325
  import { join as join53 } from "node:path";
136779
139326
  function createMcpAppResourceStore(directory) {
136780
139327
  const cache4 = new McpAppResourceCache();
@@ -136791,7 +139338,7 @@ function createMcpAppResourceStore(directory) {
136791
139338
  mkdirSync26(directory, { recursive: true });
136792
139339
  const temporary = join53(directory, `${hash2}.${randomUUID22()}.tmp`);
136793
139340
  try {
136794
- writeFileSync21(temporary, snapshot.html, { encoding: "utf8", mode: 384, flag: "wx" });
139341
+ writeFileSync23(temporary, snapshot.html, { encoding: "utf8", mode: 384, flag: "wx" });
136795
139342
  renameSync10(temporary, file2);
136796
139343
  } finally {
136797
139344
  rmSync11(temporary, { force: true });
@@ -138069,7 +140616,7 @@ init_platform_registry();
138069
140616
  import { randomUUID as randomUUID25 } from "node:crypto";
138070
140617
 
138071
140618
  // src/provider/secret-crypto.ts
138072
- import { existsSync as existsSync54, mkdirSync as mkdirSync27, readFileSync as readFileSync30, writeFileSync as writeFileSync22, chmodSync as chmodSync3 } from "node:fs";
140619
+ import { existsSync as existsSync54, mkdirSync as mkdirSync27, readFileSync as readFileSync30, writeFileSync as writeFileSync24, chmodSync as chmodSync3 } from "node:fs";
138073
140620
  import { dirname as dirname24 } from "node:path";
138074
140621
  import { createCipheriv, createDecipheriv, randomBytes as randomBytes8 } from "node:crypto";
138075
140622
  var ENC_PREFIX2 = "enc:v1:";
@@ -138084,7 +140631,7 @@ function ensureKeyFile(keyPath) {
138084
140631
  }
138085
140632
  mkdirSync27(dirname24(keyPath), { recursive: true, mode: 448 });
138086
140633
  const key3 = randomBytes8(KEY_BYTES);
138087
- writeFileSync22(keyPath, key3, { mode: 384 });
140634
+ writeFileSync24(keyPath, key3, { mode: 384 });
138088
140635
  try {
138089
140636
  chmodSync3(keyPath, 384);
138090
140637
  } catch {
@@ -152446,7 +154993,15 @@ async function startNodeRuntime(partial2 = {}) {
152446
154993
  startedAt,
152447
154994
  simulatedHarness
152448
154995
  });
152449
- writeFileSync23(
154996
+ const catalogWatch = watchHarnessCatalogStamp({
154997
+ nodeHome: config2.nodeHome,
154998
+ environmentId: identity.environmentId,
154999
+ readIds: () => harnesses.readySessionHarnessIds(),
155000
+ append: (input) => {
155001
+ events.append(input);
155002
+ }
155003
+ });
155004
+ writeFileSync25(
152450
155005
  paths.runtimeJson,
152451
155006
  JSON.stringify(
152452
155007
  {
@@ -152489,6 +155044,7 @@ async function startNodeRuntime(partial2 = {}) {
152489
155044
  server,
152490
155045
  startedAt,
152491
155046
  async stop() {
155047
+ catalogWatch.close();
152492
155048
  automationService.stop();
152493
155049
  collaboration.dispose();
152494
155050
  const disposePromise = sessions.dispose();
@@ -152532,7 +155088,7 @@ function readRuntimeStatus(nodeHome) {
152532
155088
 
152533
155089
  // src/systemd/install.ts
152534
155090
  import { spawnSync as spawnSync2 } from "node:child_process";
152535
- import { chmodSync as chmodSync4, existsSync as existsSync56, mkdirSync as mkdirSync29, unlinkSync as unlinkSync3, writeFileSync as writeFileSync24 } from "node:fs";
155091
+ import { chmodSync as chmodSync4, existsSync as existsSync56, mkdirSync as mkdirSync29, unlinkSync as unlinkSync3, writeFileSync as writeFileSync26 } from "node:fs";
152536
155092
  import { dirname as dirname25 } from "node:path";
152537
155093
 
152538
155094
  // src/systemd/unit.ts
@@ -152594,7 +155150,7 @@ function checkLinger(user) {
152594
155150
  }
152595
155151
  function writeSystemdUserUnit(opts, unitPath = systemdUserUnitPath()) {
152596
155152
  mkdirSync29(dirname25(unitPath), { recursive: true });
152597
- writeFileSync24(unitPath, renderSystemdUserUnit(opts), { encoding: "utf8", mode: 420 });
155153
+ writeFileSync26(unitPath, renderSystemdUserUnit(opts), { encoding: "utf8", mode: 420 });
152598
155154
  try {
152599
155155
  chmodSync4(unitPath, 420);
152600
155156
  } catch {
@@ -152770,40 +155326,51 @@ ${harnessUsage()}`, rest.includes("--json"));
152770
155326
  const db = openNodeDatabase(nodePaths(nodeHome).stateDb);
152771
155327
  try {
152772
155328
  const manager = new HarnessManager(db);
152773
- switch (sub) {
152774
- case "list":
152775
- return cmdList(manager, rest);
152776
- case "show":
152777
- return cmdShow(manager, rest);
152778
- case "enable":
152779
- return await cmdEnable(
152780
- manager,
152781
- rest,
152782
- /*configure*/
152783
- false
152784
- );
152785
- case "configure":
152786
- return await cmdEnable(
152787
- manager,
152788
- rest,
152789
- /*configure*/
152790
- true
152791
- );
152792
- case "disable":
152793
- return cmdDisable(manager, rest);
152794
- case "doctor":
152795
- return cmdDoctor(manager, rest);
152796
- case "probe":
152797
- return cmdProbe(manager, rest, db);
152798
- case "repair":
152799
- return await cmdRepair(manager, rest);
152800
- default:
152801
- return fail2(`unknown harness command: ${sub}`, false);
152802
- }
155329
+ const result3 = await dispatchHarnessCommand(sub, manager, rest, db);
155330
+ if (signalsHarnessCatalog(sub, result3)) signalHarnessCatalogChanged(nodeHome);
155331
+ return result3;
152803
155332
  } finally {
152804
155333
  db.close();
152805
155334
  }
152806
155335
  }
155336
+ async function dispatchHarnessCommand(sub, manager, rest, db) {
155337
+ switch (sub) {
155338
+ case "list":
155339
+ return cmdList(manager, rest);
155340
+ case "show":
155341
+ return cmdShow(manager, rest);
155342
+ case "enable":
155343
+ return await cmdEnable(
155344
+ manager,
155345
+ rest,
155346
+ /*configure*/
155347
+ false
155348
+ );
155349
+ case "configure":
155350
+ return await cmdEnable(
155351
+ manager,
155352
+ rest,
155353
+ /*configure*/
155354
+ true
155355
+ );
155356
+ case "disable":
155357
+ return cmdDisable(manager, rest);
155358
+ case "doctor":
155359
+ return cmdDoctor(manager, rest);
155360
+ case "probe":
155361
+ return cmdProbe(manager, rest, db);
155362
+ case "repair":
155363
+ return await cmdRepair(manager, rest);
155364
+ default:
155365
+ return fail2(`unknown harness command: ${sub}`, false);
155366
+ }
155367
+ }
155368
+ function signalsHarnessCatalog(sub, result3) {
155369
+ if (sub === "enable" || sub === "configure" || sub === "disable" || sub === "repair") return result3.ok;
155370
+ if (sub !== "probe") return false;
155371
+ if (result3.json && typeof result3.json === "object" && "status" in result3.json) return true;
155372
+ return result3.text.includes("\u2192");
155373
+ }
152807
155374
  function cmdList(manager, args) {
152808
155375
  const parsed = parseFlags(args, {
152809
155376
  positionals: 0,