@editframe/elements 0.13.0-beta.2 → 0.13.0-beta.3

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.
@@ -1,5 +1,4 @@
1
1
  import { LitElement } from 'lit';
2
- import { createRef } from 'lit/directives/ref.js';
3
2
  import { EFTimegroup } from '../elements/EFTimegroup.js';
4
3
  export declare const targetTimegroupContext: {
5
4
  __context__: EFTimegroup | null;
@@ -12,8 +11,6 @@ export declare class ContextMixinInterface extends LitElement {
12
11
  loop: boolean;
13
12
  currentTimeMs: number;
14
13
  focusedElement?: HTMLElement;
15
- stageRef: ReturnType<typeof createRef<HTMLDivElement>>;
16
- canvasRef: ReturnType<typeof createRef<HTMLElement>>;
17
14
  targetTimegroup: EFTimegroup | null;
18
15
  play(): void;
19
16
  pause(): void;
@@ -1,6 +1,5 @@
1
1
  import { createContext, provide } from "@lit/context";
2
2
  import { state, property } from "lit/decorators.js";
3
- import { createRef } from "lit/directives/ref.js";
4
3
  import { apiHostContext } from "./apiHostContext.js";
5
4
  import { efContext } from "./efContext.js";
6
5
  import { fetchContext } from "./fetchContext.js";
@@ -64,8 +63,6 @@ function ContextMixin(superClass) {
64
63
  this.loop = false;
65
64
  this.rendering = false;
66
65
  this.currentTimeMs = 0;
67
- this.stageRef = createRef();
68
- this.canvasRef = createRef();
69
66
  this.#FPS = 30;
70
67
  this.#MS_PER_FRAME = 1e3 / this.#FPS;
71
68
  this.#timegroupObserver = new MutationObserver((mutations) => {
@@ -736,6 +736,8 @@ EFFilmstrip.styles = [
736
736
  :host {
737
737
  display: block;
738
738
  overflow: hidden;
739
+ width: 100%;
740
+ height: 100%;
739
741
  }
740
742
  `
741
743
  ];
@@ -2,9 +2,14 @@ import { LitElement, PropertyValueMap } from 'lit';
2
2
  declare const EFWorkbench_base: (new (...args: any[]) => import('./ContextMixin.js').ContextMixinInterface) & typeof LitElement;
3
3
  export declare class EFWorkbench extends EFWorkbench_base {
4
4
  static styles: import('lit').CSSResult[];
5
- disconnectedCallback(): void;
5
+ stageRef: import('lit-html/directives/ref.js').Ref<HTMLDivElement>;
6
+ canvasRef: import('lit-html/directives/ref.js').Ref<HTMLSlotElement>;
6
7
  handleStageWheel(event: WheelEvent): void;
7
8
  focusOverlay: import('lit-html/directives/ref.js').Ref<HTMLDivElement>;
9
+ private stageScale;
10
+ setStageScale: () => void;
11
+ connectedCallback(): void;
12
+ disconnectedCallback(): void;
8
13
  update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
9
14
  drawOverlays: () => void;
10
15
  render(): import('lit-html').TemplateResult<1>;
@@ -1,5 +1,5 @@
1
1
  import { html, css, LitElement } from "lit";
2
- import { eventOptions, customElement } from "lit/decorators.js";
2
+ import { eventOptions, state, customElement } from "lit/decorators.js";
3
3
  import { createRef, ref } from "lit/directives/ref.js";
4
4
  import { ContextMixin } from "./ContextMixin.js";
5
5
  import { TWMixin } from "./TWMixin.js";
@@ -16,7 +16,45 @@ var __decorateClass = (decorators, target, key, kind) => {
16
16
  let EFWorkbench = class extends ContextMixin(TWMixin(LitElement)) {
17
17
  constructor() {
18
18
  super(...arguments);
19
+ this.stageRef = createRef();
20
+ this.canvasRef = createRef();
19
21
  this.focusOverlay = createRef();
22
+ this.stageScale = 1;
23
+ this.setStageScale = () => {
24
+ if (this.isConnected && !this.rendering) {
25
+ const canvasElement = this.canvasRef.value;
26
+ const stageElement = this.stageRef.value;
27
+ const canvasChild = canvasElement?.assignedElements()[0];
28
+ if (stageElement && canvasElement && canvasChild) {
29
+ canvasElement.style.width = `${canvasChild.clientWidth}px`;
30
+ canvasElement.style.height = `${canvasChild.clientHeight}px`;
31
+ const stageWidth = stageElement.clientWidth;
32
+ const stageHeight = stageElement.clientHeight;
33
+ const canvasWidth = canvasElement.clientWidth;
34
+ const canvasHeight = canvasElement.clientHeight;
35
+ const stageRatio = stageWidth / stageHeight;
36
+ const canvasRatio = canvasWidth / canvasHeight;
37
+ if (stageRatio > canvasRatio) {
38
+ const scale = stageHeight / canvasHeight;
39
+ if (this.stageScale !== scale) {
40
+ canvasElement.style.transform = `scale(${scale})`;
41
+ canvasElement.style.transformOrigin = "top center";
42
+ }
43
+ this.stageScale = scale;
44
+ } else {
45
+ const scale = stageWidth / canvasWidth;
46
+ if (this.stageScale !== scale) {
47
+ canvasElement.style.transform = `scale(${scale})`;
48
+ canvasElement.style.transformOrigin = "center";
49
+ }
50
+ this.stageScale = scale;
51
+ }
52
+ }
53
+ }
54
+ if (this.isConnected) {
55
+ requestAnimationFrame(this.setStageScale);
56
+ }
57
+ };
20
58
  this.drawOverlays = () => {
21
59
  const focusOverlay = this.focusOverlay.value;
22
60
  if (focusOverlay) {
@@ -37,12 +75,24 @@ let EFWorkbench = class extends ContextMixin(TWMixin(LitElement)) {
37
75
  }
38
76
  };
39
77
  }
40
- disconnectedCallback() {
41
- super.disconnectedCallback();
42
- }
43
78
  handleStageWheel(event) {
44
79
  event.preventDefault();
45
80
  }
81
+ connectedCallback() {
82
+ document.body.style.width = "100%";
83
+ document.body.style.height = "100%";
84
+ document.documentElement.style.width = "100%";
85
+ document.documentElement.style.height = "100%";
86
+ super.connectedCallback();
87
+ requestAnimationFrame(this.setStageScale);
88
+ }
89
+ disconnectedCallback() {
90
+ super.disconnectedCallback();
91
+ document.body.style.width = "";
92
+ document.body.style.height = "";
93
+ document.documentElement.style.width = "";
94
+ document.documentElement.style.height = "";
95
+ }
46
96
  update(changedProperties) {
47
97
  super.update(changedProperties);
48
98
  if (changedProperties.has("focusedElement")) {
@@ -97,6 +147,9 @@ EFWorkbench.styles = [
97
147
  __decorateClass([
98
148
  eventOptions({ passive: false, capture: true })
99
149
  ], EFWorkbench.prototype, "handleStageWheel", 1);
150
+ __decorateClass([
151
+ state()
152
+ ], EFWorkbench.prototype, "stageScale", 2);
100
153
  EFWorkbench = __decorateClass([
101
154
  customElement("ef-workbench")
102
155
  ], EFWorkbench);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@editframe/elements",
3
- "version": "0.13.0-beta.2",
3
+ "version": "0.13.0-beta.3",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -21,7 +21,7 @@
21
21
  "author": "",
22
22
  "license": "UNLICENSED",
23
23
  "dependencies": {
24
- "@editframe/assets": "0.13.0-beta.2",
24
+ "@editframe/assets": "0.13.0-beta.3",
25
25
  "@lit/context": "^1.1.2",
26
26
  "@lit/task": "^1.0.1",
27
27
  "d3": "^7.9.0",
@@ -2,7 +2,6 @@ import { createContext, provide } from "@lit/context";
2
2
  import type { LitElement } from "lit";
3
3
  import { property, state } from "lit/decorators.js";
4
4
 
5
- import { createRef } from "lit/directives/ref.js";
6
5
  import type { EFTimegroup } from "../elements/EFTimegroup.js";
7
6
  import { apiHostContext } from "./apiHostContext.js";
8
7
  import { efContext } from "./efContext.js";
@@ -23,8 +22,6 @@ export declare class ContextMixinInterface extends LitElement {
23
22
  loop: boolean;
24
23
  currentTimeMs: number;
25
24
  focusedElement?: HTMLElement;
26
- stageRef: ReturnType<typeof createRef<HTMLDivElement>>;
27
- canvasRef: ReturnType<typeof createRef<HTMLElement>>;
28
25
  targetTimegroup: EFTimegroup | null;
29
26
  play(): void;
30
27
  pause(): void;
@@ -123,9 +120,6 @@ export function ContextMixin<T extends Constructor<LitElement>>(superClass: T) {
123
120
  @state()
124
121
  currentTimeMs = 0;
125
122
 
126
- stageRef = createRef<HTMLDivElement>();
127
- canvasRef = createRef<HTMLSlotElement>();
128
-
129
123
  #FPS = 30;
130
124
  #MS_PER_FRAME = 1000 / this.#FPS;
131
125
 
@@ -525,6 +525,8 @@ export class EFFilmstrip extends TWMixin(LitElement) {
525
525
  :host {
526
526
  display: block;
527
527
  overflow: hidden;
528
+ width: 100%;
529
+ height: 100%;
528
530
  }
529
531
  `,
530
532
  ];
@@ -1,5 +1,5 @@
1
1
  import { LitElement, type PropertyValueMap, css, html } from "lit";
2
- import { customElement, eventOptions } from "lit/decorators.js";
2
+ import { customElement, eventOptions, state } from "lit/decorators.js";
3
3
  import { createRef, ref } from "lit/directives/ref.js";
4
4
 
5
5
  import { ContextMixin } from "./ContextMixin.js";
@@ -17,9 +17,8 @@ export class EFWorkbench extends ContextMixin(TWMixin(LitElement)) {
17
17
  `,
18
18
  ];
19
19
 
20
- disconnectedCallback(): void {
21
- super.disconnectedCallback();
22
- }
20
+ stageRef = createRef<HTMLDivElement>();
21
+ canvasRef = createRef<HTMLSlotElement>();
23
22
 
24
23
  @eventOptions({ passive: false, capture: true })
25
24
  handleStageWheel(event: WheelEvent) {
@@ -28,6 +27,69 @@ export class EFWorkbench extends ContextMixin(TWMixin(LitElement)) {
28
27
 
29
28
  focusOverlay = createRef<HTMLDivElement>();
30
29
 
30
+ @state()
31
+ private stageScale = 1;
32
+
33
+ setStageScale = () => {
34
+ if (this.isConnected && !this.rendering) {
35
+ const canvasElement = this.canvasRef.value;
36
+ const stageElement = this.stageRef.value;
37
+ const canvasChild = canvasElement?.assignedElements()[0];
38
+ if (stageElement && canvasElement && canvasChild) {
39
+ // Determine the appropriate scale factor to make the canvas fit into
40
+ canvasElement.style.width = `${canvasChild.clientWidth}px`;
41
+ canvasElement.style.height = `${canvasChild.clientHeight}px`;
42
+ const stageWidth = stageElement.clientWidth;
43
+ const stageHeight = stageElement.clientHeight;
44
+ const canvasWidth = canvasElement.clientWidth;
45
+ const canvasHeight = canvasElement.clientHeight;
46
+ const stageRatio = stageWidth / stageHeight;
47
+ const canvasRatio = canvasWidth / canvasHeight;
48
+
49
+ if (stageRatio > canvasRatio) {
50
+ const scale = stageHeight / canvasHeight;
51
+ if (this.stageScale !== scale) {
52
+ canvasElement.style.transform = `scale(${scale})`;
53
+ canvasElement.style.transformOrigin = "top center";
54
+ }
55
+ this.stageScale = scale;
56
+ } else {
57
+ const scale = stageWidth / canvasWidth;
58
+ if (this.stageScale !== scale) {
59
+ canvasElement.style.transform = `scale(${scale})`;
60
+ canvasElement.style.transformOrigin = "center";
61
+ }
62
+ this.stageScale = scale;
63
+ }
64
+ }
65
+ }
66
+ if (this.isConnected) {
67
+ requestAnimationFrame(this.setStageScale);
68
+ }
69
+ };
70
+
71
+ connectedCallback(): void {
72
+ // Set the body and html to 100% width and height to avoid scaling issues
73
+ // this is a hack to avoid scaling issues when the stage is scaled and during output rendering
74
+ // What I've discovered recently is that having the workbench be so smart as to determine
75
+ // how it should be displayed at render time causes problems. Much of that has been extracted
76
+ // but this is a quick fix to avoid scaling issues.
77
+ document.body.style.width = "100%";
78
+ document.body.style.height = "100%";
79
+ document.documentElement.style.width = "100%";
80
+ document.documentElement.style.height = "100%";
81
+ super.connectedCallback();
82
+ requestAnimationFrame(this.setStageScale);
83
+ }
84
+
85
+ disconnectedCallback(): void {
86
+ super.disconnectedCallback();
87
+ document.body.style.width = "";
88
+ document.body.style.height = "";
89
+ document.documentElement.style.width = "";
90
+ document.documentElement.style.height = "";
91
+ }
92
+
31
93
  update(
32
94
  changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>,
33
95
  ): void {