/**
 * Slidotron 9x16 - Vertical Slider Composition Generator for Adobe After Effects
 *
 * Creates professional 9:16 vertical slider compositions for mobile and social media.
 * Optimized for Instagram Stories, TikTok, and other vertical video formats with
 * expression-controlled horizontal sliding animations.
 *
 * @name Slidotron_9x16
 * @author IVG Design
 * @version 2.0.2
 * @date 2026-07-04
 * @license MIT
 * @ui HEADLESS
 * 
 * @description
 * Slidotron 9x16 generates a complete vertical slider system optimized for mobile
 * and social media platforms. The script creates a nested composition structure
 * with animated masks that reveal content horizontally within a vertical frame,
 * perfect for Instagram Stories, TikTok, and similar vertical video formats.
 * 
 * @functionality
 * • Creates two nested compositions: "Sliders 9x16" and "Slide 9x16"
 * • Generates animated mask layers for left and right slide transitions
 * • Adds expression-driven slider control for seamless horizontal animation
 * • Sets up track matte relationships for proper content masking
 * • Configures parent-child relationships for coordinated movement
 * • Optimizes composition settings for vertical mobile output (1080x1920)
 * 
 * @usage
 * 1. Select an existing composition in your project
 * 2. Run the script - no user interface required
 * 3. The script creates "Sliders 9x16" and "Slide 9x16" compositions
 * 4. Use the CTRL slider effect on the main layer to animate transitions
 * 5. Add content to the "Slide 9x16" composition for your slides
 * 6. Adjust slider values from 0-100 to control transition position
 * 
 * @requirements
 * • Adobe After Effects 23.0 (2023) or later — the rig is wired with the
 *   AVLayer.setTrackMatte() scripting API, which was introduced in AE 23.0.
 *   On earlier versions (CS6 through 22.6) that method does not exist; the
 *   script now detects this and exits cleanly with an explanatory message.
 * • An existing composition must be selected in the project panel
 * • Sufficient memory for vertical HD composition handling
 * 
 * @notes
 * • Output resolution is 1080x1920 at 60fps for smooth mobile playback
 * • Slider control uses linear interpolation for smooth transitions
 * • Mask layers are disabled by default to prevent visual interference
 * • Expression references specific composition names - avoid renaming
 * • Optimized for vertical viewing on mobile devices and social platforms
 * • Background color is set to dark gray (38, 38, 38) for professional look
 *
 * @changelog
 * - 2.0.2 (2026-07-04): Corrected the @requirements version claim to After Effects 23.0 (2023) or later, since the rig relies on AVLayer.setTrackMatte() (introduced in AE 23.0). Added a runtime version guard that exits cleanly with an explanatory alert on pre-23.0 hosts instead of throwing a cryptic TypeError and leaving the undo group open.
 * - 2.0.1 (2026-06-02): Removed an ECMA 3-incompatible trailing comma and replaced hard-coded comp-name expression references with the selected comp name.
 * - 2.0.0 (2025-08-13): Renamed and documented during repository standardization.
 */

// Originally created using compCode v1.2.2


try {
	app.beginUndoGroup("Slidotron 9x16");
	compCode_20230624_201440();
	app.endUndoGroup();
} catch (error) {
	alert(error.toString() +
		"\nScript file: " + File.decode(error.fileName).replace(/^.*[\|\/]/, "") +
		"\nError on line: " + error.line
	);
}

