js.documents 1.82.0 → 1.83.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.
@@ -63,20 +63,23 @@ function readAsciiSlice(bytes, offset, length) {
63
63
  if (bytes.length < offset + length) return;
64
64
  return new TextDecoder().decode(bytes.subarray(offset, offset + length));
65
65
  }
66
- function hasOdfMimetypeEntry(bytes, mediaType) {
66
+ function hasOdfMimetypeEntry(bytes, mediaTypes) {
67
67
  if (!startsWithBytes(bytes, ZIP_LOCAL_FILE_HEADER)) return false;
68
68
  if (readUint16LE(bytes, COMPRESSION_METHOD_OFFSET) !== 0) return false;
69
69
  if (readAsciiSlice(bytes, MIMETYPE_FILENAME_OFFSET, 8) !== MIMETYPE_ENTRY_FILENAME) return false;
70
- if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
71
- return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
70
+ return mediaTypes.some((mediaType) => {
71
+ if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
72
+ return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
73
+ });
72
74
  }
73
- function odfBytesSchema(label, mediaType) {
74
- return zod.z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaType), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring "${mediaType}"` });
75
+ function odfBytesSchema(label, mediaTypes) {
76
+ const accepted = mediaTypes.map((type) => `"${type}"`).join(" or ");
77
+ return zod.z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaTypes), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring ${accepted}` });
75
78
  }
76
- const OdtBytesSchema = odfBytesSchema("odt", odf_js.ODF_MEDIA_TYPES.odt);
77
- const OdsBytesSchema = odfBytesSchema("ods", odf_js.ODF_MEDIA_TYPES.ods);
78
- const OdpBytesSchema = odfBytesSchema("odp", odf_js.ODF_MEDIA_TYPES.odp);
79
- const OdgBytesSchema = odfBytesSchema("odg", odf_js.ODF_MEDIA_TYPES.odg);
79
+ const OdtBytesSchema = odfBytesSchema("odt", [odf_js.ODF_MEDIA_TYPES.odt, odf_js.ODF_MEDIA_TYPES.ott]);
80
+ const OdsBytesSchema = odfBytesSchema("ods", [odf_js.ODF_MEDIA_TYPES.ods, odf_js.ODF_MEDIA_TYPES.ots]);
81
+ const OdpBytesSchema = odfBytesSchema("odp", [odf_js.ODF_MEDIA_TYPES.odp, odf_js.ODF_MEDIA_TYPES.otp]);
82
+ const OdgBytesSchema = odfBytesSchema("odg", [odf_js.ODF_MEDIA_TYPES.odg, odf_js.ODF_MEDIA_TYPES.otg]);
80
83
  function isWellFormedUtf8Text(bytes) {
81
84
  try {
82
85
  new TextDecoder("utf-8", { fatal: true }).decode(bytes);
@@ -62,20 +62,23 @@ function readAsciiSlice(bytes, offset, length) {
62
62
  if (bytes.length < offset + length) return;
63
63
  return new TextDecoder().decode(bytes.subarray(offset, offset + length));
64
64
  }
65
- function hasOdfMimetypeEntry(bytes, mediaType) {
65
+ function hasOdfMimetypeEntry(bytes, mediaTypes) {
66
66
  if (!startsWithBytes(bytes, ZIP_LOCAL_FILE_HEADER)) return false;
67
67
  if (readUint16LE(bytes, COMPRESSION_METHOD_OFFSET) !== 0) return false;
68
68
  if (readAsciiSlice(bytes, MIMETYPE_FILENAME_OFFSET, 8) !== MIMETYPE_ENTRY_FILENAME) return false;
69
- if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
70
- return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
69
+ return mediaTypes.some((mediaType) => {
70
+ if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
71
+ return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
72
+ });
71
73
  }
72
- function odfBytesSchema(label, mediaType) {
73
- return z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaType), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring "${mediaType}"` });
74
+ function odfBytesSchema(label, mediaTypes) {
75
+ const accepted = mediaTypes.map((type) => `"${type}"`).join(" or ");
76
+ return z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaTypes), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring ${accepted}` });
74
77
  }
75
- const OdtBytesSchema = odfBytesSchema("odt", ODF_MEDIA_TYPES.odt);
76
- const OdsBytesSchema = odfBytesSchema("ods", ODF_MEDIA_TYPES.ods);
77
- const OdpBytesSchema = odfBytesSchema("odp", ODF_MEDIA_TYPES.odp);
78
- const OdgBytesSchema = odfBytesSchema("odg", ODF_MEDIA_TYPES.odg);
78
+ const OdtBytesSchema = odfBytesSchema("odt", [ODF_MEDIA_TYPES.odt, ODF_MEDIA_TYPES.ott]);
79
+ const OdsBytesSchema = odfBytesSchema("ods", [ODF_MEDIA_TYPES.ods, ODF_MEDIA_TYPES.ots]);
80
+ const OdpBytesSchema = odfBytesSchema("odp", [ODF_MEDIA_TYPES.odp, ODF_MEDIA_TYPES.otp]);
81
+ const OdgBytesSchema = odfBytesSchema("odg", [ODF_MEDIA_TYPES.odg, ODF_MEDIA_TYPES.otg]);
79
82
  function isWellFormedUtf8Text(bytes) {
80
83
  try {
81
84
  new TextDecoder("utf-8", { fatal: true }).decode(bytes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js.documents",
3
- "version": "1.82.0",
3
+ "version": "1.83.0",
4
4
  "description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {