@swc/html 0.0.15 → 0.0.17

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/binding.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export interface Diagnostic {
7
+ level: string;
8
+ message: string;
9
+ span: any;
10
+ }
11
+ export interface TransformOutput {
12
+ code: string;
13
+ errors?: Array<Diagnostic>;
14
+ }
15
+ export interface Attribute {
16
+ namespace?: string;
17
+ prefix?: string;
18
+ name: string;
19
+ value?: string;
20
+ }
21
+ export interface Element {
22
+ tagName: string;
23
+ namespace: string;
24
+ attributes: Array<Attribute>;
25
+ isSelfClosing: boolean;
26
+ }
27
+ export function minify(
28
+ code: Buffer,
29
+ opts: Buffer,
30
+ signal?: AbortSignal | undefined | null
31
+ ): Promise<TransformOutput>;
32
+ export function minifyFragment(
33
+ code: Buffer,
34
+ opts: Buffer,
35
+ signal?: AbortSignal | undefined | null
36
+ ): Promise<TransformOutput>;
37
+ export function minifySync(code: Buffer, opts: Buffer): TransformOutput;
38
+ export function minifyFragmentSync(code: Buffer, opts: Buffer): TransformOutput;
@@ -240,7 +240,10 @@ if (!nativeBinding) {
240
240
  throw new Error(`Failed to load native binding`);
241
241
  }
242
242
 
243
- const { minify, minifySync } = nativeBinding;
243
+ const { minify, minifyFragment, minifySync, minifyFragmentSync } =
244
+ nativeBinding;
244
245
 
245
246
  module.exports.minify = minify;
247
+ module.exports.minifyFragment = minifyFragment;
246
248
  module.exports.minifySync = minifySync;
249
+ module.exports.minifyFragmentSync = minifyFragmentSync;
@@ -23,16 +23,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.minifySync = exports.minify = void 0;
26
+ exports.minifyFragmentSync = exports.minifySync = exports.minifyFragment = exports.minify = void 0;
27
27
  const binding = __importStar(require("./binding"));
28
28
  async function minify(content, options) {
29
29
  return binding.minify(content, toBuffer(options !== null && options !== void 0 ? options : {}));
30
30
  }
31
31
  exports.minify = minify;
32
+ async function minifyFragment(content, options) {
33
+ return binding.minifyFragment(content, toBuffer(options !== null && options !== void 0 ? options : {}));
34
+ }
35
+ exports.minifyFragment = minifyFragment;
32
36
  function minifySync(content, options) {
33
37
  return binding.minifySync(content, toBuffer(options !== null && options !== void 0 ? options : {}));
34
38
  }
35
39
  exports.minifySync = minifySync;
40
+ async function minifyFragmentSync(content, options) {
41
+ return binding.minifyFragmentSync(content, toBuffer(options !== null && options !== void 0 ? options : {}));
42
+ }
43
+ exports.minifyFragmentSync = minifyFragmentSync;
36
44
  function toBuffer(t) {
37
45
  return Buffer.from(JSON.stringify(t));
38
46
  }
