2019-04-29 02:11:57 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div
|
|
|
|
v-if="hpml"
|
|
|
|
class="iroscrza"
|
|
|
|
:class="{ center: page.alignCenter, serif: page.font === 'serif' }"
|
|
|
|
>
|
|
|
|
<XBlock
|
|
|
|
v-for="child in page.content"
|
|
|
|
:key="child.id"
|
|
|
|
:block="child"
|
|
|
|
:hpml="hpml"
|
|
|
|
:h="2"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-04-29 02:11:57 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-09-02 01:27:33 +02:00
|
|
|
import type { PropType } from "vue";
|
|
|
|
import { defineComponent, nextTick, onMounted, onUnmounted } from "vue";
|
2023-04-08 02:01:42 +02:00
|
|
|
import { parse } from "@syuilo/aiscript";
|
|
|
|
import XBlock from "./page.block.vue";
|
|
|
|
import { Hpml } from "@/scripts/hpml/evaluator";
|
|
|
|
import { url } from "@/config";
|
2023-10-22 23:29:46 +02:00
|
|
|
import { $i } from "@/reactiveAccount";
|
2023-04-08 02:01:42 +02:00
|
|
|
import { defaultStore } from "@/store";
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2019-04-29 02:11:57 +02:00
|
|
|
components: {
|
2023-04-08 02:01:42 +02:00
|
|
|
XBlock,
|
2019-04-29 02:11:57 +02:00
|
|
|
},
|
|
|
|
props: {
|
2019-07-06 23:56:13 +02:00
|
|
|
page: {
|
2021-01-30 02:59:05 +01:00
|
|
|
type: Object as PropType<Record<string, any>>,
|
2023-04-08 02:01:42 +02:00
|
|
|
required: true,
|
2019-04-29 02:11:57 +02:00
|
|
|
},
|
|
|
|
},
|
2021-01-30 02:59:05 +01:00
|
|
|
setup(props, ctx) {
|
|
|
|
const hpml = new Hpml(props.page, {
|
2019-07-06 23:56:13 +02:00
|
|
|
randomSeed: Math.random(),
|
2021-01-30 02:59:05 +01:00
|
|
|
visitor: $i,
|
2023-09-02 01:27:33 +02:00
|
|
|
url,
|
2023-04-08 02:01:42 +02:00
|
|
|
enableAiScript: !defaultStore.state.disablePagesScript,
|
2019-07-06 23:56:13 +02:00
|
|
|
});
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2021-01-30 02:59:05 +01:00
|
|
|
onMounted(() => {
|
|
|
|
nextTick(() => {
|
|
|
|
if (props.page.script && hpml.aiscript) {
|
|
|
|
let ast;
|
|
|
|
try {
|
|
|
|
ast = parse(props.page.script);
|
2022-05-26 15:53:09 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
2023-09-02 01:27:33 +02:00
|
|
|
/* os.alert({
|
2021-01-30 02:59:05 +01:00
|
|
|
type: 'error',
|
|
|
|
text: 'Syntax error :('
|
2023-09-02 01:27:33 +02:00
|
|
|
}); */
|
2021-01-30 02:59:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-04-08 02:01:42 +02:00
|
|
|
hpml.aiscript
|
|
|
|
.exec(ast)
|
|
|
|
.then(() => {
|
|
|
|
hpml.eval();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
2023-09-02 01:27:33 +02:00
|
|
|
/* os.alert({
|
2021-01-30 02:59:05 +01:00
|
|
|
type: 'error',
|
2022-05-26 15:53:09 +02:00
|
|
|
text: err
|
2023-09-02 01:27:33 +02:00
|
|
|
}); */
|
2023-04-08 02:01:42 +02:00
|
|
|
});
|
2021-01-30 02:59:05 +01:00
|
|
|
} else {
|
|
|
|
hpml.eval();
|
2020-04-15 17:39:21 +02:00
|
|
|
}
|
2021-01-30 02:59:05 +01:00
|
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
|
|
if (hpml.aiscript) hpml.aiscript.abort();
|
|
|
|
});
|
2020-04-15 17:39:21 +02:00
|
|
|
});
|
|
|
|
|
2021-01-30 02:59:05 +01:00
|
|
|
return {
|
|
|
|
hpml,
|
|
|
|
};
|
2020-04-13 16:46:53 +02:00
|
|
|
},
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.iroscrza {
|
|
|
|
&.serif {
|
|
|
|
> div {
|
|
|
|
font-family: serif;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
&.center {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
</style>
|