Fit the QuickLook panel to screen

I'm writing a special image format preview app with QuickLook extension. What's the preferred way to resize the QuickLook preview panel so that it fits the screen?

https://github.com/yllan/JXLook/issues/12

Manually setting preferredContentSize worked for image that's smaller than the screen size.

However, if I need to scale down to fit the preview window in screen, is there some way to tell the window just fit the content size to screen?

I tried manually calculate the size with window.constrainFrameRect but it didn't return the desired size that fitting into screen when calling in QuickLook extension. (It worked in main app though)
I am also developing a QuickLook extension, and still have no idea on how to resize the "window". It should be possible, because I installed apps like Sketch or Pixelmator Pro, that include the QuickLook .appex, and they successfully resize the window to fit the content, wether it is smaller or bigger than the default size. I can't yet find an open source project that handles this.

Also, it seems that the system image QuickLook previews and others are written in the legacy .qlgenerators (found in /System/Library/QuickLook
Fit the QuickLook panel to screen
 
 
Q