Fork自 GitCode / 1024程序员开源挑战赛(10.23-11.14)
/*! * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ * * Version: 5.7.0 (2021-02-10) * */ !function(r){var t={};function o(e){if(t[e])return t[e].exports;var n=t[e]={i:e,l:!1,exports:{}};return r[e].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=r,o.c=t,o.d=function(e,n,r){o.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},o.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},o.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return o.d(n,"a",n),n},o.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},o.p="",o(o.s="./src/js/plugins/importcss/plugin.js")}({"./src/js/plugins/importcss/plugin.js":function(module,exports){eval("/**\n * Copyright (c) Tiny Technologies, Inc. All rights reserved.\n * Licensed under the LGPL or a commercial license.\n * For LGPL see License.txt in the project root for license information.\n * For commercial licenses see https://www.tiny.cloud/\n *\n * Version: 5.7.0 (2021-02-10)\n */\n (function () {\n 'use strict';\n\n var global = tinymce.util.Tools.resolve('tinymce.PluginManager');\n\n var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');\n\n var global$2 = tinymce.util.Tools.resolve('tinymce.EditorManager');\n\n var global$3 = tinymce.util.Tools.resolve('tinymce.Env');\n\n var global$4 = tinymce.util.Tools.resolve('tinymce.util.Tools');\n\n var shouldMergeClasses = function (editor) {\n return editor.getParam('importcss_merge_classes');\n };\n var shouldImportExclusive = function (editor) {\n return editor.getParam('importcss_exclusive');\n };\n var getSelectorConverter = function (editor) {\n return editor.getParam('importcss_selector_converter');\n };\n var getSelectorFilter = function (editor) {\n return editor.getParam('importcss_selector_filter');\n };\n var getCssGroups = function (editor) {\n return editor.getParam('importcss_groups');\n };\n var shouldAppend = function (editor) {\n return editor.getParam('importcss_append');\n };\n var getFileFilter = function (editor) {\n return editor.getParam('importcss_file_filter');\n };\n var getSkin = function (editor) {\n var skin = editor.getParam('skin');\n return skin !== false ? skin || 'oxide' : false;\n };\n var getSkinUrl = function (editor) {\n return editor.getParam('skin_url');\n };\n\n var typeOf = function (x) {\n var t = typeof x;\n if (x === null) {\n return 'null';\n } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {\n return 'array';\n } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {\n return 'string';\n } else {\n return t;\n }\n };\n var isType = function (type) {\n return function (value) {\n return typeOf(value) === type;\n };\n };\n var isArray = isType('array');\n\n var nativePush = Array.prototype.push;\n var map = function (xs, f) {\n var len = xs.length;\n var r = new Array(len);\n for (var i = 0; i < len; i++) {\n var x = xs[i];\n r[i] = f(x, i);\n }\n return r;\n };\n var flatten = function (xs) {\n var r = [];\n for (var i = 0, len = xs.length; i < len; ++i) {\n if (!isArray(xs[i])) {\n throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);\n }\n nativePush.apply(r, xs[i]);\n }\n return r;\n };\n var bind = function (xs, f) {\n return flatten(map(xs, f));\n };\n\n var generate = function () {\n var ungroupedOrder = [];\n var groupOrder = [];\n var groups = {};\n var addItemToGroup = function (groupTitle, itemInfo) {\n if (groups[groupTitle]) {\n groups[groupTitle].push(itemInfo);\n } else {\n groupOrder.push(groupTitle);\n groups[groupTitle] = [itemInfo];\n }\n };\n var addItem = function (itemInfo) {\n ungroupedOrder.push(itemInfo);\n };\n var toFormats = function () {\n var groupItems = bind(groupOrder, function (g) {\n var items = groups[g];\n return items.length === 0 ? [] : [{\n title: g,\n items: items\n }];\n });\n return groupItems.concat(ungroupedOrder);\n };\n return {\n addItemToGroup: addItemToGroup,\n addItem: addItem,\n toFormats: toFormats\n };\n };\n\n var removeCacheSuffix = function (url) {\n var cacheSuffix = global$3.cacheSuffix;\n if (typeof url === 'string') {\n url = url.replace('?' + cacheSuffix, '').replace('&' + cacheSuffix, '');\n }\n return url;\n };\n var isSkinContentCss = function (editor, href) {\n var skin = getSkin(editor);\n if (skin) {\n var skinUrlBase = getSkinUrl(editor);\n var skinUrl = skinUrlBase ? editor.documentBaseURI.toAbsolute(skinUrlBase) : global$2.baseURL + '/skins/ui/' + skin;\n var contentSkinUrlPart = global$2.baseURL + '/skins/content/';\n return href === skinUrl + '/content' + (editor.inline ? '.inline' : '') + '.min.css' || href.indexOf(contentSkinUrlPart) !== -1;\n }\n return false;\n };\n var compileFilter = function (filter) {\n if (typeof filter === 'string') {\n return function (value) {\n return value.indexOf(filter) !== -1;\n };\n } else if (filter instanceof RegExp) {\n return function (value) {\n return filter.test(value);\n };\n }\n return filter;\n };\n var isCssImportRule = function (rule) {\n return rule.styleSheet;\n };\n var isCssPageRule = function (rule) {\n return rule.selectorText;\n };\n var getSelectors = function (editor, doc, fileFilter) {\n var selectors = [], contentCSSUrls = {};\n var append = function (styleSheet, imported) {\n var href = styleSheet.href, rules;\n href = removeCacheSuffix(href);\n if (!href || !fileFilter(href, imported) || isSkinContentCss(editor, href)) {\n return;\n }\n global$4.each(styleSheet.imports, function (styleSheet) {\n append(styleSheet, true);\n });\n try {\n rules = styleSheet.cssRules || styleSheet.rules;\n } catch (e) {\n }\n global$4.each(rules, function (cssRule) {\n if (isCssImportRule(cssRule)) {\n append(cssRule.styleSheet, true);\n } else if (isCssPageRule(cssRule)) {\n global$4.each(cssRule.selectorText.split(','), function (selector) {\n selectors.push(global$4.trim(selector));\n });\n }\n });\n };\n global$4.each(editor.contentCSS, function (url) {\n contentCSSUrls[url] = true;\n });\n if (!fileFilter) {\n fileFilter = function (href, imported) {\n return imported || contentCSSUrls[href];\n };\n }\n try {\n global$4.each(doc.styleSheets, function (styleSheet) {\n append(styleSheet);\n });\n } catch (e) {\n }\n return selectors;\n };\n var defaultConvertSelectorToFormat = function (editor, selectorText) {\n var format;\n var selector = /^(?:([a-z0-9\\-_]+))?(\\.[a-z0-9_\\-\\.]+)$/i.exec(selectorText);\n if (!selector) {\n return;\n }\n var elementName = selector[1];\n var classes = selector[2].substr(1).split('.').join(' ');\n var inlineSelectorElements = global$4.makeMap('a,img');\n if (selector[1]) {\n format = { title: selectorText };\n if (editor.schema.getTextBlockElements()[elementName]) {\n format.block = elementName;\n } else if (editor.schema.getBlockElements()[elementName] || inlineSelectorElements[elementName.toLowerCase()]) {\n format.selector = elementName;\n } else {\n format.inline = elementName;\n }\n } else if (selector[2]) {\n format = {\n inline: 'span',\n title: selectorText.substr(1),\n classes: classes\n };\n }\n if (shouldMergeClasses(editor) !== false) {\n format.classes = classes;\n } else {\n format.attributes = { class: classes };\n }\n return format;\n };\n var getGroupsBySelector = function (groups, selector) {\n return global$4.grep(groups, function (group) {\n return !group.filter || group.filter(selector);\n });\n };\n var compileUserDefinedGroups = function (groups) {\n return global$4.map(groups, function (group) {\n return global$4.extend({}, group, {\n original: group,\n selectors: {},\n filter: compileFilter(group.filter),\n item: {\n text: group.title,\n menu: []\n }\n });\n });\n };\n var isExclusiveMode = function (editor, group) {\n return group === null || shouldImportExclusive(editor) !== false;\n };\n var isUniqueSelector = function (editor, selector, group, globallyUniqueSelectors) {\n return !(isExclusiveMode(editor, group) ? selector in globallyUniqueSelectors : selector in group.selectors);\n };\n var markUniqueSelector = function (editor, selector, group, globallyUniqueSelectors) {\n if (isExclusiveMode(editor, group)) {\n globallyUniqueSelectors[selector] = true;\n } else {\n group.selectors[selector] = true;\n }\n };\n var convertSelectorToFormat = function (editor, plugin, selector, group) {\n var selectorConverter;\n if (group && group.selector_converter) {\n selectorConverter = group.selector_converter;\n } else if (getSelectorConverter(editor)) {\n selectorConverter = getSelectorConverter(editor);\n } else {\n selectorConverter = function () {\n return defaultConvertSelectorToFormat(editor, selector);\n };\n }\n return selectorConverter.call(plugin, selector, group);\n };\n var setup = function (editor) {\n editor.on('init', function (_e) {\n var model = generate();\n var globallyUniqueSelectors = {};\n var selectorFilter = compileFilter(getSelectorFilter(editor));\n var groups = compileUserDefinedGroups(getCssGroups(editor));\n var processSelector = function (selector, group) {\n if (isUniqueSelector(editor, selector, group, globallyUniqueSelectors)) {\n markUniqueSelector(editor, selector, group, globallyUniqueSelectors);\n var format = convertSelectorToFormat(editor, editor.plugins.importcss, selector, group);\n if (format) {\n var formatName = format.name || global$1.DOM.uniqueId();\n editor.formatter.register(formatName, format);\n return global$4.extend({}, {\n title: format.title,\n format: formatName\n });\n }\n }\n return null;\n };\n global$4.each(getSelectors(editor, editor.getDoc(), compileFilter(getFileFilter(editor))), function (selector) {\n if (selector.indexOf('.mce-') === -1) {\n if (!selectorFilter || selectorFilter(selector)) {\n var selectorGroups = getGroupsBySelector(groups, selector);\n if (selectorGroups.length > 0) {\n global$4.each(selectorGroups, function (group) {\n var menuItem = processSelector(selector, group);\n if (menuItem) {\n model.addItemToGroup(group.title, menuItem);\n }\n });\n } else {\n var menuItem = processSelector(selector, null);\n if (menuItem) {\n model.addItem(menuItem);\n }\n }\n }\n }\n });\n var items = model.toFormats();\n editor.fire('addStyleModifications', {\n items: items,\n replace: !shouldAppend(editor)\n });\n });\n };\n\n var get = function (editor) {\n var convertSelectorToFormat = function (selectorText) {\n return defaultConvertSelectorToFormat(editor, selectorText);\n };\n return { convertSelectorToFormat: convertSelectorToFormat };\n };\n\n function Plugin () {\n global.add('importcss', function (editor) {\n setup(editor);\n return get(editor);\n });\n }\n\n Plugin();\n\n}());\n\n\n//# sourceURL=webpack:///./src/js/plugins/importcss/plugin.js?")}});