@mdgate/image 0.1.0 → 0.1.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.
- package/README.md +1 -1
- package/dist/image.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/types.d.ts +0 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mdgate/image
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Converter for JPEG, PNG, and WebP. Pass any `(input) => markdown` function — `@mdgate/ai`, Apple OCR, or your own.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
import { create } from '@mdgate/core';
|
package/dist/image.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function image(
|
|
1
|
+
import type { Converter } from '@mdgate/core';
|
|
2
|
+
import type { ConvertImage } from './types.js';
|
|
3
|
+
export declare function image(convertImage: ConvertImage): Converter;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { image } from './image.js';
|
|
2
|
-
export type { ConvertImage, ImageInput, ImageMime
|
|
2
|
+
export type { ConvertImage, ImageInput, ImageMime } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{ConvertError as m}from"@mdgate/core";var g={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"};function p(e){return{id:"image",sniff(r,n){if(o(r)!==void 0)return 2;if(n?.path!==void 0&&a(n.path)!==void 0)return 1;return 0},async convert(r,n){let t=o(r)??(n?.path!==void 0?a(n.path):void 0);if(t===void 0)throw m.unsupported(n?.path===void 0?"unrecognized file content: name the format explicitly":`unrecognized file content and extension: ${n.path}`);let i=await e({bytes:r,mime:t,page:n?.page});return{markdown:i.endsWith(`
|
|
2
|
+
`)?i:`${i}
|
|
3
|
+
`}}}}function o(e){if(e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255)return"image/jpeg";if(e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10)return"image/png";if(e.length>=12&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80)return"image/webp";return}function a(e){let r=e.split(/[/\\]/).pop()??"",n=r.lastIndexOf(".");if(n<=0||n===r.length-1)return;return g[r.slice(n+1).toLowerCase()]}export{p as image};
|
package/dist/types.d.ts
CHANGED
|
@@ -2,12 +2,6 @@ export type ImageMime = 'image/jpeg' | 'image/png' | 'image/webp';
|
|
|
2
2
|
export type ImageInput = {
|
|
3
3
|
bytes: Uint8Array;
|
|
4
4
|
mime: ImageMime;
|
|
5
|
-
/** 1-based page number when the image came from a paged document. */
|
|
6
5
|
page?: number;
|
|
7
6
|
};
|
|
8
|
-
/** Convert an image the format converter cannot handle into markdown. */
|
|
9
7
|
export type ConvertImage = (image: ImageInput) => Promise<string>;
|
|
10
|
-
export type ImagePlugin = {
|
|
11
|
-
readonly kind: 'image';
|
|
12
|
-
readonly convert: ConvertImage;
|
|
13
|
-
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/image",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "mdgate image converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prepublishOnly": "bun run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@mdgate/core": "0.1.
|
|
25
|
+
"@mdgate/core": "0.1.3"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|