❤️超星学习通网课小助手🍆

如有问题联系QQ群:【321412228】任何问题及时联系群主更新]自动挂机看尔雅MOOC,支持视频、音频、文档、图书自动完成,章节测验自动答题提交,支持自动切换任务点、挂机阅读时长、自动登录(不可用)等,解除各类功能限制,开放自定义参数

  1. // ==UserScript==
  2. // @name ❤️超星学习通网课小助手🍆
  3. // @namespace du
  4. // @version 2.1.8
  5. // @author du
  6. // @description 如有问题联系QQ群:【321412228】任何问题及时联系群主更新]自动挂机看尔雅MOOC,支持视频、音频、文档、图书自动完成,章节测验自动答题提交,支持自动切换任务点、挂机阅读时长、自动登录(不可用)等,解除各类功能限制,开放自定义参数
  7. // @license MIT
  8. // @icon https://api.maho.cc/random-img/pc.php
  9. // @match *://*.chaoxing.com/*
  10. // @match *://*.edu.cn/*
  11. // @match *://*.nbdlib.cn/*
  12. // @match *://*.hnsyu.net/*
  13. // @match *://*.gdhkmooc.com/*
  14. // @match *://*.zhihuishu.com/*
  15. // @require https://cdn.bootcdn.net/ajax/libs/vue/3.2.36/vue.global.prod.js
  16. // @require https://cdn.bootcdn.net/ajax/libs/vue-demi/0.14.0/index.iife.js
  17. // @require data:application/javascript,window.Vue%3DVue%3B
  18. // @require https://cdn.bootcdn.net/ajax/libs/element-plus/2.3.4/index.full.min.js
  19. // @require https://cdn.bootcdn.net/ajax/libs/pinia/2.0.35/pinia.iife.min.js
  20. // @require https://cdn.bootcdn.net/ajax/libs/rxjs/7.8.0/rxjs.umd.min.js
  21. // @require https://cdn.bootcdn.net/ajax/libs/blueimp-md5/2.19.0/js/md5.min.js
  22. // @resource ElementPlus https://cdn.bootcdn.net/ajax/libs/element-plus/2.3.4/index.css
  23. // @resource ttf https://www.forestpolice.org/ttf/2.0/table.json
  24. // @connect api.tikuhai.com
  25. // @connect cx.icodef.com
  26. // @grant GM_getResourceText
  27. // @grant GM_info
  28. // @grant GM_xmlhttpRequest
  29. // @grant unsafeWindow
  30. // @run-at document-start
  31. // @antifeature ads 支持付费代看
  32. // @antifeature payment 不支持答题付费代看
  33. // ==/UserScript==
  34. (e=>{const a=document.createElement("style");a.dataset.source="vite-plugin-monkey",a.textContent=e,document.head.append(a)})(" .log[data-v-55cd8b76]{el-text[data-v-55cd8b76] {white-space: normal;}}.setting[data-v-319ccda2]{margin-top:-8px;font-size:14px}.setting[data-v-319ccda2] .el-form-item[data-v-319ccda2]{margin-bottom:0}.question_table[data-v-e4d1840f]{width:625px}.demo-tabs[data-v-6d489ae0]{margin-right:10px}.main-page[data-v-d228382d]{z-index:1000;position:fixed}.main-page .overlay[data-v-d228382d]{position:fixed;top:0;left:0;right:0;bottom:0;z-index:1001}.main-page .el-card .card-header[data-v-d228382d]{display:flex;justify-content:space-between;flex-direction:row;align-items:center;margin:0;padding:0;cursor:move}.main-page .el-card .card-header .title[data-v-d228382d]{font-size:14px;display:flex;align-items:center;justify-content:center;font-weight:700}.main-page[data-v-d228382d] .el-card__header{height:34.5px;background-color:#1f71e0;color:#fff;padding:7px 10px 7px 16px;margin:0}.main-page[data-v-d228382d] .el-card__body{padding:0 6px 20px 16px}.main-page[data-v-d228382d] .el-tabs__nav-wrap:after{height:1px}.main-page[data-v-d228382d] .el-tabs__active-bar{background-color:#176ae5}.main-page[data-v-d228382d] .el-tabs__item{font-size:13px;height:34px}.main-page[data-v-d228382d] .el-tabs__item.is-top{font-weight:400;color:#4e5969;padding:0 8px 0 12px}.main-page[data-v-d228382d] .el-tabs__item.is-active{font-weight:500;color:#176ae5;padding:0 8px 0 12px}.content[data-v-d228382d]{width:370px} ");
  35. (function (vue, pinia, rxjs, md5, ElementPlus) {
  36. 'use strict';
  37. var __defProp = Object.defineProperty;
  38. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  39. var __publicField = (obj, key, value) => {
  40. __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  41. return value;
  42. };
  43. /*! Element Plus Icons Vue v2.1.0 */
  44. var export_helper_default = (sfc, props) => {
  45. let target = sfc.__vccOpts || sfc;
  46. for (let [key, val] of props)
  47. target[key] = val;
  48. return target;
  49. };
  50. var document_remove_vue_vue_type_script_lang_default = {
  51. name: "DocumentRemove"
  52. };
  53. var _hoisted_189 = {
  54. xmlns: "http://www.w3.org/2000/svg",
  55. viewBox: "0 0 1024 1024"
  56. }, _hoisted_289 = /* @__PURE__ */ vue.createElementVNode(
  57. "path",
  58. {
  59. fill: "currentColor",
  60. d: "M805.504 320 640 154.496V320h165.504zM832 384H576V128H192v768h640V384zM160 64h480l256 256v608a32 32 0 0 1-32 32H160a32 32 0 0 1-32-32V96a32 32 0 0 1 32-32zm192 512h320v64H352v-64z"
  61. },
  62. null,
  63. -1
  64. /* HOISTED */
  65. ), _hoisted_388 = [
  66. _hoisted_289
  67. ];
  68. function _sfc_render89(_ctx, _cache, $props, $setup, $data, $options) {
  69. return vue.openBlock(), vue.createElementBlock("svg", _hoisted_189, _hoisted_388);
  70. }
  71. var document_remove_default = /* @__PURE__ */ export_helper_default(document_remove_vue_vue_type_script_lang_default, [["render", _sfc_render89], ["__file", "document-remove.vue"]]);
  72. var full_screen_vue_vue_type_script_lang_default = {
  73. name: "FullScreen"
  74. };
  75. var _hoisted_1118 = {
  76. xmlns: "http://www.w3.org/2000/svg",
  77. viewBox: "0 0 1024 1024"
  78. }, _hoisted_2118 = /* @__PURE__ */ vue.createElementVNode(
  79. "path",
  80. {
  81. fill: "currentColor",
  82. d: "m160 96.064 192 .192a32 32 0 0 1 0 64l-192-.192V352a32 32 0 0 1-64 0V96h64v.064zm0 831.872V928H96V672a32 32 0 1 1 64 0v191.936l192-.192a32 32 0 1 1 0 64l-192 .192zM864 96.064V96h64v256a32 32 0 1 1-64 0V160.064l-192 .192a32 32 0 1 1 0-64l192-.192zm0 831.872-192-.192a32 32 0 0 1 0-64l192 .192V672a32 32 0 1 1 64 0v256h-64v-.064z"
  83. },
  84. null,
  85. -1
  86. /* HOISTED */
  87. ), _hoisted_3117 = [
  88. _hoisted_2118
  89. ];
  90. function _sfc_render118(_ctx, _cache, $props, $setup, $data, $options) {
  91. return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1118, _hoisted_3117);
  92. }
  93. var full_screen_default = /* @__PURE__ */ export_helper_default(full_screen_vue_vue_type_script_lang_default, [["render", _sfc_render118], ["__file", "full-screen.vue"]]);
  94. var minus_vue_vue_type_script_lang_default = {
  95. name: "Minus"
  96. };
  97. var _hoisted_1169 = {
  98. xmlns: "http://www.w3.org/2000/svg",
  99. viewBox: "0 0 1024 1024"
  100. }, _hoisted_2169 = /* @__PURE__ */ vue.createElementVNode(
  101. "path",
  102. {
  103. fill: "currentColor",
  104. d: "M128 544h768a32 32 0 1 0 0-64H128a32 32 0 0 0 0 64z"
  105. },
  106. null,
  107. -1
  108. /* HOISTED */
  109. ), _hoisted_3168 = [
  110. _hoisted_2169
  111. ];
  112. function _sfc_render169(_ctx, _cache, $props, $setup, $data, $options) {
  113. return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1169, _hoisted_3168);
  114. }
  115. var minus_default = /* @__PURE__ */ export_helper_default(minus_vue_vue_type_script_lang_default, [["render", _sfc_render169], ["__file", "minus.vue"]]);
  116. var position_vue_vue_type_script_lang_default = {
  117. name: "Position"
  118. };
  119. var _hoisted_1203 = {
  120. xmlns: "http://www.w3.org/2000/svg",
  121. viewBox: "0 0 1024 1024"
  122. }, _hoisted_2203 = /* @__PURE__ */ vue.createElementVNode(
  123. "path",
  124. {
  125. fill: "currentColor",
  126. d: "m249.6 417.088 319.744 43.072 39.168 310.272L845.12 178.88 249.6 417.088zm-129.024 47.168a32 32 0 0 1-7.68-61.44l777.792-311.04a32 32 0 0 1 41.6 41.6l-310.336 775.68a32 32 0 0 1-61.44-7.808L512 516.992l-391.424-52.736z"
  127. },
  128. null,
  129. -1
  130. /* HOISTED */
  131. ), _hoisted_3202 = [
  132. _hoisted_2203
  133. ];
  134. function _sfc_render203(_ctx, _cache, $props, $setup, $data, $options) {
  135. return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1203, _hoisted_3202);
  136. }
  137. var position_default = /* @__PURE__ */ export_helper_default(position_vue_vue_type_script_lang_default, [["render", _sfc_render203], ["__file", "position.vue"]]);
  138. var setting_vue_vue_type_script_lang_default = {
  139. name: "Setting"
  140. };
  141. var _hoisted_1231 = {
  142. xmlns: "http://www.w3.org/2000/svg",
  143. viewBox: "0 0 1024 1024"
  144. }, _hoisted_2231 = /* @__PURE__ */ vue.createElementVNode(
  145. "path",
  146. {
  147. fill: "currentColor",
  148. d: "M600.704 64a32 32 0 0 1 30.464 22.208l35.2 109.376c14.784 7.232 28.928 15.36 42.432 24.512l112.384-24.192a32 32 0 0 1 34.432 15.36L944.32 364.8a32 32 0 0 1-4.032 37.504l-77.12 85.12a357.12 357.12 0 0 1 0 49.024l77.12 85.248a32 32 0 0 1 4.032 37.504l-88.704 153.6a32 32 0 0 1-34.432 15.296L708.8 803.904c-13.44 9.088-27.648 17.28-42.368 24.512l-35.264 109.376A32 32 0 0 1 600.704 960H423.296a32 32 0 0 1-30.464-22.208L357.696 828.48a351.616 351.616 0 0 1-42.56-24.64l-112.32 24.256a32 32 0 0 1-34.432-15.36L79.68 659.2a32 32 0 0 1 4.032-37.504l77.12-85.248a357.12 357.12 0 0 1 0-48.896l-77.12-85.248A32 32 0 0 1 79.68 364.8l88.704-153.6a32 32 0 0 1 34.432-15.296l112.32 24.256c13.568-9.152 27.776-17.408 42.56-24.64l35.2-109.312A32 32 0 0 1 423.232 64H600.64zm-23.424 64H446.72l-36.352 113.088-24.512 11.968a294.113 294.113 0 0 0-34.816 20.096l-22.656 15.36-116.224-25.088-65.28 113.152 79.68 88.192-1.92 27.136a293.12 293.12 0 0 0 0 40.192l1.92 27.136-79.808 88.192 65.344 113.152 116.224-25.024 22.656 15.296a294.113 294.113 0 0 0 34.816 20.096l24.512 11.968L446.72 896h130.688l36.48-113.152 24.448-11.904a288.282 288.282 0 0 0 34.752-20.096l22.592-15.296 116.288 25.024 65.28-113.152-79.744-88.192 1.92-27.136a293.12 293.12 0 0 0 0-40.256l-1.92-27.136 79.808-88.128-65.344-113.152-116.288 24.96-22.592-15.232a287.616 287.616 0 0 0-34.752-20.096l-24.448-11.904L577.344 128zM512 320a192 192 0 1 1 0 384 192 192 0 0 1 0-384zm0 64a128 128 0 1 0 0 256 128 128 0 0 0 0-256z"
  149. },
  150. null,
  151. -1
  152. /* HOISTED */
  153. ), _hoisted_3230 = [
  154. _hoisted_2231
  155. ];
  156. function _sfc_render231(_ctx, _cache, $props, $setup, $data, $options) {
  157. return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1231, _hoisted_3230);
  158. }
  159. var setting_default = /* @__PURE__ */ export_helper_default(setting_vue_vue_type_script_lang_default, [["render", _sfc_render231], ["__file", "setting.vue"]]);
  160. var view_vue_vue_type_script_lang_default = {
  161. name: "View"
  162. };
  163. var _hoisted_1283 = {
  164. xmlns: "http://www.w3.org/2000/svg",
  165. viewBox: "0 0 1024 1024"
  166. }, _hoisted_2283 = /* @__PURE__ */ vue.createElementVNode(
  167. "path",
  168. {
  169. fill: "currentColor",
  170. d: "M512 160c320 0 512 352 512 352S832 864 512 864 0 512 0 512s192-352 512-352zm0 64c-225.28 0-384.128 208.064-436.8 288 52.608 79.872 211.456 288 436.8 288 225.28 0 384.128-208.064 436.8-288-52.608-79.872-211.456-288-436.8-288zm0 64a224 224 0 1 1 0 448 224 224 0 0 1 0-448zm0 64a160.192 160.192 0 0 0-160 160c0 88.192 71.744 160 160 160s160-71.808 160-160-71.744-160-160-160z"
  171. },
  172. null,
  173. -1
  174. /* HOISTED */
  175. ), _hoisted_3282 = [
  176. _hoisted_2283
  177. ];
  178. function _sfc_render283(_ctx, _cache, $props, $setup, $data, $options) {
  179. return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1283, _hoisted_3282);
  180. }
  181. var view_default = /* @__PURE__ */ export_helper_default(view_vue_vue_type_script_lang_default, [["render", _sfc_render283], ["__file", "view.vue"]]);
  182. var warning_vue_vue_type_script_lang_default = {
  183. name: "Warning"
  184. };
  185. var _hoisted_1288 = {
  186. xmlns: "http://www.w3.org/2000/svg",
  187. viewBox: "0 0 1024 1024"
  188. }, _hoisted_2288 = /* @__PURE__ */ vue.createElementVNode(
  189. "path",
  190. {
  191. fill: "currentColor",
  192. d: "M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 832a384 384 0 0 0 0-768 384 384 0 0 0 0 768zm48-176a48 48 0 1 1-96 0 48 48 0 0 1 96 0zm-48-464a32 32 0 0 1 32 32v288a32 32 0 0 1-64 0V288a32 32 0 0 1 32-32z"
  193. },
  194. null,
  195. -1
  196. /* HOISTED */
  197. ), _hoisted_3287 = [
  198. _hoisted_2288
  199. ];
  200. function _sfc_render288(_ctx, _cache, $props, $setup, $data, $options) {
  201. return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1288, _hoisted_3287);
  202. }
  203. var warning_default = /* @__PURE__ */ export_helper_default(warning_vue_vue_type_script_lang_default, [["render", _sfc_render288], ["__file", "warning.vue"]]);
  204. var _GM_getResourceText = /* @__PURE__ */ (() => typeof GM_getResourceText != "undefined" ? GM_getResourceText : void 0)();
  205. var _GM_info = /* @__PURE__ */ (() => typeof GM_info != "undefined" ? GM_info : void 0)();
  206. var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)();
  207. var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  208. const getScriptInfo = () => {
  209. return {
  210. name: _GM_info.script.name,
  211. namespace: _GM_info.script.namespace,
  212. version: _GM_info.script.version,
  213. description: _GM_info.script.description
  214. };
  215. };
  216. const useConfigStore = pinia.defineStore("configStore", {
  217. state: () => {
  218. const scriptInfo = getScriptInfo();
  219. const defaultConfig = {
  220. version: scriptInfo.version,
  221. isMinus: false,
  222. position: {
  223. x: "800px",
  224. y: "200px"
  225. },
  226. menuIndex: "0",
  227. platformName: "cx",
  228. platformParams: {
  229. cx: {
  230. name: "超星网课dd助手",
  231. parts: [
  232. {
  233. name: "章节设置",
  234. params: [
  235. // {
  236. // name: '视频速率',
  237. // value: 1,
  238. // type: 'number',
  239. // },
  240. {
  241. name: "章节是否自动提交",
  242. value: false,
  243. type: "boolean"
  244. },
  245. {
  246. name: "是否自动下一章节",
  247. value: true,
  248. type: "boolean"
  249. }
  250. ]
  251. },
  252. {
  253. name: "考试设置",
  254. params: [{
  255. name: "是否自动切换",
  256. value: true,
  257. type: "boolean"
  258. }]
  259. }
  260. ]
  261. },
  262. zhs: {
  263. name: "智慧树网课dd助手",
  264. parts: [{
  265. name: "答题设置",
  266. params: [{
  267. name: "是否自动切换",
  268. value: true,
  269. type: "boolean"
  270. }]
  271. }]
  272. },
  273. unknown: {
  274. name: "未知平台",
  275. parts: [{
  276. name: "答题设置",
  277. params: [{
  278. name: "是否自动切换",
  279. value: true,
  280. type: "boolean"
  281. }]
  282. }]
  283. }
  284. },
  285. // 没答案自动选择
  286. otherParams: {
  287. name: "其他参数",
  288. params: [
  289. // {
  290. // name: '没答案随机选择',
  291. // value: true,
  292. // type: 'boolean',
  293. // },
  294. {
  295. name: "切换、答题间隔,单位秒",
  296. value: 3,
  297. type: "number"
  298. },
  299. {
  300. name: "正确率达到多少自动提交",
  301. value: 80,
  302. type: "number"
  303. }
  304. ]
  305. },
  306. queryApis: [
  307. {
  308. name: "海量题库",
  309. token: "",
  310. url: "http://www.dubainow.top/index/index"
  311. }
  312. // {
  313. // name: '一之题库',
  314. // token: '',
  315. // url: "http://www.dubainow.top/index/index"
  316. // }
  317. ]
  318. };
  319. let globalConfig = defaultConfig;
  320. const storedConfig = localStorage.getItem("config");
  321. if (storedConfig) {
  322. try {
  323. const parsedStoredConfig = JSON.parse(storedConfig);
  324. if (scriptInfo.version === parsedStoredConfig.version) {
  325. globalConfig = parsedStoredConfig;
  326. }
  327. } catch (error) {
  328. console.error(error);
  329. }
  330. }
  331. localStorage.setItem("globalConfig", JSON.stringify(globalConfig));
  332. return globalConfig;
  333. },
  334. actions: {}
  335. });
  336. const formatDateTime = (dt) => {
  337. dt.getFullYear();
  338. dt.getMonth() + 1;
  339. dt.getDate();
  340. let hours = dt.getHours();
  341. let minutes = dt.getMinutes();
  342. let seconds = dt.getSeconds();
  343. return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
  344. };
  345. const pad = (n) => {
  346. return n < 10 ? "0" + n : n.toString();
  347. };
  348. const getDateTime = () => {
  349. let now = /* @__PURE__ */ new Date();
  350. return formatDateTime(now);
  351. };
  352. const useLogStore = pinia.defineStore("logStore", {
  353. state: () => ({
  354. logList: []
  355. }),
  356. actions: {
  357. addLog(message, type) {
  358. const log = {
  359. message,
  360. time: getDateTime(),
  361. type
  362. };
  363. this.logList.push(log);
  364. }
  365. }
  366. });
  367. const useQuestionStore = pinia.defineStore("questionStore", {
  368. state: () => ({
  369. questionList: []
  370. }),
  371. actions: {
  372. addQuestion(question) {
  373. this.questionList.push(question);
  374. }
  375. }
  376. });
  377. const _hoisted_1$4 = /* @__PURE__ */ vue.createTextVNode(" ");
  378. const _sfc_main$7 = /* @__PURE__ */ vue.defineComponent({
  379. name: "index",
  380. props: {
  381. logList: {
  382. type: Array,
  383. required: true
  384. }
  385. },
  386. setup(__props) {
  387. return (_ctx, _cache) => {
  388. const _component_el_text = vue.resolveComponent("el-text");
  389. const _component_el_divider = vue.resolveComponent("el-divider");
  390. const _component_el_scrollbar = vue.resolveComponent("el-scrollbar");
  391. return vue.openBlock(), vue.createElementBlock("div", null, [
  392. vue.createVNode(_component_el_divider, {
  393. style: { "margin": "0 0 4px 0" },
  394. "border-style": "dashed"
  395. }, {
  396. default: vue.withCtx(() => [
  397. vue.createVNode(_component_el_text, { style: { "font-size": "12px", "font-weight": "normal", "color": "#909399" } })
  398. ]),
  399. _: 1
  400. }),
  401. vue.createVNode(_component_el_scrollbar, {
  402. always: "",
  403. class: "log",
  404. "max-height": "230px"
  405. }, {
  406. default: vue.withCtx(() => [
  407. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.logList, (item, index) => {
  408. return vue.openBlock(), vue.createElementBlock("div", { key: index }, [
  409. vue.createVNode(_component_el_text, {
  410. size: "small",
  411. style: { "font-weight": "normal" },
  412. type: "info"
  413. }, {
  414. default: vue.withCtx(() => [
  415. vue.createTextVNode(vue.toDisplayString(item.time), 1)
  416. ]),
  417. _: 2
  418. }, 1024),
  419. vue.createVNode(_component_el_text, null, {
  420. default: vue.withCtx(() => [
  421. _hoisted_1$4
  422. ]),
  423. _: 1
  424. }),
  425. vue.createVNode(_component_el_text, {
  426. type: item.type ? item.type : "primary",
  427. size: "small",
  428. innerHTML: item.message
  429. }, null, 8, ["type", "innerHTML"]),
  430. vue.createVNode(_component_el_divider, {
  431. "border-style": "dashed",
  432. style: { "margin": "0" }
  433. })
  434. ]);
  435. }), 128))
  436. ]),
  437. _: 1
  438. })
  439. ]);
  440. };
  441. }
  442. });
  443. const _export_sfc = (sfc, props) => {
  444. const target = sfc.__vccOpts || sfc;
  445. for (const [key, val] of props) {
  446. target[key] = val;
  447. }
  448. return target;
  449. };
  450. const ScriptHome = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-55cd8b76"]]);
  451. const _hoisted_1$3 = { class: "setting" };
  452. const _hoisted_2$3 = { style: { "font-size": "13px" } };
  453. const _hoisted_3$2 = { style: { "font-size": "13px" } };
  454. const _sfc_main$6 = /* @__PURE__ */ vue.defineComponent({
  455. name: "index",
  456. props: {
  457. globalConfig: {
  458. type: Object,
  459. required: true
  460. }
  461. },
  462. setup(__props) {
  463. return (_ctx, _cache) => {
  464. const _component_el_divider = vue.resolveComponent("el-divider");
  465. const _component_el_checkbox = vue.resolveComponent("el-checkbox");
  466. const _component_el_input_number = vue.resolveComponent("el-input-number");
  467. const _component_el_form_item = vue.resolveComponent("el-form-item");
  468. return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$3, [
  469. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.globalConfig.platformParams[__props.globalConfig.platformName].parts, (item, index) => {
  470. return vue.openBlock(), vue.createElementBlock("div", { key: index }, [
  471. vue.createVNode(_component_el_divider, { "border-style": "dashed" }, {
  472. default: vue.withCtx(() => [
  473. vue.createElementVNode("span", _hoisted_2$3, vue.toDisplayString(item.name), 1)
  474. ]),
  475. _: 2
  476. }, 1024),
  477. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(item.params, (param, index2) => {
  478. return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
  479. param.type === "boolean" ? (vue.openBlock(), vue.createBlock(_component_el_checkbox, {
  480. key: index2,
  481. modelValue: param.value,
  482. "onUpdate:modelValue": ($event) => param.value = $event,
  483. label: param.name,
  484. size: "small"
  485. }, null, 8, ["modelValue", "onUpdate:modelValue", "label"])) : (vue.openBlock(), vue.createBlock(_component_el_form_item, {
  486. key: 1,
  487. label: param.name,
  488. required: ""
  489. }, {
  490. default: vue.withCtx(() => [
  491. vue.createVNode(_component_el_input_number, {
  492. modelValue: param.value,
  493. "onUpdate:modelValue": ($event) => param.value = $event,
  494. min: 3e3,
  495. step: 1e3,
  496. "controls-position": "right",
  497. size: "small"
  498. }, null, 8, ["modelValue", "onUpdate:modelValue"])
  499. ]),
  500. _: 2
  501. }, 1032, ["label"]))
  502. ], 64);
  503. }), 256))
  504. ]);
  505. }), 128)),
  506. vue.createElementVNode("div", null, [
  507. vue.createVNode(_component_el_divider, { "border-style": "dashed" }, {
  508. default: vue.withCtx(() => [
  509. vue.createElementVNode("span", _hoisted_3$2, vue.toDisplayString(__props.globalConfig.otherParams.name), 1)
  510. ]),
  511. _: 1
  512. }),
  513. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.globalConfig.otherParams.params, (item, index) => {
  514. return vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: index }, [
  515. item.type === "boolean" ? (vue.openBlock(), vue.createBlock(_component_el_checkbox, {
  516. key: 0,
  517. modelValue: item.value,
  518. "onUpdate:modelValue": ($event) => item.value = $event,
  519. size: "small"
  520. }, null, 8, ["modelValue", "onUpdate:modelValue"])) : (vue.openBlock(), vue.createBlock(_component_el_form_item, {
  521. key: 1,
  522. style: { "margin-top": "6px" },
  523. label: item.name,
  524. required: "",
  525. size: "small"
  526. }, {
  527. default: vue.withCtx(() => [
  528. vue.createVNode(_component_el_input_number, {
  529. modelValue: item.value,
  530. "onUpdate:modelValue": ($event) => item.value = $event,
  531. min: 3,
  532. max: 100,
  533. step: 1,
  534. size: "small"
  535. }, null, 8, ["modelValue", "onUpdate:modelValue"])
  536. ]),
  537. _: 2
  538. }, 1032, ["label"]))
  539. ], 64);
  540. }), 128))
  541. ])
  542. ]);
  543. };
  544. }
  545. });
  546. const ScriptSetting = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["__scopeId", "data-v-319ccda2"]]);
  547. const _hoisted_1$2 = /* @__PURE__ */ vue.createTextVNode("代看地址:yy.ffwk.life");
  548. const _hoisted_2$2 = { class: "question_table" };
  549. const _hoisted_3$1 = ["innerHTML"];
  550. const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
  551. name: "QuestionTable",
  552. props: {
  553. questionList: {
  554. type: Array,
  555. required: true
  556. }
  557. },
  558. setup(__props) {
  559. const configStore = useConfigStore();
  560. return (_ctx, _cache) => {
  561. const _component_el_button = vue.resolveComponent("el-button");
  562. const _component_el_input = vue.resolveComponent("el-input");
  563. const _component_el_table_column = vue.resolveComponent("el-table-column");
  564. const _component_el_table = vue.resolveComponent("el-table");
  565. const _component_el_empty = vue.resolveComponent("el-empty");
  566. return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
  567. vue.createVNode(_component_el_input, {
  568. style: { "font-size": "12px" },
  569. modelValue: vue.unref(configStore).queryApis[0].token,
  570. "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vue.unref(configStore).queryApis[0].token = $event),
  571. placeholder: "复制地址http://www.dubainow.top/index/index到浏览器即可QQ群321412228"
  572. }, {
  573. prepend: vue.withCtx(() => [
  574. vue.createVNode(_component_el_button, { style: { "border-radius": "0" } }, {
  575. default: vue.withCtx(() => [
  576. _hoisted_1$2
  577. ]),
  578. _: 1
  579. })
  580. ]),
  581. _: 1
  582. }, 8, ["modelValue"]),
  583. vue.withDirectives(vue.createElementVNode("div", _hoisted_2$2, [
  584. vue.createVNode(_component_el_table, {
  585. stripe: "",
  586. data: __props.questionList,
  587. "max-height": "400",
  588. style: { "font-size": "12px" }
  589. }, {
  590. default: vue.withCtx(() => [
  591. vue.createVNode(_component_el_table_column, {
  592. type: "index",
  593. width: "40"
  594. }),
  595. vue.createVNode(_component_el_table_column, {
  596. prop: "title",
  597. label: "题目",
  598. width: "370"
  599. }),
  600. vue.createVNode(_component_el_table_column, {
  601. style: { "background-color": "red" },
  602. prop: "answer",
  603. label: "答案",
  604. width: "215"
  605. }, {
  606. default: vue.withCtx((scope) => [
  607. vue.createElementVNode("div", {
  608. innerHTML: scope.row.answer.join()
  609. }, null, 8, _hoisted_3$1)
  610. ]),
  611. _: 1
  612. })
  613. ]),
  614. _: 1
  615. }, 8, ["data"])
  616. ], 512), [
  617. [vue.vShow, __props.questionList.length]
  618. ]),
  619. vue.withDirectives(vue.createElementVNode("div", null, [
  620. vue.createVNode(_component_el_empty, { description: "复制地址http://www.dubainow.top/index/index到浏览器即可" })
  621. ], 512), [
  622. [vue.vShow, !__props.questionList.length]
  623. ])
  624. ], 64);
  625. };
  626. }
  627. });
  628. const QuestionTable = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-e4d1840f"]]);
  629. const _sfc_main$4 = {};
  630. const _hoisted_1$1 = { style: { "font-size": "12px" } };
  631. const _hoisted_2$1 = /* @__PURE__ */ vue.createTextVNode(" 代看地址:");
  632. const _hoisted_3 = /* @__PURE__ */ vue.createElementVNode("a", null , "http://www.dubainow.top/index/index", -1);
  633. const _hoisted_4 = [
  634. _hoisted_2$1,
  635. _hoisted_3
  636. ];
  637. function _sfc_render(_ctx, _cache) {
  638. return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, _hoisted_4);
  639. }
  640. const OpenCode = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render]]);
  641. function isFunction(value) {
  642. return typeof value === "function";
  643. }
  644. function hasLift(source) {
  645. return isFunction(source === null || source === void 0 ? void 0 : source.lift);
  646. }
  647. function operate(init) {
  648. return function(source) {
  649. if (hasLift(source)) {
  650. return source.lift(function(liftedSource) {
  651. try {
  652. return init(liftedSource, this);
  653. } catch (err) {
  654. this.error(err);
  655. }
  656. });
  657. }
  658. throw new TypeError("Unable to lift unknown Observable type");
  659. };
  660. }
  661. var extendStatics = function(d, b) {
  662. extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
  663. d2.__proto__ = b2;
  664. } || function(d2, b2) {
  665. for (var p in b2)
  666. if (Object.prototype.hasOwnProperty.call(b2, p))
  667. d2[p] = b2[p];
  668. };
  669. return extendStatics(d, b);
  670. };
  671. function __extends(d, b) {
  672. if (typeof b !== "function" && b !== null)
  673. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  674. extendStatics(d, b);
  675. function __() {
  676. this.constructor = d;
  677. }
  678. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  679. }
  680. function __awaiter(thisArg, _arguments, P, generator) {
  681. function adopt(value) {
  682. return value instanceof P ? value : new P(function(resolve) {
  683. resolve(value);
  684. });
  685. }
  686. return new (P || (P = Promise))(function(resolve, reject) {
  687. function fulfilled(value) {
  688. try {
  689. step(generator.next(value));
  690. } catch (e) {
  691. reject(e);
  692. }
  693. }
  694. function rejected(value) {
  695. try {
  696. step(generator["throw"](value));
  697. } catch (e) {
  698. reject(e);
  699. }
  700. }
  701. function step(result) {
  702. result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
  703. }
  704. step((generator = generator.apply(thisArg, _arguments || [])).next());
  705. });
  706. }
  707. function __generator(thisArg, body) {
  708. var _ = { label: 0, sent: function() {
  709. if (t[0] & 1)
  710. throw t[1];
  711. return t[1];
  712. }, trys: [], ops: [] }, f, y, t, g;
  713. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
  714. return this;
  715. }), g;
  716. function verb(n) {
  717. return function(v) {
  718. return step([n, v]);
  719. };
  720. }
  721. function step(op) {
  722. if (f)
  723. throw new TypeError("Generator is already executing.");
  724. while (g && (g = 0, op[0] && (_ = 0)), _)
  725. try {
  726. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
  727. return t;
  728. if (y = 0, t)
  729. op = [op[0] & 2, t.value];
  730. switch (op[0]) {
  731. case 0:
  732. case 1:
  733. t = op;
  734. break;
  735. case 4:
  736. _.label++;
  737. return { value: op[1], done: false };
  738. case 5:
  739. _.label++;
  740. y = op[1];
  741. op = [0];
  742. continue;
  743. case 7:
  744. op = _.ops.pop();
  745. _.trys.pop();
  746. continue;
  747. default:
  748. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  749. _ = 0;
  750. continue;
  751. }
  752. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  753. _.label = op[1];
  754. break;
  755. }
  756. if (op[0] === 6 && _.label < t[1]) {
  757. _.label = t[1];
  758. t = op;
  759. break;
  760. }
  761. if (t && _.label < t[2]) {
  762. _.label = t[2];
  763. _.ops.push(op);
  764. break;
  765. }
  766. if (t[2])
  767. _.ops.pop();
  768. _.trys.pop();
  769. continue;
  770. }
  771. op = body.call(thisArg, _);
  772. } catch (e) {
  773. op = [6, e];
  774. y = 0;
  775. } finally {
  776. f = t = 0;
  777. }
  778. if (op[0] & 5)
  779. throw op[1];
  780. return { value: op[0] ? op[1] : void 0, done: true };
  781. }
  782. }
  783. function __values(o) {
  784. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  785. if (m)
  786. return m.call(o);
  787. if (o && typeof o.length === "number")
  788. return {
  789. next: function() {
  790. if (o && i >= o.length)
  791. o = void 0;
  792. return { value: o && o[i++], done: !o };
  793. }
  794. };
  795. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  796. }
  797. function __read(o, n) {
  798. var m = typeof Symbol === "function" && o[Symbol.iterator];
  799. if (!m)
  800. return o;
  801. var i = m.call(o), r, ar = [], e;
  802. try {
  803. while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
  804. ar.push(r.value);
  805. } catch (error) {
  806. e = { error };
  807. } finally {
  808. try {
  809. if (r && !r.done && (m = i["return"]))
  810. m.call(i);
  811. } finally {
  812. if (e)
  813. throw e.error;
  814. }
  815. }
  816. return ar;
  817. }
  818. function __spreadArray(to, from2, pack) {
  819. if (pack || arguments.length === 2)
  820. for (var i = 0, l = from2.length, ar; i < l; i++) {
  821. if (ar || !(i in from2)) {
  822. if (!ar)
  823. ar = Array.prototype.slice.call(from2, 0, i);
  824. ar[i] = from2[i];
  825. }
  826. }
  827. return to.concat(ar || Array.prototype.slice.call(from2));
  828. }
  829. function __await(v) {
  830. return this instanceof __await ? (this.v = v, this) : new __await(v);
  831. }
  832. function __asyncGenerator(thisArg, _arguments, generator) {
  833. if (!Symbol.asyncIterator)
  834. throw new TypeError("Symbol.asyncIterator is not defined.");
  835. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  836. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
  837. return this;
  838. }, i;
  839. function verb(n) {
  840. if (g[n])
  841. i[n] = function(v) {
  842. return new Promise(function(a, b) {
  843. q.push([n, v, a, b]) > 1 || resume(n, v);
  844. });
  845. };
  846. }
  847. function resume(n, v) {
  848. try {
  849. step(g[n](v));
  850. } catch (e) {
  851. settle(q[0][3], e);
  852. }
  853. }
  854. function step(r) {
  855. r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
  856. }
  857. function fulfill(value) {
  858. resume("next", value);
  859. }
  860. function reject(value) {
  861. resume("throw", value);
  862. }
  863. function settle(f, v) {
  864. if (f(v), q.shift(), q.length)
  865. resume(q[0][0], q[0][1]);
  866. }
  867. }
  868. function __asyncValues(o) {
  869. if (!Symbol.asyncIterator)
  870. throw new TypeError("Symbol.asyncIterator is not defined.");
  871. var m = o[Symbol.asyncIterator], i;
  872. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
  873. return this;
  874. }, i);
  875. function verb(n) {
  876. i[n] = o[n] && function(v) {
  877. return new Promise(function(resolve, reject) {
  878. v = o[n](v), settle(resolve, reject, v.done, v.value);
  879. });
  880. };
  881. }
  882. function settle(resolve, reject, d, v) {
  883. Promise.resolve(v).then(function(v2) {
  884. resolve({ value: v2, done: d });
  885. }, reject);
  886. }
  887. }
  888. var isArrayLike = function(x) {
  889. return x && typeof x.length === "number" && typeof x !== "function";
  890. };
  891. function isPromise(value) {
  892. return isFunction(value === null || value === void 0 ? void 0 : value.then);
  893. }
  894. function createErrorClass(createImpl) {
  895. var _super = function(instance) {
  896. Error.call(instance);
  897. instance.stack = new Error().stack;
  898. };
  899. var ctorFunc = createImpl(_super);
  900. ctorFunc.prototype = Object.create(Error.prototype);
  901. ctorFunc.prototype.constructor = ctorFunc;
  902. return ctorFunc;
  903. }
  904. var UnsubscriptionError = createErrorClass(function(_super) {
  905. return function UnsubscriptionErrorImpl(errors) {
  906. _super(this);
  907. this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err, i) {
  908. return i + 1 + ") " + err.toString();
  909. }).join("\n ") : "";
  910. this.name = "UnsubscriptionError";
  911. this.errors = errors;
  912. };
  913. });
  914. function arrRemove(arr, item) {
  915. if (arr) {
  916. var index = arr.indexOf(item);
  917. 0 <= index && arr.splice(index, 1);
  918. }
  919. }
  920. var Subscription = function() {
  921. function Subscription2(initialTeardown) {
  922. this.initialTeardown = initialTeardown;
  923. this.closed = false;
  924. this._parentage = null;
  925. this._finalizers = null;
  926. }
  927. Subscription2.prototype.unsubscribe = function() {
  928. var e_1, _a, e_2, _b;
  929. var errors;
  930. if (!this.closed) {
  931. this.closed = true;
  932. var _parentage = this._parentage;
  933. if (_parentage) {
  934. this._parentage = null;
  935. if (Array.isArray(_parentage)) {
  936. try {
  937. for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
  938. var parent_1 = _parentage_1_1.value;
  939. parent_1.remove(this);
  940. }
  941. } catch (e_1_1) {
  942. e_1 = { error: e_1_1 };
  943. } finally {
  944. try {
  945. if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return))
  946. _a.call(_parentage_1);
  947. } finally {
  948. if (e_1)
  949. throw e_1.error;
  950. }
  951. }
  952. } else {
  953. _parentage.remove(this);
  954. }
  955. }
  956. var initialFinalizer = this.initialTeardown;
  957. if (isFunction(initialFinalizer)) {
  958. try {
  959. initialFinalizer();
  960. } catch (e) {
  961. errors = e instanceof UnsubscriptionError ? e.errors : [e];
  962. }
  963. }
  964. var _finalizers = this._finalizers;
  965. if (_finalizers) {
  966. this._finalizers = null;
  967. try {
  968. for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
  969. var finalizer = _finalizers_1_1.value;
  970. try {
  971. execFinalizer(finalizer);
  972. } catch (err) {
  973. errors = errors !== null && errors !== void 0 ? errors : [];
  974. if (err instanceof UnsubscriptionError) {
  975. errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
  976. } else {
  977. errors.push(err);
  978. }
  979. }
  980. }
  981. } catch (e_2_1) {
  982. e_2 = { error: e_2_1 };
  983. } finally {
  984. try {
  985. if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return))
  986. _b.call(_finalizers_1);
  987. } finally {
  988. if (e_2)
  989. throw e_2.error;
  990. }
  991. }
  992. }
  993. if (errors) {
  994. throw new UnsubscriptionError(errors);
  995. }
  996. }
  997. };
  998. Subscription2.prototype.add = function(teardown) {
  999. var _a;
  1000. if (teardown && teardown !== this) {
  1001. if (this.closed) {
  1002. execFinalizer(teardown);
  1003. } else {
  1004. if (teardown instanceof Subscription2) {
  1005. if (teardown.closed || teardown._hasParent(this)) {
  1006. return;
  1007. }
  1008. teardown._addParent(this);
  1009. }
  1010. (this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
  1011. }
  1012. }
  1013. };
  1014. Subscription2.prototype._hasParent = function(parent) {
  1015. var _parentage = this._parentage;
  1016. return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
  1017. };
  1018. Subscription2.prototype._addParent = function(parent) {
  1019. var _parentage = this._parentage;
  1020. this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
  1021. };
  1022. Subscription2.prototype._removeParent = function(parent) {
  1023. var _parentage = this._parentage;
  1024. if (_parentage === parent) {
  1025. this._parentage = null;
  1026. } else if (Array.isArray(_parentage)) {
  1027. arrRemove(_parentage, parent);
  1028. }
  1029. };
  1030. Subscription2.prototype.remove = function(teardown) {
  1031. var _finalizers = this._finalizers;
  1032. _finalizers && arrRemove(_finalizers, teardown);
  1033. if (teardown instanceof Subscription2) {
  1034. teardown._removeParent(this);
  1035. }
  1036. };
  1037. Subscription2.EMPTY = function() {
  1038. var empty = new Subscription2();
  1039. empty.closed = true;
  1040. return empty;
  1041. }();
  1042. return Subscription2;
  1043. }();
  1044. Subscription.EMPTY;
  1045. function isSubscription(value) {
  1046. return value instanceof Subscription || value && "closed" in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
  1047. }
  1048. function execFinalizer(finalizer) {
  1049. if (isFunction(finalizer)) {
  1050. finalizer();
  1051. } else {
  1052. finalizer.unsubscribe();
  1053. }
  1054. }
  1055. var config = {
  1056. onUnhandledError: null,
  1057. onStoppedNotification: null,
  1058. Promise: void 0,
  1059. useDeprecatedSynchronousErrorHandling: false,
  1060. useDeprecatedNextContext: false
  1061. };
  1062. var timeoutProvider = {
  1063. setTimeout: function(handler, timeout) {
  1064. var args = [];
  1065. for (var _i = 2; _i < arguments.length; _i++) {
  1066. args[_i - 2] = arguments[_i];
  1067. }
  1068. return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
  1069. },
  1070. clearTimeout: function(handle) {
  1071. return (clearTimeout)(handle);
  1072. },
  1073. delegate: void 0
  1074. };
  1075. function reportUnhandledError(err) {
  1076. timeoutProvider.setTimeout(function() {
  1077. {
  1078. throw err;
  1079. }
  1080. });
  1081. }
  1082. function noop() {
  1083. }
  1084. function errorContext(cb) {
  1085. {
  1086. cb();
  1087. }
  1088. }
  1089. var Subscriber = function(_super) {
  1090. __extends(Subscriber2, _super);
  1091. function Subscriber2(destination) {
  1092. var _this = _super.call(this) || this;
  1093. _this.isStopped = false;
  1094. if (destination) {
  1095. _this.destination = destination;
  1096. if (isSubscription(destination)) {
  1097. destination.add(_this);
  1098. }
  1099. } else {
  1100. _this.destination = EMPTY_OBSERVER;
  1101. }
  1102. return _this;
  1103. }
  1104. Subscriber2.create = function(next, error, complete) {
  1105. return new SafeSubscriber(next, error, complete);
  1106. };
  1107. Subscriber2.prototype.next = function(value) {
  1108. if (this.isStopped)
  1109. ;
  1110. else {
  1111. this._next(value);
  1112. }
  1113. };
  1114. Subscriber2.prototype.error = function(err) {
  1115. if (this.isStopped)
  1116. ;
  1117. else {
  1118. this.isStopped = true;
  1119. this._error(err);
  1120. }
  1121. };
  1122. Subscriber2.prototype.complete = function() {
  1123. if (this.isStopped)
  1124. ;
  1125. else {
  1126. this.isStopped = true;
  1127. this._complete();
  1128. }
  1129. };
  1130. Subscriber2.prototype.unsubscribe = function() {
  1131. if (!this.closed) {
  1132. this.isStopped = true;
  1133. _super.prototype.unsubscribe.call(this);
  1134. this.destination = null;
  1135. }
  1136. };
  1137. Subscriber2.prototype._next = function(value) {
  1138. this.destination.next(value);
  1139. };
  1140. Subscriber2.prototype._error = function(err) {
  1141. try {
  1142. this.destination.error(err);
  1143. } finally {
  1144. this.unsubscribe();
  1145. }
  1146. };
  1147. Subscriber2.prototype._complete = function() {
  1148. try {
  1149. this.destination.complete();
  1150. } finally {
  1151. this.unsubscribe();
  1152. }
  1153. };
  1154. return Subscriber2;
  1155. }(Subscription);
  1156. var _bind = Function.prototype.bind;
  1157. function bind(fn, thisArg) {
  1158. return _bind.call(fn, thisArg);
  1159. }
  1160. var ConsumerObserver = function() {
  1161. function ConsumerObserver2(partialObserver) {
  1162. this.partialObserver = partialObserver;
  1163. }
  1164. ConsumerObserver2.prototype.next = function(value) {
  1165. var partialObserver = this.partialObserver;
  1166. if (partialObserver.next) {
  1167. try {
  1168. partialObserver.next(value);
  1169. } catch (error) {
  1170. handleUnhandledError(error);
  1171. }
  1172. }
  1173. };
  1174. ConsumerObserver2.prototype.error = function(err) {
  1175. var partialObserver = this.partialObserver;
  1176. if (partialObserver.error) {
  1177. try {
  1178. partialObserver.error(err);
  1179. } catch (error) {
  1180. handleUnhandledError(error);
  1181. }
  1182. } else {
  1183. handleUnhandledError(err);
  1184. }
  1185. };
  1186. ConsumerObserver2.prototype.complete = function() {
  1187. var partialObserver = this.partialObserver;
  1188. if (partialObserver.complete) {
  1189. try {
  1190. partialObserver.complete();
  1191. } catch (error) {
  1192. handleUnhandledError(error);
  1193. }
  1194. }
  1195. };
  1196. return ConsumerObserver2;
  1197. }();
  1198. var SafeSubscriber = function(_super) {
  1199. __extends(SafeSubscriber2, _super);
  1200. function SafeSubscriber2(observerOrNext, error, complete) {
  1201. var _this = _super.call(this) || this;
  1202. var partialObserver;
  1203. if (isFunction(observerOrNext) || !observerOrNext) {
  1204. partialObserver = {
  1205. next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : void 0,
  1206. error: error !== null && error !== void 0 ? error : void 0,
  1207. complete: complete !== null && complete !== void 0 ? complete : void 0
  1208. };
  1209. } else {
  1210. var context_1;
  1211. if (_this && config.useDeprecatedNextContext) {
  1212. context_1 = Object.create(observerOrNext);
  1213. context_1.unsubscribe = function() {
  1214. return _this.unsubscribe();
  1215. };
  1216. partialObserver = {
  1217. next: observerOrNext.next && bind(observerOrNext.next, context_1),
  1218. error: observerOrNext.error && bind(observerOrNext.error, context_1),
  1219. complete: observerOrNext.complete && bind(observerOrNext.complete, context_1)
  1220. };
  1221. } else {
  1222. partialObserver = observerOrNext;
  1223. }
  1224. }
  1225. _this.destination = new ConsumerObserver(partialObserver);
  1226. return _this;
  1227. }
  1228. return SafeSubscriber2;
  1229. }(Subscriber);
  1230. function handleUnhandledError(error) {
  1231. {
  1232. reportUnhandledError(error);
  1233. }
  1234. }
  1235. function defaultErrorHandler(err) {
  1236. throw err;
  1237. }
  1238. var EMPTY_OBSERVER = {
  1239. closed: true,
  1240. next: noop,
  1241. error: defaultErrorHandler,
  1242. complete: noop
  1243. };
  1244. var observable = function() {
  1245. return typeof Symbol === "function" && Symbol.observable || "@@observable";
  1246. }();
  1247. function identity(x) {
  1248. return x;
  1249. }
  1250. function pipeFromArray(fns) {
  1251. if (fns.length === 0) {
  1252. return identity;
  1253. }
  1254. if (fns.length === 1) {
  1255. return fns[0];
  1256. }
  1257. return function piped(input) {
  1258. return fns.reduce(function(prev, fn) {
  1259. return fn(prev);
  1260. }, input);
  1261. };
  1262. }
  1263. var Observable = function() {
  1264. function Observable2(subscribe) {
  1265. if (subscribe) {
  1266. this._subscribe = subscribe;
  1267. }
  1268. }
  1269. Observable2.prototype.lift = function(operator) {
  1270. var observable2 = new Observable2();
  1271. observable2.source = this;
  1272. observable2.operator = operator;
  1273. return observable2;
  1274. };
  1275. Observable2.prototype.subscribe = function(observerOrNext, error, complete) {
  1276. var _this = this;
  1277. var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
  1278. errorContext(function() {
  1279. var _a = _this, operator = _a.operator, source = _a.source;
  1280. subscriber.add(operator ? operator.call(subscriber, source) : source ? _this._subscribe(subscriber) : _this._trySubscribe(subscriber));
  1281. });
  1282. return subscriber;
  1283. };
  1284. Observable2.prototype._trySubscribe = function(sink) {
  1285. try {
  1286. return this._subscribe(sink);
  1287. } catch (err) {
  1288. sink.error(err);
  1289. }
  1290. };
  1291. Observable2.prototype.forEach = function(next, promiseCtor) {
  1292. var _this = this;
  1293. promiseCtor = getPromiseCtor(promiseCtor);
  1294. return new promiseCtor(function(resolve, reject) {
  1295. var subscriber = new SafeSubscriber({
  1296. next: function(value) {
  1297. try {
  1298. next(value);
  1299. } catch (err) {
  1300. reject(err);
  1301. subscriber.unsubscribe();
  1302. }
  1303. },
  1304. error: reject,
  1305. complete: resolve
  1306. });
  1307. _this.subscribe(subscriber);
  1308. });
  1309. };
  1310. Observable2.prototype._subscribe = function(subscriber) {
  1311. var _a;
  1312. return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
  1313. };
  1314. Observable2.prototype[observable] = function() {
  1315. return this;
  1316. };
  1317. Observable2.prototype.pipe = function() {
  1318. var operations = [];
  1319. for (var _i = 0; _i < arguments.length; _i++) {
  1320. operations[_i] = arguments[_i];
  1321. }
  1322. return pipeFromArray(operations)(this);
  1323. };
  1324. Observable2.prototype.toPromise = function(promiseCtor) {
  1325. var _this = this;
  1326. promiseCtor = getPromiseCtor(promiseCtor);
  1327. return new promiseCtor(function(resolve, reject) {
  1328. var value;
  1329. _this.subscribe(function(x) {
  1330. return value = x;
  1331. }, function(err) {
  1332. return reject(err);
  1333. }, function() {
  1334. return resolve(value);
  1335. });
  1336. });
  1337. };
  1338. Observable2.create = function(subscribe) {
  1339. return new Observable2(subscribe);
  1340. };
  1341. return Observable2;
  1342. }();
  1343. function getPromiseCtor(promiseCtor) {
  1344. var _a;
  1345. return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
  1346. }
  1347. function isObserver(value) {
  1348. return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
  1349. }
  1350. function isSubscriber(value) {
  1351. return value && value instanceof Subscriber || isObserver(value) && isSubscription(value);
  1352. }
  1353. function isInteropObservable(input) {
  1354. return isFunction(input[observable]);
  1355. }
  1356. function isAsyncIterable(obj) {
  1357. return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
  1358. }
  1359. function createInvalidObservableTypeError(input) {
  1360. return new TypeError("You provided " + (input !== null && typeof input === "object" ? "an invalid object" : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
  1361. }
  1362. function getSymbolIterator() {
  1363. if (typeof Symbol !== "function" || !Symbol.iterator) {
  1364. return "@@iterator";
  1365. }
  1366. return Symbol.iterator;
  1367. }
  1368. var iterator = getSymbolIterator();
  1369. function isIterable(input) {
  1370. return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
  1371. }
  1372. function readableStreamLikeToAsyncGenerator(readableStream) {
  1373. return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
  1374. var reader, _a, value, done;
  1375. return __generator(this, function(_b) {
  1376. switch (_b.label) {
  1377. case 0:
  1378. reader = readableStream.getReader();
  1379. _b.label = 1;
  1380. case 1:
  1381. _b.trys.push([1, , 9, 10]);
  1382. _b.label = 2;
  1383. case 2:
  1384. return [4, __await(reader.read())];
  1385. case 3:
  1386. _a = _b.sent(), value = _a.value, done = _a.done;
  1387. if (!done)
  1388. return [3, 5];
  1389. return [4, __await(void 0)];
  1390. case 4:
  1391. return [2, _b.sent()];
  1392. case 5:
  1393. return [4, __await(value)];
  1394. case 6:
  1395. return [4, _b.sent()];
  1396. case 7:
  1397. _b.sent();
  1398. return [3, 2];
  1399. case 8:
  1400. return [3, 10];
  1401. case 9:
  1402. reader.releaseLock();
  1403. return [7];
  1404. case 10:
  1405. return [2];
  1406. }
  1407. });
  1408. });
  1409. }
  1410. function isReadableStreamLike(obj) {
  1411. return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
  1412. }
  1413. function innerFrom(input) {
  1414. if (input instanceof Observable) {
  1415. return input;
  1416. }
  1417. if (input != null) {
  1418. if (isInteropObservable(input)) {
  1419. return fromInteropObservable(input);
  1420. }
  1421. if (isArrayLike(input)) {
  1422. return fromArrayLike(input);
  1423. }
  1424. if (isPromise(input)) {
  1425. return fromPromise(input);
  1426. }
  1427. if (isAsyncIterable(input)) {
  1428. return fromAsyncIterable(input);
  1429. }
  1430. if (isIterable(input)) {
  1431. return fromIterable(input);
  1432. }
  1433. if (isReadableStreamLike(input)) {
  1434. return fromReadableStreamLike(input);
  1435. }
  1436. }
  1437. throw createInvalidObservableTypeError(input);
  1438. }
  1439. function fromInteropObservable(obj) {
  1440. return new Observable(function(subscriber) {
  1441. var obs = obj[observable]();
  1442. if (isFunction(obs.subscribe)) {
  1443. return obs.subscribe(subscriber);
  1444. }
  1445. throw new TypeError("Provided object does not correctly implement Symbol.observable");
  1446. });
  1447. }
  1448. function fromArrayLike(array) {
  1449. return new Observable(function(subscriber) {
  1450. for (var i = 0; i < array.length && !subscriber.closed; i++) {
  1451. subscriber.next(array[i]);
  1452. }
  1453. subscriber.complete();
  1454. });
  1455. }
  1456. function fromPromise(promise) {
  1457. return new Observable(function(subscriber) {
  1458. promise.then(function(value) {
  1459. if (!subscriber.closed) {
  1460. subscriber.next(value);
  1461. subscriber.complete();
  1462. }
  1463. }, function(err) {
  1464. return subscriber.error(err);
  1465. }).then(null, reportUnhandledError);
  1466. });
  1467. }
  1468. function fromIterable(iterable) {
  1469. return new Observable(function(subscriber) {
  1470. var e_1, _a;
  1471. try {
  1472. for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
  1473. var value = iterable_1_1.value;
  1474. subscriber.next(value);
  1475. if (subscriber.closed) {
  1476. return;
  1477. }
  1478. }
  1479. } catch (e_1_1) {
  1480. e_1 = { error: e_1_1 };
  1481. } finally {
  1482. try {
  1483. if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return))
  1484. _a.call(iterable_1);
  1485. } finally {
  1486. if (e_1)
  1487. throw e_1.error;
  1488. }
  1489. }
  1490. subscriber.complete();
  1491. });
  1492. }
  1493. function fromAsyncIterable(asyncIterable) {
  1494. return new Observable(function(subscriber) {
  1495. process(asyncIterable, subscriber).catch(function(err) {
  1496. return subscriber.error(err);
  1497. });
  1498. });
  1499. }
  1500. function fromReadableStreamLike(readableStream) {
  1501. return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
  1502. }
  1503. function process(asyncIterable, subscriber) {
  1504. var asyncIterable_1, asyncIterable_1_1;
  1505. var e_2, _a;
  1506. return __awaiter(this, void 0, void 0, function() {
  1507. var value, e_2_1;
  1508. return __generator(this, function(_b) {
  1509. switch (_b.label) {
  1510. case 0:
  1511. _b.trys.push([0, 5, 6, 11]);
  1512. asyncIterable_1 = __asyncValues(asyncIterable);
  1513. _b.label = 1;
  1514. case 1:
  1515. return [4, asyncIterable_1.next()];
  1516. case 2:
  1517. if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done))
  1518. return [3, 4];
  1519. value = asyncIterable_1_1.value;
  1520. subscriber.next(value);
  1521. if (subscriber.closed) {
  1522. return [2];
  1523. }
  1524. _b.label = 3;
  1525. case 3:
  1526. return [3, 1];
  1527. case 4:
  1528. return [3, 11];
  1529. case 5:
  1530. e_2_1 = _b.sent();
  1531. e_2 = { error: e_2_1 };
  1532. return [3, 11];
  1533. case 6:
  1534. _b.trys.push([6, , 9, 10]);
  1535. if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return)))
  1536. return [3, 8];
  1537. return [4, _a.call(asyncIterable_1)];
  1538. case 7:
  1539. _b.sent();
  1540. _b.label = 8;
  1541. case 8:
  1542. return [3, 10];
  1543. case 9:
  1544. if (e_2)
  1545. throw e_2.error;
  1546. return [7];
  1547. case 10:
  1548. return [7];
  1549. case 11:
  1550. subscriber.complete();
  1551. return [2];
  1552. }
  1553. });
  1554. });
  1555. }
  1556. function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
  1557. return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
  1558. }
  1559. var OperatorSubscriber = function(_super) {
  1560. __extends(OperatorSubscriber2, _super);
  1561. function OperatorSubscriber2(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
  1562. var _this = _super.call(this, destination) || this;
  1563. _this.onFinalize = onFinalize;
  1564. _this.shouldUnsubscribe = shouldUnsubscribe;
  1565. _this._next = onNext ? function(value) {
  1566. try {
  1567. onNext(value);
  1568. } catch (err) {
  1569. destination.error(err);
  1570. }
  1571. } : _super.prototype._next;
  1572. _this._error = onError ? function(err) {
  1573. try {
  1574. onError(err);
  1575. } catch (err2) {
  1576. destination.error(err2);
  1577. } finally {
  1578. this.unsubscribe();
  1579. }
  1580. } : _super.prototype._error;
  1581. _this._complete = onComplete ? function() {
  1582. try {
  1583. onComplete();
  1584. } catch (err) {
  1585. destination.error(err);
  1586. } finally {
  1587. this.unsubscribe();
  1588. }
  1589. } : _super.prototype._complete;
  1590. return _this;
  1591. }
  1592. OperatorSubscriber2.prototype.unsubscribe = function() {
  1593. var _a;
  1594. if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
  1595. var closed_1 = this.closed;
  1596. _super.prototype.unsubscribe.call(this);
  1597. !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
  1598. }
  1599. };
  1600. return OperatorSubscriber2;
  1601. }(Subscriber);
  1602. function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
  1603. if (delay === void 0) {
  1604. delay = 0;
  1605. }
  1606. if (repeat === void 0) {
  1607. repeat = false;
  1608. }
  1609. var scheduleSubscription = scheduler.schedule(function() {
  1610. work();
  1611. if (repeat) {
  1612. parentSubscription.add(this.schedule(null, delay));
  1613. } else {
  1614. this.unsubscribe();
  1615. }
  1616. }, delay);
  1617. parentSubscription.add(scheduleSubscription);
  1618. if (!repeat) {
  1619. return scheduleSubscription;
  1620. }
  1621. }
  1622. function map(project, thisArg) {
  1623. return operate(function(source, subscriber) {
  1624. var index = 0;
  1625. source.subscribe(createOperatorSubscriber(subscriber, function(value) {
  1626. subscriber.next(project.call(thisArg, value, index++));
  1627. }));
  1628. });
  1629. }
  1630. function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
  1631. var buffer = [];
  1632. var active = 0;
  1633. var index = 0;
  1634. var isComplete = false;
  1635. var checkComplete = function() {
  1636. if (isComplete && !buffer.length && !active) {
  1637. subscriber.complete();
  1638. }
  1639. };
  1640. var outerNext = function(value) {
  1641. return active < concurrent ? doInnerSub(value) : buffer.push(value);
  1642. };
  1643. var doInnerSub = function(value) {
  1644. expand && subscriber.next(value);
  1645. active++;
  1646. var innerComplete = false;
  1647. innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function(innerValue) {
  1648. onBeforeNext === null || onBeforeNext === void 0 ? void 0 : onBeforeNext(innerValue);
  1649. if (expand) {
  1650. outerNext(innerValue);
  1651. } else {
  1652. subscriber.next(innerValue);
  1653. }
  1654. }, function() {
  1655. innerComplete = true;
  1656. }, void 0, function() {
  1657. if (innerComplete) {
  1658. try {
  1659. active--;
  1660. var _loop_1 = function() {
  1661. var bufferedValue = buffer.shift();
  1662. if (innerSubScheduler) {
  1663. executeSchedule(subscriber, innerSubScheduler, function() {
  1664. return doInnerSub(bufferedValue);
  1665. });
  1666. } else {
  1667. doInnerSub(bufferedValue);
  1668. }
  1669. };
  1670. while (buffer.length && active < concurrent) {
  1671. _loop_1();
  1672. }
  1673. checkComplete();
  1674. } catch (err) {
  1675. subscriber.error(err);
  1676. }
  1677. }
  1678. }));
  1679. };
  1680. source.subscribe(createOperatorSubscriber(subscriber, outerNext, function() {
  1681. isComplete = true;
  1682. checkComplete();
  1683. }));
  1684. return function() {
  1685. additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
  1686. };
  1687. }
  1688. function mergeMap(project, resultSelector, concurrent) {
  1689. if (concurrent === void 0) {
  1690. concurrent = Infinity;
  1691. }
  1692. if (isFunction(resultSelector)) {
  1693. return mergeMap(function(a, i) {
  1694. return map(function(b, ii) {
  1695. return resultSelector(a, b, i, ii);
  1696. })(innerFrom(project(a, i)));
  1697. }, concurrent);
  1698. } else if (typeof resultSelector === "number") {
  1699. concurrent = resultSelector;
  1700. }
  1701. return operate(function(source, subscriber) {
  1702. return mergeInternals(source, subscriber, project, concurrent);
  1703. });
  1704. }
  1705. function mergeAll(concurrent) {
  1706. if (concurrent === void 0) {
  1707. concurrent = Infinity;
  1708. }
  1709. return mergeMap(identity, concurrent);
  1710. }
  1711. function concatAll() {
  1712. return mergeAll(1);
  1713. }
  1714. function concatMap(project, resultSelector) {
  1715. return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
  1716. }
  1717. class IframeUtils {
  1718. static getIframes(element) {
  1719. return Array.from(element.querySelectorAll("iframe"));
  1720. }
  1721. static getAllNestedIframes(element) {
  1722. const iframes = IframeUtils.getIframes(element);
  1723. if (iframes.length === 0) {
  1724. return rxjs.of([]);
  1725. } else {
  1726. return rxjs.from(iframes).pipe(
  1727. mergeMap(
  1728. (iframe) => new rxjs.Observable((subscriber) => {
  1729. if (iframe.contentDocument && iframe.contentDocument.readyState === "complete") {
  1730. const iframeDocument = iframe.contentDocument;
  1731. const nestedIframes = IframeUtils.getAllNestedIframes(iframeDocument.documentElement);
  1732. nestedIframes.subscribe((nestedIframes2) => {
  1733. subscriber.next([iframe, ...nestedIframes2]);
  1734. subscriber.complete();
  1735. });
  1736. } else {
  1737. rxjs.fromEvent(iframe, "load").pipe(
  1738. map(() => {
  1739. if (iframe.contentDocument) {
  1740. return iframe.contentDocument.documentElement;
  1741. } else {
  1742. return document.createElement("div");
  1743. }
  1744. }),
  1745. map((doc) => IframeUtils.getAllNestedIframes(doc)),
  1746. concatAll()
  1747. ).subscribe((nestedIframes) => {
  1748. subscriber.next([iframe, ...nestedIframes]);
  1749. subscriber.complete();
  1750. });
  1751. }
  1752. })
  1753. ),
  1754. concatAll(),
  1755. rxjs.toArray()
  1756. );
  1757. }
  1758. }
  1759. }
  1760. class XMLHttpRequestInterceptor {
  1761. constructor(urlList, callback) {
  1762. __publicField(this, "xhr");
  1763. __publicField(this, "originalOpen");
  1764. __publicField(this, "callback");
  1765. this.xhr = new XMLHttpRequest();
  1766. this.originalOpen = this.xhr.open;
  1767. this.callback = callback;
  1768. this.intercept(urlList);
  1769. }
  1770. intercept(urlList) {
  1771. const self = this;
  1772. XMLHttpRequest.prototype.open = function(method, url2, async, user, password) {
  1773. if (urlList.some((urlItem) => url2.includes(urlItem))) {
  1774. self.callback(method, url2);
  1775. }
  1776. return self.originalOpen.apply(this, [method, url2, async, user, password]);
  1777. };
  1778. }
  1779. }
  1780. var Typr$1 = {};
  1781. var Typr = {};
  1782. Typr.parse = function(buff) {
  1783. var bin = Typr._bin;
  1784. var data = new Uint8Array(buff);
  1785. var tag = bin.readASCII(data, 0, 4);
  1786. if (tag == "ttcf") {
  1787. var offset = 4;
  1788. bin.readUshort(data, offset);
  1789. offset += 2;
  1790. bin.readUshort(data, offset);
  1791. offset += 2;
  1792. var numF = bin.readUint(data, offset);
  1793. offset += 4;
  1794. var fnts = [];
  1795. for (var i = 0; i < numF; i++) {
  1796. var foff = bin.readUint(data, offset);
  1797. offset += 4;
  1798. fnts.push(Typr._readFont(data, foff));
  1799. }
  1800. return fnts;
  1801. } else
  1802. return [Typr._readFont(data, 0)];
  1803. };
  1804. Typr._readFont = function(data, offset) {
  1805. var bin = Typr._bin;
  1806. var ooff = offset;
  1807. bin.readFixed(data, offset);
  1808. offset += 4;
  1809. var numTables = bin.readUshort(data, offset);
  1810. offset += 2;
  1811. bin.readUshort(data, offset);
  1812. offset += 2;
  1813. bin.readUshort(data, offset);
  1814. offset += 2;
  1815. bin.readUshort(data, offset);
  1816. offset += 2;
  1817. var tags = [
  1818. "cmap",
  1819. "head",
  1820. "hhea",
  1821. "maxp",
  1822. "hmtx",
  1823. "name",
  1824. "OS/2",
  1825. "post",
  1826. //"cvt",
  1827. //"fpgm",
  1828. "loca",
  1829. "glyf",
  1830. "kern",
  1831. //"prep"
  1832. //"gasp"
  1833. "CFF ",
  1834. "GPOS",
  1835. "GSUB",
  1836. "SVG "
  1837. //"VORG",
  1838. ];
  1839. var obj = { _data: data, _offset: ooff };
  1840. var tabs = {};
  1841. for (var i = 0; i < numTables; i++) {
  1842. var tag = bin.readASCII(data, offset, 4);
  1843. offset += 4;
  1844. bin.readUint(data, offset);
  1845. offset += 4;
  1846. var toffset = bin.readUint(data, offset);
  1847. offset += 4;
  1848. var length = bin.readUint(data, offset);
  1849. offset += 4;
  1850. tabs[tag] = { offset: toffset, length };
  1851. }
  1852. for (var i = 0; i < tags.length; i++) {
  1853. var t = tags[i];
  1854. if (tabs[t])
  1855. obj[t.trim()] = Typr[t.trim()].parse(data, tabs[t].offset, tabs[t].length, obj);
  1856. }
  1857. return obj;
  1858. };
  1859. Typr._tabOffset = function(data, tab, foff) {
  1860. var bin = Typr._bin;
  1861. var numTables = bin.readUshort(data, foff + 4);
  1862. var offset = foff + 12;
  1863. for (var i = 0; i < numTables; i++) {
  1864. var tag = bin.readASCII(data, offset, 4);
  1865. offset += 4;
  1866. bin.readUint(data, offset);
  1867. offset += 4;
  1868. var toffset = bin.readUint(data, offset);
  1869. offset += 4;
  1870. bin.readUint(data, offset);
  1871. offset += 4;
  1872. if (tag == tab)
  1873. return toffset;
  1874. }
  1875. return 0;
  1876. };
  1877. Typr._bin = {
  1878. readFixed: function(data, o) {
  1879. return (data[o] << 8 | data[o + 1]) + (data[o + 2] << 8 | data[o + 3]) / (256 * 256 + 4);
  1880. },
  1881. readF2dot14: function(data, o) {
  1882. var num = Typr._bin.readShort(data, o);
  1883. return num / 16384;
  1884. },
  1885. readInt: function(buff, p) {
  1886. return Typr._bin._view(buff).getInt32(p);
  1887. },
  1888. readInt8: function(buff, p) {
  1889. return Typr._bin._view(buff).getInt8(p);
  1890. },
  1891. readShort: function(buff, p) {
  1892. return Typr._bin._view(buff).getInt16(p);
  1893. },
  1894. readUshort: function(buff, p) {
  1895. return Typr._bin._view(buff).getUint16(p);
  1896. },
  1897. readUshorts: function(buff, p, len) {
  1898. var arr = [];
  1899. for (var i = 0; i < len; i++)
  1900. arr.push(Typr._bin.readUshort(buff, p + i * 2));
  1901. return arr;
  1902. },
  1903. readUint: function(buff, p) {
  1904. return Typr._bin._view(buff).getUint32(p);
  1905. },
  1906. readUint64: function(buff, p) {
  1907. return Typr._bin.readUint(buff, p) * (4294967295 + 1) + Typr._bin.readUint(buff, p + 4);
  1908. },
  1909. readASCII: function(buff, p, l) {
  1910. var s = "";
  1911. for (var i = 0; i < l; i++)
  1912. s += String.fromCharCode(buff[p + i]);
  1913. return s;
  1914. },
  1915. readUnicode: function(buff, p, l) {
  1916. var s = "";
  1917. for (var i = 0; i < l; i++) {
  1918. var c = buff[p++] << 8 | buff[p++];
  1919. s += String.fromCharCode(c);
  1920. }
  1921. return s;
  1922. },
  1923. _tdec: typeof window !== "undefined" && window["TextDecoder"] ? new window["TextDecoder"]() : null,
  1924. readUTF8: function(buff, p, l) {
  1925. var tdec = Typr._bin._tdec;
  1926. if (tdec && p == 0 && l == buff.length)
  1927. return tdec["decode"](buff);
  1928. return Typr._bin.readASCII(buff, p, l);
  1929. },
  1930. readBytes: function(buff, p, l) {
  1931. var arr = [];
  1932. for (var i = 0; i < l; i++)
  1933. arr.push(buff[p + i]);
  1934. return arr;
  1935. },
  1936. readASCIIArray: function(buff, p, l) {
  1937. var s = [];
  1938. for (var i = 0; i < l; i++)
  1939. s.push(String.fromCharCode(buff[p + i]));
  1940. return s;
  1941. },
  1942. _view: function(buff) {
  1943. return buff._dataView || (buff._dataView = buff.buffer ? new DataView(buff.buffer, buff.byteOffset, buff.byteLength) : new DataView(new Uint8Array(buff).buffer));
  1944. }
  1945. };
  1946. Typr._lctf = {};
  1947. Typr._lctf.parse = function(data, offset, length, font, subt) {
  1948. var bin = Typr._bin;
  1949. var obj = {};
  1950. var offset0 = offset;
  1951. bin.readFixed(data, offset);
  1952. offset += 4;
  1953. var offScriptList = bin.readUshort(data, offset);
  1954. offset += 2;
  1955. var offFeatureList = bin.readUshort(data, offset);
  1956. offset += 2;
  1957. var offLookupList = bin.readUshort(data, offset);
  1958. offset += 2;
  1959. obj.scriptList = Typr._lctf.readScriptList(data, offset0 + offScriptList);
  1960. obj.featureList = Typr._lctf.readFeatureList(data, offset0 + offFeatureList);
  1961. obj.lookupList = Typr._lctf.readLookupList(data, offset0 + offLookupList, subt);
  1962. return obj;
  1963. };
  1964. Typr._lctf.readLookupList = function(data, offset, subt) {
  1965. var bin = Typr._bin;
  1966. var offset0 = offset;
  1967. var obj = [];
  1968. var count = bin.readUshort(data, offset);
  1969. offset += 2;
  1970. for (var i = 0; i < count; i++) {
  1971. var noff = bin.readUshort(data, offset);
  1972. offset += 2;
  1973. var lut = Typr._lctf.readLookupTable(data, offset0 + noff, subt);
  1974. obj.push(lut);
  1975. }
  1976. return obj;
  1977. };
  1978. Typr._lctf.readLookupTable = function(data, offset, subt) {
  1979. var bin = Typr._bin;
  1980. var offset0 = offset;
  1981. var obj = { tabs: [] };
  1982. obj.ltype = bin.readUshort(data, offset);
  1983. offset += 2;
  1984. obj.flag = bin.readUshort(data, offset);
  1985. offset += 2;
  1986. var cnt = bin.readUshort(data, offset);
  1987. offset += 2;
  1988. var ltype = obj.ltype;
  1989. for (var i = 0; i < cnt; i++) {
  1990. var noff = bin.readUshort(data, offset);
  1991. offset += 2;
  1992. var tab = subt(data, ltype, offset0 + noff, obj);
  1993. obj.tabs.push(tab);
  1994. }
  1995. return obj;
  1996. };
  1997. Typr._lctf.numOfOnes = function(n) {
  1998. var num = 0;
  1999. for (var i = 0; i < 32; i++)
  2000. if ((n >>> i & 1) != 0)
  2001. num++;
  2002. return num;
  2003. };
  2004. Typr._lctf.readClassDef = function(data, offset) {
  2005. var bin = Typr._bin;
  2006. var obj = [];
  2007. var format = bin.readUshort(data, offset);
  2008. offset += 2;
  2009. if (format == 1) {
  2010. var startGlyph = bin.readUshort(data, offset);
  2011. offset += 2;
  2012. var glyphCount = bin.readUshort(data, offset);
  2013. offset += 2;
  2014. for (var i = 0; i < glyphCount; i++) {
  2015. obj.push(startGlyph + i);
  2016. obj.push(startGlyph + i);
  2017. obj.push(bin.readUshort(data, offset));
  2018. offset += 2;
  2019. }
  2020. }
  2021. if (format == 2) {
  2022. var count = bin.readUshort(data, offset);
  2023. offset += 2;
  2024. for (var i = 0; i < count; i++) {
  2025. obj.push(bin.readUshort(data, offset));
  2026. offset += 2;
  2027. obj.push(bin.readUshort(data, offset));
  2028. offset += 2;
  2029. obj.push(bin.readUshort(data, offset));
  2030. offset += 2;
  2031. }
  2032. }
  2033. return obj;
  2034. };
  2035. Typr._lctf.getInterval = function(tab, val) {
  2036. for (var i = 0; i < tab.length; i += 3) {
  2037. var start = tab[i], end = tab[i + 1];
  2038. tab[i + 2];
  2039. if (start <= val && val <= end)
  2040. return i;
  2041. }
  2042. return -1;
  2043. };
  2044. Typr._lctf.readCoverage = function(data, offset) {
  2045. var bin = Typr._bin;
  2046. var cvg = {};
  2047. cvg.fmt = bin.readUshort(data, offset);
  2048. offset += 2;
  2049. var count = bin.readUshort(data, offset);
  2050. offset += 2;
  2051. if (cvg.fmt == 1)
  2052. cvg.tab = bin.readUshorts(data, offset, count);
  2053. if (cvg.fmt == 2)
  2054. cvg.tab = bin.readUshorts(data, offset, count * 3);
  2055. return cvg;
  2056. };
  2057. Typr._lctf.coverageIndex = function(cvg, val) {
  2058. var tab = cvg.tab;
  2059. if (cvg.fmt == 1)
  2060. return tab.indexOf(val);
  2061. if (cvg.fmt == 2) {
  2062. var ind = Typr._lctf.getInterval(tab, val);
  2063. if (ind != -1)
  2064. return tab[ind + 2] + (val - tab[ind]);
  2065. }
  2066. return -1;
  2067. };
  2068. Typr._lctf.readFeatureList = function(data, offset) {
  2069. var bin = Typr._bin;
  2070. var offset0 = offset;
  2071. var obj = [];
  2072. var count = bin.readUshort(data, offset);
  2073. offset += 2;
  2074. for (var i = 0; i < count; i++) {
  2075. var tag = bin.readASCII(data, offset, 4);
  2076. offset += 4;
  2077. var noff = bin.readUshort(data, offset);
  2078. offset += 2;
  2079. var feat = Typr._lctf.readFeatureTable(data, offset0 + noff);
  2080. feat.tag = tag.trim();
  2081. obj.push(feat);
  2082. }
  2083. return obj;
  2084. };
  2085. Typr._lctf.readFeatureTable = function(data, offset) {
  2086. var bin = Typr._bin;
  2087. var offset0 = offset;
  2088. var feat = {};
  2089. var featureParams = bin.readUshort(data, offset);
  2090. offset += 2;
  2091. if (featureParams > 0) {
  2092. feat.featureParams = offset0 + featureParams;
  2093. }
  2094. var lookupCount = bin.readUshort(data, offset);
  2095. offset += 2;
  2096. feat.tab = [];
  2097. for (var i = 0; i < lookupCount; i++)
  2098. feat.tab.push(bin.readUshort(data, offset + 2 * i));
  2099. return feat;
  2100. };
  2101. Typr._lctf.readScriptList = function(data, offset) {
  2102. var bin = Typr._bin;
  2103. var offset0 = offset;
  2104. var obj = {};
  2105. var count = bin.readUshort(data, offset);
  2106. offset += 2;
  2107. for (var i = 0; i < count; i++) {
  2108. var tag = bin.readASCII(data, offset, 4);
  2109. offset += 4;
  2110. var noff = bin.readUshort(data, offset);
  2111. offset += 2;
  2112. obj[tag.trim()] = Typr._lctf.readScriptTable(data, offset0 + noff);
  2113. }
  2114. return obj;
  2115. };
  2116. Typr._lctf.readScriptTable = function(data, offset) {
  2117. var bin = Typr._bin;
  2118. var offset0 = offset;
  2119. var obj = {};
  2120. var defLangSysOff = bin.readUshort(data, offset);
  2121. offset += 2;
  2122. obj["default"] = Typr._lctf.readLangSysTable(data, offset0 + defLangSysOff);
  2123. var langSysCount = bin.readUshort(data, offset);
  2124. offset += 2;
  2125. for (var i = 0; i < langSysCount; i++) {
  2126. var tag = bin.readASCII(data, offset, 4);
  2127. offset += 4;
  2128. var langSysOff = bin.readUshort(data, offset);
  2129. offset += 2;
  2130. obj[tag.trim()] = Typr._lctf.readLangSysTable(data, offset0 + langSysOff);
  2131. }
  2132. return obj;
  2133. };
  2134. Typr._lctf.readLangSysTable = function(data, offset) {
  2135. var bin = Typr._bin;
  2136. var obj = {};
  2137. bin.readUshort(data, offset);
  2138. offset += 2;
  2139. obj.reqFeature = bin.readUshort(data, offset);
  2140. offset += 2;
  2141. var featureCount = bin.readUshort(data, offset);
  2142. offset += 2;
  2143. obj.features = bin.readUshorts(data, offset, featureCount);
  2144. return obj;
  2145. };
  2146. Typr.CFF = {};
  2147. Typr.CFF.parse = function(data, offset, length) {
  2148. var bin = Typr._bin;
  2149. data = new Uint8Array(data.buffer, offset, length);
  2150. offset = 0;
  2151. data[offset];
  2152. offset++;
  2153. data[offset];
  2154. offset++;
  2155. data[offset];
  2156. offset++;
  2157. data[offset];
  2158. offset++;
  2159. var ninds = [];
  2160. offset = Typr.CFF.readIndex(data, offset, ninds);
  2161. var names = [];
  2162. for (var i = 0; i < ninds.length - 1; i++)
  2163. names.push(bin.readASCII(data, offset + ninds[i], ninds[i + 1] - ninds[i]));
  2164. offset += ninds[ninds.length - 1];
  2165. var tdinds = [];
  2166. offset = Typr.CFF.readIndex(data, offset, tdinds);
  2167. var topDicts = [];
  2168. for (var i = 0; i < tdinds.length - 1; i++)
  2169. topDicts.push(Typr.CFF.readDict(data, offset + tdinds[i], offset + tdinds[i + 1]));
  2170. offset += tdinds[tdinds.length - 1];
  2171. var topdict = topDicts[0];
  2172. var sinds = [];
  2173. offset = Typr.CFF.readIndex(data, offset, sinds);
  2174. var strings = [];
  2175. for (var i = 0; i < sinds.length - 1; i++)
  2176. strings.push(bin.readASCII(data, offset + sinds[i], sinds[i + 1] - sinds[i]));
  2177. offset += sinds[sinds.length - 1];
  2178. Typr.CFF.readSubrs(data, offset, topdict);
  2179. if (topdict.CharStrings) {
  2180. offset = topdict.CharStrings;
  2181. var sinds = [];
  2182. offset = Typr.CFF.readIndex(data, offset, sinds);
  2183. var cstr = [];
  2184. for (var i = 0; i < sinds.length - 1; i++)
  2185. cstr.push(bin.readBytes(data, offset + sinds[i], sinds[i + 1] - sinds[i]));
  2186. topdict.CharStrings = cstr;
  2187. }
  2188. if (topdict.ROS) {
  2189. offset = topdict.FDArray;
  2190. var fdind = [];
  2191. offset = Typr.CFF.readIndex(data, offset, fdind);
  2192. topdict.FDArray = [];
  2193. for (var i = 0; i < fdind.length - 1; i++) {
  2194. var dict = Typr.CFF.readDict(data, offset + fdind[i], offset + fdind[i + 1]);
  2195. Typr.CFF._readFDict(data, dict, strings);
  2196. topdict.FDArray.push(dict);
  2197. }
  2198. offset += fdind[fdind.length - 1];
  2199. offset = topdict.FDSelect;
  2200. topdict.FDSelect = [];
  2201. var fmt = data[offset];
  2202. offset++;
  2203. if (fmt == 3) {
  2204. var rns = bin.readUshort(data, offset);
  2205. offset += 2;
  2206. for (var i = 0; i < rns + 1; i++) {
  2207. topdict.FDSelect.push(bin.readUshort(data, offset), data[offset + 2]);
  2208. offset += 3;
  2209. }
  2210. } else
  2211. throw fmt;
  2212. }
  2213. if (topdict.Encoding)
  2214. topdict.Encoding = Typr.CFF.readEncoding(data, topdict.Encoding, topdict.CharStrings.length);
  2215. if (topdict.charset)
  2216. topdict.charset = Typr.CFF.readCharset(data, topdict.charset, topdict.CharStrings.length);
  2217. Typr.CFF._readFDict(data, topdict, strings);
  2218. return topdict;
  2219. };
  2220. Typr.CFF._readFDict = function(data, dict, ss) {
  2221. var offset;
  2222. if (dict.Private) {
  2223. offset = dict.Private[1];
  2224. dict.Private = Typr.CFF.readDict(data, offset, offset + dict.Private[0]);
  2225. if (dict.Private.Subrs)
  2226. Typr.CFF.readSubrs(data, offset + dict.Private.Subrs, dict.Private);
  2227. }
  2228. for (var p in dict)
  2229. if (["FamilyName", "FontName", "FullName", "Notice", "version", "Copyright"].indexOf(p) != -1)
  2230. dict[p] = ss[dict[p] - 426 + 35];
  2231. };
  2232. Typr.CFF.readSubrs = function(data, offset, obj) {
  2233. var bin = Typr._bin;
  2234. var gsubinds = [];
  2235. offset = Typr.CFF.readIndex(data, offset, gsubinds);
  2236. var bias, nSubrs = gsubinds.length;
  2237. if (nSubrs < 1240)
  2238. bias = 107;
  2239. else if (nSubrs < 33900)
  2240. bias = 1131;
  2241. else
  2242. bias = 32768;
  2243. obj.Bias = bias;
  2244. obj.Subrs = [];
  2245. for (var i = 0; i < gsubinds.length - 1; i++)
  2246. obj.Subrs.push(bin.readBytes(data, offset + gsubinds[i], gsubinds[i + 1] - gsubinds[i]));
  2247. };
  2248. Typr.CFF.tableSE = [
  2249. 0,
  2250. 0,
  2251. 0,
  2252. 0,
  2253. 0,
  2254. 0,
  2255. 0,
  2256. 0,
  2257. 0,
  2258. 0,
  2259. 0,
  2260. 0,
  2261. 0,
  2262. 0,
  2263. 0,
  2264. 0,
  2265. 0,
  2266. 0,
  2267. 0,
  2268. 0,
  2269. 0,
  2270. 0,
  2271. 0,
  2272. 0,
  2273. 0,
  2274. 0,
  2275. 0,
  2276. 0,
  2277. 0,
  2278. 0,
  2279. 0,
  2280. 0,
  2281. 1,
  2282. 2,
  2283. 3,
  2284. 4,
  2285. 5,
  2286. 6,
  2287. 7,
  2288. 8,
  2289. 9,
  2290. 10,
  2291. 11,
  2292. 12,
  2293. 13,
  2294. 14,
  2295. 15,
  2296. 16,
  2297. 17,
  2298. 18,
  2299. 19,
  2300. 20,
  2301. 21,
  2302. 22,
  2303. 23,
  2304. 24,
  2305. 25,
  2306. 26,
  2307. 27,
  2308. 28,
  2309. 29,
  2310. 30,
  2311. 31,
  2312. 32,
  2313. 33,
  2314. 34,
  2315. 35,
  2316. 36,
  2317. 37,
  2318. 38,
  2319. 39,
  2320. 40,
  2321. 41,
  2322. 42,
  2323. 43,
  2324. 44,
  2325. 45,
  2326. 46,
  2327. 47,
  2328. 48,
  2329. 49,
  2330. 50,
  2331. 51,
  2332. 52,
  2333. 53,
  2334. 54,
  2335. 55,
  2336. 56,
  2337. 57,
  2338. 58,
  2339. 59,
  2340. 60,
  2341. 61,
  2342. 62,
  2343. 63,
  2344. 64,
  2345. 65,
  2346. 66,
  2347. 67,
  2348. 68,
  2349. 69,
  2350. 70,
  2351. 71,
  2352. 72,
  2353. 73,
  2354. 74,
  2355. 75,
  2356. 76,
  2357. 77,
  2358. 78,
  2359. 79,
  2360. 80,
  2361. 81,
  2362. 82,
  2363. 83,
  2364. 84,
  2365. 85,
  2366. 86,
  2367. 87,
  2368. 88,
  2369. 89,
  2370. 90,
  2371. 91,
  2372. 92,
  2373. 93,
  2374. 94,
  2375. 95,
  2376. 0,
  2377. 0,
  2378. 0,
  2379. 0,
  2380. 0,
  2381. 0,
  2382. 0,
  2383. 0,
  2384. 0,
  2385. 0,
  2386. 0,
  2387. 0,
  2388. 0,
  2389. 0,
  2390. 0,
  2391. 0,
  2392. 0,
  2393. 0,
  2394. 0,
  2395. 0,
  2396. 0,
  2397. 0,
  2398. 0,
  2399. 0,
  2400. 0,
  2401. 0,
  2402. 0,
  2403. 0,
  2404. 0,
  2405. 0,
  2406. 0,
  2407. 0,
  2408. 0,
  2409. 0,
  2410. 96,
  2411. 97,
  2412. 98,
  2413. 99,
  2414. 100,
  2415. 101,
  2416. 102,
  2417. 103,
  2418. 104,
  2419. 105,
  2420. 106,
  2421. 107,
  2422. 108,
  2423. 109,
  2424. 110,
  2425. 0,
  2426. 111,
  2427. 112,
  2428. 113,
  2429. 114,
  2430. 0,
  2431. 115,
  2432. 116,
  2433. 117,
  2434. 118,
  2435. 119,
  2436. 120,
  2437. 121,
  2438. 122,
  2439. 0,
  2440. 123,
  2441. 0,
  2442. 124,
  2443. 125,
  2444. 126,
  2445. 127,
  2446. 128,
  2447. 129,
  2448. 130,
  2449. 131,
  2450. 0,
  2451. 132,
  2452. 133,
  2453. 0,
  2454. 134,
  2455. 135,
  2456. 136,
  2457. 137,
  2458. 0,
  2459. 0,
  2460. 0,
  2461. 0,
  2462. 0,
  2463. 0,
  2464. 0,
  2465. 0,
  2466. 0,
  2467. 0,
  2468. 0,
  2469. 0,
  2470. 0,
  2471. 0,
  2472. 0,
  2473. 0,
  2474. 138,
  2475. 0,
  2476. 139,
  2477. 0,
  2478. 0,
  2479. 0,
  2480. 0,
  2481. 140,
  2482. 141,
  2483. 142,
  2484. 143,
  2485. 0,
  2486. 0,
  2487. 0,
  2488. 0,
  2489. 0,
  2490. 144,
  2491. 0,
  2492. 0,
  2493. 0,
  2494. 145,
  2495. 0,
  2496. 0,
  2497. 146,
  2498. 147,
  2499. 148,
  2500. 149,
  2501. 0,
  2502. 0,
  2503. 0,
  2504. 0
  2505. ];
  2506. Typr.CFF.glyphByUnicode = function(cff, code) {
  2507. for (var i = 0; i < cff.charset.length; i++)
  2508. if (cff.charset[i] == code)
  2509. return i;
  2510. return -1;
  2511. };
  2512. Typr.CFF.glyphBySE = function(cff, charcode) {
  2513. if (charcode < 0 || charcode > 255)
  2514. return -1;
  2515. return Typr.CFF.glyphByUnicode(cff, Typr.CFF.tableSE[charcode]);
  2516. };
  2517. Typr.CFF.readEncoding = function(data, offset, num) {
  2518. Typr._bin;
  2519. var array = [".notdef"];
  2520. var format = data[offset];
  2521. offset++;
  2522. if (format == 0) {
  2523. var nCodes = data[offset];
  2524. offset++;
  2525. for (var i = 0; i < nCodes; i++)
  2526. array.push(data[offset + i]);
  2527. } else
  2528. throw "error: unknown encoding format: " + format;
  2529. return array;
  2530. };
  2531. Typr.CFF.readCharset = function(data, offset, num) {
  2532. var bin = Typr._bin;
  2533. var charset = [".notdef"];
  2534. var format = data[offset];
  2535. offset++;
  2536. if (format == 0) {
  2537. for (var i = 0; i < num; i++) {
  2538. var first = bin.readUshort(data, offset);
  2539. offset += 2;
  2540. charset.push(first);
  2541. }
  2542. } else if (format == 1 || format == 2) {
  2543. while (charset.length < num) {
  2544. var first = bin.readUshort(data, offset);
  2545. offset += 2;
  2546. var nLeft = 0;
  2547. if (format == 1) {
  2548. nLeft = data[offset];
  2549. offset++;
  2550. } else {
  2551. nLeft = bin.readUshort(data, offset);
  2552. offset += 2;
  2553. }
  2554. for (var i = 0; i <= nLeft; i++) {
  2555. charset.push(first);
  2556. first++;
  2557. }
  2558. }
  2559. } else
  2560. throw "error: format: " + format;
  2561. return charset;
  2562. };
  2563. Typr.CFF.readIndex = function(data, offset, inds) {
  2564. var bin = Typr._bin;
  2565. var count = bin.readUshort(data, offset) + 1;
  2566. offset += 2;
  2567. var offsize = data[offset];
  2568. offset++;
  2569. if (offsize == 1)
  2570. for (var i = 0; i < count; i++)
  2571. inds.push(data[offset + i]);
  2572. else if (offsize == 2)
  2573. for (var i = 0; i < count; i++)
  2574. inds.push(bin.readUshort(data, offset + i * 2));
  2575. else if (offsize == 3)
  2576. for (var i = 0; i < count; i++)
  2577. inds.push(bin.readUint(data, offset + i * 3 - 1) & 16777215);
  2578. else if (count != 1)
  2579. throw "unsupported offset size: " + offsize + ", count: " + count;
  2580. offset += count * offsize;
  2581. return offset - 1;
  2582. };
  2583. Typr.CFF.getCharString = function(data, offset, o) {
  2584. var bin = Typr._bin;
  2585. var b0 = data[offset], b1 = data[offset + 1];
  2586. data[offset + 2];
  2587. data[offset + 3];
  2588. data[offset + 4];
  2589. var vs = 1;
  2590. var op = null, val = null;
  2591. if (b0 <= 20) {
  2592. op = b0;
  2593. vs = 1;
  2594. }
  2595. if (b0 == 12) {
  2596. op = b0 * 100 + b1;
  2597. vs = 2;
  2598. }
  2599. if (21 <= b0 && b0 <= 27) {
  2600. op = b0;
  2601. vs = 1;
  2602. }
  2603. if (b0 == 28) {
  2604. val = bin.readShort(data, offset + 1);
  2605. vs = 3;
  2606. }
  2607. if (29 <= b0 && b0 <= 31) {
  2608. op = b0;
  2609. vs = 1;
  2610. }
  2611. if (32 <= b0 && b0 <= 246) {
  2612. val = b0 - 139;
  2613. vs = 1;
  2614. }
  2615. if (247 <= b0 && b0 <= 250) {
  2616. val = (b0 - 247) * 256 + b1 + 108;
  2617. vs = 2;
  2618. }
  2619. if (251 <= b0 && b0 <= 254) {
  2620. val = -(b0 - 251) * 256 - b1 - 108;
  2621. vs = 2;
  2622. }
  2623. if (b0 == 255) {
  2624. val = bin.readInt(data, offset + 1) / 65535;
  2625. vs = 5;
  2626. }
  2627. o.val = val != null ? val : "o" + op;
  2628. o.size = vs;
  2629. };
  2630. Typr.CFF.readCharString = function(data, offset, length) {
  2631. var end = offset + length;
  2632. var bin = Typr._bin;
  2633. var arr = [];
  2634. while (offset < end) {
  2635. var b0 = data[offset], b1 = data[offset + 1];
  2636. data[offset + 2];
  2637. data[offset + 3];
  2638. data[offset + 4];
  2639. var vs = 1;
  2640. var op = null, val = null;
  2641. if (b0 <= 20) {
  2642. op = b0;
  2643. vs = 1;
  2644. }
  2645. if (b0 == 12) {
  2646. op = b0 * 100 + b1;
  2647. vs = 2;
  2648. }
  2649. if (b0 == 19 || b0 == 20) {
  2650. op = b0;
  2651. vs = 2;
  2652. }
  2653. if (21 <= b0 && b0 <= 27) {
  2654. op = b0;
  2655. vs = 1;
  2656. }
  2657. if (b0 == 28) {
  2658. val = bin.readShort(data, offset + 1);
  2659. vs = 3;
  2660. }
  2661. if (29 <= b0 && b0 <= 31) {
  2662. op = b0;
  2663. vs = 1;
  2664. }
  2665. if (32 <= b0 && b0 <= 246) {
  2666. val = b0 - 139;
  2667. vs = 1;
  2668. }
  2669. if (247 <= b0 && b0 <= 250) {
  2670. val = (b0 - 247) * 256 + b1 + 108;
  2671. vs = 2;
  2672. }
  2673. if (251 <= b0 && b0 <= 254) {
  2674. val = -(b0 - 251) * 256 - b1 - 108;
  2675. vs = 2;
  2676. }
  2677. if (b0 == 255) {
  2678. val = bin.readInt(data, offset + 1) / 65535;
  2679. vs = 5;
  2680. }
  2681. arr.push(val != null ? val : "o" + op);
  2682. offset += vs;
  2683. }
  2684. return arr;
  2685. };
  2686. Typr.CFF.readDict = function(data, offset, end) {
  2687. var bin = Typr._bin;
  2688. var dict = {};
  2689. var carr = [];
  2690. while (offset < end) {
  2691. var b0 = data[offset], b1 = data[offset + 1];
  2692. data[offset + 2];
  2693. data[offset + 3];
  2694. data[offset + 4];
  2695. var vs = 1;
  2696. var key = null, val = null;
  2697. if (b0 == 28) {
  2698. val = bin.readShort(data, offset + 1);
  2699. vs = 3;
  2700. }
  2701. if (b0 == 29) {
  2702. val = bin.readInt(data, offset + 1);
  2703. vs = 5;
  2704. }
  2705. if (32 <= b0 && b0 <= 246) {
  2706. val = b0 - 139;
  2707. vs = 1;
  2708. }
  2709. if (247 <= b0 && b0 <= 250) {
  2710. val = (b0 - 247) * 256 + b1 + 108;
  2711. vs = 2;
  2712. }
  2713. if (251 <= b0 && b0 <= 254) {
  2714. val = -(b0 - 251) * 256 - b1 - 108;
  2715. vs = 2;
  2716. }
  2717. if (b0 == 255) {
  2718. val = bin.readInt(data, offset + 1) / 65535;
  2719. vs = 5;
  2720. throw "unknown number";
  2721. }
  2722. if (b0 == 30) {
  2723. var nibs = [];
  2724. vs = 1;
  2725. while (true) {
  2726. var b = data[offset + vs];
  2727. vs++;
  2728. var nib0 = b >> 4, nib1 = b & 15;
  2729. if (nib0 != 15)
  2730. nibs.push(nib0);
  2731. if (nib1 != 15)
  2732. nibs.push(nib1);
  2733. if (nib1 == 15)
  2734. break;
  2735. }
  2736. var s = "";
  2737. var chars = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ".", "e", "e-", "reserved", "-", "endOfNumber"];
  2738. for (var i = 0; i < nibs.length; i++)
  2739. s += chars[nibs[i]];
  2740. val = parseFloat(s);
  2741. }
  2742. if (b0 <= 21) {
  2743. var keys = [
  2744. "version",
  2745. "Notice",
  2746. "FullName",
  2747. "FamilyName",
  2748. "Weight",
  2749. "FontBBox",
  2750. "BlueValues",
  2751. "OtherBlues",
  2752. "FamilyBlues",
  2753. "FamilyOtherBlues",
  2754. "StdHW",
  2755. "StdVW",
  2756. "escape",
  2757. "UniqueID",
  2758. "XUID",
  2759. "charset",
  2760. "Encoding",
  2761. "CharStrings",
  2762. "Private",
  2763. "Subrs",
  2764. "defaultWidthX",
  2765. "nominalWidthX"
  2766. ];
  2767. key = keys[b0];
  2768. vs = 1;
  2769. if (b0 == 12) {
  2770. var keys = [
  2771. "Copyright",
  2772. "isFixedPitch",
  2773. "ItalicAngle",
  2774. "UnderlinePosition",
  2775. "UnderlineThickness",
  2776. "PaintType",
  2777. "CharstringType",
  2778. "FontMatrix",
  2779. "StrokeWidth",
  2780. "BlueScale",
  2781. "BlueShift",
  2782. "BlueFuzz",
  2783. "StemSnapH",
  2784. "StemSnapV",
  2785. "ForceBold",
  2786. 0,
  2787. 0,
  2788. "LanguageGroup",
  2789. "ExpansionFactor",
  2790. "initialRandomSeed",
  2791. "SyntheticBase",
  2792. "PostScript",
  2793. "BaseFontName",
  2794. "BaseFontBlend",
  2795. 0,
  2796. 0,
  2797. 0,
  2798. 0,
  2799. 0,
  2800. 0,
  2801. "ROS",
  2802. "CIDFontVersion",
  2803. "CIDFontRevision",
  2804. "CIDFontType",
  2805. "CIDCount",
  2806. "UIDBase",
  2807. "FDArray",
  2808. "FDSelect",
  2809. "FontName"
  2810. ];
  2811. key = keys[b1];
  2812. vs = 2;
  2813. }
  2814. }
  2815. if (key != null) {
  2816. dict[key] = carr.length == 1 ? carr[0] : carr;
  2817. carr = [];
  2818. } else
  2819. carr.push(val);
  2820. offset += vs;
  2821. }
  2822. return dict;
  2823. };
  2824. Typr.cmap = {};
  2825. Typr.cmap.parse = function(data, offset, length) {
  2826. data = new Uint8Array(data.buffer, offset, length);
  2827. offset = 0;
  2828. var bin = Typr._bin;
  2829. var obj = {};
  2830. bin.readUshort(data, offset);
  2831. offset += 2;
  2832. var numTables = bin.readUshort(data, offset);
  2833. offset += 2;
  2834. var offs = [];
  2835. obj.tables = [];
  2836. for (var i = 0; i < numTables; i++) {
  2837. var platformID = bin.readUshort(data, offset);
  2838. offset += 2;
  2839. var encodingID = bin.readUshort(data, offset);
  2840. offset += 2;
  2841. var noffset = bin.readUint(data, offset);
  2842. offset += 4;
  2843. var id = "p" + platformID + "e" + encodingID;
  2844. var tind = offs.indexOf(noffset);
  2845. if (tind == -1) {
  2846. tind = obj.tables.length;
  2847. var subt;
  2848. offs.push(noffset);
  2849. var format = bin.readUshort(data, noffset);
  2850. if (format == 0)
  2851. subt = Typr.cmap.parse0(data, noffset);
  2852. else if (format == 4)
  2853. subt = Typr.cmap.parse4(data, noffset);
  2854. else if (format == 6)
  2855. subt = Typr.cmap.parse6(data, noffset);
  2856. else if (format == 12)
  2857. subt = Typr.cmap.parse12(data, noffset);
  2858. else
  2859. console.warn("unknown format: " + format, platformID, encodingID, noffset);
  2860. obj.tables.push(subt);
  2861. }
  2862. if (obj[id] != null)
  2863. throw "multiple tables for one platform+encoding";
  2864. obj[id] = tind;
  2865. }
  2866. return obj;
  2867. };
  2868. Typr.cmap.parse0 = function(data, offset) {
  2869. var bin = Typr._bin;
  2870. var obj = {};
  2871. obj.format = bin.readUshort(data, offset);
  2872. offset += 2;
  2873. var len = bin.readUshort(data, offset);
  2874. offset += 2;
  2875. bin.readUshort(data, offset);
  2876. offset += 2;
  2877. obj.map = [];
  2878. for (var i = 0; i < len - 6; i++)
  2879. obj.map.push(data[offset + i]);
  2880. return obj;
  2881. };
  2882. Typr.cmap.parse4 = function(data, offset) {
  2883. var bin = Typr._bin;
  2884. var offset0 = offset;
  2885. var obj = {};
  2886. obj.format = bin.readUshort(data, offset);
  2887. offset += 2;
  2888. var length = bin.readUshort(data, offset);
  2889. offset += 2;
  2890. bin.readUshort(data, offset);
  2891. offset += 2;
  2892. var segCountX2 = bin.readUshort(data, offset);
  2893. offset += 2;
  2894. var segCount = segCountX2 / 2;
  2895. obj.searchRange = bin.readUshort(data, offset);
  2896. offset += 2;
  2897. obj.entrySelector = bin.readUshort(data, offset);
  2898. offset += 2;
  2899. obj.rangeShift = bin.readUshort(data, offset);
  2900. offset += 2;
  2901. obj.endCount = bin.readUshorts(data, offset, segCount);
  2902. offset += segCount * 2;
  2903. offset += 2;
  2904. obj.startCount = bin.readUshorts(data, offset, segCount);
  2905. offset += segCount * 2;
  2906. obj.idDelta = [];
  2907. for (var i = 0; i < segCount; i++) {
  2908. obj.idDelta.push(bin.readShort(data, offset));
  2909. offset += 2;
  2910. }
  2911. obj.idRangeOffset = bin.readUshorts(data, offset, segCount);
  2912. offset += segCount * 2;
  2913. obj.glyphIdArray = [];
  2914. while (offset < offset0 + length) {
  2915. obj.glyphIdArray.push(bin.readUshort(data, offset));
  2916. offset += 2;
  2917. }
  2918. return obj;
  2919. };
  2920. Typr.cmap.parse6 = function(data, offset) {
  2921. var bin = Typr._bin;
  2922. var obj = {};
  2923. obj.format = bin.readUshort(data, offset);
  2924. offset += 2;
  2925. bin.readUshort(data, offset);
  2926. offset += 2;
  2927. bin.readUshort(data, offset);
  2928. offset += 2;
  2929. obj.firstCode = bin.readUshort(data, offset);
  2930. offset += 2;
  2931. var entryCount = bin.readUshort(data, offset);
  2932. offset += 2;
  2933. obj.glyphIdArray = [];
  2934. for (var i = 0; i < entryCount; i++) {
  2935. obj.glyphIdArray.push(bin.readUshort(data, offset));
  2936. offset += 2;
  2937. }
  2938. return obj;
  2939. };
  2940. Typr.cmap.parse12 = function(data, offset) {
  2941. var bin = Typr._bin;
  2942. var obj = {};
  2943. obj.format = bin.readUshort(data, offset);
  2944. offset += 2;
  2945. offset += 2;
  2946. bin.readUint(data, offset);
  2947. offset += 4;
  2948. bin.readUint(data, offset);
  2949. offset += 4;
  2950. var nGroups = bin.readUint(data, offset);
  2951. offset += 4;
  2952. obj.groups = [];
  2953. for (var i = 0; i < nGroups; i++) {
  2954. var off = offset + i * 12;
  2955. var startCharCode = bin.readUint(data, off + 0);
  2956. var endCharCode = bin.readUint(data, off + 4);
  2957. var startGlyphID = bin.readUint(data, off + 8);
  2958. obj.groups.push([startCharCode, endCharCode, startGlyphID]);
  2959. }
  2960. return obj;
  2961. };
  2962. Typr.glyf = {};
  2963. Typr.glyf.parse = function(data, offset, length, font) {
  2964. var obj = [];
  2965. for (var g = 0; g < font.maxp.numGlyphs; g++)
  2966. obj.push(null);
  2967. return obj;
  2968. };
  2969. Typr.glyf._parseGlyf = function(font, g) {
  2970. var bin = Typr._bin;
  2971. var data = font._data;
  2972. var offset = Typr._tabOffset(data, "glyf", font._offset) + font.loca[g];
  2973. if (font.loca[g] == font.loca[g + 1])
  2974. return null;
  2975. var gl = {};
  2976. gl.noc = bin.readShort(data, offset);
  2977. offset += 2;
  2978. gl.xMin = bin.readShort(data, offset);
  2979. offset += 2;
  2980. gl.yMin = bin.readShort(data, offset);
  2981. offset += 2;
  2982. gl.xMax = bin.readShort(data, offset);
  2983. offset += 2;
  2984. gl.yMax = bin.readShort(data, offset);
  2985. offset += 2;
  2986. if (gl.xMin >= gl.xMax || gl.yMin >= gl.yMax)
  2987. return null;
  2988. if (gl.noc > 0) {
  2989. gl.endPts = [];
  2990. for (var i = 0; i < gl.noc; i++) {
  2991. gl.endPts.push(bin.readUshort(data, offset));
  2992. offset += 2;
  2993. }
  2994. var instructionLength = bin.readUshort(data, offset);
  2995. offset += 2;
  2996. if (data.length - offset < instructionLength)
  2997. return null;
  2998. gl.instructions = bin.readBytes(data, offset, instructionLength);
  2999. offset += instructionLength;
  3000. var crdnum = gl.endPts[gl.noc - 1] + 1;
  3001. gl.flags = [];
  3002. for (var i = 0; i < crdnum; i++) {
  3003. var flag = data[offset];
  3004. offset++;
  3005. gl.flags.push(flag);
  3006. if ((flag & 8) != 0) {
  3007. var rep = data[offset];
  3008. offset++;
  3009. for (var j = 0; j < rep; j++) {
  3010. gl.flags.push(flag);
  3011. i++;
  3012. }
  3013. }
  3014. }
  3015. gl.xs = [];
  3016. for (var i = 0; i < crdnum; i++) {
  3017. var i8 = (gl.flags[i] & 2) != 0, same = (gl.flags[i] & 16) != 0;
  3018. if (i8) {
  3019. gl.xs.push(same ? data[offset] : -data[offset]);
  3020. offset++;
  3021. } else {
  3022. if (same)
  3023. gl.xs.push(0);
  3024. else {
  3025. gl.xs.push(bin.readShort(data, offset));
  3026. offset += 2;
  3027. }
  3028. }
  3029. }
  3030. gl.ys = [];
  3031. for (var i = 0; i < crdnum; i++) {
  3032. var i8 = (gl.flags[i] & 4) != 0, same = (gl.flags[i] & 32) != 0;
  3033. if (i8) {
  3034. gl.ys.push(same ? data[offset] : -data[offset]);
  3035. offset++;
  3036. } else {
  3037. if (same)
  3038. gl.ys.push(0);
  3039. else {
  3040. gl.ys.push(bin.readShort(data, offset));
  3041. offset += 2;
  3042. }
  3043. }
  3044. }
  3045. var x = 0, y = 0;
  3046. for (var i = 0; i < crdnum; i++) {
  3047. x += gl.xs[i];
  3048. y += gl.ys[i];
  3049. gl.xs[i] = x;
  3050. gl.ys[i] = y;
  3051. }
  3052. } else {
  3053. var ARG_1_AND_2_ARE_WORDS = 1 << 0;
  3054. var ARGS_ARE_XY_VALUES = 1 << 1;
  3055. var WE_HAVE_A_SCALE = 1 << 3;
  3056. var MORE_COMPONENTS = 1 << 5;
  3057. var WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6;
  3058. var WE_HAVE_A_TWO_BY_TWO = 1 << 7;
  3059. var WE_HAVE_INSTRUCTIONS = 1 << 8;
  3060. gl.parts = [];
  3061. var flags;
  3062. do {
  3063. flags = bin.readUshort(data, offset);
  3064. offset += 2;
  3065. var part = { m: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, p1: -1, p2: -1 };
  3066. gl.parts.push(part);
  3067. part.glyphIndex = bin.readUshort(data, offset);
  3068. offset += 2;
  3069. if (flags & ARG_1_AND_2_ARE_WORDS) {
  3070. var arg1 = bin.readShort(data, offset);
  3071. offset += 2;
  3072. var arg2 = bin.readShort(data, offset);
  3073. offset += 2;
  3074. } else {
  3075. var arg1 = bin.readInt8(data, offset);
  3076. offset++;
  3077. var arg2 = bin.readInt8(data, offset);
  3078. offset++;
  3079. }
  3080. if (flags & ARGS_ARE_XY_VALUES) {
  3081. part.m.tx = arg1;
  3082. part.m.ty = arg2;
  3083. } else {
  3084. part.p1 = arg1;
  3085. part.p2 = arg2;
  3086. }
  3087. if (flags & WE_HAVE_A_SCALE) {
  3088. part.m.a = part.m.d = bin.readF2dot14(data, offset);
  3089. offset += 2;
  3090. } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) {
  3091. part.m.a = bin.readF2dot14(data, offset);
  3092. offset += 2;
  3093. part.m.d = bin.readF2dot14(data, offset);
  3094. offset += 2;
  3095. } else if (flags & WE_HAVE_A_TWO_BY_TWO) {
  3096. part.m.a = bin.readF2dot14(data, offset);
  3097. offset += 2;
  3098. part.m.b = bin.readF2dot14(data, offset);
  3099. offset += 2;
  3100. part.m.c = bin.readF2dot14(data, offset);
  3101. offset += 2;
  3102. part.m.d = bin.readF2dot14(data, offset);
  3103. offset += 2;
  3104. }
  3105. } while (flags & MORE_COMPONENTS);
  3106. if (flags & WE_HAVE_INSTRUCTIONS) {
  3107. var numInstr = bin.readUshort(data, offset);
  3108. offset += 2;
  3109. gl.instr = [];
  3110. for (var i = 0; i < numInstr; i++) {
  3111. gl.instr.push(data[offset]);
  3112. offset++;
  3113. }
  3114. }
  3115. }
  3116. return gl;
  3117. };
  3118. Typr.GPOS = {};
  3119. Typr.GPOS.parse = function(data, offset, length, font) {
  3120. return Typr._lctf.parse(data, offset, length, font, Typr.GPOS.subt);
  3121. };
  3122. Typr.GPOS.subt = function(data, ltype, offset, ltable) {
  3123. var bin = Typr._bin, offset0 = offset, tab = {};
  3124. tab.fmt = bin.readUshort(data, offset);
  3125. offset += 2;
  3126. if (ltype == 1 || ltype == 2 || ltype == 3 || ltype == 7 || ltype == 8 && tab.fmt <= 2) {
  3127. var covOff = bin.readUshort(data, offset);
  3128. offset += 2;
  3129. tab.coverage = Typr._lctf.readCoverage(data, covOff + offset0);
  3130. }
  3131. if (ltype == 1 && tab.fmt == 1) {
  3132. var valFmt1 = bin.readUshort(data, offset);
  3133. offset += 2;
  3134. var ones1 = Typr._lctf.numOfOnes(valFmt1);
  3135. if (valFmt1 != 0)
  3136. tab.pos = Typr.GPOS.readValueRecord(data, offset, valFmt1);
  3137. } else if (ltype == 2 && tab.fmt >= 1 && tab.fmt <= 2) {
  3138. var valFmt1 = bin.readUshort(data, offset);
  3139. offset += 2;
  3140. var valFmt2 = bin.readUshort(data, offset);
  3141. offset += 2;
  3142. var ones1 = Typr._lctf.numOfOnes(valFmt1);
  3143. var ones2 = Typr._lctf.numOfOnes(valFmt2);
  3144. if (tab.fmt == 1) {
  3145. tab.pairsets = [];
  3146. var psc = bin.readUshort(data, offset);
  3147. offset += 2;
  3148. for (var i = 0; i < psc; i++) {
  3149. var psoff = offset0 + bin.readUshort(data, offset);
  3150. offset += 2;
  3151. var pvc = bin.readUshort(data, psoff);
  3152. psoff += 2;
  3153. var arr = [];
  3154. for (var j = 0; j < pvc; j++) {
  3155. var gid2 = bin.readUshort(data, psoff);
  3156. psoff += 2;
  3157. var value1, value2;
  3158. if (valFmt1 != 0) {
  3159. value1 = Typr.GPOS.readValueRecord(data, psoff, valFmt1);
  3160. psoff += ones1 * 2;
  3161. }
  3162. if (valFmt2 != 0) {
  3163. value2 = Typr.GPOS.readValueRecord(data, psoff, valFmt2);
  3164. psoff += ones2 * 2;
  3165. }
  3166. arr.push({ gid2, val1: value1, val2: value2 });
  3167. }
  3168. tab.pairsets.push(arr);
  3169. }
  3170. }
  3171. if (tab.fmt == 2) {
  3172. var classDef1 = bin.readUshort(data, offset);
  3173. offset += 2;
  3174. var classDef2 = bin.readUshort(data, offset);
  3175. offset += 2;
  3176. var class1Count = bin.readUshort(data, offset);
  3177. offset += 2;
  3178. var class2Count = bin.readUshort(data, offset);
  3179. offset += 2;
  3180. tab.classDef1 = Typr._lctf.readClassDef(data, offset0 + classDef1);
  3181. tab.classDef2 = Typr._lctf.readClassDef(data, offset0 + classDef2);
  3182. tab.matrix = [];
  3183. for (var i = 0; i < class1Count; i++) {
  3184. var row = [];
  3185. for (var j = 0; j < class2Count; j++) {
  3186. var value1 = null, value2 = null;
  3187. if (valFmt1 != 0) {
  3188. value1 = Typr.GPOS.readValueRecord(data, offset, valFmt1);
  3189. offset += ones1 * 2;
  3190. }
  3191. if (valFmt2 != 0) {
  3192. value2 = Typr.GPOS.readValueRecord(data, offset, valFmt2);
  3193. offset += ones2 * 2;
  3194. }
  3195. row.push({ val1: value1, val2: value2 });
  3196. }
  3197. tab.matrix.push(row);
  3198. }
  3199. }
  3200. } else if (ltype == 9 && tab.fmt == 1) {
  3201. var extType = bin.readUshort(data, offset);
  3202. offset += 2;
  3203. var extOffset = bin.readUint(data, offset);
  3204. offset += 4;
  3205. if (ltable.ltype == 9) {
  3206. ltable.ltype = extType;
  3207. } else if (ltable.ltype != extType) {
  3208. throw "invalid extension substitution";
  3209. }
  3210. return Typr.GPOS.subt(data, ltable.ltype, offset0 + extOffset);
  3211. } else
  3212. console.warn("unsupported GPOS table LookupType", ltype, "format", tab.fmt);
  3213. return tab;
  3214. };
  3215. Typr.GPOS.readValueRecord = function(data, offset, valFmt) {
  3216. var bin = Typr._bin;
  3217. var arr = [];
  3218. arr.push(valFmt & 1 ? bin.readShort(data, offset) : 0);
  3219. offset += valFmt & 1 ? 2 : 0;
  3220. arr.push(valFmt & 2 ? bin.readShort(data, offset) : 0);
  3221. offset += valFmt & 2 ? 2 : 0;
  3222. arr.push(valFmt & 4 ? bin.readShort(data, offset) : 0);
  3223. offset += valFmt & 4 ? 2 : 0;
  3224. arr.push(valFmt & 8 ? bin.readShort(data, offset) : 0);
  3225. offset += valFmt & 8 ? 2 : 0;
  3226. return arr;
  3227. };
  3228. Typr.GSUB = {};
  3229. Typr.GSUB.parse = function(data, offset, length, font) {
  3230. return Typr._lctf.parse(data, offset, length, font, Typr.GSUB.subt);
  3231. };
  3232. Typr.GSUB.subt = function(data, ltype, offset, ltable) {
  3233. var bin = Typr._bin, offset0 = offset, tab = {};
  3234. tab.fmt = bin.readUshort(data, offset);
  3235. offset += 2;
  3236. if (ltype != 1 && ltype != 4 && ltype != 5 && ltype != 6)
  3237. return null;
  3238. if (ltype == 1 || ltype == 4 || ltype == 5 && tab.fmt <= 2 || ltype == 6 && tab.fmt <= 2) {
  3239. var covOff = bin.readUshort(data, offset);
  3240. offset += 2;
  3241. tab.coverage = Typr._lctf.readCoverage(data, offset0 + covOff);
  3242. }
  3243. if (ltype == 1 && tab.fmt >= 1 && tab.fmt <= 2) {
  3244. if (tab.fmt == 1) {
  3245. tab.delta = bin.readShort(data, offset);
  3246. offset += 2;
  3247. } else if (tab.fmt == 2) {
  3248. var cnt = bin.readUshort(data, offset);
  3249. offset += 2;
  3250. tab.newg = bin.readUshorts(data, offset, cnt);
  3251. offset += tab.newg.length * 2;
  3252. }
  3253. } else if (ltype == 4) {
  3254. tab.vals = [];
  3255. var cnt = bin.readUshort(data, offset);
  3256. offset += 2;
  3257. for (var i = 0; i < cnt; i++) {
  3258. var loff = bin.readUshort(data, offset);
  3259. offset += 2;
  3260. tab.vals.push(Typr.GSUB.readLigatureSet(data, offset0 + loff));
  3261. }
  3262. } else if (ltype == 5 && tab.fmt == 2) {
  3263. if (tab.fmt == 2) {
  3264. var cDefOffset = bin.readUshort(data, offset);
  3265. offset += 2;
  3266. tab.cDef = Typr._lctf.readClassDef(data, offset0 + cDefOffset);
  3267. tab.scset = [];
  3268. var subClassSetCount = bin.readUshort(data, offset);
  3269. offset += 2;
  3270. for (var i = 0; i < subClassSetCount; i++) {
  3271. var scsOff = bin.readUshort(data, offset);
  3272. offset += 2;
  3273. tab.scset.push(scsOff == 0 ? null : Typr.GSUB.readSubClassSet(data, offset0 + scsOff));
  3274. }
  3275. }
  3276. } else if (ltype == 6 && tab.fmt == 3) {
  3277. if (tab.fmt == 3) {
  3278. for (var i = 0; i < 3; i++) {
  3279. var cnt = bin.readUshort(data, offset);
  3280. offset += 2;
  3281. var cvgs = [];
  3282. for (var j = 0; j < cnt; j++)
  3283. cvgs.push(Typr._lctf.readCoverage(data, offset0 + bin.readUshort(data, offset + j * 2)));
  3284. offset += cnt * 2;
  3285. if (i == 0)
  3286. tab.backCvg = cvgs;
  3287. if (i == 1)
  3288. tab.inptCvg = cvgs;
  3289. if (i == 2)
  3290. tab.ahedCvg = cvgs;
  3291. }
  3292. var cnt = bin.readUshort(data, offset);
  3293. offset += 2;
  3294. tab.lookupRec = Typr.GSUB.readSubstLookupRecords(data, offset, cnt);
  3295. }
  3296. } else if (ltype == 7 && tab.fmt == 1) {
  3297. var extType = bin.readUshort(data, offset);
  3298. offset += 2;
  3299. var extOffset = bin.readUint(data, offset);
  3300. offset += 4;
  3301. if (ltable.ltype == 9) {
  3302. ltable.ltype = extType;
  3303. } else if (ltable.ltype != extType) {
  3304. throw "invalid extension substitution";
  3305. }
  3306. return Typr.GSUB.subt(data, ltable.ltype, offset0 + extOffset);
  3307. } else
  3308. console.warn("unsupported GSUB table LookupType", ltype, "format", tab.fmt);
  3309. return tab;
  3310. };
  3311. Typr.GSUB.readSubClassSet = function(data, offset) {
  3312. var rUs = Typr._bin.readUshort, offset0 = offset, lset = [];
  3313. var cnt = rUs(data, offset);
  3314. offset += 2;
  3315. for (var i = 0; i < cnt; i++) {
  3316. var loff = rUs(data, offset);
  3317. offset += 2;
  3318. lset.push(Typr.GSUB.readSubClassRule(data, offset0 + loff));
  3319. }
  3320. return lset;
  3321. };
  3322. Typr.GSUB.readSubClassRule = function(data, offset) {
  3323. var rUs = Typr._bin.readUshort, rule = {};
  3324. var gcount = rUs(data, offset);
  3325. offset += 2;
  3326. var scount = rUs(data, offset);
  3327. offset += 2;
  3328. rule.input = [];
  3329. for (var i = 0; i < gcount - 1; i++) {
  3330. rule.input.push(rUs(data, offset));
  3331. offset += 2;
  3332. }
  3333. rule.substLookupRecords = Typr.GSUB.readSubstLookupRecords(data, offset, scount);
  3334. return rule;
  3335. };
  3336. Typr.GSUB.readSubstLookupRecords = function(data, offset, cnt) {
  3337. var rUs = Typr._bin.readUshort;
  3338. var out = [];
  3339. for (var i = 0; i < cnt; i++) {
  3340. out.push(rUs(data, offset), rUs(data, offset + 2));
  3341. offset += 4;
  3342. }
  3343. return out;
  3344. };
  3345. Typr.GSUB.readChainSubClassSet = function(data, offset) {
  3346. var bin = Typr._bin, offset0 = offset, lset = [];
  3347. var cnt = bin.readUshort(data, offset);
  3348. offset += 2;
  3349. for (var i = 0; i < cnt; i++) {
  3350. var loff = bin.readUshort(data, offset);
  3351. offset += 2;
  3352. lset.push(Typr.GSUB.readChainSubClassRule(data, offset0 + loff));
  3353. }
  3354. return lset;
  3355. };
  3356. Typr.GSUB.readChainSubClassRule = function(data, offset) {
  3357. var bin = Typr._bin, rule = {};
  3358. var pps = ["backtrack", "input", "lookahead"];
  3359. for (var pi = 0; pi < pps.length; pi++) {
  3360. var cnt = bin.readUshort(data, offset);
  3361. offset += 2;
  3362. if (pi == 1)
  3363. cnt--;
  3364. rule[pps[pi]] = bin.readUshorts(data, offset, cnt);
  3365. offset += rule[pps[pi]].length * 2;
  3366. }
  3367. var cnt = bin.readUshort(data, offset);
  3368. offset += 2;
  3369. rule.subst = bin.readUshorts(data, offset, cnt * 2);
  3370. offset += rule.subst.length * 2;
  3371. return rule;
  3372. };
  3373. Typr.GSUB.readLigatureSet = function(data, offset) {
  3374. var bin = Typr._bin, offset0 = offset, lset = [];
  3375. var lcnt = bin.readUshort(data, offset);
  3376. offset += 2;
  3377. for (var j = 0; j < lcnt; j++) {
  3378. var loff = bin.readUshort(data, offset);
  3379. offset += 2;
  3380. lset.push(Typr.GSUB.readLigature(data, offset0 + loff));
  3381. }
  3382. return lset;
  3383. };
  3384. Typr.GSUB.readLigature = function(data, offset) {
  3385. var bin = Typr._bin, lig = { chain: [] };
  3386. lig.nglyph = bin.readUshort(data, offset);
  3387. offset += 2;
  3388. var ccnt = bin.readUshort(data, offset);
  3389. offset += 2;
  3390. for (var k = 0; k < ccnt - 1; k++) {
  3391. lig.chain.push(bin.readUshort(data, offset));
  3392. offset += 2;
  3393. }
  3394. return lig;
  3395. };
  3396. Typr.head = {};
  3397. Typr.head.parse = function(data, offset, length) {
  3398. var bin = Typr._bin;
  3399. var obj = {};
  3400. bin.readFixed(data, offset);
  3401. offset += 4;
  3402. obj.fontRevision = bin.readFixed(data, offset);
  3403. offset += 4;
  3404. bin.readUint(data, offset);
  3405. offset += 4;
  3406. bin.readUint(data, offset);
  3407. offset += 4;
  3408. obj.flags = bin.readUshort(data, offset);
  3409. offset += 2;
  3410. obj.unitsPerEm = bin.readUshort(data, offset);
  3411. offset += 2;
  3412. obj.created = bin.readUint64(data, offset);
  3413. offset += 8;
  3414. obj.modified = bin.readUint64(data, offset);
  3415. offset += 8;
  3416. obj.xMin = bin.readShort(data, offset);
  3417. offset += 2;
  3418. obj.yMin = bin.readShort(data, offset);
  3419. offset += 2;
  3420. obj.xMax = bin.readShort(data, offset);
  3421. offset += 2;
  3422. obj.yMax = bin.readShort(data, offset);
  3423. offset += 2;
  3424. obj.macStyle = bin.readUshort(data, offset);
  3425. offset += 2;
  3426. obj.lowestRecPPEM = bin.readUshort(data, offset);
  3427. offset += 2;
  3428. obj.fontDirectionHint = bin.readShort(data, offset);
  3429. offset += 2;
  3430. obj.indexToLocFormat = bin.readShort(data, offset);
  3431. offset += 2;
  3432. obj.glyphDataFormat = bin.readShort(data, offset);
  3433. offset += 2;
  3434. return obj;
  3435. };
  3436. Typr.hhea = {};
  3437. Typr.hhea.parse = function(data, offset, length) {
  3438. var bin = Typr._bin;
  3439. var obj = {};
  3440. bin.readFixed(data, offset);
  3441. offset += 4;
  3442. obj.ascender = bin.readShort(data, offset);
  3443. offset += 2;
  3444. obj.descender = bin.readShort(data, offset);
  3445. offset += 2;
  3446. obj.lineGap = bin.readShort(data, offset);
  3447. offset += 2;
  3448. obj.advanceWidthMax = bin.readUshort(data, offset);
  3449. offset += 2;
  3450. obj.minLeftSideBearing = bin.readShort(data, offset);
  3451. offset += 2;
  3452. obj.minRightSideBearing = bin.readShort(data, offset);
  3453. offset += 2;
  3454. obj.xMaxExtent = bin.readShort(data, offset);
  3455. offset += 2;
  3456. obj.caretSlopeRise = bin.readShort(data, offset);
  3457. offset += 2;
  3458. obj.caretSlopeRun = bin.readShort(data, offset);
  3459. offset += 2;
  3460. obj.caretOffset = bin.readShort(data, offset);
  3461. offset += 2;
  3462. offset += 4 * 2;
  3463. obj.metricDataFormat = bin.readShort(data, offset);
  3464. offset += 2;
  3465. obj.numberOfHMetrics = bin.readUshort(data, offset);
  3466. offset += 2;
  3467. return obj;
  3468. };
  3469. Typr.hmtx = {};
  3470. Typr.hmtx.parse = function(data, offset, length, font) {
  3471. var bin = Typr._bin;
  3472. var obj = {};
  3473. obj.aWidth = [];
  3474. obj.lsBearing = [];
  3475. var aw = 0, lsb = 0;
  3476. for (var i = 0; i < font.maxp.numGlyphs; i++) {
  3477. if (i < font.hhea.numberOfHMetrics) {
  3478. aw = bin.readUshort(data, offset);
  3479. offset += 2;
  3480. lsb = bin.readShort(data, offset);
  3481. offset += 2;
  3482. }
  3483. obj.aWidth.push(aw);
  3484. obj.lsBearing.push(lsb);
  3485. }
  3486. return obj;
  3487. };
  3488. Typr.kern = {};
  3489. Typr.kern.parse = function(data, offset, length, font) {
  3490. var bin = Typr._bin;
  3491. var version = bin.readUshort(data, offset);
  3492. offset += 2;
  3493. if (version == 1)
  3494. return Typr.kern.parseV1(data, offset - 2, length, font);
  3495. var nTables = bin.readUshort(data, offset);
  3496. offset += 2;
  3497. var map2 = { glyph1: [], rval: [] };
  3498. for (var i = 0; i < nTables; i++) {
  3499. offset += 2;
  3500. var length = bin.readUshort(data, offset);
  3501. offset += 2;
  3502. var coverage = bin.readUshort(data, offset);
  3503. offset += 2;
  3504. var format = coverage >>> 8;
  3505. format &= 15;
  3506. if (format == 0)
  3507. offset = Typr.kern.readFormat0(data, offset, map2);
  3508. else
  3509. throw "unknown kern table format: " + format;
  3510. }
  3511. return map2;
  3512. };
  3513. Typr.kern.parseV1 = function(data, offset, length, font) {
  3514. var bin = Typr._bin;
  3515. bin.readFixed(data, offset);
  3516. offset += 4;
  3517. var nTables = bin.readUint(data, offset);
  3518. offset += 4;
  3519. var map2 = { glyph1: [], rval: [] };
  3520. for (var i = 0; i < nTables; i++) {
  3521. bin.readUint(data, offset);
  3522. offset += 4;
  3523. var coverage = bin.readUshort(data, offset);
  3524. offset += 2;
  3525. bin.readUshort(data, offset);
  3526. offset += 2;
  3527. var format = coverage >>> 8;
  3528. format &= 15;
  3529. if (format == 0)
  3530. offset = Typr.kern.readFormat0(data, offset, map2);
  3531. else
  3532. throw "unknown kern table format: " + format;
  3533. }
  3534. return map2;
  3535. };
  3536. Typr.kern.readFormat0 = function(data, offset, map2) {
  3537. var bin = Typr._bin;
  3538. var pleft = -1;
  3539. var nPairs = bin.readUshort(data, offset);
  3540. offset += 2;
  3541. bin.readUshort(data, offset);
  3542. offset += 2;
  3543. bin.readUshort(data, offset);
  3544. offset += 2;
  3545. bin.readUshort(data, offset);
  3546. offset += 2;
  3547. for (var j = 0; j < nPairs; j++) {
  3548. var left = bin.readUshort(data, offset);
  3549. offset += 2;
  3550. var right = bin.readUshort(data, offset);
  3551. offset += 2;
  3552. var value = bin.readShort(data, offset);
  3553. offset += 2;
  3554. if (left != pleft) {
  3555. map2.glyph1.push(left);
  3556. map2.rval.push({ glyph2: [], vals: [] });
  3557. }
  3558. var rval = map2.rval[map2.rval.length - 1];
  3559. rval.glyph2.push(right);
  3560. rval.vals.push(value);
  3561. pleft = left;
  3562. }
  3563. return offset;
  3564. };
  3565. Typr.loca = {};
  3566. Typr.loca.parse = function(data, offset, length, font) {
  3567. var bin = Typr._bin;
  3568. var obj = [];
  3569. var ver = font.head.indexToLocFormat;
  3570. var len = font.maxp.numGlyphs + 1;
  3571. if (ver == 0)
  3572. for (var i = 0; i < len; i++)
  3573. obj.push(bin.readUshort(data, offset + (i << 1)) << 1);
  3574. if (ver == 1)
  3575. for (var i = 0; i < len; i++)
  3576. obj.push(bin.readUint(data, offset + (i << 2)));
  3577. return obj;
  3578. };
  3579. Typr.maxp = {};
  3580. Typr.maxp.parse = function(data, offset, length) {
  3581. var bin = Typr._bin;
  3582. var obj = {};
  3583. var ver = bin.readUint(data, offset);
  3584. offset += 4;
  3585. obj.numGlyphs = bin.readUshort(data, offset);
  3586. offset += 2;
  3587. if (ver == 65536) {
  3588. obj.maxPoints = bin.readUshort(data, offset);
  3589. offset += 2;
  3590. obj.maxContours = bin.readUshort(data, offset);
  3591. offset += 2;
  3592. obj.maxCompositePoints = bin.readUshort(data, offset);
  3593. offset += 2;
  3594. obj.maxCompositeContours = bin.readUshort(data, offset);
  3595. offset += 2;
  3596. obj.maxZones = bin.readUshort(data, offset);
  3597. offset += 2;
  3598. obj.maxTwilightPoints = bin.readUshort(data, offset);
  3599. offset += 2;
  3600. obj.maxStorage = bin.readUshort(data, offset);
  3601. offset += 2;
  3602. obj.maxFunctionDefs = bin.readUshort(data, offset);
  3603. offset += 2;
  3604. obj.maxInstructionDefs = bin.readUshort(data, offset);
  3605. offset += 2;
  3606. obj.maxStackElements = bin.readUshort(data, offset);
  3607. offset += 2;
  3608. obj.maxSizeOfInstructions = bin.readUshort(data, offset);
  3609. offset += 2;
  3610. obj.maxComponentElements = bin.readUshort(data, offset);
  3611. offset += 2;
  3612. obj.maxComponentDepth = bin.readUshort(data, offset);
  3613. offset += 2;
  3614. }
  3615. return obj;
  3616. };
  3617. Typr.name = {};
  3618. Typr.name.parse = function(data, offset, length) {
  3619. var bin = Typr._bin;
  3620. var obj = {};
  3621. bin.readUshort(data, offset);
  3622. offset += 2;
  3623. var count = bin.readUshort(data, offset);
  3624. offset += 2;
  3625. bin.readUshort(data, offset);
  3626. offset += 2;
  3627. var names = [
  3628. "copyright",
  3629. "fontFamily",
  3630. "fontSubfamily",
  3631. "ID",
  3632. "fullName",
  3633. "version",
  3634. "postScriptName",
  3635. "trademark",
  3636. "manufacturer",
  3637. "designer",
  3638. "description",
  3639. "urlVendor",
  3640. "urlDesigner",
  3641. "licence",
  3642. "licenceURL",
  3643. "---",
  3644. "typoFamilyName",
  3645. "typoSubfamilyName",
  3646. "compatibleFull",
  3647. "sampleText",
  3648. "postScriptCID",
  3649. "wwsFamilyName",
  3650. "wwsSubfamilyName",
  3651. "lightPalette",
  3652. "darkPalette"
  3653. ];
  3654. var offset0 = offset;
  3655. for (var i = 0; i < count; i++) {
  3656. var platformID = bin.readUshort(data, offset);
  3657. offset += 2;
  3658. var encodingID = bin.readUshort(data, offset);
  3659. offset += 2;
  3660. var languageID = bin.readUshort(data, offset);
  3661. offset += 2;
  3662. var nameID = bin.readUshort(data, offset);
  3663. offset += 2;
  3664. var slen = bin.readUshort(data, offset);
  3665. offset += 2;
  3666. var noffset = bin.readUshort(data, offset);
  3667. offset += 2;
  3668. var cname = names[nameID];
  3669. var soff = offset0 + count * 12 + noffset;
  3670. var str;
  3671. if (platformID == 0)
  3672. str = bin.readUnicode(data, soff, slen / 2);
  3673. else if (platformID == 3 && encodingID == 0)
  3674. str = bin.readUnicode(data, soff, slen / 2);
  3675. else if (encodingID == 0)
  3676. str = bin.readASCII(data, soff, slen);
  3677. else if (encodingID == 1)
  3678. str = bin.readUnicode(data, soff, slen / 2);
  3679. else if (encodingID == 3)
  3680. str = bin.readUnicode(data, soff, slen / 2);
  3681. else if (platformID == 1) {
  3682. str = bin.readASCII(data, soff, slen);
  3683. console.warn("reading unknown MAC encoding " + encodingID + " as ASCII");
  3684. } else
  3685. throw "unknown encoding " + encodingID + ", platformID: " + platformID;
  3686. var tid = "p" + platformID + "," + languageID.toString(16);
  3687. if (obj[tid] == null)
  3688. obj[tid] = {};
  3689. obj[tid][cname !== void 0 ? cname : nameID] = str;
  3690. obj[tid]._lang = languageID;
  3691. }
  3692. for (var p in obj)
  3693. if (obj[p].postScriptName != null && obj[p]._lang == 1033)
  3694. return obj[p];
  3695. for (var p in obj)
  3696. if (obj[p].postScriptName != null && obj[p]._lang == 0)
  3697. return obj[p];
  3698. for (var p in obj)
  3699. if (obj[p].postScriptName != null && obj[p]._lang == 3084)
  3700. return obj[p];
  3701. for (var p in obj)
  3702. if (obj[p].postScriptName != null)
  3703. return obj[p];
  3704. var tname;
  3705. for (var p in obj) {
  3706. tname = p;
  3707. break;
  3708. }
  3709. console.warn("returning name table with languageID " + obj[tname]._lang);
  3710. return obj[tname];
  3711. };
  3712. Typr["OS/2"] = {};
  3713. Typr["OS/2"].parse = function(data, offset, length) {
  3714. var bin = Typr._bin;
  3715. var ver = bin.readUshort(data, offset);
  3716. offset += 2;
  3717. var obj = {};
  3718. if (ver == 0)
  3719. Typr["OS/2"].version0(data, offset, obj);
  3720. else if (ver == 1)
  3721. Typr["OS/2"].version1(data, offset, obj);
  3722. else if (ver == 2 || ver == 3 || ver == 4)
  3723. Typr["OS/2"].version2(data, offset, obj);
  3724. else if (ver == 5)
  3725. Typr["OS/2"].version5(data, offset, obj);
  3726. else
  3727. throw "unknown OS/2 table version: " + ver;
  3728. return obj;
  3729. };
  3730. Typr["OS/2"].version0 = function(data, offset, obj) {
  3731. var bin = Typr._bin;
  3732. obj.xAvgCharWidth = bin.readShort(data, offset);
  3733. offset += 2;
  3734. obj.usWeightClass = bin.readUshort(data, offset);
  3735. offset += 2;
  3736. obj.usWidthClass = bin.readUshort(data, offset);
  3737. offset += 2;
  3738. obj.fsType = bin.readUshort(data, offset);
  3739. offset += 2;
  3740. obj.ySubscriptXSize = bin.readShort(data, offset);
  3741. offset += 2;
  3742. obj.ySubscriptYSize = bin.readShort(data, offset);
  3743. offset += 2;
  3744. obj.ySubscriptXOffset = bin.readShort(data, offset);
  3745. offset += 2;
  3746. obj.ySubscriptYOffset = bin.readShort(data, offset);
  3747. offset += 2;
  3748. obj.ySuperscriptXSize = bin.readShort(data, offset);
  3749. offset += 2;
  3750. obj.ySuperscriptYSize = bin.readShort(data, offset);
  3751. offset += 2;
  3752. obj.ySuperscriptXOffset = bin.readShort(data, offset);
  3753. offset += 2;
  3754. obj.ySuperscriptYOffset = bin.readShort(data, offset);
  3755. offset += 2;
  3756. obj.yStrikeoutSize = bin.readShort(data, offset);
  3757. offset += 2;
  3758. obj.yStrikeoutPosition = bin.readShort(data, offset);
  3759. offset += 2;
  3760. obj.sFamilyClass = bin.readShort(data, offset);
  3761. offset += 2;
  3762. obj.panose = bin.readBytes(data, offset, 10);
  3763. offset += 10;
  3764. obj.ulUnicodeRange1 = bin.readUint(data, offset);
  3765. offset += 4;
  3766. obj.ulUnicodeRange2 = bin.readUint(data, offset);
  3767. offset += 4;
  3768. obj.ulUnicodeRange3 = bin.readUint(data, offset);
  3769. offset += 4;
  3770. obj.ulUnicodeRange4 = bin.readUint(data, offset);
  3771. offset += 4;
  3772. obj.achVendID = [bin.readInt8(data, offset), bin.readInt8(data, offset + 1), bin.readInt8(data, offset + 2), bin.readInt8(data, offset + 3)];
  3773. offset += 4;
  3774. obj.fsSelection = bin.readUshort(data, offset);
  3775. offset += 2;
  3776. obj.usFirstCharIndex = bin.readUshort(data, offset);
  3777. offset += 2;
  3778. obj.usLastCharIndex = bin.readUshort(data, offset);
  3779. offset += 2;
  3780. obj.sTypoAscender = bin.readShort(data, offset);
  3781. offset += 2;
  3782. obj.sTypoDescender = bin.readShort(data, offset);
  3783. offset += 2;
  3784. obj.sTypoLineGap = bin.readShort(data, offset);
  3785. offset += 2;
  3786. obj.usWinAscent = bin.readUshort(data, offset);
  3787. offset += 2;
  3788. obj.usWinDescent = bin.readUshort(data, offset);
  3789. offset += 2;
  3790. return offset;
  3791. };
  3792. Typr["OS/2"].version1 = function(data, offset, obj) {
  3793. var bin = Typr._bin;
  3794. offset = Typr["OS/2"].version0(data, offset, obj);
  3795. obj.ulCodePageRange1 = bin.readUint(data, offset);
  3796. offset += 4;
  3797. obj.ulCodePageRange2 = bin.readUint(data, offset);
  3798. offset += 4;
  3799. return offset;
  3800. };
  3801. Typr["OS/2"].version2 = function(data, offset, obj) {
  3802. var bin = Typr._bin;
  3803. offset = Typr["OS/2"].version1(data, offset, obj);
  3804. obj.sxHeight = bin.readShort(data, offset);
  3805. offset += 2;
  3806. obj.sCapHeight = bin.readShort(data, offset);
  3807. offset += 2;
  3808. obj.usDefault = bin.readUshort(data, offset);
  3809. offset += 2;
  3810. obj.usBreak = bin.readUshort(data, offset);
  3811. offset += 2;
  3812. obj.usMaxContext = bin.readUshort(data, offset);
  3813. offset += 2;
  3814. return offset;
  3815. };
  3816. Typr["OS/2"].version5 = function(data, offset, obj) {
  3817. var bin = Typr._bin;
  3818. offset = Typr["OS/2"].version2(data, offset, obj);
  3819. obj.usLowerOpticalPointSize = bin.readUshort(data, offset);
  3820. offset += 2;
  3821. obj.usUpperOpticalPointSize = bin.readUshort(data, offset);
  3822. offset += 2;
  3823. return offset;
  3824. };
  3825. Typr.post = {};
  3826. Typr.post.parse = function(data, offset, length) {
  3827. var bin = Typr._bin;
  3828. var obj = {};
  3829. obj.version = bin.readFixed(data, offset);
  3830. offset += 4;
  3831. obj.italicAngle = bin.readFixed(data, offset);
  3832. offset += 4;
  3833. obj.underlinePosition = bin.readShort(data, offset);
  3834. offset += 2;
  3835. obj.underlineThickness = bin.readShort(data, offset);
  3836. offset += 2;
  3837. return obj;
  3838. };
  3839. Typr.SVG = {};
  3840. Typr.SVG.parse = function(data, offset, length) {
  3841. var bin = Typr._bin;
  3842. var obj = { entries: [] };
  3843. var offset0 = offset;
  3844. bin.readUshort(data, offset);
  3845. offset += 2;
  3846. var svgDocIndexOffset = bin.readUint(data, offset);
  3847. offset += 4;
  3848. bin.readUint(data, offset);
  3849. offset += 4;
  3850. offset = svgDocIndexOffset + offset0;
  3851. var numEntries = bin.readUshort(data, offset);
  3852. offset += 2;
  3853. for (var i = 0; i < numEntries; i++) {
  3854. var startGlyphID = bin.readUshort(data, offset);
  3855. offset += 2;
  3856. var endGlyphID = bin.readUshort(data, offset);
  3857. offset += 2;
  3858. var svgDocOffset = bin.readUint(data, offset);
  3859. offset += 4;
  3860. var svgDocLength = bin.readUint(data, offset);
  3861. offset += 4;
  3862. var sbuf = new Uint8Array(data.buffer, offset0 + svgDocOffset + svgDocIndexOffset, svgDocLength);
  3863. var svg = bin.readUTF8(sbuf, 0, sbuf.length);
  3864. for (var f = startGlyphID; f <= endGlyphID; f++) {
  3865. obj.entries[f] = svg;
  3866. }
  3867. }
  3868. return obj;
  3869. };
  3870. Typr.SVG.toPath = function(str) {
  3871. var pth = { cmds: [], crds: [] };
  3872. if (str == null)
  3873. return pth;
  3874. var prsr = new DOMParser();
  3875. var doc = prsr["parseFromString"](str, "image/svg+xml");
  3876. var svg = doc.firstChild;
  3877. while (svg.tagName != "svg")
  3878. svg = svg.nextSibling;
  3879. var vb = svg.getAttribute("viewBox");
  3880. if (vb)
  3881. vb = vb.trim().split(" ").map(parseFloat);
  3882. else
  3883. vb = [0, 0, 1e3, 1e3];
  3884. Typr.SVG._toPath(svg.children, pth);
  3885. for (var i = 0; i < pth.crds.length; i += 2) {
  3886. var x = pth.crds[i], y = pth.crds[i + 1];
  3887. x -= vb[0];
  3888. y -= vb[1];
  3889. y = -y;
  3890. pth.crds[i] = x;
  3891. pth.crds[i + 1] = y;
  3892. }
  3893. return pth;
  3894. };
  3895. Typr.SVG._toPath = function(nds, pth, fill) {
  3896. for (var ni = 0; ni < nds.length; ni++) {
  3897. var nd = nds[ni], tn = nd.tagName;
  3898. var cfl = nd.getAttribute("fill");
  3899. if (cfl == null)
  3900. cfl = fill;
  3901. if (tn == "g")
  3902. Typr.SVG._toPath(nd.children, pth, cfl);
  3903. else if (tn == "path") {
  3904. pth.cmds.push(cfl ? cfl : "#000000");
  3905. var d = nd.getAttribute("d");
  3906. var toks = Typr.SVG._tokens(d);
  3907. Typr.SVG._toksToPath(toks, pth);
  3908. pth.cmds.push("X");
  3909. } else if (tn == "defs")
  3910. ;
  3911. else
  3912. console.warn(tn, nd);
  3913. }
  3914. };
  3915. Typr.SVG._tokens = function(d) {
  3916. var ts = [], off = 0, rn = false, cn = "";
  3917. while (off < d.length) {
  3918. var cc = d.charCodeAt(off), ch = d.charAt(off);
  3919. off++;
  3920. var isNum = 48 <= cc && cc <= 57 || ch == "." || ch == "-";
  3921. if (rn) {
  3922. if (ch == "-") {
  3923. ts.push(parseFloat(cn));
  3924. cn = ch;
  3925. } else if (isNum)
  3926. cn += ch;
  3927. else {
  3928. ts.push(parseFloat(cn));
  3929. if (ch != "," && ch != " ")
  3930. ts.push(ch);
  3931. rn = false;
  3932. }
  3933. } else {
  3934. if (isNum) {
  3935. cn = ch;
  3936. rn = true;
  3937. } else if (ch != "," && ch != " ")
  3938. ts.push(ch);
  3939. }
  3940. }
  3941. if (rn)
  3942. ts.push(parseFloat(cn));
  3943. return ts;
  3944. };
  3945. Typr.SVG._toksToPath = function(ts, pth) {
  3946. var i = 0, x = 0, y = 0, ox = 0, oy = 0;
  3947. var pc = { "M": 2, "L": 2, "H": 1, "V": 1, "S": 4, "C": 6 };
  3948. var cmds = pth.cmds, crds = pth.crds;
  3949. while (i < ts.length) {
  3950. var cmd = ts[i];
  3951. i++;
  3952. if (cmd == "z") {
  3953. cmds.push("Z");
  3954. x = ox;
  3955. y = oy;
  3956. } else {
  3957. var cmu = cmd.toUpperCase();
  3958. var ps = pc[cmu], reps = Typr.SVG._reps(ts, i, ps);
  3959. for (var j = 0; j < reps; j++) {
  3960. var xi = 0, yi = 0;
  3961. if (cmd != cmu) {
  3962. xi = x;
  3963. yi = y;
  3964. }
  3965. if (cmu == "M") {
  3966. x = xi + ts[i++];
  3967. y = yi + ts[i++];
  3968. cmds.push("M");
  3969. crds.push(x, y);
  3970. ox = x;
  3971. oy = y;
  3972. } else if (cmu == "L") {
  3973. x = xi + ts[i++];
  3974. y = yi + ts[i++];
  3975. cmds.push("L");
  3976. crds.push(x, y);
  3977. } else if (cmu == "H") {
  3978. x = xi + ts[i++];
  3979. cmds.push("L");
  3980. crds.push(x, y);
  3981. } else if (cmu == "V") {
  3982. y = yi + ts[i++];
  3983. cmds.push("L");
  3984. crds.push(x, y);
  3985. } else if (cmu == "C") {
  3986. var x1 = xi + ts[i++], y1 = yi + ts[i++], x2 = xi + ts[i++], y2 = yi + ts[i++], x3 = xi + ts[i++], y3 = yi + ts[i++];
  3987. cmds.push("C");
  3988. crds.push(x1, y1, x2, y2, x3, y3);
  3989. x = x3;
  3990. y = y3;
  3991. } else if (cmu == "S") {
  3992. var co = Math.max(crds.length - 4, 0);
  3993. var x1 = x + x - crds[co], y1 = y + y - crds[co + 1];
  3994. var x2 = xi + ts[i++], y2 = yi + ts[i++], x3 = xi + ts[i++], y3 = yi + ts[i++];
  3995. cmds.push("C");
  3996. crds.push(x1, y1, x2, y2, x3, y3);
  3997. x = x3;
  3998. y = y3;
  3999. } else
  4000. console.warn("Unknown SVG command " + cmd);
  4001. }
  4002. }
  4003. }
  4004. };
  4005. Typr.SVG._reps = function(ts, off, ps) {
  4006. var i = off;
  4007. while (i < ts.length) {
  4008. if (typeof ts[i] == "string")
  4009. break;
  4010. i += ps;
  4011. }
  4012. return (i - off) / ps;
  4013. };
  4014. if (Typr == null)
  4015. Typr = {};
  4016. if (Typr.U == null)
  4017. Typr.U = {};
  4018. Typr.U.codeToGlyph = function(font, code) {
  4019. var cmap = font.cmap;
  4020. var tind = -1;
  4021. if (cmap.p0e4 != null)
  4022. tind = cmap.p0e4;
  4023. else if (cmap.p3e1 != null)
  4024. tind = cmap.p3e1;
  4025. else if (cmap.p1e0 != null)
  4026. tind = cmap.p1e0;
  4027. else if (cmap.p0e3 != null)
  4028. tind = cmap.p0e3;
  4029. if (tind == -1)
  4030. throw "no familiar platform and encoding!";
  4031. var tab = cmap.tables[tind];
  4032. if (tab.format == 0) {
  4033. if (code >= tab.map.length)
  4034. return 0;
  4035. return tab.map[code];
  4036. } else if (tab.format == 4) {
  4037. var sind = -1;
  4038. for (var i = 0; i < tab.endCount.length; i++) {
  4039. if (code <= tab.endCount[i]) {
  4040. sind = i;
  4041. break;
  4042. }
  4043. }
  4044. if (sind == -1)
  4045. return 0;
  4046. if (tab.startCount[sind] > code)
  4047. return 0;
  4048. var gli = 0;
  4049. if (tab.idRangeOffset[sind] != 0) {
  4050. gli = tab.glyphIdArray[code - tab.startCount[sind] + (tab.idRangeOffset[sind] >> 1) - (tab.idRangeOffset.length - sind)];
  4051. } else {
  4052. gli = code + tab.idDelta[sind];
  4053. }
  4054. return gli & 65535;
  4055. } else if (tab.format == 12) {
  4056. if (code > tab.groups[tab.groups.length - 1][1])
  4057. return 0;
  4058. for (var i = 0; i < tab.groups.length; i++) {
  4059. var grp = tab.groups[i];
  4060. if (grp[0] <= code && code <= grp[1])
  4061. return grp[2] + (code - grp[0]);
  4062. }
  4063. return 0;
  4064. } else {
  4065. throw "unknown cmap table format " + tab.format;
  4066. }
  4067. };
  4068. Typr.U.glyphToPath = function(font, gid) {
  4069. var path = { cmds: [], crds: [] };
  4070. if (font.SVG && font.SVG.entries[gid]) {
  4071. var p = font.SVG.entries[gid];
  4072. if (p == null)
  4073. return path;
  4074. if (typeof p == "string") {
  4075. p = Typr.SVG.toPath(p);
  4076. font.SVG.entries[gid] = p;
  4077. }
  4078. return p;
  4079. } else if (font.CFF) {
  4080. var state = { x: 0, y: 0, stack: [], nStems: 0, haveWidth: false, width: font.CFF.Private ? font.CFF.Private.defaultWidthX : 0, open: false };
  4081. var cff = font.CFF, pdct = font.CFF.Private;
  4082. if (cff.ROS) {
  4083. var gi = 0;
  4084. while (cff.FDSelect[gi + 2] <= gid)
  4085. gi += 2;
  4086. pdct = cff.FDArray[cff.FDSelect[gi + 1]].Private;
  4087. }
  4088. Typr.U._drawCFF(font.CFF.CharStrings[gid], state, cff, pdct, path);
  4089. } else if (font.glyf) {
  4090. Typr.U._drawGlyf(gid, font, path);
  4091. }
  4092. return path;
  4093. };
  4094. Typr.U._drawGlyf = function(gid, font, path) {
  4095. var gl = font.glyf[gid];
  4096. if (gl == null)
  4097. gl = font.glyf[gid] = Typr.glyf._parseGlyf(font, gid);
  4098. if (gl != null) {
  4099. if (gl.noc > -1) {
  4100. Typr.U._simpleGlyph(gl, path);
  4101. } else {
  4102. Typr.U._compoGlyph(gl, font, path);
  4103. }
  4104. }
  4105. };
  4106. Typr.U._simpleGlyph = function(gl, p) {
  4107. for (var c = 0; c < gl.noc; c++) {
  4108. var i0 = c == 0 ? 0 : gl.endPts[c - 1] + 1;
  4109. var il = gl.endPts[c];
  4110. for (var i = i0; i <= il; i++) {
  4111. var pr = i == i0 ? il : i - 1;
  4112. var nx = i == il ? i0 : i + 1;
  4113. var onCurve = gl.flags[i] & 1;
  4114. var prOnCurve = gl.flags[pr] & 1;
  4115. var nxOnCurve = gl.flags[nx] & 1;
  4116. var x = gl.xs[i], y = gl.ys[i];
  4117. if (i == i0) {
  4118. if (onCurve) {
  4119. if (prOnCurve) {
  4120. Typr.U.P.moveTo(p, gl.xs[pr], gl.ys[pr]);
  4121. } else {
  4122. Typr.U.P.moveTo(p, x, y);
  4123. continue;
  4124. }
  4125. } else {
  4126. if (prOnCurve) {
  4127. Typr.U.P.moveTo(p, gl.xs[pr], gl.ys[pr]);
  4128. } else {
  4129. Typr.U.P.moveTo(p, (gl.xs[pr] + x) / 2, (gl.ys[pr] + y) / 2);
  4130. }
  4131. }
  4132. }
  4133. if (onCurve) {
  4134. if (prOnCurve)
  4135. Typr.U.P.lineTo(p, x, y);
  4136. } else {
  4137. if (nxOnCurve) {
  4138. Typr.U.P.qcurveTo(p, x, y, gl.xs[nx], gl.ys[nx]);
  4139. } else {
  4140. Typr.U.P.qcurveTo(p, x, y, (x + gl.xs[nx]) / 2, (y + gl.ys[nx]) / 2);
  4141. }
  4142. }
  4143. }
  4144. Typr.U.P.closePath(p);
  4145. }
  4146. };
  4147. Typr.U._compoGlyph = function(gl, font, p) {
  4148. for (var j = 0; j < gl.parts.length; j++) {
  4149. var path = { cmds: [], crds: [] };
  4150. var prt = gl.parts[j];
  4151. Typr.U._drawGlyf(prt.glyphIndex, font, path);
  4152. var m = prt.m;
  4153. for (var i = 0; i < path.crds.length; i += 2) {
  4154. var x = path.crds[i], y = path.crds[i + 1];
  4155. p.crds.push(x * m.a + y * m.b + m.tx);
  4156. p.crds.push(x * m.c + y * m.d + m.ty);
  4157. }
  4158. for (var i = 0; i < path.cmds.length; i++) {
  4159. p.cmds.push(path.cmds[i]);
  4160. }
  4161. }
  4162. };
  4163. Typr.U._getGlyphClass = function(g, cd) {
  4164. var intr = Typr._lctf.getInterval(cd, g);
  4165. return intr == -1 ? 0 : cd[intr + 2];
  4166. };
  4167. Typr.U.getPairAdjustment = function(font, g1, g2) {
  4168. var hasGPOSkern = false;
  4169. if (font.GPOS) {
  4170. var gpos = font["GPOS"];
  4171. var llist = gpos.lookupList, flist = gpos.featureList;
  4172. var tused = [];
  4173. for (var i = 0; i < flist.length; i++) {
  4174. var fl = flist[i];
  4175. if (fl.tag != "kern")
  4176. continue;
  4177. hasGPOSkern = true;
  4178. for (var ti = 0; ti < fl.tab.length; ti++) {
  4179. if (tused[fl.tab[ti]])
  4180. continue;
  4181. tused[fl.tab[ti]] = true;
  4182. var tab = llist[fl.tab[ti]];
  4183. for (var j = 0; j < tab.tabs.length; j++) {
  4184. if (tab.tabs[j] == null)
  4185. continue;
  4186. var ltab = tab.tabs[j], ind;
  4187. if (ltab.coverage) {
  4188. ind = Typr._lctf.coverageIndex(ltab.coverage, g1);
  4189. if (ind == -1)
  4190. continue;
  4191. }
  4192. if (tab.ltype == 1)
  4193. ;
  4194. else if (tab.ltype == 2) {
  4195. var adj = null;
  4196. if (ltab.fmt == 1) {
  4197. var right = ltab.pairsets[ind];
  4198. for (var i = 0; i < right.length; i++) {
  4199. if (right[i].gid2 == g2)
  4200. adj = right[i];
  4201. }
  4202. } else if (ltab.fmt == 2) {
  4203. var c1 = Typr.U._getGlyphClass(g1, ltab.classDef1);
  4204. var c2 = Typr.U._getGlyphClass(g2, ltab.classDef2);
  4205. adj = ltab.matrix[c1][c2];
  4206. }
  4207. if (adj) {
  4208. var offset = 0;
  4209. if (adj.val1 && adj.val1[2])
  4210. offset += adj.val1[2];
  4211. if (adj.val2 && adj.val2[0])
  4212. offset += adj.val2[0];
  4213. return offset;
  4214. }
  4215. }
  4216. }
  4217. }
  4218. }
  4219. }
  4220. if (font.kern && !hasGPOSkern) {
  4221. var ind1 = font.kern.glyph1.indexOf(g1);
  4222. if (ind1 != -1) {
  4223. var ind2 = font.kern.rval[ind1].glyph2.indexOf(g2);
  4224. if (ind2 != -1)
  4225. return font.kern.rval[ind1].vals[ind2];
  4226. }
  4227. }
  4228. return 0;
  4229. };
  4230. Typr.U.stringToGlyphs = function(font, str) {
  4231. var gls = [];
  4232. for (var i = 0; i < str.length; i++) {
  4233. var cc = str.codePointAt(i);
  4234. if (cc > 65535)
  4235. i++;
  4236. gls.push(Typr.U.codeToGlyph(font, cc));
  4237. }
  4238. for (var i = 0; i < str.length; i++) {
  4239. var cc = str.codePointAt(i);
  4240. if (cc == 2367) {
  4241. var t = gls[i - 1];
  4242. gls[i - 1] = gls[i];
  4243. gls[i] = t;
  4244. }
  4245. if (cc > 65535)
  4246. i++;
  4247. }
  4248. var gsub = font["GSUB"];
  4249. if (gsub == null)
  4250. return gls;
  4251. var llist = gsub.lookupList, flist = gsub.featureList;
  4252. var cligs = [
  4253. "rlig",
  4254. "liga",
  4255. "mset",
  4256. "isol",
  4257. "init",
  4258. "fina",
  4259. "medi",
  4260. "half",
  4261. "pres",
  4262. "blws"
  4263. /* Tibetan fonts like Himalaya.ttf */
  4264. ];
  4265. var tused = [];
  4266. for (var fi = 0; fi < flist.length; fi++) {
  4267. var fl = flist[fi];
  4268. if (cligs.indexOf(fl.tag) == -1)
  4269. continue;
  4270. for (var ti = 0; ti < fl.tab.length; ti++) {
  4271. if (tused[fl.tab[ti]])
  4272. continue;
  4273. tused[fl.tab[ti]] = true;
  4274. var tab = llist[fl.tab[ti]];
  4275. for (var ci = 0; ci < gls.length; ci++) {
  4276. var feat = Typr.U._getWPfeature(str, ci);
  4277. if ("isol,init,fina,medi".indexOf(fl.tag) != -1 && fl.tag != feat)
  4278. continue;
  4279. Typr.U._applySubs(gls, ci, tab, llist);
  4280. }
  4281. }
  4282. }
  4283. return gls;
  4284. };
  4285. Typr.U._getWPfeature = function(str, ci) {
  4286. var wsep = '\n " ,.:;!?() ،';
  4287. var R = "آأؤإاةدذرزوٱٲٳٵٶٷڈډڊڋڌڍڎڏڐڑڒړڔڕږڗژڙۀۃۄۅۆۇۈۉۊۋۍۏےۓەۮۯܐܕܖܗܘܙܞܨܪܬܯݍݙݚݛݫݬݱݳݴݸݹࡀࡆࡇࡉࡔࡧࡩࡪࢪࢫࢬࢮࢱࢲࢹૅેૉ૊૎૏ૐ૑૒૝ૡ૤૯஁ஃ஄அஉ஌எஏ஑னப஫஬";
  4288. var L = "ꡲ્૗";
  4289. var slft = ci == 0 || wsep.indexOf(str[ci - 1]) != -1;
  4290. var srgt = ci == str.length - 1 || wsep.indexOf(str[ci + 1]) != -1;
  4291. if (!slft && R.indexOf(str[ci - 1]) != -1)
  4292. slft = true;
  4293. if (!srgt && R.indexOf(str[ci]) != -1)
  4294. srgt = true;
  4295. if (!srgt && L.indexOf(str[ci + 1]) != -1)
  4296. srgt = true;
  4297. if (!slft && L.indexOf(str[ci]) != -1)
  4298. slft = true;
  4299. var feat = null;
  4300. if (slft) {
  4301. feat = srgt ? "isol" : "init";
  4302. } else {
  4303. feat = srgt ? "fina" : "medi";
  4304. }
  4305. return feat;
  4306. };
  4307. Typr.U._applySubs = function(gls, ci, tab, llist) {
  4308. var rlim = gls.length - ci - 1;
  4309. for (var j = 0; j < tab.tabs.length; j++) {
  4310. if (tab.tabs[j] == null)
  4311. continue;
  4312. var ltab = tab.tabs[j], ind;
  4313. if (ltab.coverage) {
  4314. ind = Typr._lctf.coverageIndex(ltab.coverage, gls[ci]);
  4315. if (ind == -1)
  4316. continue;
  4317. }
  4318. if (tab.ltype == 1) {
  4319. gls[ci];
  4320. if (ltab.fmt == 1)
  4321. gls[ci] = gls[ci] + ltab.delta;
  4322. else
  4323. gls[ci] = ltab.newg[ind];
  4324. } else if (tab.ltype == 4) {
  4325. var vals = ltab.vals[ind];
  4326. for (var k = 0; k < vals.length; k++) {
  4327. var lig = vals[k], rl = lig.chain.length;
  4328. if (rl > rlim)
  4329. continue;
  4330. var good = true, em1 = 0;
  4331. for (var l = 0; l < rl; l++) {
  4332. while (gls[ci + em1 + (1 + l)] == -1)
  4333. em1++;
  4334. if (lig.chain[l] != gls[ci + em1 + (1 + l)])
  4335. good = false;
  4336. }
  4337. if (!good)
  4338. continue;
  4339. gls[ci] = lig.nglyph;
  4340. for (var l = 0; l < rl + em1; l++)
  4341. gls[ci + l + 1] = -1;
  4342. break;
  4343. }
  4344. } else if (tab.ltype == 5 && ltab.fmt == 2) {
  4345. var cind = Typr._lctf.getInterval(ltab.cDef, gls[ci]);
  4346. var cls = ltab.cDef[cind + 2], scs = ltab.scset[cls];
  4347. for (var i = 0; i < scs.length; i++) {
  4348. var sc = scs[i], inp = sc.input;
  4349. if (inp.length > rlim)
  4350. continue;
  4351. var good = true;
  4352. for (var l = 0; l < inp.length; l++) {
  4353. var cind2 = Typr._lctf.getInterval(ltab.cDef, gls[ci + 1 + l]);
  4354. if (cind == -1 && ltab.cDef[cind2 + 2] != inp[l]) {
  4355. good = false;
  4356. break;
  4357. }
  4358. }
  4359. if (!good)
  4360. continue;
  4361. var lrs = sc.substLookupRecords;
  4362. for (var k = 0; k < lrs.length; k += 2) {
  4363. lrs[k];
  4364. lrs[k + 1];
  4365. }
  4366. }
  4367. } else if (tab.ltype == 6 && ltab.fmt == 3) {
  4368. if (!Typr.U._glsCovered(gls, ltab.backCvg, ci - ltab.backCvg.length))
  4369. continue;
  4370. if (!Typr.U._glsCovered(gls, ltab.inptCvg, ci))
  4371. continue;
  4372. if (!Typr.U._glsCovered(gls, ltab.ahedCvg, ci + ltab.inptCvg.length))
  4373. continue;
  4374. var lr = ltab.lookupRec;
  4375. for (var i = 0; i < lr.length; i += 2) {
  4376. var cind = lr[i], tab2 = llist[lr[i + 1]];
  4377. Typr.U._applySubs(gls, ci + cind, tab2, llist);
  4378. }
  4379. }
  4380. }
  4381. };
  4382. Typr.U._glsCovered = function(gls, cvgs, ci) {
  4383. for (var i = 0; i < cvgs.length; i++) {
  4384. var ind = Typr._lctf.coverageIndex(cvgs[i], gls[ci + i]);
  4385. if (ind == -1)
  4386. return false;
  4387. }
  4388. return true;
  4389. };
  4390. Typr.U.glyphsToPath = function(font, gls, clr) {
  4391. var tpath = { cmds: [], crds: [] };
  4392. var x = 0;
  4393. for (var i = 0; i < gls.length; i++) {
  4394. var gid = gls[i];
  4395. if (gid == -1)
  4396. continue;
  4397. var gid2 = i < gls.length - 1 && gls[i + 1] != -1 ? gls[i + 1] : 0;
  4398. var path = Typr.U.glyphToPath(font, gid);
  4399. for (var j = 0; j < path.crds.length; j += 2) {
  4400. tpath.crds.push(path.crds[j] + x);
  4401. tpath.crds.push(path.crds[j + 1]);
  4402. }
  4403. if (clr)
  4404. tpath.cmds.push(clr);
  4405. for (var j = 0; j < path.cmds.length; j++)
  4406. tpath.cmds.push(path.cmds[j]);
  4407. if (clr)
  4408. tpath.cmds.push("X");
  4409. x += font.hmtx.aWidth[gid];
  4410. if (i < gls.length - 1)
  4411. x += Typr.U.getPairAdjustment(font, gid, gid2);
  4412. }
  4413. return tpath;
  4414. };
  4415. Typr.U.pathToSVG = function(path, prec) {
  4416. if (prec == null)
  4417. prec = 5;
  4418. var out = [], co = 0, lmap = { "M": 2, "L": 2, "Q": 4, "C": 6 };
  4419. for (var i = 0; i < path.cmds.length; i++) {
  4420. var cmd = path.cmds[i], cn = co + (lmap[cmd] ? lmap[cmd] : 0);
  4421. out.push(cmd);
  4422. while (co < cn) {
  4423. var c = path.crds[co++];
  4424. out.push(parseFloat(c.toFixed(prec)) + (co == cn ? "" : " "));
  4425. }
  4426. }
  4427. return out.join("");
  4428. };
  4429. Typr.U.pathToContext = function(path, ctx) {
  4430. var c = 0, crds = path.crds;
  4431. for (var j = 0; j < path.cmds.length; j++) {
  4432. var cmd = path.cmds[j];
  4433. if (cmd == "M") {
  4434. ctx.moveTo(crds[c], crds[c + 1]);
  4435. c += 2;
  4436. } else if (cmd == "L") {
  4437. ctx.lineTo(crds[c], crds[c + 1]);
  4438. c += 2;
  4439. } else if (cmd == "C") {
  4440. ctx.bezierCurveTo(crds[c], crds[c + 1], crds[c + 2], crds[c + 3], crds[c + 4], crds[c + 5]);
  4441. c += 6;
  4442. } else if (cmd == "Q") {
  4443. ctx.quadraticCurveTo(crds[c], crds[c + 1], crds[c + 2], crds[c + 3]);
  4444. c += 4;
  4445. } else if (cmd.charAt(0) == "#") {
  4446. ctx.beginPath();
  4447. ctx.fillStyle = cmd;
  4448. } else if (cmd == "Z") {
  4449. ctx.closePath();
  4450. } else if (cmd == "X") {
  4451. ctx.fill();
  4452. }
  4453. }
  4454. };
  4455. Typr.U.P = {};
  4456. Typr.U.P.moveTo = function(p, x, y) {
  4457. p.cmds.push("M");
  4458. p.crds.push(x, y);
  4459. };
  4460. Typr.U.P.lineTo = function(p, x, y) {
  4461. p.cmds.push("L");
  4462. p.crds.push(x, y);
  4463. };
  4464. Typr.U.P.curveTo = function(p, a, b, c, d, e, f) {
  4465. p.cmds.push("C");
  4466. p.crds.push(a, b, c, d, e, f);
  4467. };
  4468. Typr.U.P.qcurveTo = function(p, a, b, c, d) {
  4469. p.cmds.push("Q");
  4470. p.crds.push(a, b, c, d);
  4471. };
  4472. Typr.U.P.closePath = function(p) {
  4473. p.cmds.push("Z");
  4474. };
  4475. Typr.U._drawCFF = function(cmds, state, font, pdct, p) {
  4476. var stack = state.stack;
  4477. var nStems = state.nStems, haveWidth = state.haveWidth, width = state.width, open = state.open;
  4478. var i = 0;
  4479. var x = state.x, y = state.y, c1x = 0, c1y = 0, c2x = 0, c2y = 0, c3x = 0, c3y = 0, c4x = 0, c4y = 0, jpx = 0, jpy = 0;
  4480. var o = { val: 0, size: 0 };
  4481. while (i < cmds.length) {
  4482. Typr.CFF.getCharString(cmds, i, o);
  4483. var v = o.val;
  4484. i += o.size;
  4485. if (v == "o1" || v == "o18") {
  4486. var hasWidthArg;
  4487. hasWidthArg = stack.length % 2 !== 0;
  4488. if (hasWidthArg && !haveWidth) {
  4489. width = stack.shift() + pdct.nominalWidthX;
  4490. }
  4491. nStems += stack.length >> 1;
  4492. stack.length = 0;
  4493. haveWidth = true;
  4494. } else if (v == "o3" || v == "o23") {
  4495. var hasWidthArg;
  4496. hasWidthArg = stack.length % 2 !== 0;
  4497. if (hasWidthArg && !haveWidth) {
  4498. width = stack.shift() + pdct.nominalWidthX;
  4499. }
  4500. nStems += stack.length >> 1;
  4501. stack.length = 0;
  4502. haveWidth = true;
  4503. } else if (v == "o4") {
  4504. if (stack.length > 1 && !haveWidth) {
  4505. width = stack.shift() + pdct.nominalWidthX;
  4506. haveWidth = true;
  4507. }
  4508. if (open)
  4509. Typr.U.P.closePath(p);
  4510. y += stack.pop();
  4511. Typr.U.P.moveTo(p, x, y);
  4512. open = true;
  4513. } else if (v == "o5") {
  4514. while (stack.length > 0) {
  4515. x += stack.shift();
  4516. y += stack.shift();
  4517. Typr.U.P.lineTo(p, x, y);
  4518. }
  4519. } else if (v == "o6" || v == "o7") {
  4520. var count = stack.length;
  4521. var isX = v == "o6";
  4522. for (var j = 0; j < count; j++) {
  4523. var sval = stack.shift();
  4524. if (isX) {
  4525. x += sval;
  4526. } else {
  4527. y += sval;
  4528. }
  4529. isX = !isX;
  4530. Typr.U.P.lineTo(p, x, y);
  4531. }
  4532. } else if (v == "o8" || v == "o24") {
  4533. var count = stack.length;
  4534. var index = 0;
  4535. while (index + 6 <= count) {
  4536. c1x = x + stack.shift();
  4537. c1y = y + stack.shift();
  4538. c2x = c1x + stack.shift();
  4539. c2y = c1y + stack.shift();
  4540. x = c2x + stack.shift();
  4541. y = c2y + stack.shift();
  4542. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y);
  4543. index += 6;
  4544. }
  4545. if (v == "o24") {
  4546. x += stack.shift();
  4547. y += stack.shift();
  4548. Typr.U.P.lineTo(p, x, y);
  4549. }
  4550. } else if (v == "o11") {
  4551. break;
  4552. } else if (v == "o1234" || v == "o1235" || v == "o1236" || v == "o1237") {
  4553. if (v == "o1234") {
  4554. c1x = x + stack.shift();
  4555. c1y = y;
  4556. c2x = c1x + stack.shift();
  4557. c2y = c1y + stack.shift();
  4558. jpx = c2x + stack.shift();
  4559. jpy = c2y;
  4560. c3x = jpx + stack.shift();
  4561. c3y = c2y;
  4562. c4x = c3x + stack.shift();
  4563. c4y = y;
  4564. x = c4x + stack.shift();
  4565. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy);
  4566. Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y);
  4567. }
  4568. if (v == "o1235") {
  4569. c1x = x + stack.shift();
  4570. c1y = y + stack.shift();
  4571. c2x = c1x + stack.shift();
  4572. c2y = c1y + stack.shift();
  4573. jpx = c2x + stack.shift();
  4574. jpy = c2y + stack.shift();
  4575. c3x = jpx + stack.shift();
  4576. c3y = jpy + stack.shift();
  4577. c4x = c3x + stack.shift();
  4578. c4y = c3y + stack.shift();
  4579. x = c4x + stack.shift();
  4580. y = c4y + stack.shift();
  4581. stack.shift();
  4582. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy);
  4583. Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y);
  4584. }
  4585. if (v == "o1236") {
  4586. c1x = x + stack.shift();
  4587. c1y = y + stack.shift();
  4588. c2x = c1x + stack.shift();
  4589. c2y = c1y + stack.shift();
  4590. jpx = c2x + stack.shift();
  4591. jpy = c2y;
  4592. c3x = jpx + stack.shift();
  4593. c3y = c2y;
  4594. c4x = c3x + stack.shift();
  4595. c4y = c3y + stack.shift();
  4596. x = c4x + stack.shift();
  4597. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy);
  4598. Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y);
  4599. }
  4600. if (v == "o1237") {
  4601. c1x = x + stack.shift();
  4602. c1y = y + stack.shift();
  4603. c2x = c1x + stack.shift();
  4604. c2y = c1y + stack.shift();
  4605. jpx = c2x + stack.shift();
  4606. jpy = c2y + stack.shift();
  4607. c3x = jpx + stack.shift();
  4608. c3y = jpy + stack.shift();
  4609. c4x = c3x + stack.shift();
  4610. c4y = c3y + stack.shift();
  4611. if (Math.abs(c4x - x) > Math.abs(c4y - y)) {
  4612. x = c4x + stack.shift();
  4613. } else {
  4614. y = c4y + stack.shift();
  4615. }
  4616. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy);
  4617. Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y);
  4618. }
  4619. } else if (v == "o14") {
  4620. if (stack.length > 0 && !haveWidth) {
  4621. width = stack.shift() + font.nominalWidthX;
  4622. haveWidth = true;
  4623. }
  4624. if (stack.length == 4) {
  4625. var adx = stack.shift();
  4626. var ady = stack.shift();
  4627. var bchar = stack.shift();
  4628. var achar = stack.shift();
  4629. var bind2 = Typr.CFF.glyphBySE(font, bchar);
  4630. var aind = Typr.CFF.glyphBySE(font, achar);
  4631. Typr.U._drawCFF(font.CharStrings[bind2], state, font, pdct, p);
  4632. state.x = adx;
  4633. state.y = ady;
  4634. Typr.U._drawCFF(font.CharStrings[aind], state, font, pdct, p);
  4635. }
  4636. if (open) {
  4637. Typr.U.P.closePath(p);
  4638. open = false;
  4639. }
  4640. } else if (v == "o19" || v == "o20") {
  4641. var hasWidthArg;
  4642. hasWidthArg = stack.length % 2 !== 0;
  4643. if (hasWidthArg && !haveWidth) {
  4644. width = stack.shift() + pdct.nominalWidthX;
  4645. }
  4646. nStems += stack.length >> 1;
  4647. stack.length = 0;
  4648. haveWidth = true;
  4649. i += nStems + 7 >> 3;
  4650. } else if (v == "o21") {
  4651. if (stack.length > 2 && !haveWidth) {
  4652. width = stack.shift() + pdct.nominalWidthX;
  4653. haveWidth = true;
  4654. }
  4655. y += stack.pop();
  4656. x += stack.pop();
  4657. if (open)
  4658. Typr.U.P.closePath(p);
  4659. Typr.U.P.moveTo(p, x, y);
  4660. open = true;
  4661. } else if (v == "o22") {
  4662. if (stack.length > 1 && !haveWidth) {
  4663. width = stack.shift() + pdct.nominalWidthX;
  4664. haveWidth = true;
  4665. }
  4666. x += stack.pop();
  4667. if (open)
  4668. Typr.U.P.closePath(p);
  4669. Typr.U.P.moveTo(p, x, y);
  4670. open = true;
  4671. } else if (v == "o25") {
  4672. while (stack.length > 6) {
  4673. x += stack.shift();
  4674. y += stack.shift();
  4675. Typr.U.P.lineTo(p, x, y);
  4676. }
  4677. c1x = x + stack.shift();
  4678. c1y = y + stack.shift();
  4679. c2x = c1x + stack.shift();
  4680. c2y = c1y + stack.shift();
  4681. x = c2x + stack.shift();
  4682. y = c2y + stack.shift();
  4683. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y);
  4684. } else if (v == "o26") {
  4685. if (stack.length % 2) {
  4686. x += stack.shift();
  4687. }
  4688. while (stack.length > 0) {
  4689. c1x = x;
  4690. c1y = y + stack.shift();
  4691. c2x = c1x + stack.shift();
  4692. c2y = c1y + stack.shift();
  4693. x = c2x;
  4694. y = c2y + stack.shift();
  4695. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y);
  4696. }
  4697. } else if (v == "o27") {
  4698. if (stack.length % 2) {
  4699. y += stack.shift();
  4700. }
  4701. while (stack.length > 0) {
  4702. c1x = x + stack.shift();
  4703. c1y = y;
  4704. c2x = c1x + stack.shift();
  4705. c2y = c1y + stack.shift();
  4706. x = c2x + stack.shift();
  4707. y = c2y;
  4708. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y);
  4709. }
  4710. } else if (v == "o10" || v == "o29") {
  4711. var obj = v == "o10" ? pdct : font;
  4712. if (stack.length == 0) {
  4713. console.warn("error: empty stack");
  4714. } else {
  4715. var ind = stack.pop();
  4716. var subr = obj.Subrs[ind + obj.Bias];
  4717. state.x = x;
  4718. state.y = y;
  4719. state.nStems = nStems;
  4720. state.haveWidth = haveWidth;
  4721. state.width = width;
  4722. state.open = open;
  4723. Typr.U._drawCFF(subr, state, font, pdct, p);
  4724. x = state.x;
  4725. y = state.y;
  4726. nStems = state.nStems;
  4727. haveWidth = state.haveWidth;
  4728. width = state.width;
  4729. open = state.open;
  4730. }
  4731. } else if (v == "o30" || v == "o31") {
  4732. var count, count1 = stack.length;
  4733. var index = 0;
  4734. var alternate = v == "o31";
  4735. count = count1 & ~2;
  4736. index += count1 - count;
  4737. while (index < count) {
  4738. if (alternate) {
  4739. c1x = x + stack.shift();
  4740. c1y = y;
  4741. c2x = c1x + stack.shift();
  4742. c2y = c1y + stack.shift();
  4743. y = c2y + stack.shift();
  4744. if (count - index == 5) {
  4745. x = c2x + stack.shift();
  4746. index++;
  4747. } else {
  4748. x = c2x;
  4749. }
  4750. alternate = false;
  4751. } else {
  4752. c1x = x;
  4753. c1y = y + stack.shift();
  4754. c2x = c1x + stack.shift();
  4755. c2y = c1y + stack.shift();
  4756. x = c2x + stack.shift();
  4757. if (count - index == 5) {
  4758. y = c2y + stack.shift();
  4759. index++;
  4760. } else {
  4761. y = c2y;
  4762. }
  4763. alternate = true;
  4764. }
  4765. Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y);
  4766. index += 4;
  4767. }
  4768. } else if ((v + "").charAt(0) == "o") {
  4769. console.warn("Unknown operation: " + v, cmds);
  4770. throw v;
  4771. } else
  4772. stack.push(v);
  4773. }
  4774. state.x = x;
  4775. state.y = y;
  4776. state.nStems = nStems;
  4777. state.haveWidth = haveWidth;
  4778. state.width = width;
  4779. state.open = open;
  4780. };
  4781. Typr$1.Typr = Typr;
  4782. var Font_1 = void 0;
  4783. var Typr_js_1 = Typr$1;
  4784. var friendlyTags = { "aalt": "Access All Alternates", "abvf": "Above-base Forms", "abvm": "Above - base Mark Positioning", "abvs": "Above - base Substitutions", "afrc": "Alternative Fractions", "akhn": "Akhands", "blwf": "Below - base Forms", "blwm": "Below - base Mark Positioning", "blws": "Below - base Substitutions", "calt": "Contextual Alternates", "case": "Case - Sensitive Forms", "ccmp": "Glyph Composition / Decomposition", "cfar": "Conjunct Form After Ro", "cjct": "Conjunct Forms", "clig": "Contextual Ligatures", "cpct": "Centered CJK Punctuation", "cpsp": "Capital Spacing", "cswh": "Contextual Swash", "curs": "Cursive Positioning", "c2pc": "Petite Capitals From Capitals", "c2sc": "Small Capitals From Capitals", "dist": "Distances", "dlig": "Discretionary Ligatures", "dnom": "Denominators", "dtls": "Dotless Forms", "expt": "Expert Forms", "falt": "Final Glyph on Line Alternates", "fin2": "Terminal Forms #2", "fin3": "Terminal Forms #3", "fina": "Terminal Forms", "flac": "Flattened accent forms", "frac": "Fractions", "fwid": "Full Widths", "half": "Half Forms", "haln": "Halant Forms", "halt": "Alternate Half Widths", "hist": "Historical Forms", "hkna": "Horizontal Kana Alternates", "hlig": "Historical Ligatures", "hngl": "Hangul", "hojo": "Hojo Kanji Forms(JIS X 0212 - 1990 Kanji Forms)", "hwid": "Half Widths", "init": "Initial Forms", "isol": "Isolated Forms", "ital": "Italics", "jalt": "Justification Alternates", "jp78": "JIS78 Forms", "jp83": "JIS83 Forms", "jp90": "JIS90 Forms", "jp04": "JIS2004 Forms", "kern": "Kerning", "lfbd": "Left Bounds", "liga": "Standard Ligatures", "ljmo": "Leading Jamo Forms", "lnum": "Lining Figures", "locl": "Localized Forms", "ltra": "Left - to - right alternates", "ltrm": "Left - to - right mirrored forms", "mark": "Mark Positioning", "med2": "Medial Forms #2", "medi": "Medial Forms", "mgrk": "Mathematical Greek", "mkmk": "Mark to Mark Positioning", "mset": "Mark Positioning via Substitution", "nalt": "Alternate Annotation Forms", "nlck": "NLC Kanji Forms", "nukt": "Nukta Forms", "numr": "Numerators", "onum": "Oldstyle Figures", "opbd": "Optical Bounds", "ordn": "Ordinals", "ornm": "Ornaments", "palt": "Proportional Alternate Widths", "pcap": "Petite Capitals", "pkna": "Proportional Kana", "pnum": "Proportional Figures", "pref": "Pre - Base Forms", "pres": "Pre - base Substitutions", "pstf": "Post - base Forms", "psts": "Post - base Substitutions", "pwid": "Proportional Widths", "qwid": "Quarter Widths", "rand": "Randomize", "rclt": "Required Contextual Alternates", "rkrf": "Rakar Forms", "rlig": "Required Ligatures", "rphf": "Reph Forms", "rtbd": "Right Bounds", "rtla": "Right - to - left alternates", "rtlm": "Right - to - left mirrored forms", "ruby": "Ruby Notation Forms", "rvrn": "Required Variation Alternates", "salt": "Stylistic Alternates", "sinf": "Scientific Inferiors", "size": "Optical size", "smcp": "Small Capitals", "smpl": "Simplified Forms", "ssty": "Math script style alternates", "stch": "Stretching Glyph Decomposition", "subs": "Subscript", "sups": "Superscript", "swsh": "Swash", "titl": "Titling", "tjmo": "Trailing Jamo Forms", "tnam": "Traditional Name Forms", "tnum": "Tabular Figures", "trad": "Traditional Forms", "twid": "Third Widths", "unic": "Unicase", "valt": "Alternate Vertical Metrics", "vatu": "Vattu Variants", "vert": "Vertical Writing", "vhal": "Alternate Vertical Half Metrics", "vjmo": "Vowel Jamo Forms", "vkna": "Vertical Kana Alternates", "vkrn": "Vertical Kerning", "vpal": "Proportional Alternate Vertical Metrics", "vrt2": "Vertical Alternates and Rotation", "vrtr": "Vertical Alternates for Rotation", "zero": "Slashed Zero" };
  4785. var Font = (
  4786. /** @class */
  4787. function() {
  4788. function Font2(data) {
  4789. var obj = Typr_js_1.Typr.parse(data);
  4790. if (!obj.length || typeof obj[0] !== "object" || typeof obj[0].hasOwnProperty !== "function") {
  4791. throw "unable to parse font";
  4792. }
  4793. for (var n in obj[0]) {
  4794. this[n] = obj[0][n];
  4795. }
  4796. this.enabledGSUB = {};
  4797. }
  4798. Font2.prototype.getFamilyName = function() {
  4799. return this.name && (this.name.typoFamilyName || this.name.fontFamily) || "";
  4800. };
  4801. Font2.prototype.getSubFamilyName = function() {
  4802. return this.name && (this.name.typoSubfamilyName || this.name.fontSubfamily) || "";
  4803. };
  4804. Font2.prototype.glyphToPath = function(gid) {
  4805. return Typr_js_1.Typr.U.glyphToPath(this, gid);
  4806. };
  4807. Font2.prototype.getPairAdjustment = function(gid1, gid2) {
  4808. return Typr_js_1.Typr.U.getPairAdjustment(this, gid1, gid2);
  4809. };
  4810. Font2.prototype.stringToGlyphs = function(str) {
  4811. return Typr_js_1.Typr.U.stringToGlyphs(this, str);
  4812. };
  4813. Font2.prototype.glyphsToPath = function(gls) {
  4814. return Typr_js_1.Typr.U.glyphsToPath(this, gls);
  4815. };
  4816. Font2.prototype.pathToSVG = function(path, prec) {
  4817. return Typr_js_1.Typr.U.pathToSVG(path, prec);
  4818. };
  4819. Font2.prototype.pathToContext = function(path, ctx) {
  4820. return Typr_js_1.Typr.U.pathToContext(path, ctx);
  4821. };
  4822. Font2.prototype.lookupFriendlyName = function(table, feature) {
  4823. if (this[table] !== void 0) {
  4824. var tbl = this[table];
  4825. var feat = tbl.featureList[feature];
  4826. return this.featureFriendlyName(feat);
  4827. }
  4828. return "";
  4829. };
  4830. Font2.prototype.featureFriendlyName = function(feature) {
  4831. if (friendlyTags[feature.tag]) {
  4832. return friendlyTags[feature.tag];
  4833. }
  4834. if (feature.tag.match(/ss[0-2][0-9]/)) {
  4835. var name_1 = "Stylistic Set " + Number(feature.tag.substr(2, 2)).toString();
  4836. if (feature.featureParams) {
  4837. var version = Typr_js_1.Typr._bin.readUshort(this._data, feature.featureParams);
  4838. if (version === 0) {
  4839. var nameID = Typr_js_1.Typr._bin.readUshort(this._data, feature.featureParams + 2);
  4840. if (this.name && this.name[nameID] !== void 0) {
  4841. return name_1 + " - " + this.name[nameID];
  4842. }
  4843. }
  4844. }
  4845. return name_1;
  4846. }
  4847. if (feature.tag.match(/cv[0-9][0-9]/)) {
  4848. return "Character Variant " + Number(feature.tag.substr(2, 2)).toString();
  4849. }
  4850. return "";
  4851. };
  4852. Font2.prototype.enableGSUB = function(featureNumber) {
  4853. if (this.GSUB) {
  4854. var feature = this.GSUB.featureList[featureNumber];
  4855. if (feature) {
  4856. for (var i = 0; i < feature.tab.length; ++i) {
  4857. this.enabledGSUB[feature.tab[i]] = (this.enabledGSUB[feature.tab[i]] || 0) + 1;
  4858. }
  4859. }
  4860. }
  4861. };
  4862. Font2.prototype.disableGSUB = function(featureNumber) {
  4863. if (this.GSUB) {
  4864. var feature = this.GSUB.featureList[featureNumber];
  4865. if (feature) {
  4866. for (var i = 0; i < feature.tab.length; ++i) {
  4867. if (this.enabledGSUB[feature.tab[i]] > 1) {
  4868. --this.enabledGSUB[feature.tab[i]];
  4869. } else {
  4870. delete this.enabledGSUB[feature.tab[i]];
  4871. }
  4872. }
  4873. }
  4874. }
  4875. };
  4876. Font2.prototype.codeToGlyph = function(code) {
  4877. var g = Typr_js_1.Typr.U.codeToGlyph(this, code);
  4878. if (this.GSUB) {
  4879. var gls = [g];
  4880. for (var n in this.enabledGSUB) {
  4881. var l = this.GSUB.lookupList[n];
  4882. Typr_js_1.Typr.U._applySubs(gls, 0, l, this.GSUB.lookupList);
  4883. }
  4884. if (gls.length === 1)
  4885. return gls[0];
  4886. }
  4887. return g;
  4888. };
  4889. return Font2;
  4890. }()
  4891. );
  4892. Font_1 = Font;
  4893. function decrypt(iframeDocument) {
  4894. var _a, _b, _c;
  4895. const styles = iframeDocument.querySelectorAll("style");
  4896. let tip;
  4897. for (let i = 0; i < styles.length; i++) {
  4898. if ((_a = styles[i].textContent) == null ? void 0 : _a.includes("font-cxsecret")) {
  4899. tip = styles[i];
  4900. break;
  4901. }
  4902. }
  4903. if (!tip)
  4904. return;
  4905. const fontData = (_c = (_b = tip.textContent) == null ? void 0 : _b.match(/base64,([\w\W]+?)'/)) == null ? void 0 : _c[1];
  4906. if (!fontData)
  4907. return;
  4908. const fontArray = base64ToUint8Array(fontData);
  4909. const font = new Font_1(fontArray);
  4910. const table = JSON.parse(_GM_getResourceText("ttf"));
  4911. const match = {};
  4912. for (let i = 19968; i < 40870; i++) {
  4913. const glyph = font.codeToGlyph(i);
  4914. if (!glyph)
  4915. continue;
  4916. const path = font.glyphToPath(glyph);
  4917. const hash = md5(JSON.stringify(path)).slice(24);
  4918. match[i] = table[hash];
  4919. }
  4920. const elements = iframeDocument.querySelectorAll(".font-cxsecret");
  4921. for (let i = 0; i < elements.length; i++) {
  4922. const el = elements[i];
  4923. let html = el.innerHTML;
  4924. for (const key in match) {
  4925. const value = String.fromCharCode(match[key]);
  4926. const regExp = new RegExp(String.fromCharCode(Number(key)), "g");
  4927. html = html.replace(regExp, value);
  4928. }
  4929. el.innerHTML = html;
  4930. el.classList.remove("font-cxsecret");
  4931. }
  4932. function base64ToUint8Array(base64) {
  4933. const data = window.atob(base64);
  4934. const buffer = new Uint8Array(data.length);
  4935. for (let i = 0; i < data.length; ++i) {
  4936. buffer[i] = data.charCodeAt(i);
  4937. }
  4938. return buffer;
  4939. }
  4940. }
  4941. const sleep = (ms) => {
  4942. return new Promise((resolve) => setTimeout(resolve, ms * 1e3));
  4943. };
  4944. const questionType = {
  4945. "单选题": "0",
  4946. "多选题": "1",
  4947. "填空题": "2",
  4948. "判断题": "3",
  4949. "简答题": "4",
  4950. "名词解释": "5",
  4951. "论述题": "6",
  4952. "计算题": "7"
  4953. };
  4954. class BaseQuestionHandler {
  4955. constructor() {
  4956. __publicField(this, "_document", document);
  4957. __publicField(this, "_window", _unsafeWindow);
  4958. __publicField(this, "addLog");
  4959. __publicField(this, "addQuestion");
  4960. __publicField(this, "questions", []);
  4961. __publicField(this, "correctRate", 0);
  4962. __publicField(this, "parseHtml", () => {
  4963. throw new Error("请使用继承类的重写方法");
  4964. });
  4965. __publicField(this, "fillQuestion", (question) => {
  4966. throw new Error("请使用继承类的重写方法");
  4967. });
  4968. __publicField(this, "removeHtml", (html) => {
  4969. if (html == null) {
  4970. return "";
  4971. }
  4972. return html.replace(/<((?!img|sub|sup|br)[^>]+)>/g, "").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").replace(/<br\s*\/?>/g, "\n").replace(/<img.*?src="(.*?)".*?>/g, '<img src="$1"/>').trim();
  4973. });
  4974. const logStore = useLogStore();
  4975. const questionStore = useQuestionStore();
  4976. this.addLog = logStore.addLog;
  4977. this.addQuestion = questionStore.addQuestion;
  4978. }
  4979. }
  4980. const handleError = (msg) => ({
  4981. code: -1,
  4982. data: {
  4983. answer: [],
  4984. num: "",
  4985. usenum: ""
  4986. },
  4987. msg
  4988. });
  4989. const getAnswer = async (question) => {
  4990. var _a;
  4991. const configStore = useConfigStore();
  4992. const url2 = `http://api.tikuhai.com/search`;
  4993. const headers = {
  4994. "Content-Type": "application/json",
  4995. "referer": question.refer
  4996. };
  4997. const data = JSON.stringify({
  4998. "question": question.title,
  4999. "options": Object.keys(question.options),
  5000. "type": questionType[question.type],
  5001. "questionData": question.element.outerHTML,
  5002. "workType": question.workType,
  5003. "id": ((_a = question.refer.match(/courseId=(\d+)/)) == null ? void 0 : _a[1]) || "",
  5004. "key": configStore.queryApis[0].token
  5005. });
  5006. await sleep(configStore.otherParams.params[0].value);
  5007. return new Promise((resolve) => {
  5008. _GM_xmlhttpRequest({
  5009. url: url2,
  5010. method: "POST",
  5011. headers,
  5012. data,
  5013. onload: (response) => {
  5014. const apiResponse = JSON.parse(response.responseText);
  5015. resolve(apiResponse);
  5016. },
  5017. onerror: () => resolve(handleError("请求出错")),
  5018. ontimeout: () => resolve(handleError("请求超时"))
  5019. });
  5020. });
  5021. };
  5022. class CxQuestionHandler extends BaseQuestionHandler {
  5023. constructor(type, iframe) {
  5024. super();
  5025. __publicField(this, "type");
  5026. __publicField(this, "init", async () => {
  5027. this.questions = [];
  5028. this.parseHtml();
  5029. if (this.questions.length) {
  5030. this.addLog(`成功解析到${this.questions.length}个题目`, "primary");
  5031. for (const [index, question] of this.questions.entries()) {
  5032. const answerData = await getAnswer(question);
  5033. if (answerData.code === 200) {
  5034. question.answer = answerData.data.answer;
  5035. this.fillQuestion(question);
  5036. this.addLog(`第${index + 1}道题搜索成功`, "success");
  5037. this.addLog(`剩余次数:${answerData.data.num}`, "primary");
  5038. this.correctRate += 1 / this.questions.length * 100;
  5039. } else if (answerData.code === -1) {
  5040. this.addLog(`第${index + 1}道题搜索失败,点击上方答题查看原因`, "danger");
  5041. question.answer[0] = answerData.msg + '<a style="font</a>';
  5042. }
  5043. this.addQuestion(question);
  5044. }
  5045. } else
  5046. this.addLog("未解析到题目", "danger");
  5047. return Promise.resolve(this.correctRate);
  5048. });
  5049. __publicField(this, "parseHtml", () => {
  5050. if (!this._document)
  5051. return [];
  5052. if (["zj", "zj_new"].includes(this.type)) {
  5053. const questionElements = this._document.querySelectorAll(".TiMu");
  5054. this.addQuestions(questionElements);
  5055. } else if (["zy", "ks"].includes(this.type)) {
  5056. const questionElements = this._document.querySelectorAll(".questionLi");
  5057. this.addQuestions(questionElements);
  5058. }
  5059. });
  5060. __publicField(this, "fillQuestion", (question) => {
  5061. var _a, _b;
  5062. if (!this._window)
  5063. return;
  5064. if (question.type === "单选题" || question.type === "多选题") {
  5065. question.answer.forEach((answer) => {
  5066. for (const key in question.options) {
  5067. if (key === answer) {
  5068. if (["zj"].includes(this.type)) {
  5069. const optionElement = question.options[key].querySelector("input");
  5070. if (optionElement == null ? void 0 : optionElement.getAttribute("checked"))
  5071. return;
  5072. optionElement == null ? void 0 : optionElement.click();
  5073. } else if (["zj_new", "zy"].includes(this.type)) {
  5074. const optionElement = question.options[key];
  5075. if (optionElement.getAttribute("aria-checked") === "true")
  5076. return;
  5077. optionElement == null ? void 0 : optionElement.click();
  5078. } else if (["ks"].includes(this.type)) {
  5079. const optionElement = question.options[key];
  5080. if (optionElement.querySelector(".check_answer"))
  5081. return;
  5082. optionElement == null ? void 0 : optionElement.click();
  5083. }
  5084. }
  5085. }
  5086. });
  5087. } else if (question.type === "填空题") {
  5088. const textareaElements = question.element.querySelectorAll("textarea");
  5089. if (textareaElements.length === 0)
  5090. return;
  5091. textareaElements.forEach((textareaElement, index) => {
  5092. try {
  5093. const ueditor = this._window.UE.getEditor(textareaElement.name);
  5094. ueditor.setContent(question.answer[index]);
  5095. } catch (e) {
  5096. textareaElement.value = "";
  5097. }
  5098. });
  5099. } else if (question.type === "判断题") {
  5100. let answer = "true";
  5101. if (question.answer[0].match(/(^|,)(正确|是|对|√|T|ri|right|true)(,|$)/)) {
  5102. answer = "true";
  5103. } else if (question.answer[0].match(/(^|,)(错误|否|错|×|F|wr|wrong|false)(,|$)/)) {
  5104. answer = "false";
  5105. }
  5106. const trueOrFalse = {
  5107. "true": "对",
  5108. "false": "错"
  5109. };
  5110. for (const key in question.options) {
  5111. if (["zj"].includes(this.type)) {
  5112. const optionElement = question.options[key].querySelector(`input[value='${answer}']`);
  5113. if (optionElement == null ? void 0 : optionElement.getAttribute("checked"))
  5114. return;
  5115. optionElement == null ? void 0 : optionElement.click();
  5116. } else if (["zj_new", "zy"].includes(this.type)) {
  5117. if ((_a = question.options[key].getAttribute("aria-label")) == null ? void 0 : _a.includes(`${trueOrFalse[answer]}选择`)) {
  5118. if (question.options[key].getAttribute("aria-checked") === "true")
  5119. return;
  5120. (_b = question.options[key]) == null ? void 0 : _b.click();
  5121. }
  5122. } else if (["ks"].includes(this.type)) {
  5123. const optionElement = question.options[key].querySelector(`span[data='${answer}']`);
  5124. if (optionElement == null ? void 0 : optionElement.querySelector(".check_answer"))
  5125. return;
  5126. optionElement == null ? void 0 : optionElement.click();
  5127. }
  5128. }
  5129. } else if (question.type === "简答题") {
  5130. const textareaElement = question.element.querySelector("textarea");
  5131. if (!textareaElement)
  5132. return;
  5133. const ueditor = this._window.UE.getEditor(textareaElement.name);
  5134. ueditor.setContent(question.answer[0]);
  5135. } else
  5136. ;
  5137. });
  5138. this.type = type;
  5139. if (iframe) {
  5140. this._document = iframe.contentDocument;
  5141. this._window = iframe.contentWindow;
  5142. }
  5143. }
  5144. extractOptions(optionElements, optionSelector) {
  5145. const optionsObject = {};
  5146. optionElements.forEach((optionElement) => {
  5147. var _a;
  5148. const optionTextContent = this.removeHtml(((_a = optionElement.querySelector(optionSelector)) == null ? void 0 : _a.innerHTML) || "");
  5149. optionsObject[optionTextContent] = optionElement;
  5150. });
  5151. return optionsObject;
  5152. }
  5153. addQuestions(questionElements) {
  5154. questionElements.forEach((questionElement) => {
  5155. var _a, _b, _c;
  5156. let questionTitle = "";
  5157. let questionTypeText = "";
  5158. let optionElements;
  5159. let optionsObject = {};
  5160. if (["zy", "ks"].includes(this.type)) {
  5161. const titleElement = ((_a = questionElement == null ? void 0 : questionElement.querySelector("h3")) == null ? void 0 : _a.innerHTML) || "";
  5162. const colorShallowElement = ((_b = questionElement.querySelector(".colorShallow")) == null ? void 0 : _b.outerHTML) || "";
  5163. if (["zy"].includes(this.type)) {
  5164. questionTypeText = (questionElement == null ? void 0 : questionElement.getAttribute("typename")) || "";
  5165. } else if (["ks"].includes(this.type)) {
  5166. questionTypeText = this.removeHtml(colorShallowElement).slice(1, 4) || "";
  5167. }
  5168. questionTitle = this.removeHtml(titleElement.split(colorShallowElement || "")[1] || "");
  5169. optionElements = questionElement.querySelectorAll(".answerBg");
  5170. optionsObject = this.extractOptions(optionElements, ".answer_p");
  5171. } else if (["zj", "zj_new"].includes(this.type)) {
  5172. questionTitle = this.removeHtml(((_c = questionElement.querySelector(".fontLabel")) == null ? void 0 : _c.innerHTML) || "");
  5173. questionTypeText = questionTitle.slice(1, 4) || "";
  5174. optionElements = questionElement.querySelectorAll('[class*="before-after"]');
  5175. optionsObject = this.extractOptions(optionElements, ".fl.after");
  5176. questionTitle = questionTitle.replace(`【${questionTypeText}】`, "");
  5177. }
  5178. this.questions.push({
  5179. element: questionElement,
  5180. type: questionTypeText,
  5181. title: questionTitle,
  5182. options: optionsObject,
  5183. answer: [],
  5184. workType: ["zj_new"].includes(this.type) ? "zj" : this.type,
  5185. refer: this._window.location.href
  5186. });
  5187. });
  5188. }
  5189. }
  5190. const useCxChapterLogic = () => {
  5191. const logStore = useLogStore();
  5192. const init = () => {
  5193. const currentUrl = window.location.href;
  5194. if (!currentUrl.includes("&mooc2=1")) {
  5195. window.location.href = currentUrl + "&mooc2=1";
  5196. }
  5197. logStore.addLog(`检测到用户进入到章节学习页面`, "primary");
  5198. logStore.addLog(`正在解析任务点,请稍等5-10秒(如果长时间没有反应,请刷新页面)`, "warning");
  5199. };
  5200. const configStore = useConfigStore();
  5201. const processIframeTask = (mode) => {
  5202. const documentElement = document.documentElement;
  5203. const iframe = documentElement.querySelector("iframe");
  5204. if (!iframe) {
  5205. console.warn("No iframe found.");
  5206. return;
  5207. }
  5208. if (mode === "WATCH") {
  5209. watchIframe(documentElement);
  5210. }
  5211. iframe.addEventListener("load", function() {
  5212. watchIframe(documentElement);
  5213. });
  5214. };
  5215. const setupInterceptor = () => {
  5216. const callback = () => {
  5217. processIframeTask("INIT");
  5218. };
  5219. new XMLHttpRequestInterceptor(["validatejobcount", "schoolCourseInfo"], callback);
  5220. };
  5221. const watchIframe = (documentElement) => {
  5222. IframeUtils.getAllNestedIframes(documentElement).subscribe((allIframes) => {
  5223. rxjs.from(allIframes).pipe(concatMap((iframe) => processIframe(iframe))).subscribe({
  5224. complete: async () => {
  5225. logStore.addLog(`本页任务点已全部完成,正前往下一章节`, "success");
  5226. if (configStore.platformParams.cx.parts[0].params[1].value) {
  5227. const nextBtn = documentElement.querySelector("#prevNextFocusNext");
  5228. if (nextBtn == null ? void 0 : nextBtn.getAttribute("onclick")) {
  5229. await sleep(configStore.otherParams.params[0].value);
  5230. document.querySelector(".jb_btn.jb_btn_92.fr.fs14.nextChapter").click();
  5231. } else
  5232. logStore.addLog(`当前是最后一个任务点`, "success");
  5233. } else {
  5234. logStore.addLog(`已经关闭自动下一章节,在设置里可更改`, "danger");
  5235. }
  5236. }
  5237. });
  5238. });
  5239. };
  5240. const processMedia = async (mediaType, iframeDocument) => {
  5241. return new Promise((resolve) => {
  5242. logStore.addLog(`发现一个${mediaType},正在解析`, "warning");
  5243. logStore.addLog(`正在尝试播放${mediaType},请稍等5s`, "primary");
  5244. let isExecuted = false;
  5245. const intervalId = setInterval(async () => {
  5246. const mediaElement = iframeDocument.documentElement.querySelector(mediaType);
  5247. if (mediaElement && !isExecuted) {
  5248. logStore.addLog("播放成功", "success");
  5249. await mediaElement.pause();
  5250. mediaElement.muted = true;
  5251. await mediaElement.play();
  5252. const listener = async () => {
  5253. await sleep(configStore.otherParams.params[0].value);
  5254. await mediaElement.play();
  5255. };
  5256. mediaElement.addEventListener("pause", listener);
  5257. mediaElement.addEventListener("ended", () => {
  5258. logStore.addLog(`${mediaType}已播放完成`, "success");
  5259. mediaElement.removeEventListener("pause", listener);
  5260. resolve();
  5261. });
  5262. isExecuted = true;
  5263. clearInterval(intervalId);
  5264. }
  5265. }, 2500);
  5266. });
  5267. };
  5268. const processWork = async (iframe, iframeDocument, iframeWindow) => {
  5269. logStore.addLog("发现一个作业,正在解析", "warning");
  5270. return new Promise(async (resolve) => {
  5271. if (!iframeDocument)
  5272. return resolve();
  5273. if (iframeDocument.documentElement.innerText.includes("已完成") || iframeDocument.documentElement.innerText.includes("待批阅")) {
  5274. logStore.addLog("作业已经完成,跳过", "success");
  5275. return resolve();
  5276. }
  5277. decrypt(iframeDocument);
  5278. logStore.addLog(`题目列表获取成功`, "primary");
  5279. let chapterType;
  5280. if (iframe.src.includes("mooc2")) {
  5281. chapterType = "zj_new";
  5282. } else
  5283. chapterType = "zj";
  5284. const correctRate = await new CxQuestionHandler(chapterType, iframe).init();
  5285. if (configStore.platformParams.cx.parts[0].params[0].value) {
  5286. logStore.addLog("自动提交已开启,尝试提交", "primary");
  5287. if (correctRate < Number(configStore.otherParams.params[1].value)) {
  5288. logStore.addLog(`正确率小于${configStore.otherParams.params[1].value}%,暂存`, "danger");
  5289. await iframeWindow.noSubmit();
  5290. } else {
  5291. logStore.addLog(`正确率大于${configStore.otherParams.params[1].value}%,提交`, "success");
  5292. await iframeWindow.btnBlueSubmit();
  5293. await sleep(configStore.otherParams.params[0].value);
  5294. await iframeWindow.submitCheckTimes();
  5295. logStore.addLog("提交成功", "success");
  5296. }
  5297. } else {
  5298. logStore.addLog("未开启自动提交,暂存", "primary");
  5299. iframeWindow.alert = () => {
  5300. };
  5301. await iframeWindow.noSubmit();
  5302. }
  5303. logStore.addLog("作业已完成", "success");
  5304. resolve();
  5305. });
  5306. };
  5307. const waitIframeLoad = async (iframe) => {
  5308. return new Promise((resolve) => {
  5309. const intervalId = setInterval(async () => {
  5310. var _a;
  5311. if (iframe.contentDocument && ((_a = iframe.contentDocument) == null ? void 0 : _a.readyState) == "complete") {
  5312. resolve();
  5313. clearInterval(intervalId);
  5314. }
  5315. }, 500);
  5316. });
  5317. };
  5318. const processIframe = async (iframe) => {
  5319. var _a;
  5320. const iframeSrc = iframe.src;
  5321. const iframeDocument = iframe.contentDocument;
  5322. const iframeWindow = iframe.contentWindow;
  5323. if (!iframeDocument || !iframeWindow)
  5324. return Promise.resolve();
  5325. if (iframeSrc.includes("video") || iframeSrc.includes("audio") || iframeSrc.includes("api/work")) {
  5326. await waitIframeLoad(iframe);
  5327. const parentClass = ((_a = iframe.parentElement) == null ? void 0 : _a.className) || "";
  5328. if (parentClass.includes("ans-job-finished")) {
  5329. logStore.addLog("发现一个已完成任务点", "success");
  5330. return Promise.resolve();
  5331. } else if (iframeSrc.includes("video")) {
  5332. return processMedia("video", iframeDocument);
  5333. } else if (iframeSrc.includes("audio")) {
  5334. return processMedia("audio", iframeDocument);
  5335. } else if (iframeSrc.includes("api/work")) {
  5336. return processWork(iframe, iframeDocument, iframeWindow);
  5337. }
  5338. }
  5339. return Promise.resolve();
  5340. };
  5341. init();
  5342. processIframeTask("WATCH");
  5343. setupInterceptor();
  5344. };
  5345. const useCxWorkLogic = async () => {
  5346. const logStore = useLogStore();
  5347. useConfigStore();
  5348. logStore.addLog(`进入新版作业页面,开始准备答题`, "primary");
  5349. logStore.addLog(`正在解析题目, 请等待5s`, "warning");
  5350. await new CxQuestionHandler("zy").init();
  5351. };
  5352. const useCxExamLogic = async () => {
  5353. const logStore = useLogStore();
  5354. const configStore = useConfigStore();
  5355. logStore.addLog(`进入新版考试页面,开始准备答题`, "primary");
  5356. logStore.addLog(`正在解析题目, 请等待5s`, "warning");
  5357. await new CxQuestionHandler("ks").init();
  5358. if (configStore.platformParams.cx.parts[1].params[0].value) {
  5359. logStore.addLog("自动切换已开启,正在前往下一题", "success");
  5360. await sleep(configStore.otherParams.params[0].value);
  5361. document.querySelector(".jb_btn.jb_btn_92.fs14").click();
  5362. } else {
  5363. logStore.addLog("已经关闭自动切换,在设置里可更改", "danger");
  5364. }
  5365. };
  5366. class ZhsQuestionHandler extends BaseQuestionHandler {
  5367. constructor() {
  5368. super();
  5369. __publicField(this, "init", async () => {
  5370. var _a;
  5371. this.questions = [];
  5372. this.parseHtml();
  5373. if (this.questions.length) {
  5374. this.addLog(`成功解析到${this.questions.length}个题目`, "primary");
  5375. for (const [index, question] of this.questions.entries()) {
  5376. const answerData = await getAnswer(question);
  5377. if (answerData.code === 200) {
  5378. question.answer = answerData.data.answer;
  5379. this.fillQuestion(question);
  5380. this.addLog(`第${index + 1}道题搜索成功`, "success");
  5381. this.addLog(`剩余次数:${answerData.data.num}`, "primary");
  5382. } else if (answerData.code === -1) {
  5383. this.addLog(`第${index + 1}道题搜索失败,点击上方答题查看原因`, "danger");
  5384. question.answer[0] = answerData.msg + '<a http://www.dubainow.top/index/index=</a>';
  5385. }
  5386. this.addQuestion(question);
  5387. await ((_a = this._document) == null ? void 0 : _a.querySelectorAll(".switch-btn-box > button")[1]).click();
  5388. }
  5389. } else
  5390. this.addLog("未解析到题目,正在重试", "danger");
  5391. });
  5392. __publicField(this, "parseHtml", () => {
  5393. if (!this._document)
  5394. return [];
  5395. const questionElements = this._document.querySelectorAll(".examPaper_subject");
  5396. this.addQuestions(questionElements);
  5397. });
  5398. __publicField(this, "fillQuestion", (question) => {
  5399. if (!this._window)
  5400. return;
  5401. if (question.type === "单选题" || question.type === "多选题") {
  5402. question.answer.forEach((answer) => {
  5403. for (const key in question.options) {
  5404. if (key === answer) {
  5405. question.options[key].click();
  5406. }
  5407. }
  5408. });
  5409. } else if (question.type === "判断题") {
  5410. let answer = "对";
  5411. if (question.answer[0].match(/(^|,)(正确|是|对|√|T|ri|right|true)(,|$)/)) {
  5412. answer = "对";
  5413. } else if (question.answer[0].match(/(^|,)(错误|否|错|×|F|wr|wrong|false)(,|$)/)) {
  5414. answer = "错";
  5415. }
  5416. for (const key in question.options) {
  5417. if (key === answer) {
  5418. question.options[key].click();
  5419. }
  5420. }
  5421. } else
  5422. ;
  5423. });
  5424. }
  5425. extractOptions(optionElements, optionSelector) {
  5426. const optionsObject = {};
  5427. optionElements.forEach((optionElement) => {
  5428. var _a;
  5429. const optionTextContent = this.removeHtml(((_a = optionElement.querySelector(optionSelector)) == null ? void 0 : _a.innerHTML) || "");
  5430. optionsObject[optionTextContent] = optionElement;
  5431. });
  5432. return optionsObject;
  5433. }
  5434. addQuestions(questionElements) {
  5435. questionElements.forEach((questionElement) => {
  5436. var _a, _b;
  5437. const questionTitle = (questionElement == null ? void 0 : questionElement.querySelector(".subject_describe div,.smallStem_describe p")).__Ivue__._data.shadowDom.textContent;
  5438. const questionType2 = ((_b = (_a = questionElement == null ? void 0 : questionElement.querySelector(".subject_type span")) == null ? void 0 : _a.textContent) == null ? void 0 : _b.slice(1, 4)) || "";
  5439. const optionsObject = this.extractOptions(questionElement == null ? void 0 : questionElement.querySelectorAll(".label"), ".node_detail");
  5440. this.questions.push({
  5441. element: questionElement,
  5442. type: questionType2,
  5443. title: questionTitle,
  5444. options: optionsObject,
  5445. answer: [],
  5446. workType: "zhs",
  5447. refer: this._window.location.href
  5448. });
  5449. });
  5450. }
  5451. }
  5452. const hookError = () => {
  5453. console.log("hookError");
  5454. const oldset = _unsafeWindow.setInterval;
  5455. const oldout = _unsafeWindow.setTimeout;
  5456. _unsafeWindow.setInterval = function(...args) {
  5457. const err = new Error("");
  5458. if (err.stack && err.stack.indexOf("checkoutNotTrustScript") !== -1) {
  5459. return -1;
  5460. }
  5461. return oldset.call(this, ...args);
  5462. };
  5463. _unsafeWindow.setTimeout = function(...args) {
  5464. const err = new Error("");
  5465. if (err.stack && err.stack.indexOf("checkoutNotTrustScript") !== -1) {
  5466. return -1;
  5467. }
  5468. return oldout.call(this, ...args);
  5469. };
  5470. };
  5471. const useZhsAnswerLogic = async () => {
  5472. hookError();
  5473. const logStore = useLogStore();
  5474. useConfigStore();
  5475. logStore.addLog(`进入答题页面,开始准备答题`, "primary");
  5476. logStore.addLog(`正在解析题目, 请等待5s`, "warning");
  5477. new XMLHttpRequestInterceptor(["gateway/t/v1/student"], async () => {
  5478. await new ZhsQuestionHandler().init();
  5479. });
  5480. };
  5481. const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
  5482. name: "Index",
  5483. emits: ["customEvent"],
  5484. setup(__props, { emit }) {
  5485. var _a;
  5486. const cardWidth = vue.ref("310px");
  5487. const isShow = vue.ref(false);
  5488. (_a = document.querySelector("a.experience:not([onclick])")) == null ? void 0 : _a.click();
  5489. const configStore = useConfigStore();
  5490. const logStore = useLogStore();
  5491. const questionStore = useQuestionStore();
  5492. const url2 = window.location.href;
  5493. if (configStore.menuIndex === "1") {
  5494. cardWidth.value = "630px";
  5495. } else {
  5496. cardWidth.value = "310px";
  5497. }
  5498. vue.watch(() => configStore.menuIndex, (newVal) => {
  5499. if (newVal === "1") {
  5500. cardWidth.value = "630px";
  5501. } else {
  5502. cardWidth.value = "310px";
  5503. }
  5504. }, { deep: true });
  5505. logStore.addLog("脚本加载成功,正在解析网页", "primary");
  5506. logStore.addLog("请不要多个脚本同时使用,会有脚本冲突问题", "warning");
  5507. logStore.addLog("如果脚本出现异常,请用谷歌、火狐等浏览器", "warning");
  5508. const urlLogicPairs = [
  5509. { keyword: "/mycourse/studentstudy", logic: useCxChapterLogic },
  5510. { keyword: "/mooc2/work/dowork", logic: useCxWorkLogic },
  5511. { keyword: "/exam-ans/exam", logic: useCxExamLogic },
  5512. { keyword: "mycourse/stu?courseid", logic: () => console.log(101112) },
  5513. { keyword: "/stuExamWeb.html", logic: useZhsAnswerLogic }
  5514. ];
  5515. const executeLogicByUrl = (url22) => {
  5516. for (const { keyword, logic } of urlLogicPairs) {
  5517. if (url22.includes(keyword)) {
  5518. logic();
  5519. isShow.value = true;
  5520. return;
  5521. }
  5522. }
  5523. isShow.value = false;
  5524. };
  5525. executeLogicByUrl(url2);
  5526. emit("customEvent", isShow.value);
  5527. const tabs = [
  5528. {
  5529. label: "首页QQ群321412228",
  5530. icon: position_default,
  5531. component: ScriptHome,
  5532. props: { "log-list": logStore.logList }
  5533. },
  5534. {
  5535. label: "代看",
  5536. icon: document_remove_default,
  5537. component: QuestionTable,
  5538. props: { "question-list": questionStore.questionList }
  5539. },
  5540. {
  5541. label: "设置",
  5542. icon: setting_default,
  5543. component: ScriptSetting,
  5544. props: { "global-config": configStore }
  5545. },
  5546. {
  5547. label: "代看",
  5548. icon: view_default,
  5549. component: OpenCode
  5550. },
  5551. {
  5552. label: "说明",
  5553. icon: view_default
  5554. }
  5555. ];
  5556. return (_ctx, _cache) => {
  5557. const _component_el_tab_pane = vue.resolveComponent("el-tab-pane");
  5558. const _component_el_tabs = vue.resolveComponent("el-tabs");
  5559. return vue.openBlock(), vue.createElementBlock("div", {
  5560. style: vue.normalizeStyle({ width: cardWidth.value }),
  5561. class: "card_content"
  5562. }, [
  5563. vue.createVNode(_component_el_tabs, {
  5564. modelValue: vue.unref(configStore).menuIndex,
  5565. "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vue.unref(configStore).menuIndex = $event),
  5566. class: "demo-tabs"
  5567. }, {
  5568. default: vue.withCtx(() => [
  5569. (vue.openBlock(), vue.createElementBlock(vue.Fragment, null, vue.renderList(tabs, (tab) => {
  5570. return vue.createVNode(_component_el_tab_pane, {
  5571. key: tab.label,
  5572. label: tab.label
  5573. }, {
  5574. default: vue.withCtx(() => [
  5575. tab.component ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(tab.component), vue.normalizeProps(vue.mergeProps({ key: 0 }, tab.props)), null, 16)) : vue.createCommentVNode("", true)
  5576. ]),
  5577. _: 2
  5578. }, 1032, ["label"]);
  5579. }), 64))
  5580. ]),
  5581. _: 1
  5582. }, 8, ["modelValue"])
  5583. ], 4);
  5584. };
  5585. }
  5586. });
  5587. const CardBody = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-6d489ae0"]]);
  5588. const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
  5589. name: "ZoomButtons",
  5590. emits: ["toggleZoom"],
  5591. setup(__props, { emit }) {
  5592. const toggleZoom = (value) => {
  5593. emit("toggleZoom", value);
  5594. };
  5595. return (_ctx, _cache) => {
  5596. const _component_el_icon = vue.resolveComponent("el-icon");
  5597. return vue.openBlock(), vue.createElementBlock("div", {
  5598. onMousedown: _cache[2] || (_cache[2] = vue.withModifiers(() => {
  5599. }, ["stop"]))
  5600. }, [
  5601. vue.createVNode(_component_el_icon, {
  5602. onClick: _cache[0] || (_cache[0] = ($event) => toggleZoom(true)),
  5603. size: "small",
  5604. style: { "cursor": "pointer" }
  5605. }, {
  5606. default: vue.withCtx(() => [
  5607. vue.createVNode(vue.unref(minus_default))
  5608. ]),
  5609. _: 1
  5610. }),
  5611. vue.createVNode(_component_el_icon, {
  5612. onClick: _cache[1] || (_cache[1] = ($event) => toggleZoom(false)),
  5613. size: "small",
  5614. style: { "cursor": "pointer", "margin-left": "8px" }
  5615. }, {
  5616. default: vue.withCtx(() => [
  5617. vue.createVNode(vue.unref(full_screen_default))
  5618. ]),
  5619. _: 1
  5620. })
  5621. ], 32);
  5622. };
  5623. }
  5624. });
  5625. const _hoisted_1 = { class: "overlay" };
  5626. const _hoisted_2 = { class: "title" };
  5627. const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
  5628. name: "layout",
  5629. setup(__props) {
  5630. const isShow = vue.ref(false);
  5631. const configStore = useConfigStore();
  5632. vue.watch(configStore, (newVal) => {
  5633. localStorage.setItem("config", JSON.stringify(newVal));
  5634. }, { deep: true });
  5635. const isDragging = vue.ref(false);
  5636. const offsetX = vue.ref(0);
  5637. const offsetY = vue.ref(0);
  5638. const moveStyle = vue.ref({
  5639. left: configStore.position.x,
  5640. top: configStore.position.y
  5641. });
  5642. const startDrag = (event) => {
  5643. isDragging.value = true;
  5644. offsetX.value = event.clientX - event.target.getBoundingClientRect().left;
  5645. offsetY.value = event.clientY - event.target.getBoundingClientRect().top;
  5646. document.addEventListener("mousemove", drag);
  5647. document.addEventListener("mouseup", endDrag);
  5648. };
  5649. const drag = (event) => {
  5650. if (!isDragging.value)
  5651. return;
  5652. const x = event.clientX - offsetX.value;
  5653. const y = event.clientY - offsetY.value;
  5654. moveStyle.value = {
  5655. left: `${x - 11}px`,
  5656. top: `${y - 11}px`
  5657. };
  5658. configStore.position.x = x - 11 + "px";
  5659. configStore.position.y = y - 11 + "px";
  5660. if (x < 0) {
  5661. moveStyle.value.left = "0px";
  5662. configStore.position.x = "0px";
  5663. }
  5664. if (y < 0) {
  5665. moveStyle.value.top = "0px";
  5666. configStore.position.y = "0px";
  5667. }
  5668. if (x > window.innerWidth - 334) {
  5669. moveStyle.value.left = `${window.innerWidth - 334}px`;
  5670. configStore.position.x = `${window.innerWidth - 334}px`;
  5671. }
  5672. if (y > window.innerHeight - 35) {
  5673. moveStyle.value.top = `${window.innerHeight - 35}px`;
  5674. configStore.position.y = `${window.innerHeight - 35}px`;
  5675. }
  5676. };
  5677. const endDrag = () => {
  5678. isDragging.value = false;
  5679. document.removeEventListener("mousemove", drag);
  5680. document.removeEventListener("mouseup", endDrag);
  5681. };
  5682. return (_ctx, _cache) => {
  5683. const _component_el_icon = vue.resolveComponent("el-icon");
  5684. const _component_el_tooltip = vue.resolveComponent("el-tooltip");
  5685. const _component_el_card = vue.resolveComponent("el-card");
  5686. return vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", {
  5687. style: vue.normalizeStyle(moveStyle.value),
  5688. class: "main-page"
  5689. }, [
  5690. vue.withDirectives(vue.createElementVNode("div", _hoisted_1, null, 512), [
  5691. [vue.vShow, isDragging.value]
  5692. ]),
  5693. vue.createVNode(_component_el_card, {
  5694. style: { "border": "0" },
  5695. "close-on-click-modal": false,
  5696. "lock-scroll": false,
  5697. modal: false,
  5698. "show-close": false,
  5699. "modal-class": "modal"
  5700. }, {
  5701. header: vue.withCtx(() => [
  5702. vue.createElementVNode("div", {
  5703. class: "card-header",
  5704. onMousedown: startDrag
  5705. }, [
  5706. vue.withDirectives(vue.createElementVNode("div", _hoisted_2, [
  5707. vue.createElementVNode("div", null, vue.toDisplayString(vue.unref(configStore).platformParams[vue.unref(configStore).platformName].name), 1),
  5708. isShow.value && !vue.unref(configStore).isMinus ? (vue.openBlock(), vue.createBlock(_component_el_tooltip, {
  5709. key: 0,
  5710. teleported: "",
  5711. effect: "dark",
  5712. placement: "top-start",
  5713. content: "<span>注意事项:<br/>请尽量使用新版,不要使用旧版。有人脸建议代看地址http://www.dubainow.top/index/index<br/></span>",
  5714. "raw-content": ""
  5715. }, {
  5716. default: vue.withCtx(() => [
  5717. vue.createVNode(_component_el_icon, { style: { "margin-left": "5px" } }, {
  5718. default: vue.withCtx(() => [
  5719. vue.createVNode(vue.unref(warning_default))
  5720. ]),
  5721. _: 1
  5722. })
  5723. ]),
  5724. _: 1
  5725. })) : vue.createCommentVNode("", true)
  5726. ], 512), [
  5727. [vue.vShow, !vue.unref(configStore).isMinus]
  5728. ]),
  5729. vue.createVNode(_sfc_main$2, {
  5730. onToggleZoom: _cache[0] || (_cache[0] = ($event) => vue.unref(configStore).isMinus = $event)
  5731. })
  5732. ], 32)
  5733. ]),
  5734. default: vue.withCtx(() => [
  5735. vue.withDirectives(vue.createVNode(CardBody, {
  5736. onCustomEvent: _cache[1] || (_cache[1] = (newValue) => isShow.value = newValue)
  5737. }, null, 512), [
  5738. [vue.vShow, !vue.unref(configStore).isMinus]
  5739. ])
  5740. ]),
  5741. _: 1
  5742. })
  5743. ], 4)), [
  5744. [vue.vShow, isShow.value]
  5745. ]);
  5746. };
  5747. }
  5748. });
  5749. const Layout = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d228382d"]]);
  5750. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  5751. name: "App",
  5752. setup(__props) {
  5753. const configStore = useConfigStore();
  5754. const url2 = window.location.href;
  5755. if (url2.includes("chaoxing"))
  5756. configStore.platformName = "cx";
  5757. else if (url2.includes("zhihuishu"))
  5758. configStore.platformName = "zhs";
  5759. return (_ctx, _cache) => {
  5760. return vue.openBlock(), vue.createBlock(Layout);
  5761. };
  5762. }
  5763. });
  5764. const cssLoader = (e) => {
  5765. const t = GM_getResourceText(e), o = document.createElement("style");
  5766. return o.innerText = t, document.head.append(o), t;
  5767. };
  5768. cssLoader("ElementPlus");
  5769. const hookWebpack = () => {
  5770. let originCall = _unsafeWindow.Function.prototype.call;
  5771. _unsafeWindow.Function.prototype.call = function(...args) {
  5772. var _a, _b;
  5773. const result = originCall.apply(this, args);
  5774. if (((_b = (_a = args[0]) == null ? void 0 : _a.a) == null ? void 0 : _b.version) === "2.5.0") {
  5775. const install = args[1].exports.a.install;
  5776. args[1].exports.a.install = function(...installArgs) {
  5777. installArgs[0].mixin({
  5778. mounted: function() {
  5779. this.$el["__Ivue__"] = this;
  5780. }
  5781. });
  5782. return install.apply(this, installArgs);
  5783. };
  5784. return result;
  5785. }
  5786. return result;
  5787. };
  5788. };
  5789. const url = _unsafeWindow.location.href;
  5790. if (url.includes("zhihuishu.com")) {
  5791. hookWebpack();
  5792. }
  5793. const timer = setInterval(() => {
  5794. if (document.readyState === "complete") {
  5795. clearInterval(timer);
  5796. const app = vue.createApp(_sfc_main);
  5797. const pinia$1 = pinia.createPinia();
  5798. app.use(pinia$1);
  5799. app.use(ElementPlus);
  5800. app.mount(
  5801. (() => {
  5802. const app2 = document.createElement("div");
  5803. document.body.appendChild(app2);
  5804. return app2;
  5805. })()
  5806. );
  5807. }
  5808. }, 100);
  5809. })(Vue, Pinia, rxjs, md5, ElementPlus);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址