This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
anot
Archived
1
0
Fork 0

移除非浏览器环境的代码

master
宇天 2020-08-13 18:43:04 +08:00
parent 2fcdf274cc
commit eb3d4f82fc
30 changed files with 103 additions and 228 deletions

View File

@ -16,15 +16,15 @@ export default [
name: '_Anot'
},
plugins: [esm()]
},
{
input: 'src/anot.touch.js',
output: {
file: 'dist/anot.touch.js',
format: 'iife',
sourcemap: true,
name: '_Anot'
},
plugins: [esm()]
}
// {
// input: 'src/anot.touch.js',
// output: {
// file: 'dist/anot.touch.js',
// format: 'iife',
// sourcemap: true,
// name: '_Anot'
// },
// plugins: [esm()]
// }
]

View File

@ -1,5 +1,5 @@
import { Anot } from './seed/core'
import './seed/lang.modern'
import './seed/lang'
import './filters/index'
import './dom/modern'

View File

@ -1,5 +1,5 @@
import { Anot } from './seed/core'
import './seed/lang.modern'
import './seed/lang'
import './filters/index'
import './dom/modern'

View File

@ -5,13 +5,7 @@
* 2. value属性重写
* 3. 定时器轮询
*/
import {
Anot,
getShortID as markID,
window,
document,
msie
} from '../../seed/core'
import { Anot, getShortID as markID } from '../../seed/core'
import { updateModel } from './updateDataHandle'
export function updateDataEvents(dom, data) {
@ -48,9 +42,6 @@ export function updateDataEvents(dom, data) {
//https://github.com/RubyLouvre/Anot/issues/1368#issuecomment-220503284
events.compositionstart = openComposition
events.compositionend = closeComposition
if (Anot.msie) {
events.keyup = updateModelKeyDown
}
}
break
}

View File

