dcmjs 0.52.2 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/dcmjs.es.js CHANGED
@@ -9691,8 +9691,8 @@ function toWindows(inputArray, size) {
9691
9691
  }
9692
9692
  var DicomMessage$3, Tag$1, DicomMetaDictionary$1;
9693
9693
  var binaryVRs = ["FL", "FD", "SL", "SS", "UL", "US", "AT", "UV"],
9694
- length32VRs = ["OB", "OW", "OF", "SQ", "UC", "UR", "UT", "UN", "OD", "UV"],
9695
- singleVRs$1 = ["SQ", "OF", "OW", "OB", "UN"];
9694
+ length32VRs = ["OB", "OW", "OF", "OL", "SQ", "UC", "UR", "UT", "UN", "OD", "UV"],
9695
+ singleVRs$1 = ["SQ", "OF", "OL", "OW", "OB", "UN"];
9696
9696
  var ValueRepresentation = /*#__PURE__*/function () {
9697
9697
  function ValueRepresentation(type) {
9698
9698
  _classCallCheck(this, ValueRepresentation);
@@ -11272,6 +11272,22 @@ var OtherFloatString = /*#__PURE__*/function (_BinaryRepresentation6) {
11272
11272
  }
11273
11273
  _inherits(OtherFloatString, _BinaryRepresentation6);
11274
11274
  return _createClass(OtherFloatString);
11275
+ }(BinaryRepresentation); // A stream of 32 bit words. Used by the large mesh attributes of Surface
11276
+ // Segmentation - Long Triangle Point Index List (0066,0041) and its Edge and
11277
+ // Vertex counterparts - where the 16 bit indices of the OW forms cap a surface
11278
+ // at 65535 points.
11279
+ var OtherLongString = /*#__PURE__*/function (_BinaryRepresentation7) {
11280
+ function OtherLongString() {
11281
+ var _this34;
11282
+ _classCallCheck(this, OtherLongString);
11283
+ _this34 = _callSuper(this, OtherLongString, ["OL"]);
11284
+ _this34.maxLength = null;
11285
+ _this34.padByte = PADDING_NULL;
11286
+ _this34.noMultiple = true;
11287
+ return _this34;
11288
+ }
11289
+ _inherits(OtherLongString, _BinaryRepresentation7);
11290
+ return _createClass(OtherLongString);
11275
11291
  }(BinaryRepresentation); // these VR instances are precreate and are reused for each requested vr/tag
11276
11292
  var VRinstances = {
11277
11293
  AE: new ApplicationEntity(),
@@ -11289,6 +11305,7 @@ var VRinstances = {
11289
11305
  OB: new OtherByteString(),
11290
11306
  OD: new OtherDoubleString(),
11291
11307
  OF: new OtherFloatString(),
11308
+ OL: new OtherLongString(),
11292
11309
  OW: new OtherWordString(),
11293
11310
  PN: new PersonName(),
11294
11311
  SH: new ShortString(),
@@ -11307,6 +11324,208 @@ var VRinstances = {
11307
11324
  UV: new Unsigned64BitVeryLong()
11308
11325
  };
11309
11326
 
11327
+ /**
11328
+ * Private block reservation, per PS3.5 Section 7.8.1.
11329
+ *
11330
+ * A private group is odd. Within it, a Private Creator Data Element at
11331
+ * (gggg,00xx) - where xx is 0x10 through 0xFF - identifies an implementer and
11332
+ * reserves the block of Data Elements (gggg,xx00) through (gggg,xxFF) for them.
11333
+ *
11334
+ * Which block a creator gets is decided by whoever wrote the file, so the
11335
+ * creator string is the identity and the block has to be looked up. A block
11336
+ * is named as in the 1.0 naturalized form: the block key "gggg:creator"
11337
+ * (for example "4D43:ACME 1.0"), or the pair (group, creator); an element of
11338
+ * the block is its number 0x00-0xFF, or the element key "xEE" (for example
11339
+ * "x01"):
11340
+ *
11341
+ * // writing
11342
+ * const block = dicomDict.privateBlock("4D43:ACME 1.0");
11343
+ * block.set("x01", "CS", ["HYBRID"]); // -> (4D43,1001), or wherever it landed
11344
+ *
11345
+ * // reading, from any parsed dict
11346
+ * const found = findPrivateBlock(dict, "4D43:ACME 1.0");
11347
+ * found && found.get("x01").Value;
11348
+ */
11349
+
11350
+ var CREATOR_MIN = 0x10;
11351
+ var CREATOR_MAX = 0xff;
11352
+ var CREATOR_MAX_LENGTH = 64; // LO
11353
+ var BLOCK_KEY = /^([0-9A-Fa-f]{4}):([^]+)$/;
11354
+ var ELEMENT_KEY = /^x([0-9A-Fa-f]{2})$/;
11355
+ var hex2 = function hex2(n) {
11356
+ return n.toString(16).toUpperCase().padStart(2, "0");
11357
+ };
11358
+ var hex4 = function hex4(n) {
11359
+ return n.toString(16).toUpperCase().padStart(4, "0");
11360
+ };
11361
+
11362
+ /**
11363
+ * The block key "gggg:creator" of a group and creator. A line break in the
11364
+ * creator is written as the text `\n` (and `\r`); LO holds no backslash, so
11365
+ * the key reads back to the same creator.
11366
+ */
11367
+ function privateBlockKey(group, creator) {
11368
+ var text = creator.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
11369
+ return "".concat(hex4(group), ":").concat(text);
11370
+ }
11371
+
11372
+ /** The creator of the creator part of a block key: `\n` and `\r` unescaped. */
11373
+ function keyCreator(text) {
11374
+ return text.replace(/\\r/g, "\r").replace(/\\n/g, "\n");
11375
+ }
11376
+
11377
+ /**
11378
+ * The creator text of a creator element value: no leading spaces, no
11379
+ * trailing spaces or NULs. A value in bytes (UN) is read as Latin-1.
11380
+ */
11381
+ function creatorText(value) {
11382
+ var v = Array.isArray(value) ? value[0] : value;
11383
+ if (typeof v === "string") return v.replace(/^ +|[\0 ]+$/g, "");
11384
+ if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) {
11385
+ var bytes = ArrayBuffer.isView(v) ? new Uint8Array(v.buffer, v.byteOffset, v.byteLength) : new Uint8Array(v);
11386
+ return creatorText(String.fromCharCode.apply(String, _toConsumableArray(bytes.subarray(0, 64))));
11387
+ }
11388
+ return "";
11389
+ }
11390
+
11391
+ /** [group, creator] from (groupOrKey, creator), validated. */
11392
+ function blockArgs(groupOrKey, creator) {
11393
+ var group = groupOrKey;
11394
+ if (typeof groupOrKey === "string") {
11395
+ var match = BLOCK_KEY.exec(groupOrKey);
11396
+ if (!match) {
11397
+ throw new Error("Private block key must be \"gggg:creator\", got ".concat(groupOrKey));
11398
+ }
11399
+ group = parseInt(match[1], 16);
11400
+ creator = keyCreator(match[2]);
11401
+ }
11402
+ if (!Number.isInteger(group) || group < 0 || group > 0xffff) {
11403
+ throw new Error("Private group must be a 16 bit number, got ".concat(group));
11404
+ }
11405
+ if (group % 2 === 0) {
11406
+ throw new Error("Private group must be odd, got ".concat(hex4(group), " - an even group is standard, not private"));
11407
+ }
11408
+ if (typeof creator !== "string" || creatorText(creator).length === 0) {
11409
+ throw new Error("Private creator must be a non-empty string");
11410
+ }
11411
+ creator = creatorText(creator);
11412
+ if (creator.length > CREATOR_MAX_LENGTH) {
11413
+ throw new Error("Private creator must be at most ".concat(CREATOR_MAX_LENGTH, " characters (LO), got ").concat(creator.length));
11414
+ }
11415
+ return [group, creator];
11416
+ }
11417
+
11418
+ /** The element number of 0x00-0xFF or "xEE". */
11419
+ function elementNumber(element) {
11420
+ var match = typeof element === "string" && ELEMENT_KEY.exec(element);
11421
+ var n = match ? parseInt(match[1], 16) : element;
11422
+ if (!Number.isInteger(n) || n < 0x00 || n > 0xff) {
11423
+ throw new Error("Private element must be 0x00 to 0xFF or \"xEE\", got ".concat(element));
11424
+ }
11425
+ return n;
11426
+ }
11427
+
11428
+ /**
11429
+ * An accessor for one reserved block of a dict, keyed by 'GGGGEEEE'.
11430
+ * `reservedBlock` is the xx of the block in this dict.
11431
+ */
11432
+ function blockAccessor(dict, group, creator, reservedBlock) {
11433
+ var tag = function tag(element) {
11434
+ return hex4(group) + hex2(reservedBlock) + hex2(elementNumber(element));
11435
+ };
11436
+ return {
11437
+ key: privateBlockKey(group, creator),
11438
+ group: group,
11439
+ creator: creator,
11440
+ reservedBlock: reservedBlock,
11441
+ /** The 'GGGGEEEE' key of an element of this block. */
11442
+ tag: tag,
11443
+ /** Whether this block holds that element. */
11444
+ has: function has(element) {
11445
+ return Object.prototype.hasOwnProperty.call(dict, tag(element));
11446
+ },
11447
+ /** The element object, or undefined. */
11448
+ get: function get(element) {
11449
+ return dict[tag(element)];
11450
+ },
11451
+ /**
11452
+ * Writes an element of this block, as DicomDict#upsertTag does.
11453
+ *
11454
+ * @param {number|string} element 0x00 to 0xFF, or "xEE"
11455
+ * @param {string} vr value representation
11456
+ * @param {*} values value, or array of values
11457
+ * @returns {string} the tag that was written
11458
+ */
11459
+ set: function set(element, vr, values) {
11460
+ var key = tag(element);
11461
+ dict[key] = ValueRepresentation.addTagAccessors({
11462
+ vr: vr
11463
+ });
11464
+ dict[key].Value = Array.isArray(values) ? values : [values];
11465
+ return key;
11466
+ }
11467
+ };
11468
+ }
11469
+
11470
+ /**
11471
+ * Finds the block a creator has reserved in a dict.
11472
+ *
11473
+ * @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
11474
+ * @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
11475
+ * @param {string} [creator] creator string, with a group number
11476
+ * @returns {object|null} a block accessor, or null when the creator is absent
11477
+ */
11478
+ function findPrivateBlock(dict, groupOrKey, creator) {
11479
+ var _blockArgs = blockArgs(groupOrKey, creator),
11480
+ _blockArgs2 = _slicedToArray(_blockArgs, 2),
11481
+ group = _blockArgs2[0],
11482
+ wanted = _blockArgs2[1];
11483
+ for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
11484
+ var element = dict[hex4(group) + hex4(xx)];
11485
+ if (element && creatorText(element.Value) === wanted) {
11486
+ return blockAccessor(dict, group, wanted, xx);
11487
+ }
11488
+ }
11489
+ return null;
11490
+ }
11491
+
11492
+ /**
11493
+ * Finds the block a creator has reserved, or reserves the first free block
11494
+ * and writes the creator element. A block is free when the dict holds no
11495
+ * creator element for it and no element in its range.
11496
+ *
11497
+ * @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
11498
+ * @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
11499
+ * @param {string} [creator] creator string, with a group number
11500
+ * @returns {object} a block accessor
11501
+ */
11502
+ function reservePrivateBlock(dict, groupOrKey, creator) {
11503
+ var existing = findPrivateBlock(dict, groupOrKey, creator);
11504
+ if (existing) return existing;
11505
+ var _blockArgs3 = blockArgs(groupOrKey, creator),
11506
+ _blockArgs4 = _slicedToArray(_blockArgs3, 2),
11507
+ group = _blockArgs4[0],
11508
+ wanted = _blockArgs4[1];
11509
+ var prefix = hex4(group);
11510
+ var used = new Set();
11511
+ for (var _i = 0, _Object$keys = Object.keys(dict); _i < _Object$keys.length; _i++) {
11512
+ var key = _Object$keys[_i];
11513
+ if (!key.startsWith(prefix) || key.length !== 8) continue;
11514
+ var element = parseInt(key.slice(4), 16);
11515
+ used.add(element <= 0xff ? element : element >> 8);
11516
+ }
11517
+ for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
11518
+ if (!used.has(xx)) {
11519
+ dict[prefix + hex4(xx)] = ValueRepresentation.addTagAccessors({
11520
+ vr: "LO"
11521
+ });
11522
+ dict[prefix + hex4(xx)].Value = [wanted];
11523
+ return blockAccessor(dict, group, wanted, xx);
11524
+ }
11525
+ }
11526
+ throw new Error("No free private block in group ".concat(prefix, " - all of 0x10 to 0xFF are reserved"));
11527
+ }
11528
+
11310
11529
  var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