package/index.ts ADDED
@@ -0,0 +1,74 @@
1
+ import * as binding from "./binding";
2
+
3
+ type MinifierType = "js-module" | "js-script" | "json" | "css" | "html";
4
+
5
+ type Options = {
6
+ filename?: string;
7
+ iframeSrcdoc?: boolean;
8
+ scriptingEnabled?: boolean;
9
+ forceSetHtml5Doctype?: boolean;
10
+ collapseWhitespaces?:
11
+ | "none"
12
+ | "all"
13
+ | "smart"
14
+ | "conservative"
15
+ | "advanced-conservative"
16
+ | "only-metadata";
17
+ removeEmptyMetadataElements?: boolean;
18
+ removeComments?: boolean;
19
+ preserveComments: string[];
20
+ minifyConditionalComments?: boolean;
21
+ removeEmptyAttributes?: boolean;
22
+ removeRedundantAttributes?: boolean;
23
+ collapseBooleanAttributes?: boolean;
24
+ normalizeAttributes?: boolean;
25
+ minifyJson?: boolean | { pretty?: boolean };
26
+ // TODO improve me after typing `@swc/css`
27
+ minifyJs?: boolean | { parser?: any; minifier?: any; codegen?: any };
28
+ minifyCss?: boolean | { parser?: any; minifier?: any; codegen?: any };
29
+ minifyAdditionalScriptsContent?: [string, MinifierType][];
30
+ minifyAdditionalAttributes?: [string, MinifierType][];
31
+ sortSpaceSeparatedAttributeValues?: boolean;
32
+ sortAttributes?: boolean;
33
+ tagOmission?: boolean;
34
+ selfClosingVoidElements?: boolean;
35
+ quotes?: boolean;
36
+ };
37
+
38
+ type FragmentOptions = Options & {
39
+ mode?: "no-quirks" | "limited-quirks" | "quirks";
40
+ context_element?: binding.Element;
41
+ form_element?: binding.Element;
42
+ };
43
+
44
+ export async function minify(
45
+ content: Buffer,
46
+ options?: Options
47
+ ): Promise<binding.TransformOutput> {
48
+ return binding.minify(content, toBuffer(options ?? {}));
49
+ }
50
+
51
+ export async function minifyFragment(
52
+ content: Buffer,
53
+ options?: FragmentOptions
54
+ ): Promise<binding.TransformOutput> {
55
+ return binding.minifyFragment(content, toBuffer(options ?? {}));
56
+ }
57
+
58
+ export function minifySync(
59
+ content: Buffer,
60
+ options?: Options
61
+ ): binding.TransformOutput {
62
+ return binding.minifySync(content, toBuffer(options ?? {}));
63
+ }
64
+
65
+ export async function minifyFragmentSync(
66
+ content: Buffer,
67
+ options?: FragmentOptions
68
+ ): Promise<binding.TransformOutput> {
69
+ return binding.minifyFragmentSync(content, toBuffer(options ?? {}));
70
+ }
71
+
72
+ function toBuffer(t: any): Buffer {
73
+ return Buffer.from(JSON.stringify(t));
74
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@swc/html",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Super-fast alternative for posthtml",
5
5
  "homepage": "https://swc.rs",
6
- "main": "./lib/index.js",
6
+ "main": "./index.js",
7
7
  "author": "강동윤 <kdy1997.dev@gmail.com>",
8
8
  "license": "Apache-2.0",
9
9
  "keywords": [
@@ -48,24 +48,24 @@
48
48
  "pack": "wasm-pack",
49
49
  "build:ts": "tsc -d",
50
50
  "build:wasm": "npm-run-all \"pack -- build ./crates/wasm --scope swc {1} -t {2} \" --",
51
- "build": "tsc -d && napi build --platform --cargo-name html_node --js ./lib/binding.js --dts ./lib/binding.d.ts -p html_node --release --cargo-cwd ../..",
52
- "build:dev": "tsc -d && napi build --platform --cargo-name html_node --js ./lib/binding.js --dts ./lib/binding.d.ts -p html_node --cargo-cwd ../..",
51
+ "build": "tsc -d && napi build --platform --cargo-name html_node --js ./binding.js --dts binding.d.ts -p html_node --release --cargo-cwd ../..",
52
+ "build:dev": "tsc -d && napi build --platform --cargo-name html_node --js ./binding.js --dts binding.d.ts -p html_node --cargo-cwd ../..",
53
53
  "test": "echo 'done!'",
54
54
  "version": "napi version -p scripts/npm"
55
55
  },
56
56
  "optionalDependencies": {
57
- "@swc/html-win32-x64-msvc": "0.0.15",
58
- "@swc/html-darwin-x64": "0.0.15",
59
- "@swc/html-linux-x64-gnu": "0.0.15",
60
- "@swc/html-linux-x64-musl": "0.0.15",
61
- "@swc/html-freebsd-x64": "0.0.15",
62
- "@swc/html-win32-ia32-msvc": "0.0.15",
63
- "@swc/html-linux-arm64-gnu": "0.0.15",
64
- "@swc/html-linux-arm-gnueabihf": "0.0.15",
65
- "@swc/html-darwin-arm64": "0.0.15",
66
- "@swc/html-android-arm64": "0.0.15",
67
- "@swc/html-linux-arm64-musl": "0.0.15",
68
- "@swc/html-win32-arm64-msvc": "0.0.15",
69
- "@swc/html-android-arm-eabi": "0.0.15"
57
+ "@swc/html-win32-x64-msvc": "0.0.17",
58
+ "@swc/html-darwin-x64": "0.0.17",
59
+ "@swc/html-linux-x64-gnu": "0.0.17",
60
+ "@swc/html-linux-x64-musl": "0.0.17",
61
+ "@swc/html-freebsd-x64": "0.0.17",
62
+ "@swc/html-win32-ia32-msvc": "0.0.17",
63
+ "@swc/html-linux-arm64-gnu": "0.0.17",
64
+ "@swc/html-linux-arm-gnueabihf": "0.0.17",
65
+ "@swc/html-darwin-arm64": "0.0.17",
66
+ "@swc/html-android-arm64": "0.0.17",
67
+ "@swc/html-linux-arm64-musl": "0.0.17",
68
+ "@swc/html-win32-arm64-msvc": "0.0.17",
69
+ "@swc/html-android-arm-eabi": "0.0.17"
70
70
  }
71
71
  }
package/lib/binding.d.ts DELETED
@@ -1,11 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
-
4
- /* auto-generated by NAPI-RS */
5
-
6
- export function minify(
7
- code: Buffer,
8
- opts: Buffer,
9
- signal?: AbortSignal | undefined | null
10
- ): Promise<string>;
11
- export function minifySync(code: Buffer, opts: Buffer): string;
package/lib/index.ts DELETED
@@ -1,13 +0,0 @@
1
- import * as binding from "./binding";
2
-
3
- export async function minify(content: Buffer, options?: any): Promise<string> {
4
- return binding.minify(content, toBuffer(options ?? {}));
5
- }
6
-
7
- export function minifySync(content: Buffer, options?: any) {
8
- return binding.minifySync(content, toBuffer(options ?? {}));
9
- }
10
-
11
- function toBuffer(t: any): Buffer {
12
- return Buffer.from(JSON.stringify(t));
13
- }