@mdgate/wps 0.5.0 → 0.5.1

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 (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{create as Zq}from"@mdgate/core";import{CompoundFile as n,detectOleDoc as r,detectZipDoc as i,hasOleMagic as o,Package as b}from"@mdgate/containers";import{ConvertError as y}from"@mdgate/core";import{doc as s}from"@mdgate/doc";import{documentToMarkdown as t}from"@mdgate/document";import{docx as e}from"@mdgate/docx";import{ppt as qq}from"@mdgate/ppt";import{pptx as Gq}from"@mdgate/pptx";import{fileExtension as Hq}from"@mdgate/utils";import{xlsx as Jq}from"@mdgate/xlsx";import{CompoundFile as P,hasOleMagic as v,Package as C,parseXml as w}from"@mdgate/containers";import{ConvertError as W}from"@mdgate/core";import{emptyDocument as k,plain as h}from"@mdgate/document";import{cleanText as B,collapseWs as I,isAlphanumeric as g}from"@mdgate/utils";var u=2,R=2;function O(q){let G=[];try{if(a(q))x(q,G);else if(v(q))m(q,G);else S(q,G)}catch(Q){if(Q instanceof W&&(Q.code==="encrypted"||Q.code==="resourceLimit"))throw Q;S(q,G)}let H=new Set,J=k();for(let Q of G){let V=I(B(Q)).trim();if(!F(V)||H.has(V))continue;H.add(V),J.blocks.push({type:"paragraph",inlines:[h(V)]})}if(J.blocks.length===0)throw W.malformed("no readable text in WPS document");return J}function x(q,G){let H=C.open(q);for(let J of H.partNames()){if(l(J))continue;let Q=H.optionalPart(J);if(Q!==void 0)S(Q,G)}}function m(q,G){let H=P.open(q);if(H.exists("EncryptionInfo")||H.exists("EncryptedPackage"))throw W.encrypted();let J=!1;for(let Q of H.readRootStorage()){if(Q.type!==u)continue;try{S(H.readStream(Q.name),G),J=!0}catch(V){if(V instanceof W&&V.isFatal())throw V}}if(!J)S(q,G)}function S(q,G){if(c(q))try{f(w(q),G);return}catch(H){if(H instanceof W&&H.isFatal())throw H}d(q,G),p(q,G)}function f(q,G){let H=(J)=>{let Q="",V=!1;for(let Y of J.children)if(Y.type==="text")Q+=Y.text;else V=!0;let $=I(B(Q)).trim();if(F($))G.push($);if(V)for(let Y of J.childElems())H(Y)};H(q)}function d(q,G){let H=[],J=()=>{if(H.length>=R)G.push(String.fromCharCode(...H));H.length=0};for(let Q=0;Q+1<q.length;Q+=2){let V=q[Q]|q[Q+1]<<8;if(V!==0&&A(V))H.push(V);else J()}J()}function p(q,G){let J=new TextDecoder("utf-8",{fatal:!1}).decode(q),Q=-1,V=($)=>{if(Q>=0&&$-Q>=R)G.push(J.slice(Q,$));Q=-1};for(let $=0;$<J.length;$+=1){let Y=J.charCodeAt($);if(A(Y)){if(Q<0)Q=$}else V($)}V(J.length)}function A(q){if(q===9||q===10||q===13||q===32)return!0;if(q<32||q>=127&&q<=159)return!1;return q!==65534&&q!==65535}function F(q){if(q.length<R)return!1;let G=0;for(let J of q)if(g(J))G+=1;if(G<2)return!1;let H=q.toLowerCase();if(H.includes("xmlns")||H.includes("http://schemas.")||H.includes("https://schemas."))return!1;if(H.startsWith("application/"))return!1;return!0}function c(q){let G=0;if(q.length>=3&&q[0]===239&&q[1]===187&&q[2]===191)G=3;while(G<q.length){let H=q[G];if(H!==9&&H!==10&&H!==13&&H!==32)break;G+=1}return q[G]===60}function l(q){let G=q.toLowerCase();if(G==="mimetype"||G==="[content_types].xml")return!0;if(G.endsWith(".rels"))return!0;return/\.(png|jpe?g|gif|bmp|emf|wmf|bin|ttf|otf|woff2?)$/i.test(G)}function a(q){return q.length>=4&&q[0]===80&&q[1]===75&&q[2]===3&&q[3]===4}var Qq=new Set(["wps","wpt","et","ett","dps","dpt"]),Vq=e(),$q=s(),Yq=Jq(),Wq=Gq(),Sq=qq();function Z(){return{id:"wps",sniff(q,G){if(U(q)!==void 0)return 0;if(zq(q))return 2;if(G?.path!==void 0&&Qq.has(Hq(G.path)??""))return 1;return 0},convert(q,G){if(Dq(q))throw y.unsupported("pdf");let H=U(q);if(H==="docx")return Vq.convert(q,G);if(H==="doc")return $q.convert(q,G);if(H==="xlsx"||H==="xls")return Yq.convert(q,G);if(H==="pptx")return Wq.convert(q,G);if(H==="ppt")return Sq.convert(q,G);return{markdown:t(O(q))}}}}function U(q){let G=i(q);if(G==="docx"||G==="xlsx"||G==="pptx")return G;let H=r(q);if(H==="doc"||H==="xls"||H==="ppt")return H;return}function zq(q){if(Lq(q))try{let G=b.open(q),H=G.optionalPart("mimetype");if(H!==void 0&&X(K(H)))return!0;for(let Q of G.partNames())if(M(Q))return!0;let J=G.optionalPart("[Content_Types].xml");if(J!==void 0&&X(K(J)))return!0;return!1}catch{}else if(o(q))try{let G=n.open(q);for(let H of G.readRootStorage())if(M(H.name))return!0}catch{}return _q(q)}function M(q){let G=q.charCodeAt(0)===5?q.slice(1):q;for(let H of G.split(/[/\\]/)){if(H.length===0)continue;if(N(H,"ks")||N(H,"wps"))return!0}return!1}function X(q){let G=q.toLowerCase();return G.includes("kingsoft")||G.includes("application/wps")||G.includes("application/vnd.wps")||G.includes("application/vnd.kingsoft")}function _q(q){let G=q.subarray(0,Math.min(q.length,65536));return L(G,"kingsoft")||L(G,"application/wps")||L(G,"application/vnd.wps")||L(G,"application/vnd.kingsoft")}function Dq(q){let G=0;if(q.length>=3&&q[0]===239&&q[1]===187&&q[2]===191)G=3;while(G<q.length){let H=q[G];if(H!==9&&H!==10&&H!==13&&H!==32)break;G+=1}return Rq(q,"%PDF-",G)}function Lq(q){return q.length>=4&&q[0]===80&&q[1]===75&&q[2]===3&&q[3]===4}function K(q){return new TextDecoder("utf-8",{fatal:!1}).decode(q)}function N(q,G){if(q.length<G.length)return!1;return q.slice(0,G.length).toLowerCase()===G}function Rq(q,G,H){if(H+G.length>q.length)return!1;for(let J=0;J<G.length;J+=1)if(q[H+J]!==G.charCodeAt(J))return!1;return!0}function L(q,G){if(G.length===0||q.length<G.length)return!1;let H=G.length,J=G.charCodeAt(0),Q=J>=65&&J<=90?J+32:J;for(let V=0;V<=q.length-H;V+=1){let $=q[V];if(($>=65&&$<=90?$+32:$)!==Q)continue;let j=!0;for(let z=1;z<H;z+=1){let _=q[V+z],D=G.charCodeAt(z),T=_>=65&&_<=90?_+32:_,E=D>=65&&D<=90?D+32:D;if(T!==E){j=!1;break}}if(j)return!0}return!1}var jq=Zq([Z()]);function Bq(q,G){return jq(q,G)}export{Z as wps,Bq as toMarkdown};
1
+ import{create as Zq}from"@mdgate/core";import{CompoundFile as n,detectOleDoc as r,detectZipDoc as i,hasOleMagic as o,Package as b}from"@mdgate/containers";import{ConvertError as y}from"@mdgate/core";import{doc as s}from"@mdgate/doc";import{documentToMarkdown as t}from"@mdgate/document";import{docx as e}from"@mdgate/docx";import{ppt as qq}from"@mdgate/ppt";import{pptx as Gq}from"@mdgate/pptx";import{fileExtension as Hq}from"@mdgate/utils";import{xlsx as Jq}from"@mdgate/xlsx";import{CompoundFile as P,hasOleMagic as v,Package as C,parseXml as w}from"@mdgate/containers";import{ConvertError as W}from"@mdgate/core";import{emptyDocument as k,plain as h}from"@mdgate/document";import{cleanText as B,collapseWs as I,isAlphanumeric as g}from"@mdgate/utils";var u=2,R=2;function O(q){let G=[];try{if(a(q))x(q,G);else if(v(q))m(q,G);else S(q,G)}catch(Q){if(Q instanceof W&&(Q.code==="encrypted"||Q.isFatal()))throw Q;S(q,G)}let H=new Set,J=k();for(let Q of G){let V=I(B(Q)).trim();if(!F(V)||H.has(V))continue;H.add(V),J.blocks.push({type:"paragraph",inlines:[h(V)]})}if(J.blocks.length===0)throw W.malformed("no readable text in WPS document");return J}function x(q,G){let H=C.open(q);for(let J of H.partNames()){if(l(J))continue;let Q=H.optionalPart(J);if(Q!==void 0)S(Q,G)}}function m(q,G){let H=P.open(q);if(H.exists("EncryptionInfo")||H.exists("EncryptedPackage"))throw W.encrypted();let J=!1;for(let Q of H.readRootStorage()){if(Q.type!==u)continue;try{S(H.readStream(Q.name),G),J=!0}catch(V){if(V instanceof W&&V.isFatal())throw V}}if(!J)S(q,G)}function S(q,G){if(c(q))try{f(w(q),G);return}catch(H){if(H instanceof W&&H.isFatal())throw H}d(q,G),p(q,G)}function f(q,G){let H=(J)=>{let Q="",V=!1;for(let Y of J.children)if(Y.type==="text")Q+=Y.text;else V=!0;let $=I(B(Q)).trim();if(F($))G.push($);if(V)for(let Y of J.childElems())H(Y)};H(q)}function d(q,G){let H=[],J=()=>{if(H.length>=R)G.push(String.fromCharCode(...H));H.length=0};for(let Q=0;Q+1<q.length;Q+=2){let V=q[Q]|q[Q+1]<<8;if(V!==0&&A(V))H.push(V);else J()}J()}function p(q,G){let J=new TextDecoder("utf-8",{fatal:!1}).decode(q),Q=-1,V=($)=>{if(Q>=0&&$-Q>=R)G.push(J.slice(Q,$));Q=-1};for(let $=0;$<J.length;$+=1){let Y=J.charCodeAt($);if(A(Y)){if(Q<0)Q=$}else V($)}V(J.length)}function A(q){if(q===9||q===10||q===13||q===32)return!0;if(q<32||q>=127&&q<=159)return!1;return q!==65534&&q!==65535}function F(q){if(q.length<R)return!1;let G=0;for(let J of q)if(g(J))G+=1;if(G<2)return!1;let H=q.toLowerCase();if(H.includes("xmlns")||H.includes("http://schemas.")||H.includes("https://schemas."))return!1;if(H.startsWith("application/"))return!1;return!0}function c(q){let G=0;if(q.length>=3&&q[0]===239&&q[1]===187&&q[2]===191)G=3;while(G<q.length){let H=q[G];if(H!==9&&H!==10&&H!==13&&H!==32)break;G+=1}return q[G]===60}function l(q){let G=q.toLowerCase();if(G==="mimetype"||G==="[content_types].xml")return!0;if(G.endsWith(".rels"))return!0;return/\.(png|jpe?g|gif|bmp|emf|wmf|bin|ttf|otf|woff2?)$/i.test(G)}function a(q){return q.length>=4&&q[0]===80&&q[1]===75&&q[2]===3&&q[3]===4}var Qq=new Set(["wps","wpt","et","ett","dps","dpt"]),Vq=e(),$q=s(),Yq=Jq(),Wq=Gq(),Sq=qq();function Z(){return{id:"wps",sniff(q,G){if(U(q)!==void 0)return 0;if(zq(q))return 2;if(G?.path!==void 0&&Qq.has(Hq(G.path)??""))return 1;return 0},convert(q,G){if(Dq(q))throw y.unsupported("pdf");let H=U(q);if(H==="docx")return Vq.convert(q,G);if(H==="doc")return $q.convert(q,G);if(H==="xlsx"||H==="xls")return Yq.convert(q,G);if(H==="pptx")return Wq.convert(q,G);if(H==="ppt")return Sq.convert(q,G);return{markdown:t(O(q))}}}}function U(q){let G=i(q);if(G==="docx"||G==="xlsx"||G==="pptx")return G;let H=r(q);if(H==="doc"||H==="xls"||H==="ppt")return H;return}function zq(q){if(Lq(q))try{let G=b.open(q),H=G.optionalPart("mimetype");if(H!==void 0&&X(K(H)))return!0;for(let Q of G.partNames())if(M(Q))return!0;let J=G.optionalPart("[Content_Types].xml");if(J!==void 0&&X(K(J)))return!0;return!1}catch{}else if(o(q))try{let G=n.open(q);for(let H of G.readRootStorage())if(M(H.name))return!0}catch{}return _q(q)}function M(q){let G=q.charCodeAt(0)===5?q.slice(1):q;for(let H of G.split(/[/\\]/)){if(H.length===0)continue;if(N(H,"ks")||N(H,"wps"))return!0}return!1}function X(q){let G=q.toLowerCase();return G.includes("kingsoft")||G.includes("application/wps")||G.includes("application/vnd.wps")||G.includes("application/vnd.kingsoft")}function _q(q){let G=q.subarray(0,Math.min(q.length,65536));return L(G,"kingsoft")||L(G,"application/wps")||L(G,"application/vnd.wps")||L(G,"application/vnd.kingsoft")}function Dq(q){let G=0;if(q.length>=3&&q[0]===239&&q[1]===187&&q[2]===191)G=3;while(G<q.length){let H=q[G];if(H!==9&&H!==10&&H!==13&&H!==32)break;G+=1}return Rq(q,"%PDF-",G)}function Lq(q){return q.length>=4&&q[0]===80&&q[1]===75&&q[2]===3&&q[3]===4}function K(q){return new TextDecoder("utf-8",{fatal:!1}).decode(q)}function N(q,G){if(q.length<G.length)return!1;return q.slice(0,G.length).toLowerCase()===G}function Rq(q,G,H){if(H+G.length>q.length)return!1;for(let J=0;J<G.length;J+=1)if(q[H+J]!==G.charCodeAt(J))return!1;return!0}function L(q,G){if(G.length===0||q.length<G.length)return!1;let H=G.length,J=G.charCodeAt(0),Q=J>=65&&J<=90?J+32:J;for(let V=0;V<=q.length-H;V+=1){let $=q[V];if(($>=65&&$<=90?$+32:$)!==Q)continue;let j=!0;for(let z=1;z<H;z+=1){let _=q[V+z],D=G.charCodeAt(z),T=_>=65&&_<=90?_+32:_,E=D>=65&&D<=90?D+32:D;if(T!==E){j=!1;break}}if(j)return!0}return!1}var jq=Zq([Z()]);function Bq(q,G){return jq(q,G)}export{Z as wps,Bq as toMarkdown};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/wps",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "mdgate Kingsoft WPS converter (wps/et/dps)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,15 +22,15 @@
22
22
  "prepublishOnly": "bun run build"
23
23
  },
24
24
  "dependencies": {
25
- "@mdgate/containers": "0.5.0",
26
- "@mdgate/core": "0.5.0",
27
- "@mdgate/doc": "0.5.0",
28
- "@mdgate/document": "0.5.0",
29
- "@mdgate/docx": "0.5.0",
30
- "@mdgate/ppt": "0.5.0",
31
- "@mdgate/pptx": "0.5.0",
32
- "@mdgate/utils": "0.5.0",
33
- "@mdgate/xlsx": "0.5.0"
25
+ "@mdgate/containers": "0.5.1",
26
+ "@mdgate/core": "0.5.1",
27
+ "@mdgate/doc": "0.5.1",
28
+ "@mdgate/document": "0.5.1",
29
+ "@mdgate/docx": "0.5.1",
30
+ "@mdgate/ppt": "0.5.1",
31
+ "@mdgate/pptx": "0.5.1",
32
+ "@mdgate/utils": "0.5.1",
33
+ "@mdgate/xlsx": "0.5.1"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"