@matrajs/vue 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nahim Hossain Shohan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @matrajs/vue
2
+
3
+ Vue 3 bindings for Matra: `useEditor`, `useEditorState`, `useEditorFocus` and
4
+ `EditorContent`.
5
+
6
+ ```bash
7
+ npm i @matrajs/core @matrajs/vue
8
+ ```
9
+
10
+ ```vue
11
+ <script setup lang="ts">
12
+ import { starterKit } from '@matrajs/core'
13
+ import { EditorContent, useEditor, useEditorState } from '@matrajs/vue'
14
+
15
+ const editor = useEditor({ extensions: starterKit, content: '<p>Hello</p>' })
16
+ const isBold = useEditorState(editor, (e) => e.getHTML().includes('<strong>'))
17
+ </script>
18
+
19
+ <template>
20
+ <button :aria-pressed="isBold" @mousedown.prevent="editor.commands.toggleBold()">
21
+ Bold
22
+ </button>
23
+ <EditorContent :editor="editor" />
24
+ </template>
25
+ ```
26
+
27
+ The editor is `markRaw`-ed on purpose: it is a mutable object with its own
28
+ change events, and putting it in Vue's reactivity graph would trace every
29
+ document node on every keystroke. Read from it with `useEditorState`.
30
+
31
+ - Source: https://github.com/amrelaco/matra
32
+
33
+ MIT.
package/dist/index.cjs ADDED
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+ var core = require('@matrajs/core');
5
+
6
+ // src/editor-content.ts
7
+ var EditorContent = vue.defineComponent({
8
+ name: "EditorContent",
9
+ props: {
10
+ editor: {
11
+ type: Object,
12
+ required: true
13
+ }
14
+ },
15
+ setup(props) {
16
+ const root = vue.ref(null);
17
+ vue.onMounted(() => {
18
+ const element = root.value;
19
+ if (!element || props.editor.unsafe.view) return;
20
+ props.editor.mount(element);
21
+ });
22
+ return () => vue.h("div", { ref: root, class: "matra-content" });
23
+ }
24
+ });
25
+ function useEditor(options) {
26
+ const editor = vue.markRaw(core.createEditor(options));
27
+ const dispose = () => editor.destroy();
28
+ if (vue.getCurrentInstance()) vue.onBeforeUnmount(dispose);
29
+ else vue.onScopeDispose(dispose);
30
+ return editor;
31
+ }
32
+ function useEditorState(editor, select) {
33
+ const value = vue.ref(select(editor));
34
+ const update = () => {
35
+ value.value = select(editor);
36
+ };
37
+ const offChange = editor.on("change", update);
38
+ const offSelection = editor.on("selectionChange", update);
39
+ const dispose = () => {
40
+ offChange();
41
+ offSelection();
42
+ };
43
+ if (vue.getCurrentInstance()) vue.onBeforeUnmount(dispose);
44
+ else vue.onScopeDispose(dispose);
45
+ return vue.readonly(value);
46
+ }
47
+ function useEditorFocus(editor) {
48
+ const focused = vue.ref(false);
49
+ const offFocus = editor.on("focus", () => {
50
+ focused.value = true;
51
+ });
52
+ const offBlur = editor.on("blur", () => {
53
+ focused.value = false;
54
+ });
55
+ const dispose = () => {
56
+ offFocus();
57
+ offBlur();
58
+ };
59
+ if (vue.getCurrentInstance()) vue.onBeforeUnmount(dispose);
60
+ else vue.onScopeDispose(dispose);
61
+ return vue.readonly(focused);
62
+ }
63
+
64
+ exports.EditorContent = EditorContent;
65
+ exports.useEditor = useEditor;
66
+ exports.useEditorFocus = useEditorFocus;
67
+ exports.useEditorState = useEditorState;
68
+ //# sourceMappingURL=index.cjs.map
69
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/editor-content.ts","../src/use-editor.ts"],"names":["defineComponent","ref","onMounted","h","markRaw","createEditor","getCurrentInstance","onBeforeUnmount","readonly"],"mappings":";;;;;;AASO,IAAM,gBAAgBA,mBAAA,CAAgB;AAAA,EAC3C,IAAA,EAAM,eAAA;AAAA,EACN,KAAA,EAAO;AAAA,IACL,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,MAAA;AAAA,MACN,QAAA,EAAU;AAAA;AACZ,GACF;AAAA,EACA,MAAM,KAAA,EAAO;AACX,IAAA,MAAM,IAAA,GAAOC,QAAwB,IAAI,CAAA;AAEzC,IAAAC,aAAA,CAAU,MAAM;AACd,MAAA,MAAM,UAAU,IAAA,CAAK,KAAA;AACrB,MAAA,IAAI,CAAC,OAAA,IAAW,KAAA,CAAM,MAAA,CAAO,OAAO,IAAA,EAAM;AAC1C,MAAA,KAAA,CAAM,MAAA,CAAO,MAAM,OAAO,CAAA;AAAA,IAC5B,CAAC,CAAA;AAED,IAAA,OAAO,MAAMC,MAAE,KAAA,EAAO,EAAE,KAAK,IAAA,EAAM,KAAA,EAAO,iBAAiB,CAAA;AAAA,EAC7D;AACF,CAAC;ACRM,SAAS,UACd,OAAA,EACW;AACX,EAAA,MAAM,MAAA,GAASC,WAAA,CAAQC,iBAAA,CAAa,OAAO,CAAC,CAAA;AAE5C,EAAA,MAAM,OAAA,GAAU,MAAM,MAAA,CAAO,OAAA,EAAQ;AAErC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gB,OAAO,CAAA;AAAA,0BAC7B,OAAO,CAAA;AAE3B,EAAA,OAAOC,aAAS,OAAO,CAAA;AACzB","file":"index.cjs","sourcesContent":["import type { AnyDef, Editor } from '@matrajs/core'\nimport { type PropType, defineComponent, h, onMounted, ref } from 'vue'\n\n/**\n * The element the editor mounts into.\n *\n * The mount is guarded on `unsafe.view`, so a component remounted by a\n * `<KeepAlive>` or a hot reload does not attach a second view to one element.\n */\nexport const EditorContent = defineComponent({\n name: 'EditorContent',\n props: {\n editor: {\n type: Object as PropType<Editor<readonly AnyDef[]>>,\n required: true,\n },\n },\n setup(props) {\n const root = ref<HTMLElement | null>(null)\n\n onMounted(() => {\n const element = root.value\n if (!element || props.editor.unsafe.view) return\n props.editor.mount(element)\n })\n\n return () => h('div', { ref: root, class: 'matra-content' })\n },\n})\n","import { createEditor } from '@matrajs/core'\nimport type { AnyDef, Editor, EditorOptions } from '@matrajs/core'\nimport {\n type Ref,\n getCurrentInstance,\n markRaw,\n onBeforeUnmount,\n onScopeDispose,\n readonly,\n ref,\n} from 'vue'\n\n/**\n * Create an editor that lives as long as the component using it.\n *\n * The editor is deliberately **not** reactive: it is a mutable object with its\n * own change events, and wrapping it in a proxy would make Vue trace every\n * document node on every keystroke. `markRaw` keeps it out of the reactivity\n * graph; use `useEditorState` to read from it reactively.\n */\nexport function useEditor<const T extends readonly AnyDef[]>(\n options: EditorOptions<T>,\n): Editor<T> {\n const editor = markRaw(createEditor(options))\n\n const dispose = () => editor.destroy()\n // Works inside a component or a bare effect scope.\n if (getCurrentInstance()) onBeforeUnmount(dispose)\n else onScopeDispose(dispose)\n\n return editor\n}\n\n/**\n * A reactive view of the editor.\n *\n * Toolbars need this: commands mutate the document, but Vue has no way to know\n * unless something subscribes. The selector re-runs on every change and\n * selection move.\n */\nexport function useEditorState<T extends readonly AnyDef[], S>(\n editor: Editor<T>,\n select: (editor: Editor<T>) => S,\n): Readonly<Ref<S>> {\n const value = ref(select(editor)) as Ref<S>\n\n const update = () => {\n value.value = select(editor)\n }\n const offChange = editor.on('change', update)\n const offSelection = editor.on('selectionChange', update)\n\n const dispose = () => {\n offChange()\n offSelection()\n }\n if (getCurrentInstance()) onBeforeUnmount(dispose)\n else onScopeDispose(dispose)\n\n return readonly(value) as Readonly<Ref<S>>\n}\n\n/** True while the editor has DOM focus. */\nexport function useEditorFocus<T extends readonly AnyDef[]>(\n editor: Editor<T>,\n): Readonly<Ref<boolean>> {\n const focused = ref(false)\n const offFocus = editor.on('focus', () => {\n focused.value = true\n })\n const offBlur = editor.on('blur', () => {\n focused.value = false\n })\n\n const dispose = () => {\n offFocus()\n offBlur()\n }\n if (getCurrentInstance()) onBeforeUnmount(dispose)\n else onScopeDispose(dispose)\n\n return readonly(focused)\n}\n"]}
@@ -0,0 +1,45 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, Ref } from 'vue';
3
+ import { Editor, AnyDef, EditorOptions } from '@matrajs/core';
4
+
5
+ /**
6
+ * The element the editor mounts into.
7
+ *
8
+ * The mount is guarded on `unsafe.view`, so a component remounted by a
9
+ * `<KeepAlive>` or a hot reload does not attach a second view to one element.
10
+ */
11
+ declare const EditorContent: vue.DefineComponent<vue.ExtractPropTypes<{
12
+ editor: {
13
+ type: PropType<Editor<readonly AnyDef[]>>;
14
+ required: true;
15
+ };
16
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
17
+ [key: string]: any;
18
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
19
+ editor: {
20
+ type: PropType<Editor<readonly AnyDef[]>>;
21
+ required: true;
22
+ };
23
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
24
+
25
+ /**
26
+ * Create an editor that lives as long as the component using it.
27
+ *
28
+ * The editor is deliberately **not** reactive: it is a mutable object with its
29
+ * own change events, and wrapping it in a proxy would make Vue trace every
30
+ * document node on every keystroke. `markRaw` keeps it out of the reactivity
31
+ * graph; use `useEditorState` to read from it reactively.
32
+ */
33
+ declare function useEditor<const T extends readonly AnyDef[]>(options: EditorOptions<T>): Editor<T>;
34
+ /**
35
+ * A reactive view of the editor.
36
+ *
37
+ * Toolbars need this: commands mutate the document, but Vue has no way to know
38
+ * unless something subscribes. The selector re-runs on every change and
39
+ * selection move.
40
+ */
41
+ declare function useEditorState<T extends readonly AnyDef[], S>(editor: Editor<T>, select: (editor: Editor<T>) => S): Readonly<Ref<S>>;
42
+ /** True while the editor has DOM focus. */
43
+ declare function useEditorFocus<T extends readonly AnyDef[]>(editor: Editor<T>): Readonly<Ref<boolean>>;
44
+
45
+ export { EditorContent, useEditor, useEditorFocus, useEditorState };
@@ -0,0 +1,45 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, Ref } from 'vue';
3
+ import { Editor, AnyDef, EditorOptions } from '@matrajs/core';
4
+
5
+ /**
6
+ * The element the editor mounts into.
7
+ *
8
+ * The mount is guarded on `unsafe.view`, so a component remounted by a
9
+ * `<KeepAlive>` or a hot reload does not attach a second view to one element.
10
+ */
11
+ declare const EditorContent: vue.DefineComponent<vue.ExtractPropTypes<{
12
+ editor: {
13
+ type: PropType<Editor<readonly AnyDef[]>>;
14
+ required: true;
15
+ };
16
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
17
+ [key: string]: any;
18
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
19
+ editor: {
20
+ type: PropType<Editor<readonly AnyDef[]>>;
21
+ required: true;
22
+ };
23
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
24
+
25
+ /**
26
+ * Create an editor that lives as long as the component using it.
27
+ *
28
+ * The editor is deliberately **not** reactive: it is a mutable object with its
29
+ * own change events, and wrapping it in a proxy would make Vue trace every
30
+ * document node on every keystroke. `markRaw` keeps it out of the reactivity
31
+ * graph; use `useEditorState` to read from it reactively.
32
+ */
33
+ declare function useEditor<const T extends readonly AnyDef[]>(options: EditorOptions<T>): Editor<T>;
34
+ /**
35
+ * A reactive view of the editor.
36
+ *
37
+ * Toolbars need this: commands mutate the document, but Vue has no way to know
38
+ * unless something subscribes. The selector re-runs on every change and
39
+ * selection move.
40
+ */
41
+ declare function useEditorState<T extends readonly AnyDef[], S>(editor: Editor<T>, select: (editor: Editor<T>) => S): Readonly<Ref<S>>;
42
+ /** True while the editor has DOM focus. */
43
+ declare function useEditorFocus<T extends readonly AnyDef[]>(editor: Editor<T>): Readonly<Ref<boolean>>;
44
+
45
+ export { EditorContent, useEditor, useEditorFocus, useEditorState };
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ import { defineComponent, ref, onMounted, h, markRaw, getCurrentInstance, onBeforeUnmount, onScopeDispose, readonly } from 'vue';
2
+ import { createEditor } from '@matrajs/core';
3
+
4
+ // src/editor-content.ts
5
+ var EditorContent = defineComponent({
6
+ name: "EditorContent",
7
+ props: {
8
+ editor: {
9
+ type: Object,
10
+ required: true
11
+ }
12
+ },
13
+ setup(props) {
14
+ const root = ref(null);
15
+ onMounted(() => {
16
+ const element = root.value;
17
+ if (!element || props.editor.unsafe.view) return;
18
+ props.editor.mount(element);
19
+ });
20
+ return () => h("div", { ref: root, class: "matra-content" });
21
+ }
22
+ });
23
+ function useEditor(options) {
24
+ const editor = markRaw(createEditor(options));
25
+ const dispose = () => editor.destroy();
26
+ if (getCurrentInstance()) onBeforeUnmount(dispose);
27
+ else onScopeDispose(dispose);
28
+ return editor;
29
+ }
30
+ function useEditorState(editor, select) {
31
+ const value = ref(select(editor));
32
+ const update = () => {
33
+ value.value = select(editor);
34
+ };
35
+ const offChange = editor.on("change", update);
36
+ const offSelection = editor.on("selectionChange", update);
37
+ const dispose = () => {
38
+ offChange();
39
+ offSelection();
40
+ };
41
+ if (getCurrentInstance()) onBeforeUnmount(dispose);
42
+ else onScopeDispose(dispose);
43
+ return readonly(value);
44
+ }
45
+ function useEditorFocus(editor) {
46
+ const focused = ref(false);
47
+ const offFocus = editor.on("focus", () => {
48
+ focused.value = true;
49
+ });
50
+ const offBlur = editor.on("blur", () => {
51
+ focused.value = false;
52
+ });
53
+ const dispose = () => {
54
+ offFocus();
55
+ offBlur();
56
+ };
57
+ if (getCurrentInstance()) onBeforeUnmount(dispose);
58
+ else onScopeDispose(dispose);
59
+ return readonly(focused);
60
+ }
61
+
62
+ export { EditorContent, useEditor, useEditorFocus, useEditorState };
63
+ //# sourceMappingURL=index.js.map
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/editor-content.ts","../src/use-editor.ts"],"names":["ref"],"mappings":";;;;AASO,IAAM,gBAAgB,eAAA,CAAgB;AAAA,EAC3C,IAAA,EAAM,eAAA;AAAA,EACN,KAAA,EAAO;AAAA,IACL,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,MAAA;AAAA,MACN,QAAA,EAAU;AAAA;AACZ,GACF;AAAA,EACA,MAAM,KAAA,EAAO;AACX,IAAA,MAAM,IAAA,GAAO,IAAwB,IAAI,CAAA;AAEzC,IAAA,SAAA,CAAU,MAAM;AACd,MAAA,MAAM,UAAU,IAAA,CAAK,KAAA;AACrB,MAAA,IAAI,CAAC,OAAA,IAAW,KAAA,CAAM,MAAA,CAAO,OAAO,IAAA,EAAM;AAC1C,MAAA,KAAA,CAAM,MAAA,CAAO,MAAM,OAAO,CAAA;AAAA,IAC5B,CAAC,CAAA;AAED,IAAA,OAAO,MAAM,EAAE,KAAA,EAAO,EAAE,KAAK,IAAA,EAAM,KAAA,EAAO,iBAAiB,CAAA;AAAA,EAC7D;AACF,CAAC;ACRM,SAAS,UACd,OAAA,EACW;AACX,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,YAAA,CAAa,OAAO,CAAC,CAAA;AAE5C,EAAA,MAAM,OAAA,GAAU,MAAM,MAAA,CAAO,OAAA,EAAQ;AAErC,EAAA,IA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sBAC7B,OAAO,CAAA;AAE3B,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB","file":"index.js","sourcesContent":["import type { AnyDef, Editor } from '@matrajs/core'\nimport { type PropType, defineComponent, h, onMounted, ref } from 'vue'\n\n/**\n * The element the editor mounts into.\n *\n * The mount is guarded on `unsafe.view`, so a component remounted by a\n * `<KeepAlive>` or a hot reload does not attach a second view to one element.\n */\nexport const EditorContent = defineComponent({\n name: 'EditorContent',\n props: {\n editor: {\n type: Object as PropType<Editor<readonly AnyDef[]>>,\n required: true,\n },\n },\n setup(props) {\n const root = ref<HTMLElement | null>(null)\n\n onMounted(() => {\n const element = root.value\n if (!element || props.editor.unsafe.view) return\n props.editor.mount(element)\n })\n\n return () => h('div', { ref: root, class: 'matra-content' })\n },\n})\n","import { createEditor } from '@matrajs/core'\nimport type { AnyDef, Editor, EditorOptions } from '@matrajs/core'\nimport {\n type Ref,\n getCurrentInstance,\n markRaw,\n onBeforeUnmount,\n onScopeDispose,\n readonly,\n ref,\n} from 'vue'\n\n/**\n * Create an editor that lives as long as the component using it.\n *\n * The editor is deliberately **not** reactive: it is a mutable object with its\n * own change events, and wrapping it in a proxy would make Vue trace every\n * document node on every keystroke. `markRaw` keeps it out of the reactivity\n * graph; use `useEditorState` to read from it reactively.\n */\nexport function useEditor<const T extends readonly AnyDef[]>(\n options: EditorOptions<T>,\n): Editor<T> {\n const editor = markRaw(createEditor(options))\n\n const dispose = () => editor.destroy()\n // Works inside a component or a bare effect scope.\n if (getCurrentInstance()) onBeforeUnmount(dispose)\n else onScopeDispose(dispose)\n\n return editor\n}\n\n/**\n * A reactive view of the editor.\n *\n * Toolbars need this: commands mutate the document, but Vue has no way to know\n * unless something subscribes. The selector re-runs on every change and\n * selection move.\n */\nexport function useEditorState<T extends readonly AnyDef[], S>(\n editor: Editor<T>,\n select: (editor: Editor<T>) => S,\n): Readonly<Ref<S>> {\n const value = ref(select(editor)) as Ref<S>\n\n const update = () => {\n value.value = select(editor)\n }\n const offChange = editor.on('change', update)\n const offSelection = editor.on('selectionChange', update)\n\n const dispose = () => {\n offChange()\n offSelection()\n }\n if (getCurrentInstance()) onBeforeUnmount(dispose)\n else onScopeDispose(dispose)\n\n return readonly(value) as Readonly<Ref<S>>\n}\n\n/** True while the editor has DOM focus. */\nexport function useEditorFocus<T extends readonly AnyDef[]>(\n editor: Editor<T>,\n): Readonly<Ref<boolean>> {\n const focused = ref(false)\n const offFocus = editor.on('focus', () => {\n focused.value = true\n })\n const offBlur = editor.on('blur', () => {\n focused.value = false\n })\n\n const dispose = () => {\n offFocus()\n offBlur()\n }\n if (getCurrentInstance()) onBeforeUnmount(dispose)\n else onScopeDispose(dispose)\n\n return readonly(focused)\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@matrajs/vue",
3
+ "version": "0.2.0",
4
+ "description": "Vue 3 bindings for Matra — useEditor and EditorContent.",
5
+ "license": "MIT",
6
+ "author": "Nahim Hossain Shohan",
7
+ "homepage": "https://matrajs.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/amrelaco/matra.git",
11
+ "directory": "packages/vue"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/amrelaco/matra/issues"
15
+ },
16
+ "keywords": [
17
+ "editor",
18
+ "rich-text",
19
+ "vue",
20
+ "matra"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "require": "./dist/index.cjs"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "README.md"
40
+ ],
41
+ "dependencies": {
42
+ "@matrajs/core": "^0.2.0"
43
+ },
44
+ "peerDependencies": {
45
+ "vue": "^3.4.0"
46
+ },
47
+ "devDependencies": {
48
+ "vue": "^3.5.41"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup",
52
+ "clean": "rm -rf dist"
53
+ }
54
+ }