How to use dimensions method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ve.dm.Scalable.js

Source: ve.dm.Scalable.js Github

copy
1/*!
2 * VisualEditor DataModel Scalable class.
3 *
4 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
5 */
6
7/**
8 * Scalable object.
9 *
10 * @class
11 * @mixins OO.EventEmitter
12 *
13 * @constructor
14 * @param {Object} [config] Configuration options
15 * @cfg {boolean} [fixedRatio=true] Object has a fixed aspect ratio
16 * @cfg {Object} [currentDimensions] Current dimensions, width & height
17 * @cfg {Object} [originalDimensions] Original dimensions, width & height
18 * @cfg {Object} [defaultDimensions] Default dimensions, width & height
19 * @cfg {boolean} [isDefault] Object is using its default dimensions
20 * @cfg {Object} [minDimensions] Minimum dimensions, width & height
21 * @cfg {Object} [maxDimensions] Maximum dimensions, width & height
22 * @cfg {boolean} [enforceMin=true] Enforce the minimum dimensions
23 * @cfg {boolean} [enforceMax=true] Enforce the maximum dimensions
24 */
25ve.dm.Scalable = function VeDmScalable( config ) {
26	config = ve.extendObject( {
27		fixedRatio: true,
28		enforceMin: true,
29		enforceMax: true
30	}, config );
31
32	// Mixin constructors
33	OO.EventEmitter.call( this );
34
35	// Computed properties
36	this.ratio = null;
37	this.valid = null;
38	this.defaultSize = false;
39
40	// Initialize
41	this.currentDimensions = null;
42	this.defaultDimensions = null;
43	this.originalDimensions = null;
44	this.minDimensions = null;
45	this.maxDimensions = null;
46
47	// Properties
48	this.fixedRatio = config.fixedRatio;
49	if ( config.currentDimensions ) {
50		this.setCurrentDimensions( config.currentDimensions );
51	}
52	if ( config.originalDimensions ) {
53		this.setOriginalDimensions( config.originalDimensions );
54	}
55	if ( config.defaultDimensions ) {
56		this.setDefaultDimensions( config.defaultDimensions );
57	}
58	if ( config.isDefault ) {
59		this.toggleDefault( !!config.isDefault );
60	}
61	if ( config.minDimensions ) {
62		this.setMinDimensions( config.minDimensions );
63	}
64	if ( config.maxDimensions ) {
65		this.setMaxDimensions( config.maxDimensions );
66	}
67
68	this.setEnforcedMin( config.enforceMin );
69	this.setEnforcedMax( config.enforceMax );
70};
71
72/* Inheritance */
73
74OO.mixinClass( ve.dm.Scalable, OO.EventEmitter );
75
76/* Events */
77
78/**
79 * Current changed
80 *
81 * @event currentSizeChange
82 * @param {Object} currentDimensions Current dimensions width and height
83 */
84
85/**
86 * Default size or state changed
87 *
88 * @event defaultSizeChange
89 * @param {boolean} isDefault The size is default
90 */
91
92/**
93 * Original size changed
94 *
95 * @event originalSizeChange
96 * @param {Object} originalDimensions Original dimensions width and height
97 */
98
99/**
100 * Min size changed
101 *
102 * @event minSizeChange
103 * @param {Object} minDimensions Min dimensions width and height
104 */
105
106/**
107 * Max size changed
108 *
109 * @event maxSizeChange
110 * @param {Object} maxDimensions Max dimensions width and height
111 */
112
113/**
114 * Calculate the dimensions from a given value of either width or height.
115 * This method doesn't take into account any restrictions of minimum or maximum,
116 * it simply calculates the new dimensions according to the aspect ratio in case
117 * it exists.
118 *
119 * If aspect ratio does not exist, or if the original object is empty, or if the
120 * original object is fully specified, the object is returned as-is without
121 * calculations.
122 *
123 * @param {Object} dimensions Dimensions object with either width or height
124 * if both are given, the object will be returned as-is.
125 * @param {number} [dimensions.width] The width of the image
126 * @param {number} [dimensions.height] The height of the image
127 * @param {number} [ratio] The image width/height ratio, if it exists
128 * @return {Object} Dimensions object with width and height
129 */
130ve.dm.Scalable.static.getDimensionsFromValue = function ( dimensions, ratio ) {
131	dimensions = ve.copy( dimensions );
132
133	// Normalize for 'empty' values that are specifically given
134	// so if '' is explicitly given, it should be translated to 0
135	if ( dimensions.width === '' ) {
136		dimensions.width = 0;
137	}
138	if ( dimensions.height === '' ) {
139		dimensions.height = 0;
140	}
141
142	// Calculate the opposite size if needed
143	if ( !dimensions.height && ratio !== null && +dimensions.width ) {
144		dimensions.height = Math.round( dimensions.width / ratio );
145	}
146	if ( !dimensions.width && ratio !== null && +dimensions.height ) {
147		dimensions.width = Math.round( dimensions.height * ratio );
148	}
149
150	return dimensions;
151};
152
153/**
154 * Check if an object is a dimensions object.
155 * Make sure that if width or height are set, they are not 'undefined'.
156 *
157 * @param {Object} dimensions A dimensions object to test
158 * @return {boolean} Valid or invalid dimensions object
159 */
160ve.dm.Scalable.static.isDimensionsObjectValid = function ( dimensions ) {
161	if (
162		dimensions &&
163		!ve.isEmptyObject( dimensions ) &&
164		(
165			dimensions.width !== undefined ||
166			dimensions.height !== undefined
167		)
168	) {
169		return true;
170	}
171	return false;
172};
173
174/* Methods */
175
176/**
177 * Clone the current scalable object
178 *
179 * @return {ve.dm.Scalable} Cloned scalable object
180 */
181ve.dm.Scalable.prototype.clone = function () {
182	var currentDimensions = this.getCurrentDimensions(),
183		originalDimensions = this.getOriginalDimensions(),
184		defaultDimensions = this.getDefaultDimensions(),
185		minDimensions = this.getMinDimensions(),
186		maxDimensions = this.getMaxDimensions(),
187		config = {
188			isDefault: !!this.isDefault(),
189			enforceMin: !!this.isEnforcedMin(),
190			enforceMax: !!this.isEnforcedMax()
191		};
192	if ( currentDimensions ) {
193		config.currentDimensions = ve.copy( currentDimensions );
194	}
195	if ( originalDimensions ) {
196		config.originalDimensions = ve.copy( originalDimensions );
197	}
198	if ( defaultDimensions ) {
199		config.defaultDimensions = ve.copy( defaultDimensions );
200	}
201	if ( minDimensions ) {
202		config.minDimensions = ve.copy( minDimensions );
203	}
204	if ( maxDimensions ) {
205		config.maxDimensions = ve.copy( maxDimensions );
206	}
207	return new this.constructor( config );
208};
209
210/**
211 * Set the fixed aspect ratio from specified dimensions.
212 *
213 * @param {Object} dimensions Dimensions object with width & height
214 */
215ve.dm.Scalable.prototype.setRatioFromDimensions = function ( dimensions ) {
216	if ( dimensions && dimensions.width && dimensions.height ) {
217		this.ratio = dimensions.width / dimensions.height;
218	}
219	this.valid = null;
220};
221
222/**
223 * Set the current dimensions
224 *
225 * Also sets the aspect ratio if not set and in fixed ratio mode.
226 *
227 * @param {Object} dimensions Dimensions object with width & height
228 * @fires currentSizeChange
229 */
230ve.dm.Scalable.prototype.setCurrentDimensions = function ( dimensions ) {
231	if (
232		this.constructor.static.isDimensionsObjectValid( dimensions ) &&
233		!ve.compare( dimensions, this.getCurrentDimensions() )
234	) {
235		this.currentDimensions = ve.copy( dimensions );
236		// Only use current dimensions for ratio if it isn't set
237		if ( this.fixedRatio && !this.ratio ) {
238			this.setRatioFromDimensions( this.getCurrentDimensions() );
239		}
240		this.valid = null;
241		this.emit( 'currentSizeChange', this.getCurrentDimensions() );
242	}
243};
244
245/**
246 * Set the original dimensions
247 *
248 * Also resets the aspect ratio if in fixed ratio mode.
249 *
250 * @param {Object} dimensions Dimensions object with width & height
251 * @fires originalSizeChange
252 */
253ve.dm.Scalable.prototype.setOriginalDimensions = function ( dimensions ) {
254	if (
255		this.constructor.static.isDimensionsObjectValid( dimensions ) &&
256		!ve.compare( dimensions, this.getOriginalDimensions() )
257	) {
258		this.originalDimensions = ve.copy( dimensions );
259		// Always overwrite ratio
260		if ( this.fixedRatio ) {
261			this.setRatioFromDimensions( this.getOriginalDimensions() );
262		}
263		this.valid = null;
264		this.emit( 'originalSizeChange', this.getOriginalDimensions() );
265	}
266};
267
268/**
269 * Set the default dimensions
270 *
271 * @param {Object} dimensions Dimensions object with width & height
272 * @fires defaultSizeChange
273 */
274ve.dm.Scalable.prototype.setDefaultDimensions = function ( dimensions ) {
275	if (
276		this.constructor.static.isDimensionsObjectValid( dimensions ) &&
277		!ve.compare( dimensions, this.getDefaultDimensions() )
278	) {
279		this.defaultDimensions = ve.copy( dimensions );
280		this.valid = null;
281		this.emit( 'defaultSizeChange', this.isDefault() );
282	}
283};
284
285/**
286 * Reset and remove the default dimensions
287 *
288 * @fires defaultSizeChange
289 */
290ve.dm.Scalable.prototype.clearDefaultDimensions = function () {
291	if ( this.defaultDimensions !== null ) {
292		this.defaultDimensions = null;
293		this.valid = null;
294		this.emit( 'defaultSizeChange', this.isDefault() );
295	}
296};
297
298/**
299 * Reset and remove the default dimensions
300 *
301 * @fires originalSizeChange
302 */
303ve.dm.Scalable.prototype.clearOriginalDimensions = function () {
304	if ( this.originalDimensions !== null ) {
305		this.originalDimensions = null;
306		this.valid = null;
307		this.emit( 'originalSizeChange', this.isDefault() );
308	}
309};
310
311/**
312 * Toggle the default size setting, or set it to particular value
313 *
314 * @param {boolean} [isDefault] Default or not, toggles if unset
315 * @fires defaultSizeChange
316 */
317ve.dm.Scalable.prototype.toggleDefault = function ( isDefault ) {
318	if ( isDefault === undefined ) {
319		isDefault = !this.isDefault();
320	}
321	if ( this.isDefault() !== isDefault ) {
322		this.defaultSize = isDefault;
323		if ( isDefault ) {
324			this.setCurrentDimensions(
325				this.getDefaultDimensions()
326			);
327		}
328		this.emit( 'defaultSizeChange', this.isDefault() );
329	}
330};
331
332/**
333 * Set the minimum dimensions
334 *
335 * @param {Object} dimensions Dimensions object with width & height
336 * @fires minSizeChange
337 */
338ve.dm.Scalable.prototype.setMinDimensions = function ( dimensions ) {
339	if (
340		this.constructor.static.isDimensionsObjectValid( dimensions ) &&
341		!ve.compare( dimensions, this.getMinDimensions() )
342	) {
343		this.minDimensions = ve.copy( dimensions );
344		this.valid = null;
345		this.emit( 'minSizeChange', dimensions );
346	}
347};
348
349/**
350 * Set the maximum dimensions
351 *
352 * @param {Object} dimensions Dimensions object with width & height
353 * @fires maxSizeChange
354 */
355ve.dm.Scalable.prototype.setMaxDimensions = function ( dimensions ) {
356	if (
357		this.constructor.static.isDimensionsObjectValid( dimensions ) &&
358		!ve.compare( dimensions, this.getMaxDimensions() )
359	) {
360		this.maxDimensions = ve.copy( dimensions );
361		this.emit( 'maxSizeChange', dimensions );
362		this.valid = null;
363	}
364};
365
366/**
367 * Clear the minimum dimensions
368 *
369 * @fires minSizeChange
370 */
371ve.dm.Scalable.prototype.clearMinDimensions = function () {
372	if ( this.minDimensions !== null ) {
373		this.minDimensions = null;
374		this.valid = null;
375		this.emit( 'minSizeChange', this.minDimensions );
376	}
377};
378
379/**
380 * Clear the maximum dimensions
381 *
382 * @fires maxSizeChange
383 */
384ve.dm.Scalable.prototype.clearMaxDimensions = function () {
385	if ( this.maxDimensions !== null ) {
386		this.maxDimensions = null;
387		this.valid = null;
388		this.emit( 'maxSizeChange', this.maxDimensions );
389	}
390};
391
392/**
393 * Get the original dimensions
394 *
395 * @return {Object} Dimensions object with width & height
396 */
397ve.dm.Scalable.prototype.getCurrentDimensions = function () {
398	return this.currentDimensions;
399};
400
401/**
402 * Get the original dimensions
403 *
404 * @return {Object} Dimensions object with width & height
405 */
406ve.dm.Scalable.prototype.getOriginalDimensions = function () {
407	return this.originalDimensions;
408};
409
410/**
411 * Get the default dimensions
412 *
413 * @return {Object} Dimensions object with width & height
414 */
415ve.dm.Scalable.prototype.getDefaultDimensions = function () {
416	return this.defaultDimensions;
417};
418
419/**
420 * Get the default state of the scalable object
421 *
422 * @return {boolean} Default size or custom
423 */
424ve.dm.Scalable.prototype.isDefault = function () {
425	return this.defaultSize;
426};
427
428/**
429 * Get the minimum dimensions
430 *
431 * @return {Object} Dimensions object with width & height
432 */
433ve.dm.Scalable.prototype.getMinDimensions = function () {
434	return this.minDimensions;
435};
436
437/**
438 * Get the maximum dimensions
439 *
440 * @return {Object} Dimensions object with width & height
441 */
442ve.dm.Scalable.prototype.getMaxDimensions = function () {
443	return this.maxDimensions;
444};
445
446/**
447 * The object enforces the minimum dimensions when scaling
448 *
449 * @return {boolean} Enforces the minimum dimensions
450 */
451ve.dm.Scalable.prototype.isEnforcedMin = function () {
452	return this.enforceMin;
453};
454
455/**
456 * The object enforces the maximum dimensions when scaling
457 *
458 * @return {boolean} Enforces the maximum dimensions
459 */
460ve.dm.Scalable.prototype.isEnforcedMax = function () {
461	return this.enforceMax;
462};
463
464/**
465 * Set enforcement of minimum dimensions
466 *
467 * @param {boolean} enforceMin Enforces the minimum dimensions
468 */
469ve.dm.Scalable.prototype.setEnforcedMin = function ( enforceMin ) {
470	this.valid = null;
471	this.enforceMin = !!enforceMin;
472};
473
474/**
475 * Set enforcement of maximum dimensions
476 *
477 * @param {boolean} enforceMax Enforces the maximum dimensions
478 */
479ve.dm.Scalable.prototype.setEnforcedMax = function ( enforceMax ) {
480	this.valid = null;
481	this.enforceMax = !!enforceMax;
482};
483
484/**
485 * Get the fixed aspect ratio (width/height)
486 *
487 * @return {number} Aspect ratio
488 */
489ve.dm.Scalable.prototype.getRatio = function () {
490	return this.ratio;
491};
492
493/**
494 * Check if the object has a fixed ratio
495 *
496 * @return {boolean} The object has a fixed ratio
497 */
498ve.dm.Scalable.prototype.isFixedRatio = function () {
499	return this.fixedRatio;
500};
501
502/**
503 * Get the current scale of the object
504 *
505 * @return {number|null} A scale (1=100%), or null if not applicable
506 */
507ve.dm.Scalable.prototype.getCurrentScale = function () {
508	if ( !this.isFixedRatio() || !this.getCurrentDimensions() || !this.getOriginalDimensions() ) {
509		return null;
510	}
511	return this.getCurrentDimensions().width / this.getOriginalDimensions().width;
512};
513
514/**
515 * Check if current dimensions are smaller than minimum dimensions in either direction
516 *
517 * Only possible if enforceMin is false.
518 *
519 * @return {boolean} Current dimensions are greater than maximum dimensions
520 */
521ve.dm.Scalable.prototype.isTooSmall = function () {
522	return !!( this.getCurrentDimensions() && this.getMinDimensions() &&
523		(
524			this.getCurrentDimensions().width < this.getMinDimensions().width ||
525			this.getCurrentDimensions().height < this.getMinDimensions().height
526		)
527	);
528};
529
530/**
531 * Check if current dimensions are greater than maximum dimensions in either direction
532 *
533 * Only possible if enforceMax is false.
534 *
535 * @return {boolean} Current dimensions are greater than maximum dimensions
536 */
537ve.dm.Scalable.prototype.isTooLarge = function () {
538	return !!( this.getCurrentDimensions() && this.getMaxDimensions() &&
539		(
540			this.getCurrentDimensions().width > this.getMaxDimensions().width ||
541			this.getCurrentDimensions().height > this.getMaxDimensions().height
542		)
543	);
544};
545
546/**
547 * Get a set of dimensions bounded by current restrictions, from specified dimensions
548 *
549 * @param {Object} dimensions Dimensions object with width & height
550 * @param {number} [grid] Optional grid size to snap to
551 * @return {Object} Dimensions object with width & height
552 */
553ve.dm.Scalable.prototype.getBoundedDimensions = function ( dimensions, grid ) {
554	var ratio, snap, snapMin, snapMax,
555		minDimensions = this.isEnforcedMin() && this.getMinDimensions(),
556		maxDimensions = this.isEnforcedMax() && this.getMaxDimensions();
557
558	dimensions = ve.copy( dimensions );
559
560	// Bound to min/max
561	if ( minDimensions ) {
562		dimensions.width = Math.max( dimensions.width, this.minDimensions.width );
563		dimensions.height = Math.max( dimensions.height, this.minDimensions.height );
564	}
565	if ( maxDimensions ) {
566		dimensions.width = Math.min( dimensions.width, this.maxDimensions.width );
567		dimensions.height = Math.min( dimensions.height, this.maxDimensions.height );
568	}
569
570	// Bound to ratio
571	if ( this.isFixedRatio() ) {
572		ratio = dimensions.width / dimensions.height;
573		if ( ratio < this.getRatio() ) {
574			dimensions.height = Math.round( dimensions.width / this.getRatio() );
575		} else {
576			dimensions.width = Math.round( dimensions.height * this.getRatio() );
577		}
578	}
579
580	// Snap to grid
581	if ( grid ) {
582		snapMin = minDimensions ? Math.ceil( minDimensions.width / grid ) : -Infinity;
583		snapMax = maxDimensions ? Math.floor( maxDimensions.width / grid ) : Infinity;
584		snap = Math.round( dimensions.width / grid );
585		dimensions.width = Math.max( Math.min( snap, snapMax ), snapMin ) * grid;
586		if ( this.isFixedRatio() ) {
587			// If the ratio is fixed we can't snap both to the grid, so just snap the width
588			dimensions.height = Math.round( dimensions.width / this.getRatio() );
589		} else {
590			snapMin = minDimensions ? Math.ceil( minDimensions.height / grid ) : -Infinity;
591			snapMax = maxDimensions ? Math.floor( maxDimensions.height / grid ) : Infinity;
592			snap = Math.round( dimensions.height / grid );
593			dimensions.height = Math.max( Math.min( snap, snapMax ), snapMin ) * grid;
594		}
595	}
596
597	return dimensions;
598};
599
600/**
601 * Checks whether the current dimensions are numeric and within range
602 *
603 * @return {boolean} Current dimensions are valid
604 */
605ve.dm.Scalable.prototype.isCurrentDimensionsValid = function () {
606	var dimensions = this.getCurrentDimensions(),
607		minDimensions = this.isEnforcedMin() && !ve.isEmptyObject( this.getMinDimensions() ) && this.getMinDimensions(),
608		maxDimensions = this.isEnforcedMax() && !ve.isEmptyObject( this.getMaxDimensions() ) && this.getMaxDimensions();
609
610	this.valid = (
611		!!dimensions &&
612		// Dimensions must be non-zero
613		+dimensions.width &&
614		+dimensions.height &&
615		(
616			!minDimensions || (
617				dimensions.width >= minDimensions.width &&
618				dimensions.height >= minDimensions.height
619			)
620		) &&
621		(
622			!maxDimensions || (
623				dimensions.width <= maxDimensions.width &&
624				dimensions.height <= maxDimensions.height
625			)
626		)
627	);
628	return this.valid;
629};
630
Full Screen

