Skip to content

Instantly share code, notes, and snippets.

@padmkris123
padmkris123 / webComponents.html
Created April 17, 2023 07:40
Web Components in UXP (HTML)
<style>
.container {
margin: 8px;
display: flex;
flex-direction: row;
justify-content: flex-start;
}
span {
color: darkgoldenrod;
@padmkris123
padmkris123 / webComponents.js
Created April 17, 2023 07:38
Web Components in UXP (JS logic)
class HelloWorld extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<span> 'Hello World!'</span>
<style>
span {
font-style: italic;
color: darkblue;
@padmkris123
padmkris123 / manifest.json
Created April 17, 2023 07:37
Web Components in UXP
{
"featureFlags": {
"enableSWCSupport": true
},
"host": [
{
"app": "PS",
"minVersion": "24.4"
}
],
@padmkris123
padmkris123 / canvas2dInUXP.html
Created April 17, 2023 07:35
UXP Canvas 2d example
<canvas id="canvas" height="250" width="250"></canvas>
@padmkris123
padmkris123 / drawShape.js
Created April 17, 2023 07:34
UXP Canvas 2d example
function drawShape() {
const canvas = document.getElementById("canvas");
// get the canvas context
let context = canvas.getContext("2d");
//draw triangle
context.lineWidth = 2.0;
context.beginPath();
context.moveTo(20, 20);
context.lineTo(100, 20);
context.lineTo(100, 100);
@padmkris123
padmkris123 / imageBlob_html.html
Created April 17, 2023 07:33
ImageBlob example
<img id="image"></img>
@padmkris123
padmkris123 / imageBlob_js.js
Created April 17, 2023 07:32
ImageBlob example
function createBlueBox() {
const width = 8;
const height = 8;
let buffer = new ArrayBuffer(width * height * 4);
let colorArrayView = new Uint8Array(buffer);
// Define pixels. Fill it with blue.
for (let i = 0; i < colorArrayView.length / 4; i++) {
colorArrayView[i * 4] = 0x00; // R
colorArrayView[i * 4 + 1] = 0x0; // G
@padmkris123
padmkris123 / indesign_dom.js
Created April 17, 2023 07:28
InDesign DOM APIs
// in InDesign v18.0
let doc = app.documents.add();
// InDesign v18.4 onwards
let idDom = require("indesign");
let doc = idDom.app.documents.add();
@padmkris123
padmkris123 / id_dom.js
Created April 17, 2023 07:25
Select InDesign DOM v18.0
let idDom = require("indesign_18.0"); // selects v18.0 version
let doc = idDom.app.documents.add();
@padmkris123
padmkris123 / sample.js
Created February 1, 2023 08:25
UXP Hybrid plugin - JS code
const addon = await require("sample.uxpaddon");
const result = addon.getGreeting();
console.log(`The plugins says: ${result}`);