function compCode_20230624_201440() {

	var tempStartingComp = app.project.activeItem;
	if (!tempStartingComp || !(tempStartingComp instanceof CompItem)) {
		alert("Please select a composition first");
		return;
	}

	// This rig is wired with AVLayer.setTrackMatte(), which only exists in
	// After Effects 23.0 (2023) and later. Bail out cleanly on older hosts
	// rather than throwing a cryptic "setTrackMatte is not a function" error.
	if (parseFloat(app.version) < 23) {
		alert("Slidotron 9x16 requires After Effects 23.0 (2023) or later.\n" +
			"It uses the AVLayer.setTrackMatte() API, which is unavailable in your version (" + app.version + ").");
		return;
	}

	// CREATE COMPOSITIONS START
	var bookTutorialShort9x16_comp = tempStartingComp;
	var sliders9x16_comp_properties = { "name": "Sliders 9x16", "label": 13, "comment": "", "height": 1920, "width": 1080, "pixelAspect": 1, "bgColor": [0.14901960784314, 0.14901960784314, 0.14901960784314], "duration": 2100, "numLayers": 4, "frameRate": 60, "itemIsCompItem": { "type": "function", "arguments": ["item"], "body": "return item instanceof CompItem;" } };
	var sliders9x16_comp = app.project.items.addComp(sliders9x16_comp_properties.name, sliders9x16_comp_properties.width, sliders9x16_comp_properties.height, sliders9x16_comp_properties.pixelAspect, sliders9x16_comp_properties.duration, sliders9x16_comp_properties.frameRate);
	sliders9x16_comp.time = 0.96666666666667;
	sliders9x16_comp.bgColor = sliders9x16_comp_properties.bgColor;
	sliders9x16_comp.motionBlurAdaptiveSampleLimit = 90;
	sliders9x16_comp.resolutionFactor = [1, 1];
	var slide9x16_comp_properties = { "name": "Slide 9x16", "label": 13, "comment": "", "height": 1920, "width": 1080, "pixelAspect": 1, "bgColor": [0.14901960784314, 0.14901960784314, 0.14901960784314], "duration": 2100, "numLayers": 0, "frameRate": 60, "itemIsCompItem": { "type": "function", "arguments": ["item"], "body": "return item instanceof CompItem;" } };
	var slide9x16_comp = app.project.items.addComp(slide9x16_comp_properties.name, slide9x16_comp_properties.width, slide9x16_comp_properties.height, slide9x16_comp_properties.pixelAspect, slide9x16_comp_properties.duration, slide9x16_comp_properties.frameRate);
	slide9x16_comp.time = 0.96666666666667;
	slide9x16_comp.bgColor = slide9x16_comp_properties.bgColor;
	slide9x16_comp.motionBlurAdaptiveSampleLimit = 90;
	slide9x16_comp.resolutionFactor = [1, 1];
	// CREATE COMPOSITIONS END

	// Working with comp "Book Tutorial Short 9x16", varName "bookTutorialShort9x16_comp";
	bookTutorialShort9x16_comp.openInViewer();
	// Add existing composition "Sliders 9x16", varName "sliders9x16_comp";
	var sliders9x16 = bookTutorialShort9x16_comp.layers.add(sliders9x16_comp);
	sliders9x16.property("ADBE Effect Parade").addProperty("ADBE Slider Control");
	sliders9x16.property("ADBE Effect Parade").property(1).name = "CTRL";
	sliders9x16.property("ADBE Effect Parade").property(1).property("ADBE Slider Control-0001").setValue(100);
	sliders9x16.selected = false;


	// Apply hidden values

	// Working with comp "Sliders 9x16", varName "sliders9x16_comp";
	// Add Shape Layer "Mask L", varName "maskL";
	var maskL = sliders9x16_comp.layers.addShape();
	maskL.name = "Mask L";
	maskL.enabled = false;
	maskL.moveToEnd();
	maskL.property("ADBE Root Vectors Group").addProperty("ADBE Vector Group");
	maskL.property("ADBE Root Vectors Group").property(1).name = "Rectangle 1";
	maskL.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Shape - Rect");
	maskL.property("ADBE Root Vectors Group").property(1).property(2).property(1).name = "Rectangle Path 1";
	maskL.property("ADBE Root Vectors Group").property(1).property(2).property(1).property("ADBE Vector Rect Size").setValue([540, 1920]);
	maskL.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Graphic - Stroke");
	maskL.property("ADBE Root Vectors Group").property(1).property(2).property(2).name = "Stroke 1";
	maskL.property("ADBE Root Vectors Group").property(1).property(2).property(2).property("ADBE Vector Stroke Color").setValue([0.71372549019608, 0.30980392156863, 0.08627450980392, 1]);
	maskL.property("ADBE Root Vectors Group").property(1).property(2).property(2).property("ADBE Vector Stroke Width").setValue(0);
	maskL.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Graphic - Fill");
	maskL.property("ADBE Root Vectors Group").property(1).property(2).property(3).name = "Fill 1";
	maskL.property("ADBE Root Vectors Group").property(1).property(2).property(3).property("ADBE Vector Fill Color").setValue([0, 0, 0, 1]);
	maskL.property("ADBE Root Vectors Group").property(1).property(3).property("ADBE Vector Position").setValue([-282.207763671875, -11.171630859375]);
	maskL.property("ADBE Transform Group").property("ADBE Anchor Point").setValue([-552.207763671875, -11.171630859375, 0]);
	maskL.property("ADBE Transform Group").property("ADBE Position").dimensionsSeparated = true;
	maskL.property("ADBE Transform Group").property("ADBE Position_0").setValue(540);
	maskL.property("ADBE Transform Group").property("ADBE Scale").setValue([-100, 100, 100]);
	maskL.selected = false;
	// Add Shape Layer "Mask R", varName "maskR";
	var maskR = sliders9x16_comp.layers.addShape();
	maskR.name = "Mask R";
	maskR.enabled = false;
	maskR.moveToEnd();
	maskR.property("ADBE Root Vectors Group").addProperty("ADBE Vector Group");
	maskR.property("ADBE Root Vectors Group").property(1).name = "Rectangle 1";
	maskR.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Shape - Rect");
	maskR.property("ADBE Root Vectors Group").property(1).property(2).property(1).name = "Rectangle Path 1";
	maskR.property("ADBE Root Vectors Group").property(1).property(2).property(1).property("ADBE Vector Rect Size").setValue([540, 1920]);
	maskR.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Graphic - Stroke");
	maskR.property("ADBE Root Vectors Group").property(1).property(2).property(2).name = "Stroke 1";
	maskR.property("ADBE Root Vectors Group").property(1).property(2).property(2).property("ADBE Vector Stroke Color").setValue([0.71372549019608, 0.30980392156863, 0.08627450980392, 1]);
	maskR.property("ADBE Root Vectors Group").property(1).property(2).property(2).property("ADBE Vector Stroke Width").setValue(0);
	maskR.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Graphic - Fill");
	maskR.property("ADBE Root Vectors Group").property(1).property(2).property(3).name = "Fill 1";
	maskR.property("ADBE Root Vectors Group").property(1).property(2).property(3).property("ADBE Vector Fill Color").setValue([0, 0, 0, 1]);
	maskR.property("ADBE Root Vectors Group").property(1).property(3).property("ADBE Vector Position").setValue([-282.207763671875, -11.171630859375]);
	maskR.property("ADBE Transform Group").property("ADBE Anchor Point").setValue([-552.207763671875, -11.171630859375, 0]);
	maskR.property("ADBE Transform Group").property("ADBE Position").dimensionsSeparated = true;
	maskR.property("ADBE Transform Group").property("ADBE Position_0").setValue(540);
	maskR.selected = false;
	// Add existing composition "Slide 9x16", varName "slide9x16_comp";
	var slide9x16 = sliders9x16_comp.layers.add(slide9x16_comp);
	slide9x16.moveToEnd();
	slide9x16.setTrackMatte(maskL, TrackMatteType.ALPHA);
	slide9x16.selected = false;
	// Add existing composition "Slide 9x16", varName "slide9x16_comp";
	var slide9x17 = sliders9x16_comp.layers.add(slide9x16_comp);
	slide9x17.moveToEnd();
	slide9x17.setTrackMatte(maskR, TrackMatteType.ALPHA);
	slide9x17.selected = false;


	// Apply parents
	slide9x16.parent = maskL;
	slide9x17.parent = maskR;
	// Working with comp "Slide 9x16", varName "slide9x16_comp";


	// Apply hidden values



	// Apply expressions to properties
	var compExpressionName = bookTutorialShort9x16_comp.name.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
	maskL.property("ADBE Transform Group").property("ADBE Position_0").expression = "d = comp(\"" + compExpressionName + "\").layer(\"Sliders 9x16\").effect(\"CTRL\")(\"Slider\")\riMin = 0;\riMax = 100;\roMin = -5;\roMax = 540;\rlinear(d, iMin, iMax, oMin, oMax)";
	maskR.property("ADBE Transform Group").property("ADBE Position_0").expression = "d = comp(\"" + compExpressionName + "\").layer(\"Sliders 9x16\").effect(\"CTRL\")(\"Slider\")\riMin = 0;\riMax = 100;\roMin = 1085;\roMax = 540;\rlinear(d, iMin, iMax, oMin, oMax)";

	bookTutorialShort9x16_comp.openInViewer();

	return {
		compItem: bookTutorialShort9x16_comp
	};

}