ve.dm.Scalable.test.js

Source: ve.dm.Scalable.test.js Github

copy
1/*!
2 * VisualEditor DataModel Scalable tests.
3 *
4 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
5 */
6
7QUnit.module( 've.dm.Scalable' );
8
9QUnit.test( 'construction/clone/getters/setters/toggleDefault/clearers', function ( assert ) {
10	var eventEmitted = false,
11		currentDimensions = {
12			width: 300,
13			height: 200
14		},
15		originalDimensions = {
16			width: 600,
17			height: 400
18		},
19		defaultDimensions = {
20			width: 150,
21			height: 50
22		},
23		minDimensions = {
24			width: 1,
25			height: 1
26		},
27		maxDimensions = {
28			width: 1200,
29			height: 800
30		},
31		scalable = new ve.dm.Scalable( {
32			currentDimensions: currentDimensions,
33			originalDimensions: originalDimensions,
34			defaultDimensions: defaultDimensions,
35			minDimensions: minDimensions,
36			maxDimensions: maxDimensions
37		} ),
38		clone = scalable.clone();
39
40	assert.deepEqual( scalable, clone, 'Clone is deepEqual' );
41	assert.notStrictEqual( scalable, clone, 'Clone is not reference equal' );
42	assert.deepEqual( scalable.getCurrentDimensions(), currentDimensions, 'getCurrentDimensions' );
43	assert.deepEqual( scalable.getOriginalDimensions(), originalDimensions, 'getOriginalDimensions' );
44	assert.deepEqual( scalable.getDefaultDimensions(), defaultDimensions, 'getDefaultDimensions' );
45	assert.deepEqual( scalable.getMinDimensions(), minDimensions, 'getMinDimensions' );
46	assert.deepEqual( scalable.getMaxDimensions(), maxDimensions, 'getMaxDimensions' );
47	assert.strictEqual( scalable.getRatio(), 1.5, 'getRatio' );
48
49	scalable.toggleDefault();
50	assert.deepEqual( scalable.getCurrentDimensions(), scalable.getDefaultDimensions(), 'toggleDefault makes an image use default dimensions' );
51	scalable.toggleDefault();
52	assert.deepEqual( scalable.getCurrentDimensions(), scalable.getDefaultDimensions(), 'toggleDefault on an already-default image has no effect' );
53	scalable.toggleDefault( false );
54	assert.deepEqual( scalable.getCurrentDimensions(), scalable.getDefaultDimensions(), 'toggleDefault( false ) on an already-default image has no effect' );
55
56	scalable.clearDefaultDimensions();
57	assert.strictEqual( scalable.getDefaultDimensions(), null, 'clearDefaultDimensions' );
58
59	scalable.on( 'defaultSizeChange', function () {
60		eventEmitted = true;
61	} );
62	eventEmitted = false;
63	scalable.clearDefaultDimensions();
64	scalable.off( 'defaultSizeChange' );
65	assert.strictEqual( eventEmitted, false, 'clearDefaultDimensions doesn\'t re-run' );
66
67	scalable.clearOriginalDimensions();
68	assert.strictEqual( scalable.getOriginalDimensions(), null, 'clearOriginalDimensions' );
69
70	scalable.on( 'originalSizeChange', function () {
71		eventEmitted = true;
72	} );
73	eventEmitted = false;
74	scalable.clearOriginalDimensions();
75	scalable.off( 'originalSizeChange' );
76	assert.strictEqual( eventEmitted, false, 'clearOriginalDimensions doesn\'t re-run' );
77
78	scalable.clearMinDimensions();
79	assert.strictEqual( scalable.getMinDimensions(), null, 'clearMinDimensions' );
80
81	scalable.on( 'minSizeChange', function () {
82		eventEmitted = true;
83	} );
84	eventEmitted = false;
85	scalable.clearMinDimensions();
86	scalable.off( 'minSizeChange' );
87	assert.strictEqual( eventEmitted, false, 'clearMinDimensions doesn\'t re-run' );
88
89	scalable.clearMaxDimensions();
90	assert.strictEqual( scalable.getMaxDimensions(), null, 'clearMaxDimensions' );
91
92	scalable.on( 'maxSizeChange', function () {
93		eventEmitted = true;
94	} );
95	eventEmitted = false;
96	scalable.clearMaxDimensions();
97	scalable.off( 'maxSizeChange' );
98	assert.strictEqual( eventEmitted, false, 'clearMaxDimensions doesn\'t re-run' );
99
100	assert.deepEqual( scalable.getBoundedDimensions( { width: 448, height: 317 }, 10 ), { width: 450, height: 300 }, 'getBoundedDimensions without bounds snapped to 10px grid' );
101
102	scalable.fixedRatio = false;
103
104	assert.deepEqual( scalable.getBoundedDimensions( { width: 448, height: 317 }, 10 ), { width: 450, height: 320 }, 'getBoundedDimensions without bounds or fixed ratio snapped to 10px grid' );
105
106	scalable.fixedRatio = true;
107	scalable.setRatioFromDimensions( scalable.getCurrentDimensions() );
108
109	clone = scalable.clone();
110	clone.setOriginalDimensions();
111	clone.setDefaultDimensions();
112	clone.setMinDimensions();
113	clone.setMaxDimensions();
114
115	assert.strictEqual( clone.getOriginalDimensions(), scalable.getOriginalDimensions(), 'setOriginalDimensions without values is a no-op' );
116	assert.strictEqual( clone.getDefaultDimensions(), scalable.getDefaultDimensions(), 'setDefaultDimensions without values is a no-op' );
117	assert.strictEqual( clone.getMinDimensions(), scalable.getMinDimensions(), 'setMinDimensions without values is a no-op' );
118	assert.strictEqual( clone.getMaxDimensions(), scalable.getMaxDimensions(), 'setMaxDimensions without values is a no-op' );
119
120	clone = scalable.clone();
121	clone.setRatioFromDimensions();
122	assert.strictEqual( clone.getRatio(), scalable.getRatio(), 'setRatioFromDimensions without values is a no-op' );
123
124	scalable.setOriginalDimensions( { width: 300, height: 100 } );
125	assert.strictEqual( scalable.getRatio(), 3, 'setOriginalDimensions overwrites the ratio if set' );
126
127	scalable.fixedRatio = false;
128	scalable.setOriginalDimensions( { width: 300, height: 200 } );
129	assert.strictEqual( scalable.getRatio(), 3, 'setOriginalDimensions doesn\'t overwrite the ratio if not set' );
130
131	scalable.fixedRatio = true;
132	scalable.setOriginalDimensions( { width: 1, height: 1 } );
133	assert.strictEqual( scalable.getRatio(), 1, 'setOriginalDimensions overwrites the ratio if set again' );
134
135} );
136
137QUnit.test( 'getBoundedDimensions/getCurrentScale/isCurrentDimensionsValid/isTooSmall/isTooLarge', function ( assert ) {
138	var currentDimensions = {
139			width: 300,
140			height: 200
141		},
142		originalDimensions = {
143			width: 600,
144			height: 400
145		},
146		minDimensions = {
147			width: 150,
148			height: 100
149		},
150		maxDimensions = {
151			width: 1200,
152			height: 800
153		},
154		scalable = new ve.dm.Scalable( {
155			currentDimensions: currentDimensions,
156			originalDimensions: originalDimensions,
157			minDimensions: minDimensions,
158			maxDimensions: maxDimensions
159		} );
160
161	assert.deepEqual( scalable.getBoundedDimensions( { width: 600, height: 600 } ), { width: 600, height: 400 }, 'getBoundedDimensions' );
162	assert.deepEqual( scalable.getBoundedDimensions( { width: 2000, height: 2000 } ), { width: 1200, height: 800 }, 'getBoundedDimensions beyond maxDimensions' );
163	assert.deepEqual( scalable.getBoundedDimensions( { width: 30, height: 30 } ), { width: 150, height: 100 }, 'getBoundedDimensions beyond minDimensions' );
164	assert.deepEqual( scalable.getBoundedDimensions( { width: 448, height: 317 }, 10 ), { width: 450, height: 300 }, 'getBoundedDimensions snapped to 10px grid' );
165
166	scalable.fixedRatio = false;
167
168	assert.strictEqual( scalable.getCurrentScale(), null, 'Scale is null when not fixed ratio' );
169
170	assert.deepEqual( scalable.getBoundedDimensions( { width: 600, height: 600 } ), { width: 600, height: 600 }, 'getBoundedDimensions, no fixed ratio' );
171	assert.deepEqual( scalable.getBoundedDimensions( { width: 448, height: 317 }, 10 ), { width: 450, height: 320 }, 'getBoundedDimensions snapped to 10px grid, no fixed ratio' );
172
173	scalable.fixedRatio = true;
174
175	assert.strictEqual( scalable.isCurrentDimensionsValid(), true, '300x200 are valid dimensions' );
176	assert.strictEqual( scalable.getCurrentScale(), 0.5, '300x200 is scale of 0.5' );
177
178	scalable.setCurrentDimensions( { width: 1200, height: 800 } );
179	assert.strictEqual( scalable.getCurrentScale(), 2, '1200x800 is scale of 2' );
180
181	scalable.setCurrentDimensions( { width: 1300, height: 810 } );
182	assert.strictEqual( scalable.isCurrentDimensionsValid(), false, 'Too large dimensions are not valid' );
183	assert.strictEqual( scalable.isTooSmall(), false, 'Too large dimensions are not too small' );
184	assert.strictEqual( scalable.isTooLarge(), true, 'Too large dimensions are too large' );
185
186	scalable.setCurrentDimensions( { width: 30, height: 20 } );
187	assert.strictEqual( scalable.isCurrentDimensionsValid(), false, 'Too small dimensions are not valid' );
188	assert.strictEqual( scalable.isTooSmall(), true, 'Too large dimensions are too small' );
189	assert.strictEqual( scalable.isTooLarge(), false, 'Too large dimensions are not too large' );
190
191} );
192
193QUnit.test( 'isDefault/toggleDefault', function ( assert ) {
194	var scalable = new ve.dm.Scalable( {
195			isDefault: true
196		} ),
197		clone = scalable.clone();
198
199	assert.deepEqual( scalable, clone, 'Clone is deepEqual even when config is sparse' );
200
201	assert.strictEqual( scalable.isDefault(), true, 'isDefault' );
202	scalable.toggleDefault();
203	assert.strictEqual( scalable.isDefault(), false, 'toggleDefault changes true to false' );
204	scalable.toggleDefault();
205	assert.strictEqual( scalable.isDefault(), true, 'toggleDefault changes false to true' );
206} );
207
208QUnit.test( 'isDimensionsObjectValid', function ( assert ) {
209	var i,
210		cases = [
211			{ dimensions: null, expected: false, msg: 'Null' },
212			{ dimensions: { width: 200 }, expected: true, msg: 'Only width' },
213			{ dimensions: { height: 200 }, expected: true, msg: 'Only height' },
214			{ dimensions: {}, expected: false, msg: 'Empty object' },
215			{ dimensions: { width: undefined, height: undefined }, expected: false, msg: 'Explicity undefined' }
216		];
217
218	for ( i = 0; i < cases.length; i++ ) {
219		assert.strictEqual( ve.dm.Scalable.static.isDimensionsObjectValid( cases[ i ].dimensions ), cases[ i ].expected, cases[ i ].msg );
220	}
221} );
222
223QUnit.test( 'getDimensionsFromValue', function ( assert ) {
224	var i,
225		cases = [
226			{ dimensions: { width: 200 }, ratio: 1, expected: { width: 200, height: 200 }, msg: 'Only width' },
227			{ dimensions: { height: 200 }, ratio: 2, expected: { width: 400, height: 200 }, msg: 'Only height' },
228			{ dimensions: { width: '', height: 400 }, ratio: 0.5, expected: { width: 200, height: 400 }, msg: 'Empty width' },
229			{ dimensions: { width: 200, height: '' }, ratio: 0.5, expected: { width: 200, height: 400 }, msg: 'Empty height' }
230		];
231
232	for ( i = 0; i < cases.length; i++ ) {
233		assert.deepEqual( ve.dm.Scalable.static.getDimensionsFromValue( cases[ i ].dimensions, cases[ i ].ratio ), cases[ i ].expected, cases[ i ].msg );
234	}
235} );
236
Full Screen

