Skip to content

Commit

Permalink
Upgrade to lit 2 (#3405)
Browse files Browse the repository at this point in the history
* upgrade to lit 2

* add license to spread directive

* remove lit 2 binding artifacts from snippets

* Update comment to match current comment style
  • Loading branch information
e111077 authored May 2, 2022
1 parent 4734ba3 commit 0ec49c5
Show file tree
Hide file tree
Showing 109 changed files with 2,290 additions and 1,014 deletions.
79 changes: 63 additions & 16 deletions packages/model-viewer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/model-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
],
"dependencies": {
"three": "^0.139.2",
"lit-element": "^2.5.1",
"lit-html": "^1.4.1"
"lit": "^2.2.3"
},
"devDependencies": {
"@open-wc/karma-esm": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/assets/close-material-svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {html} from 'lit-html';
import {html} from 'lit';

export default html`
<svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" viewBox="0 0 24 24" fill="#000000">
Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/assets/controls-svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {html} from 'lit-html';
import {html} from 'lit';

export default html`
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="25" height="36">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {html} from 'lit-html';
import {html} from 'lit';

export default html`
<svg version="1.1" id="view_x5F_in_x5F_AR_x5F_icon"
Expand Down
12 changes: 6 additions & 6 deletions packages/model-viewer/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
* limitations under the License.
*/

import {UpdatingElement} from 'lit-element/lib/updating-element';
import {ReactiveElement} from 'lit';
import {EvaluatedStyle, Intrinsics, StyleEvaluator} from './styles/evaluators';
import {parseExpressions, Unit} from './styles/parsers';
import {StyleEffector} from './styles/style-effector';

// An IntrinsicsFactory generates up-to-date intrinsics for a given ModelViewer
// element instance when it is invoked.
export type IntrinsicsFactory<T extends Intrinsics<Array<Unit>>,
U extends UpdatingElement> =
U extends ReactiveElement> =
(element: U) => T;

// When applying the @style decorator, it needs to be configured with
// corresponding Intrinsics and the property key of a method to receive updated
// values. Optionally, it can also be configured to observe environment effects,
// which causes a StyleEffector to be created for the property.
export interface StyleDecoratorConfig<T extends Intrinsics<Array<Unit>>,
U extends UpdatingElement> {
U extends ReactiveElement> {
intrinsics: T|IntrinsicsFactory<T, U>;
updateHandler: symbol;
observeEffects?: boolean;
Expand Down Expand Up @@ -66,14 +66,14 @@ export interface StyleDecoratorConfig<T extends Intrinsics<Array<Unit>>,
* static).
*/
export const style =
<T extends Intrinsics<Array<Unit>>, U extends UpdatingElement>(
<T extends Intrinsics<Array<Unit>>, U extends ReactiveElement>(
config: StyleDecoratorConfig<T, U>) => {
const observeEffects: boolean = config.observeEffects || false;
const getIntrinsics = config.intrinsics instanceof Function ?
config.intrinsics :
(() => config.intrinsics) as IntrinsicsFactory<T, U>;

return <U extends typeof UpdatingElement['prototype']>(
return <U extends typeof ReactiveElement['prototype']>(
proto: U, propertyName: string) => {
const originalUpdated = (proto as any).updated;
const originalConnectedCallback = proto.connectedCallback;
Expand All @@ -93,7 +93,7 @@ export const style =
[$updateEvaluator]: {
value: function() {
const ast = parseExpressions(
this[propertyName as keyof UpdatingElement] as string);
this[propertyName as keyof ReactiveElement] as string);
this[$styleEvaluator] =
new StyleEvaluator(ast, getIntrinsics(this));

Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/features/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {property} from 'lit/decorators.js';
import {LoopOnce, LoopPingPong, LoopRepeat} from 'three';

import ModelViewerElementBase, {$hasTransitioned, $needsRender, $onModelLoad, $renderer, $scene, $tick, $updateSource} from '../model-viewer-base.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/features/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {property} from 'lit/decorators.js';
import {Event as ThreeEvent} from 'three';
import {USDZExporter} from 'three/examples/jsm/exporters/USDZExporter.js';

Expand Down
8 changes: 5 additions & 3 deletions packages/model-viewer/src/features/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {property} from 'lit/decorators.js';
import {Event, PerspectiveCamera, Spherical, Vector3} from 'three';

import {style} from '../decorators.js';
Expand Down Expand Up @@ -563,7 +563,8 @@ export const ControlsMixin = <T extends Constructor<ModelViewerElementBase>>(
this.requestUpdate('fieldOfView');
this.requestUpdate('minCameraOrbit');
this.requestUpdate('maxCameraOrbit');
await this.requestUpdate('cameraOrbit');
this.requestUpdate('cameraOrbit');
await this.updateComplete;
}

[$syncFieldOfView](style: EvaluatedStyle<Intrinsics<['rad']>>) {
Expand Down Expand Up @@ -729,7 +730,8 @@ export const ControlsMixin = <T extends Constructor<ModelViewerElementBase>>(

controls.updateAspect(this[$scene].aspect);

await this.requestUpdate('maxFieldOfView', this.maxFieldOfView);
this.requestUpdate('maxFieldOfView', this.maxFieldOfView);
await this.updateComplete;
this[$controls].setFieldOfView(fov);

this.jumpCameraToGoal();
Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/features/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {property} from 'lit/decorators.js';
import {Event as ThreeEvent, Texture} from 'three';

import ModelViewerElementBase, {$needsRender, $onModelLoad, $progressTracker, $renderer, $scene, $shouldAttemptPreload} from '../model-viewer-base.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/features/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {property} from 'lit/decorators.js';

import ModelViewerElementBase, {$altDefaulted, $announceModelVisibility, $getModelIsVisible, $hasTransitioned, $isElementInViewport, $progressTracker, $scene, $sceneIsReady, $shouldAttemptPreload, $updateSource, $updateStatus, $userInputElement, toVector3D, Vector3D} from '../model-viewer-base.js';
import {$loader, CachingGLTFLoader} from '../three-components/CachingGLTFLoader.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/features/scene-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {property} from 'lit/decorators.js';
import {Euler, RepeatWrapping, sRGBEncoding, Texture, TextureLoader} from 'three';
import {GLTFExporter, GLTFExporterOptions} from 'three/examples/jsm/exporters/GLTFExporter.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/model-viewer/src/features/staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {property} from 'lit/decorators.js';
import {style} from '../decorators.js';
import ModelViewerElementBase, {$hasTransitioned, $renderer, $scene, $tick} from '../model-viewer-base.js';
import {degreesToRadians} from '../styles/conversions.js';
Expand Down
6 changes: 3 additions & 3 deletions packages/model-viewer/src/model-viewer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import {property} from 'lit-element';
import {UpdatingElement} from 'lit-element/lib/updating-element';
import {ReactiveElement} from 'lit';
import {property} from 'lit/decorators.js';
import {Event as ThreeEvent, Vector2, Vector3} from 'three';

import {HAS_INTERSECTION_OBSERVER, HAS_RESIZE_OBSERVER} from './constants.js';
Expand Down Expand Up @@ -129,7 +129,7 @@ export interface RendererInterface {
/**
* Definition for a basic <model-viewer> element.
*/
export default class ModelViewerElementBase extends UpdatingElement {
export default class ModelViewerElementBase extends ReactiveElement {
static get is() {
return 'model-viewer';
}
Expand Down
8 changes: 4 additions & 4 deletions packages/model-viewer/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {html, render} from 'lit-html';
import {html, render} from 'lit';

import CloseIcon from './assets/close-material-svg.js';
import ControlsPrompt from './assets/controls-svg.js';
Expand Down Expand Up @@ -318,7 +318,7 @@ canvas.show {
<canvas></canvas>
</slot>
</div>
</div>
<!-- NOTE(cdata): We need to wrap slots because browsers without ShadowDOM
Expand All @@ -341,7 +341,7 @@ canvas.show {
<div class="slot pan-target">
<slot name="pan-target">
<div id="default-pan-target">
<div id="default-pan-target">
</div>
</slot>
</div>
Expand All @@ -365,7 +365,7 @@ canvas.show {
</div>
</slot>
</div>
<div class="slot exit-webxr-ar-button">
<slot name="exit-webxr-ar-button">
<a id="default-exit-webxr-ar-button" part="default-exit-webxr-ar-button"
Expand Down
5 changes: 3 additions & 2 deletions packages/model-viewer/src/test/decorators-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {property, UpdatingElement} from 'lit-element';
import {property} from 'lit/decorators.js';
import {ReactiveElement} from 'lit';

import {style} from '../decorators.js';
import {numberNode} from '../styles/parsers.js';
Expand All @@ -27,7 +28,7 @@ const fooIntrinsics = {
keywords: {auto: [null, numberNode(200, '%')]}
};

class StyleableElement extends UpdatingElement {
class StyleableElement extends ReactiveElement {
@style({intrinsics: fooIntrinsics, updateHandler: $updateFoo})
@property({type: String})
foo: string = '200cm 1rad';
Expand Down
3 changes: 2 additions & 1 deletion packages/model-viewer/src/three-components/ModelScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ export class ModelScene extends Scene {
const {center} = this.boundingSphere;

if (this.tightBounds === true) {
await this.element.requestUpdate('cameraTarget');
this.element.requestUpdate('cameraTarget');
await this.element.updateComplete;
center.copy(this.getTarget());
} else {
this.boundingBox.getCenter(center);
Expand Down
Loading

0 comments on commit 0ec49c5

Please sign in to comment.