diff --git a/popup/src/App.vue b/popup/src/App.vue
index cfdbe72..460fb34 100644
--- a/popup/src/App.vue
+++ b/popup/src/App.vue
@@ -21,6 +21,7 @@
:is-draggable="state.isDraggable"
:image-url="state.layoutPreview.imageUrl"
:opacity="state.layoutPreview.opacity"
+ :user-style="state.layoutPreview.style"
/>
@@ -28,28 +29,45 @@
+./utils
diff --git a/popup/src/components/LayoutPreview.spec.ts b/popup/src/components/LayoutPreview.spec.ts
index e6a4d1a..bedbdd9 100644
--- a/popup/src/components/LayoutPreview.spec.ts
+++ b/popup/src/components/LayoutPreview.spec.ts
@@ -6,11 +6,17 @@ beforeEach(() => {
window._unpluginOverlayLayout = {}
})
-const mountElement = (props?: { isDraggable?: boolean; imageUrl?: string; opacity?: number }) => {
+const mountElement = (props?: {
+ isDraggable?: boolean
+ imageUrl?: string
+ opacity?: number
+ userStyle?: string
+}) => {
const defaultProps = {
isDraggable: true,
imageUrl: '',
- opacity: 100
+ opacity: 100,
+ userStyle: ''
}
return shallowMount(LayoutPreview, {
props: {
@@ -22,15 +28,12 @@ const mountElement = (props?: { isDraggable?: boolean; imageUrl?: string; opacit
describe('LayoutPreview.vue', () => {
it('global style config can work', () => {
- const style = 'width: 20px'
- window._unpluginOverlayLayout = {
- layoutPreview: {
- style
- }
- }
+ const userStyle = 'width: 20px'
- const wrapper = mountElement()
- expect(wrapper.attributes('style')).toContain(style)
+ const wrapper = mountElement({
+ userStyle
+ })
+ expect(wrapper.attributes('style')).toContain(userStyle)
})
it('computes the style correctly', () => {
diff --git a/popup/src/components/LayoutPreview.vue b/popup/src/components/LayoutPreview.vue
index 1e0e993..f7e5b73 100644
--- a/popup/src/components/LayoutPreview.vue
+++ b/popup/src/components/LayoutPreview.vue
@@ -11,6 +11,7 @@ const props = defineProps<{
isDraggable: boolean
imageUrl: string
opacity: number
+ userStyle: StyleValue
}>()
const defaultStyle = computed(() => {
@@ -20,8 +21,6 @@ const defaultStyle = computed(() => {
}
})
-const userStyle = window._unpluginOverlayLayout?.layoutPreview?.style || {}
-
const el = ref(null)
const { style: dragStyle } = useDraggable(el)
@@ -45,6 +44,6 @@ const controlStyle = computed(() => {
})
const mergedStyle = computed(() => {
- return [defaultStyle.value, userStyle, ...controlStyle.value]
+ return [defaultStyle.value, props.userStyle, ...controlStyle.value]
})
diff --git a/popup/src/utils.ts b/popup/src/utils.ts
new file mode 100644
index 0000000..308c492
--- /dev/null
+++ b/popup/src/utils.ts
@@ -0,0 +1,35 @@
+export function deepEqual(obj1: any, obj2: any, excludeProps: string[] = []): boolean {
+ // Check if both objects are of the same type
+ if (typeof obj1 !== typeof obj2) {
+ return false
+ }
+
+ // Check if both objects are primitive types or null
+ if (obj1 == null || obj2 == null || typeof obj1 !== 'object') {
+ return obj1 === obj2
+ }
+
+ // Get the keys of the objects
+ const keys1 = Object.keys(obj1)
+ const keys2 = Object.keys(obj2)
+
+ // Check if the number of keys is the same
+ if (keys1.length !== keys2.length) {
+ return false
+ }
+
+ // Iterate through the keys and recursively compare the values
+ for (const key of keys1) {
+ // Check if the current key should be excluded
+ if (excludeProps.includes(key)) {
+ continue
+ }
+
+ if (!deepEqual(obj1[key], obj2[key], excludeProps)) {
+ return false
+ }
+ }
+
+ // If all comparisons passed, the objects are deep equal
+ return true
+}