animation-presets.js

Source: animation-presets.js Github

copy
1/**
2 * Copyright 2017 The AMP HTML Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS-IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {GRID_LAYER_TEMPLATE_CLASS_NAMES} from './amp-story-grid-layer';
18import {StoryAnimationPresetDef} from './animation-types';
19import {
20  calculateTargetScalingFactor,
21  rotateAndTranslate,
22  scaleAndTranslate,
23  translate2d,
24  whooshIn,
25} from './animation-presets-utils';
26import {px} from '../../../src/style';
27
28const FULL_BLEED_CATEGORY = 'full-bleed';
29const FILL_TEMPLATE_LAYOUT = 'fill';
30
31/**
32 * A list of animations that are full bleed.
33 * @private @const {!Array<string>}
34 */
35const FULL_BLEED_ANIMATION_NAMES = [
36  'pan-up',
37  'pan-down',
38  'pan-right',
39  'pan-left',
40  'zoom-in',
41  'zoom-out',
42];
43
44/**
45 * A mapping of animation categories to corresponding CSS class names.
46 * @private @const {!Object<string, string>}
47 */
48const ANIMATION_CSS_CLASS_NAMES = {
49  [FULL_BLEED_CATEGORY]:
50      'i-amphtml-story-grid-template-with-full-bleed-animation',
51};
52
53/**
54 * Perform style-specific operations for presets.
55 * @param {!Element} el
56 * @param {string} presetName
57 */
58export function setStyleForPreset(el, presetName) {
59  // For full bleed animations.
60  if (FULL_BLEED_ANIMATION_NAMES.indexOf(presetName) >= 0) {
61    const parent = el.parentElement;
62    if (parent.classList.contains(
63        GRID_LAYER_TEMPLATE_CLASS_NAMES[FILL_TEMPLATE_LAYOUT])) {
64      parent.classList
65          .remove(GRID_LAYER_TEMPLATE_CLASS_NAMES[FILL_TEMPLATE_LAYOUT]);
66    }
67    parent.classList.add(ANIMATION_CSS_CLASS_NAMES[FULL_BLEED_CATEGORY]);
68  }
69}
70
71/** @const {!Object<string, !StoryAnimationPresetDef>} */
72// First keyframe will always be considered offset: 0 and will be applied to the
73// element as the first frame before animation starts.
74export const PRESETS = {
75  'pulse': {
76    duration: 500,
77    easing: 'linear',
78    keyframes: [
79      {
80        offset: 0,
81        transform: 'scale(1)',
82      },
83      {
84        offset: 0.25,
85        transform: 'scale(0.95)',
86      },
87      {
88        offset: 0.75,
89        transform: 'scale(1.05)',
90      },
91      {
92        offset: 1,
93        transform: 'scale(1)',
94      },
95    ],
96  },
97  'fly-in-left': {
98    duration: 500,
99    easing: 'ease-out',
100    keyframes(dimensions) {
101      const offsetX = -(dimensions.targetX + dimensions.targetWidth);
102      return translate2d(offsetX, 0, 0, 0);
103    },
104  },
105  'fly-in-right': {
106    duration: 500,
107    easing: 'ease-out',
108    keyframes(dimensions) {
109      const offsetX = dimensions.pageWidth - dimensions.targetX;
110      return translate2d(offsetX, 0, 0, 0);
111    },
112  },
113  'fly-in-top': {
114    duration: 500,
115    easing: 'ease-out',
116    keyframes(dimensions) {
117      const offsetY = -(dimensions.targetY + dimensions.targetHeight);
118      return translate2d(0, offsetY, 0, 0);
119    },
120  },
121  'fly-in-bottom': {
122    duration: 500,
123    easing: 'ease-out',
124    keyframes(dimensions) {
125      const offsetY = dimensions.pageHeight - dimensions.targetY;
126      return translate2d(0, offsetY, 0, 0);
127    },
128  },
129  'rotate-in-left': {
130    duration: 700,
131    easing: 'ease-out',
132    keyframes(dimensions) {
133      const offsetX = -(dimensions.targetX + dimensions.targetWidth);
134      return rotateAndTranslate(offsetX, 0, 0, 0, -1);
135    },
136  },
137  'rotate-in-right': {
138    duration: 700,
139    easing: 'ease-out',
140    keyframes(dimensions) {
141      const offsetX = dimensions.pageWidth - dimensions.targetX;
142      return rotateAndTranslate(offsetX, 0, 0, 0, 1);
143    },
144  },
145  'fade-in': {
146    duration: 500,
147    easing: 'ease-out',
148    keyframes: [
149      {
150        opacity: 0,
151      },
152      {
153        opacity: 1,
154      },
155    ],
156  },
157  'drop': {
158    duration: 1600,
159    keyframes(dimensions) {
160      const maxBounceHeight =
161          Math.max(160, dimensions.targetY + dimensions.targetHeight);
162
163      return [
164        {
165          offset: 0,
166          transform: `translateY(${px(-maxBounceHeight)})`,
167          easing: 'cubic-bezier(.75,.05,.86,.08)',
168        },
169        {
170          offset: 0.3,
171          transform: 'translateY(0)',
172          easing: 'cubic-bezier(.22,.61,.35,1)',
173        },
174        {
175          offset: 0.52,
176          transform: `translateY(${px(-0.6 * maxBounceHeight)})`,
177          easing: 'cubic-bezier(.75,.05,.86,.08)',
178        },
179        {
180          offset: 0.74,
181          transform: 'translateY(0)',
182          easing: 'cubic-bezier(.22,.61,.35,1)',
183        },
184        {
185          offset: 0.83,
186          transform: `translateY(${px(-0.3 * maxBounceHeight)})`,
187          easing: 'cubic-bezier(.75,.05,.86,.08)',
188        },
189        {
190          offset: 1,
191          transform: 'translateY(0)',
192          easing: 'cubic-bezier(.22,.61,.35,1)',
193        },
194      ];
195    },
196  },
197  'twirl-in': {
198    duration: 1000,
199    easing: 'cubic-bezier(.2,.75,.4,1)',
200    keyframes: [
201      {
202        transform: 'rotate(-540deg) scale(0.1)',
203        opacity: 0,
204      },
205      {
206        transform: 'none',
207        opacity: 1,
208      },
209    ],
210  },
211  'whoosh-in-left': {
212    duration: 500,
213    easing: 'ease-out',
214    keyframes(dimensions) {
215      const offsetX = -(dimensions.targetX + dimensions.targetWidth);
216      return whooshIn(offsetX, 0, 0, 0);
217    },
218  },
219  'whoosh-in-right': {
220    duration: 500,
221    easing: 'ease-out',
222    keyframes(dimensions) {
223      const offsetX = dimensions.pageWidth - dimensions.targetX;
224      return whooshIn(offsetX, 0, 0, 0);
225    },
226  },
227  'pan-left': {
228    duration: 1000,
229    easing: 'linear',
230    keyframes(dimensions) {
231      const scalingFactor = calculateTargetScalingFactor(dimensions);
232      dimensions.targetWidth *= scalingFactor;
233      dimensions.targetHeight *= scalingFactor;
234
235      const offsetX = dimensions.pageWidth - dimensions.targetWidth;
236      const offsetY = (dimensions.pageHeight - dimensions.targetHeight) / 2;
237
238      return scaleAndTranslate(offsetX, offsetY, 0, offsetY, scalingFactor);
239    },
240  },
241  'pan-right': {
242    duration: 1000,
243    easing: 'linear',
244    keyframes(dimensions) {
245      const scalingFactor = calculateTargetScalingFactor(dimensions);
246      dimensions.targetWidth *= scalingFactor;
247      dimensions.targetHeight *= scalingFactor;
248
249      const offsetX = dimensions.pageWidth - dimensions.targetWidth;
250      const offsetY = (dimensions.pageHeight - dimensions.targetHeight) / 2;
251
252      return scaleAndTranslate(0, offsetY, offsetX, offsetY, scalingFactor);
253    },
254  },
255  'pan-down': {
256    duration: 1000,
257    easing: 'linear',
258    keyframes(dimensions) {
259      const scalingFactor = calculateTargetScalingFactor(dimensions);
260      dimensions.targetWidth *= scalingFactor;
261      dimensions.targetHeight *= scalingFactor;
262
263      const offsetX = -dimensions.targetWidth / 2;
264      const offsetY = dimensions.pageHeight - dimensions.targetHeight;
265
266      return scaleAndTranslate(offsetX, 0, offsetX, offsetY, scalingFactor);
267    },
268  },
269  'pan-up': {
270    duration: 1000,
271    easing: 'linear',
272    keyframes(dimensions) {
273      const scalingFactor = calculateTargetScalingFactor(dimensions);
274      dimensions.targetWidth *= scalingFactor;
275      dimensions.targetHeight *= scalingFactor;
276
277      const offsetX = -dimensions.targetWidth / 2;
278      const offsetY = dimensions.pageHeight - dimensions.targetHeight;
279
280      return scaleAndTranslate(offsetX, offsetY, offsetX, 0, scalingFactor);
281    },
282  },
283  'zoom-in': {
284    duration: 1000,
285    easing: 'linear',
286    keyframes: [
287      {transform: 'scale(1,1)'},
288      {transform: 'scale(3,3)'},
289    ],
290  },
291  'zoom-out': {
292    duration: 1000,
293    easing: 'linear',
294    keyframes: [
295      {transform: 'scale(3,3)'},
296      {transform: 'scale(1,1)'},
297    ],
298  },
299};
300
Full Screen

