#target aftereffects
// FrameSafe Studio: YouTube, videopohjat After Effectsiin (https://framesafe.studio/fi/pohjat).
// Aja After Effectsissa (File > Scripts > Run Script File...). Skripti lisaa projektiin kansion, jossa
// on kompositio jokaiselle koolle; jos mainospaikalla on turva-alue, lukittu ohjaintaso nayttaa
// kayttoliittyman peittaman alueen (magenta, 35 %) ja turva-alueen reunan. Ohjaintasot eivat renderoidy.
// Koot ja turva-alueet: FrameSafen rekisteri 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 YouTube videopohjat","fps":25,"duration":15,"text":{"folder":"videopohjat","layer":"FrameSafe-turva-alue (ohjaintaso, ei render\u00f6idy)","covered":"Alustan k\u00e4ytt\u00f6liittym\u00e4n peitt\u00e4m\u00e4 alue","blocked":"Alustan k\u00e4ytt\u00f6liittym\u00e4","safe":"Turva-alue","undo":"FrameSafe-pohjat"},"comps":[{"name":"In-stream 16x9 1920x1080","width":1920,"height":1080,"safe":[[[1444,38],[1444,133],[1758,133],[1758,183],[1758,693],[38,693],[38,183],[496,183],[496,133],[496,38]]],"obstructions":[],"zone":"Googlen yleinen turva-alue (vaaka, mitattu)"},{"name":"Shorts 9x16 1080x1920","width":1080,"height":1920,"safe":[[[48,288],[888,288],[888,1248],[48,1248]]],"obstructions":[],"zone":"Googlen yleinen turva-alue (pysty, mitattu)"},{"name":"Video orgaaninen 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();
  }
})();
