"use strict"; define(function (require, exports, module) { console.log(("import ctx")) class MyCtx { #MyRoot = null; constructor() { console.log(("ctx init")); //可以修改的 let editFrontSize = localStorage.getItem('editFrontSize'); if (editFrontSize !== undefined && editFrontSize !== null) { this.editFrontSize = editFrontSize; } else { this.editFrontSize = 14; } this.usn = "syjSyj"; this.docType = 0; // 获取 User-Agent 字符串 const userAgent = window.navigator.userAgent; // 判断是否是手机 this.isMobile = /mobi|android|iphone|ipad|ipod/i.test(userAgent.toLocaleLowerCase()) || this.getScreenWidth() < 768; this.isIOS = /iphone|ipad|ipod/i.test(userAgent.toLocaleLowerCase()) || this.getScreenWidth() < 768; this.isAndroid = /android/i.test(userAgent.toLocaleLowerCase()) || this.getScreenWidth() < 768; // 判断是否是平板电脑 this.isTablet = /tablet/i.test(userAgent.toLocaleLowerCase()) || (this.getScreenWidth() >= 768 && this.getScreenWidth() < 1024); //屏幕宽高 this.screenWidth = 0; this.screenHeight = 0; //默认a4 纸 const a4Utils = require('./a4Utils'); this.designWith = a4Utils.width; //h5 this.MyRoot //文档map this.doc = new Map(); //行号 this.rowNo = 0; //是否开始输入中文 this.inCompositionEvent = false; //最近一次操作 this.latestOpDoc = null; //初始化 } MyRoot() { if (this.#MyRoot === null) { this.#MyRoot = document.getElementById("yxl_note"); } return this.#MyRoot } getMapItem(orderNo) { return this.docMap.get(orderNo); } incrementNumThenReturn() { return this.rowNo++; } getCurRowNo(){ return this.rowNol } getScreenWidth() { return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; } getScreenHeight() { return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; } /** * 新增一个元素 * @param newParagraph */ addNewParagraph(newParagraph) { //docRoot this.MyRoot.appendChild(newParagraph); //mapRoot let myP = new MyDocItem(newParagraph); let curOrder = myP.parseOrder(); let uuid = myP.parseUuid(); this.doc.set(curOrder, new MyMapItem(uuid)) //收起选区到一个点,光标落在一个可编辑元素上 window.myEdit.utils.GetSelection().setPosition(newParagraph, 0); } /** * 同步某一行数据到对应的 map节点 * @param docP * @constructor */ SyncMapItemChildrenStyle(docP) { //子元素为空不处理 let items = docP.childNodes; if (items.length <= 0) { return } //构造参数 let curMyP = new MyDocItem(docP); let mapItem = window.myEdit.ctx.getMapItem(curMyP.parseOrder()); //清空重置 // console.log(mapItem); mapItem.getStyle().setChildrenStyleMapNull(); //遍历 for (let i = 0; i < items.length; i++) { let curItem = items[i]; let tmpClassList = curItem.classList; if (tmpClassList != null && tmpClassList.length > 0) { mapItem.getStyle().setChildrenStyle(i, tmpClassList); } } // console.log("sync docP : ", docP, " children: ", docP.children, " childrenMap: ", mapItem.getStyle().getChildrenStyleMap()) } /** * */ showTestText() { } } // 初始化一次 module.exports = new MyCtx(); })