Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

media-captions

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

media-captions - npm Package Compare versions

Comparing version 0.0.18 to 1.0.0

10

dist/dev/index.js

@@ -788,3 +788,3 @@ const ParseErrorCode = {

function setPartAttr(el, name) {
el.setAttribute("part", name);
el.setAttribute("data-part", name);
}

@@ -814,5 +814,5 @@ function getLineHeight(el) {

attrs.lang = token.type === "lang" && token.lang;
attrs["part"] = token.type === "v" && "voice";
attrs["data-part"] = token.type === "v" && "voice";
if (isTimestamp) {
attrs["part"] = "timed";
attrs["data-part"] = "timed";
attrs["data-time"] = token.time;

@@ -832,3 +832,3 @@ attrs["data-future"] = token.time > currentTime;

function updateTimedVTTCueNodes(root, currentTime) {
for (const el of root.querySelectorAll('[part="timed"]')) {
for (const el of root.querySelectorAll('[data-part="timed"]')) {
const time = Number(el.getAttribute("data-time"));

@@ -1092,3 +1092,3 @@ if (Number.isNaN(time))

function positionRegion(container, region, regionEl, boxes) {
let cues = Array.from(regionEl.querySelectorAll('[part="cue-display"]')), height = 0, limit = Math.max(0, cues.length - region.lines);
let cues = Array.from(regionEl.querySelectorAll('[data-part="cue-display"]')), height = 0, limit = Math.max(0, cues.length - region.lines);
for (let i = cues.length - 1; i >= limit; i--) {

@@ -1095,0 +1095,0 @@ height += cues[i].offsetHeight;

@@ -317,17 +317,17 @@ const ParseErrorCode = {

f;
c = 0;
g = {};
h = {};
j = [];
b = 0;
j = {};
k = {};
e = [];
a = null;
b = null;
k = [];
d;
l = "";
g = null;
m = [];
h;
d = "";
async init(init) {
this.f = init;
if (init.strict)
this.c = 1;
this.b = 1;
if (init.errors)
this.d = (await import('./errors.js')).ParseErrorBuilder;
this.h = (await import('./errors.js')).ParseErrorBuilder;
}

@@ -337,18 +337,18 @@ parse(line, lineCount) {

if (this.a) {
this.j.push(this.a);
this.e.push(this.a);
this.f.onCue?.(this.a);
this.a = null;
} else if (this.b) {
this.h[this.b.id] = this.b;
this.f.onRegion?.(this.b);
this.b = null;
} else if (this.c === 1) {
this.i(line, lineCount);
this.f.onHeaderMetadata?.(this.g);
} else if (this.g) {
this.k[this.g.id] = this.g;
this.f.onRegion?.(this.g);
this.g = null;
} else if (this.b === 1) {
this.l(line, lineCount);
this.f.onHeaderMetadata?.(this.j);
}
this.c = 0;
} else if (this.c) {
switch (this.c) {
this.b = 0;
} else if (this.b) {
switch (this.b) {
case 1:
this.i(line, lineCount);
this.l(line, lineCount);
break;

@@ -359,3 +359,3 @@ case 2:

if (!hasText && SETTING_LINE_RE.test(line)) {
this.m(line.split(SPACE_RE), lineCount);
this.n(line.split(SPACE_RE), lineCount);
} else {

@@ -367,33 +367,33 @@ this.a.text += (hasText ? "\n" : "") + line;

case 3:
this.n(line.split(SPACE_RE), lineCount);
this.o(line.split(SPACE_RE), lineCount);
break;
}
} else if (line.startsWith(NOTE_BLOCK_START)) {
this.c = 4;
this.b = 4;
} else if (line.startsWith(REGION_BLOCK_START)) {
this.c = 3;
this.b = new VTTRegion();
this.n(line.replace(REGION_BLOCK_START_RE, "").split(SPACE_RE), lineCount);
this.b = 3;
this.g = new VTTRegion();
this.o(line.replace(REGION_BLOCK_START_RE, "").split(SPACE_RE), lineCount);
} else if (line.includes(TIMESTAMP_SEP)) {
const result = this.o(line, lineCount);
const result = this.c(line, lineCount);
if (result) {
this.a = new VTTCue(result[0], result[1], "");
this.a.id = this.l;
this.m(result[2], lineCount);
this.a.id = this.d;
this.n(result[2], lineCount);
}
this.c = 2;
this.b = 2;
} else if (lineCount === 1) {
this.i(line, lineCount);
this.l(line, lineCount);
}
this.l = line;
this.d = line;
}
done() {
return {
metadata: this.g,
cues: this.j,
regions: Object.values(this.h),
errors: this.k
metadata: this.j,
cues: this.e,
regions: Object.values(this.k),
errors: this.m
};
}
i(line, lineCount) {
l(line, lineCount) {
if (lineCount > 1) {

@@ -403,11 +403,11 @@ if (SETTING_SEP_RE.test(line)) {

if (key)
this.g[key] = (value || "").replace(SPACE_RE, "");
this.j[key] = (value || "").replace(SPACE_RE, "");
}
} else if (line.startsWith(HEADER_MAGIC)) {
this.c = 1;
this.b = 1;
} else {
this.e(this.d?.p());
this.i(this.h?.p());
}
}
o(line, lineCount) {
c(line, lineCount) {
const [startTimeText, trailingText = ""] = line.split(TIMESTAMP_SEP_RE), [endTimeText, ...settingsText] = trailingText.split(SPACE_RE), startTime = parseVTTTimestamp(startTimeText), endTime = parseVTTTimestamp(endTimeText);

@@ -418,9 +418,9 @@ if (startTime !== null && endTime !== null && endTime > startTime) {

if (startTime === null) {
this.e(this.d?.q(startTimeText, lineCount));
this.i(this.h?.q(startTimeText, lineCount));
}
if (endTime === null) {
this.e(this.d?.r(endTimeText, lineCount));
this.i(this.h?.r(endTimeText, lineCount));
}
if (startTime != null && endTime !== null && endTime > startTime) {
this.e(this.d?.s(startTime, endTime, lineCount));
this.i(this.h?.s(startTime, endTime, lineCount));
}

@@ -432,3 +432,3 @@ }

*/
n(settings, line) {
o(settings, line) {
let badValue;

@@ -441,3 +441,3 @@ for (let i = 0; i < settings.length; i++) {

case "id":
this.b.id = value;
this.g.id = value;
break;

@@ -447,3 +447,3 @@ case "width":

if (width !== null)
this.b.width = width;
this.g.width = width;
else

@@ -455,3 +455,3 @@ badValue = true;

if (lines !== null)
this.b.lines = lines;
this.g.lines = lines;
else

@@ -463,4 +463,4 @@ badValue = true;

if (region !== null) {
this.b.regionAnchorX = region[0];
this.b.regionAnchorY = region[1];
this.g.regionAnchorX = region[0];
this.g.regionAnchorY = region[1];
} else

@@ -472,4 +472,4 @@ badValue = true;

if (viewport !== null) {
this.b.viewportAnchorX = viewport[0];
this.b.viewportAnchorY = viewport[1];
this.g.viewportAnchorX = viewport[0];
this.g.viewportAnchorY = viewport[1];
} else

@@ -480,3 +480,3 @@ badValue = true;

if (value === "up")
this.b.scroll = "up";
this.g.scroll = "up";
else

@@ -486,6 +486,6 @@ badValue = true;

default:
this.e(this.d?.t(name, value, line));
this.i(this.h?.t(name, value, line));
}
if (badValue) {
this.e(this.d?.u(name, value, line));
this.i(this.h?.u(name, value, line));
}

@@ -498,3 +498,3 @@ }

*/
m(settings, line) {
n(settings, line) {
let badValue;

@@ -507,3 +507,3 @@ for (let i = 0; i < settings.length; i++) {

case "region":
const region = this.h[value];
const region = this.k[value];
if (region)

@@ -573,6 +573,6 @@ this.a.region = region;

default:
this.e(this.d?.v(name, value, line));
this.i(this.h?.v(name, value, line));
}
if (badValue) {
this.e(this.d?.w(name, value, line));
this.i(this.h?.w(name, value, line));
}

@@ -582,6 +582,6 @@ }

}
e(error) {
i(error) {
if (!error)
return;
this.k.push(error);
this.m.push(error);
if (this.f.strict) {

@@ -798,3 +798,3 @@ this.f.cancel();

function setPartAttr(el, name) {
el.setAttribute("part", name);
el.setAttribute("data-part", name);
}

@@ -824,5 +824,5 @@ function getLineHeight(el) {

attrs.lang = token.type === "lang" && token.lang;
attrs["part"] = token.type === "v" && "voice";
attrs["data-part"] = token.type === "v" && "voice";
if (isTimestamp) {
attrs["part"] = "timed";
attrs["data-part"] = "timed";
attrs["data-time"] = token.time;

@@ -842,3 +842,3 @@ attrs["data-future"] = token.time > currentTime;

function updateTimedVTTCueNodes(root, currentTime) {
for (const el of root.querySelectorAll('[part="timed"]')) {
for (const el of root.querySelectorAll('[data-part="timed"]')) {
const time = Number(el.getAttribute("data-time"));

@@ -1102,3 +1102,3 @@ if (Number.isNaN(time))

function positionRegion(container, region, regionEl, boxes) {
let cues = Array.from(regionEl.querySelectorAll('[part="cue-display"]')), height = 0, limit = Math.max(0, cues.length - region.lines);
let cues = Array.from(regionEl.querySelectorAll('[data-part="cue-display"]')), height = 0, limit = Math.max(0, cues.length - region.lines);
for (let i = cues.length - 1; i >= limit; i--) {

@@ -1130,4 +1130,4 @@ height += cues[i].offsetHeight;

E;
h = /* @__PURE__ */ new Map();
j = /* @__PURE__ */ new Map();
k = /* @__PURE__ */ new Map();
e = /* @__PURE__ */ new Map();
/* Text direction. */

@@ -1163,11 +1163,11 @@ get dir() {

for (const cue of cues)
this.j.set(cue, null);
this.e.set(cue, null);
this.update();
}
addCue(cue) {
this.j.set(cue, null);
this.e.set(cue, null);
this.update();
}
removeCue(cue) {
this.j.delete(cue);
this.e.delete(cue);
this.update();

@@ -1179,4 +1179,4 @@ }

reset() {
this.j.clear();
this.h.clear();
this.e.clear();
this.k.clear();
this.B = [];

@@ -1196,6 +1196,6 @@ this.overlay.textContent = "";

this.G();
for (const el of this.h.values()) {
for (const el of this.k.values()) {
el[STARTING_BOX] = null;
}
for (const el of this.j.values()) {
for (const el of this.e.values()) {
if (el)

@@ -1212,5 +1212,5 @@ el[STARTING_BOX] = null;

H(forceUpdate = false) {
if (!this.j.size || this.D)
if (!this.e.size || this.D)
return;
let cue, activeCues = [...this.j.keys()].filter((cue2) => this.A >= cue2.startTime && this.A <= cue2.endTime).sort(
let cue, activeCues = [...this.e.keys()].filter((cue2) => this.A >= cue2.startTime && this.A <= cue2.endTime).sort(
(cueA, cueB) => cueA.startTime !== cueB.startTime ? cueA.startTime - cueB.startTime : cueA.endTime - cueB.endTime

@@ -1223,3 +1223,3 @@ ), activeRegions = activeCues.map((cue2) => cue2.region);

if (cue.region && !activeRegions.includes(cue.region)) {
const regionEl = this.h.get(cue.region.id);
const regionEl = this.k.get(cue.region.id);
if (regionEl) {

@@ -1230,3 +1230,3 @@ regionEl.removeAttribute("data-active");

}
const cueEl = this.j.get(cue);
const cueEl = this.e.get(cue);
if (cueEl) {

@@ -1239,6 +1239,6 @@ cueEl.remove();

cue = activeCues[i];
let cueEl = this.j.get(cue);
let cueEl = this.e.get(cue);
if (!cueEl)
this.j.set(cue, cueEl = this.L(cue));
const regionEl = this.F(cue) && this.h.get(cue.region.id);
this.e.set(cue, cueEl = this.L(cue));
const regionEl = this.F(cue) && this.k.get(cue.region.id);
if (regionEl && !regionEl.hasAttribute("data-active")) {

@@ -1259,3 +1259,3 @@ requestAnimationFrame(() => setDataAttr(regionEl, "active"));

continue;
const isRegion = this.F(cue), el = isRegion ? this.h.get(cue.region.id) : this.j.get(cue);
const isRegion = this.F(cue), el = isRegion ? this.k.get(cue.region.id) : this.e.get(cue);
if (isRegion) {

@@ -1277,3 +1277,3 @@ boxes.push(positionRegion(this.z, cue.region, el, boxes));

const el = this.M(region);
this.h.set(region.id, el);
this.k.set(region.id, el);
this.overlay.append(el);

@@ -1280,0 +1280,0 @@ }

@@ -8,21 +8,21 @@ import { V as VTTParser, a as VTTBlock, b as VTTCue } from './index.js';

if (this.a) {
this.j.push(this.a);
this.e.push(this.a);
this.f.onCue?.(this.a);
this.a = null;
}
this.c = VTTBlock.None;
} else if (this.c === VTTBlock.Cue) {
this.b = VTTBlock.None;
} else if (this.b === VTTBlock.Cue) {
this.a.text += (this.a.text ? "\n" : "") + line;
} else if (line.includes(TIMESTAMP_SEP)) {
const result = this.o(line, lineCount);
const result = this.c(line, lineCount);
if (result) {
this.a = new VTTCue(result[0], result[1], result[2].join(" "));
this.a.id = this.l;
this.c = VTTBlock.Cue;
this.a.id = this.d;
this.b = VTTBlock.Cue;
}
}
this.l = line;
this.d = line;
}
o(line, lineCount) {
return super.o(line.replace(MILLISECOND_SEP_RE, "."), lineCount);
c(line, lineCount) {
return super.c(line.replace(MILLISECOND_SEP_RE, "."), lineCount);
}

@@ -29,0 +29,0 @@ }

@@ -8,6 +8,6 @@ import { b as VTTCue, p as parseVTTTimestamp } from './index.js';

a = null;
j = [];
k = [];
e = [];
m = [];
N = null;
d;
h;
P = {};

@@ -17,3 +17,3 @@ async init(init) {

if (init.errors)
this.d = (await import('./errors.js')).ParseErrorBuilder;
this.h = (await import('./errors.js')).ParseErrorBuilder;
}

@@ -31,3 +31,3 @@ parse(line, lineCount) {

} else {
this.e(this.d?.T("Style", lineCount));
this.i(this.h?.T("Style", lineCount));
}

@@ -51,3 +51,3 @@ } else if (FORMAT_START_RE.test(line)) {

} else {
this.e(this.d?.T("Dialogue", lineCount));
this.i(this.h?.T("Dialogue", lineCount));
}

@@ -76,5 +76,5 @@ } else if (this.a) {

metadata: {},
cues: this.j,
cues: this.e,
regions: [],
errors: this.k
errors: this.m
};

@@ -85,3 +85,3 @@ }

return;
this.j.push(this.a);
this.e.push(this.a);
this.f.onCue?.(this.a);

@@ -217,3 +217,3 @@ this.a = null;

const fields = this.V(values);
const timestamp = this.o(fields.Start, fields.End, lineCount);
const timestamp = this.c(fields.Start, fields.End, lineCount);
if (!timestamp)

@@ -247,3 +247,3 @@ return;

}
o(startTimeText, endTimeText, lineCount) {
c(startTimeText, endTimeText, lineCount) {
const startTime = parseVTTTimestamp(startTimeText), endTime = parseVTTTimestamp(endTimeText);

@@ -254,16 +254,16 @@ if (startTime !== null && endTime !== null && endTime > startTime) {

if (startTime === null) {
this.e(this.d?.q(startTimeText, lineCount));
this.i(this.h?.q(startTimeText, lineCount));
}
if (endTime === null) {
this.e(this.d?.r(endTimeText, lineCount));
this.i(this.h?.r(endTimeText, lineCount));
}
if (startTime != null && endTime !== null && endTime > startTime) {
this.e(this.d?.s(startTime, endTime, lineCount));
this.i(this.h?.s(startTime, endTime, lineCount));
}
}
}
e(error) {
i(error) {
if (!error)
return;
this.k.push(error);
this.m.push(error);
if (this.f.strict) {

@@ -270,0 +270,0 @@ this.f.cancel();

@@ -788,3 +788,3 @@ const ParseErrorCode = {

function setPartAttr(el, name) {
el.setAttribute("part", name);
el.setAttribute("data-part", name);
}

@@ -816,5 +816,5 @@ function getLineHeight(el) {

attrs.lang = token.type === "lang" && token.lang;
attrs["part"] = token.type === "v" && "voice";
attrs["data-part"] = token.type === "v" && "voice";
if (isTimestamp) {
attrs["part"] = "timed";
attrs["data-part"] = "timed";
attrs["data-time"] = token.time;

@@ -1081,3 +1081,3 @@ attrs["data-future"] = token.time > currentTime;

function positionRegion(container, region, regionEl, boxes) {
let cues = Array.from(regionEl.querySelectorAll('[part="cue-display"]')), height = 0, limit = Math.max(0, cues.length - region.lines);
let cues = Array.from(regionEl.querySelectorAll('[data-part="cue-display"]')), height = 0, limit = Math.max(0, cues.length - region.lines);
for (let i = cues.length - 1; i >= limit; i--) {

@@ -1084,0 +1084,0 @@ height += cues[i].offsetHeight;

{
"name": "media-captions",
"version": "0.0.18",
"version": "1.0.0",
"description": "Media captions parser and renderer.",

@@ -23,6 +23,7 @@ "license": "MIT",

"format": "prettier src --write --loglevel warn",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"test": "vitest --run",
"test:watch": "vitest --watch --single-thread",
"sandbox": "node ./.sandbox/launch.js",
"release": "pnpm validate && standard-version && git push --follow-tags origin main && npm publish",
"release": "pnpm validate && pnpm changelog && git push --follow-tags origin main && npm publish --tag next",
"validate": "pnpm test && pnpm build"

@@ -34,2 +35,3 @@ },

"acorn-walk": "^8.2.0",
"conventional-changelog-cli": "^4.1.0",
"esbuild": "^0.18.1",

@@ -41,3 +43,2 @@ "magic-string": "^0.30.0",

"rollup-plugin-esbuild": "^5.0.0",
"standard-version": "^9.5.0",
"tslib": "^2.5.0",

@@ -44,0 +45,0 @@ "typescript": "^5.0.0",

@@ -415,3 +415,3 @@ # Media Captions

// <span title="Joe" part="voice">Hello world!</span>
// <span title="Joe" data-part="voice">Hello world!</span>
const cueHTML = template.content.cloneNode(true);

@@ -430,3 +430,3 @@ ```

// Output: <span title="Joe" part="voice">Hello world!</span>
// Output: <span title="Joe" data-part="voice">Hello world!</span>
const content = renderVTTCueString(cue);

@@ -441,6 +441,6 @@ ```

// Output: Hello my name is <span part="timed" data-time="80" data-future>Joe!</span>
// Output: Hello my name is <span data-part="timed" data-time="80" data-future>Joe!</span>
renderVTTCueString(cue, 310);
// Output: Hello my name is <span part="timed" data-time="80" data-past>Joe!</span>
// Output: Hello my name is <span data-part="timed" data-time="80" data-past>Joe!</span>
renderVTTCueString(cue, 321);

@@ -536,3 +536,3 @@ ```

// Output: <span title="Joe" part="voice">Hello world!</span>
// Output: <span title="Joe" data-part="voice">Hello world!</span>
const result = renderVTTTokensString(tokens);

@@ -563,4 +563,4 @@ ```

// Timed text nodes that would be updated at 303 seconds:
// <span part="timed" data-time="300" data-past>Timed...</span>
// <span part="timed" data-time="305" data-future>Text!</span>
// <span data-part="timed" data-time="300" data-past>Timed...</span>
// <span data-part="timed" data-time="305" data-future>Text!</span>
```

@@ -645,33 +645,33 @@

#captions [part='region'] {
#captions [data-part='region'] {
}
#captions [part='region'][data-active] {
#captions [data-part='region'][data-active] {
}
#captions [part='region'][data-scroll='up'] {
#captions [data-part='region'][data-scroll='up'] {
}
#captions [part='cue-display'] {
#captions [data-part='cue-display'] {
}
#captions [part='cue'] {
#captions [data-part='cue'] {
}
#captions [part='cue'][data-id='...'] {
#captions [data-part='cue'][data-id='...'] {
}
#captions [part='voice'] {
#captions [data-part='voice'] {
}
#captions [part='voice'][title='Joe'] {
#captions [data-part='voice'][title='Joe'] {
}
#captions [part='timed'] {
#captions [data-part='timed'] {
}
#captions [part='timed'][data-past] {
#captions [data-part='timed'][data-past] {
}
#captions [part='timed'][data-future] {
#captions [data-part='timed'][data-future] {
}

@@ -678,0 +678,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc