#target aftereffects
// FrameSafe Studio: Spotgate video templates for After Effects (https://framesafe.studio/en/templates).
// Run in After Effects (File > Scripts > Run Script File...). It adds a project folder with one
// composition per size; where the placement has a safe zone, a locked guide layer shows the area
// platform UI may cover (magenta, 35 %) and the safe area's outline. Guide layers don't render.
// Sizes and safe zones from the FrameSafe registry 0.2.10 (2026-11-17).
// Generated: edit apps/web/src/lib/aeTemplates.ts and run apps/web/scripts/photoshop-templates.ts, not this file.
var DATA = {"folder":"FrameSafe Spotgate video templates","fps":25,"duration":15,"text":{"folder":"video templates","layer":"FrameSafe safe zone (guide layer, not rendered)","covered":"Covered by platform UI","blocked":"Platform UI","safe":"Safe area","undo":"FrameSafe templates"},"comps":[{"name":"HD TV commercial 16x9 1920x1080","width":1920,"height":1080,"safe":[],"obstructions":[],"zone":null}]};
(function () {
  if (typeof app === "undefined" || !app.project) return;
  var MAGENTA = [1, 45 / 255, 160 / 255];

  function addPath(vectors, points) {
    var path = vectors.addProperty("ADBE Vector Shape - Group");
    var shape = new Shape();
    shape.vertices = points;
    shape.closed = true;
    path.property("ADBE Vector Shape").setValue(shape);
  }

  // One group: its paths, then a fill (even-odd, so the frame minus the safe areas) or a stroke.
  function addGroup(root, name, paths, paint, width) {
    var group = root.addProperty("ADBE Vector Group");
    group.name = name;
    var vectors = group.property("ADBE Vectors Group");
    for (var i = 0; i < paths.length; i++) addPath(vectors, paths[i]);
    if (paint === "fill") {
      var fill = vectors.addProperty("ADBE Vector Graphic - Fill");
      fill.property("ADBE Vector Fill Color").setValue(MAGENTA);
      fill.property("ADBE Vector Fill Opacity").setValue(35);
      fill.property("ADBE Vector Fill Rule").setValue(2);
    } else {
      var stroke = vectors.addProperty("ADBE Vector Graphic - Stroke");
      stroke.property("ADBE Vector Stroke Color").setValue(MAGENTA);
      stroke.property("ADBE Vector Stroke Width").setValue(width);
    }
  }

  function drawZone(comp, c) {
    if (!c.safe.length && !c.obstructions.length) return;
    var layer = comp.layers.addShape();
    layer.name = DATA.text.layer + (c.zone ? ": " + c.zone : "");
    layer.guideLayer = true;
    // Position 0,0 with the anchor at 0,0: the shape's coordinates are the composition's.
    layer.property("ADBE Transform Group").property("ADBE Position").setValue([0, 0]);
    var root = layer.property("ADBE Root Vectors Group");
    if (c.safe.length) {
      var frame = [[[0, 0], [c.width, 0], [c.width, c.height], [0, c.height]]];
      addGroup(root, DATA.text.covered, frame.concat(c.safe), "fill");
    }
    if (c.obstructions.length) addGroup(root, DATA.text.blocked, c.obstructions, "fill");
    if (c.safe.length) addGroup(root, DATA.text.safe, c.safe, "stroke", Math.max(2, Math.round(c.width / 180)));
    layer.locked = true;
  }

  app.beginUndoGroup(DATA.text.undo);
  try {
    var folder = app.project.items.addFolder(DATA.folder);
    for (var k = 0; k < DATA.comps.length; k++) {
      var c = DATA.comps[k];
      var comp = app.project.items.addComp(c.name, c.width, c.height, 1, DATA.duration, DATA.fps);
      comp.parentFolder = folder;
      drawZone(comp, c);
    }
  } finally {
    app.endUndoGroup();
  }
})();
