@mbler/mcx-core 0.1.2-rc.11 → 0.1.2-rc.13
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 +40 -40
- package/client.d.ts +17 -17
- package/dist/index.js +64 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-DEq-mXcV.js +0 -15
package/README.md
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# @mbler/mcx-core
|
|
2
|
-
|
|
3
|
-
The MCX DSL compiler — the core of the MCX ecosystem. Compiles `.mcx` source files into MCBE-compatible JSON components, UI forms, and event systems.
|
|
4
|
-
|
|
5
|
-
## Pipeline
|
|
6
|
-
|
|
7
|
-
`.mcx` file → **parser** → AST → **transform** (Babel) → compiled JS → MCBE JSON
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- **MCX Parser** — Parses `.mcx` source into a tokenized AST (`tag`, `prop`)
|
|
12
|
-
- **Transform Pipeline** — Detects file type (`event`, `ui`, `component`, `app`) and generates compiled Babel AST
|
|
13
|
-
- **Component Compilation** — Runs component scripts in a sandboxed VM, generates MCBE JSON, executes file edit operations
|
|
14
|
-
- **CJS Transform** — Rewrites ESM imports to CommonJS `require()` for VM execution
|
|
15
|
-
- **Image Assets** — Compiles PNG, JPG, SVG, GIF image references into MCBE texture assets
|
|
16
|
-
- **Rollup/Rolldown Plugin** — Seamless `.mcx` file resolution and transformation in your build pipeline
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
pnpm add -D @mbler/mcx-core
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Usage
|
|
25
|
-
|
|
26
|
-
Add the plugin to your Rollup or Rolldown config:
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
import { rollupPlugin } from '@mbler/mcx-core'
|
|
30
|
-
|
|
31
|
-
export default {
|
|
32
|
-
plugins: [rollupPlugin({ moduleDir: './modules', tsconfigPath: './tsconfig.json' })],
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
For full documentation, visit the **[Docs](https://mbler-docs.ruanhor.dpdns.org/guide/mcx)**.
|
|
37
|
-
|
|
38
|
-
## License
|
|
39
|
-
|
|
40
|
-
MIT
|
|
1
|
+
# @mbler/mcx-core
|
|
2
|
+
|
|
3
|
+
The MCX DSL compiler — the core of the MCX ecosystem. Compiles `.mcx` source files into MCBE-compatible JSON components, UI forms, and event systems.
|
|
4
|
+
|
|
5
|
+
## Pipeline
|
|
6
|
+
|
|
7
|
+
`.mcx` file → **parser** → AST → **transform** (Babel) → compiled JS → MCBE JSON
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **MCX Parser** — Parses `.mcx` source into a tokenized AST (`tag`, `prop`)
|
|
12
|
+
- **Transform Pipeline** — Detects file type (`event`, `ui`, `component`, `app`) and generates compiled Babel AST
|
|
13
|
+
- **Component Compilation** — Runs component scripts in a sandboxed VM, generates MCBE JSON, executes file edit operations
|
|
14
|
+
- **CJS Transform** — Rewrites ESM imports to CommonJS `require()` for VM execution
|
|
15
|
+
- **Image Assets** — Compiles PNG, JPG, SVG, GIF image references into MCBE texture assets
|
|
16
|
+
- **Rollup/Rolldown Plugin** — Seamless `.mcx` file resolution and transformation in your build pipeline
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add -D @mbler/mcx-core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Add the plugin to your Rollup or Rolldown config:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { rollupPlugin } from '@mbler/mcx-core'
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
plugins: [rollupPlugin({ moduleDir: './modules', tsconfigPath: './tsconfig.json' })],
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For full documentation, visit the **[Docs](https://mbler-docs.ruanhor.dpdns.org/guide/mcx)**.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT
|
package/client.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type * as mcx from "."
|
|
2
|
-
|
|
3
|
-
declare module "*.png" {
|
|
4
|
-
export default mcx.PNGImageComponent
|
|
5
|
-
}
|
|
6
|
-
declare module "*.svg" {
|
|
7
|
-
export default mcx.SVGImageComponent
|
|
8
|
-
}
|
|
9
|
-
declare module "*.jpg" {
|
|
10
|
-
export default mcx.JPGImageComponent
|
|
11
|
-
}
|
|
12
|
-
declare module "*.jpeg" {
|
|
13
|
-
export default mcx.JPGImageComponent
|
|
14
|
-
}
|
|
15
|
-
declare module "*.gif" {
|
|
16
|
-
export default mcx.GIFImageComponent
|
|
17
|
-
}
|
|
1
|
+
import type * as mcx from "."
|
|
2
|
+
|
|
3
|
+
declare module "*.png" {
|
|
4
|
+
export default mcx.PNGImageComponent
|
|
5
|
+
}
|
|
6
|
+
declare module "*.svg" {
|
|
7
|
+
export default mcx.SVGImageComponent
|
|
8
|
+
}
|
|
9
|
+
declare module "*.jpg" {
|
|
10
|
+
export default mcx.JPGImageComponent
|
|
11
|
+
}
|
|
12
|
+
declare module "*.jpeg" {
|
|
13
|
+
export default mcx.JPGImageComponent
|
|
14
|
+
}
|
|
15
|
+
declare module "*.gif" {
|
|
16
|
+
export default mcx.GIFImageComponent
|
|
17
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -13510,23 +13510,23 @@ var import_compiler_core = (/* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
13510
13510
|
if (process.env.NODE_ENV === "production") module.exports = require_compiler_core_cjs_prod();
|
|
13511
13511
|
else module.exports = require_compiler_core_cjs();
|
|
13512
13512
|
})))();
|
|
13513
|
-
function createTagToken() {
|
|
13514
|
-
return {
|
|
13515
|
-
data: "",
|
|
13516
|
-
type: "Tag",
|
|
13517
|
-
start: {
|
|
13518
|
-
line: 0,
|
|
13519
|
-
column: 0
|
|
13520
|
-
},
|
|
13521
|
-
end: {
|
|
13522
|
-
line: 0,
|
|
13523
|
-
column: 0
|
|
13524
|
-
}
|
|
13525
|
-
};
|
|
13526
|
-
}
|
|
13527
13513
|
function getExpressionContent(expr) {
|
|
13528
13514
|
return expr?.content ?? "true";
|
|
13529
13515
|
}
|
|
13516
|
+
/** Convert absolute character offset in source to MCX position (line: 1-indexed, column: 0-indexed) */
|
|
13517
|
+
function absOffsetToMCXPos(source, absOffset) {
|
|
13518
|
+
let line = 1;
|
|
13519
|
+
let col = 0;
|
|
13520
|
+
const len = Math.min(absOffset, source.length);
|
|
13521
|
+
for (let i = 0; i < len; i++) if (source.charCodeAt(i) === 10) {
|
|
13522
|
+
line++;
|
|
13523
|
+
col = 0;
|
|
13524
|
+
} else col++;
|
|
13525
|
+
return {
|
|
13526
|
+
line,
|
|
13527
|
+
column: col
|
|
13528
|
+
};
|
|
13529
|
+
}
|
|
13530
13530
|
var McxAst = class McxAst {
|
|
13531
13531
|
text;
|
|
13532
13532
|
includeComments;
|
|
@@ -13535,7 +13535,10 @@ var McxAst = class McxAst {
|
|
|
13535
13535
|
this.includeComments = includeComments;
|
|
13536
13536
|
}
|
|
13537
13537
|
parseAST() {
|
|
13538
|
-
const ast = (0, import_compiler_core.baseParse)(this.text, {
|
|
13538
|
+
const ast = (0, import_compiler_core.baseParse)(this.text, {
|
|
13539
|
+
comments: true,
|
|
13540
|
+
whitespace: "preserve"
|
|
13541
|
+
});
|
|
13539
13542
|
const result = [];
|
|
13540
13543
|
for (const child of ast.children) {
|
|
13541
13544
|
const node = this.convertTemplateChild(child);
|
|
@@ -13592,12 +13595,56 @@ var McxAst = class McxAst {
|
|
|
13592
13595
|
}
|
|
13593
13596
|
}
|
|
13594
13597
|
const children = this.convertVueChildren(node.children);
|
|
13598
|
+
const fullSource = this.text;
|
|
13599
|
+
const baseOffset = node.loc.start.offset;
|
|
13600
|
+
const elementSource = node.loc.source;
|
|
13601
|
+
let openEnd = elementSource.length;
|
|
13602
|
+
let inQuote = null;
|
|
13603
|
+
for (let i = 0; i < elementSource.length; i++) {
|
|
13604
|
+
const c = elementSource[i];
|
|
13605
|
+
if (inQuote) {
|
|
13606
|
+
if (c === "\\") {
|
|
13607
|
+
i++;
|
|
13608
|
+
continue;
|
|
13609
|
+
}
|
|
13610
|
+
if (c === inQuote) inQuote = null;
|
|
13611
|
+
} else if (c === "\"" || c === "'") inQuote = c;
|
|
13612
|
+
else if (c === ">") {
|
|
13613
|
+
openEnd = i + 1;
|
|
13614
|
+
break;
|
|
13615
|
+
}
|
|
13616
|
+
}
|
|
13617
|
+
let closeStart = -1;
|
|
13618
|
+
if (!node.isSelfClosing) {
|
|
13619
|
+
for (let i = elementSource.length - 2; i >= 0; i--) if (elementSource[i] === "<" && elementSource[i + 1] === "/") {
|
|
13620
|
+
closeStart = i;
|
|
13621
|
+
break;
|
|
13622
|
+
}
|
|
13623
|
+
}
|
|
13624
|
+
const openTagStartAbs = baseOffset;
|
|
13625
|
+
const openTagEndAbs = baseOffset + openEnd;
|
|
13626
|
+
let endToken = null;
|
|
13627
|
+
if (closeStart >= 0) {
|
|
13628
|
+
const closeTagStartAbs = baseOffset + closeStart;
|
|
13629
|
+
const closeTagEndAbs = baseOffset + elementSource.length;
|
|
13630
|
+
endToken = {
|
|
13631
|
+
data: elementSource.slice(closeStart),
|
|
13632
|
+
type: "TagEnd",
|
|
13633
|
+
start: absOffsetToMCXPos(fullSource, closeTagStartAbs),
|
|
13634
|
+
end: absOffsetToMCXPos(fullSource, closeTagEndAbs)
|
|
13635
|
+
};
|
|
13636
|
+
}
|
|
13595
13637
|
return {
|
|
13596
|
-
start:
|
|
13638
|
+
start: {
|
|
13639
|
+
data: elementSource.slice(0, openEnd),
|
|
13640
|
+
type: "Tag",
|
|
13641
|
+
start: absOffsetToMCXPos(fullSource, openTagStartAbs),
|
|
13642
|
+
end: absOffsetToMCXPos(fullSource, openTagEndAbs)
|
|
13643
|
+
},
|
|
13597
13644
|
name: node.tag,
|
|
13598
13645
|
arr: attrs,
|
|
13599
13646
|
content: children,
|
|
13600
|
-
end:
|
|
13647
|
+
end: endToken,
|
|
13601
13648
|
loc: {
|
|
13602
13649
|
start: {
|
|
13603
13650
|
line: node.loc.start.line,
|