@rafaelaugusto/jolt 0.1.0-beta.2 → 0.1.0-beta.4
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.
- package/README.md +112 -16
- package/dist/animate.d.ts +3 -1
- package/dist/animate.d.ts.map +1 -1
- package/dist/animate.js +89 -3
- package/dist/animate.js.map +1 -1
- package/dist/color.d.ts +11 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +73 -0
- package/dist/color.js.map +1 -0
- package/dist/decay.d.ts +11 -0
- package/dist/decay.d.ts.map +1 -0
- package/dist/decay.js +22 -0
- package/dist/decay.js.map +1 -0
- package/dist/driver/android-color.d.ts +17 -0
- package/dist/driver/android-color.d.ts.map +1 -0
- package/dist/driver/android-color.js +134 -0
- package/dist/driver/android-color.js.map +1 -0
- package/dist/driver/android.d.ts +1 -1
- package/dist/driver/android.d.ts.map +1 -1
- package/dist/driver/android.js +101 -5
- package/dist/driver/android.js.map +1 -1
- package/dist/driver/index.d.ts +4 -2
- package/dist/driver/index.d.ts.map +1 -1
- package/dist/driver/index.js.map +1 -1
- package/dist/driver/ios-color.d.ts +14 -0
- package/dist/driver/ios-color.d.ts.map +1 -0
- package/dist/driver/ios-color.js +381 -0
- package/dist/driver/ios-color.js.map +1 -0
- package/dist/driver/ios.d.ts.map +1 -1
- package/dist/driver/ios.js +9 -1
- package/dist/driver/ios.js.map +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +15 -8
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/liquid-grid.d.ts +3 -0
- package/dist/liquid-grid.d.ts.map +1 -0
- package/dist/liquid-grid.js +24 -0
- package/dist/liquid-grid.js.map +1 -0
- package/dist/liquid.d.ts +18 -0
- package/dist/liquid.d.ts.map +1 -0
- package/dist/liquid.js +229 -0
- package/dist/liquid.js.map +1 -0
- package/dist/loader.d.ts +19 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +172 -0
- package/dist/loader.js.map +1 -0
- package/dist/press.d.ts.map +1 -1
- package/dist/press.js +6 -1
- package/dist/press.js.map +1 -1
- package/dist/properties.d.ts +5 -3
- package/dist/properties.d.ts.map +1 -1
- package/dist/properties.js +13 -2
- package/dist/properties.js.map +1 -1
- package/dist/reveal.d.ts +25 -0
- package/dist/reveal.d.ts.map +1 -0
- package/dist/reveal.js +293 -0
- package/dist/reveal.js.map +1 -0
- package/dist/text-layout.d.ts +22 -0
- package/dist/text-layout.d.ts.map +1 -0
- package/dist/text-layout.js +179 -0
- package/dist/text-layout.js.map +1 -0
- package/dist/text.d.ts +17 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +267 -0
- package/dist/text.js.map +1 -0
- package/dist/track.d.ts +1 -1
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +63 -5
- package/dist/track.js.map +1 -1
- package/dist/transition.d.ts +5 -0
- package/dist/transition.d.ts.map +1 -1
- package/dist/transition.js +8 -2
- package/dist/transition.js.map +1 -1
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -2
- package/platforms/android/include.gradle +7 -0
- package/platforms/android/java/org/rafaelaugusto/jolt/ColorTarget.java +102 -0
- package/platforms/android/proguard-rules.pro +6 -0
- package/src/animate.ts +105 -5
- package/src/color.ts +101 -0
- package/src/decay.ts +45 -0
- package/src/driver/android-color.ts +168 -0
- package/src/driver/android.ts +120 -10
- package/src/driver/index.ts +9 -2
- package/src/driver/ios-color.ts +432 -0
- package/src/driver/ios.ts +13 -3
- package/src/engine.ts +17 -9
- package/src/index.ts +10 -1
- package/src/liquid-grid.ts +28 -0
- package/src/liquid.ts +282 -0
- package/src/loader.ts +201 -0
- package/src/press.ts +8 -2
- package/src/properties.ts +16 -6
- package/src/reveal.ts +374 -0
- package/src/text-layout.ts +216 -0
- package/src/text.ts +298 -0
- package/src/track.ts +105 -5
- package/src/transition.ts +16 -2
- package/src/types.ts +18 -0
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMjD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid-grid.d.ts","sourceRoot":"","sources":["../src/liquid-grid.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,6BAsBlB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A periodic displacement field. The fixed boundary keeps transparent edges in bounds. */
|
|
2
|
+
export function liquidGrid(columns, rows, phase, intensity) {
|
|
3
|
+
const positions = new Float32Array((columns + 1) * (rows + 1) * 2);
|
|
4
|
+
const t = phase * Math.PI * 2;
|
|
5
|
+
let index = 0;
|
|
6
|
+
for (let row = 0; row <= rows; row++) {
|
|
7
|
+
const y = row / rows;
|
|
8
|
+
for (let column = 0; column <= columns; column++) {
|
|
9
|
+
const x = column / columns;
|
|
10
|
+
const edge = Math.sin(Math.PI * x) ** 2 * Math.sin(Math.PI * y) ** 2;
|
|
11
|
+
const amount = 0.055 * intensity * edge;
|
|
12
|
+
positions[index++] =
|
|
13
|
+
x +
|
|
14
|
+
amount *
|
|
15
|
+
(Math.sin(Math.PI * 2 * y + t) + 0.4 * Math.sin(Math.PI * 2 * (x + y) - 2 * t));
|
|
16
|
+
positions[index++] =
|
|
17
|
+
y +
|
|
18
|
+
amount *
|
|
19
|
+
(Math.cos(Math.PI * 2 * x - t) + 0.4 * Math.cos(Math.PI * 2 * (x - y) + 2 * t));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return positions;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=liquid-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid-grid.js","sourceRoot":"","sources":["../src/liquid-grid.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,MAAM,UAAU,UAAU,CACxB,OAAe,EACf,IAAY,EACZ,KAAa,EACb,SAAiB;IAEjB,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAClE,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAA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}
|
package/dist/liquid.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Target } from './types.js';
|
|
2
|
+
export interface LiquidOptions {
|
|
3
|
+
/** Amount of internal deformation, from 0 to 1. Defaults to 0.7. */
|
|
4
|
+
intensity?: number;
|
|
5
|
+
/** Milliseconds per seamless cycle. Defaults to 8000. */
|
|
6
|
+
duration?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface LiquidEffect {
|
|
9
|
+
/** Freeze the current deformation. */
|
|
10
|
+
pause(): void;
|
|
11
|
+
/** Continue from the paused deformation. */
|
|
12
|
+
resume(): void;
|
|
13
|
+
/** Remove the effect and restore the image. Idempotent. */
|
|
14
|
+
stop(): void;
|
|
15
|
+
}
|
|
16
|
+
/** Deforms a raster image with native iOS texture warps. Android leaves it unchanged. */
|
|
17
|
+
export declare function liquid(target: Target, options?: LiquidOptions): LiquidEffect;
|
|
18
|
+
//# sourceMappingURL=liquid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid.d.ts","sourceRoot":"","sources":["../src/liquid.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,KAAK,IAAI,IAAI,CAAA;IACb,4CAA4C;IAC5C,MAAM,IAAI,IAAI,CAAA;IACd,2DAA2D;IAC3D,IAAI,IAAI,IAAI,CAAA;CACb;AASD,yFAAyF;AACzF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CAkBhF"}
|
package/dist/liquid.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { Application, Image, isIOS } from '@nativescript/core';
|
|
2
|
+
import { tintColorProperty } from '@nativescript/core/ui/image';
|
|
3
|
+
import { toView } from './animate.js';
|
|
4
|
+
import { liquidGrid } from './liquid-grid.js';
|
|
5
|
+
const running = new WeakMap();
|
|
6
|
+
const key = 'jolt:liquid';
|
|
7
|
+
const columns = 24;
|
|
8
|
+
const rows = 24;
|
|
9
|
+
const steps = 64;
|
|
10
|
+
const noop = () => { };
|
|
11
|
+
/** Deforms a raster image with native iOS texture warps. Android leaves it unchanged. */
|
|
12
|
+
export function liquid(target, options = {}) {
|
|
13
|
+
const settings = {
|
|
14
|
+
intensity: options.intensity ?? 0.7,
|
|
15
|
+
duration: options.duration ?? 8000,
|
|
16
|
+
};
|
|
17
|
+
if (!Number.isFinite(settings.intensity) ||
|
|
18
|
+
settings.intensity < 0 ||
|
|
19
|
+
settings.intensity > 1)
|
|
20
|
+
throw new RangeError('Liquid intensity must be between zero and one.');
|
|
21
|
+
if (!Number.isFinite(settings.duration) || settings.duration <= 0)
|
|
22
|
+
throw new RangeError('Liquid duration must be a positive finite number.');
|
|
23
|
+
const image = toView(target);
|
|
24
|
+
if (!(image instanceof Image))
|
|
25
|
+
throw new TypeError('Expected a NativeScript Image.');
|
|
26
|
+
running.get(image)?.stop();
|
|
27
|
+
if (!isIOS || settings.intensity === 0)
|
|
28
|
+
return { pause: noop, resume: noop, stop: noop };
|
|
29
|
+
return new Liquid(image, settings);
|
|
30
|
+
}
|
|
31
|
+
class Liquid {
|
|
32
|
+
image;
|
|
33
|
+
settings;
|
|
34
|
+
stopped = false;
|
|
35
|
+
queued = false;
|
|
36
|
+
pausedByUser = false;
|
|
37
|
+
active = UIApplication.sharedApplication.applicationState === 0; // UIApplicationStateActive
|
|
38
|
+
native;
|
|
39
|
+
original;
|
|
40
|
+
source;
|
|
41
|
+
renderer;
|
|
42
|
+
scene;
|
|
43
|
+
sprite;
|
|
44
|
+
observers = [];
|
|
45
|
+
constructor(image, settings) {
|
|
46
|
+
this.image = image;
|
|
47
|
+
this.settings = settings;
|
|
48
|
+
running.set(image, this);
|
|
49
|
+
for (const event of ['loaded', 'layoutChanged', 'imageSourceChange', 'stretchChange'])
|
|
50
|
+
image.on(event, this.schedule);
|
|
51
|
+
image.on('unloaded', this.unloaded);
|
|
52
|
+
image.style.on('visibilityChange', this.schedule);
|
|
53
|
+
image.style.on('tintColorChange', this.schedule);
|
|
54
|
+
this.observe(UIAccessibilityReduceMotionStatusDidChangeNotification, this.schedule);
|
|
55
|
+
this.observe(UIApplicationWillResignActiveNotification, this.suspend);
|
|
56
|
+
this.observe(UIApplicationDidBecomeActiveNotification, this.activate);
|
|
57
|
+
this.schedule();
|
|
58
|
+
}
|
|
59
|
+
pause = () => {
|
|
60
|
+
this.pausedByUser = true;
|
|
61
|
+
if (this.renderer)
|
|
62
|
+
this.renderer.paused = true;
|
|
63
|
+
};
|
|
64
|
+
resume = () => {
|
|
65
|
+
if (this.stopped)
|
|
66
|
+
return;
|
|
67
|
+
this.pausedByUser = false;
|
|
68
|
+
this.schedule();
|
|
69
|
+
};
|
|
70
|
+
stop = () => {
|
|
71
|
+
if (this.stopped)
|
|
72
|
+
return;
|
|
73
|
+
this.stopped = true;
|
|
74
|
+
for (const event of ['loaded', 'layoutChanged', 'imageSourceChange', 'stretchChange'])
|
|
75
|
+
this.image.off(event, this.schedule);
|
|
76
|
+
this.image.off('unloaded', this.unloaded);
|
|
77
|
+
this.image.style.off('visibilityChange', this.schedule);
|
|
78
|
+
this.image.style.off('tintColorChange', this.schedule);
|
|
79
|
+
for (const [name, observer] of this.observers)
|
|
80
|
+
Application.ios.removeNotificationObserver(observer, name);
|
|
81
|
+
this.observers = [];
|
|
82
|
+
if (running.get(this.image) === this)
|
|
83
|
+
running.delete(this.image);
|
|
84
|
+
this.remove();
|
|
85
|
+
};
|
|
86
|
+
observe(name, callback) {
|
|
87
|
+
this.observers.push([name, Application.ios.addNotificationObserver(name, callback)]);
|
|
88
|
+
}
|
|
89
|
+
suspend = () => {
|
|
90
|
+
this.active = false;
|
|
91
|
+
if (this.renderer)
|
|
92
|
+
this.renderer.paused = true;
|
|
93
|
+
};
|
|
94
|
+
activate = () => {
|
|
95
|
+
this.active = true;
|
|
96
|
+
this.schedule();
|
|
97
|
+
};
|
|
98
|
+
unloaded = () => this.remove();
|
|
99
|
+
schedule = () => {
|
|
100
|
+
if (this.stopped || this.queued)
|
|
101
|
+
return;
|
|
102
|
+
this.queued = true;
|
|
103
|
+
void Promise.resolve().then(() => {
|
|
104
|
+
this.queued = false;
|
|
105
|
+
if (this.stopped)
|
|
106
|
+
return;
|
|
107
|
+
try {
|
|
108
|
+
this.update();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
this.stop();
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
update() {
|
|
117
|
+
if (!this.image.isLoaded ||
|
|
118
|
+
this.image.visibility !== 'visible' ||
|
|
119
|
+
this.image.tintColor ||
|
|
120
|
+
UIAccessibilityIsReduceMotionEnabled())
|
|
121
|
+
return this.remove();
|
|
122
|
+
const native = this.image.nativeViewProtected;
|
|
123
|
+
if (!(native instanceof UIImageView) || !native.window)
|
|
124
|
+
return this.remove();
|
|
125
|
+
if (this.native &&
|
|
126
|
+
(this.native !== native ||
|
|
127
|
+
native.image !== null ||
|
|
128
|
+
this.image.imageSource !== this.source))
|
|
129
|
+
this.remove();
|
|
130
|
+
const source = this.original ?? native.image;
|
|
131
|
+
if (!source?.CGImage ||
|
|
132
|
+
source.images?.count ||
|
|
133
|
+
source.renderingMode === 2 /* AlwaysTemplate */)
|
|
134
|
+
return this.remove();
|
|
135
|
+
if (source.size.width * source.size.height * source.scale ** 2 > 16_777_216)
|
|
136
|
+
return this.remove();
|
|
137
|
+
const bounds = native.bounds;
|
|
138
|
+
if (bounds.size.width <= 0 ||
|
|
139
|
+
bounds.size.height <= 0 ||
|
|
140
|
+
source.size.width <= 0 ||
|
|
141
|
+
source.size.height <= 0)
|
|
142
|
+
return this.remove();
|
|
143
|
+
if (!this.renderer) {
|
|
144
|
+
// A paused SKView cannot draw its first frame. Keep the original visible
|
|
145
|
+
// until rendering can start, including source changes while paused.
|
|
146
|
+
if (this.pausedByUser || !this.active)
|
|
147
|
+
return;
|
|
148
|
+
this.create(native, source);
|
|
149
|
+
}
|
|
150
|
+
const renderer = this.renderer;
|
|
151
|
+
renderer.frame = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
|
|
152
|
+
this.scene.size = CGSizeMake(bounds.size.width, bounds.size.height);
|
|
153
|
+
const iw = source.size.width;
|
|
154
|
+
const ih = source.size.height;
|
|
155
|
+
const { width, height } = bounds.size;
|
|
156
|
+
const stretch = this.image.stretch;
|
|
157
|
+
const scale = stretch === 'aspectFill'
|
|
158
|
+
? Math.max(width / iw, height / ih)
|
|
159
|
+
: Math.min(width / iw, height / ih);
|
|
160
|
+
this.sprite.size = CGSizeMake(stretch === 'fill' ? width : stretch === 'none' ? iw : iw * scale, stretch === 'fill' ? height : stretch === 'none' ? ih : ih * scale);
|
|
161
|
+
this.sprite.position = CGPointMake(width / 2, height / 2);
|
|
162
|
+
renderer.paused = this.pausedByUser || !this.active;
|
|
163
|
+
}
|
|
164
|
+
create(native, source) {
|
|
165
|
+
const renderer = SKView.alloc().initWithFrame(native.bounds);
|
|
166
|
+
this.renderer = renderer;
|
|
167
|
+
this.native = native;
|
|
168
|
+
this.original = source;
|
|
169
|
+
this.source = this.image.imageSource;
|
|
170
|
+
renderer.opaque = false;
|
|
171
|
+
renderer.backgroundColor = UIColor.clearColor;
|
|
172
|
+
renderer.allowsTransparency = true;
|
|
173
|
+
renderer.asynchronous = true;
|
|
174
|
+
renderer.userInteractionEnabled = false;
|
|
175
|
+
renderer.accessibilityElementsHidden = true;
|
|
176
|
+
renderer.clipsToBounds = true;
|
|
177
|
+
renderer.preferredFramesPerSecond = Math.min(120, native.window?.screen?.maximumFramesPerSecond ?? 60);
|
|
178
|
+
renderer.paused = true;
|
|
179
|
+
const scene = SKScene.sceneWithSize(native.bounds.size);
|
|
180
|
+
this.scene = scene;
|
|
181
|
+
scene.backgroundColor = UIColor.clearColor;
|
|
182
|
+
scene.scaleMode = 3; // SKSceneScaleModeResizeFill
|
|
183
|
+
const texture = SKTexture.textureWithImage(source);
|
|
184
|
+
const sprite = SKSpriteNode.spriteNodeWithTexture(texture);
|
|
185
|
+
this.sprite = sprite;
|
|
186
|
+
const warps = [];
|
|
187
|
+
const times = [];
|
|
188
|
+
for (let step = 0; step <= steps; step++) {
|
|
189
|
+
const positions = liquidGrid(columns, rows, step === steps ? 0 : step / steps, this.settings.intensity);
|
|
190
|
+
warps.push(SKWarpGeometryGrid.gridWithColumnsRowsSourcePositionsDestPositions(columns, rows, null, positions));
|
|
191
|
+
times.push(((step / steps) * this.settings.duration) / 1000);
|
|
192
|
+
}
|
|
193
|
+
const loop = SKAction.animateWithWarpsTimes(warps, times);
|
|
194
|
+
if (!loop)
|
|
195
|
+
throw new Error('Unable to create the liquid warp action.');
|
|
196
|
+
sprite.warpGeometry = SKWarpGeometryGrid.gridWithColumnsRows(columns, rows);
|
|
197
|
+
const entrance = SKAction.warpToDuration(warps[0], Math.min(0.35, this.settings.duration / 10000));
|
|
198
|
+
if (!entrance)
|
|
199
|
+
throw new Error('Unable to create the liquid entrance.');
|
|
200
|
+
sprite.runActionWithKey(SKAction.sequence([entrance, SKAction.repeatActionForever(loop)]), key);
|
|
201
|
+
scene.addChild(sprite);
|
|
202
|
+
renderer.presentScene(scene);
|
|
203
|
+
native.addSubview(renderer);
|
|
204
|
+
native.image = null;
|
|
205
|
+
}
|
|
206
|
+
remove() {
|
|
207
|
+
const { renderer, sprite, native, original } = this;
|
|
208
|
+
if (renderer) {
|
|
209
|
+
renderer.paused = true;
|
|
210
|
+
sprite?.removeAllActions();
|
|
211
|
+
sprite?.removeFromParent();
|
|
212
|
+
renderer.presentScene(null);
|
|
213
|
+
renderer.removeFromSuperview();
|
|
214
|
+
}
|
|
215
|
+
if (native &&
|
|
216
|
+
native.image === null &&
|
|
217
|
+
original &&
|
|
218
|
+
this.image.imageSource === this.source) {
|
|
219
|
+
native.image = original;
|
|
220
|
+
// Core couldn't turn the suppressed UIImage into a template while it was
|
|
221
|
+
// hidden. Reapply its public native setter when a tint takes over.
|
|
222
|
+
if (this.image.tintColor)
|
|
223
|
+
this.image[tintColorProperty.setNative](this.image.tintColor);
|
|
224
|
+
}
|
|
225
|
+
this.renderer = this.scene = this.sprite = this.native = this.original = undefined;
|
|
226
|
+
this.source = undefined;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=liquid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid.js","sourceRoot":"","sources":["../src/liquid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAmB7C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAuB,CAAA;AAClD,MAAM,GAAG,GAAG,aAAa,CAAA;AACzB,MAAM,OAAO,GAAG,EAAE,CAAA;AAClB,MAAM,IAAI,GAAG,EAAE,CAAA;AACf,MAAM,KAAK,GAAG,EAAE,CAAA;AAChB,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAErB,yFAAyF;AACzF,MAAM,UAAU,MAAM,CAAC,MAAc,EAAE,OAAO,GAAkB,EAAE;IAChE,MAAM,QAAQ,GAAG;QACf,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,GAAG;QACnC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;KACnC,CAAA;IACD,IACE,CAAC,MAAM,CAAC,QAA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AC,CAAA;QAC5B,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QAC3B,MAAM,CAAC,KAAK,GAAG,IAAI,CAAA;IACrB,CAAC;IACO,MAAM;QACZ,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;QACnD,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAA;YACtB,MAAM,EAAE,gBAAgB,EAAE,CAAA;YAC1B,MAAM,EAAE,gBAAgB,EAAE,CAAA;YAC1B,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;YAC3B,QAAQ,CAAC,mBAAmB,EAAE,CAAA;QAChC,CAAC;QACD,IACE,MAAM;YACN,MAAM,CAAC,KAAK,KAAK,IAAI;YACrB,QAAQ;YACR,IAAI,CAAC,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC,MAAM,EACtC,CAAC;YACD,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAA;YACvB,yEAAyE;YACzE,mEAAmE;YACnE,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS;gBACrB,IAAI,CAAC,KAA6D,CACjE,iBAAiB,CAAC,SAAS,CAC3B,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAC5B,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAA;QAClF,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;IACzB,CAAC;CACF"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Target } from './types.js';
|
|
2
|
+
export type LoaderStyle = 'dots' | 'bars' | 'ring';
|
|
3
|
+
export interface LoaderOptions {
|
|
4
|
+
/** Defaults to 'dots'. */
|
|
5
|
+
style?: LoaderStyle;
|
|
6
|
+
/** A NativeScript color string. Defaults to '#71717a'. */
|
|
7
|
+
color?: string;
|
|
8
|
+
/** Maximum width and height in DIPs, fitted inside the target. Defaults to 48. */
|
|
9
|
+
size?: number;
|
|
10
|
+
/** Milliseconds per cycle. Defaults to 1200. */
|
|
11
|
+
duration?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Adds a centered native iOS loading indicator. Returns an idempotent cleanup.
|
|
15
|
+
* Unloading releases native resources; loading resumes until explicitly stopped.
|
|
16
|
+
* Reduce Motion keeps the indicator static. Android is a no-op.
|
|
17
|
+
*/
|
|
18
|
+
export declare function loader(target: Target, options?: LoaderOptions): () => void;
|
|
19
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAElD,MAAM,WAAW,aAAa;IAC5B,0BAA0B;IAC1B,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kFAAkF;IAClF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAKD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,IAAI,CAkB9E"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Application, Color, isIOS } from '@nativescript/core';
|
|
2
|
+
import { toView } from './animate.js';
|
|
3
|
+
const running = new WeakMap();
|
|
4
|
+
const key = 'jolt:loader';
|
|
5
|
+
/**
|
|
6
|
+
* Adds a centered native iOS loading indicator. Returns an idempotent cleanup.
|
|
7
|
+
* Unloading releases native resources; loading resumes until explicitly stopped.
|
|
8
|
+
* Reduce Motion keeps the indicator static. Android is a no-op.
|
|
9
|
+
*/
|
|
10
|
+
export function loader(target, options = {}) {
|
|
11
|
+
const settings = {
|
|
12
|
+
style: options.style ?? 'dots',
|
|
13
|
+
color: options.color ?? '#71717a',
|
|
14
|
+
size: options.size ?? 48,
|
|
15
|
+
duration: options.duration ?? 1200,
|
|
16
|
+
};
|
|
17
|
+
if (!['dots', 'bars', 'ring'].includes(settings.style))
|
|
18
|
+
throw new TypeError('Unknown loader style.');
|
|
19
|
+
if (typeof settings.color !== 'string' || !Color.isValid(settings.color))
|
|
20
|
+
throw new TypeError('Loader color must be a valid color string.');
|
|
21
|
+
for (const name of ['size', 'duration'])
|
|
22
|
+
if (!Number.isFinite(settings[name]) || settings[name] <= 0)
|
|
23
|
+
throw new RangeError(`Loader ${name} must be a positive finite number.`);
|
|
24
|
+
const view = toView(target);
|
|
25
|
+
running.get(view)?.();
|
|
26
|
+
if (!isIOS)
|
|
27
|
+
return () => { };
|
|
28
|
+
return new Loader(view, settings).stop;
|
|
29
|
+
}
|
|
30
|
+
class Loader {
|
|
31
|
+
view;
|
|
32
|
+
settings;
|
|
33
|
+
stopped = false;
|
|
34
|
+
queued = false;
|
|
35
|
+
waitingForLoad;
|
|
36
|
+
native;
|
|
37
|
+
layer;
|
|
38
|
+
item;
|
|
39
|
+
animating = false;
|
|
40
|
+
observer;
|
|
41
|
+
constructor(view, settings) {
|
|
42
|
+
this.view = view;
|
|
43
|
+
this.settings = settings;
|
|
44
|
+
this.waitingForLoad = !view.isLoaded;
|
|
45
|
+
running.set(view, this.stop);
|
|
46
|
+
view.on('loaded', this.loaded);
|
|
47
|
+
view.on('layoutChanged', this.schedule);
|
|
48
|
+
view.on('unloaded', this.unloaded);
|
|
49
|
+
this.schedule();
|
|
50
|
+
}
|
|
51
|
+
stop = () => {
|
|
52
|
+
if (this.stopped)
|
|
53
|
+
return;
|
|
54
|
+
this.stopped = true;
|
|
55
|
+
this.view.off('loaded', this.loaded);
|
|
56
|
+
this.view.off('layoutChanged', this.schedule);
|
|
57
|
+
this.view.off('unloaded', this.unloaded);
|
|
58
|
+
if (running.get(this.view) === this.stop)
|
|
59
|
+
running.delete(this.view);
|
|
60
|
+
this.unloaded();
|
|
61
|
+
};
|
|
62
|
+
loaded = () => {
|
|
63
|
+
this.waitingForLoad = false;
|
|
64
|
+
this.schedule();
|
|
65
|
+
};
|
|
66
|
+
unloaded = () => {
|
|
67
|
+
this.waitingForLoad = true;
|
|
68
|
+
if (this.observer) {
|
|
69
|
+
Application.ios.removeNotificationObserver(this.observer, UIAccessibilityReduceMotionStatusDidChangeNotification);
|
|
70
|
+
this.observer = undefined;
|
|
71
|
+
}
|
|
72
|
+
this.remove();
|
|
73
|
+
};
|
|
74
|
+
schedule = () => {
|
|
75
|
+
if (this.stopped || this.queued)
|
|
76
|
+
return;
|
|
77
|
+
this.queued = true;
|
|
78
|
+
void Promise.resolve().then(() => {
|
|
79
|
+
this.queued = false;
|
|
80
|
+
if (this.stopped)
|
|
81
|
+
return;
|
|
82
|
+
try {
|
|
83
|
+
this.update();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.stop();
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
update() {
|
|
92
|
+
if (this.waitingForLoad || !this.view.isLoaded)
|
|
93
|
+
return;
|
|
94
|
+
const native = this.view.nativeViewProtected;
|
|
95
|
+
if (!native?.window)
|
|
96
|
+
return this.remove();
|
|
97
|
+
const bounds = native.layer.bounds;
|
|
98
|
+
const size = Math.min(this.settings.size, bounds.size.width, bounds.size.height);
|
|
99
|
+
if (size <= 0)
|
|
100
|
+
return this.remove();
|
|
101
|
+
if (this.native && this.native !== native)
|
|
102
|
+
this.remove();
|
|
103
|
+
this.observer ??= Application.ios.addNotificationObserver(UIAccessibilityReduceMotionStatusDidChangeNotification, this.schedule);
|
|
104
|
+
CATransaction.begin();
|
|
105
|
+
CATransaction.setDisableActions(true);
|
|
106
|
+
try {
|
|
107
|
+
if (!this.layer) {
|
|
108
|
+
this.native = native;
|
|
109
|
+
this.layer = CAReplicatorLayer.new();
|
|
110
|
+
this.layer.name = key;
|
|
111
|
+
this.item = CALayer.new();
|
|
112
|
+
this.item.backgroundColor = new Color(this.settings.color).ios.CGColor;
|
|
113
|
+
this.layer.addSublayer(this.item);
|
|
114
|
+
native.layer.addSublayer(this.layer);
|
|
115
|
+
}
|
|
116
|
+
const layer = this.layer;
|
|
117
|
+
const item = this.item;
|
|
118
|
+
const { style, duration } = this.settings;
|
|
119
|
+
layer.bounds = CGRectMake(0, 0, size, size);
|
|
120
|
+
layer.position = CGPointMake(bounds.origin.x + bounds.size.width / 2, bounds.origin.y + bounds.size.height / 2);
|
|
121
|
+
layer.instanceCount = style === 'dots' ? 3 : style === 'bars' ? 5 : 12;
|
|
122
|
+
layer.instanceDelay = duration / 1000 / (style === 'ring' ? 12 : 5);
|
|
123
|
+
if (style === 'ring') {
|
|
124
|
+
const diameter = size * 0.16;
|
|
125
|
+
item.bounds = CGRectMake(0, 0, diameter, diameter);
|
|
126
|
+
item.position = CGPointMake(size / 2, diameter / 2);
|
|
127
|
+
item.cornerRadius = diameter / 2;
|
|
128
|
+
layer.instanceTransform = CATransform3DMakeRotation((2 * Math.PI) / 12, 0, 0, 1);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const width = size * (style === 'dots' ? 0.2 : 0.12);
|
|
132
|
+
const height = style === 'dots' ? width : size * 0.75;
|
|
133
|
+
item.bounds = CGRectMake(0, 0, width, height);
|
|
134
|
+
item.position = CGPointMake(width / 2, size / 2);
|
|
135
|
+
item.cornerRadius = width / 2;
|
|
136
|
+
layer.instanceTransform = CATransform3DMakeTranslation((size - width) / (layer.instanceCount - 1), 0, 0);
|
|
137
|
+
}
|
|
138
|
+
const reduced = UIAccessibilityIsReduceMotionEnabled();
|
|
139
|
+
item.opacity = style === 'ring' ? 0.35 : 1;
|
|
140
|
+
if (reduced && this.animating) {
|
|
141
|
+
item.removeAnimationForKey(key);
|
|
142
|
+
this.animating = false;
|
|
143
|
+
}
|
|
144
|
+
else if (!reduced && !this.animating) {
|
|
145
|
+
const animation = CAKeyframeAnimation.animationWithKeyPath(style === 'ring'
|
|
146
|
+
? 'opacity'
|
|
147
|
+
: style === 'bars'
|
|
148
|
+
? 'transform.scale.y'
|
|
149
|
+
: 'transform.scale');
|
|
150
|
+
animation.values = NSArray.arrayWithArray(style === 'ring' ? [1, 0.2] : [0.35, 1, 0.35, 0.35]);
|
|
151
|
+
animation.keyTimes = NSArray.arrayWithArray(style === 'ring' ? [0, 1] : [0, 0.3, 0.6, 1]);
|
|
152
|
+
animation.duration = duration / 1000;
|
|
153
|
+
animation.repeatCount = Infinity;
|
|
154
|
+
// Start one cycle in so every delayed copy is already participating.
|
|
155
|
+
animation.beginTime =
|
|
156
|
+
item.convertTimeFromLayer(CACurrentMediaTime(), null) - animation.duration;
|
|
157
|
+
item.addAnimationForKey(animation, key);
|
|
158
|
+
this.animating = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
CATransaction.commit();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
remove() {
|
|
166
|
+
this.item?.removeAnimationForKey(key);
|
|
167
|
+
this.layer?.removeFromSuperlayer();
|
|
168
|
+
this.item = this.layer = this.native = undefined;
|
|
169
|
+
this.animating = false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAa,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE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oot":"","sources":["../src/press.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"press.d.ts","sourceRoot":"","sources":["../src/press.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,iBAAiB,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAKnE;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CACnB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,SAA2B,EACpC,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,GACpC,MAAM,IAAI,CA+BZ"}
|
package/dist/press.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Color } from '@nativescript/core';
|
|
2
|
+
import { isColorProperty } from './color.js';
|
|
1
3
|
import { animate, toView } from './animate.js';
|
|
2
4
|
import { isProperty, readValue } from './properties.js';
|
|
3
5
|
const pressIn = { type: 'spring', duration: 200, bounce: 0 };
|
|
@@ -18,7 +20,10 @@ export function press(target, pressed = { scale: 0.96 }, options) {
|
|
|
18
20
|
const onTouch = (event) => {
|
|
19
21
|
const { action } = event;
|
|
20
22
|
if (action === 'down' && !rest && view.isEnabled !== false) {
|
|
21
|
-
rest = Object.fromEntries(properties.map((p) => [
|
|
23
|
+
rest = Object.fromEntries(properties.map((p) => [
|
|
24
|
+
p,
|
|
25
|
+
isColorProperty(p) ? new Color(readValue(view, p)) : readValue(view, p),
|
|
26
|
+
]));
|
|
22
27
|
animate(view, pressed, options ?? pressIn);
|
|
23
28
|
}
|
|
24
29
|
else if ((action === 'up' || action === 'cancel') && rest) {
|
package/dist/press.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"press.js","sourceRoot":"","sources":["../src/press.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"press.js","sourceRoot":"","sources":["../src/press.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EA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,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;aACxE,CAAC,CACH,CAAA;YACD,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,CAAA;QAC5C,CAAC;aAAM,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;YAC5D,OAAO,CACL,IAAI,EACJ,IAAI,EACJ,OAAO,OAAO,KAAK,QAAQ;gBACzB,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACjC,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,CACzB,CAAA;YACD,IAAI,GAAG,SAAS,CAAA;QAClB,CAAC;IACH,CAAC,CAAA;IAED,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACzB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzC,CAAC"}
|
package/dist/properties.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type View } from '@nativescript/core';
|
|
2
|
+
import { type ColorProperty } from './color.js';
|
|
3
|
+
export type NumericProperty = 'opacity' | 'x' | 'y' | 'scaleX' | 'scaleY' | 'rotate' | 'rotateX' | 'rotateY';
|
|
4
|
+
export type Property = NumericProperty | ColorProperty;
|
|
5
|
+
/** How close to its target a spring or decay has to be to count as settled. */
|
|
4
6
|
export declare const precision: Record<Property, number>;
|
|
5
7
|
export declare function isProperty(key: string): key is Property;
|
|
6
8
|
export declare function readValue(view: View, property: Property): number;
|
package/dist/properties.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAA8B,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAE3E,MAAM,MAAM,eAAe,GACzB,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAChF,MAAM,MAAM,QAAQ,GAAG,eAAe,GAAG,aAAa,CAAA;AAwBtD,+EAA+E;AAC/E,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAY9C,CAAA;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,QAAQ,CAEvD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAIhE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,QAMvE"}
|
package/dist/properties.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Color } from '@nativescript/core';
|
|
2
|
+
import { isColorProperty, readColor } from './color.js';
|
|
1
3
|
const viewKeys = {
|
|
2
4
|
opacity: 'opacity',
|
|
3
5
|
x: 'translateX',
|
|
@@ -18,8 +20,11 @@ const defaults = {
|
|
|
18
20
|
rotateX: 0,
|
|
19
21
|
rotateY: 0,
|
|
20
22
|
};
|
|
21
|
-
/** How close to its target a spring has to be to count as settled. */
|
|
23
|
+
/** How close to its target a spring or decay has to be to count as settled. */
|
|
22
24
|
export const precision = {
|
|
25
|
+
backgroundColor: 0.002,
|
|
26
|
+
borderColor: 0.002,
|
|
27
|
+
color: 0.002,
|
|
23
28
|
opacity: 0.002,
|
|
24
29
|
x: 0.25,
|
|
25
30
|
y: 0.25,
|
|
@@ -30,13 +35,19 @@ export const precision = {
|
|
|
30
35
|
rotateY: 0.1,
|
|
31
36
|
};
|
|
32
37
|
export function isProperty(key) {
|
|
33
|
-
return key in viewKeys;
|
|
38
|
+
return key in viewKeys || isColorProperty(key);
|
|
34
39
|
}
|
|
35
40
|
export function readValue(view, property) {
|
|
41
|
+
if (isColorProperty(property))
|
|
42
|
+
return readColor(view, property);
|
|
36
43
|
const value = view[viewKeys[property]];
|
|
37
44
|
return typeof value === 'number' && !Number.isNaN(value) ? value : defaults[property];
|
|
38
45
|
}
|
|
39
46
|
export function writeValue(view, property, value) {
|
|
47
|
+
if (isColorProperty(property)) {
|
|
48
|
+
view[property] = new Color(value);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
40
51
|
view[viewKeys[property]] = value;
|
|
41
52
|
}
|
|
42
53
|
//# sourceMappingURL=properties.js.map
|
package/dist/properties.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAsB,MAAM,YAAY,CAAA;AAM3E,MAAM,QAAQ,GAAG;IACf,OAAO,EAAE,SAAS;IAClB,CAAC,EAAE,YAAY;IACf,CAAC,EAAE,YAAY;IACf,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;CACoC,CAAA;AAExD,MAAM,QAAQ,GAAoC;IAChD,OAAO,EAAE,CAAC;I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