@ -8,7 +8,6 @@ var impDir = Anot.directive('important', {
throw 'error! no vmodel called ' + name
},
update: function(node, attrName, $id) {
if (!Anot.inBrowser) return
var dom = Anot.vdom(node, 'toDOM')
if (dom.nodeType === 1) {
dom.removeAttribute(attrName)

View File

@ -1,4 +1,4 @@
import { Anot, inBrowser } from '../seed/core'
import { Anot } from '../seed/core'
import { addScope, makeHandle } from '../parser/index'

View File

@ -1,4 +1,4 @@
import { Anot, inBrowser } from '../seed/core'
import { Anot } from '../seed/core'
Anot.directive('text', {
delay: true,
@ -9,10 +9,10 @@ Anot.directive('text', {
}
var child = { nodeName: '#text', nodeValue: this.getValue() }
node.children.splice(0, node.children.length, child)
if (inBrowser) {
Anot.clearHTML(node.dom)
node.dom.appendChild(Anot.vdom(child, 'toDOM'))
}
this.node = child
var type = 'expr'
this.type = this.name = type

View File

@ -1,4 +1,4 @@
import { Anot, window, document } from '../../seed/core'
import { Anot } from '../../seed/core'
import { propMap } from './propMap'
var rsvg = /^\[object SVG\w*Element\]$/

View File

@ -1,4 +1,4 @@
import { Anot, oneObject, cssHooks, window } from '../../seed/core'
import { Anot, oneObject, cssHooks } from '../../seed/core'
var cssMap = oneObject('float', 'cssFloat')
export { cssMap, cssHooks }

View File

@ -1,4 +1,4 @@
import { Anot, document } from '../../seed/core'
import { Anot } from '../../seed/core'
import { avEvent } from './share'
export { avEvent }

View File

@ -1,16 +1,7 @@
import {
Anot,
_slice,
eventHooks,
modern,
window,
document,
root,
getShortID
} from '../../seed/core'
import { Anot, _slice, eventHooks, root, getShortID } from '../../seed/core'
import { canBubbleUp } from './canBubbleUp'
/* istanbul ignore if */
var hackSafari = Anot.modern && document.ontouchstart
var hackSafari = document.ontouchstart
//添加fn.bind, fn.unbind, bind, unbind
Anot.fn.bind = function(type, fn, phase) {
@ -54,7 +45,7 @@ Anot.bind = function(elem, type, fn) {
/* istanbul ignore if */
if (value.indexOf(type + ':') === -1) {
//同一种事件只绑定一次
if (canBubbleUp[type] || (Anot.modern && focusBlur[type])) {
if (canBubbleUp[type] || focusBlur[type]) {
delegateEvent(type)
} else {
Anot._nativeBind(elem, type, dispatch)
@ -206,16 +197,14 @@ var eventProto = {
preventDefault: function() {
var e = this.originalEvent || {}
e.returnValue = this.returnValue = false
if (modern && e.preventDefault) {
e.preventDefault()
}
},
stopPropagation: function() {
var e = this.originalEvent || {}
e.cancelBubble = this.cancelBubble = true
if (modern && e.stopPropagation) {
e.stopPropagation()
}
},
stopImmediatePropagation: function() {
this.stopPropagation()

View File

@ -1,4 +1,4 @@
import { Anot, Cache, document, createFragment } from '../../seed/core'
import { Anot, Cache, createFragment } from '../../seed/core'
import { fromString } from '../../vtree/fromString'
export { Anot }

View File

@ -1,4 +1,4 @@
import { Anot, window, document, root, inBrowser } from '../../seed/core'
import { Anot, root } from '../../seed/core'
var readyList = []
@ -33,6 +33,4 @@ function bootstrap() {
Anot.bind(window, 'load', fireReady)
}
if (inBrowser) {
bootstrap()
}

View File

@ -1,5 +1,5 @@
//safari5+是把contains方法放在Element.prototype上而不是Node.prototype
import { Anot, document, window, root } from '../../seed/core'
import { Anot, root } from '../../seed/core'
import { fixContains } from './fixContains'
export { Anot }
@ -9,7 +9,6 @@ Anot.cloneNode = function(a) {
return a.cloneNode(true)
}
if (Anot.modern) {
if (!document.contains) {
Node.prototype.contains = function(child) {
//IE6-8没有Node对象
@ -40,4 +39,3 @@ if (Anot.modern) {
fixFF('innerText', function() {
return this.textContent
})
}

View File

@ -4,7 +4,6 @@
* ------------------------------------------------------------
*/
import { window } from '../seed/core'
let checker = {
TransitionEvent: 'transitionend',
WebKitTransitionEvent: 'webkitTransitionEnd',

View File

@ -1,4 +1,4 @@
import { Anot, window, Cache } from '../seed/core'
import { Anot, Cache } from '../seed/core'
import { cssDiff } from '../directives/css'
import {
css3,

View File

@ -1,37 +1,3 @@
/*
'yyyy': 4 digit representation of year (e.g. AD 1 => 0001, AD 2010 => 2010)
'yy': 2 digit representation of year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10)
'y': 1 digit representation of year, e.g. (AD 1 => 1, AD 199 => 199)
'MMMM': Month in year (January-December)
'MMM': Month in year (Jan-Dec)
'MM': Month in year, padded (01-12)
'M': Month in year (1-12)
'dd': Day in month, padded (01-31)
'd': Day in month (1-31)
'EEEE': Day in Week,(Sunday-Saturday)
'EEE': Day in Week, (Sun-Sat)
'HH': Hour in day, padded (00-23)
'H': Hour in day (0-23)
'hh': Hour in am/pm, padded (01-12)
'h': Hour in am/pm, (1-12)
'mm': Minute in hour, padded (00-59)
'm': Minute in hour (0-59)
'ss': Second in minute, padded (00-59)
's': Second in minute (0-59)
'a': am/pm marker
'Z': 4 digit (+sign) representation of the timezone offset (-1200-+1200)
format string can also be one of the following predefined localizable formats:
'medium': equivalent to 'MMM d, y h:mm:ss a' for en_US locale (e.g. Sep 3, 2010 12:05:08 pm)
'short': equivalent to 'M/d/yy h:mm a' for en_US locale (e.g. 9/3/10 12:05 pm)
'fullDate': equivalent to 'EEEE, MMMM d,y' for en_US locale (e.g. Friday, September 3, 2010)
'longDate': equivalent to 'MMMM d, y' for en_US locale (e.g. September 3, 2010
'mediumDate': equivalent to 'MMM d, y' for en_US locale (e.g. Sep 3, 2010)
'shortDate': equivalent to 'M/d/yy' for en_US locale (e.g. 9/3/10)
'mediumTime': equivalent to 'h:mm:ss a' for en_US locale (e.g. 12:05:08 pm)
'shortTime': equivalent to 'h:mm a' for en_US locale (e.g. 12:05 pm)
*/
function toInt(str) {
return parseInt(str, 10) || 0
}
@ -44,8 +10,12 @@ function padNumber(num, digits, trim) {
num = -num
}
num = '' + num
while (num.length < digits) num = '0' + num
if (trim) num = num.substr(num.length - digits)
while (num.length < digits) {
num = '0' + num
}
if (trim) {
num = num.substr(num.length - digits)
}
return neg + num
}

View File

@ -1,4 +1,4 @@
import { Anot, msie, Cache } from '../seed/core'
import { Anot, Cache } from '../seed/core'
import { clearString, stringPool, fill, rfill, dig } from '../vtree/clearString'
var keyMap = Anot.oneObject(
@ -105,18 +105,6 @@ export function makeHandle(body) {
if (rhandleName.test(body)) {
body = body + '($event)'
}
/* istanbul ignore if */
if (msie < 9) {
body = body.replace(rfixIE678, function(a, b, c) {
return (
'__vmodel__.' +
b +
'.call(__vmodel__' +
(/\S/.test(c) ? ',' + c : '') +
')'
)
})
}
return body
}
export function createGetter(expr, type) {

View File

@ -1,4 +1,4 @@
import { Anot, inBrowser } from '../seed/core'
import { Anot } from '../seed/core'
import { Action, protectedMenbers } from '../vmodel/Action'
@ -11,13 +11,13 @@ import { Action, protectedMenbers } from '../vmodel/Action'
export function Directive(vm, binding, vdom, render) {
var type = binding.type
var decorator = Anot.directives[type]
if (inBrowser) {
var dom = Anot.vdom(vdom, 'toDOM')
if (dom.nodeType === 1) {
dom.removeAttribute(binding.attrName)
}
vdom.dom = dom
}
var callback = decorator.update
? function(value) {
if (!render.mount && /css|visible|duplex/.test(type)) {

View File

@ -1,10 +1,4 @@
import {
Anot,
config,
inBrowser,
delayCompileNodes,
directives
} from '../seed/core'
import { Anot, config, delayCompileNodes, directives } from '../seed/core'
import { fromDOM } from '../vtree/fromDOM'
import { fromString } from '../vtree/fromString'
@ -173,11 +167,11 @@ Render.prototype = {
//推算出指令类型
var type = dirs['ms-important'] === $id ? 'important' : 'controller'
//推算出用户定义时属性名,是使用ms-属性还是:属性
var attrName = 'ms-' + type in attrs ? 'ms-' + type : ':' + type
var _tmp = 'ms-' + type
var attrName = _tmp in attrs ? _tmp : ':' + type
if (inBrowser) {
delete attrs[attrName]
}
var dir = directives[type]
scope = dir.getScope.call(this, $id, scope)
if (!scope) {
@ -237,13 +231,11 @@ Render.prototype = {
complete() {
this.yieldDirectives()
this.beforeReady()
if (inBrowser) {
var root = this.root
if (inBrowser) {
var rootDom = Anot.vdom(root, 'toDOM')
groupTree(rootDom, root.children)
}
}
this.mount = true
var fn
@ -271,9 +263,9 @@ Render.prototype = {
}
for (var i = 0, binding; (binding = bindings[i++]); ) {
var dir = directives[binding.type]
if (!inBrowser && /on|duplex|active|hover/.test(binding.type)) {
continue
}
// if (!inBrowser && /on|duplex|active|hover/.test(binding.type)) {
// continue
// }
if (dir.beforeInit) {
dir.beforeInit.call(binding)
}

View File

@ -1,32 +0,0 @@
export let win =
typeof window === 'object' ? window : typeof global === 'object' ? global : {}
export let inBrowser = !!win.location && win.navigator
/* istanbul ignore if */
export let document = inBrowser
? win.document
: {
createElement: Object,
createElementNS: Object,
documentElement: 'xx',
contains: Boolean
}
export var root = inBrowser
? document.documentElement
: {
outerHTML: 'x'
}
let versions = {
objectobject: 7, //IE7-8
objectundefined: 6, //IE6
undefinedfunction: NaN, // other modern browsers
undefinedobject: NaN //Mobile Safari 8.0.0 (iOS 8.4.0)
//objectfunction chrome 47
}
/* istanbul ignore next */
export var msie =
document.documentMode || versions[typeof document.all + typeof XMLHttpRequest]
export var modern = /NaN|undefined/.test(msie) || msie > 8

View File

@ -1,8 +1,8 @@
import { win, document, msie, inBrowser, root, modern } from './browser'
import { Cache } from './cache'
import { directive, directives, delayCompileNodes } from './directive'
export var window = win
const root = document.documentElement
export function Anot(el) {
return new Anot.init(el)
}
@ -53,17 +53,7 @@ export function log() {
Function.apply.call(console.log, console, arguments)
}
}
export {
Cache,
directive,
directives,
delayCompileNodes,
document,
root,
msie,
modern,
inBrowser
}
export { Cache, directive, directives, delayCompileNodes, root }
export function warn() {
if (hasConsole && Anot.config.debug) {
var method = console.warn || console.log
@ -274,12 +264,9 @@ shadowCopy(Anot, {
error,
config,
modern,
msie,
root,
document,
window,
inBrowser,
isObject,
range,

View File

@ -1,5 +1,3 @@
import { document } from '../seed/core'
export function VComment(text) {
this.nodeName = '#comment'
this.nodeValue = text

View File

@ -1,4 +1,4 @@
import { Anot, document } from '../seed/core'
import { Anot } from '../seed/core'
export function VElement(type, props, children, isVoidTag) {
this.nodeName = type
@ -12,7 +12,7 @@ VElement.prototype = {
if (this.dom) return this.dom
var dom,
tagName = this.nodeName
if (Anot.modern && svgTags[tagName]) {
if (svgTags[tagName]) {
dom = createSVG(tagName)
} else {
dom = document.createElement(tagName)
@ -89,6 +89,4 @@ var svgTags = Anot.oneObject(
'path,polygon,polyline,rect,symbol,text,use,g,svg'
)
if (Anot.inBrowser) {
var supportTemplate = 'content' in document.createElement('template')
}

View File

@ -1,4 +1,4 @@
import { Anot, document } from '../seed/core'
import { Anot } from '../seed/core'
export function VText(text) {
this.nodeName = '#text'

View File

@ -1,4 +1,4 @@
import { Anot, ap, platform, modern, isObject } from '../seed/core'
import { Anot, ap, platform, isObject } from '../seed/core'
import { Mutation } from './Mutation'
var _splice = ap.splice
@ -102,9 +102,9 @@ __method__.forEach(function(method) {
export function listFactory(array, stop, dd) {
if (!stop) {
hijackMethods(array)
if (modern) {
Object.defineProperty(array, '$model', platform.modelAccessor)
}
platform.hideProperty(array, '$hashcode', Anot.makeHashCode('$'))
platform.hideProperty(array, '$events', { __dep__: dd || new Mutation() })
}

View File

@ -1,4 +1,4 @@
import { Anot, platform, modern } from '../seed/core'
import { Anot, platform } from '../seed/core'
import { $$skipArray } from './reserved'
import { Action } from './Action'
import './share'

View File

@ -1,4 +1,4 @@
import { Anot, platform, isObject, modern } from '../seed/core'
import { Anot, platform, isObject } from '../seed/core'
import { $$skipArray } from './reserved'
import { Mutation } from './Mutation'
import { Computed } from './Computed'

View File

@ -1,4 +1,4 @@
import { Anot, platform, isObject, modern } from '../seed/core'
import { Anot, platform, isObject } from '../seed/core'
import { $$skipArray } from './reserved'
import { Mutation } from './Mutation'
import { Computed } from './Computed'