Link Search Menu Expand Document

Test Closet Inside Your Browser

  • filterManager.install(
      closet.browser.recipes.occlusionEditor(),
      closet.browser.recipes.rect.show({ tagname: 'rect' }),
      closet.browser.recipes.rect.reveal({ tagname: 'rectr' }),
      closet.browser.recipes.rect.hide({ tagname: 'recth' }),
    )
    
  • filterManager.install(
      closet.recipes.mingle.show({ tagname: 'shuf' }),
      closet.recipes.sort.show({ tagname: 'sort' }),
      closet.recipes.jumble.show({ tagname: 'jumb' }),
    )
    
  • const firstValue = (tag) => [tag.values[0]]
    const obscureYellow = closet.Stylizer.make({
      processor: v => `<span style="color: yellow; filter: blur(0.2rem);">${v}</span>`,
    })
    
    const obscureOptions = {
      frontEllipser: firstValue,
      frontStylizer: obscureYellow,
    }
    
    filterManager.install(
      closet.recipes.cloze.show({
        tagname: 'c',
        ...obscureOptions,
      }),
    
      closet.recipes.cloze.hide({
        tagname: 'ch',
        ...obscureOptions,
      }),
    
      closet.recipes.cloze.reveal({
        tagname: 'cr',
        ...obscureOptions,
      }),
    )
    
  • const colorWheel = function*() {
      while (true) {
        yield 'pink'
        yield 'lime'
        yield 'yellow'
      }
    }
    
    const cw = colorWheel()
    cw.next()
    
    const colorfulWithMiddleDot = closet.Stylizer.make({
      separator: '・',
      mapper: v => (
        `<span style="color: ${cw.next().value};">${v}</span>`
      ),
      processor: v => `〈${v}〉`,
    })
    
    const withMiddleDot = closet.Stylizer.make({
      separator: '・',
    })
    
    const withSlash = closet.Stylizer.make({
      separator: ' / ',
    })
    
    const withVs = closet.Stylizer.make({
      separator: ' vs ',
      mapper: (v, i) => `${i}: ${v}`
    })
    
    filterManager.install(
      closet.recipes.shuffle({
        tagname: 'cmix',
        stylizer: colorfulWithMiddleDot,
      }),
    
      closet.recipes.shuffle({
        tagname: 'amix',
        stylizer: withMiddleDot,
      }),
    
      closet.recipes.shuffle({
        tagname: 'vmix',
        stylizer: withVs,
      }),
    
      closet.recipes.shuffle({
        tagname: 'mix',
        stylizer: withSlash
      }),
    )
    
  • filterManager.install(
      closet.recipes.debug(),
      closet.recipes.define({ tagname: 'def' }),
      closet.recipes.specification.hide({ tagname: 'spec' }),
    )
    
  • const backProperties = {
      fill: 'transparent',
      strokeWidth: '2px',
      stroke: 'red',
    }
    
    filterManager.install(
      closet.browser.recipes.rect.show({ tagname: 'rect', backProperties }),
      closet.browser.recipes.rect.reveal({ tagname: 'rectr', backProperties }),
      closet.browser.recipes.rect.hide({ tagname: 'recth', backProperties }),
    )
    
  • filterManager.install(
      closet.recipes.activate({ tagname: 'on', storeId: 'flashcardActive' }),
      closet.recipes.deactivate({ tagname: 'off', storeId: 'flashcardActive' }),
    
      closet.wrappers.product(closet.recipes.setNumber, closet.recipes.setNumber)({
        tagname: 'around',
        optionsFirst: { storeId: 'flashcardActiveTop' },
        optionsSecond: { storeId: 'flashcardActiveBottom' },
      }),
    
      closet.recipes.setNumber({ tagname: 'up', storeId: 'flashcardActiveTop' }),
      closet.recipes.setNumber({ tagname: 'down', storeId: 'flashcardActiveBottom' }),
    
      closet.recipes.activate({ tagname: 'show', storeId: 'flashcardShow' }),
      closet.recipes.activate({ tagname: 'hide', storeId: 'flashcardHide' }),
    
      closet.recipes.setNumber({ tagname: 'top', storeId: 'flashcardShowTop' }),
      closet.recipes.setNumber({ tagname: 'bottom', storeId: 'flashcardShowBottom' }),
    
      closet.wrappers.product(closet.recipes.setNumber, closet.recipes.setNumber)({
        tagname: 'ctxt',
        optionsFirst: { storeId: 'flashcardShowTop' },
        optionsSecond: { storeId: 'flashcardShowBottom' },
      }),
    )
    
  • filterManager.install( 
      closet.recipes.multipleChoice.show({ tagname: 'mc' }),
      closet.recipes.multipleChoice.hide({ tagname: 'mch' }),
      closet.recipes.multipleChoice.reveal({ tagname: 'mcr' }),
    )
    
  • filterManager.install(
      closet.recipes.setList({ tagname: 'setl' }),
    )
    
  • filterManager.install(
      closet.recipes.cloze.show({ tagname: 'c' }),
      closet.recipes.cloze.hide({ tagname: 'ch' }),
      closet.recipes.cloze.reveal({ tagname: 'cr' }),
    )
    
  • filterManager.install(
      closet.recipes.pick({ tagname: 'pick' }),
      closet.recipes.pickIndex({ tagname: 'pi' }),
      closet.recipes.pickCardNumber({ tagname: 'sel' }),
    )
    
  • const baseStylizer = closet.Stylizer.make({
      separator: '・',
      processor: (v) => `《${v}》`,
    })
    
    const colorMapper = (v, _i, cat) => {
      if (v === '') {
        return []
      }
    
      const theColor = cat === 0
        ? 'yellow'
        : cat === 1
        ? 'darkseagreen'
        : 'indianred'
    
        return `<span style="color: ${theColor};${cat === 0
          ? '-webkit-text-stroke: 0.8px black; text-stroke: 0.8px black;'
          : ''}">${v}</span>`
    }
    
    const theBackStylizer = baseStylizer.toStylizer({
      mapper: colorMapper,
    })
    
    const theFrontStylizer = baseStylizer.toStylizer({
      mapper: (v) => v === '' ? [] : `<span style="color: lightgrey">${v}</span>`,
    })
    
    const theContexter = (tag) => {
      const flattedValues = tag.values.flatMap((vs, i) => vs.map(v => [v, i]))
      return flattedValues.map((v, i) => colorMapper(v[0], i, v[1]))
    }
    
    const assignCategorySettings = {
      backStylizer: theBackStylizer,
      frontStylizer: theFrontStylizer,
    
      inactiveStylizer: baseStylizer,
      contexter: theContexter,
    }
    
    filterManager.install(
      closet.recipes.multipleChoice.show({
        tagname: 'mc',
        ...assignCategorySettings,
      }),
    
      closet.recipes.multipleChoice.hide({
        tagname: 'mch',
        ...assignCategorySettings,
      }),
    
      closet.recipes.multipleChoice.reveal({
        tagname: 'mcr',
        ...assignCategorySettings,
      }),
    )
    
  • const fancyMultipleChoiceStyle = `
    .cl--container {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
      grid-gap: 0px 20px;
      margin: 40px auto;
    }
    
    .cl--card {
      cursor: pointer;
      position: relative;
      height: 0;
      padding-bottom: 100%;
      transition: transform 0.6s ease;
      --translate: 0;
      transform: translate(var(--translate), var(--translate));
    }
    
    .cl--card:hover {
      --translate: calc(-5px);
      transition: transform 0.3s ease;
    }
    
    .cl--child {
      position: absolute;
      width: 100%;
      height: 80%;
    
      padding: 8px 16px;
      background: #fff;
      box-shadow: 0px 4px 8px rgba(128, 128, 128, 0.1), 0px -4px 8px rgba(255, 255, 255, 0.8);
      border-radius: 6px;
      transition: inherit;
      transform: translate(var(--translate), var(--translate));
      z-index: 5;
    }
    
    .cl--child > h3 {
      color: black;
    }
    
    .cl--reveal .cl--category-0 {
      background-color: lime;
    }
    
    .cl--reveal .cl--category-1 {
      background-color: coral;
    }`
    
    const wrappedMultipleChoiceShow = closet.wrappers.aftermath(closet.recipes.multipleChoice.show, (e, inter) => {
      document.querySelectorAll('.cl--child')
        .forEach(v => v.addEventListener('click', () => {
          const container = document.querySelector('.cl--container')
    
          if (container) {
            container.classList.add('cl--reveal')
          }
        }))
    
      const keyword = 'fancyMultipleChoice'
    
      if (!inter.environment.has(keyword)) {
        closet.browser.appendStyleTag(fancyMultipleChoiceStyle)
        inter.environment.set(keyword, true)
      }
    })
    
    const wrapItem = (v, _i, cat) => `<div class="cl--card"><div class="cl--child cl--category-${cat}"><h3>${v}</h3></div></div>`
    
    filterManager.install(wrappedMultipleChoiceShow({
      tagname: 'mc',
      frontStylizer: closet.Stylizer.make({
        mapper: wrapItem,
        separator: '',
        processor: (v) => `<div class="cl--container">${v}</div>`,
      }),
      backStylizer: closet.Stylizer.make({
        mapper: wrapItem,
        separator: '',
        processor: (v) => `<div class="cl--container cl--reveal">${v}</div>`,
      }),
    }))
    
  • const blank = function(tag) {
      return [tag.values[0].replace(closet.unicodeAlphanumericPattern, '_')]
    }
    
    const blankOptions = {
      frontEllipser: blank,
      frontStylizer: closet.Stylizer.make({
        process: v => `<span style="color: cornflowerblue">${v}</span>`,
        separator: '',
      }),
    }
    
    filterManager.install(
      closet.recipes.cloze.show({
        tagname: 'c',
        ...blankOptions,
      }),
      closet.recipes.cloze.hide({
        tagname: 'ch',
        ...blankOptions,
      }),
      closet.recipes.cloze.reveal({
        tagname: 'cr',
        ...blankOptions,
      }),
    )
    
  • filterManager.install(
      closet.recipes.generateInteger({ tagname: 'gen' }),
      closet.recipes.generateReal({ tagname: 'genr' }),
    )
    
  • closet.browser.appendStyleTag(`
    .cl--obscure-hint {
      filter: blur(0.25em);
    }
    
    .cl--obscure-fix::after {
      content: 'XXXXXXXXXX';
      filter: blur(0.25em);
    }
    
    .cl--obscure-fix > span {
      display: none;
    }`)
    
    const removeObscure = function(event) {
      if (event.currentTarget.classList.contains('cl--obscure-clickable')) {
        event.currentTarget.classList.remove('cl--obscure')
        event.currentTarget.classList.remove('cl--obscure-hint')
        event.currentTarget.classList.remove('cl--obscure-fix')
      }
    }
    
    const wrappedClozeShow = closet.wrappers.aftermath(closet.recipes.cloze.show, () => {
      document.querySelectorAll('.cl--obscure')
      .forEach(tag => {
        tag.addEventListener('click', removeObscure, {
          once: true,
        })
      })
    })
    
    const obscureAndClick = (t) => {
      return [`<span class="cl--obscure cl--obscure-hint cl--obscure-clickable">${t.values[0]}</span>`]
    }
    
    const obscureAndClickFix = (t) => {
      return [`<span class="cl--obscure cl--obscure-fix cl--obscure-clickable"><span>${t.values[0]}</span></span>`]
    }
    
    const frontStylizer = closet.Stylizer.make({
      processor: v => `<span style="color: cornflowerblue">${v}</span>`,
    })
    
    filterManager.install(
      wrappedClozeShow({
        tagname: 'c',
        frontEllipser: obscureAndClick,
        frontStylizer: frontStylizer,
      }),
    
      wrappedClozeShow({
        tagname: 'cx',
        frontEllipser: obscureAndClickFix,
        frontStylizer: frontStylizer,
      }),
    )
    
  • filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))
    
  • const countRightAnswers = (tag, internals) => {
      const rightAnswerKeyword = `${tag.fullKey}:rightAnswers`
      const increaseByRightAnswers = (v) => v + (tag.values
        ? tag.values[0].length
        : 0)
    
      internals.cache.fold(rightAnswerKeyword, increaseByRightAnswers, 0)
    
      return tag.values
        ? tag.values.flatMap((v, i) => v.map((w) => [
          w,
          i,
          tag.fullKey,
          tag.fullOccur,
          internals.cache,
          internals.aftermath,
        ]))
        : []
    }
    
    const refreshInputChecked = (elementId, aftermath) => {
      const oldInput = document.getElementById(elementId)
      if (oldInput && oldInput.checked) {
        aftermath.register(`${elementId}:recheck`, () => {
          const newInput = document.getElementById(elementId)
    
          if (newInput) {
            newInput.checked = true
          }
        })
      }
    }
    
    const createInputElement = (classLabel) => (value, index, type, fullKey, fullOccur, cache, aftermath) => {
      const rightAnswerKeyword = `${fullKey}:rightAnswers`
      const rightAnswerCount = cache.get(rightAnswerKeyword, 0)
    
      const elementId = `${fullKey}-${fullOccur}-${index}`
      const inputType = rightAnswerCount === 1 ? 'radio' : 'checkbox'
    
      refreshInputChecked(elementId, aftermath)
      const className = type === 0 ? `class="${classLabel}" ` : ''
    
      return `
        <input type="${inputType}" id="${elementId}" name="${fullKey}" />
        <label ${className} for="${elementId}">${value}</label>
      `
    }
    
    const front = closet.Stylizer.make({
      separator: '<br />',
      mapper: createInputElement('')
    })
    
    const backClassName = 'closet-mc-right-answer'
    
    const back = closet.Stylizer.make({
      separator: '<br />',
      mapper: createInputElement(backClassName),
    })
    
    const inputMultipleChoiceStyle = `
    .${backClassName} {
      color: lime;
    }`
    
    const addHighlightCSS = (entry, internals) => {
      const keyword = 'inputMultipleChoice'
    
      if (!internals.environment.post(keyword, () => true, false)) {
        closet.browser.appendStyleTag(inputMultipleChoiceStyle)
      }
    }
    
    const wrappedMultipleChoiceShow = closet.wrappers.aftermath(closet.recipes.multipleChoice.show, addHighlightCSS)
    
    filterManager.install(wrappedMultipleChoiceShow({
      tagname: 'mc',
      getValues: countRightAnswers,
      frontStylizer: front,
      backStylizer: back,
    }))
    
  • /*
    MIT License
    Copyright (c) 2018 Pepe Becker
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
    
    With changes by Henrik Giesel, 2020
    */
    
    const syllables = [
      "a", "ai", "an", "ang", "ao",
      "ba", "bai", "ban", "bang", "bao", "bei", "ben", "beng", "bi", "bian", "biao", "bie", "bin", "bing", "bo", "bu",
      "ca", "cai", "can", "cang", "cao", "ce", "cei", "cen", "ceng", "cha", "chai", "chan", "chang", "chao", "che", "chen", "cheng", "chi", "chong", "chou", "chu", "chua", "chuai", "chuan", "chuang", "chui", "chun", "chuo", "ci", "cong", "cou", "cu", "cuan", "cui", "cun", "cuo",
      "da", "dai", "dan", "dang", "dao", "de", "dei", "den", "deng", "di", "dian", "diao", "die", "ding", "diu", "dong", "dou", "du", "duan", "dui", "dun", "duo",
      "e", "ei", "en", "er",
      "fa", "fan", "fang", "fei", "fen", "feng", "fo", "fou", "fu",
      "ga", "gai", "gan", "gang", "gao", "ge", "gei", "gen", "geng", "gong", "gou", "gu", "gua", "guai", "guan", "guang", "gui", "gun", "guo",
      "ha", "hai", "han", "hang", "hao", "he", "hei", "hen", "heng", "hm", "hng", "hong", "hou", "hu", "hua", "huai", "huan", "huang", "hui", "hun", "huo",
      "ji", "jia", "jian", "jiang", "jiao", "jie", "jin", "jing", "jiong", "jiu", "ju", "juan", "jue", "jun",
      "ka", "kai", "kan", "kang", "kao", "ke", "kei", "ken", "keng", "kong", "kou", "ku", "kua", "kuai", "kuan", "kuang", "kui", "kun", "kuo",
      "lü", "la", "lai", "lan", "lang", "lao", "le", "lüe", "lei", "leng", "li", "lia", "lian", "liang", "liao", "lie", "lin", "ling", "liu", "long", "lou", "lu", "luan", "lun", "luo",
      "m", "ma", "mai", "man", "mang", "mao", "me", "mei", "men", "meng", "mi", "mian", "miao", "mie", "min", "ming", "miu", "mo", "mou", "mu",
      "n", "nü", "na", "nai", "nan", "nang", "nao", "ne", "nüe", "nei", "nen", "neng", "ng", "ni", "nian", "niang", "niao", "nie", "nin", "ning", "niu", "nong", "nou", "nu", "nuan", "nuo",
      "o", "ou",
      "pa", "pai", "pan", "pang", "pao", "pei", "pen", "peng", "pi", "pian", "piao", "pie", "pin", "ping", "po", "pou", "pu",
      "qi", "qia", "qian", "qiang", "qiao", "qie", "qin", "qing", "qiong", "qiu", "qu", "quan", "que", "qun",
      "ran", "rang", "rao", "re", "ren", "reng", "ri", "rong", "rou", "ru", "rua", "ruan", "rui", "run", "ruo",
      "sa", "sai", "san", "sang", "sao", "se", "sei", "sen", "seng", "sha", "shai", "shan", "shang", "shao", "she", "shei", "shen", "sheng", "shi", "shou", "shu", "shua", "shuai", "shuan", "shuang", "shui", "shun", "shuo", "si", "song", "sou", "su", "suan", "sui", "sun", "suo",
      "ta", "tai", "tan", "tang", "tao", "te", "teng", "ti", "tian", "tiao", "tie", "ting", "tong", "tou", "tu", "tuan", "tui", "tun", "tuo",
      "wa", "wai", "wan", "wang", "wei", "wen", "weng", "wo", "wu",
      "xi", "xia", "xian", "xiang", "xiao", "xie", "xin", "xing", "xiong", "xiu", "xu", "xuan", "xue", "xun",
      "ya", "yan", "yang", "yao", "ye", "yi", "yin", "ying", "yong", "you", "yu", "yuan", "yue", "yun",
      "za", "zai", "zan", "zang", "zao", "ze", "zei", "zen", "zeng", "zha", "zhai", "zhan", "zhang", "zhao", "zhe", "zhei", "zhen", "zheng", "zhi", "zhong", "zhou", "zhu", "zhua", "zhuai", "zhuan", "zhuang", "zhui", "zhun", "zhuo", "zi", "zong", "zou", "zuan", "zui", "zun", "zuo", "zu",
    ]
    
    const bopomofoTable = {
      "a": "ㄚ", "ai": "ㄞ", "an": "ㄢ", "ang": "ㄤ", "ao": "ㄠ",
      "ba": "ㄅㄚ", "bai": "ㄅㄞ", "ban": "ㄅㄢ", "bang": "ㄅㄤ", "bao": "ㄅㄠ", "bei": "ㄅㄟ", "ben": "ㄅㄣ", "beng": "ㄅㄥ", "bi": "ㄅㄧ", "bian": "ㄅㄧㄢ", "biao": "ㄅㄧㄠ", "bie": "ㄅㄧㄝ", "bin": "ㄅㄧㄣ", "bing": "ㄅㄧㄥ", "bo": "ㄅㄛ", "bu": "ㄅㄨ",
      "ca": "ㄘㄚ", "cai": "ㄘㄞ", "can": "ㄘㄢ", "cang": "ㄘㄤ", "cao": "ㄘㄠ", "ce": "ㄘㄜ", "cei": "ㄘㄟ", "cen": "ㄘㄣ", "ceng": "ㄘㄥ", "cha": "ㄔㄚ", "chai": "ㄔㄞ", "chan": "ㄔㄢ", "chang": "ㄔㄤ", "chao": "ㄔㄠ", "che": "ㄔㄜ", "chen": "ㄔㄣ", "cheng": "ㄔㄥ", "chi": "ㄔ", "chong": "ㄔㄨㄥ", "chou": "ㄔㄡ", "chu": "ㄔㄨ", "chua": "ㄔㄨㄚ", "chuai": "ㄔㄨㄞ", "chuan": "ㄔㄨㄢ", "chuang": "ㄔㄨㄤ", "chui": "ㄔㄨㄟ", "chun": "ㄔㄨㄣ", "chuo": "ㄔㄨㄛ", "ci": "ㄘ", "cong": "ㄘㄨㄥ", "cou": "ㄘㄡ", "cu": "ㄘㄨ", "cuan": "ㄘㄨㄢ", "cui": "ㄘㄨㄟ", "cun": "ㄘㄨㄣ", "cuo": "ㄘㄨㄛ",
      "da": "ㄉㄚ", "dai": "ㄉㄞ", "dan": "ㄉㄢ", "dang": "ㄉㄤ", "dao": "ㄉㄠ", "de": "ㄉㄜ", "dei": "ㄉㄟ", "den": "ㄉㄣ", "deng": "ㄉㄥ", "di": "ㄉㄧ", "dia": "ㄉㄧㄚ", "dian": "ㄉㄧㄢ", "diao": "ㄉㄧㄠ", "die": "ㄉㄧㄝ", "ding": "ㄉㄧㄥ", "diu": "ㄉㄧㄡ", "dong": "ㄉㄨㄥ", "dou": "ㄉㄡ", "du": "ㄉㄨ", "duan": "ㄉㄨㄢ", "dui": "ㄉㄨㄟ", "dun": "ㄉㄨㄣ", "duo": "ㄉㄨㄛ",
      "e": "ㄜ", "ei": "ㄟ", "en": "ㄣ", "eng": "ㄥ", "er": "ㄦ",
      "fa": "ㄈㄚ", "fan": "ㄈㄢ", "fang": "ㄈㄤ", "fei": "ㄈㄟ", "fen": "ㄈㄣ", "feng": "ㄈㄥ", "fo": "ㄈㄛ", "fou": "ㄈㄡ", "fu": "ㄈㄨ",
      "ga": "ㄍㄚ", "gai": "ㄍㄞ", "gan": "ㄍㄢ", "gang": "ㄍㄤ", "gao": "ㄍㄠ", "ge": "ㄍㄜ", "gei": "ㄍㄟ", "gen": "ㄍㄣ", "geng": "ㄍㄥ", "gong": "ㄍㄨㄥ", "gou": "ㄍㄡ", "gu": "ㄍㄨ", "gua": "ㄍㄨㄚ", "guai": "ㄍㄨㄞ", "guan": "ㄍㄨㄢ", "guang": "ㄍㄨㄤ", "gui": "ㄍㄨㄟ", "gun": "ㄍㄨㄣ", "guo": "ㄍㄨㄛ",
      "ha": "ㄏㄚ", "hai": "ㄏㄞ", "han": "ㄏㄢ", "hang": "ㄏㄤ", "hao": "ㄏㄠ", "he": "ㄏㄜ", "hei": "ㄏㄟ", "hen": "ㄏㄣ", "heng": "ㄏㄥ", "hm": "ㄏㄇ", "hng": "ㄏㄫ", "hong": "ㄏㄨㄥ", "hou": "ㄏㄡ", "hu": "ㄏㄨ", "hua": "ㄏㄨㄚ", "huai": "ㄏㄨㄞ", "huan": "ㄏㄨㄢ", "huang": "ㄏㄨㄤ", "hui": "ㄏㄨㄟ", "hun": "ㄏㄨㄣ", "huo": "ㄏㄨㄛ",
      "ji": "ㄐㄧ", "jia": "ㄐㄧㄚ", "jian": "ㄐㄧㄢ", "jiang": "ㄐㄧㄤ", "jiao": "ㄐㄧㄠ", "jie": "ㄐㄧㄝ", "jin": "ㄐㄧㄣ", "jing": "ㄐㄧㄥ", "jiong": "ㄐㄩㄥ", "jiu": "ㄐㄧㄡ", "ju": "ㄐㄩ", "juan": "ㄐㄩㄢ", "jue": "ㄐㄩㄝ", "jun": "ㄐㄩㄣ",
      "ka": "ㄎㄚ", "kai": "ㄎㄞ", "kan": "ㄎㄢ", "kang": "ㄎㄤ", "kao": "ㄎㄠ", "ke": "ㄎㄜ", "kei": "ㄎㄟ", "ken": "ㄎㄣ", "keng": "ㄎㄥ", "kong": "ㄎㄨㄥ", "kou": "ㄎㄡ", "ku": "ㄎㄨ", "kua": "ㄎㄨㄚ", "kuai": "ㄎㄨㄞ", "kuan": "ㄎㄨㄢ", "kuang": "ㄎㄨㄤ", "kui": "ㄎㄨㄟ", "kun": "ㄎㄨㄣ", "kuo": "ㄎㄨㄛ",
      "la": "ㄌㄚ", "lai": "ㄌㄞ", "lan": "ㄌㄢ", "lang": "ㄌㄤ", "lao": "ㄌㄠ", "le": "ㄌㄜ", "lei": "ㄌㄟ", "leng": "ㄌㄥ", "li": "ㄌㄧ", "lia": "ㄌㄧㄚ", "lian": "ㄌㄧㄢ", "liang": "ㄌㄧㄤ", "liao": "ㄌㄧㄠ", "lie": "ㄌㄧㄝ", "lin": "ㄌㄧㄣ", "ling": "ㄌㄧㄥ", "liu": "ㄌㄧㄡ", "lo": "ㄌㄛ", "long": "ㄌㄨㄥ", "lou": "ㄌㄡ", "lu": "ㄌㄨ", "lv": "ㄌㄩ", "luan": "ㄌㄨㄢ", "lve": "ㄌㄩㄝ", "lun": "ㄌㄨㄣ", "luo": "ㄌㄨㄛ",
      "m": "ㄇ", "ma": "ㄇㄚ", "mai": "ㄇㄞ", "man": "ㄇㄢ", "mang": "ㄇㄤ", "mao": "ㄇㄠ", "me": "ㄇㄜ", "mei": "ㄇㄟ", "men": "ㄇㄣ", "meng": "ㄇㄥ", "mi": "ㄇㄧ", "mian": "ㄇㄧㄢ", "miao": "ㄇㄧㄠ", "mie": "ㄇㄧㄝ", "min": "ㄇㄧㄣ", "ming": "ㄇㄧㄥ", "miu": "ㄇㄧㄡ", "mo": "ㄇㄛ", "mou": "ㄇㄡ", "mu": "ㄇㄨ",
      "n": "ㄋ", "na": "ㄋㄚ", "nai": "ㄋㄞ", "nan": "ㄋㄢ", "nang": "ㄋㄤ", "nao": "ㄋㄠ", "ne": "ㄋㄜ", "nei": "ㄋㄟ", "nen": "ㄋㄣ", "neng": "ㄋㄥ", "ng": "ㄫ", "ni": "ㄋㄧ", "nia": "ㄋㄧㄚ", "nian": "ㄋㄧㄢ", "niang": "ㄋㄧㄤ", "niao": "ㄋㄧㄠ", "nie": "ㄋㄧㄝ", "nin": "ㄋㄧㄣ", "ning": "ㄋㄧㄥ", "niu": "ㄋㄧㄡ", "nong": "ㄋㄨㄥ", "nou": "ㄋㄡ", "nu": "ㄋㄨ", "nv": "ㄋㄩ", "nuan": "ㄋㄨㄢ", "nve": "ㄋㄩㄝ", "nuo": "ㄋㄨㄛ",
      "o": "ㄛ", "ou": "ㄡ",
      "pa": "ㄆㄚ", "pai": "ㄆㄞ", "pan": "ㄆㄢ", "pang": "ㄆㄤ", "pao": "ㄆㄠ", "pei": "ㄆㄟ", "pen": "ㄆㄣ", "peng": "ㄆㄥ", "pi": "ㄆㄧ", "pian": "ㄆㄧㄢ", "piao": "ㄆㄧㄠ", "pie": "ㄆㄧㄝ", "pin": "ㄆㄧㄣ", "ping": "ㄆㄧㄥ", "po": "ㄆㄛ", "pou": "ㄆㄡ", "pu": "ㄆㄨ",
      "qi": "ㄑㄧ", "qia": "ㄑㄧㄚ", "qian": "ㄑㄧㄢ", "qiang": "ㄑㄧㄤ", "qiao": "ㄑㄧㄠ", "qie": "ㄑㄧㄝ", "qin": "ㄑㄧㄣ", "qing": "ㄑㄧㄥ", "qiong": "ㄑㄩㄥ", "qiu": "ㄑㄧㄡ", "qu": "ㄑㄩ", "quan": "ㄑㄩㄢ", "que": "ㄑㄩㄝ", "qun": "ㄑㄩㄣ",
      "r": "ㄦ", "ran": "ㄖㄢ", "rang": "ㄖㄤ", "rao": "ㄖㄠ", "re": "ㄖㄜ", "ren": "ㄖㄣ", "reng": "ㄖㄥ", "ri": "ㄖ", "rong": "ㄖㄨㄥ", "rou": "ㄖㄡ", "ru": "ㄖㄨ", "rua": "ㄖㄨㄚ", "ruan": "ㄖㄨㄢ", "rui": "ㄖㄨㄟ", "run": "ㄖㄨㄣ", "ruo": "ㄖㄨㄛ",
      "sa": "ㄙㄚ", "sai": "ㄙㄞ", "san": "ㄙㄢ", "sang": "ㄙㄤ", "sao": "ㄙㄠ", "se": "ㄙㄜ", "sen": "ㄙㄣ", "seng": "ㄙㄥ",
      "sha": "ㄕㄚ", "shai": "ㄕㄞ", "shan": "ㄕㄢ", "shang": "ㄕㄤ", "shao": "ㄕㄠ", "she": "ㄕㄜ", "shei": "ㄕㄟ", "shen": "ㄕㄣ", "sheng": "ㄕㄥ", "shi": "ㄕ", "shou": "ㄕㄡ", "shu": "ㄕㄨ", "shua": "ㄕㄨㄚ", "shuai": "ㄕㄨㄞ", "shuan": "ㄕㄨㄢ", "shuang": "ㄕㄨㄤ", "shui": "ㄕㄨㄟ", "shun": "ㄕㄨㄣ", "shuo": "ㄕㄨㄛ",
      "si": "ㄙ", "song": "ㄙㄨㄥ", "sou": "ㄙㄡ", "su": "ㄙㄨ", "suan": "ㄙㄨㄢ", "sui": "ㄙㄨㄟ", "sun": "ㄙㄨㄣ", "suo": "ㄙㄨㄛ",
      "ta": "ㄊㄚ", "tai": "ㄊㄞ", "tan": "ㄊㄢ", "tang": "ㄊㄤ", "tao": "ㄊㄠ", "te": "ㄊㄜ", "tei": "ㄊㄟ", "teng": "ㄊㄥ", "ti": "ㄊㄧ", "tian": "ㄊㄧㄢ", "tiao": "ㄊㄧㄠ", "tie": "ㄊㄧㄝ", "ting": "ㄊㄧㄥ", "tong": "ㄊㄨㄥ", "tou": "ㄊㄡ", "tu": "ㄊㄨ", "tuan": "ㄊㄨㄢ", "tui": "ㄊㄨㄟ", "tun": "ㄊㄨㄣ", "tuo": "ㄊㄨㄛ",
      "wa": "ㄨㄚ", "wai": "ㄨㄞ", "wan": "ㄨㄢ", "wang": "ㄨㄤ", "wei": "ㄨㄟ", "wen": "ㄨㄣ", "weng": "ㄨㄥ", "wo": "ㄨㄛ", "wu": "ㄨ",
      "xi": "ㄒㄧ", "xia": "ㄒㄧㄚ", "xian": "ㄒㄧㄢ", "xiang": "ㄒㄧㄤ", "xiao": "ㄒㄧㄠ", "xie": "ㄒㄧㄝ", "xin": "ㄒㄧㄣ", "xing": "ㄒㄧㄥ", "xiong": "ㄒㄩㄥ", "xiu": "ㄒㄧㄡ", "xu": "ㄒㄩ", "xuan": "ㄒㄩㄢ", "xue": "ㄒㄩㄝ", "xun": "ㄒㄩㄣ",
      "ya": "ㄧㄚ", "yan": "ㄧㄢ", "yang": "ㄧㄤ", "yao": "ㄧㄠ", "ye": "ㄧㄝ", "yi": "ㄧ", "yin": "ㄧㄣ", "ying": "ㄧㄥ", "yo": "ㄧㄛ", "yong": "ㄩㄥ", "you": "ㄧㄡ",
      "yu": "ㄩ", "yuan": "ㄩㄢ", "yue": "ㄩㄝ", "yun": "ㄩㄣ",
      "za": "ㄗㄚ", "zai": "ㄗㄞ", "zan": "ㄗㄢ", "zang": "ㄗㄤ", "zao": "ㄗㄠ", "ze": "ㄗㄜ", "zei": "ㄗㄟ", "zen": "ㄗㄣ", "zeng": "ㄗㄥ",
      "zha": "ㄓㄚ", "zhai": "ㄓㄞ", "zhan": "ㄓㄢ", "zhang": "ㄓㄤ", "zhao": "ㄓㄠ", "zhe": "ㄓㄜ", "zhei": "ㄓㄟ", "zhen": "ㄓㄣ", "zheng": "ㄓㄥ", "zhi": "ㄓ", "zhong": "ㄓㄨㄥ", "zhou": "ㄓㄡ", "zhu": "ㄓㄨ", "zhua": "ㄓㄨㄚ", "zhuai": "ㄓㄨㄞ", "zhuan": "ㄓㄨㄢ", "zhuang": "ㄓㄨㄤ", "zhui": "ㄓㄨㄟ", "zhun": "ㄓㄨㄣ", "zhuo": "ㄓㄨㄛ",
      "zi": "ㄗ", "zong": "ㄗㄨㄥ", "zou": "ㄗㄡ", "zu": "ㄗㄨ", "zuan": "ㄗㄨㄢ", "zui": "ㄗㄨㄟ", "zun": "ㄗㄨㄣ", "zuo": "ㄗㄨㄛ"
    }
    
    const zhuyinTones = ["", "ˉ", "ˊ", "ˇ", "ˋ", "˙"]
    const tones = ['', '\u0304', '\u0301', '\u030c' /* combining caron */, '\u0300', '\u0307']
    
    const normalizePinyin = pinyin => {
      pinyin = pinyin.normalize('NFD').replace(/\u0304|\u0301|\u030c|\u0300/g, '')
      return pinyin.normalize('NFC').replace(/(\w|ü)[1-5]/gi, '$1').toLowerCase()
    }
    
    const split = (text, everything=false, wrapInList=false) => {
      const list = []
      let prevWordFound = false
      let wordEnd = text.length
      while (wordEnd > 0) {
        let count = wordEnd
        let wordFound = false
        while (count > 0) {
          const word = text.substring(wordEnd - count, wordEnd)
          if (syllables.includes(normalizePinyin(word))) {
            wordFound = true
            list.push(wrapInList ? [word] : word)
            wordEnd -= (count - 1)
            break
          }
          count--
        }
        if (!wordFound && everything) {
          const prevIndex = list.length - 1
          const prevEntry = list[prevIndex]
          if (wordEnd === text.length || typeof prevEntry === 'object' || prevWordFound) {
            list.push(text[wordEnd - 1])
          }
          else if (typeof prevEntry === 'string') {
            list[prevIndex] = text[wordEnd - 1] + prevEntry
          }
        }
        wordEnd --
        prevWordFound = wordFound
      }
      return list.reverse()
    }
    
    const getToneNumber = (str) => {
      // Check for tone number
      const matches = str.match(/[a-zü\u3100-\u312F](\d)/ui);
      if (matches) {
        return +matches[1];
      }
    
      // Check for tone mark
      for (let i = 1 /* no tone has no character */; i < tones.length; i++) {
        if (str.normalize('NFD').match(tones[i])) {
          return i
        }
      }
    
      // Check for tone character
      const lastCharacter = str[str.length - 1]
      if (zhuyinTones.includes(lastCharacter)) {
        return zhuyinTones.findIndex(v => v === lastCharacter)
      }
    
      // Return 0 as default: no tone mark
      return 0
    }
    
    const removeTone = (str) => {
      const normalizedNfd = str.normalize('NFD').replace(/\u0304|\u0301|\u030c|\u0300/g, '')
      const result = str.normalize('NFC').replace(/(\w|ü)[1-5]/gi, '$1')
    
      const lastCharacter = str[str.length - 1]
      return zhuyinTones.includes(lastCharacter)
        ? result.slice(0, -1)
        : result
    }
    
    const trim = str => str.replace(/^\s*|\s*$/g, '')
    
    const numberToMark = (syllables) => {
      const process = (pinyin) => {
        if (trim(pinyin).length === 0) return pinyin
    
        const tone = getToneNumber(pinyin)
    
        pinyin = removeTone(pinyin)
    
        if (tone !== 5 && tone !== 0) {
          if (pinyin === 'm' || pinyin === 'n' || pinyin === 'M' || pinyin === 'N') {
            return (pinyin + tones[tone]).normalize('NFC')
          }
          const matchedVovels = pinyin.match(/[aeiouü]/gi);
          if (matchedVovels) {
            let vovel = matchedVovels[matchedVovels.length - 1];
            if (pinyin.match('ou')) vovel = 'o'
            if (pinyin.match('a')) vovel = 'a'
            if (pinyin.match('e')) vovel = 'e'
            return pinyin.replace(vovel, vovel + tones[tone]).normalize('NFC')
          }
        }
        return pinyin
      }
    
      if (Array.isArray(syllables)) {
        return syllables.map(process)
      } else {
        return process(syllables)
      }
    }
    
    const toneColors = [null, 'aqua', 'lime', 'orange', 'coral', 'grey']
    const toColoredSpan = (str, toneNumber) => {
    
      const theColor = toneColors[toneNumber]
      return theColor
        ? `<span style="color: ${theColor}">${str}</span>`
        : `<span>${str}</span>`
    }
    
    const mapPinyin = (vs, f) => {
      return vs.map((v) => Array.isArray(v)
        ? v.map(f).join('')
        : v
      )
    }
    
    const colored = (dropSymbols) => (v) => {
      const toneNumber = getToneNumber(v)
      return toColoredSpan(dropSymbols ? removeTone(v) : v, toneNumber)
    }
    
    const toBopomofo = (dropSymbols) => (pinyin) => {
      const result = bopomofoTable[removeTone(pinyin).toLowerCase()]
      return dropSymbols
        ? result
        : result + zhuyinTones[getToneNumber(pinyin)]
    }
    
    const splitAndMap = (f) => (str) => mapPinyin(split(str, true, true), f).join('')
    
    // Filter Manager Setup
    const sideSensitiveStyler = closet.wrappers.sum(closet.recipes.process, closet.recipes.process, closet.deciders.isBack)
    
    const wrappedSideSensitive = closet.wrappers.aftermath(sideSensitiveStyler, (_e, internals) => {
      if (!internals.environment.has('addMandarinToneStyleTag')) {
        closet.browser.appendStyleTag(`
        .zh--tone-1 { color: dodgerblue; }
        .zh--tone-2 { color: lime; }
        .zh--tone-3 { color: yellow; }
        .zh--tone-4 { color: red; }
        .zh--tone-5 { color: grey; }`)
    
        internals.environment.set('addMandarinToneStyleTag', true)
      }
    })
    
    const removeFormatting = (v) => v.replace(/<.*?>/g, '')
    
    filterManager.install(wrappedSideSensitive({ 
      tagname: 'tf',
      optionsFalse: { processor: removeFormatting },
    }))
    
    const coloredSymbolsStylizer = splitAndMap(v => colored(true)(numberToMark(v)))
    const dropNumbersStylizer = removeTone
    
    filterManager.install(sideSensitiveStyler({ 
      tagname: 'ts',
      optionsFalse: { processor: dropNumbersStylizer },
      optionsTrue: { processor: coloredSymbolsStylizer },
    }))
    
    const simpleBopomofoStylizer = splitAndMap(toBopomofo(true))
    const coloredBopomofoStylizer = splitAndMap(v => colored(true)(toBopomofo(false)(v)))
    
    filterManager.install(sideSensitiveStyler({ 
      tagname: 'bpmf',
      optionsFalse: { processor: simpleBopomofoStylizer },
      optionsTrue: { processor: coloredBopomofoStylizer },
    }))
    
  • filterManager.install(closet.recipes.order({ tagname: 'ord' }))
    
  • const makeObscureOnKd = (keycode, uid) => {
      return function removeObscureOnKd(event) {
        if (event.keyCode === keycode) {
          const nextTarget = document.querySelector(`.cl--obscure.cl--obscure-kd-${uid}`)
    
          if (nextTarget) {
            nextTarget.classList.remove('cl--obscure')
            nextTarget.classList.remove('cl--obscure-hint')
            nextTarget.classList.remove('cl--obscure-fix')
          }
        }
      }
    }
    
    const makeObscureOnKdAll = (keycode, uid) => {
      return function removeObscureOnKdAll(event) {
        if (event.keyCode === keycode) {
          const nextTargets = document.querySelectorAll(`.cl--obscure.cl--obscure-kd-${uid}`)
    
          for (const nt of nextTargets) {
            nt.classList.remove('cl--obscure')
            nt.classList.remove('cl--obscure-hint')
            nt.classList.remove('cl--obscure-fix')
          }
        }
      }
    }
    
    const wrappedClozeShow = closet.wrappers.aftermath(closet.recipes.cloze.show, (e, inter) => {
      const keyword = 'keydownToRevealObscure'
    
      if (!inter.environment.has(keyword)) {
        closet.browser.appendStyleTag(`
        .cl--obscure-hint {
          filter: blur(0.25em);
        }
    
        .cl--obscure-fix::after {
          content: 'XXXXXXXXXX';
          filter: blur(0.25em);
        }
    
        .cl--obscure-fix > span {
          display: none;
        }`)
    
        const revealOnQ = makeObscureOnKd(KeyEvent.DOM_VK_Q, '6')
        const revealAllOnW = makeObscureOnKdAll(KeyEvent.DOM_VK_W, '5')
    
        document.addEventListener('keydown', revealOnQ)
        document.addEventListener('keydown', revealAllOnW)
    
        inter.environment.set(keyword, true)
      }
    })
    
    const obscureAndKeydown = (tag) => {
      return [`<span class="cl--obscure cl--obscure-hint cl--obscure-kd-5 cl--obscure-kd-6">${tag.values[0]}</span>`]
    }
    
    const obscureAndKeydownFix = (tag) => {
      return [`<span class="cl--obscure cl--obscure-fix cl--obscure-kd-5 cl--obscure-kd-6"><span>${tag.values[0]}</span></span>`]
    }
    
    const frontStylizer = closet.Stylizer.make({
      processor: v => `<span style="color: cornflowerblue">${v}</span>`,
    })
    
    filterManager.install(wrappedClozeShow({
      tagname: 'c',
      frontEllipser: obscureAndKeydown,
      frontStylizer: frontStylizer,
    }))
    
    filterManager.install(wrappedClozeShow({
      tagname: 'cx',
      frontEllipser: obscureAndKeydownFix,
      frontStylizer: frontStylizer,
    }))
    
  • const postprocess = (value, valueList) => (tag) => {
      return value.padEnd(valueList.reduce((accu, value) => Math.max(accu, value.length), 0), ' ')
    }
    
    filterManager.install(
      closet.recipes.pick({ tagname: 'ppick', postprocess }),
      closet.recipes.pickIndex({ tagname: 'ppi', postprocess }),
      closet.recipes.pickCardNumber({ tagname: 'psel', postprocess }),
    )
    
Template Applied