@love-rox/kumihimo-vue 0.1.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 +21 -0
- package/README.md +36 -0
- package/dist/Kumihimo.d.ts +70 -0
- package/dist/Kumihimo.d.ts.map +1 -0
- package/dist/Kumihimo.js +54 -0
- package/dist/Kumihimo.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/useKumihimo.d.ts +31 -0
- package/dist/useKumihimo.d.ts.map +1 -0
- package/dist/useKumihimo.js +51 -0
- package/dist/useKumihimo.js.map +1 -0
- package/package.json +60 -0
- package/src/Kumihimo.ts +63 -0
- package/src/index.ts +10 -0
- package/src/useKumihimo.ts +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SASAGAWA Kiyoshi
|
|
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,36 @@
|
|
|
1
|
+
# @love-rox/kumihimo-vue
|
|
2
|
+
|
|
3
|
+
Vue 3 component and composable for [kumihimo](https://github.com/Love-Rox/kumihimo) — AV signal flow diagrams
|
|
4
|
+
(系統図) written as text.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @love-rox/kumihimo-vue
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```vue
|
|
11
|
+
<script setup>
|
|
12
|
+
import { Kumihimo } from '@love-rox/kumihimo-vue';
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<Kumihimo :source="src" theme="dark" @diagnostics="report">
|
|
17
|
+
<template #fallback>読み込み中…</template>
|
|
18
|
+
</Kumihimo>
|
|
19
|
+
</template>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { useKumihimo } from '@love-rox/kumihimo-vue';
|
|
24
|
+
|
|
25
|
+
const { svg, diagram, diagnostics, pending, error } = useKumihimo(() => src.value);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Accepts values, refs or getters, and keeps the previous diagram on screen through a
|
|
29
|
+
recompile.
|
|
30
|
+
|
|
31
|
+
See the [project README](https://github.com/Love-Rox/kumihimo#readme) for the language and
|
|
32
|
+
the other packages.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT © SASAGAWA Kiyoshi
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue component rendering a kumihimo diagram.
|
|
3
|
+
*/
|
|
4
|
+
import type { PropType, VNode } from 'vue';
|
|
5
|
+
import type { CompileOptions, Diagnostic } from '@love-rox/kumihimo-core';
|
|
6
|
+
/**
|
|
7
|
+
* Draw a kumihimo diagram.
|
|
8
|
+
*
|
|
9
|
+
* The SVG is generated by this package from the caller's source, and every text value in
|
|
10
|
+
* it is escaped by the renderer, so it is inlined with `v-html` rather than parsed again.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```vue
|
|
14
|
+
* <Kumihimo :source="src" theme="dark" @diagnostics="onDiagnostics" />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const Kumihimo: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
18
|
+
/** The `.khm` source to draw. */
|
|
19
|
+
source: {
|
|
20
|
+
type: StringConstructor;
|
|
21
|
+
required: true;
|
|
22
|
+
};
|
|
23
|
+
/** Colour theme name. */
|
|
24
|
+
theme: {
|
|
25
|
+
type: StringConstructor;
|
|
26
|
+
default: undefined;
|
|
27
|
+
};
|
|
28
|
+
/** Any other compile option. */
|
|
29
|
+
options: {
|
|
30
|
+
type: PropType<CompileOptions>;
|
|
31
|
+
default: () => {};
|
|
32
|
+
};
|
|
33
|
+
/** Class applied to the wrapper element. */
|
|
34
|
+
className: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
default: undefined;
|
|
37
|
+
};
|
|
38
|
+
}>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
39
|
+
/** Fired whenever a compile produces diagnostics. */
|
|
40
|
+
diagnostics: (value: readonly Diagnostic[]) => value is any[];
|
|
41
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
42
|
+
/** The `.khm` source to draw. */
|
|
43
|
+
source: {
|
|
44
|
+
type: StringConstructor;
|
|
45
|
+
required: true;
|
|
46
|
+
};
|
|
47
|
+
/** Colour theme name. */
|
|
48
|
+
theme: {
|
|
49
|
+
type: StringConstructor;
|
|
50
|
+
default: undefined;
|
|
51
|
+
};
|
|
52
|
+
/** Any other compile option. */
|
|
53
|
+
options: {
|
|
54
|
+
type: PropType<CompileOptions>;
|
|
55
|
+
default: () => {};
|
|
56
|
+
};
|
|
57
|
+
/** Class applied to the wrapper element. */
|
|
58
|
+
className: {
|
|
59
|
+
type: StringConstructor;
|
|
60
|
+
default: undefined;
|
|
61
|
+
};
|
|
62
|
+
}>> & Readonly<{
|
|
63
|
+
onDiagnostics?: (value: readonly Diagnostic[]) => any;
|
|
64
|
+
}>, {
|
|
65
|
+
theme: string;
|
|
66
|
+
options: CompileOptions;
|
|
67
|
+
className: string;
|
|
68
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
69
|
+
export default Kumihimo;
|
|
70
|
+
//# sourceMappingURL=Kumihimo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kumihimo.d.ts","sourceRoot":"","sources":["../src/Kumihimo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ;IAGjB,iCAAiC;;;;;IAEjC,yBAAyB;;;;;IAEzB,gCAAgC;;cACL,QAAQ,CAAC,cAAc,CAAC;;;IACnD,4CAA4C;;;;;UAiBjC,KAAK;IAbhB,qDAAqD;yBAChC,SAAS,UAAU,EAAE;;IAX1C,iCAAiC;;;;;IAEjC,yBAAyB;;;;;IAEzB,gCAAgC;;cACL,QAAQ,CAAC,cAAc,CAAC;;;IACnD,4CAA4C;;;;;;;;;;;4EA6B9C,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
package/dist/Kumihimo.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue component rendering a kumihimo diagram.
|
|
3
|
+
*/
|
|
4
|
+
import { computed, defineComponent, h, watch } from 'vue';
|
|
5
|
+
import { useKumihimo } from './useKumihimo.js';
|
|
6
|
+
/**
|
|
7
|
+
* Draw a kumihimo diagram.
|
|
8
|
+
*
|
|
9
|
+
* The SVG is generated by this package from the caller's source, and every text value in
|
|
10
|
+
* it is escaped by the renderer, so it is inlined with `v-html` rather than parsed again.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```vue
|
|
14
|
+
* <Kumihimo :source="src" theme="dark" @diagnostics="onDiagnostics" />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const Kumihimo = defineComponent({
|
|
18
|
+
name: 'Kumihimo',
|
|
19
|
+
props: {
|
|
20
|
+
/** The `.khm` source to draw. */
|
|
21
|
+
source: { type: String, required: true },
|
|
22
|
+
/** Colour theme name. */
|
|
23
|
+
theme: { type: String, default: undefined },
|
|
24
|
+
/** Any other compile option. */
|
|
25
|
+
options: { type: Object, default: () => ({}) },
|
|
26
|
+
/** Class applied to the wrapper element. */
|
|
27
|
+
className: { type: String, default: undefined },
|
|
28
|
+
},
|
|
29
|
+
emits: {
|
|
30
|
+
/** Fired whenever a compile produces diagnostics. */
|
|
31
|
+
diagnostics: (value) => Array.isArray(value),
|
|
32
|
+
},
|
|
33
|
+
setup(props, { emit, slots }) {
|
|
34
|
+
const config = computed(() => props.theme === undefined ? props.options : { ...props.options, theme: props.theme });
|
|
35
|
+
const { svg, diagnostics, pending, error } = useKumihimo(() => props.source, config);
|
|
36
|
+
watch(diagnostics, (value) => {
|
|
37
|
+
if (value.length > 0)
|
|
38
|
+
emit('diagnostics', value);
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
if (error.value) {
|
|
42
|
+
return h('div', { class: props.className, role: 'alert' }, error.value.message);
|
|
43
|
+
}
|
|
44
|
+
// Only fall back before anything has ever been drawn. Keeping the previous diagram
|
|
45
|
+
// on screen through a recompile is what makes live editing bearable.
|
|
46
|
+
if (pending.value && !svg.value) {
|
|
47
|
+
return h('div', { class: props.className }, slots['fallback']?.());
|
|
48
|
+
}
|
|
49
|
+
return h('div', { class: props.className, innerHTML: svg.value });
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
export default Kumihimo;
|
|
54
|
+
//# sourceMappingURL=Kumihimo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kumihimo.js","sourceRoot":"","sources":["../src/Kumihimo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAI1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;IACtC,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE;QACL,iCAAiC;QACjC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;QACxC,yBAAyB;QACzB,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;QAC3C,gCAAgC;QAChC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAkC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE;QAC1E,4CAA4C;QAC5C,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;KAChD;IACD,KAAK,EAAE;QACL,qDAAqD;QACrD,WAAW,EAAE,CAAC,KAA4B,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;KACpE;IACD,KAAK,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;QAC1B,MAAM,MAAM,GAAG,QAAQ,CAAiB,GAAG,EAAE,C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
|
+
* Public API of `@love-rox/kumihimo-vue`.
|
|
3
|
+
*
|
|
4
|
+
* A component for the common case and a composable for everything else.
|
|
5
|
+
*/
|
|
6
|
+
export type { UseKumihimoResult } from './useKumihimo.js';
|
|
7
|
+
export { useKumihimo } from './useKumihimo.js';
|
|
8
|
+
export { Kumihimo, default } from './Kumihimo.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API of `@love-rox/kumihimo-vue`.
|
|
3
|
+
*
|
|
4
|
+
* A component for the common case and a composable for everything else.
|
|
5
|
+
*/
|
|
6
|
+
export { useKumihimo } from './useKumihimo.js';
|
|
7
|
+
export { Kumihimo, default } from './Kumihimo.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue composable compiling kumihimo source into SVG.
|
|
3
|
+
*
|
|
4
|
+
* Compiling is asynchronous — the layout engine is — so the last good SVG is kept on
|
|
5
|
+
* screen while a new one is produced. Typing in an editor should not make the diagram
|
|
6
|
+
* flash away and back.
|
|
7
|
+
*/
|
|
8
|
+
import type { MaybeRefOrGetter, Ref } from 'vue';
|
|
9
|
+
import type { CompileOptions, Diagnostic, Diagram } from '@love-rox/kumihimo-core';
|
|
10
|
+
/** What {@link useKumihimo} returns. */
|
|
11
|
+
export interface UseKumihimoResult {
|
|
12
|
+
/** The rendered SVG, empty until the first compile finishes. */
|
|
13
|
+
svg: Ref<string>;
|
|
14
|
+
/** The resolved diagram, for callers that want the model as well as the picture. */
|
|
15
|
+
diagram: Ref<Diagram | undefined>;
|
|
16
|
+
/** Everything the compile had to say about the wiring. */
|
|
17
|
+
diagnostics: Ref<readonly Diagnostic[]>;
|
|
18
|
+
/** Whether a compile is in flight. The previous `svg` stays available meanwhile. */
|
|
19
|
+
pending: Ref<boolean>;
|
|
20
|
+
/** Set when compiling threw, which should not happen for source-level problems. */
|
|
21
|
+
error: Ref<Error | undefined>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compile kumihimo source, re-running whenever it or the options change.
|
|
25
|
+
*
|
|
26
|
+
* @param source - The `.khm` text, as a value, ref or getter.
|
|
27
|
+
* @param options - Compile options, as a value, ref or getter.
|
|
28
|
+
* @returns Reactive SVG, model, diagnostics and progress state.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useKumihimo(source: MaybeRefOrGetter<string>, options?: MaybeRefOrGetter<CompileOptions>): UseKumihimoResult;
|
|
31
|
+
//# sourceMappingURL=useKumihimo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKumihimo.d.ts","sourceRoot":"","sources":["../src/useKumihimo.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAGjD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGnF,wCAAwC;AACxC,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACjB,oFAAoF;IACpF,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IAClC,0DAA0D;IAC1D,WAAW,EAAE,GAAG,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC;IACxC,oFAAoF;IACpF,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,mFAAmF;IACnF,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAChC,OAAO,GAAE,gBAAgB,CAAC,cAAc,CAAM,GAC7C,iBAAiB,CAkCnB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue composable compiling kumihimo source into SVG.
|
|
3
|
+
*
|
|
4
|
+
* Compiling is asynchronous — the layout engine is — so the last good SVG is kept on
|
|
5
|
+
* screen while a new one is produced. Typing in an editor should not make the diagram
|
|
6
|
+
* flash away and back.
|
|
7
|
+
*/
|
|
8
|
+
import { ref, toValue, watchEffect } from 'vue';
|
|
9
|
+
import { compile } from '@love-rox/kumihimo-core';
|
|
10
|
+
/**
|
|
11
|
+
* Compile kumihimo source, re-running whenever it or the options change.
|
|
12
|
+
*
|
|
13
|
+
* @param source - The `.khm` text, as a value, ref or getter.
|
|
14
|
+
* @param options - Compile options, as a value, ref or getter.
|
|
15
|
+
* @returns Reactive SVG, model, diagnostics and progress state.
|
|
16
|
+
*/
|
|
17
|
+
export function useKumihimo(source, options = {}) {
|
|
18
|
+
const svg = ref('');
|
|
19
|
+
const diagram = ref(undefined);
|
|
20
|
+
const diagnostics = ref([]);
|
|
21
|
+
const pending = ref(true);
|
|
22
|
+
const error = ref(undefined);
|
|
23
|
+
let latest = 0;
|
|
24
|
+
watchEffect(() => {
|
|
25
|
+
const text = toValue(source);
|
|
26
|
+
const config = toValue(options);
|
|
27
|
+
const run = ++latest;
|
|
28
|
+
pending.value = true;
|
|
29
|
+
compile(text, config)
|
|
30
|
+
.then((result) => {
|
|
31
|
+
// A slower earlier compile must never overwrite a newer one.
|
|
32
|
+
if (run !== latest)
|
|
33
|
+
return;
|
|
34
|
+
svg.value = result.svg;
|
|
35
|
+
diagram.value = result.diagram;
|
|
36
|
+
diagnostics.value = result.diagnostics;
|
|
37
|
+
error.value = undefined;
|
|
38
|
+
})
|
|
39
|
+
.catch((cause) => {
|
|
40
|
+
if (run !== latest)
|
|
41
|
+
return;
|
|
42
|
+
error.value = cause instanceof Error ? cause : new Error(String(cause));
|
|
43
|
+
})
|
|
44
|
+
.finally(() => {
|
|
45
|
+
if (run === latest)
|
|
46
|
+
pending.value = false;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return { svg, diagram, diagnostics, pending, error };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=useKumihimo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKumihimo.js","sourceRoot":"","sources":["../src/useKumihimo.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAGhD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAgBlD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,MAAgC,EAChC,UAA4C,EAAE;IAE9C,MAAM,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC;IACpB,MAAM,OAAO,GAAG,GAAG,CAAsB,SAAS,CAA6B,CAAC;IAChF,MAAM,WAAW,GAAG,GAAG,CAAwB,EAAE,CAA+B,CAAC;IACjF,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,MAAM,KAAK,GAAG,GAAG,CAAoB,SAAS,CAAC,CAAC;IAEhD,IA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|
|
4
|
+
"description": "Vue 3 component and composable rendering kumihimo AV signal flow diagrams (系統図)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"av",
|
|
7
|
+
"diagram",
|
|
8
|
+
"signal-flow",
|
|
9
|
+
"svg",
|
|
10
|
+
"vue",
|
|
11
|
+
"wiring",
|
|
12
|
+
"系統図"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/Love-Rox/kumihimo#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/Love-Rox/kumihimo/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "SASAGAWA Kiyoshi <dev@love-rox.cc>",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Love-Rox/kumihimo.git",
|
|
23
|
+
"directory": "packages/vue"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"provenance": true
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@love-rox/kumihimo-core": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@vue/test-utils": "^2.4.6",
|
|
49
|
+
"happy-dom": "^20.0.0",
|
|
50
|
+
"vue": "^3.5.40"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"vue": ">=3.3"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsc -p tsconfig.build.json",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"typecheck": "tsc --noEmit"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/Kumihimo.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue component rendering a kumihimo diagram.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { PropType, VNode } from 'vue';
|
|
6
|
+
import { computed, defineComponent, h, watch } from 'vue';
|
|
7
|
+
|
|
8
|
+
import type { CompileOptions, Diagnostic } from '@love-rox/kumihimo-core';
|
|
9
|
+
|
|
10
|
+
import { useKumihimo } from './useKumihimo.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Draw a kumihimo diagram.
|
|
14
|
+
*
|
|
15
|
+
* The SVG is generated by this package from the caller's source, and every text value in
|
|
16
|
+
* it is escaped by the renderer, so it is inlined with `v-html` rather than parsed again.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```vue
|
|
20
|
+
* <Kumihimo :source="src" theme="dark" @diagnostics="onDiagnostics" />
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const Kumihimo = defineComponent({
|
|
24
|
+
name: 'Kumihimo',
|
|
25
|
+
props: {
|
|
26
|
+
/** The `.khm` source to draw. */
|
|
27
|
+
source: { type: String, required: true },
|
|
28
|
+
/** Colour theme name. */
|
|
29
|
+
theme: { type: String, default: undefined },
|
|
30
|
+
/** Any other compile option. */
|
|
31
|
+
options: { type: Object as PropType<CompileOptions>, default: () => ({}) },
|
|
32
|
+
/** Class applied to the wrapper element. */
|
|
33
|
+
className: { type: String, default: undefined },
|
|
34
|
+
},
|
|
35
|
+
emits: {
|
|
36
|
+
/** Fired whenever a compile produces diagnostics. */
|
|
37
|
+
diagnostics: (value: readonly Diagnostic[]) => Array.isArray(value),
|
|
38
|
+
},
|
|
39
|
+
setup(props, { emit, slots }) {
|
|
40
|
+
const config = computed<CompileOptions>(() =>
|
|
41
|
+
props.theme === undefined ? props.options : { ...props.options, theme: props.theme },
|
|
42
|
+
);
|
|
43
|
+
const { svg, diagnostics, pending, error } = useKumihimo(() => props.source, config);
|
|
44
|
+
|
|
45
|
+
watch(diagnostics, (value) => {
|
|
46
|
+
if (value.length > 0) emit('diagnostics', value);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (): VNode => {
|
|
50
|
+
if (error.value) {
|
|
51
|
+
return h('div', { class: props.className, role: 'alert' }, error.value.message);
|
|
52
|
+
}
|
|
53
|
+
// Only fall back before anything has ever been drawn. Keeping the previous diagram
|
|
54
|
+
// on screen through a recompile is what makes live editing bearable.
|
|
55
|
+
if (pending.value && !svg.value) {
|
|
56
|
+
return h('div', { class: props.className }, slots['fallback']?.());
|
|
57
|
+
}
|
|
58
|
+
return h('div', { class: props.className, innerHTML: svg.value });
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default Kumihimo;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API of `@love-rox/kumihimo-vue`.
|
|
3
|
+
*
|
|
4
|
+
* A component for the common case and a composable for everything else.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type { UseKumihimoResult } from './useKumihimo.js';
|
|
8
|
+
export { useKumihimo } from './useKumihimo.js';
|
|
9
|
+
|
|
10
|
+
export { Kumihimo, default } from './Kumihimo.js';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue composable compiling kumihimo source into SVG.
|
|
3
|
+
*
|
|
4
|
+
* Compiling is asynchronous — the layout engine is — so the last good SVG is kept on
|
|
5
|
+
* screen while a new one is produced. Typing in an editor should not make the diagram
|
|
6
|
+
* flash away and back.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { MaybeRefOrGetter, Ref } from 'vue';
|
|
10
|
+
import { ref, toValue, watchEffect } from 'vue';
|
|
11
|
+
|
|
12
|
+
import type { CompileOptions, Diagnostic, Diagram } from '@love-rox/kumihimo-core';
|
|
13
|
+
import { compile } from '@love-rox/kumihimo-core';
|
|
14
|
+
|
|
15
|
+
/** What {@link useKumihimo} returns. */
|
|
16
|
+
export interface UseKumihimoResult {
|
|
17
|
+
/** The rendered SVG, empty until the first compile finishes. */
|
|
18
|
+
svg: Ref<string>;
|
|
19
|
+
/** The resolved diagram, for callers that want the model as well as the picture. */
|
|
20
|
+
diagram: Ref<Diagram | undefined>;
|
|
21
|
+
/** Everything the compile had to say about the wiring. */
|
|
22
|
+
diagnostics: Ref<readonly Diagnostic[]>;
|
|
23
|
+
/** Whether a compile is in flight. The previous `svg` stays available meanwhile. */
|
|
24
|
+
pending: Ref<boolean>;
|
|
25
|
+
/** Set when compiling threw, which should not happen for source-level problems. */
|
|
26
|
+
error: Ref<Error | undefined>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Compile kumihimo source, re-running whenever it or the options change.
|
|
31
|
+
*
|
|
32
|
+
* @param source - The `.khm` text, as a value, ref or getter.
|
|
33
|
+
* @param options - Compile options, as a value, ref or getter.
|
|
34
|
+
* @returns Reactive SVG, model, diagnostics and progress state.
|
|
35
|
+
*/
|
|
36
|
+
export function useKumihimo(
|
|
37
|
+
source: MaybeRefOrGetter<string>,
|
|
38
|
+
options: MaybeRefOrGetter<CompileOptions> = {},
|
|
39
|
+
): UseKumihimoResult {
|
|
40
|
+
const svg = ref('');
|
|
41
|
+
const diagram = ref<Diagram | undefined>(undefined) as Ref<Diagram | undefined>;
|
|
42
|
+
const diagnostics = ref<readonly Diagnostic[]>([]) as Ref<readonly Diagnostic[]>;
|
|
43
|
+
const pending = ref(true);
|
|
44
|
+
const error = ref<Error | undefined>(undefined);
|
|
45
|
+
|
|
46
|
+
let latest = 0;
|
|
47
|
+
|
|
48
|
+
watchEffect(() => {
|
|
49
|
+
const text = toValue(source);
|
|
50
|
+
const config = toValue(options);
|
|
51
|
+
const run = ++latest;
|
|
52
|
+
pending.value = true;
|
|
53
|
+
|
|
54
|
+
compile(text, config)
|
|
55
|
+
.then((result) => {
|
|
56
|
+
// A slower earlier compile must never overwrite a newer one.
|
|
57
|
+
if (run !== latest) return;
|
|
58
|
+
svg.value = result.svg;
|
|
59
|
+
diagram.value = result.diagram;
|
|
60
|
+
diagnostics.value = result.diagnostics;
|
|
61
|
+
error.value = undefined;
|
|
62
|
+
})
|
|
63
|
+
.catch((cause: unknown) => {
|
|
64
|
+
if (run !== latest) return;
|
|
65
|
+
error.value = cause instanceof Error ? cause : new Error(String(cause));
|
|
66
|
+
})
|
|
67
|
+
.finally(() => {
|
|
68
|
+
if (run === latest) pending.value = false;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return { svg, diagram, diagnostics, pending, error };
|
|
73
|
+
}
|