import { Fun, Id, Optional } from '@ephox/katamari';
import { SugarNode } from '@ephox/sugar';
import * as AlloyTags from '../ephemera/AlloyTags';
import * as AlloyLogger from '../log/AlloyLogger';
const prefix = AlloyTags.prefix();
const idAttr = AlloyTags.idAttr();
const write = (label, elem) => {
    const id = Id.generate(prefix + label);
    writeOnly(elem, id);
    return id;
};
const writeOnly = (elem, uid) => {
    Object.defineProperty(elem.dom, idAttr, {
        value: uid,
        writable: true
    });
};
const read = (elem) => {
    const id = SugarNode.isElement(elem) ? elem.dom[idAttr] : null;
    return Optional.from(id);
};
const readOrDie = (elem) => read(elem).getOrDie('Could not find alloy uid in: ' + AlloyLogger.element(elem));
const generate = (prefix) => Id.generate(prefix);
const revoke = (elem) => {
    // This looks like it is only used by ForeignGui, which is experimental.
    writeOnly(elem, null);
};
// TODO: Consider deprecating.
const attribute = Fun.constant(idAttr);
export { revoke, write, writeOnly, read, readOrDie, generate, attribute };
//# sourceMappingURL=Tagger.js.map