@mdgate/wps 0.1.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/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @mdgate/wps
2
+
3
+ Convert Kingsoft WPS Writer, Spreadsheets, and Presentation files to Markdown.
4
+ Outputs GitHub-Flavored Markdown. Works in Node, Edge, and browsers. No native
5
+ addons.
6
+
7
+ Handles: `.wps`, `.wpt`, `.et`, `.ett`, `.dps`, `.dpt`
8
+
9
+ OOXML/OLE Office-compatible files are delegated to the matching official
10
+ converter. Proprietary Kingsoft packages are best-effort text extraction.
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import { toMarkdown } from '@mdgate/wps';
16
+
17
+ const markdown = await toMarkdown(bytes);
18
+ ```
19
+
20
+ Compose with other converters:
21
+
22
+ ```ts
23
+ import { create } from '@mdgate/core';
24
+ import { wps } from '@mdgate/wps';
25
+
26
+ const convert = create([wps()]);
27
+ ```
28
+
29
+ Part of [mdgate converters](https://github.com/mdgate/converters); install
30
+ `@mdgate/converters` for every format at once.
@@ -0,0 +1,2 @@
1
+ export { toMarkdown } from './to-markdown.js';
2
+ export { wps } from './wps.js';
package/dist/index.js ADDED
@@ -0,0 +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};
@@ -0,0 +1,6 @@
1
+ import { type ConvertHint } from '@mdgate/core';
2
+ /**
3
+ * Convert a single file's bytes to Markdown with the wps converter.
4
+ * `hint.path` is only a sniff hint; it is never read from disk.
5
+ */
6
+ export declare function toMarkdown(bytes: Uint8Array, hint?: ConvertHint): Promise<string>;
package/dist/wps.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { Converter } from '@mdgate/core';
2
+ export declare function wps(): Converter;
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@mdgate/wps",
3
+ "version": "0.1.0",
4
+ "description": "mdgate Kingsoft WPS converter (wps/et/dps)",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist/**/*.js",
18
+ "dist/**/*.d.ts"
19
+ ],
20
+ "scripts": {
21
+ "build": "bun ../../scripts/build-package.ts",
22
+ "prepublishOnly": "bun run build"
23
+ },
24
+ "dependencies": {
25
+ "@mdgate/containers": "0.1.0",
26
+ "@mdgate/core": "0.1.3",
27
+ "@mdgate/doc": "0.1.0",
28
+ "@mdgate/document": "0.1.0",
29
+ "@mdgate/docx": "0.1.0",
30
+ "@mdgate/ppt": "0.1.0",
31
+ "@mdgate/pptx": "0.1.0",
32
+ "@mdgate/utils": "0.1.2",
33
+ "@mdgate/xlsx": "0.1.0"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "engines": {
39
+ "node": ">=20"
40
+ },
41
+ "keywords": [
42
+ "mdgate",
43
+ "markdown",
44
+ "wps",
45
+ "et",
46
+ "dps",
47
+ "kingsoft"
48
+ ]
49
+ }