@mbler/mcx-core 0.1.2-rc.12 → 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 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;
@@ -13595,12 +13595,56 @@ var McxAst = class McxAst {
13595
13595
  }
13596
13596
  }
13597
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
+ }
13598
13637
  return {
13599
- start: createTagToken(),
13638
+ start: {
13639
+ data: elementSource.slice(0, openEnd),
13640
+ type: "Tag",
13641
+ start: absOffsetToMCXPos(fullSource, openTagStartAbs),
13642
+ end: absOffsetToMCXPos(fullSource, openTagEndAbs)
13643
+ },
13600
13644
  name: node.tag,
13601
13645
  arr: attrs,
13602
13646
  content: children,
13603
- end: null,
13647
+ end: endToken,
13604
13648
  loc: {
13605
13649
  start: {
13606
13650
  line: node.loc.start.line,