Div.js

Source: Div.js Github

copy
1/*
2  Contains helper functions for dealing with divs:
3    - Is a position inside the div?
4    - Get a random position within the div
5    - ???
6
7  TODO layout could probably be improved here
8*/
9
10class Div {
11  // static helper functions
12  // rectangular
13  static dimensionsOf ($div) {
14    // note ... expects a JQuery object, if it's not, this'll error
15    return {
16      xP     : $div.offset ().left,
17      yP     : $div.offset ().top,
18      width  : $div.outerWidth (),
19      height : $div.outerHeight ()
20    };
21  }
22
23  static intersects (x, y, div) {
24    var dimensions = Div.dimensionsOf (div);
25    return (x >= dimensions.xP && x <= dimensions.xP + dimensions.width)
26          && (y >= dimensions.yP && y <= dimensions.yP + dimensions.height);
27  }
28
29  static randomPositionWithin (div) {
30    var dimensions = this.dimensionsOf (div);
31    return {
32      left: ODSRandom.getRandomIntInclusive (dimensions.xP, dimensions.xP + dimensions.width),
33      top: ODSRandom.getRandomIntInclusive (dimensions.yP, dimensions.yP + dimensions.height)
34    }
35  }
36
37  // round
38  static dimensionsOfRound (div) {
39  	var dimensions = Div.dimensionsOf (div);
40  	return {
41  		xP: dimensions.xP + dimensions.width/2,
42  		yP: dimensions.yP + dimensions.height/2,
43  		rx: dimensions.width / 2,
44  		ry: dimensions.height / 2
45  	};
46  }
47
48  static intersectsRound (x, y, div) {
49    var dimensions = Div.dimensionsOfRound (div);
50
51    var xp = ( (x - dimensions.xP) * (x - dimensions.xP) ) / (dimensions.rx * dimensions.rx);
52    var yp = ( (y - dimensions.yP) * (y - dimensions.yP) ) / (dimensions.ry * dimensions.ry);
53
54    return xp + yp <= 1;
55  }
56
57  static randomPositionWithinRound (div) {
58    // https://stackoverflow.com/questions/5529148/algorithm-calculate-pseudo-random-point-inside-an-ellipse
59    var dimensions = this.dimensionsOfRound (div);
60    var phi        = ODSRandom.getRandomMinMax (0, 2 * Math.PI);
61    var rho        = ODSRandom.getRandom ();
62    var rhosqrt    = Math.sqrt (rho);
63
64    var x          = rhosqrt * Math.cos (phi);
65    var y          = rhosqrt * Math.sin (phi);
66
67    // TODO: Change 50. Make it an option or something.
68    // For now, just an offset so it doesn't go on the border of the ellipse
69    return {
70      left: (x * (dimensions.rx - 50)) + dimensions.xP,
71      top: (y * (dimensions.ry - 50)) + dimensions.yP
72    };
73  }
74
75  static positionFromPercentage (div, percentage) {
76    var dimensions = this.dimensionsOf (div);
77    var xOs        = dimensions.width * percentage.x;
78    var yOs        = dimensions.height * percentage.y;
79
80    return {
81      top : yOs + dimensions.yP,
82      left : xOs + dimensions.xP
83    }
84  };
85
86  static fromOffset (div, offset){
87    var dimensions = this.dimensionsOf (div);
88    return {
89      top: dimensions.yP + offset.top,
90      left: dimensions.xP + offset.left
91    }
92  }
93
94  /* methods */
95  constructor (div) {
96    this.myDiv = div;
97    this.$div  = $(div);
98
99    this.originalData = Div.dimensionsOf (this.$div);
100    this.proportionRatio = parseInt (this.originalData.height) /
101                           parseInt (this.originalData.width);
102  }
103
104  getDimensions () {
105    if (this.$div.hasClass ("round"))
106      return Div.dimensionsOfRound (this.myDiv);
107    return Div.dimensionsOf (this.myDiv);
108  }
109
110  intersects (x, y) {
111    if (this.$div.hasClass ("round"))
112      return Div.intersectsRound (x, y, this.myDiv);
113    return Div.intersects (x, y, this.myDiv);
114  }
115
116  randomPosition () {
117    if (this.$div.hasClass ("round"))
118      return Div.randomPositionWithinRound (this.myDiv);
119    return Div.randomPositionWithin (this.myDiv);
120  }
121
122  fromPercentage (p) {
123    return Div.positionFromPercentage (this.$div, p);
124  }
125
126  fromOffset (os) {
127    return Div.fromOffset(this.$div, os);
128  }
129
130
131  elementOver (element) {
132    var pos = $(element).offset ();
133    return this.intersects (pos.left, pos.top);
134  }
135
136  calcHeight (newWidth) {
137    if (!newWidth && newWidth !== 0)
138      newWidth = parseInt (Div.dimensionsOf (this.$div).width);
139    var newHeight = newWidth * this.proportionRatio;
140
141    return newHeight;
142  }
143
144  setHeight (h) {
145    this.$div.height (h);
146    this.calcHeight ();
147  }
148
149  fixHeight () {
150    this.$div.css ("height", this.calcHeight ());
151  }
152
153  storePosition (element) {
154    var divPos = Div.dimensionsOf (element);
155    var myDims = Div.dimensionsOf (this.$div);
156
157    // store %width, %height
158    var pWidth  = (divPos.xP - myDims.xP) / myDims.width;
159    var pHeight = (divPos.yP - myDims.yP) / myDims.height;
160
161    element.data ("%width", pWidth);
162    element.data ("%height", pHeight);
163  }
164
165  fixPosition (element) {
166    var pX = element.data ("%width");
167    var pY = element.data ("%height");
168
169    var myDimensions = Div.dimensionsOf (this.$div);
170
171    var newX = pX * myDimensions.width + myDimensions.xP;
172    var newY = pY * myDimensions.height + myDimensions.yP;
173
174    element.css ({top: newY, left: newX});
175  }
176
177  storePositions (elements) {
178    for (var e in elements)
179      this.storePosition (elements [e]);
180  }
181
182  fixPositions (elements) {
183    // If we store % of width, % of height ... then we can reset that ...
184    for (var e in elements)
185      this.fixPosition (elements [e]);
186  }
187}
188
Full Screen