11311
11530
  var DicomMessage$2;
11312
11531
  var DicomDict = /*#__PURE__*/function () {
@@ -11328,6 +11547,35 @@ var DicomDict = /*#__PURE__*/function () {
11328
11547
  this.dict[tag].Value = values;
11329
11548
  }
11330
11549
  }
11550
+
11551
+ /**
11552
+ * Reserves a private block for a creator, and writes its creator element
11553
+ * when the creator has no block yet; pass `{ create: false }` to only look
11554
+ * it up. See src/privateBlock.js: the block is found by creator, never
11555
+ * assumed.
11556
+ *
11557
+ * dicomDict.privateBlock("4D43:ACME 1.0").set("x01", "CS", ["HYBRID"]);
11558
+ *
11559
+ * @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
11560
+ * @param {string} [creator] creator string, with a group number
11561
+ * @param {{create?: boolean}} [options] create defaults to true; false
11562
+ * returns null when the creator is absent
11563
+ * @returns {object|null} accessor with key, group, creator, reservedBlock,
11564
+ * tag, has, get and set
11565
+ */
11566
+ }, {
11567
+ key: "privateBlock",
11568
+ value: function privateBlock(groupOrKey, creator) {
11569
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11570
+ if (typeof groupOrKey === "string" && _typeof(creator) === "object") {
11571
+ options = creator;
11572
+ creator = undefined;
11573
+ }
11574
+ var _ref = options || {},
11575
+ _ref$create = _ref.create,
11576
+ create = _ref$create === void 0 ? true : _ref$create;
11577
+ return create ? reservePrivateBlock(this.dict, groupOrKey, creator) : findPrivateBlock(this.dict, groupOrKey, creator);
11578
+ }
11331
11579
  }, {
11332
11580
  key: "write",
11333
11581
  value: function write() {
@@ -12414,6 +12662,12 @@ var DicomMetaDictionary = /*#__PURE__*/function () {
12414
12662
  }
12415
12663
  }
12416
12664
  var _vr = ValueRepresentation.createByTypeString(dataItem.vr);
12665
+ if (dataItem.vr === "DS" && Array.isArray(dataItem.Value)) {
12666
+ // Format numbers to fit 16 characters instead of truncating String(number) below
12667
+ dataItem.Value = dataItem.Value.map(function (value) {
12668
+ return typeof value === "number" ? _vr.convertToString(value) : value;
12669
+ });
12670
+ }
12417
12671
  dataItem.Value = DicomMetaDictionary.denaturalizeValue(dataItem.Value);
12418
12672
  if (entry.vr == "SQ") {
12419
12673
  var unnaturalValues = [];
@@ -14336,7 +14590,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
14336
14590
  break;
14337
14591
  }
14338
14592
  // Group length
14339
- stream.increment(tagObj.length);
14593
+ stream.increment(length);
14340
14594
  return _context5.abrupt("continue", 1);
14341
14595
  case 5:
14342
14596
  addTagResult = listener.addTag(tag, tagInfo);
@@ -28164,7 +28418,12 @@ var data = {
28164
28418
  Colors: Colors,
28165
28419
  datasetToDict: datasetToDict,
28166
28420
  datasetToBuffer: datasetToBuffer,
28167
- datasetToBlob: datasetToBlob
28421
+ datasetToBlob: datasetToBlob,
28422
+ // Private block reservation, PS3.5 Section 7.8.1. findPrivateBlock() works
28423
+ // on any parsed dict; DicomDict#privateBlock() is the writing side.
28424
+ findPrivateBlock: findPrivateBlock,
28425
+ reservePrivateBlock: reservePrivateBlock,
28426
+ privateBlockKey: privateBlockKey
28168
28427
  };
28169
28428
  var async = {
28170
28429
  AsyncDicomReader: AsyncDicomReader