jojotaoo_preview 0.0.1-beta.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.
@@ -0,0 +1,5 @@
1
+ import { type Ref } from 'vue';
2
+ export declare function usePreviewScale(designWidth: Ref<number>, designHeight: Ref<number>, containerRef: Ref<HTMLElement | undefined>): {
3
+ scale: Ref<number, number>;
4
+ };
5
+ //# sourceMappingURL=usePreviewScale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePreviewScale.d.ts","sourceRoot":"","sources":["../../src/composables/usePreviewScale.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAE3D,wBAAgB,eAAe,CAC7B,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,EACxB,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,YAAY,EAAE,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC;;EAuB3C"}
@@ -0,0 +1,18 @@
1
+ import { ref, onMounted, onUnmounted } from 'vue';
2
+ export function usePreviewScale(designWidth, designHeight, containerRef) {
3
+ const scale = ref(1);
4
+ function updateScale() {
5
+ if (!containerRef.value)
6
+ return;
7
+ const { clientWidth, clientHeight } = containerRef.value;
8
+ scale.value = Math.min(clientWidth / designWidth.value, clientHeight / designHeight.value);
9
+ }
10
+ onMounted(() => {
11
+ updateScale();
12
+ window.addEventListener('resize', updateScale);
13
+ });
14
+ onUnmounted(() => {
15
+ window.removeEventListener('resize', updateScale);
16
+ });
17
+ return { scale };
18
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@demo/components");function n(t,n,r){let i=(0,e.ref)(1);function a(){if(!r.value)return;let{clientWidth:e,clientHeight:a}=r.value;i.value=Math.min(e/t.value,a/n.value)}return(0,e.onMounted)(()=>{a(),window.addEventListener(`resize`,a)}),(0,e.onUnmounted)(()=>{window.removeEventListener(`resize`,a)}),{scale:i}}var r={class:`preview-overlay`},i={key:0,class:`preview-empty`},a=`preview_schema`,o=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,e.defineComponent)({__name:`PreviewPage`,setup(o){let s=(0,t.useDashboardStore)(),c=(0,e.ref)(null);function l(){localStorage.removeItem(a)}function u(){}function d(e){e.key===`Escape`&&document.fullscreenElement&&(e.preventDefault(),document.exitFullscreen()),e.key===`F11`&&(e.preventDefault(),document.fullscreenElement||document.documentElement.requestFullscreen().catch(()=>{}))}(0,e.onMounted)(()=>{let e=localStorage.getItem(a);if(!e){window.close();return}c.value=JSON.parse(e),localStorage.removeItem(a),c.value&&(s.editCanvasConfig={...s.editCanvasConfig,...c.value.editCanvasConfig},s.requestGlobalConfig={...s.requestGlobalConfig,...c.value.requestGlobalConfig},s.components=c.value.componentList??[]),s.setPreviewMode(!0),document.documentElement.requestFullscreen().catch(()=>{}),document.addEventListener(`fullscreenchange`,u),window.addEventListener(`keydown`,d),window.addEventListener(`beforeunload`,l)}),(0,e.onUnmounted)(()=>{s.setPreviewMode(!1),document.removeEventListener(`fullscreenchange`,u),window.removeEventListener(`keydown`,d),window.removeEventListener(`beforeunload`,l)});let f=(0,e.ref)(),p=(0,e.computed)(()=>({backgroundColor:c.value?.editCanvasConfig?.background||`#11111b`})),{scale:m}=n((0,e.computed)(()=>c.value?.editCanvasConfig.width??1920),(0,e.computed)(()=>c.value?.editCanvasConfig.height??1080),f),h=(0,e.computed)(()=>{if(!c.value)return{};let e=c.value.editCanvasConfig;return{width:e.width+`px`,height:e.height+`px`,backgroundColor:e.background,backgroundImage:e.backgroundImage?`url(${e.backgroundImage})`:void 0,backgroundSize:e.backgroundImage?`cover`:void 0,backgroundPosition:`center`,backgroundRepeat:`no-repeat`,filter:e.filterShow?`opacity(${e.opacity}) saturate(${e.saturate}) contrast(${e.contrast}) hue-rotate(${e.hueRotate}deg) brightness(${e.brightness})`:void 0,transform:`scale(${m.value})`,transformOrigin:`center center`,flexShrink:0,mixBlendMode:e.blendMode===`normal`?void 0:e.blendMode}});function g(e){return{left:e.attr.x+`px`,top:e.attr.y+`px`,width:e.attr.w+`px`,height:e.attr.h+`px`,opacity:e.styles.opacity,filter:e.styles.filterShow?`saturate(${e.styles.saturate}) contrast(${e.styles.contrast}) hue-rotate(${e.styles.hueRotate}deg) brightness(${e.styles.brightness})`:void 0,transform:`rotateZ(${e.styles.rotateZ}deg) rotateX(${e.styles.rotateX}deg) rotateY(${e.styles.rotateY}deg) skewX(${e.styles.skewX}deg) skewY(${e.styles.skewY}deg)`,mixBlendMode:e.styles.blendMode===`normal`?void 0:e.styles.blendMode,overflow:e.preview.overFlowHidden?`hidden`:void 0}}let _=(0,e.computed)(()=>c.value?.componentList??[]);return(n,a)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,r,[(0,e.createElementVNode)(`div`,{class:`preview-wrap`,ref_key:`wrapRef`,ref:f,style:(0,e.normalizeStyle)(p.value)},[(0,e.createElementVNode)(`div`,{class:`preview-stage`,style:(0,e.normalizeStyle)(h.value)},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(_.value,n=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:n.id,class:(0,e.normalizeClass)([`preview-component`,{hidden:n.status.hide}]),style:(0,e.normalizeStyle)(g(n))},[n.key===`group`?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(t.GroupPreview),{key:0,component:n},null,8,[`component`])):((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)((0,e.unref)(t.componentMap)[n.key]),(0,e.mergeProps)({key:1,ref_for:!0},(0,e.unref)(t.getComponentProps)(n)),null,16)),(0,e.createVNode)((0,e.unref)(t.DataFetchManager),{"component-id":n.id,mode:`preview`},null,8,[`component-id`])],6))),128)),_.value.length===0?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,i,` 暂无组件 `)):(0,e.createCommentVNode)(``,!0)],4)],4)]))}}),[[`__scopeId`,`data-v-3afe6fa0`]]);exports.PreviewPage=o,exports.usePreviewScale=n;
package/dist/index.css ADDED
@@ -0,0 +1,2 @@
1
+ .preview-overlay[data-v-3afe6fa0]{z-index:1000;background:#11111b;display:flex;position:fixed;inset:0}.preview-stage[data-v-3afe6fa0]{position:relative}.preview-wrap[data-v-3afe6fa0]{flex:1;justify-content:center;align-items:center;display:flex;overflow:hidden}.preview-component[data-v-3afe6fa0]{border-radius:6px;position:absolute;overflow:hidden}.preview-component.hidden[data-v-3afe6fa0]{display:none}.preview-empty[data-v-3afe6fa0]{color:#6c7086;-webkit-user-select:none;user-select:none;font-size:16px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}
2
+ /*$vite$:1*/
@@ -0,0 +1,3 @@
1
+ export { default as PreviewPage } from './pages/PreviewPage.vue';
2
+ export { usePreviewScale } from './composables/usePreviewScale';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // jojotaoo_preview - 预览容器入口
2
+ export { default as PreviewPage } from './pages/PreviewPage.vue';
3
+ export { usePreviewScale } from './composables/usePreviewScale';
@@ -0,0 +1,4 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
4
+ //# sourceMappingURL=PreviewPage.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreviewPage.vue.d.ts","sourceRoot":"","sources":["../../src/pages/PreviewPage.vue"],"names":[],"mappings":"AAiaA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -0,0 +1,173 @@
1
+ import { ref, computed, onMounted, onUnmounted } from 'vue';
2
+ import { useDashboardStore, GroupPreview, DataFetchManager, componentMap, getComponentProps } from 'jojotaoo_components';
3
+ import { usePreviewScale } from '../composables/usePreviewScale';
4
+ const STORAGE_KEY = 'preview_schema';
5
+ const store = useDashboardStore();
6
+ const schema = ref(null);
7
+ function handleBeforeUnload() {
8
+ localStorage.removeItem(STORAGE_KEY);
9
+ }
10
+ function handleFullscreenChange() {
11
+ }
12
+ function handleKeydown(e) {
13
+ if (e.key === 'Escape' && document.fullscreenElement) {
14
+ e.preventDefault();
15
+ document.exitFullscreen();
16
+ }
17
+ if (e.key === 'F11') {
18
+ e.preventDefault();
19
+ if (!document.fullscreenElement) {
20
+ document.documentElement.requestFullscreen().catch(() => { });
21
+ }
22
+ }
23
+ }
24
+ onMounted(() => {
25
+ const raw = localStorage.getItem(STORAGE_KEY);
26
+ if (!raw) {
27
+ window.close();
28
+ return;
29
+ }
30
+ schema.value = JSON.parse(raw);
31
+ localStorage.removeItem(STORAGE_KEY);
32
+ if (schema.value) {
33
+ store.editCanvasConfig = { ...store.editCanvasConfig, ...schema.value.editCanvasConfig };
34
+ store.requestGlobalConfig = { ...store.requestGlobalConfig, ...schema.value.requestGlobalConfig };
35
+ store.components = (schema.value.componentList ?? []);
36
+ }
37
+ store.setPreviewMode(true);
38
+ document.documentElement.requestFullscreen().catch(() => { });
39
+ document.addEventListener('fullscreenchange', handleFullscreenChange);
40
+ window.addEventListener('keydown', handleKeydown);
41
+ window.addEventListener('beforeunload', handleBeforeUnload);
42
+ });
43
+ onUnmounted(() => {
44
+ store.setPreviewMode(false);
45
+ document.removeEventListener('fullscreenchange', handleFullscreenChange);
46
+ window.removeEventListener('keydown', handleKeydown);
47
+ window.removeEventListener('beforeunload', handleBeforeUnload);
48
+ });
49
+ const wrapRef = ref();
50
+ const wrapStyle = computed(() => ({
51
+ backgroundColor: schema.value?.editCanvasConfig?.background || '#11111b',
52
+ }));
53
+ const { scale } = usePreviewScale(computed(() => schema.value?.editCanvasConfig.width ?? 1920), computed(() => schema.value?.editCanvasConfig.height ?? 1080), wrapRef);
54
+ const stageStyle = computed(() => {
55
+ if (!schema.value)
56
+ return {};
57
+ const c = schema.value.editCanvasConfig;
58
+ return {
59
+ width: c.width + 'px',
60
+ height: c.height + 'px',
61
+ backgroundColor: c.background,
62
+ backgroundImage: c.backgroundImage ? `url(${c.backgroundImage})` : undefined,
63
+ backgroundSize: c.backgroundImage ? 'cover' : undefined,
64
+ backgroundPosition: 'center',
65
+ backgroundRepeat: 'no-repeat',
66
+ filter: c.filterShow
67
+ ? `opacity(${c.opacity}) saturate(${c.saturate}) contrast(${c.contrast}) hue-rotate(${c.hueRotate}deg) brightness(${c.brightness})`
68
+ : undefined,
69
+ transform: `scale(${scale.value})`,
70
+ transformOrigin: 'center center',
71
+ flexShrink: 0,
72
+ mixBlendMode: c.blendMode !== 'normal'
73
+ ? c.blendMode
74
+ : undefined,
75
+ };
76
+ });
77
+ function componentStyle(comp) {
78
+ return {
79
+ left: comp.attr.x + 'px',
80
+ top: comp.attr.y + 'px',
81
+ width: comp.attr.w + 'px',
82
+ height: comp.attr.h + 'px',
83
+ opacity: comp.styles.opacity,
84
+ filter: comp.styles.filterShow
85
+ ? `saturate(${comp.styles.saturate}) contrast(${comp.styles.contrast}) hue-rotate(${comp.styles.hueRotate}deg) brightness(${comp.styles.brightness})`
86
+ : undefined,
87
+ transform: `rotateZ(${comp.styles.rotateZ}deg) rotateX(${comp.styles.rotateX}deg) rotateY(${comp.styles.rotateY}deg) skewX(${comp.styles.skewX}deg) skewY(${comp.styles.skewY}deg)`,
88
+ mixBlendMode: comp.styles.blendMode !== 'normal'
89
+ ? comp.styles.blendMode
90
+ : undefined,
91
+ overflow: comp.preview.overFlowHidden ? 'hidden' : undefined,
92
+ };
93
+ }
94
+ const rootComponents = computed(() => schema.value?.componentList ?? []);
95
+ const __VLS_ctx = {
96
+ ...{},
97
+ ...{},
98
+ };
99
+ let __VLS_components;
100
+ let __VLS_intrinsics;
101
+ let __VLS_directives;
102
+ /** @type {__VLS_StyleScopedClasses['preview-component']} */ ;
103
+ __VLS_asFunctionalElement1(__VLS_intrinsics.div, __VLS_intrinsics.div)({
104
+ ...{ class: "preview-overlay" },
105
+ });
106
+ /** @type {__VLS_StyleScopedClasses['preview-overlay']} */ ;
107
+ __VLS_asFunctionalElement1(__VLS_intrinsics.div, __VLS_intrinsics.div)({
108
+ ...{ class: "preview-wrap" },
109
+ ref: "wrapRef",
110
+ ...{ style: (__VLS_ctx.wrapStyle) },
111
+ });
112
+ /** @type {__VLS_StyleScopedClasses['preview-wrap']} */ ;
113
+ __VLS_asFunctionalElement1(__VLS_intrinsics.div, __VLS_intrinsics.div)({
114
+ ...{ class: "preview-stage" },
115
+ ...{ style: (__VLS_ctx.stageStyle) },
116
+ });
117
+ /** @type {__VLS_StyleScopedClasses['preview-stage']} */ ;
118
+ for (const [comp] of __VLS_vFor((__VLS_ctx.rootComponents))) {
119
+ __VLS_asFunctionalElement1(__VLS_intrinsics.div, __VLS_intrinsics.div)({
120
+ key: (comp.id),
121
+ ...{ class: "preview-component" },
122
+ ...{ class: ({ hidden: comp.status.hide }) },
123
+ ...{ style: (__VLS_ctx.componentStyle(comp)) },
124
+ });
125
+ /** @type {__VLS_StyleScopedClasses['preview-component']} */ ;
126
+ /** @type {__VLS_StyleScopedClasses['hidden']} */ ;
127
+ if (comp.key === 'group') {
128
+ let __VLS_0;
129
+ /** @ts-ignore @type { | typeof __VLS_components.GroupPreview} */
130
+ GroupPreview;
131
+ // @ts-ignore
132
+ const __VLS_1 = __VLS_asFunctionalComponent1(__VLS_0, new __VLS_0({
133
+ component: (comp),
134
+ }));
135
+ const __VLS_2 = __VLS_1({
136
+ component: (comp),
137
+ }, ...__VLS_functionalComponentArgsRest(__VLS_1));
138
+ }
139
+ else {
140
+ const __VLS_5 = (__VLS_ctx.componentMap[comp.key]);
141
+ // @ts-ignore
142
+ const __VLS_6 = __VLS_asFunctionalComponent1(__VLS_5, new __VLS_5({
143
+ ...(__VLS_ctx.getComponentProps(comp)),
144
+ }));
145
+ const __VLS_7 = __VLS_6({
146
+ ...(__VLS_ctx.getComponentProps(comp)),
147
+ }, ...__VLS_functionalComponentArgsRest(__VLS_6));
148
+ }
149
+ let __VLS_10;
150
+ /** @ts-ignore @type { | typeof __VLS_components.DataFetchManager} */
151
+ DataFetchManager;
152
+ // @ts-ignore
153
+ const __VLS_11 = __VLS_asFunctionalComponent1(__VLS_10, new __VLS_10({
154
+ componentId: (comp.id),
155
+ mode: "preview",
156
+ }));
157
+ const __VLS_12 = __VLS_11({
158
+ componentId: (comp.id),
159
+ mode: "preview",
160
+ }, ...__VLS_functionalComponentArgsRest(__VLS_11));
161
+ // @ts-ignore
162
+ [wrapStyle, stageStyle, rootComponents, componentStyle, componentMap, getComponentProps,];
163
+ }
164
+ if (__VLS_ctx.rootComponents.length === 0) {
165
+ __VLS_asFunctionalElement1(__VLS_intrinsics.div, __VLS_intrinsics.div)({
166
+ ...{ class: "preview-empty" },
167
+ });
168
+ /** @type {__VLS_StyleScopedClasses['preview-empty']} */ ;
169
+ }
170
+ // @ts-ignore
171
+ [rootComponents,];
172
+ const __VLS_export = (await import('vue')).defineComponent({});
173
+ export default {};
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "jojotaoo_preview",
3
+ "version": "0.0.1-beta.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.cjs",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "peerDependencies": {
21
+ "vue": "^3.5.0",
22
+ "jojotaoo_components": "0.0.1-beta.0"
23
+ },
24
+ "devDependencies": {
25
+ "vue": "^3.5.35",
26
+ "typescript": "~6.0.2",
27
+ "jojotaoo_components": "0.0.1-beta.0"
28
+ },
29
+ "module": "./dist/index.js"
30
+ }