hlsl.getdimensions.dx10.frag

Source: hlsl.getdimensions.dx10.frag Github

copy
1SamplerState       g_sSamp : register(s0);
2
3uniform Texture1D <float4> g_tTex1df4 : register(t0);
4Texture1D <int4>   g_tTex1di4;
5Texture1D <uint4>  g_tTex1du4;
6
7Texture2D <float4> g_tTex2df4;
8Texture2D <int4>   g_tTex2di4;
9Texture2D <uint4>  g_tTex2du4;
10
11Texture3D <float4> g_tTex3df4;
12Texture3D <int4>   g_tTex3di4;
13Texture3D <uint4>  g_tTex3du4;
14
15TextureCube <float4> g_tTexcdf4;
16TextureCube <int4>   g_tTexcdi4;
17TextureCube <uint4>  g_tTexcdu4;
18
19Texture1DArray <float4> g_tTex1df4a;
20Texture1DArray <int4>   g_tTex1di4a;
21Texture1DArray <uint4>  g_tTex1du4a;
22
23Texture2DArray <float4> g_tTex2df4a;
24Texture2DArray <int4>   g_tTex2di4a;
25Texture2DArray <uint4>  g_tTex2du4a;
26
27TextureCubeArray <float4> g_tTexcdf4a;
28TextureCubeArray <int4>   g_tTexcdi4a;
29TextureCubeArray <uint4>  g_tTexcdu4a;
30
31Texture2DMS <float4> g_tTex2dmsf4;
32Texture2DMS <int4>   g_tTex2dmsi4;
33Texture2DMS <uint4>  g_tTex2dmsu4;
34
35Texture2DMSArray <float4> g_tTex2dmsf4a;
36Texture2DMSArray <int4>   g_tTex2dmsi4a;
37Texture2DMSArray <uint4>  g_tTex2dmsu4a;
38
39struct PS_OUTPUT
40{
41    float4 Color : SV_Target0;
42    float  Depth : SV_Depth;
43};
44
45PS_OUTPUT main()
46{
47   PS_OUTPUT psout;
48
49   uint MipLevel;
50   uint WidthU;
51   uint HeightU;
52   uint ElementsU;
53   uint DepthU;
54   uint NumberOfLevelsU;
55   uint NumberOfSamplesU;
56
57   float WidthF;
58   float HeightF;
59   float ElementsF;
60   float DepthF;
61   float NumberOfLevelsF;
62   float NumberOfSamplesF;
63
64   // 1D, float tx, uint params
65   g_tTex1df4 . GetDimensions(WidthU);
66   g_tTex1df4 . GetDimensions(6, WidthU, NumberOfLevelsU);
67
68   // 1D, int, uint params
69   g_tTex1di4 . GetDimensions(WidthU);
70   g_tTex1di4 . GetDimensions(6, WidthU, NumberOfLevelsU);
71
72   // 1D, uint, uint params
73   g_tTex1du4 . GetDimensions(WidthU);
74   g_tTex1du4 . GetDimensions(6, WidthU, NumberOfLevelsU);
75
76   // 1DArray, float tx, uint params
77   g_tTex1df4a . GetDimensions(WidthU, ElementsU);
78   g_tTex1df4a . GetDimensions(6, WidthU, ElementsU, NumberOfLevelsU);
79
80   // 1DArray, int, uint params
81   g_tTex1di4a . GetDimensions(WidthU, ElementsU);
82   g_tTex1di4a . GetDimensions(6, WidthU, ElementsU, NumberOfLevelsU);
83
84   // 1DArray, uint, uint params
85   g_tTex1du4a . GetDimensions(WidthU, ElementsU);
86   g_tTex1du4a . GetDimensions(6, WidthU, ElementsU, NumberOfLevelsU);
87
88   // 2D, float tx, uint params
89   g_tTex2df4 . GetDimensions(WidthU, HeightU);
90   g_tTex2df4 . GetDimensions(6, WidthU, HeightU, NumberOfLevelsU);
91
92   // 2D, int, uint params
93   g_tTex2di4 . GetDimensions(WidthU, HeightU);
94   g_tTex2di4 . GetDimensions(6, WidthU, HeightU, NumberOfLevelsU);
95
96   // 2D, uint, uint params
97   g_tTex2du4 . GetDimensions(WidthU, HeightU);
98   g_tTex2du4 . GetDimensions(6, WidthU, HeightU, NumberOfLevelsU);
99
100   // 2Darray, float tx, uint params
101   g_tTex2df4a . GetDimensions(WidthU, HeightU, ElementsU);
102   g_tTex2df4a . GetDimensions(6, WidthU, HeightU, ElementsU, NumberOfLevelsU);
103
104   // 2Darray, int, uint params
105   g_tTex2di4a . GetDimensions(WidthU, HeightU, ElementsU);
106   g_tTex2di4a . GetDimensions(6, WidthU, HeightU, ElementsU, NumberOfLevelsU);
107
108   // 2Darray, uint, uint params
109   g_tTex2du4a . GetDimensions(WidthU, HeightU, ElementsU);
110   g_tTex2du4a . GetDimensions(6, WidthU, HeightU, ElementsU, NumberOfLevelsU);
111
112   // 3D, float tx, uint params
113   g_tTex3df4 . GetDimensions(WidthU, HeightU, DepthU);
114   g_tTex3df4 . GetDimensions(6, WidthU, HeightU, DepthU, NumberOfLevelsU);
115
116   // 3D, int, uint params
117   g_tTex3di4 . GetDimensions(WidthU, HeightU, DepthU);
118   g_tTex3di4 . GetDimensions(6, WidthU, HeightU, DepthU, NumberOfLevelsU);
119
120   // 3D, uint, uint params
121   g_tTex3du4 . GetDimensions(WidthU, HeightU, DepthU);
122   g_tTex3du4 . GetDimensions(6, WidthU, HeightU, DepthU, NumberOfLevelsU);
123
124   // Cube, float tx, uint params
125   g_tTexcdf4 . GetDimensions(WidthU, HeightU);
126   g_tTexcdf4 . GetDimensions(6, WidthU, HeightU, NumberOfLevelsU);
127
128   // Cube, int, uint params
129   g_tTexcdi4 . GetDimensions(WidthU, HeightU);
130   g_tTexcdi4 . GetDimensions(6, WidthU, HeightU, NumberOfLevelsU);
131
132   // Cube, uint, uint params
133   g_tTexcdu4 . GetDimensions(WidthU, HeightU);
134   g_tTexcdu4 . GetDimensions(6, WidthU, HeightU, NumberOfLevelsU);
135
136   // Cubearray, float tx, uint params
137   g_tTexcdf4a . GetDimensions(WidthU, HeightU, ElementsU);
138   g_tTexcdf4a . GetDimensions(6, WidthU, HeightU, ElementsU, NumberOfLevelsU);
139
140   // Cubearray, int, uint params
141   g_tTexcdi4a . GetDimensions(WidthU, HeightU, ElementsU);
142   g_tTexcdi4a . GetDimensions(6, WidthU, HeightU, ElementsU, NumberOfLevelsU);
143
144   // Cubearray, uint, uint params
145   g_tTexcdu4a . GetDimensions(WidthU, HeightU, ElementsU);
146   g_tTexcdu4a . GetDimensions(6, WidthU, HeightU, ElementsU, NumberOfLevelsU);
147
148   // 2DMS, float tx, uint params
149   g_tTex2dmsf4 . GetDimensions(WidthU, HeightU, NumberOfSamplesU);
150
151   // 2DMS, int tx, uint params
152   g_tTex2dmsi4 . GetDimensions(WidthU, HeightU, NumberOfSamplesU);
153
154   // 2DMS, uint tx, uint params
155   g_tTex2dmsu4 . GetDimensions(WidthU, HeightU, NumberOfSamplesU);
156
157   // 2DMSArray, float tx, uint params
158   g_tTex2dmsf4a . GetDimensions(WidthU, HeightU, ElementsU, NumberOfSamplesU);
159
160   // 2DMSArray, int tx, uint params
161   g_tTex2dmsi4a . GetDimensions(WidthU, HeightU, ElementsU, NumberOfSamplesU);
162
163   // 2DMSArray, uint tx, uint params
164   g_tTex2dmsu4a . GetDimensions(WidthU, HeightU, ElementsU, NumberOfSamplesU);
165
166   // TODO: ***************************************************
167   // Change this to 1 to enable float overloads when the HLSL
168   // function overload resolution is fixed.
169#define OVERLOAD_FIX 0
170
171   // TODO: enable when function overload resolution rules are fixed
172#if OVERLOAD_FIX
173   // 1D, float tx, float params
174   g_tTex1df4 . GetDimensions(WidthF);
175   g_tTex1df4 . GetDimensions(6, WidthF, NumberOfLevelsF);
176
177   // 1D, int, float params
178   g_tTex1di4 . GetDimensions(WidthF);
179   g_tTex1di4 . GetDimensions(6, WidthF, NumberOfLevelsF);
180
181   // 1D, uint, float params
182   g_tTex1du4 . GetDimensions(WidthF);
183   g_tTex1du4 . GetDimensions(6, WidthF, NumberOfLevelsF);
184
185   // 1DArray, float tx, float params
186   g_tTex1df4a . GetDimensions(WidthF, ElementsF);
187   g_tTex1df4a . GetDimensions(6, WidthF, ElementsF, NumberOfLevelsF);
188
189   // 1DArray, int, float params
190   g_tTex1di4a . GetDimensions(WidthF, ElementsF);
191   g_tTex1di4a . GetDimensions(6, WidthF, ElementsF, NumberOfLevelsF);
192
193   // 1DArray, uint, float params
194   g_tTex1du4a . GetDimensions(WidthF, ElementsF);
195   g_tTex1du4a . GetDimensions(6, WidthF, ElementsF, NumberOfLevelsF);
196
197   // 2D, float tx, float params
198   g_tTex2df4 . GetDimensions(WidthF, HeightF);
199   g_tTex2df4 . GetDimensions(6, WidthF, HeightF, NumberOfLevelsF);
200
201   // 2D, int, float params
202   g_tTex2di4 . GetDimensions(WidthF, HeightF);
203   g_tTex2di4 . GetDimensions(6, WidthF, HeightF, NumberOfLevelsF);
204
205   // 2D, uint, float params
206   g_tTex2du4 . GetDimensions(WidthF, HeightF);
207   g_tTex2du4 . GetDimensions(6, WidthF, HeightF, NumberOfLevelsF);
208
209   // 2Darray, float tx, float params
210   g_tTex2df4a . GetDimensions(WidthF, HeightF, ElementsF);
211   g_tTex2df4a . GetDimensions(6, WidthF, HeightF, ElementsF, NumberOfLevelsF);
212
213   // 2Darray, int, float params
214   g_tTex2di4a . GetDimensions(WidthF, HeightF, ElementsF);
215   g_tTex2di4a . GetDimensions(6, WidthF, HeightF, ElementsF, NumberOfLevelsF);
216
217   // 2Darray, uint, float params
218   g_tTex2du4a . GetDimensions(WidthF, HeightF, ElementsF);
219   g_tTex2du4a . GetDimensions(6, WidthF, HeightF, ElementsF, NumberOfLevelsF);
220
221   // 3D, float tx, float params
222   g_tTex3df4 . GetDimensions(WidthF, HeightF, DepthF);
223   g_tTex3df4 . GetDimensions(6, WidthF, HeightF, DepthF, NumberOfLevelsF);
224
225   // 3D, int, float params
226   g_tTex3di4 . GetDimensions(WidthF, HeightF, DepthF);
227   g_tTex3di4 . GetDimensions(6, WidthF, HeightF, DepthF, NumberOfLevelsF);
228
229   // 3D, uint, float params
230   g_tTex3du4 . GetDimensions(WidthF, HeightF, DepthF);
231   g_tTex3du4 . GetDimensions(6, WidthF, HeightF, DepthF, NumberOfLevelsF);
232
233   // Cube, float tx, float params
234   g_tTexcdf4 . GetDimensions(WidthF, HeightF);
235   g_tTexcdf4 . GetDimensions(6, WidthF, HeightF, NumberOfLevelsF);
236
237   // Cube, int, float params
238   g_tTexcdi4 . GetDimensions(WidthF, HeightF);
239   g_tTexcdi4 . GetDimensions(6, WidthF, HeightF, NumberOfLevelsF);
240
241   // Cube, uint, float params
242   g_tTexcdu4 . GetDimensions(WidthF, HeightF);
243   g_tTexcdu4 . GetDimensions(6, WidthF, HeightF, NumberOfLevelsF);
244
245   // Cubearray, float tx, float params
246   g_tTexcdf4a . GetDimensions(WidthF, HeightF, ElementsF);
247   g_tTexcdf4a . GetDimensions(6, WidthF, HeightF, ElementsF, NumberOfLevelsF);
248
249   // Cubearray, int, float params
250   g_tTexcdi4a . GetDimensions(WidthF, HeightF, ElementsF);
251   g_tTexcdi4a . GetDimensions(6, WidthF, HeightF, ElementsF, NumberOfLevelsF);
252
253   // Cubearray, uint, float params
254   g_tTexcdu4a . GetDimensions(WidthF, HeightF, ElementsF);
255   g_tTexcdu4a . GetDimensions(6, WidthF, HeightF, ElementsF, NumberOfLevelsF);
256
257   // 2DMS, float tx, uint params
258   g_tTex2dmsf4 . GetDimensions(WidthF, HeightF, NumberOfSamplesF);
259
260   // 2DMS, int tx, uint params
261   g_tTex2dmsi4 . GetDimensions(WidthF, HeightF, NumberOfSamplesF);
262
263   // 2DMS, uint tx, uint params
264   g_tTex2dmsu4 . GetDimensions(WidthF, HeightF, NumberOfSamplesF);
265
266   // 2DMSArray, float tx, uint params
267   g_tTex2dmsf4a . GetDimensions(WidthF, HeightF, ElementsF, NumberOfSamplesF);
268
269   // 2DMSArray, int tx, uint params
270   g_tTex2dmsi4a . GetDimensions(WidthF, HeightF, ElementsF, NumberOfSamplesF);
271
272   // 2DMSArray, uint tx, uint params
273   g_tTex2dmsu4a . GetDimensions(WidthF, HeightF, ElementsF, NumberOfSamplesF);
274#endif // OVERLOAD_FIX
275
276   psout.Color = 1.0;
277   psout.Depth = 1.0;
278
279   return psout;
280}
281
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)