Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

61
node_modules/parchment/src/attributor/attributor.ts generated vendored Normal file
View File

@@ -0,0 +1,61 @@
import * as Registry from '../registry';
export interface AttributorOptions {
scope?: Registry.Scope;
whitelist?: string[];
}
export default class Attributor {
attrName: string;
keyName: string;
scope: Registry.Scope;
whitelist: string[] | undefined;
static keys(node: HTMLElement): string[] {
return [].map.call(node.attributes, function(item: Attr) {
return item.name;
});
}
constructor(attrName: string, keyName: string, options: AttributorOptions = {}) {
this.attrName = attrName;
this.keyName = keyName;
let attributeBit = Registry.Scope.TYPE & Registry.Scope.ATTRIBUTE;
if (options.scope != null) {
// Ignore type bits, force attribute bit
this.scope = (options.scope & Registry.Scope.LEVEL) | attributeBit;
} else {
this.scope = Registry.Scope.ATTRIBUTE;
}
if (options.whitelist != null) this.whitelist = options.whitelist;
}
add(node: HTMLElement, value: string): boolean {
if (!this.canAdd(node, value)) return false;
node.setAttribute(this.keyName, value);
return true;
}
canAdd(node: HTMLElement, value: any): boolean {
let match = Registry.query(node, Registry.Scope.BLOT & (this.scope | Registry.Scope.TYPE));
if (match == null) return false;
if (this.whitelist == null) return true;
if (typeof value === 'string') {
return this.whitelist.indexOf(value.replace(/["']/g, '')) > -1;
} else {
return this.whitelist.indexOf(value) > -1;
}
}
remove(node: HTMLElement): void {
node.removeAttribute(this.keyName);
}
value(node: HTMLElement): string {
let value = node.getAttribute(this.keyName);
if (this.canAdd(node, value) && value) {
return value;
}
return '';
}
}

44
node_modules/parchment/src/attributor/class.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import Attributor from './attributor';
function match(node: HTMLElement, prefix: string): string[] {
let className = node.getAttribute('class') || '';
return className.split(/\s+/).filter(function(name) {
return name.indexOf(`${prefix}-`) === 0;
});
}
class ClassAttributor extends Attributor {
static keys(node: HTMLElement): string[] {
return (node.getAttribute('class') || '').split(/\s+/).map(function(name) {
return name
.split('-')
.slice(0, -1)
.join('-');
});
}
add(node: HTMLElement, value: string): boolean {
if (!this.canAdd(node, value)) return false;
this.remove(node);
node.classList.add(`${this.keyName}-${value}`);
return true;
}
remove(node: HTMLElement): void {
let matches = match(node, this.keyName);
matches.forEach(function(name) {
node.classList.remove(name);
});
if (node.classList.length === 0) {
node.removeAttribute('class');
}
}
value(node: HTMLElement): string {
let result = match(node, this.keyName)[0] || '';
let value = result.slice(this.keyName.length + 1); // +1 for hyphen
return this.canAdd(node, value) ? value : '';
}
}
export default ClassAttributor;

73
node_modules/parchment/src/attributor/store.ts generated vendored Normal file
View File

@@ -0,0 +1,73 @@
import Attributor from './attributor';
import ClassAttributor from './class';
import StyleAttributor from './style';
import { Formattable } from '../blot/abstract/blot';
import * as Registry from '../registry';
class AttributorStore {
private attributes: { [key: string]: Attributor } = {};
private domNode: HTMLElement;
constructor(domNode: HTMLElement) {
this.domNode = domNode;
this.build();
}
attribute(attribute: Attributor, value: any): void {
// verb
if (value) {
if (attribute.add(this.domNode, value)) {
if (attribute.value(this.domNode) != null) {
this.attributes[attribute.attrName] = attribute;
} else {
delete this.attributes[attribute.attrName];
}
}
} else {
attribute.remove(this.domNode);
delete this.attributes[attribute.attrName];
}
}
build(): void {
this.attributes = {};
let attributes = Attributor.keys(this.domNode);
let classes = ClassAttributor.keys(this.domNode);
let styles = StyleAttributor.keys(this.domNode);
attributes
.concat(classes)
.concat(styles)
.forEach(name => {
let attr = Registry.query(name, Registry.Scope.ATTRIBUTE);
if (attr instanceof Attributor) {
this.attributes[attr.attrName] = attr;
}
});
}
copy(target: Formattable): void {
Object.keys(this.attributes).forEach(key => {
let value = this.attributes[key].value(this.domNode);
target.format(key, value);
});
}
move(target: Formattable): void {
this.copy(target);
Object.keys(this.attributes).forEach(key => {
this.attributes[key].remove(this.domNode);
});
this.attributes = {};
}
values(): { [key: string]: any } {
return Object.keys(
this.attributes,
).reduce((attributes: { [key: string]: any }, name: string) => {
attributes[name] = this.attributes[name].value(this.domNode);
return attributes;
}, {});
}
}
export default AttributorStore;

44
node_modules/parchment/src/attributor/style.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import Attributor from './attributor';
function camelize(name: string): string {
let parts = name.split('-');
let rest = parts
.slice(1)
.map(function(part: string) {
return part[0].toUpperCase() + part.slice(1);
})
.join('');
return parts[0] + rest;
}
class StyleAttributor extends Attributor {
static keys(node: Element): string[] {
return (node.getAttribute('style') || '').split(';').map(function(value) {
let arr = value.split(':');
return arr[0].trim();
});
}
add(node: HTMLElement, value: string): boolean {
if (!this.canAdd(node, value)) return false;
// @ts-ignore
node.style[camelize(this.keyName)] = value;
return true;
}
remove(node: HTMLElement): void {
// @ts-ignore
node.style[camelize(this.keyName)] = '';
if (!node.getAttribute('style')) {
node.removeAttribute('style');
}
}
value(node: HTMLElement): string {
// @ts-ignore
let value = node.style[camelize(this.keyName)];
return this.canAdd(node, value) ? value : '';
}
}
export default StyleAttributor;