import { FillerResource } from "./FillerData";
import { AreaGroups, TexImage } from "./common";
import { loadImage } from "../base/utils";

async function loadImageBase64(
  mime: string,
  base64: string,
): Promise<HTMLImageElement> {
  return new Promise((done, reject) => {
    let img = new Image();
    img.src = `data:${mime};base64, ${base64}`;
    img.onload = () => {
      done(img);
    };
    img.onerror = reject;
  });
}

function getKey(str: string): string | undefined {
  let regex = /[0-9a-z]{24}/i;
  let res = regex.exec(str);
  if (res == null) return;
  return res[0];
}

function str2ab(str: string): Uint16Array {
  var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
  var bufView = new Uint16Array(buf);
  for (var i = 0, strLen = str.length; i < strLen; i++) {
    bufView[i] = str.charCodeAt(i);
  }
  return bufView;
}
